1 /* 2 * Copyright 2014 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. 6 */ 7 8 #ifndef GrStencilAndCoverTextContext_DEFINED 9 #define GrStencilAndCoverTextContext_DEFINED 10 11 #include "GrTextContext.h" 12 #include "GrDrawTarget.h" 13 #include "SkStrokeRec.h" 14 15 class GrTextStrike; 16 class GrPath; 17 class GrPathRange; 18 19 /* 20 * This class implements text rendering using stencil and cover path rendering 21 * (by the means of GrDrawTarget::drawPath). 22 * This class exposes the functionality through GrTextContext interface. 23 */ 24 class GrStencilAndCoverTextContext : public GrTextContext { 25 public: 26 static GrStencilAndCoverTextContext* Create(GrContext*, SkGpuDevice*, 27 const SkDeviceProperties&); 28 29 virtual ~GrStencilAndCoverTextContext(); 30 31 private: 32 static const int kGlyphBufferSize = 1024; 33 34 enum RenderMode { 35 /** 36 * This is the render mode used by drawText(), which is mainly used by 37 * the Skia unit tests. It tries match the other text backends exactly, 38 * with the exception of not implementing LCD text, and doing anti- 39 * aliasing with the built-in MSAA. 40 */ 41 kMaxAccuracy_RenderMode, 42 43 /** 44 * This is the render mode used by drawPosText(). It ignores hinting and 45 * LCD text, even if the client provided positions for hinted glyphs, 46 * and renders from a canonically-sized, generic set of paths for the 47 * given typeface. In the future we should work out a system for the 48 * client to know it should not provide hinted glyph positions. This 49 * render mode also tries to use GPU stroking for fake bold, even when 50 * SK_USE_FREETYPE_EMBOLDEN is set. 51 */ 52 kMaxPerformance_RenderMode, 53 }; 54 55 GrPipelineBuilder fPipelineBuilder; 56 GrPipelineBuilder::AutoRestoreFragmentProcessors fStateRestore; 57 SkScalar fTextRatio; 58 float fTextInverseRatio; 59 SkGlyphCache* fGlyphCache; 60 GrPathRange* fGlyphs; 61 SkStrokeRec fStroke; 62 uint16_t fGlyphIndices[kGlyphBufferSize]; 63 SkPoint fGlyphPositions[kGlyphBufferSize]; 64 int fQueuedGlyphCount; 65 int fFallbackGlyphsIdx; 66 SkMatrix fContextInitialMatrix; 67 SkMatrix fViewMatrix; 68 SkMatrix fLocalMatrix; 69 bool fUsingDeviceSpaceGlyphs; 70 71 GrStencilAndCoverTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); 72 73 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, 74 const SkPaint&, const SkMatrix& viewMatrix) override; 75 76 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, 77 const SkMatrix& viewMatrix, 78 const char text[], size_t byteLength, 79 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override; 80 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, 81 const SkMatrix& viewMatrix, 82 const char text[], size_t byteLength, 83 const SkScalar pos[], int scalarsPerPosition, 84 const SkPoint& offset, const SkIRect& regionClipBounds) override; 85 86 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, 87 size_t textByteLength, RenderMode, const SkMatrix& viewMatrix, 88 const SkIRect& regionClipBounds); 89 bool mapToFallbackContext(SkMatrix* inverse); 90 void appendGlyph(const SkGlyph&, const SkPoint&); 91 void flush(); 92 void finish(); 93 94 }; 95 96 #endif 97