OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrAtlasTextContext_DEFINED | 8 #ifndef GrAtlasTextContext_DEFINED |
9 #define GrAtlasTextContext_DEFINED | 9 #define GrAtlasTextContext_DEFINED |
10 | 10 |
11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
12 | 12 |
13 #include "GrBatchAtlas.h" | 13 #include "GrBatchAtlas.h" |
14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
15 #include "SkDescriptor.h" | 15 #include "SkDescriptor.h" |
| 16 #include "GrMemoryPool.h" |
16 #include "SkTextBlob.h" | 17 #include "SkTextBlob.h" |
17 #include "SkTHash.h" | 18 #include "SkTInternalLList.h" |
18 | 19 |
19 class GrBatchTextStrike; | 20 class GrBatchTextStrike; |
20 class GrPipelineBuilder; | 21 class GrPipelineBuilder; |
| 22 class GrTextBlobCache; |
21 | 23 |
22 /* | 24 /* |
23 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. | 25 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. |
24 * TODO replace GrBitmapTextContext | 26 * TODO replace GrBitmapTextContext |
25 */ | 27 */ |
26 class GrAtlasTextContext : public GrTextContext { | 28 class GrAtlasTextContext : public GrTextContext { |
27 public: | 29 public: |
28 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr
operties&); | 30 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr
operties&); |
29 | 31 |
30 virtual ~GrAtlasTextContext(); | |
31 | |
32 private: | 32 private: |
33 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); | 33 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
34 | 34 |
35 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, | 35 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, |
36 const SkPaint&, const SkMatrix& viewMatrix) override; | 36 const SkPaint&, const SkMatrix& viewMatrix) override; |
37 | 37 |
38 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, | 38 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, |
39 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, | 39 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, |
40 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; | 40 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove
rride; |
41 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, | 41 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, |
(...skipping 10 matching lines...) Expand all Loading... |
52 * on the GPU. These are initially created with valid positions and colors,
but invalid | 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 | 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 | 54 * consists of a number of runs. Runs inside a blob are flushed individuall
y so they can be |
55 * reordered. | 55 * reordered. |
56 * | 56 * |
57 * The only thing(aside from a memcopy) required to flush a BitmapTextBlob i
s to ensure that | 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. | 58 * the GrAtlas will not evict anything the Blob needs. |
59 * TODO this is currently a bug | 59 * TODO this is currently a bug |
60 */ | 60 */ |
61 struct BitmapTextBlob : public SkRefCnt { | 61 struct BitmapTextBlob : public SkRefCnt { |
| 62 SK_DECLARE_INTERNAL_LLIST_INTERFACE(BitmapTextBlob); |
| 63 |
62 /* | 64 /* |
63 * Each Run inside of the blob can have its texture coordinates regenera
ted if required. | 65 * Each Run inside of the blob can have its texture coordinates regenera
ted if required. |
64 * To determine if regeneration is necessary, fAtlasGeneration is used.
If there have been | 66 * To determine if regeneration is necessary, fAtlasGeneration is used.
If there have been |
65 * any evictions inside of the atlas, then we will simply regenerate Run
s. We could track | 67 * any evictions inside of the atlas, then we will simply regenerate Run
s. We could track |
66 * this at a more fine grained level, but its not clear if this is worth
it, as evictions | 68 * this at a more fine grained level, but its not clear if this is worth
it, as evictions |
67 * should be fairly rare. | 69 * should be fairly rare. |
68 * | 70 * |
69 * One additional point, each run can contain glyphs with any of the thr
ee mask formats. | 71 * One additional point, each run can contain glyphs with any of the thr
ee mask formats. |
70 * We call these SubRuns. Because a subrun must be a contiguous range,
we have to create | 72 * We call these SubRuns. Because a subrun must be a contiguous range,
we have to create |
71 * a new subrun each time the mask format changes in a run. In theory,
a run can have as | 73 * a new subrun each time the mask format changes in a run. In theory,
a run can have as |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 int fVx; | 123 int fVx; |
122 int fVy; | 124 int fVy; |
123 }; | 125 }; |
124 | 126 |
125 SkTArray<BigGlyph> fBigGlyphs; | 127 SkTArray<BigGlyph> fBigGlyphs; |
126 SkMatrix fViewMatrix; | 128 SkMatrix fViewMatrix; |
127 SkScalar fX; | 129 SkScalar fX; |
128 SkScalar fY; | 130 SkScalar fY; |
129 SkPaint::Style fStyle; | 131 SkPaint::Style fStyle; |
130 int fRunCount; | 132 int fRunCount; |
| 133 uint32_t fUniqueID; |
| 134 GrMemoryPool* fPool; |
131 | 135 |
132 // all glyph / vertex offsets are into these pools. | 136 // all glyph / vertex offsets are into these pools. |
133 unsigned char* fVertices; | 137 unsigned char* fVertices; |
134 GrGlyph::PackedID* fGlyphIDs; | 138 GrGlyph::PackedID* fGlyphIDs; |
135 Run* fRuns; | 139 Run* fRuns; |
136 | 140 |
| 141 static const uint32_t& GetKey(const BitmapTextBlob& blob) { |
| 142 return blob.fUniqueID; |
| 143 } |
| 144 |
137 static uint32_t Hash(const uint32_t& key) { | 145 static uint32_t Hash(const uint32_t& key) { |
138 return SkChecksum::Mix(key); | 146 return SkChecksum::Mix(key); |
139 } | 147 } |
140 | 148 |
141 void operator delete(void* p) { sk_free(p); } | 149 void operator delete(void* p) { |
| 150 BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); |
| 151 blob->fPool->release(p); |
| 152 } |
142 void* operator new(size_t) { | 153 void* operator new(size_t) { |
143 SkFAIL("All blobs are created by placement new."); | 154 SkFAIL("All blobs are created by placement new."); |
144 return sk_malloc_throw(0); | 155 return sk_malloc_throw(0); |
145 } | 156 } |
146 | 157 |
147 void* operator new(size_t, void* p) { return p; } | 158 void* operator new(size_t, void* p) { return p; } |
148 void operator delete(void* target, void* placement) { | 159 void operator delete(void* target, void* placement) { |
149 ::operator delete(target, placement); | 160 ::operator delete(target, placement); |
150 } | 161 } |
151 }; | 162 }; |
152 | 163 |
153 typedef BitmapTextBlob::Run Run; | 164 typedef BitmapTextBlob::Run Run; |
154 typedef Run::SubRunInfo PerSubRunInfo; | 165 typedef Run::SubRunInfo PerSubRunInfo; |
155 | 166 |
156 BitmapTextBlob* CreateBlob(int glyphCount, int runCount); | |
157 | |
158 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, | 167 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, |
159 GrColor color, GrFontScaler*, const SkIRect& clipRect); | 168 GrColor color, GrFontScaler*, const SkIRect& clipRect); |
160 | 169 |
161 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&,
SkDrawFilter*, | 170 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&,
SkDrawFilter*, |
162 const SkMatrix& viewMatrix, const SkIRect& clipB
ounds, SkScalar x, | 171 const SkMatrix& viewMatrix, const SkIRect& clipB
ounds, SkScalar x, |
163 SkScalar y); | 172 SkScalar y); |
164 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int
run, GrColor, | 173 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int
run, GrColor, |
165 uint8_t paintAlpha); | 174 uint8_t paintAlpha); |
166 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, | 175 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, |
167 const GrPaint& grPaint, const GrClip& clip); | 176 const GrPaint& grPaint, const GrClip& clip); |
(...skipping 15 matching lines...) Expand all Loading... |
183 const SkPoint& offset, const SkIRect& clipRect); | 192 const SkPoint& offset, const SkIRect& clipRect); |
184 | 193 |
185 // sets up the descriptor on the blob and returns a detached cache. Client
must attach | 194 // sets up the descriptor on the blob and returns a detached cache. Client
must attach |
186 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); | 195 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); |
187 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, | 196 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, |
188 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); | 197 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); |
189 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, | 198 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, |
190 const SkTextBlob* blob, SkScalar x, SkScalar y, | 199 const SkTextBlob* blob, SkScalar x, SkScalar y, |
191 SkDrawFilter* drawFilter, const SkIRect& clipRect); | 200 SkDrawFilter* drawFilter, const SkIRect& clipRect); |
192 | 201 |
193 // TODO this currently only uses the public interface of SkTextBlob, however
, I may need to add | 202 GrBatchTextStrike* fCurrStrike; |
194 // functionality to it while looping over the runs so I'm putting this here
for the time being. | 203 GrTextBlobCache* fCache; |
195 // If this lands in Chrome without changes, move it to SkTextBlob. | |
196 static inline void BlobGlyphCount(int* glyphCount, int* runCount, const SkTe
xtBlob*); | |
197 | 204 |
198 GrBatchTextStrike* fCurrStrike; | 205 friend class GrTextBlobCache; |
199 | |
200 // TODO use real cache | |
201 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); | |
202 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; | |
203 | |
204 friend class BitmapTextBatch; | 206 friend class BitmapTextBatch; |
205 | 207 |
206 typedef GrTextContext INHERITED; | 208 typedef GrTextContext INHERITED; |
207 }; | 209 }; |
208 | 210 |
209 #endif | 211 #endif |
OLD | NEW |