| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrStencilAndCoverTextContext_DEFINED | 8 #ifndef GrStencilAndCoverTextContext_DEFINED |
| 9 #define GrStencilAndCoverTextContext_DEFINED | 9 #define GrStencilAndCoverTextContext_DEFINED |
| 10 | 10 |
| 11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
| 12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
| 13 #include "GrDrawTarget.h" | 13 #include "GrDrawTarget.h" |
| 14 #include "SkStrokeRec.h" | 14 #include "SkStrokeRec.h" |
| 15 | 15 |
| 16 class GrTextStrike; | 16 class GrTextStrike; |
| 17 class GrPath; | 17 class GrPath; |
| 18 class GrPathRange; |
| 18 | 19 |
| 19 /* | 20 /* |
| 20 * This class implements text rendering using stencil and cover path rendering | 21 * This class implements text rendering using stencil and cover path rendering |
| 21 * (by the means of GrDrawTarget::drawPath). | 22 * (by the means of GrDrawTarget::drawPath). |
| 22 * This class exposes the functionality through GrTextContext interface. | 23 * This class exposes the functionality through GrTextContext interface. |
| 23 */ | 24 */ |
| 24 class GrStencilAndCoverTextContext : public GrTextContext { | 25 class GrStencilAndCoverTextContext : public GrTextContext { |
| 25 public: | 26 public: |
| 26 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&); | 27 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&); |
| 27 virtual ~GrStencilAndCoverTextContext(); | 28 virtual ~GrStencilAndCoverTextContext(); |
| 28 | 29 |
| 29 virtual void drawText(const GrPaint&, const SkPaint&, const char text[], | 30 virtual void drawText(const GrPaint&, const SkPaint&, const char text[], |
| 30 size_t byteLength, | 31 size_t byteLength, |
| 31 SkScalar x, SkScalar y) SK_OVERRIDE; | 32 SkScalar x, SkScalar y) SK_OVERRIDE; |
| 32 virtual void drawPosText(const GrPaint&, const SkPaint&, | 33 virtual void drawPosText(const GrPaint&, const SkPaint&, |
| 33 const char text[], size_t byteLength, | 34 const char text[], size_t byteLength, |
| 34 const SkScalar pos[], SkScalar constY, | 35 const SkScalar pos[], SkScalar constY, |
| 35 int scalarsPerPosition) SK_OVERRIDE; | 36 int scalarsPerPosition) SK_OVERRIDE; |
| 36 | 37 |
| 37 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; | 38 virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE; |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 class GlyphPathRange; | |
| 41 static const int kGlyphBufferSize = 1024; | 41 static const int kGlyphBufferSize = 1024; |
| 42 | 42 |
| 43 enum DeviceSpaceGlyphsBehavior { | 43 enum RenderMode { |
| 44 kUseIfNeeded_DeviceSpaceGlyphsBehavior, | 44 /** |
| 45 kDoNotUse_DeviceSpaceGlyphsBehavior, | 45 * This is the render mode used by drawText(), which is mainly used by |
| 46 * the Skia unit tests. It tries match the other text backends exactly, |
| 47 * with the exception of not implementing LCD text, and doing anti- |
| 48 * aliasing with the built-in MSAA. |
| 49 */ |
| 50 kMaxAccuracy_RenderMode, |
| 51 |
| 52 /** |
| 53 * This is the render mode used by drawPosText(). It ignores hinting and |
| 54 * LCD text, even if the client provided positions for hinted glyphs, |
| 55 * and renders from a canonically-sized, generic set of paths for the |
| 56 * given typeface. In the future we should work out a system for the |
| 57 * client to know it should not provide hinted glyph positions. This |
| 58 * render mode also tries to use GPU stroking for fake bold, even when |
| 59 * SK_USE_FREETYPE_EMBOLDEN is set. |
| 60 */ |
| 61 kMaxPerformance_RenderMode, |
| 46 }; | 62 }; |
| 63 |
| 47 void init(const GrPaint&, const SkPaint&, size_t textByteLength, | 64 void init(const GrPaint&, const SkPaint&, size_t textByteLength, |
| 48 DeviceSpaceGlyphsBehavior, SkScalar textTranslateY = 0); | 65 RenderMode, SkScalar textTranslateY = 0); |
| 49 void initGlyphs(SkGlyphCache* cache); | 66 void initGlyphs(SkGlyphCache* cache); |
| 50 void appendGlyph(uint16_t glyphID, float x); | 67 void appendGlyph(uint16_t glyphID, float x); |
| 51 void appendGlyph(uint16_t glyphID, float x, float y); | 68 void appendGlyph(uint16_t glyphID, float x, float y); |
| 52 void flush(); | 69 void flush(); |
| 53 void finish(); | 70 void finish(); |
| 54 | 71 |
| 55 GrDrawState::AutoRestoreEffects fStateRestore; | 72 GrDrawState::AutoRestoreEffects fStateRestore; |
| 56 SkScalar fTextRatio; | 73 SkScalar fTextRatio; |
| 57 float fTextInverseRatio; | 74 float fTextInverseRatio; |
| 58 SkStrokeRec fStroke; | |
| 59 SkGlyphCache* fGlyphCache; | 75 SkGlyphCache* fGlyphCache; |
| 60 GlyphPathRange* fGlyphs; | 76 GrPathRange* fGlyphs; |
| 61 uint32_t fIndexBuffer[kGlyphBufferSize]; | 77 uint32_t fIndexBuffer[kGlyphBufferSize]; |
| 62 float fTransformBuffer[2 * kGlyphBufferSize]; | 78 float fTransformBuffer[2 * kGlyphBufferSize]; |
| 63 GrDrawTarget::PathTransformType fTransformType; | 79 GrDrawTarget::PathTransformType fTransformType; |
| 64 int fPendingGlyphCount; | 80 int fPendingGlyphCount; |
| 65 SkMatrix fContextInitialMatrix; | 81 SkMatrix fContextInitialMatrix; |
| 66 bool fNeedsDeviceSpaceGlyphs; | 82 bool fNeedsDeviceSpaceGlyphs; |
| 67 }; | 83 }; |
| 68 | 84 |
| 69 #endif | 85 #endif |
| OLD | NEW |