OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrTextContext_DEFINED | 8 #ifndef GrTextContext_DEFINED |
9 #define GrTextContext_DEFINED | 9 #define GrTextContext_DEFINED |
10 | 10 |
11 #include "GrClip.h" | 11 #include "GrClip.h" |
12 #include "GrGlyph.h" | 12 #include "GrGlyph.h" |
13 #include "GrPaint.h" | 13 #include "GrPaint.h" |
14 #include "SkDeviceProperties.h" | 14 #include "SkDeviceProperties.h" |
15 | 15 |
16 #include "SkPostConfig.h" | 16 #include "SkPostConfig.h" |
17 | 17 |
18 class GrClip; | 18 class GrClip; |
19 class GrContext; | 19 class GrContext; |
20 class GrDrawTarget; | 20 class GrDrawTarget; |
21 class GrFontScaler; | 21 class GrFontScaler; |
| 22 class SkGpuDevice; |
22 | 23 |
23 /* | 24 /* |
24 * This class wraps the state for a single text render | 25 * This class wraps the state for a single text render |
25 */ | 26 */ |
26 class GrTextContext { | 27 class GrTextContext { |
27 public: | 28 public: |
28 virtual ~GrTextContext(); | 29 virtual ~GrTextContext(); |
29 | 30 |
30 bool drawText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const SkPa
int&, | 31 void drawText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const SkPa
int&, |
31 const SkMatrix& viewMatrix, const char text[], size_t byteLeng
th, SkScalar x, | 32 const SkMatrix& viewMatrix, const char text[], size_t byteLeng
th, SkScalar x, |
32 SkScalar y); | 33 SkScalar y, const SkIRect& clipBounds); |
33 bool drawPosText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const Sk
Paint&, | 34 void drawPosText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const Sk
Paint&, |
34 const SkMatrix& viewMatrix, | 35 const SkMatrix& viewMatrix, |
35 const char text[], size_t byteLength, | 36 const char text[], size_t byteLength, |
36 const SkScalar pos[], int scalarsPerPosition, | 37 const SkScalar pos[], int scalarsPerPosition, |
37 const SkPoint& offset); | 38 const SkPoint& offset, const SkIRect& clipBounds); |
38 | 39 |
39 protected: | 40 protected: |
40 GrTextContext* fFallbackTextContext; | 41 GrTextContext* fFallbackTextContext; |
41 GrContext* fContext; | 42 GrContext* fContext; |
| 43 // TODO we probably don't really need to store a back pointer to the owning
SkGpuDevice, except |
| 44 // we need to be able to call drawPath on it in the event no other text cont
ext can draw the |
| 45 // text. We might be able to move this logic to context though. This is un
reffed because |
| 46 // GrTextContext is completely owned by SkGpuDevice |
| 47 SkGpuDevice* fGpuDevice; |
42 SkDeviceProperties fDeviceProperties; | 48 SkDeviceProperties fDeviceProperties; |
43 | 49 |
44 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 50 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
45 GrClip fClip; | 51 GrClip fClip; |
46 GrDrawTarget* fDrawTarget; | 52 GrDrawTarget* fDrawTarget; |
47 SkIRect fClipRect; | 53 SkIRect fClipRect; |
| 54 SkIRect fRegionClipBounds; |
48 GrPaint fPaint; | 55 GrPaint fPaint; |
49 SkPaint fSkPaint; | 56 SkPaint fSkPaint; |
50 | 57 |
51 GrTextContext(GrContext*, const SkDeviceProperties&); | 58 GrTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
52 | 59 |
53 virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) = 0; | 60 virtual bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) = 0; |
54 | 61 |
55 virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, cons
t SkPaint&, | 62 virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, cons
t SkPaint&, |
56 const SkMatrix& viewMatrix, const char text[], size_
t byteLength, | 63 const SkMatrix& viewMatrix, const char text[], size_
t byteLength, |
57 SkScalar x, SkScalar y) = 0; | 64 SkScalar x, SkScalar y, const SkIRect& clipBounds) =
0; |
58 virtual void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, c
onst SkPaint&, | 65 virtual void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, c
onst SkPaint&, |
59 const SkMatrix& viewMatrix, | 66 const SkMatrix& viewMatrix, |
60 const char text[], size_t byteLength, | 67 const char text[], size_t byteLength, |
61 const SkScalar pos[], int scalarsPerPosition, | 68 const SkScalar pos[], int scalarsPerPosition, |
62 const SkPoint& offset) = 0; | 69 const SkPoint& offset, const SkIRect& clipBounds)
= 0; |
63 | 70 |
64 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&); | 71 void drawTextAsPath(const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 72 const char text[], size_t byteLength, SkScalar x, SkScal
ar y, |
| 73 const SkIRect& clipBounds); |
| 74 void drawPosTextAsPath(const SkPaint& origPaint, const SkMatrix& viewMatrix, |
| 75 const char text[], size_t byteLength, |
| 76 const SkScalar pos[], int scalarsPerPosition, |
| 77 const SkPoint& offset, const SkIRect& clipBounds); |
| 78 |
| 79 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 80 const SkIRect& regionClipBounds); |
65 void finish() { fDrawTarget = NULL; } | 81 void finish() { fDrawTarget = NULL; } |
66 | 82 |
67 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); | 83 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache); |
68 // sets extent in stopVector and returns glyph count | 84 // sets extent in stopVector and returns glyph count |
69 static int MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, | 85 static int MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, |
70 const char text[], size_t byteLength, SkVector* stopV
ector); | 86 const char text[], size_t byteLength, SkVector* stopV
ector); |
71 }; | 87 }; |
72 | 88 |
73 #endif | 89 #endif |
OLD | NEW |