Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1291)

Side by Side Diff: gm/texteffects.cpp

Issue 2335493005: Use sk_sp text blob APIs (Closed)
Patch Set: SK_SUPPORT_LEGACY_TEXTBLOB_BUILDER Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/textblobuseaftergpufree.cpp ('k') | include/core/SkTextBlob.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkBlurMask.h" 9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 canvas->drawPath(underline, paint); 344 canvas->drawPath(underline, paint);
345 345
346 canvas->translate(0, textSize * 1.3f); 346 canvas->translate(0, textSize * 1.3f);
347 } 347 }
348 canvas->translate(0, 60); 348 canvas->translate(0, 60);
349 } 349 }
350 } 350 }
351 351
352 namespace { 352 namespace {
353 353
354 sk_sp<const SkTextBlob> MakeFancyBlob(const SkPaint& paint, const char* text) { 354 sk_sp<SkTextBlob> MakeFancyBlob(const SkPaint& paint, const char* text) {
355 SkPaint blobPaint(paint); 355 SkPaint blobPaint(paint);
356 356
357 const size_t textLen = strlen(text); 357 const size_t textLen = strlen(text);
358 const int glyphCount = blobPaint.textToGlyphs(text, textLen, nullptr); 358 const int glyphCount = blobPaint.textToGlyphs(text, textLen, nullptr);
359 SkAutoTArray<SkGlyphID> glyphs(glyphCount); 359 SkAutoTArray<SkGlyphID> glyphs(glyphCount);
360 blobPaint.textToGlyphs(text, textLen, glyphs.get()); 360 blobPaint.textToGlyphs(text, textLen, glyphs.get());
361 361
362 blobPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 362 blobPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
363 const size_t glyphTextBytes = SkTo<uint32_t>(glyphCount) * sizeof(SkGlyphID) ; 363 const size_t glyphTextBytes = SkTo<uint32_t>(glyphCount) * sizeof(SkGlyphID) ;
364 const int widthCount = blobPaint.getTextWidths(glyphs.get(), glyphTextBytes, nullptr); 364 const int widthCount = blobPaint.getTextWidths(glyphs.get(), glyphTextBytes, nullptr);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 const SkTextBlobBuilder::RunBuffer& buf = blobBuilder.allocRunPos(blobPa int, fullRunLen); 404 const SkTextBlobBuilder::RunBuffer& buf = blobBuilder.allocRunPos(blobPa int, fullRunLen);
405 memcpy(buf.glyphs, glyphs.get() + glyphIndex, 405 memcpy(buf.glyphs, glyphs.get() + glyphIndex,
406 SkTo<uint32_t>(fullRunLen) * sizeof(SkGlyphID)); 406 SkTo<uint32_t>(fullRunLen) * sizeof(SkGlyphID));
407 for (int i = 0; i < fullRunLen; ++i) { 407 for (int i = 0; i < fullRunLen; ++i) {
408 buf.pos[i * 2 + 0] = advance; // x offset 408 buf.pos[i * 2 + 0] = advance; // x offset
409 buf.pos[i * 2 + 1] = 0; // y offset 409 buf.pos[i * 2 + 1] = 0; // y offset
410 advance += widths[glyphIndex++]; 410 advance += widths[glyphIndex++];
411 } 411 }
412 } 412 }
413 413
414 return sk_sp<const SkTextBlob>(blobBuilder.build()); 414 return blobBuilder.make();
415 } 415 }
416 416
417 } // anonymous ns 417 } // anonymous ns
418 418
419 DEF_SIMPLE_GM(fancyblobunderline, canvas, 1480, 1380) { 419 DEF_SIMPLE_GM(fancyblobunderline, canvas, 1480, 1380) {
420 SkPaint paint; 420 SkPaint paint;
421 paint.setAntiAlias(true); 421 paint.setAntiAlias(true);
422 const char* fam[] = { "sans-serif", "serif", "monospace" }; 422 const char* fam[] = { "sans-serif", "serif", "monospace" };
423 const char test[] = "aAjJgGyY_|{-(~[,]qQ}pP}zZ"; 423 const char test[] = "aAjJgGyY_|{-(~[,]qQ}pP}zZ";
424 const SkPoint blobOffset = { 10, 80 }; 424 const SkPoint blobOffset = { 10, 80 };
425 425
426 for (size_t font = 0; font < SK_ARRAY_COUNT(fam); ++font) { 426 for (size_t font = 0; font < SK_ARRAY_COUNT(fam); ++font) {
427 sk_tool_utils::set_portable_typeface(&paint, fam[font]); 427 sk_tool_utils::set_portable_typeface(&paint, fam[font]);
428 for (SkScalar textSize = 100; textSize > 10; textSize -= 20) { 428 for (SkScalar textSize = 100; textSize > 10; textSize -= 20) {
429 paint.setTextSize(textSize); 429 paint.setTextSize(textSize);
430 const SkScalar uWidth = textSize / 15; 430 const SkScalar uWidth = textSize / 15;
431 paint.setStrokeWidth(uWidth); 431 paint.setStrokeWidth(uWidth);
432 paint.setStyle(SkPaint::kFill_Style); 432 paint.setStyle(SkPaint::kFill_Style);
433 433
434 sk_sp<const SkTextBlob> blob = MakeFancyBlob(paint, test); 434 sk_sp<SkTextBlob> blob = MakeFancyBlob(paint, test);
435 canvas->drawTextBlob(blob.get(), blobOffset.x(), blobOffset.y(), pai nt); 435 canvas->drawTextBlob(blob, blobOffset.x(), blobOffset.y(), paint);
436 436
437 const SkScalar uPos = uWidth; 437 const SkScalar uPos = uWidth;
438 const SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 }; 438 const SkScalar bounds[2] = { uPos - uWidth / 2, uPos + uWidth / 2 };
439 const int interceptCount = paint.getTextBlobIntercepts(blob.get(), b ounds, nullptr); 439 const int interceptCount = paint.getTextBlobIntercepts(blob.get(), b ounds, nullptr);
440 SkASSERT(!(interceptCount % 2)); 440 SkASSERT(!(interceptCount % 2));
441 441
442 SkTDArray<SkScalar> intercepts; 442 SkTDArray<SkScalar> intercepts;
443 intercepts.setCount(interceptCount); 443 intercepts.setCount(interceptCount);
444 paint.getTextBlobIntercepts(blob.get(), bounds, intercepts.begin()); 444 paint.getTextBlobIntercepts(blob.get(), bounds, intercepts.begin());
445 445
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 489
490 SkScalar start = textPt.fX; 490 SkScalar start = textPt.fX;
491 SkScalar end = posX; 491 SkScalar end = posX;
492 SkScalar uPos = pos[0].fY + uWidth; 492 SkScalar uPos = pos[0].fY + uWidth;
493 SkPath underline = create_underline(intersections, start, end, uPos, uWi dth, textSize); 493 SkPath underline = create_underline(intersections, start, end, uPos, uWi dth, textSize);
494 paint.setStyle(SkPaint::kStroke_Style); 494 paint.setStyle(SkPaint::kStroke_Style);
495 canvas->drawPath(underline, paint); 495 canvas->drawPath(underline, paint);
496 canvas->translate(0, textSize * 1.3f); 496 canvas->translate(0, textSize * 1.3f);
497 } 497 }
498 } 498 }
OLDNEW
« no previous file with comments | « gm/textblobuseaftergpufree.cpp ('k') | include/core/SkTextBlob.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698