reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #ifndef GrTextContext_DEFINED |
| 9 | #define GrTextContext_DEFINED |
| 10 | |
| 11 | #include "GrGlyph.h" |
tomhudson@google.com | 375ff85 | 2012-06-29 18:37:57 +0000 | [diff] [blame] | 12 | #include "GrPaint.h" |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 13 | #include "SkDeviceProperties.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | cc40f06 | 2014-01-24 14:38:27 +0000 | [diff] [blame] | 15 | #include "SkPostConfig.h" |
| 16 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | class GrContext; |
tomhudson@google.com | 375ff85 | 2012-06-29 18:37:57 +0000 | [diff] [blame] | 18 | class GrDrawTarget; |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 19 | class GrFontScaler; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 20 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 21 | /* |
| 22 | * This class wraps the state for a single text render |
| 23 | */ |
tomhudson@google.com | 375ff85 | 2012-06-29 18:37:57 +0000 | [diff] [blame] | 24 | class GrTextContext { |
bsalomon@google.com | f4a9c82 | 2012-03-16 14:02:46 +0000 | [diff] [blame] | 25 | public: |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 26 | virtual ~GrTextContext(); |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 27 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 28 | bool drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength, |
| 29 | SkScalar x, SkScalar y); |
| 30 | bool drawPosText(const GrPaint&, const SkPaint&, |
| 31 | const char text[], size_t byteLength, |
| 32 | const SkScalar pos[], int scalarsPerPosition, |
| 33 | const SkPoint& offset); |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 34 | |
jvanverth@google.com | c7a40fa | 2013-10-16 18:15:34 +0000 | [diff] [blame] | 35 | protected: |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 36 | GrTextContext* fFallbackTextContext; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 37 | GrContext* fContext; |
commit-bot@chromium.org | cbbc481 | 2014-01-30 22:05:47 +0000 | [diff] [blame] | 38 | SkDeviceProperties fDeviceProperties; |
| 39 | |
| 40 | GrDrawTarget* fDrawTarget; |
| 41 | SkIRect fClipRect; |
commit-bot@chromium.org | e8612d9 | 2014-01-28 22:02:07 +0000 | [diff] [blame] | 42 | GrPaint fPaint; |
| 43 | SkPaint fSkPaint; |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 44 | |
| 45 | GrTextContext(GrContext*, const SkDeviceProperties&); |
| 46 | |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 47 | virtual bool canDraw(const SkPaint& paint) = 0; |
| 48 | |
jvanverth | aab626c | 2014-10-16 08:04:39 -0700 | [diff] [blame] | 49 | virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength, |
| 50 | SkScalar x, SkScalar y) = 0; |
jvanverth | 8c27a18 | 2014-10-14 08:45:50 -0700 | [diff] [blame] | 51 | virtual void onDrawPosText(const GrPaint&, const SkPaint&, |
| 52 | const char text[], size_t byteLength, |
| 53 | const SkScalar pos[], int scalarsPerPosition, |
| 54 | const SkPoint& offset) = 0; |
| 55 | |
jvanverth | 0fedb19 | 2014-10-08 09:07:27 -0700 | [diff] [blame] | 56 | void init(const GrPaint&, const SkPaint&); |
| 57 | void finish() { fDrawTarget = NULL; } |
| 58 | |
| 59 | static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); |
| 60 | static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, |
| 61 | const char text[], size_t byteLength, SkVector* stopVector); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #endif |