| 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 #include "GrAtlasTextContext.h" | 7 #include "GrAtlasTextContext.h" |
| 8 | 8 |
| 9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // TODO | 61 // TODO |
| 62 // More tests | 62 // More tests |
| 63 // move to SkCache | 63 // move to SkCache |
| 64 // handle textblobs where the whole run is larger than the cache size | 64 // handle textblobs where the whole run is larger than the cache size |
| 65 // TODO implement micro speedy hash map for fast refing of glyphs | 65 // TODO implement micro speedy hash map for fast refing of glyphs |
| 66 | 66 |
| 67 GrBitmapTextContextB::GrBitmapTextContextB(GrContext* context, | 67 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, |
| 68 SkGpuDevice* gpuDevice, | 68 SkGpuDevice* gpuDevice, |
| 69 const SkDeviceProperties& properties) | 69 const SkDeviceProperties& properties) |
| 70 : INHERITED(context, gpuDevice, propertie
s) { | 70 : INHERITED(context, gpuDevice, propertie
s) { |
| 71 fCurrStrike = NULL; | 71 fCurrStrike = NULL; |
| 72 } | 72 } |
| 73 | 73 |
| 74 void GrBitmapTextContextB::ClearCacheEntry(uint32_t key, BitmapTextBlob** blob)
{ | 74 void GrAtlasTextContext::ClearCacheEntry(uint32_t key, BitmapTextBlob** blob) { |
| 75 (*blob)->unref(); | 75 (*blob)->unref(); |
| 76 } | 76 } |
| 77 | 77 |
| 78 GrBitmapTextContextB::~GrBitmapTextContextB() { | 78 GrAtlasTextContext::~GrAtlasTextContext() { |
| 79 fCache.foreach(&GrBitmapTextContextB::ClearCacheEntry); | 79 fCache.foreach(&GrAtlasTextContext::ClearCacheEntry); |
| 80 } | 80 } |
| 81 | 81 |
| 82 GrBitmapTextContextB* GrBitmapTextContextB::Create(GrContext* context, | 82 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
| 83 SkGpuDevice* gpuDevice, | 83 SkGpuDevice* gpuDevice, |
| 84 const SkDeviceProperties& props
) { | 84 const SkDeviceProperties& props)
{ |
| 85 return SkNEW_ARGS(GrBitmapTextContextB, (context, gpuDevice, props)); | 85 return SkNEW_ARGS(GrAtlasTextContext, (context, gpuDevice, props)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool GrBitmapTextContextB::canDraw(const GrRenderTarget*, | 88 bool GrAtlasTextContext::canDraw(const GrRenderTarget*, |
| 89 const GrClip&, | 89 const GrClip&, |
| 90 const GrPaint&, | 90 const GrPaint&, |
| 91 const SkPaint& skPaint, | 91 const SkPaint& skPaint, |
| 92 const SkMatrix& viewMatrix) { | 92 const SkMatrix& viewMatrix) { |
| 93 return !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); | 93 return !SkDraw::ShouldDrawTextAsPaths(skPaint, viewMatrix); |
| 94 } | 94 } |
| 95 | 95 |
| 96 inline void GrBitmapTextContextB::init(GrRenderTarget* rt, const GrClip& clip, | 96 inline void GrAtlasTextContext::init(GrRenderTarget* rt, const GrClip& clip, |
| 97 const GrPaint& paint, const SkPaint& skPai
nt, | 97 const GrPaint& paint, const SkPaint& skPain
t, |
| 98 const SkIRect& regionClipBounds) { | 98 const SkIRect& regionClipBounds) { |
| 99 INHERITED::init(rt, clip, paint, skPaint, regionClipBounds); | 99 INHERITED::init(rt, clip, paint, skPaint, regionClipBounds); |
| 100 | 100 |
| 101 fCurrStrike = NULL; | 101 fCurrStrike = NULL; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool GrBitmapTextContextB::MustRegenerateBlob(const BitmapTextBlob& blob, const
SkPaint& paint, | 104 bool GrAtlasTextContext::MustRegenerateBlob(const BitmapTextBlob& blob, const Sk
Paint& paint, |
| 105 const SkMatrix& viewMatrix, SkScala
r x, SkScalar y) { | 105 const SkMatrix& viewMatrix, SkScalar
x, SkScalar y) { |
| 106 // We always regenerate blobs with patheffects or mask filters we could cach
e these | 106 // We always regenerate blobs with patheffects or mask filters we could cach
e these |
| 107 // TODO find some way to cache the maskfilter / patheffects on the textblob | 107 // TODO find some way to cache the maskfilter / patheffects on the textblob |
| 108 return !blob.fViewMatrix.cheapEqualTo(viewMatrix) || blob.fX != x || blob.fY
!= y || | 108 return !blob.fViewMatrix.cheapEqualTo(viewMatrix) || blob.fX != x || blob.fY
!= y || |
| 109 paint.getMaskFilter() || paint.getPathEffect() || paint.getStyle() !
= blob.fStyle; | 109 paint.getMaskFilter() || paint.getPathEffect() || paint.getStyle() !
= blob.fStyle; |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 inline SkGlyphCache* GrBitmapTextContextB::setupCache(BitmapTextBlob::Run* run, | 113 inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run, |
| 114 const SkPaint& skPaint, | 114 const SkPaint& skPaint, |
| 115 const SkMatrix& viewMatrix
) { | 115 const SkMatrix& viewMatrix)
{ |
| 116 skPaint.getScalerContextDescriptor(&run->fDescriptor, &fDeviceProperties, &v
iewMatrix, false); | 116 skPaint.getScalerContextDescriptor(&run->fDescriptor, &fDeviceProperties, &v
iewMatrix, false); |
| 117 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); | 117 run->fTypeface.reset(SkSafeRef(skPaint.getTypeface())); |
| 118 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; | 118 return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc())
; |
| 119 } | 119 } |
| 120 | 120 |
| 121 inline void GrBitmapTextContextB::BlobGlyphCount(int* glyphCount, int* runCount, | 121 inline void GrAtlasTextContext::BlobGlyphCount(int* glyphCount, int* runCount, |
| 122 const SkTextBlob* blob) { | 122 const SkTextBlob* blob) { |
| 123 SkTextBlob::RunIterator itCounter(blob); | 123 SkTextBlob::RunIterator itCounter(blob); |
| 124 for (; !itCounter.done(); itCounter.next(), (*runCount)++) { | 124 for (; !itCounter.done(); itCounter.next(), (*runCount)++) { |
| 125 *glyphCount += itCounter.glyphCount(); | 125 *glyphCount += itCounter.glyphCount(); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 GrBitmapTextContextB::BitmapTextBlob* GrBitmapTextContextB::CreateBlob(int glyph
Count, | 129 GrAtlasTextContext::BitmapTextBlob* GrAtlasTextContext::CreateBlob(int glyphCoun
t, |
| 130 int runCo
unt) { | 130 int runCount)
{ |
| 131 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, | 131 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, |
| 132 // and size for the glyphIds array. | 132 // and size for the glyphIds array. |
| 133 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, | 133 SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >=
kLCDTextVASize, |
| 134 vertex_attribute_changed); | 134 vertex_attribute_changed); |
| 135 size_t verticesCount = glyphCount * kVerticesPerGlyph * kGrayTextVASize; | 135 size_t verticesCount = glyphCount * kVerticesPerGlyph * kGrayTextVASize; |
| 136 size_t length = sizeof(BitmapTextBlob) + | 136 size_t length = sizeof(BitmapTextBlob) + |
| 137 verticesCount + | 137 verticesCount + |
| 138 glyphCount * sizeof(GrGlyph::PackedID) + | 138 glyphCount * sizeof(GrGlyph::PackedID) + |
| 139 sizeof(BitmapTextBlob::Run) * runCount; | 139 sizeof(BitmapTextBlob::Run) * runCount; |
| 140 | 140 |
| 141 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(sk_malloc_throw(length), BitmapT
extBlob); | 141 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(sk_malloc_throw(length), BitmapT
extBlob); |
| 142 | 142 |
| 143 // setup offsets for vertices / glyphs | 143 // setup offsets for vertices / glyphs |
| 144 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch
ar*>(cacheBlob); | 144 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch
ar*>(cacheBlob); |
| 145 cacheBlob->fGlyphIDs = | 145 cacheBlob->fGlyphIDs = |
| 146 reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + vertices
Count); | 146 reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + vertices
Count); |
| 147 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphI
Ds + glyphCount); | 147 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphI
Ds + glyphCount); |
| 148 | 148 |
| 149 // Initialize runs | 149 // Initialize runs |
| 150 for (int i = 0; i < runCount; i++) { | 150 for (int i = 0; i < runCount; i++) { |
| 151 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run); | 151 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run); |
| 152 } | 152 } |
| 153 cacheBlob->fRunCount = runCount; | 153 cacheBlob->fRunCount = runCount; |
| 154 return cacheBlob; | 154 return cacheBlob; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void GrBitmapTextContextB::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, | 157 void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip, |
| 158 const SkPaint& skPaint, const SkMatrix&
viewMatrix, | 158 const SkPaint& skPaint, const SkMatrix& vi
ewMatrix, |
| 159 const SkTextBlob* blob, SkScalar x, SkSc
alar y, | 159 const SkTextBlob* blob, SkScalar x, SkScal
ar y, |
| 160 SkDrawFilter* drawFilter, const SkIRect&
clipBounds) { | 160 SkDrawFilter* drawFilter, const SkIRect& c
lipBounds) { |
| 161 BitmapTextBlob* cacheBlob; | 161 BitmapTextBlob* cacheBlob; |
| 162 BitmapTextBlob** foundBlob = fCache.find(blob->uniqueID()); | 162 BitmapTextBlob** foundBlob = fCache.find(blob->uniqueID()); |
| 163 SkIRect clipRect; | 163 SkIRect clipRect; |
| 164 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 164 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 165 | 165 |
| 166 if (foundBlob) { | 166 if (foundBlob) { |
| 167 cacheBlob = *foundBlob; | 167 cacheBlob = *foundBlob; |
| 168 if (MustRegenerateBlob(*cacheBlob, skPaint, viewMatrix, x, y)) { | 168 if (MustRegenerateBlob(*cacheBlob, skPaint, viewMatrix, x, y)) { |
| 169 // We have to remake the blob because changes may invalidate our mas
ks. | 169 // We have to remake the blob because changes may invalidate our mas
ks. |
| 170 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 170 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 189 | 189 |
| 190 // Though for the time being runs in the textblob can override the paint, th
ey only touch font | 190 // Though for the time being runs in the textblob can override the paint, th
ey only touch font |
| 191 // info. | 191 // info. |
| 192 GrPaint grPaint; | 192 GrPaint grPaint; |
| 193 SkPaint2GrPaintShader(fContext, rt, skPaint, viewMatrix, true, &grPaint); | 193 SkPaint2GrPaintShader(fContext, rt, skPaint, viewMatrix, true, &grPaint); |
| 194 | 194 |
| 195 this->flush(fContext->getTextTarget(), cacheBlob, rt, grPaint, clip, viewMat
rix, | 195 this->flush(fContext->getTextTarget(), cacheBlob, rt, grPaint, clip, viewMat
rix, |
| 196 fSkPaint.getAlpha()); | 196 fSkPaint.getAlpha()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void GrBitmapTextContextB::regenerateTextBlob(BitmapTextBlob* cacheBlob, | 199 void GrAtlasTextContext::regenerateTextBlob(BitmapTextBlob* cacheBlob, |
| 200 const SkPaint& skPaint, const SkMa
trix& viewMatrix, | 200 const SkPaint& skPaint, const SkMatr
ix& viewMatrix, |
| 201 const SkTextBlob* blob, SkScalar x
, SkScalar y, | 201 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
| 202 SkDrawFilter* drawFilter, const Sk
IRect& clipRect) { | 202 SkDrawFilter* drawFilter, const SkIR
ect& clipRect) { |
| 203 cacheBlob->fViewMatrix = viewMatrix; | 203 cacheBlob->fViewMatrix = viewMatrix; |
| 204 cacheBlob->fX = x; | 204 cacheBlob->fX = x; |
| 205 cacheBlob->fY = y; | 205 cacheBlob->fY = y; |
| 206 cacheBlob->fStyle = skPaint.getStyle(); | 206 cacheBlob->fStyle = skPaint.getStyle(); |
| 207 | 207 |
| 208 // Regenerate textblob | 208 // Regenerate textblob |
| 209 SkPaint runPaint = skPaint; | 209 SkPaint runPaint = skPaint; |
| 210 SkTextBlob::RunIterator it(blob); | 210 SkTextBlob::RunIterator it(blob); |
| 211 for (int run = 0; !it.done(); it.next(), run++) { | 211 for (int run = 0; !it.done(); it.next(), run++) { |
| 212 int glyphCount = it.glyphCount(); | 212 int glyphCount = it.glyphCount(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 258 |
| 259 if (drawFilter) { | 259 if (drawFilter) { |
| 260 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. | 260 // A draw filter may change the paint arbitrarily, so we must re-see
d in this case. |
| 261 runPaint = skPaint; | 261 runPaint = skPaint; |
| 262 } | 262 } |
| 263 | 263 |
| 264 SkGlyphCache::AttachCache(cache); | 264 SkGlyphCache::AttachCache(cache); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void GrBitmapTextContextB::onDrawText(GrRenderTarget* rt, const GrClip& clip, | 268 void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip, |
| 269 const GrPaint& paint, const SkPaint& skPain
t, | 269 const GrPaint& paint, const SkPaint& skPaint
, |
| 270 const SkMatrix& viewMatrix, | 270 const SkMatrix& viewMatrix, |
| 271 const char text[], size_t byteLength, | 271 const char text[], size_t byteLength, |
| 272 SkScalar x, SkScalar y, const SkIRect& regi
onClipBounds) { | 272 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { |
| 273 int glyphCount = skPaint.countText(text, byteLength); | 273 int glyphCount = skPaint.countText(text, byteLength); |
| 274 SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1)); | 274 SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1)); |
| 275 blob->fViewMatrix = viewMatrix; | 275 blob->fViewMatrix = viewMatrix; |
| 276 blob->fX = x; | 276 blob->fX = x; |
| 277 blob->fY = y; | 277 blob->fY = y; |
| 278 blob->fStyle = skPaint.getStyle(); | 278 blob->fStyle = skPaint.getStyle(); |
| 279 | 279 |
| 280 SkIRect clipRect; | 280 SkIRect clipRect; |
| 281 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 281 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 282 | 282 |
| 283 // setup cache | 283 // setup cache |
| 284 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; | 284 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; |
| 285 this->internalDrawText(blob, 0, cache, skPaint, viewMatrix, text, byteLength
, x, y, clipRect); | 285 this->internalDrawText(blob, 0, cache, skPaint, viewMatrix, text, byteLength
, x, y, clipRect); |
| 286 SkGlyphCache::AttachCache(cache); | 286 SkGlyphCache::AttachCache(cache); |
| 287 | 287 |
| 288 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, sk
Paint.getAlpha()); | 288 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, sk
Paint.getAlpha()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void GrBitmapTextContextB::internalDrawText(BitmapTextBlob* blob, int runIndex, | 291 void GrAtlasTextContext::internalDrawText(BitmapTextBlob* blob, int runIndex, |
| 292 SkGlyphCache* cache, const SkPaint&
skPaint, | 292 SkGlyphCache* cache, const SkPaint& sk
Paint, |
| 293 const SkMatrix& viewMatrix, | 293 const SkMatrix& viewMatrix, |
| 294 const char text[], size_t byteLength, | 294 const char text[], size_t byteLength, |
| 295 SkScalar x, SkScalar y, const SkIRect
& clipRect) { | 295 SkScalar x, SkScalar y, const SkIRect&
clipRect) { |
| 296 SkASSERT(byteLength == 0 || text != NULL); | 296 SkASSERT(byteLength == 0 || text != NULL); |
| 297 | 297 |
| 298 // nothing to draw | 298 // nothing to draw |
| 299 if (text == NULL || byteLength == 0) { | 299 if (text == NULL || byteLength == 0) { |
| 300 return; | 300 return; |
| 301 } | 301 } |
| 302 | 302 |
| 303 fCurrStrike = NULL; | 303 fCurrStrike = NULL; |
| 304 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); | 304 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| 305 | 305 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 Sk48Dot16FloorToInt(fy), | 370 Sk48Dot16FloorToInt(fy), |
| 371 fontScaler, | 371 fontScaler, |
| 372 clipRect); | 372 clipRect); |
| 373 } | 373 } |
| 374 | 374 |
| 375 fx += glyph.fAdvanceX; | 375 fx += glyph.fAdvanceX; |
| 376 fy += glyph.fAdvanceY; | 376 fy += glyph.fAdvanceY; |
| 377 } | 377 } |
| 378 } | 378 } |
| 379 | 379 |
| 380 void GrBitmapTextContextB::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, | 380 void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip, |
| 381 const GrPaint& paint, const SkPaint& skP
aint, | 381 const GrPaint& paint, const SkPaint& skPa
int, |
| 382 const SkMatrix& viewMatrix, | 382 const SkMatrix& viewMatrix, |
| 383 const char text[], size_t byteLength, | 383 const char text[], size_t byteLength, |
| 384 const SkScalar pos[], int scalarsPerPosi
tion, | 384 const SkScalar pos[], int scalarsPerPosit
ion, |
| 385 const SkPoint& offset, const SkIRect& re
gionClipBounds) { | 385 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { |
| 386 int glyphCount = skPaint.countText(text, byteLength); | 386 int glyphCount = skPaint.countText(text, byteLength); |
| 387 SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1)); | 387 SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1)); |
| 388 blob->fStyle = skPaint.getStyle(); | 388 blob->fStyle = skPaint.getStyle(); |
| 389 blob->fViewMatrix = viewMatrix; | 389 blob->fViewMatrix = viewMatrix; |
| 390 | 390 |
| 391 SkIRect clipRect; | 391 SkIRect clipRect; |
| 392 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); | 392 clip.getConservativeBounds(rt->width(), rt->height(), &clipRect); |
| 393 | 393 |
| 394 // setup cache | 394 // setup cache |
| 395 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; | 395 SkGlyphCache* cache = this->setupCache(&blob->fRuns[0], skPaint, viewMatrix)
; |
| 396 this->internalDrawPosText(blob, 0, cache, skPaint, viewMatrix, text, byteLen
gth, pos, | 396 this->internalDrawPosText(blob, 0, cache, skPaint, viewMatrix, text, byteLen
gth, pos, |
| 397 scalarsPerPosition, offset, clipRect); | 397 scalarsPerPosition, offset, clipRect); |
| 398 SkGlyphCache::AttachCache(cache); | 398 SkGlyphCache::AttachCache(cache); |
| 399 | 399 |
| 400 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, fS
kPaint.getAlpha()); | 400 this->flush(fContext->getTextTarget(), blob, rt, paint, clip, viewMatrix, fS
kPaint.getAlpha()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 void GrBitmapTextContextB::internalDrawPosText(BitmapTextBlob* blob, int runInde
x, | 403 void GrAtlasTextContext::internalDrawPosText(BitmapTextBlob* blob, int runIndex, |
| 404 SkGlyphCache* cache, const SkPain
t& skPaint, | 404 SkGlyphCache* cache, const SkPaint&
skPaint, |
| 405 const SkMatrix& viewMatrix, | 405 const SkMatrix& viewMatrix, |
| 406 const char text[], size_t byteLeng
th, | 406 const char text[], size_t byteLengt
h, |
| 407 const SkScalar pos[], int scalarsP
erPosition, | 407 const SkScalar pos[], int scalarsPe
rPosition, |
| 408 const SkPoint& offset, const SkIRe
ct& clipRect) { | 408 const SkPoint& offset, const SkIRec
t& clipRect) { |
| 409 SkASSERT(byteLength == 0 || text != NULL); | 409 SkASSERT(byteLength == 0 || text != NULL); |
| 410 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 410 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 411 | 411 |
| 412 // nothing to draw | 412 // nothing to draw |
| 413 if (text == NULL || byteLength == 0) { | 413 if (text == NULL || byteLength == 0) { |
| 414 return; | 414 return; |
| 415 } | 415 } |
| 416 | 416 |
| 417 fCurrStrike = NULL; | 417 fCurrStrike = NULL; |
| 418 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); | 418 SkDrawCacheProc glyphCacheProc = skPaint.getDrawCacheProc(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 Sk48Dot16FloorToInt(fy), | 551 Sk48Dot16FloorToInt(fy), |
| 552 fontScaler, | 552 fontScaler, |
| 553 clipRect); | 553 clipRect); |
| 554 } | 554 } |
| 555 pos += scalarsPerPosition; | 555 pos += scalarsPerPosition; |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 void GrBitmapTextContextB::appendGlyph(BitmapTextBlob* blob, int runIndex, GrGly
ph::PackedID packed, | 561 void GrAtlasTextContext::appendGlyph(BitmapTextBlob* blob, int runIndex, GrGlyph
::PackedID packed, |
| 562 int vx, int vy, GrFontScaler* scaler, | 562 int vx, int vy, GrFontScaler* scaler, |
| 563 const SkIRect& clipRect) { | 563 const SkIRect& clipRect) { |
| 564 if (NULL == fCurrStrike) { | 564 if (NULL == fCurrStrike) { |
| 565 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); | 565 fCurrStrike = fContext->getBatchFontCache()->getStrike(scaler); |
| 566 } | 566 } |
| 567 | 567 |
| 568 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); | 568 GrGlyph* glyph = fCurrStrike->getGlyph(packed, scaler); |
| 569 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 569 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| 570 return; | 570 return; |
| 571 } | 571 } |
| 572 | 572 |
| 573 int x = vx + glyph->fBounds.fLeft; | 573 int x = vx + glyph->fBounds.fLeft; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint))
; | 666 SkColor* colorPtr = reinterpret_cast<SkColor*>(vertex + sizeof(SkPoint))
; |
| 667 *colorPtr = color; | 667 *colorPtr = color; |
| 668 } | 668 } |
| 669 | 669 |
| 670 subRun->fGlyphEndIndex++; | 670 subRun->fGlyphEndIndex++; |
| 671 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; | 671 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; |
| 672 } | 672 } |
| 673 | 673 |
| 674 class BitmapTextBatch : public GrBatch { | 674 class BitmapTextBatch : public GrBatch { |
| 675 public: | 675 public: |
| 676 typedef GrBitmapTextContextB::BitmapTextBlob Blob; | 676 typedef GrAtlasTextContext::BitmapTextBlob Blob; |
| 677 typedef Blob::Run Run; | 677 typedef Blob::Run Run; |
| 678 typedef Run::SubRunInfo TextInfo; | 678 typedef Run::SubRunInfo TextInfo; |
| 679 struct Geometry { | 679 struct Geometry { |
| 680 Geometry() {} | 680 Geometry() {} |
| 681 Geometry(const Geometry& geometry) | 681 Geometry(const Geometry& geometry) |
| 682 : fBlob(SkRef(geometry.fBlob.get())) | 682 : fBlob(SkRef(geometry.fBlob.get())) |
| 683 , fRun(geometry.fRun) | 683 , fRun(geometry.fRun) |
| 684 , fSubRun(geometry.fSubRun) | 684 , fSubRun(geometry.fSubRun) |
| 685 , fColor(geometry.fColor) {} | 685 , fColor(geometry.fColor) {} |
| 686 SkAutoTUnref<Blob> fBlob; | 686 SkAutoTUnref<Blob> fBlob; |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 int fNumGlyphs; | 1002 int fNumGlyphs; |
| 1003 }; | 1003 }; |
| 1004 | 1004 |
| 1005 BatchTracker fBatch; | 1005 BatchTracker fBatch; |
| 1006 SkSTArray<1, Geometry, true> fGeoData; | 1006 SkSTArray<1, Geometry, true> fGeoData; |
| 1007 GrMaskFormat fMaskFormat; | 1007 GrMaskFormat fMaskFormat; |
| 1008 GrPixelConfig fPixelConfig; | 1008 GrPixelConfig fPixelConfig; |
| 1009 GrBatchFontCache* fFontCache; | 1009 GrBatchFontCache* fFontCache; |
| 1010 }; | 1010 }; |
| 1011 | 1011 |
| 1012 void GrBitmapTextContextB::flush(GrDrawTarget* target, BitmapTextBlob* blob, GrR
enderTarget* rt, | 1012 void GrAtlasTextContext::flush(GrDrawTarget* target, BitmapTextBlob* blob, GrRen
derTarget* rt, |
| 1013 const GrPaint& paint, const GrClip& clip, | 1013 const GrPaint& paint, const GrClip& clip, |
| 1014 const SkMatrix& viewMatrix, int paintAlpha) { | 1014 const SkMatrix& viewMatrix, int paintAlpha) { |
| 1015 GrPipelineBuilder pipelineBuilder; | 1015 GrPipelineBuilder pipelineBuilder; |
| 1016 pipelineBuilder.setFromPaint(paint, rt, clip); | 1016 pipelineBuilder.setFromPaint(paint, rt, clip); |
| 1017 | 1017 |
| 1018 GrColor color = paint.getColor(); | 1018 GrColor color = paint.getColor(); |
| 1019 for (uint32_t run = 0; run < blob->fRunCount; run++) { | 1019 for (uint32_t run = 0; run < blob->fRunCount; run++) { |
| 1020 for (int subRun = 0; subRun < blob->fRuns[run].fSubRunInfo.count(); subR
un++) { | 1020 for (int subRun = 0; subRun < blob->fRuns[run].fSubRunInfo.count(); subR
un++) { |
| 1021 PerSubRunInfo& info = blob->fRuns[run].fSubRunInfo[subRun]; | 1021 PerSubRunInfo& info = blob->fRuns[run].fSubRunInfo[subRun]; |
| 1022 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 1022 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
| 1023 if (0 == glyphCount) { | 1023 if (0 == glyphCount) { |
| 1024 continue; | 1024 continue; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1045 for (int i = 0; i < blob->fBigGlyphs.count(); i++) { | 1045 for (int i = 0; i < blob->fBigGlyphs.count(); i++) { |
| 1046 BitmapTextBlob::BigGlyph& bigGlyph = blob->fBigGlyphs[i]; | 1046 BitmapTextBlob::BigGlyph& bigGlyph = blob->fBigGlyphs[i]; |
| 1047 SkMatrix translate; | 1047 SkMatrix translate; |
| 1048 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly
ph.fVy)); | 1048 translate.setTranslate(SkIntToScalar(bigGlyph.fVx), SkIntToScalar(bigGly
ph.fVy)); |
| 1049 SkPath tmpPath(bigGlyph.fPath); | 1049 SkPath tmpPath(bigGlyph.fPath); |
| 1050 tmpPath.transform(translate); | 1050 tmpPath.transform(translate); |
| 1051 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 1051 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
| 1052 fContext->drawPath(rt, clip, paint, SkMatrix::I(), tmpPath, strokeInfo); | 1052 fContext->drawPath(rt, clip, paint, SkMatrix::I(), tmpPath, strokeInfo); |
| 1053 } | 1053 } |
| 1054 } | 1054 } |
| OLD | NEW |