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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 274 } |
275 | 275 |
276 inline GrAtlasTextBlob* | 276 inline GrAtlasTextBlob* |
277 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, | 277 GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
int, |
278 const SkMatrix& viewMatrix, | 278 const SkMatrix& viewMatrix, |
279 const char text[], size_t byteLength, | 279 const char text[], size_t byteLength, |
280 SkScalar x, SkScalar y) { | 280 SkScalar x, SkScalar y) { |
281 int glyphCount = skPaint.countText(text, byteLength); | 281 int glyphCount = skPaint.countText(text, byteLength); |
282 | 282 |
283 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 283 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); |
284 blob->initThrowawayBlob(viewMatrix); | 284 blob->initThrowawayBlob(viewMatrix, x, y); |
285 | 285 |
286 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 286 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
287 *fContext->caps()->shaderCaps())) { | 287 *fContext->caps()->shaderCaps())) { |
288 GrTextUtils::DrawDFText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, | 288 GrTextUtils::DrawDFText(blob, 0, fContext->getBatchFontCache(), fSurface
Props, |
289 skPaint, paint.getColor(), viewMatrix, text, | 289 skPaint, paint.getColor(), viewMatrix, text, |
290 byteLength, x, y); | 290 byteLength, x, y); |
291 } else { | 291 } else { |
292 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, | 292 GrTextUtils::DrawBmpText(blob, 0, fContext->getBatchFontCache(), fSurfac
eProps, skPaint, |
293 paint.getColor(), viewMatrix, text, byteLength,
x, y); | 293 paint.getColor(), viewMatrix, text, byteLength,
x, y); |
294 } | 294 } |
295 return blob; | 295 return blob; |
296 } | 296 } |
297 | 297 |
298 inline GrAtlasTextBlob* | 298 inline GrAtlasTextBlob* |
299 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, | 299 GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
kPaint, |
300 const SkMatrix& viewMatrix, | 300 const SkMatrix& viewMatrix, |
301 const char text[], size_t byteLength, | 301 const char text[], size_t byteLength, |
302 const SkScalar pos[], int scalarsPerPo
sition, | 302 const SkScalar pos[], int scalarsPerPo
sition, |
303 const SkPoint& offset) { | 303 const SkPoint& offset) { |
304 int glyphCount = skPaint.countText(text, byteLength); | 304 int glyphCount = skPaint.countText(text, byteLength); |
305 | 305 |
306 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); | 306 GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::k
GrayTextVASize); |
307 blob->initThrowawayBlob(viewMatrix); | 307 blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y()); |
308 | 308 |
309 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, | 309 if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps, |
310 *fContext->caps()->shaderCaps())) { | 310 *fContext->caps()->shaderCaps())) { |
311 GrTextUtils::DrawDFPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, | 311 GrTextUtils::DrawDFPosText(blob, 0, fContext->getBatchFontCache(), fSurf
aceProps, |
312 skPaint, paint.getColor(), viewMatrix, text, | 312 skPaint, paint.getColor(), viewMatrix, text, |
313 byteLength, pos, scalarsPerPosition, offset); | 313 byteLength, pos, scalarsPerPosition, offset); |
314 } else { | 314 } else { |
315 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, | 315 GrTextUtils::DrawBmpPosText(blob, 0, fContext->getBatchFontCache(), fSur
faceProps, skPaint, |
316 paint.getColor(), viewMatrix, text, | 316 paint.getColor(), viewMatrix, text, |
317 byteLength, pos, scalarsPerPosition, offset)
; | 317 byteLength, pos, scalarsPerPosition, offset)
; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 386 |
387 // Setup clip | 387 // Setup clip |
388 GrClip clip; | 388 GrClip clip; |
389 | 389 |
390 // 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 |
391 // 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. |
392 SkAutoTUnref<GrAtlasTextBlob> blob( | 392 SkAutoTUnref<GrAtlasTextBlob> blob( |
393 gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text, | 393 gTextContext->createDrawTextBlob(grPaint, skPaint, viewMatrix, text, |
394 static_cast<size_t>(textLen), 0, 0)
); | 394 static_cast<size_t>(textLen), 0, 0)
); |
395 | 395 |
396 SkScalar transX = static_cast<SkScalar>(random->nextU()); | 396 // We'd like to be able to test this with random translations, but currently
the vertex |
397 SkScalar transY = static_cast<SkScalar>(random->nextU()); | 397 // bounds and vertices will get out of sync |
| 398 SkScalar transX = 0.f;//SkIntToScalar(random->nextU()); |
| 399 SkScalar transY = 0.f;//SkIntToScalar(random->nextU()); |
398 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, | 400 return blob->test_createBatch(textLen, 0, 0, color, transX, transY, skPaint, |
399 gSurfaceProps, gTextContext->dfAdjustTable(), | 401 gSurfaceProps, gTextContext->dfAdjustTable(), |
400 context->getBatchFontCache()); | 402 context->getBatchFontCache()); |
401 } | 403 } |
402 | 404 |
403 #endif | 405 #endif |
OLD | NEW |