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