1 /* 2 * Copyright 2015 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 GrAtlasTextContext_DEFINED 9 #define GrAtlasTextContext_DEFINED 10 11 #include "GrAtlasTextBlob.h" 12 #include "GrDistanceFieldAdjustTable.h" 13 #include "GrGeometryProcessor.h" 14 #include "GrTextUtils.h" 15 #include "SkTextBlobRunIterator.h" 16 17 #if GR_TEST_UTILS 18 #include "GrDrawOpTest.h" 19 #endif 20 21 class GrDrawOp; 22 class GrRenderTargetContext; 23 class GrPipelineBuilder; 24 class GrTextBlobCache; 25 class SkGlyph; 26 27 /* 28 * Renders text using some kind of an atlas, ie BitmapText or DistanceField text 29 */ 30 class GrAtlasTextContext { 31 public: 32 static GrAtlasTextContext* Create(); 33 34 bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&, 35 const GrShaderCaps&); 36 37 void drawText(GrContext*, GrRenderTargetContext*, const GrClip&, const SkPaint&, 38 const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[], 39 size_t byteLength, SkScalar x, SkScalar y, const SkIRect& regionClipBounds); 40 void drawPosText(GrContext*, GrRenderTargetContext*, const GrClip&, const SkPaint&, 41 const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[], 42 size_t byteLength, const SkScalar pos[], int scalarsPerPosition, 43 const SkPoint& offset, const SkIRect& regionClipBounds); 44 void drawTextBlob(GrContext*, GrRenderTargetContext*, const GrClip&, const SkPaint&, 45 const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*, 46 SkScalar x, SkScalar y, 47 SkDrawFilter*, const SkIRect& clipBounds); 48 49 private: 50 GrAtlasTextContext(); 51 52 // sets up the descriptor on the blob and returns a detached cache. Client must attach 53 inline static SkColor ComputeCanonicalColor(const SkPaint&, bool lcd); 54 // Determines if we need to use fake gamma (and contrast boost): 55 inline static uint32_t ComputeScalerContextFlags(GrRenderTargetContext*); 56 static void RegenerateTextBlob(GrAtlasTextBlob* bmp, 57 GrAtlasGlyphCache*, 58 const GrShaderCaps&, 59 const GrTextUtils::Paint&, 60 uint32_t scalerContextFlags, 61 const SkMatrix& viewMatrix, 62 const SkSurfaceProps&, 63 const SkTextBlob* blob, SkScalar x, SkScalar y, 64 SkDrawFilter* drawFilter); 65 inline static bool HasLCD(const SkTextBlob*); 66 67 static inline sk_sp<GrAtlasTextBlob> MakeDrawTextBlob(GrTextBlobCache*, GrAtlasGlyphCache*, 68 const GrShaderCaps&, 69 const GrTextUtils::Paint&, 70 uint32_t scalerContextFlags, 71 const SkMatrix& viewMatrix, 72 const SkSurfaceProps&, 73 const char text[], size_t byteLength, 74 SkScalar x, SkScalar y); 75 static inline sk_sp<GrAtlasTextBlob> MakeDrawPosTextBlob(GrTextBlobCache*, GrAtlasGlyphCache*, 76 const GrShaderCaps&, 77 const GrTextUtils::Paint&, 78 uint32_t scalerContextFlags, 79 const SkMatrix& viewMatrix, 80 const SkSurfaceProps&, 81 const char text[], size_t byteLength, 82 const SkScalar pos[], 83 int scalarsPerPosition, 84 const SkPoint& offset); dfAdjustTable()85 const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable.get(); } 86 87 sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; 88 89 #if GR_TEST_UTILS 90 static const uint32_t kTextBlobOpScalerContextFlags = 91 SkPaint::kFakeGammaAndBoostContrast_ScalerContextFlags; 92 DRAW_OP_TEST_FRIEND(TextBlobOp); 93 #endif 94 }; 95 96 #endif 97