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

Side by Side Diff: tests/TextBlobCacheTest.cpp

Issue 1275393003: Fix for 510931, merge to m44 (Closed) Base URL: https://skia.googlesource.com/skia.git@m44
Patch Set: Created 5 years, 4 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/gpu/GrFontScaler.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "sk_tool_utils.h"
9 #include "SkCanvas.h"
10 #include "SkPaint.h"
11 #include "SkPoint.h"
12 #include "SkTextBlob.h"
13 #include "SkFontMgr.h"
14 #include "SkGraphics.h"
15 #include "SkSurface.h"
16 #include "SkTypeface.h"
17 #include "../src/fonts/SkRandomScalerContext.h"
18
19 #ifdef SK_BUILD_FOR_WIN
20 #include "SkTypeface_win.h"
21 #endif
22
23 #include "Test.h"
24
25 #if SK_SUPPORT_GPU
26 #include "GrContextFactory.h"
27
28 struct TextBlobWrapper {
29 // This class assumes it 'owns' the textblob it wraps, and thus does not nee d to take a ref
30 explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {}
31 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get()) ) {}
32
33 SkAutoTUnref<const SkTextBlob> fBlob;
34 };
35
36 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>& blobs) {
37 int yOffset = 0;
38 for (int r = 0; r < redraw; r++) {
39 for (int i = 0; i < blobs.count(); i++) {
40 const SkTextBlob* blob = blobs[i].fBlob.get();
41 const SkRect& bounds = blob->bounds();
42 yOffset += SkScalarCeilToInt(bounds.height());
43 SkPaint paint;
44 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint);
45 }
46 }
47 }
48
49 static const int kWidth = 1024;
50 static const int kHeight = 768;
51
52 // This test hammers the GPU textblobcache and font atlas
53 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory * factory,
54 int maxTotalText, int maxGlyphID, int maxFamil ies, bool normal) {
55 // setup surface
56 uint32_t flags = 0;
57 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
58
59 // We don't typically actually draw with this unittest
60 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
61 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre mul_SkAlphaType);
62 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k No_Budgeted, info,
63 0, &props));
64 REPORTER_ASSERT(reporter, surface);
65 if (!surface) {
66 return;
67 }
68
69 SkCanvas* canvas = surface->getCanvas();
70
71 SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
72
73 int count = SkMin32(fm->countFamilies(), maxFamilies);
74
75 // make a ton of text
76 SkAutoTArray<uint16_t> text(maxTotalText);
77 for (int i = 0; i < maxTotalText; i++) {
78 text[i] = i % maxGlyphID;
79 }
80
81 // generate textblobs
82 SkTArray<TextBlobWrapper> blobs;
83 for (int i = 0; i < count; i++) {
84 SkPaint paint;
85 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
86 paint.setTextSize(48); // draw big glyphs to really stress the atlas
87
88 SkString familyName;
89 fm->getFamilyName(i, &familyName);
90 SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
91 for (int j = 0; j < set->count(); ++j) {
92 SkFontStyle fs;
93 set->getStyle(j, &fs, NULL);
94
95 // We use a typeface which randomy returns unexpected mask formats t o fuzz
96 SkAutoTUnref<SkTypeface> orig(set->createTypeface(j));
97 if (normal) {
98 paint.setTypeface(orig);
99 } else {
100 SkAutoTUnref<SkTypeface> typeface(SkNEW_ARGS(SkRandomTypeface, ( orig, paint, true)));
101 paint.setTypeface(typeface);
102 }
103
104 SkTextBlobBuilder builder;
105 for (int aa = 0; aa < 2; aa++) {
106 for (int subpixel = 0; subpixel < 2; subpixel++) {
107 for (int lcd = 0; lcd < 2; lcd++) {
108 paint.setAntiAlias(SkToBool(aa));
109 paint.setSubpixelText(SkToBool(subpixel));
110 paint.setLCDRenderText(SkToBool(lcd));
111 if (!SkToBool(lcd)) {
112 paint.setTextSize(160);
113 }
114 const SkTextBlobBuilder::RunBuffer& run = builder.allocR un(paint,
115 maxTotalText,
116 0, 0,
117 NULL);
118 memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uin t16_t));
119 }
120 }
121 }
122 SkNEW_APPEND_TO_TARRAY(&blobs, TextBlobWrapper, (builder.build()));
123 }
124 }
125
126 // create surface where LCD is impossible
127 info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
128 SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry);
129 SkAutoTUnref<SkSurface> surfaceNoLCD(canvas->newSurface(info, &propsNoLCD));
130 REPORTER_ASSERT(reporter, surface);
131 if (!surface) {
132 return;
133 }
134
135 SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas();
136
137 // test redraw
138 draw(canvas, 2, blobs);
139 draw(canvasNoLCD, 2, blobs);
140
141 // test draw after free
142 ctx->freeGpuResources();
143 draw(canvas, 1, blobs);
144
145 ctx->freeGpuResources();
146 draw(canvasNoLCD, 1, blobs);
147
148 // test draw after abandon
149 ctx->abandonContext();
150 draw(canvas, 1, blobs);
151 }
152
153 DEF_GPUTEST(TextBlobCache, reporter, factory) {
154 text_blob_cache_inner(reporter, factory, 4096, 256, 30, true);
155 }
156
157 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) {
158 #ifdef SK_BUILD_FOR_ANDROID
159 text_blob_cache_inner(reporter, factory, 256, 256, 30, false);
160 #else
161 text_blob_cache_inner(reporter, factory, 512, 256, 30, false);
162 #endif
163 }
164 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrFontScaler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698