| 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 24 matching lines...) Expand all Loading... |
| 35 #include "batches/GrAtlasTextBatch.h" | 35 #include "batches/GrAtlasTextBatch.h" |
| 36 | 36 |
| 37 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, const SkSurfaceProps&
surfaceProps) | 37 GrAtlasTextContext::GrAtlasTextContext(GrContext* context, const SkSurfaceProps&
surfaceProps) |
| 38 : INHERITED(context, surfaceProps) | 38 : INHERITED(context, surfaceProps) |
| 39 , fDistanceAdjustTable(new GrDistanceFieldAdjustTable) { | 39 , fDistanceAdjustTable(new GrDistanceFieldAdjustTable) { |
| 40 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest | 40 // We overallocate vertices in our textblobs based on the assumption that A8
has the greatest |
| 41 // vertexStride | 41 // vertexStride |
| 42 static_assert(GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kColorTex
tVASize && | 42 static_assert(GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kColorTex
tVASize && |
| 43 GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kLCDTextV
ASize, | 43 GrAtlasTextBlob::kGrayTextVASize >= GrAtlasTextBlob::kLCDTextV
ASize, |
| 44 "vertex_attribute_changed"); | 44 "vertex_attribute_changed"); |
| 45 fCurrStrike = nullptr; | |
| 46 fCache = context->getTextBlobCache(); | 45 fCache = context->getTextBlobCache(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 | 48 |
| 50 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, | 49 GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context, |
| 51 const SkSurfaceProps& surfaceProp
s) { | 50 const SkSurfaceProps& surfaceProp
s) { |
| 52 return new GrAtlasTextContext(context, surfaceProps); | 51 return new GrAtlasTextContext(context, surfaceProps); |
| 53 } | 52 } |
| 54 | 53 |
| 55 bool GrAtlasTextContext::canDraw(const SkPaint& skPaint, const SkMatrix& viewMat
rix) { | 54 bool GrAtlasTextContext::canDraw(const SkPaint& skPaint, const SkMatrix& viewMat
rix) { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 skPaint, paint.getColor(), viewMatrix, text, | 306 skPaint, paint.getColor(), viewMatrix, text, |
| 308 byteLength, pos, scalarsPerPosition, offset); | 307 byteLength, pos, scalarsPerPosition, offset); |
| 309 } else { | 308 } else { |
| 310 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, | 309 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, |
| 311 paint.getColor(), viewMatrix, text, | 310 paint.getColor(), viewMatrix, text, |
| 312 byteLength, pos, scalarsPerPosition, offset)
; | 311 byteLength, pos, scalarsPerPosition, offset)
; |
| 313 } | 312 } |
| 314 return blob; | 313 return blob; |
| 315 } | 314 } |
| 316 | 315 |
| 317 void GrAtlasTextContext::onDrawText(GrDrawContext* dc, | 316 void GrAtlasTextContext::drawText(GrDrawContext* dc, |
| 318 const GrClip& clip, | 317 const GrClip& clip, |
| 319 const GrPaint& paint, const SkPaint& skPaint
, | 318 const GrPaint& paint, const SkPaint& skPaint, |
| 320 const SkMatrix& viewMatrix, | 319 const SkMatrix& viewMatrix, |
| 321 const char text[], size_t byteLength, | 320 const char text[], size_t byteLength, |
| 322 SkScalar x, SkScalar y, const SkIRect& regio
nClipBounds) { | 321 SkScalar x, SkScalar y, const SkIRect& regionC
lipBounds) { |
| 323 SkAutoTUnref<GrAtlasTextBlob> blob( | 322 if (fContext->abandoned()) { |
| 324 this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLength, x
, y)); | 323 return; |
| 325 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa
int, paint, | 324 } else if (this->canDraw(skPaint, viewMatrix)) { |
| 326 clip, regionClipBounds); | 325 SkAutoTUnref<GrAtlasTextBlob> blob( |
| 326 this->createDrawTextBlob(paint, skPaint, viewMatrix, text, byteLengt
h, x, y)); |
| 327 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable,
skPaint, paint, |
| 328 clip, regionClipBounds); |
| 329 return; |
| 330 } |
| 331 |
| 332 // fall back to drawing as a path |
| 333 GrTextUtils::DrawTextAsPath(fContext, dc, clip, skPaint, viewMatrix, text, b
yteLength, x, y, |
| 334 regionClipBounds); |
| 327 } | 335 } |
| 328 | 336 |
| 329 void GrAtlasTextContext::onDrawPosText(GrDrawContext* dc, | 337 void GrAtlasTextContext::drawPosText(GrDrawContext* dc, |
| 330 const GrClip& clip, | 338 const GrClip& clip, |
| 331 const GrPaint& paint, const SkPaint& skPa
int, | 339 const GrPaint& paint, const SkPaint& skPain
t, |
| 332 const SkMatrix& viewMatrix, | 340 const SkMatrix& viewMatrix, |
| 333 const char text[], size_t byteLength, | 341 const char text[], size_t byteLength, |
| 334 const SkScalar pos[], int scalarsPerPosit
ion, | 342 const SkScalar pos[], int scalarsPerPositio
n, |
| 335 const SkPoint& offset, const SkIRect& reg
ionClipBounds) { | 343 const SkPoint& offset, const SkIRect& regio
nClipBounds) { |
| 336 SkAutoTUnref<GrAtlasTextBlob> blob( | 344 if (fContext->abandoned()) { |
| 337 this->createDrawPosTextBlob(paint, skPaint, viewMatrix, | 345 return; |
| 338 text, byteLength, | 346 } else if (this->canDraw(skPaint, viewMatrix)) { |
| 339 pos, scalarsPerPosition, | 347 SkAutoTUnref<GrAtlasTextBlob> blob( |
| 340 offset)); | 348 this->createDrawPosTextBlob(paint, skPaint, viewMatrix, |
| 349 text, byteLength, |
| 350 pos, scalarsPerPosition, |
| 351 offset)); |
| 352 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable,
skPaint, paint, |
| 353 clip, regionClipBounds); |
| 354 return; |
| 355 } |
| 341 | 356 |
| 342 blob->flushThrowaway(fContext, dc, fSurfaceProps, fDistanceAdjustTable, skPa
int, paint, clip, | 357 // fall back to drawing as a path |
| 343 regionClipBounds); | 358 GrTextUtils::DrawPosTextAsPath(fContext, dc, fSurfaceProps, clip, skPaint, v
iewMatrix, text, |
| 359 byteLength, pos, scalarsPerPosition, offset,
regionClipBounds); |
| 344 } | 360 } |
| 345 | 361 |
| 346 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 362 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 347 | 363 |
| 348 #ifdef GR_TEST_UTILS | 364 #ifdef GR_TEST_UTILS |
| 349 | 365 |
| 350 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { | 366 DRAW_BATCH_TEST_DEFINE(TextBlobBatch) { |
| 351 static uint32_t gContextID = SK_InvalidGenID; | 367 static uint32_t gContextID = SK_InvalidGenID; |
| 352 static GrAtlasTextContext* gTextContext = nullptr; | 368 static GrAtlasTextContext* gTextContext = nullptr; |
| 353 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); | 369 static SkSurfaceProps gSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType
); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // We'd like to be able to test this with random translations, but currently
the vertex | 407 // We'd like to be able to test this with random translations, but currently
the vertex |
| 392 // bounds and vertices will get out of sync | 408 // bounds and vertices will get out of sync |
| 393 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); | 409 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); |
| 394 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); | 410 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); |
| 395 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, | 411 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, |
| 396 gSurfaceProps, gTextContext->dfAdjustTable(), | 412 gSurfaceProps, gTextContext->dfAdjustTable(), |
| 397 context->getBatchFontCache()); | 413 context->getBatchFontCache()); |
| 398 } | 414 } |
| 399 | 415 |
| 400 #endif | 416 #endif |
| OLD | NEW |