| OLD | NEW |
| (Empty) |
| 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 "GrTextContext.h" | |
| 12 | |
| 13 #include "GrAtlasTextBlob.h" | |
| 14 #include "GrDistanceFieldAdjustTable.h" | |
| 15 #include "GrGeometryProcessor.h" | |
| 16 #include "SkTextBlobRunIterator.h" | |
| 17 | |
| 18 #ifdef GR_TEST_UTILS | |
| 19 #include "GrBatchTest.h" | |
| 20 #endif | |
| 21 | |
| 22 class GrDrawBatch; | |
| 23 class GrDrawContext; | |
| 24 class GrDrawTarget; | |
| 25 class GrPipelineBuilder; | |
| 26 class GrTextBlobCache; | |
| 27 class SkGlyph; | |
| 28 | |
| 29 /* | |
| 30 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. | |
| 31 */ | |
| 32 class GrAtlasTextContext : public GrTextContext { | |
| 33 public: | |
| 34 static GrAtlasTextContext* Create(GrContext*, const SkSurfaceProps&); | |
| 35 | |
| 36 private: | |
| 37 GrAtlasTextContext(GrContext*, const SkSurfaceProps&); | |
| 38 ~GrAtlasTextContext() override {} | |
| 39 | |
| 40 bool canDraw(const SkPaint&, const SkMatrix& viewMatrix) override; | |
| 41 | |
| 42 void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint
&, | |
| 43 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, | |
| 44 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; | |
| 45 void onDrawPosText(GrDrawContext*, const GrClip&, const GrPaint&, | |
| 46 const SkPaint&, const SkMatrix& viewMatrix, | |
| 47 const char text[], size_t byteLength, | |
| 48 const SkScalar pos[], int scalarsPerPosition, | |
| 49 const SkPoint& offset, const SkIRect& regionClipBounds) o
verride; | |
| 50 void drawTextBlob(GrDrawContext*, const GrClip&, const SkPaint&, | |
| 51 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x,
SkScalar y, | |
| 52 SkDrawFilter*, const SkIRect& clipBounds) override; | |
| 53 | |
| 54 typedef GrAtlasTextBlob::Run Run; | |
| 55 typedef Run::SubRunInfo PerSubRunInfo; | |
| 56 | |
| 57 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatr
ix); | |
| 58 GrAtlasTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, | |
| 59 const SkMatrix& viewMatrix, SkPaint* dfPaint, | |
| 60 SkScalar* textRatio); | |
| 61 void bmpAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, int left
, int top, | |
| 62 GrColor color, GrFontScaler*); | |
| 63 bool dfAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, SkScalar
sx, SkScalar sy, | |
| 64 GrColor color, GrFontScaler*, SkScalar textRatio, | |
| 65 const SkMatrix& viewMatrix); | |
| 66 | |
| 67 // A helper for drawing BitmapText in a run of distance fields | |
| 68 inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex, | |
| 69 const GrClip&, GrColor color, | |
| 70 const SkPaint&, const SkMatrix& viewMatrix, | |
| 71 const SkTDArray<char>& fallbackTxt, | |
| 72 const SkTDArray<SkScalar>& fallbackPos, | |
| 73 int scalarsPerPosition, | |
| 74 const SkPoint& offset); | |
| 75 | |
| 76 void internalDrawDFText(GrAtlasTextBlob*, int runIndex, const SkPaint&, | |
| 77 GrColor color, const SkMatrix& viewMatrix, | |
| 78 const char text[], size_t byteLength, | |
| 79 SkScalar x, SkScalar y, | |
| 80 SkScalar textRatio, | |
| 81 SkTDArray<char>* fallbackTxt, | |
| 82 SkTDArray<SkScalar>* fallbackPos, | |
| 83 SkPoint* offset, const SkPaint& origPaint); | |
| 84 void internalDrawDFPosText(GrAtlasTextBlob*, int runIndex, const SkPaint&, | |
| 85 GrColor color, const SkMatrix& viewMatrix, | |
| 86 const char text[], size_t byteLength, | |
| 87 const SkScalar pos[], int scalarsPerPosition, | |
| 88 const SkPoint& offset, | |
| 89 SkScalar textRatio, | |
| 90 SkTDArray<char>* fallbackTxt, | |
| 91 SkTDArray<SkScalar>* fallbackPos); | |
| 92 | |
| 93 // sets up the descriptor on the blob and returns a detached cache. Client
must attach | |
| 94 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); | |
| 95 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMa
trix, bool noGamma); | |
| 96 void regenerateTextBlob(GrAtlasTextBlob* bmp, const SkPaint& skPaint, GrColo
r, | |
| 97 const SkMatrix& viewMatrix, | |
| 98 const SkTextBlob* blob, SkScalar x, SkScalar y, | |
| 99 SkDrawFilter* drawFilter, | |
| 100 const GrClip&); | |
| 101 inline static bool HasLCD(const SkTextBlob*); | |
| 102 inline void initDistanceFieldPaint(GrAtlasTextBlob*, SkPaint*, SkScalar* tex
tRatio, | |
| 103 const SkMatrix&); | |
| 104 | |
| 105 // Test methods | |
| 106 // TODO this is really ugly. It'd be much nicer if positioning could be mov
ed to batch | |
| 107 inline GrAtlasTextBlob* createDrawTextBlob(const GrClip&, const GrPaint&, | |
| 108 const SkPaint&, const SkMatrix& v
iewMatrix, | |
| 109 const char text[], size_t byteLen
gth, | |
| 110 SkScalar x, SkScalar y, | |
| 111 const SkIRect& regionClipBounds); | |
| 112 inline GrAtlasTextBlob* createDrawPosTextBlob(const GrClip&, const GrPaint&, | |
| 113 const SkPaint&, const SkMatrix
& viewMatrix, | |
| 114 const char text[], size_t byte
Length, | |
| 115 const SkScalar pos[], int scal
arsPerPosition, | |
| 116 const SkPoint& offset, | |
| 117 const SkIRect& regionClipBound
s); | |
| 118 const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAd
justTable; } | |
| 119 | |
| 120 GrBatchTextStrike* fCurrStrike; | |
| 121 GrTextBlobCache* fCache; | |
| 122 SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable; | |
| 123 | |
| 124 #ifdef GR_TEST_UTILS | |
| 125 DRAW_BATCH_TEST_FRIEND(TextBlobBatch); | |
| 126 #endif | |
| 127 | |
| 128 typedef GrTextContext INHERITED; | |
| 129 }; | |
| 130 | |
| 131 #endif | |
| OLD | NEW |