| 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 "GrMemoryPool.h" |
| 17 #include "SkMaskFilter.h" |
| 17 #include "SkTextBlob.h" | 18 #include "SkTextBlob.h" |
| 18 #include "SkTInternalLList.h" | 19 #include "SkTInternalLList.h" |
| 19 | 20 |
| 20 class GrBatchTextStrike; | 21 class GrBatchTextStrike; |
| 21 class GrPipelineBuilder; | 22 class GrPipelineBuilder; |
| 22 class GrTextBlobCache; | 23 class GrTextBlobCache; |
| 23 | 24 |
| 24 /* | 25 /* |
| 25 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. | 26 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. |
| 26 * TODO replace GrBitmapTextContext | 27 * TODO replace GrBitmapTextContext |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 * Finally, for runs where the entire thing is too large for the GrAtlas
TextContext to | 78 * Finally, for runs where the entire thing is too large for the GrAtlas
TextContext to |
| 78 * handle, we have a bit to mark the run as flusahable via rendering as
paths. It is worth | 79 * handle, we have a bit to mark the run as flusahable via rendering as
paths. It is worth |
| 79 * pointing. It would be a bit expensive to figure out ahead of time whe
ther or not a run | 80 * pointing. It would be a bit expensive to figure out ahead of time whe
ther or not a run |
| 80 * can flush in this manner, so we always allocate vertices for the run,
regardless of | 81 * can flush in this manner, so we always allocate vertices for the run,
regardless of |
| 81 * whether or not it is too large. The benefit of this strategy is that
we can always reuse | 82 * whether or not it is too large. The benefit of this strategy is that
we can always reuse |
| 82 * a blob allocation regardless of viewmatrix changes. We could store p
ositions for these | 83 * a blob allocation regardless of viewmatrix changes. We could store p
ositions for these |
| 83 * glyphs. However, its not clear if this is a win because we'd still h
ave to either go the | 84 * glyphs. However, its not clear if this is a win because we'd still h
ave to either go the |
| 84 * glyph cache to get the path at flush time, or hold onto the path in t
he cache, which | 85 * glyph cache to get the path at flush time, or hold onto the path in t
he cache, which |
| 85 * would greatly increase the memory of these cached items. | 86 * would greatly increase the memory of these cached items. |
| 86 */ | 87 */ |
| 87 | |
| 88 struct Run { | 88 struct Run { |
| 89 Run() : fColor(GrColor_ILLEGAL), fInitialized(false), fDrawAsPaths(f
alse) { | 89 Run() : fColor(GrColor_ILLEGAL), fInitialized(false), fDrawAsPaths(f
alse) { |
| 90 fVertexBounds.setLargestInverted(); | 90 fVertexBounds.setLargestInverted(); |
| 91 // We insert the first subrun to gurantee a run always has atlea
st one subrun. | 91 // We insert the first subrun to gurantee a run always has atlea
st one subrun. |
| 92 // We do this to simplify things when we 'hand off' data from on
e subrun to the | 92 // We do this to simplify things when we 'hand off' data from on
e subrun to the |
| 93 // next | 93 // next |
| 94 fSubRunInfo.push_back(); | 94 fSubRunInfo.push_back(); |
| 95 } | 95 } |
| 96 struct SubRunInfo { | 96 struct SubRunInfo { |
| 97 SubRunInfo() | 97 SubRunInfo() |
| (...skipping 27 matching lines...) Expand all Loading... |
| 125 }; | 125 }; |
| 126 #ifdef SK_DEBUG | 126 #ifdef SK_DEBUG |
| 127 mutable SkScalar fTotalXError; | 127 mutable SkScalar fTotalXError; |
| 128 mutable SkScalar fTotalYError; | 128 mutable SkScalar fTotalYError; |
| 129 #endif | 129 #endif |
| 130 SkTArray<BigGlyph> fBigGlyphs; | 130 SkTArray<BigGlyph> fBigGlyphs; |
| 131 GrColor fColor; // the original color on the paint | 131 GrColor fColor; // the original color on the paint |
| 132 SkMatrix fViewMatrix; | 132 SkMatrix fViewMatrix; |
| 133 SkScalar fX; | 133 SkScalar fX; |
| 134 SkScalar fY; | 134 SkScalar fY; |
| 135 SkPaint::Style fStyle; | |
| 136 int fRunCount; | 135 int fRunCount; |
| 137 uint32_t fUniqueID; | 136 SkMaskFilter::BlurRec fBlurRec; |
| 137 struct StrokeInfo { |
| 138 SkScalar fFrameWidth; |
| 139 SkScalar fMiterLimit; |
| 140 SkPaint::Join fJoin; |
| 141 }; |
| 142 StrokeInfo fStrokeInfo; |
| 138 GrMemoryPool* fPool; | 143 GrMemoryPool* fPool; |
| 139 | 144 |
| 140 // all glyph / vertex offsets are into these pools. | 145 // all glyph / vertex offsets are into these pools. |
| 141 unsigned char* fVertices; | 146 unsigned char* fVertices; |
| 142 GrGlyph::PackedID* fGlyphIDs; | 147 GrGlyph::PackedID* fGlyphIDs; |
| 143 Run* fRuns; | 148 Run* fRuns; |
| 144 | 149 |
| 145 static const uint32_t& GetKey(const BitmapTextBlob& blob) { | 150 struct Key { |
| 146 return blob.fUniqueID; | 151 Key() { |
| 152 memset(this, 0, sizeof(Key)); |
| 153 } |
| 154 uint32_t fUniqueID; |
| 155 SkPaint::Style fStyle; |
| 156 bool fHasBlur; |
| 157 |
| 158 bool operator==(const Key& other) const { |
| 159 return 0 == memcmp(this, &other, sizeof(Key)); |
| 160 } |
| 161 }; |
| 162 Key fKey; |
| 163 |
| 164 static const Key& GetKey(const BitmapTextBlob& blob) { |
| 165 return blob.fKey; |
| 147 } | 166 } |
| 148 | 167 |
| 149 static uint32_t Hash(const uint32_t& key) { | 168 static uint32_t Hash(const Key& key) { |
| 150 return SkChecksum::Mix(key); | 169 return SkChecksum::Murmur3(&key, sizeof(Key)); |
| 151 } | 170 } |
| 152 | 171 |
| 153 void operator delete(void* p) { | 172 void operator delete(void* p) { |
| 154 BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); | 173 BitmapTextBlob* blob = reinterpret_cast<BitmapTextBlob*>(p); |
| 155 blob->fPool->release(p); | 174 blob->fPool->release(p); |
| 156 } | 175 } |
| 157 void* operator new(size_t) { | 176 void* operator new(size_t) { |
| 158 SkFAIL("All blobs are created by placement new."); | 177 SkFAIL("All blobs are created by placement new."); |
| 159 return sk_malloc_throw(0); | 178 return sk_malloc_throw(0); |
| 160 } | 179 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const
SkPaint&, | 212 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const
SkPaint&, |
| 194 const SkMatrix& viewMatrix, | 213 const SkMatrix& viewMatrix, |
| 195 const char text[], size_t byteLength, | 214 const char text[], size_t byteLength, |
| 196 const SkScalar pos[], int scalarsPerPosition, | 215 const SkScalar pos[], int scalarsPerPosition, |
| 197 const SkPoint& offset, const SkIRect& clipRect); | 216 const SkPoint& offset, const SkIRect& clipRect); |
| 198 | 217 |
| 199 // sets up the descriptor on the blob and returns a detached cache. Client
must attach | 218 // sets up the descriptor on the blob and returns a detached cache. Client
must attach |
| 200 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); | 219 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa
trix); |
| 201 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran
sY, | 220 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran
sY, |
| 202 const BitmapTextBlob&, const SkPaint&, | 221 const BitmapTextBlob&, const SkPaint&, |
| 222 const SkMaskFilter::BlurRec&, |
| 203 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); | 223 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); |
| 204 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, | 224 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S
kMatrix& viewMatrix, |
| 205 const SkTextBlob* blob, SkScalar x, SkScalar y, | 225 const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 206 SkDrawFilter* drawFilter, const SkIRect& clipRect); | 226 SkDrawFilter* drawFilter, const SkIRect& clipRect); |
| 207 | 227 |
| 208 GrBatchTextStrike* fCurrStrike; | 228 GrBatchTextStrike* fCurrStrike; |
| 209 GrTextBlobCache* fCache; | 229 GrTextBlobCache* fCache; |
| 210 | 230 |
| 211 friend class GrTextBlobCache; | 231 friend class GrTextBlobCache; |
| 212 friend class BitmapTextBatch; | 232 friend class BitmapTextBatch; |
| 213 | 233 |
| 214 typedef GrTextContext INHERITED; | 234 typedef GrTextContext INHERITED; |
| 215 }; | 235 }; |
| 216 | 236 |
| 217 #endif | 237 #endif |
| OLD | NEW |