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

Side by Side Diff: tests/TextBlobCacheTest.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 | « src/utils/SkTextBox.cpp ('k') | tests/TextBlobTest.cpp » ('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 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 7
8 #include "sk_tool_utils.h" 8 #include "sk_tool_utils.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkPoint.h" 12 #include "SkPoint.h"
13 #include "SkTextBlob.h" 13 #include "SkTextBlob.h"
14 #include "SkFontMgr.h" 14 #include "SkFontMgr.h"
15 #include "SkGraphics.h" 15 #include "SkGraphics.h"
16 #include "SkSurface.h" 16 #include "SkSurface.h"
17 #include "SkTypeface.h" 17 #include "SkTypeface.h"
18 #include "../src/fonts/SkRandomScalerContext.h" 18 #include "../src/fonts/SkRandomScalerContext.h"
19 19
20 #ifdef SK_BUILD_FOR_WIN 20 #ifdef SK_BUILD_FOR_WIN
21 #include "SkTypeface_win.h" 21 #include "SkTypeface_win.h"
22 #endif 22 #endif
23 23
24 #include "Test.h" 24 #include "Test.h"
25 25
26 #if SK_SUPPORT_GPU 26 #if SK_SUPPORT_GPU
27 #include "GrContext.h" 27 #include "GrContext.h"
28 #include "GrTest.h" 28 #include "GrTest.h"
29 29
30 struct TextBlobWrapper { 30 static void draw(SkCanvas* canvas, int redraw, const SkTArray<sk_sp<SkTextBlob>> & blobs) {
31 // This class assumes it 'owns' the textblob it wraps, and thus does not nee d to take a ref
32 explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {}
33 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get()) ) {}
34
35 SkAutoTUnref<const SkTextBlob> fBlob;
36 };
37
38 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>& blobs) {
39 int yOffset = 0; 31 int yOffset = 0;
40 for (int r = 0; r < redraw; r++) { 32 for (int r = 0; r < redraw; r++) {
41 for (int i = 0; i < blobs.count(); i++) { 33 for (int i = 0; i < blobs.count(); i++) {
42 const SkTextBlob* blob = blobs[i].fBlob.get(); 34 const auto& blob = blobs[i];
43 const SkRect& bounds = blob->bounds(); 35 const SkRect& bounds = blob->bounds();
44 yOffset += SkScalarCeilToInt(bounds.height()); 36 yOffset += SkScalarCeilToInt(bounds.height());
45 SkPaint paint; 37 SkPaint paint;
46 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); 38 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint);
47 } 39 }
48 } 40 }
49 } 41 }
50 42
51 static const int kWidth = 1024; 43 static const int kWidth = 1024;
52 static const int kHeight = 768; 44 static const int kHeight = 768;
(...skipping 25 matching lines...) Expand all
78 70
79 int count = SkMin32(fm->countFamilies(), maxFamilies); 71 int count = SkMin32(fm->countFamilies(), maxFamilies);
80 72
81 // make a ton of text 73 // make a ton of text
82 SkAutoTArray<uint16_t> text(maxTotalText); 74 SkAutoTArray<uint16_t> text(maxTotalText);
83 for (int i = 0; i < maxTotalText; i++) { 75 for (int i = 0; i < maxTotalText; i++) {
84 text[i] = i % maxGlyphID; 76 text[i] = i % maxGlyphID;
85 } 77 }
86 78
87 // generate textblobs 79 // generate textblobs
88 SkTArray<TextBlobWrapper> blobs; 80 SkTArray<sk_sp<SkTextBlob>> blobs;
89 for (int i = 0; i < count; i++) { 81 for (int i = 0; i < count; i++) {
90 SkPaint paint; 82 SkPaint paint;
91 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 83 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
92 paint.setTextSize(48); // draw big glyphs to really stress the atlas 84 paint.setTextSize(48); // draw big glyphs to really stress the atlas
93 85
94 SkString familyName; 86 SkString familyName;
95 fm->getFamilyName(i, &familyName); 87 fm->getFamilyName(i, &familyName);
96 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i)); 88 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
97 for (int j = 0; j < set->count(); ++j) { 89 for (int j = 0; j < set->count(); ++j) {
98 SkFontStyle fs; 90 SkFontStyle fs;
(...skipping 18 matching lines...) Expand all
117 paint.setTextSize(160); 109 paint.setTextSize(160);
118 } 110 }
119 const SkTextBlobBuilder::RunBuffer& run = builder.allocR un(paint, 111 const SkTextBlobBuilder::RunBuffer& run = builder.allocR un(paint,
120 maxTotalText, 112 maxTotalText,
121 0, 0, 113 0, 0,
122 nullptr); 114 nullptr);
123 memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uin t16_t)); 115 memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uin t16_t));
124 } 116 }
125 } 117 }
126 } 118 }
127 blobs.emplace_back(builder.build()); 119 blobs.emplace_back(builder.make());
128 } 120 }
129 } 121 }
130 122
131 // create surface where LCD is impossible 123 // create surface where LCD is impossible
132 info = SkImageInfo::MakeN32Premul(kWidth, kHeight); 124 info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
133 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry); 125 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry);
134 auto surfaceNoLCD(canvas->makeSurface(info, &propsNoLCD)); 126 auto surfaceNoLCD(canvas->makeSurface(info, &propsNoLCD));
135 REPORTER_ASSERT(reporter, surface); 127 REPORTER_ASSERT(reporter, surface);
136 if (!surface) { 128 if (!surface) {
137 return; 129 return;
(...skipping 26 matching lines...) Expand all
164 } 156 }
165 157
166 DEF_GPUTEST_FOR_NULLGL_CONTEXT(TextBlobAbnormal, reporter, ctxInfo) { 158 DEF_GPUTEST_FOR_NULLGL_CONTEXT(TextBlobAbnormal, reporter, ctxInfo) {
167 text_blob_cache_inner(reporter, ctxInfo.grContext(), 256, 256, 10, false, fa lse); 159 text_blob_cache_inner(reporter, ctxInfo.grContext(), 256, 256, 10, false, fa lse);
168 } 160 }
169 161
170 DEF_GPUTEST_FOR_NULLGL_CONTEXT(TextBlobStressAbnormal, reporter, ctxInfo) { 162 DEF_GPUTEST_FOR_NULLGL_CONTEXT(TextBlobStressAbnormal, reporter, ctxInfo) {
171 text_blob_cache_inner(reporter, ctxInfo.grContext(), 256, 256, 10, false, tr ue); 163 text_blob_cache_inner(reporter, ctxInfo.grContext(), 256, 256, 10, false, tr ue);
172 } 164 }
173 #endif 165 #endif
OLDNEW
« no previous file with comments | « src/utils/SkTextBox.cpp ('k') | tests/TextBlobTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698