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 "GrDrawContext.h" | 9 #include "GrDrawContext.h" |
10 #include "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ComputeCanonicalColor(skPaint, hasLCD)
; | 102 ComputeCanonicalColor(skPaint, hasLCD)
; |
103 | 103 |
104 key.fPixelGeometry = pixelGeometry; | 104 key.fPixelGeometry = pixelGeometry; |
105 key.fUniqueID = blob->uniqueID(); | 105 key.fUniqueID = blob->uniqueID(); |
106 key.fStyle = skPaint.getStyle(); | 106 key.fStyle = skPaint.getStyle(); |
107 key.fHasBlur = SkToBool(mf); | 107 key.fHasBlur = SkToBool(mf); |
108 key.fCanonicalColor = canonicalColor; | 108 key.fCanonicalColor = canonicalColor; |
109 cacheBlob.reset(SkSafeRef(cache->find(key))); | 109 cacheBlob.reset(SkSafeRef(cache->find(key))); |
110 } | 110 } |
111 | 111 |
112 SkScalar transX = 0.f; | |
113 SkScalar transY = 0.f; | |
114 | |
115 // Though for the time being runs in the textblob can override the paint, th
ey only touch font | 112 // Though for the time being runs in the textblob can override the paint, th
ey only touch font |
116 // info. | 113 // info. |
117 GrPaint grPaint; | 114 GrPaint grPaint; |
118 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) { | 115 if (!SkPaintToGrPaint(context, skPaint, viewMatrix, &grPaint)) { |
119 return; | 116 return; |
120 } | 117 } |
121 | 118 |
122 if (cacheBlob) { | 119 if (cacheBlob) { |
123 if (cacheBlob->mustRegenerate(&transX, &transY, skPaint, grPaint.getColo
r(), blurRec, | 120 if (cacheBlob->mustRegenerate(skPaint, grPaint.getColor(), blurRec, view
Matrix, x, y)) { |
124 viewMatrix, x, y)) { | |
125 // We have to remake the blob because changes may invalidate our mas
ks. | 121 // We have to remake the blob because changes may invalidate our mas
ks. |
126 // TODO we could probably get away reuse most of the time if the poi
nter is unique, | 122 // TODO we could probably get away reuse most of the time if the poi
nter is unique, |
127 // but we'd have to clear the subrun information | 123 // but we'd have to clear the subrun information |
128 cache->remove(cacheBlob); | 124 cache->remove(cacheBlob); |
129 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk
Paint))); | 125 cacheBlob.reset(SkRef(cache->createCachedBlob(blob, key, blurRec, sk
Paint))); |
130 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), | 126 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), |
131 *context->caps()->shaderCaps(), skPaint, grPaint.
getColor(), | 127 *context->caps()->shaderCaps(), skPaint, grPaint.
getColor(), |
132 viewMatrix, props, | 128 viewMatrix, props, |
133 blob, x, y, drawFilter); | 129 blob, x, y, drawFilter); |
134 } else { | 130 } else { |
(...skipping 18 matching lines...) Expand all Loading... |
153 } else { | 149 } else { |
154 cacheBlob.reset(cache->createBlob(blob)); | 150 cacheBlob.reset(cache->createBlob(blob)); |
155 } | 151 } |
156 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), | 152 RegenerateTextBlob(cacheBlob, context->getBatchFontCache(), |
157 *context->caps()->shaderCaps(), skPaint, grPaint.getC
olor(), | 153 *context->caps()->shaderCaps(), skPaint, grPaint.getC
olor(), |
158 viewMatrix, props, | 154 viewMatrix, props, |
159 blob, x, y, drawFilter); | 155 blob, x, y, drawFilter); |
160 } | 156 } |
161 | 157 |
162 cacheBlob->flushCached(context, dc, blob, props, fDistanceAdjustTable, skPai
nt, | 158 cacheBlob->flushCached(context, dc, blob, props, fDistanceAdjustTable, skPai
nt, |
163 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y, transX, transY); | 159 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y); |
164 } | 160 } |
165 | 161 |
166 void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob, | 162 void GrAtlasTextContext::RegenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
167 GrBatchFontCache* fontCache, | 163 GrBatchFontCache* fontCache, |
168 const GrShaderCaps& shaderCaps, | 164 const GrShaderCaps& shaderCaps, |
169 const SkPaint& skPaint, GrColor colo
r, | 165 const SkPaint& skPaint, GrColor colo
r, |
170 const SkMatrix& viewMatrix, | 166 const SkMatrix& viewMatrix, |
171 const SkSurfaceProps& props, | 167 const SkSurfaceProps& props, |
172 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 168 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
173 SkDrawFilter* drawFilter) { | 169 SkDrawFilter* drawFilter) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (context->abandoned()) { | 310 if (context->abandoned()) { |
315 return; | 311 return; |
316 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade
rCaps())) { | 312 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade
rCaps())) { |
317 SkAutoTUnref<GrAtlasTextBlob> blob( | 313 SkAutoTUnref<GrAtlasTextBlob> blob( |
318 CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFon
tCache(), | 314 CreateDrawTextBlob(context->getTextBlobCache(), context->getBatchFon
tCache(), |
319 *context->caps()->shaderCaps(), | 315 *context->caps()->shaderCaps(), |
320 paint, skPaint, | 316 paint, skPaint, |
321 viewMatrix, props, | 317 viewMatrix, props, |
322 text, byteLength, x, y)); | 318 text, byteLength, x, y)); |
323 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint,
paint, | 319 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint,
paint, |
324 clip, regionClipBounds); | 320 clip, viewMatrix, regionClipBounds, x, y); |
325 return; | 321 return; |
326 } | 322 } |
327 | 323 |
328 // fall back to drawing as a path | 324 // fall back to drawing as a path |
329 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by
teLength, x, y, | 325 GrTextUtils::DrawTextAsPath(context, dc, clip, skPaint, viewMatrix, text, by
teLength, x, y, |
330 regionClipBounds); | 326 regionClipBounds); |
331 } | 327 } |
332 | 328 |
333 void GrAtlasTextContext::drawPosText(GrContext* context, | 329 void GrAtlasTextContext::drawPosText(GrContext* context, |
334 GrDrawContext* dc, | 330 GrDrawContext* dc, |
335 const GrClip& clip, | 331 const GrClip& clip, |
336 const GrPaint& paint, const SkPaint& skPain
t, | 332 const GrPaint& paint, const SkPaint& skPain
t, |
337 const SkMatrix& viewMatrix, | 333 const SkMatrix& viewMatrix, |
338 const SkSurfaceProps& props, | 334 const SkSurfaceProps& props, |
339 const char text[], size_t byteLength, | 335 const char text[], size_t byteLength, |
340 const SkScalar pos[], int scalarsPerPositio
n, | 336 const SkScalar pos[], int scalarsPerPositio
n, |
341 const SkPoint& offset, const SkIRect& regio
nClipBounds) { | 337 const SkPoint& offset, const SkIRect& regio
nClipBounds) { |
342 if (context->abandoned()) { | 338 if (context->abandoned()) { |
343 return; | 339 return; |
344 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade
rCaps())) { | 340 } else if (this->canDraw(skPaint, viewMatrix, props, *context->caps()->shade
rCaps())) { |
345 SkAutoTUnref<GrAtlasTextBlob> blob( | 341 SkAutoTUnref<GrAtlasTextBlob> blob( |
346 CreateDrawPosTextBlob(context->getTextBlobCache(), | 342 CreateDrawPosTextBlob(context->getTextBlobCache(), |
347 context->getBatchFontCache(), | 343 context->getBatchFontCache(), |
348 *context->caps()->shaderCaps(), | 344 *context->caps()->shaderCaps(), |
349 paint, skPaint, viewMatrix, props, | 345 paint, skPaint, viewMatrix, props, |
350 text, byteLength, | 346 text, byteLength, |
351 pos, scalarsPerPosition, | 347 pos, scalarsPerPosition, |
352 offset)); | 348 offset)); |
353 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint,
paint, | 349 blob->flushThrowaway(context, dc, props, fDistanceAdjustTable, skPaint,
paint, |
354 clip, regionClipBounds); | 350 clip, viewMatrix, regionClipBounds, offset.fX, offs
et.fY); |
355 return; | 351 return; |
356 } | 352 } |
357 | 353 |
358 // fall back to drawing as a path | 354 // fall back to drawing as a path |
359 GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix
, text, | 355 GrTextUtils::DrawPosTextAsPath(context, dc, props, clip, skPaint, viewMatrix
, text, |
360 byteLength, pos, scalarsPerPosition, offset,
regionClipBounds); | 356 byteLength, pos, scalarsPerPosition, offset,
regionClipBounds); |
361 } | 357 } |
362 | 358 |
363 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 359 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
364 | 360 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 SkAutoTUnref<GrAtlasTextBlob> blob( | 397 SkAutoTUnref<GrAtlasTextBlob> blob( |
402 GrAtlasTextContext::CreateDrawTextBlob(context->getTextBlobCache(), | 398 GrAtlasTextContext::CreateDrawTextBlob(context->getTextBlobCache(), |
403 context->getBatchFontCache(), | 399 context->getBatchFontCache(), |
404 *context->caps()->shaderCaps(), g
rPaint, skPaint, | 400 *context->caps()->shaderCaps(), g
rPaint, skPaint, |
405 viewMatrix, | 401 viewMatrix, |
406 gSurfaceProps, text, | 402 gSurfaceProps, text, |
407 static_cast<size_t>(textLen), 0,
0)); | 403 static_cast<size_t>(textLen), 0,
0)); |
408 | 404 |
409 // We'd like to be able to test this with random translations, but currently
the vertex | 405 // We'd like to be able to test this with random translations, but currently
the vertex |
410 // bounds and vertices will get out of sync | 406 // bounds and vertices will get out of sync |
411 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); | 407 SkScalar x = 0.f;//SkIntToScalar(random->nextU()); |
412 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); | 408 SkScalar y = 0.f;//SkIntToScalar(random->nextU()); |
413 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, | 409 return blob->test_createBatch(textLen, 0, 0, viewMatrix, x, y, color, skPain
t, |
414 gSurfaceProps, gTextContext->dfAdjustTable(), | 410 gSurfaceProps, gTextContext->dfAdjustTable(), |
415 context->getBatchFontCache()); | 411 context->getBatchFontCache()); |
416 } | 412 } |
417 | 413 |
418 #endif | 414 #endif |
OLD | NEW |