OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrBitmapTextContext_DEFINED | 8 #ifndef GrBitmapTextContext_DEFINED |
9 #define GrBitmapTextContext_DEFINED | 9 #define GrBitmapTextContext_DEFINED |
10 | 10 |
11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
12 | 12 |
13 #include "GrGeometryProcessor.h" | 13 #include "GrGeometryProcessor.h" |
| 14 #include "SkTHash.h" |
| 15 |
| 16 class GrBatchTextStrike; |
| 17 class GrPipelineBuilder; |
| 18 |
| 19 /* |
| 20 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. |
| 21 * TODO replace GrBitmapTextContext |
| 22 */ |
| 23 class GrBitmapTextContextB : public GrTextContext { |
| 24 public: |
| 25 static GrBitmapTextContextB* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); |
| 26 |
| 27 virtual ~GrBitmapTextContextB(); |
| 28 |
| 29 private: |
| 30 GrBitmapTextContextB(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
| 31 |
| 32 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
| 33 const SkPaint&, const SkMatrix& viewMatrix) override; |
| 34 |
| 35 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, |
| 36 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, |
| 37 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; |
| 38 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, |
| 39 const SkMatrix& viewMatrix, |
| 40 const char text[], size_t byteLength, |
| 41 const SkScalar pos[], int scalarsPerPosition, |
| 42 const SkPoint& offset, const SkIRect& regionClipBounds) o
verride; |
| 43 void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, |
| 44 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x,
SkScalar y, |
| 45 SkDrawFilter*, const SkIRect& clipBounds) override; |
| 46 |
| 47 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 48 const SkIRect& regionClipBounds); |
| 49 |
| 50 /* |
| 51 * A BitmapTextBlob contains a fully processed SkTextBlob, suitable for near
ly immediate drawing |
| 52 * on the GPU. These are initially created with valid positions and colors,
but invalid |
| 53 * texture coordinates. The BitmapTextBlob itself has a few Blob-wide prope
rties, and also |
| 54 * consists of a number of runs. Runs inside a blob are flushed individuall
y so they can be |
| 55 * reordered. |
| 56 * |
| 57 * The only thing(aside from a memcopy) required to flush a BitmapTextBlob i
s to ensure that |
| 58 * the GrAtlas will not evict anything the Blob needs. |
| 59 * TODO this is currently a bug |
| 60 */ |
| 61 struct BitmapTextBlob : public SkRefCnt { |
| 62 // Each Run inside of the blob can have its texture coordinates regenera
ted if required. |
| 63 // To determine if regeneration is necessary, fAtlasGeneration is used.
If there have been |
| 64 // any evictions inside of the atlas, then we will simply regenerate Run
s. We could track |
| 65 // this at a more fine grained level, but its not clear if this is worth
it, as evictions |
| 66 // should be fairly rare. |
| 67 // One additional point, each run can contain glyphs with any of the thr
ee mask formats. |
| 68 // We maintain separate arrays for each format type, and flush them sepa
rately. In practice |
| 69 // most of the time a run will have the same format type |
| 70 struct Run { |
| 71 Run() : fColor(GrColor_ILLEGAL) { fVertexBounds.setLargestInverted()
; } |
| 72 struct PerFormatInfo { |
| 73 PerFormatInfo() : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGe
neration) {} |
| 74 SkTDArray<unsigned char> fVertices; |
| 75 SkTDArray<GrGlyph::PackedID> fGlyphIDs; |
| 76 uint64_t fAtlasGeneration; |
| 77 }; |
| 78 SkAutoTUnref<const SkData> fDescriptor; |
| 79 SkAutoTUnref<SkTypeface> fTypeface; |
| 80 PerFormatInfo fInfos[kMaskFormatCount]; |
| 81 SkRect fVertexBounds; |
| 82 GrColor fColor; |
| 83 }; |
| 84 SkSTArray<1, Run, true> fRuns; |
| 85 struct BigGlyph { |
| 86 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx),
fVy(vy) {} |
| 87 SkPath fPath; |
| 88 int fVx; |
| 89 int fVy; |
| 90 }; |
| 91 SkTArray<BigGlyph> fBigGlyphs; |
| 92 SkTextBlob* fBlob; |
| 93 SkMatrix fViewMatrix; |
| 94 SkScalar fX; |
| 95 SkScalar fY; |
| 96 SkPaint::Style fStyle; |
| 97 |
| 98 static uint32_t Hash(const uint32_t& key) { |
| 99 return SkChecksum::Mix(key); |
| 100 } |
| 101 }; |
| 102 |
| 103 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, |
| 104 GrFontScaler*, const SkIRect& clipRect); |
| 105 void flushSubRun(GrDrawTarget*, BitmapTextBlob*, int i, GrPipelineBuilder*,
GrMaskFormat, |
| 106 GrColor color, int paintAlpha); |
| 107 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const GrPaint&,
const GrClip&, |
| 108 const SkMatrix& viewMatrix, int paintAlpha); |
| 109 |
| 110 void internalDrawText(BitmapTextBlob*, int runIndex, const SkPaint&, |
| 111 const SkMatrix& viewMatrix, const char text[], size_t
byteLength, |
| 112 SkScalar x, SkScalar y, const SkIRect& clipRect); |
| 113 void internalDrawPosText(BitmapTextBlob*, int runIndex, const SkPaint&, |
| 114 const SkMatrix& viewMatrix, |
| 115 const char text[], size_t byteLength, |
| 116 const SkScalar pos[], int scalarsPerPosition, |
| 117 const SkPoint& offset, const SkIRect& clipRect); |
| 118 |
| 119 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, |
| 120 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); |
| 121 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, |
| 122 const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 123 SkDrawFilter* drawFilter, const SkIRect& clipRect); |
| 124 |
| 125 GrBatchTextStrike* fCurrStrike; |
| 126 |
| 127 // TODO use real cache |
| 128 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); |
| 129 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; |
| 130 |
| 131 friend class BitmapTextBatch; |
| 132 |
| 133 typedef GrTextContext INHERITED; |
| 134 }; |
14 | 135 |
15 class GrTextStrike; | 136 class GrTextStrike; |
16 | 137 |
17 /* | 138 /* |
18 * This class implements GrTextContext using standard bitmap fonts | 139 * This class implements GrTextContext using standard bitmap fonts |
19 */ | 140 */ |
20 class GrBitmapTextContext : public GrTextContext { | 141 class GrBitmapTextContext : public GrTextContext { |
21 public: | 142 public: |
22 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); | 143 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); |
23 | 144 |
(...skipping 29 matching lines...) Expand all Loading... |
53 | 174 |
54 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, | 175 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
55 const SkIRect& regionClipBounds); | 176 const SkIRect& regionClipBounds); |
56 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*
); | 177 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*
); |
57 bool uploadGlyph(GrGlyph*, GrFontScaler*); | 178 bool uploadGlyph(GrGlyph*, GrFontScaler*); |
58 void flush(); // automatically called by destructor | 179 void flush(); // automatically called by destructor |
59 void finish(); | 180 void finish(); |
60 }; | 181 }; |
61 | 182 |
62 #endif | 183 #endif |
OLD | NEW |