| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 cacheBlob->flushCached(fContext, dc, blob, fSurfaceProps, fDistanceAdjustTab
le, skPaint, | 185 cacheBlob->flushCached(fContext, dc, blob, fSurfaceProps, fDistanceAdjustTab
le, skPaint, |
| 186 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y, transX, transY); | 186 grPaint, drawFilter, clip, viewMatrix, clipBounds, x,
y, transX, transY); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, | 189 void GrAtlasTextContext::regenerateTextBlob(GrAtlasTextBlob* cacheBlob, |
| 190 const SkPaint& skPaint, GrColor colo
r, | 190 const SkPaint& skPaint, GrColor colo
r, |
| 191 const SkMatrix& viewMatrix, | 191 const SkMatrix& viewMatrix, |
| 192 const SkTextBlob* blob, SkScalar x,
SkScalar y, | 192 const SkTextBlob* blob, SkScalar x,
SkScalar y, |
| 193 SkDrawFilter* drawFilter) { | 193 SkDrawFilter* drawFilter) { |
| 194 // The color here is the GrPaint color, and it is used to determine whether
we | 194 cacheBlob->initReusableBlob(color, viewMatrix, x, y); |
| 195 // have to regenerate LCD text blobs. | |
| 196 // We use this color vs the SkPaint color because it has the colorfilter app
lied. | |
| 197 cacheBlob->fPaintColor = color; | |
| 198 cacheBlob->fViewMatrix = viewMatrix; | |
| 199 cacheBlob->fX = x; | |
| 200 cacheBlob->fY = y; | |
| 201 | 195 |
| 202 // Regenerate textblob | 196 // Regenerate textblob |
| 203 SkPaint runPaint = skPaint; | 197 SkPaint runPaint = skPaint; |
| 204 SkTextBlobRunIterator it(blob); | 198 SkTextBlobRunIterator it(blob); |
| 205 for (int run = 0; !it.done(); it.next(), run++) { | 199 for (int run = 0; !it.done(); it.next(), run++) { |
| 206 int glyphCount = it.glyphCount(); | 200 int glyphCount = it.glyphCount(); |
| 207 size_t textLen = glyphCount * sizeof(uint16_t); | 201 size_t textLen = glyphCount * sizeof(uint16_t); |
| 208 const SkPoint& offset = it.offset(); | 202 const SkPoint& offset = it.offset(); |
| 209 // applyFontToPaint() always overwrites the exact same attributes, | 203 // applyFontToPaint() always overwrites the exact same attributes, |
| 210 // so it is safe to not re-seed the paint for this reason. | 204 // so it is safe to not re-seed the paint for this reason. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 241 case SkTextBlob::kFull_Positioning: { | 235 case SkTextBlob::kFull_Positioning: { |
| 242 SkPoint dfOffset = SkPoint::Make(x, y); | 236 SkPoint dfOffset = SkPoint::Make(x, y); |
| 243 GrTextUtils::DrawDfPosText(cacheBlob, run, fContext->getBat
chFontCache(), | 237 GrTextUtils::DrawDfPosText(cacheBlob, run, fContext->getBat
chFontCache(), |
| 244 fSurfaceProps, runPaint, color, v
iewMatrix, | 238 fSurfaceProps, runPaint, color, v
iewMatrix, |
| 245 (const char*)it.glyphs(), textLen
, it.pos(), | 239 (const char*)it.glyphs(), textLen
, it.pos(), |
| 246 2, dfOffset); | 240 2, dfOffset); |
| 247 break; | 241 break; |
| 248 } | 242 } |
| 249 } | 243 } |
| 250 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { | 244 } else if (SkDraw::ShouldDrawTextAsPaths(runPaint, viewMatrix)) { |
| 251 cacheBlob->fRuns[run].fDrawAsPaths = true; | 245 cacheBlob->setRunDrawAsPaths(run); |
| 252 } else { | 246 } else { |
| 253 switch (it.positioning()) { | 247 switch (it.positioning()) { |
| 254 case SkTextBlob::kDefault_Positioning: | 248 case SkTextBlob::kDefault_Positioning: |
| 255 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF
ontCache(), | 249 GrTextUtils::DrawBmpText(cacheBlob, run, fContext->getBatchF
ontCache(), |
| 256 fSurfaceProps, runPaint, color, vie
wMatrix, | 250 fSurfaceProps, runPaint, color, vie
wMatrix, |
| 257 (const char *)it.glyphs(), textLen, | 251 (const char *)it.glyphs(), textLen, |
| 258 x + offset.x(), y + offset.y()); | 252 x + offset.x(), y + offset.y()); |
| 259 break; | 253 break; |
| 260 case SkTextBlob::kHorizontal_Positioning: | 254 case SkTextBlob::kHorizontal_Positioning: |
| 261 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), | 255 GrTextUtils::DrawBmpPosText(cacheBlob, run, fContext->getBat
chFontCache(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 280 } | 274 } |
| 281 | 275 |
| 282 inline GrAtlasTextBlob* | 276 inline GrAtlasTextBlob* |
| 283 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, | 277 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, |
| 284 const SkMatrix& viewMatrix, | 278 const SkMatrix& viewMatrix, |
| 285 const char text[], size_t byteLength, | 279 const char text[], size_t byteLength, |
| 286 SkScalar x, SkScalar y) { | 280 SkScalar x, SkScalar y) { |
| 287 int glyphCount = skPaint.countText(text, byteLength); | 281 int glyphCount = skPaint.countText(text, byteLength); |
| 288 | 282 |
| 289 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 283 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); |
| 290 blob->fViewMatrix = viewMatrix; | 284 blob->initThrowawayBlob(viewMatrix); |
| 291 | 285 |
| 292 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 286 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
| 293 *fContext->caps()->shaderCaps())) { | 287 *fContext->caps()->shaderCaps())) { |
| 294 GrTextUtils::DrawDfText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, | 288 GrTextUtils::DrawDfText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, |
| 295 skPaint, paint.getColor(), viewMatrix, text, | 289 skPaint, paint.getColor(), viewMatrix, text, |
| 296 byteLength, x, y); | 290 byteLength, x, y); |
| 297 } else { | 291 } else { |
| 298 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, | 292 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, |
| 299 paint.getColor(), viewMatrix, text, byteLength,
x, y); | 293 paint.getColor(), viewMatrix, text, byteLength,
x, y); |
| 300 } | 294 } |
| 301 return blob; | 295 return blob; |
| 302 } | 296 } |
| 303 | 297 |
| 304 inline GrAtlasTextBlob* | 298 inline GrAtlasTextBlob* |
| 305 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, | 299 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, |
| 306 const SkMatrix& viewMatrix, | 300 const SkMatrix& viewMatrix, |
| 307 const char text[], size_t byteLength, | 301 const char text[], size_t byteLength, |
| 308 const SkScalar pos[], int scalarsPerPo
sition, | 302 const SkScalar pos[], int scalarsPerPo
sition, |
| 309 const SkPoint& offset) { | 303 const SkPoint& offset) { |
| 310 int glyphCount = skPaint.countText(text, byteLength); | 304 int glyphCount = skPaint.countText(text, byteLength); |
| 311 | 305 |
| 312 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 306 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); |
| 313 blob->fViewMatrix = viewMatrix; | 307 blob->initThrowawayBlob(viewMatrix); |
| 314 | 308 |
| 315 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 309 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
| 316 *fContext->caps()->shaderCaps())) { | 310 *fContext->caps()->shaderCaps())) { |
| 317 GrTextUtils::DrawDfPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, | 311 GrTextUtils::DrawDfPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, |
| 318 skPaint, paint.getColor(), viewMatrix, text, | 312 skPaint, paint.getColor(), viewMatrix, text, |
| 319 byteLength, pos, scalarsPerPosition, offset); | 313 byteLength, pos, scalarsPerPosition, offset); |
| 320 } else { | 314 } else { |
| 321 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, | 315 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, |
| 322 paint.getColor(), viewMatrix, text, | 316 paint.getColor(), viewMatrix, text, |
| 323 byteLength, pos, scalarsPerPosition, offset)
; | 317 byteLength, pos, scalarsPerPosition, offset)
; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 GrClip clip; | 388 GrClip clip; |
| 395 | 389 |
| 396 // right now we don't handle textblobs, nor do we handle drawPosText. Since
we only | 390 // right now we don't handle textblobs, nor do we handle drawPosText. Since
we only |
| 397 // intend to test the batch with this unit test, that is okay. | 391 // intend to test the batch with this unit test, that is okay. |
| 398 SkAutoTUnref<GrAtlasTextBlob> blob( | 392 SkAutoTUnref<GrAtlasTextBlob> blob( |
| 399 gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text, | 393 gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text, |
| 400 static_cast<size_t>(textLen), 0, 0)
); | 394 static_cast<size_t>(textLen), 0, 0)
); |
| 401 | 395 |
| 402 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 396 SkScalar transX = static_cast<SkScalar>(random->nextU()); |
| 403 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 397 SkScalar transY = static_cast<SkScalar>(random->nextU()); |
| 404 const GrAtlasTextBlob::Run::SubRunInfo& info = blob->fRuns[0].fSubRunInfo[0]
; | 398 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, |
| 405 return blob->createBatch(info, textLen, 0, 0, color, transX, transY, skPaint
, | 399 gSurfaceProps, gTextContext->dfAdjustTable(), |
| 406 gSurfaceProps, gTextContext->dfAdjustTable(), | 400 context->getBatchFontCache()); |
| 407 context->getBatchFontCache()); | |
| 408 } | 401 } |
| 409 | 402 |
| 410 #endif | 403 #endif |
| OLD | NEW |