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 SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE; | |
33 | |
34 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain t&, | |
35 const SkMatrix& viewMatrix, const char text[], size_t byteLe ngth, | |
36 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) SK_ OVERRIDE; | |
37 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP aint&, | |
38 const SkMatrix& viewMatrix, | |
39 const char text[], size_t byteLength, | |
40 const SkScalar pos[], int scalarsPerPosition, | |
41 const SkPoint& offset, const SkIRect& regionClipBounds) S K_OVERRIDE; | |
42 void onDrawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, | |
43 const SkMatrix& viewMatrix, const SkTextBlob*, | |
44 SkScalar x, SkScalar y, SkDrawFilter*, | |
45 const SkIRect& clipBounds) SK_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 is to ensure that | |
Jvsquare
2015/03/27 15:07:29
Nit: "The only thing (aside from a memcopy) requir
joshualitt
2015/03/30 14:56:43
Acknowledged.
| |
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 uint32_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 flush(GrDrawTarget*, BitmapTextBlob*, int i, GrPipelineBuilder*, GrMask Format, | |
Jvsquare
2015/03/27 15:07:29
It's not clear to me which is the main flush() her
joshualitt
2015/03/30 14:56:43
Acknowledged.
| |
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 28 matching lines...) Expand all Loading... | |
52 | 173 |
53 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, | 174 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
54 const SkIRect& regionClipBounds); | 175 const SkIRect& regionClipBounds); |
55 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* ); | 176 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* ); |
56 bool uploadGlyph(GrGlyph*, GrFontScaler*); | 177 bool uploadGlyph(GrGlyph*, GrFontScaler*); |
57 void flush(); // automatically called by destructor | 178 void flush(); // automatically called by destructor |
58 void finish(); | 179 void finish(); |
59 }; | 180 }; |
60 | 181 |
61 #endif | 182 #endif |
OLD | NEW |