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

Side by Side Diff: tests/TextBlobCacheTest.cpp

Issue 1300813007: wire up reduced atlas and zero textblob cache to test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks 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/GrTextBlobCache.h ('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
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 #include "SkCanvas.h" 10 #include "SkCanvas.h"
10 #include "SkPaint.h" 11 #include "SkPaint.h"
11 #include "SkPoint.h" 12 #include "SkPoint.h"
12 #include "SkTextBlob.h" 13 #include "SkTextBlob.h"
13 #include "SkFontMgr.h" 14 #include "SkFontMgr.h"
14 #include "SkGraphics.h" 15 #include "SkGraphics.h"
15 #include "SkSurface.h" 16 #include "SkSurface.h"
16 #include "SkTypeface.h" 17 #include "SkTypeface.h"
17 #include "../src/fonts/SkRandomScalerContext.h" 18 #include "../src/fonts/SkRandomScalerContext.h"
18 19
19 #ifdef SK_BUILD_FOR_WIN 20 #ifdef SK_BUILD_FOR_WIN
20 #include "SkTypeface_win.h" 21 #include "SkTypeface_win.h"
21 #endif 22 #endif
22 23
23 #include "Test.h" 24 #include "Test.h"
24 25
25 #if SK_SUPPORT_GPU 26 #if SK_SUPPORT_GPU
26 #include "GrContextFactory.h" 27 #include "GrContextFactory.h"
28 #include "GrTest.h"
27 29
28 struct TextBlobWrapper { 30 struct TextBlobWrapper {
29 // This class assumes it 'owns' the textblob it wraps, and thus does not nee d to take a ref 31 // 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) {} 32 explicit TextBlobWrapper(const SkTextBlob* blob) : fBlob(blob) {}
31 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get()) ) {} 33 TextBlobWrapper(const TextBlobWrapper& blob) : fBlob(SkRef(blob.fBlob.get()) ) {}
32 34
33 SkAutoTUnref<const SkTextBlob> fBlob; 35 SkAutoTUnref<const SkTextBlob> fBlob;
34 }; 36 };
35 37
36 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>& blobs) { 38 static void draw(SkCanvas* canvas, int redraw, const SkTArray<TextBlobWrapper>& blobs) {
37 int yOffset = 0; 39 int yOffset = 0;
38 for (int r = 0; r < redraw; r++) { 40 for (int r = 0; r < redraw; r++) {
39 for (int i = 0; i < blobs.count(); i++) { 41 for (int i = 0; i < blobs.count(); i++) {
40 const SkTextBlob* blob = blobs[i].fBlob.get(); 42 const SkTextBlob* blob = blobs[i].fBlob.get();
41 const SkRect& bounds = blob->bounds(); 43 const SkRect& bounds = blob->bounds();
42 yOffset += SkScalarCeilToInt(bounds.height()); 44 yOffset += SkScalarCeilToInt(bounds.height());
43 SkPaint paint; 45 SkPaint paint;
44 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint); 46 canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint);
45 } 47 }
46 } 48 }
47 } 49 }
48 50
49 static const int kWidth = 1024; 51 static const int kWidth = 1024;
50 static const int kHeight = 768; 52 static const int kHeight = 768;
51 53
52 // This test hammers the GPU textblobcache and font atlas 54 // This test hammers the GPU textblobcache and font atlas
53 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory * factory, 55 static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContextFactory * factory,
54 int maxTotalText, int maxGlyphID, int maxFamil ies, bool normal) { 56 int maxTotalText, int maxGlyphID, int maxFamil ies, bool normal,
57 bool stressTest) {
55 // setup surface 58 // setup surface
56 uint32_t flags = 0; 59 uint32_t flags = 0;
57 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); 60 SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
58 61
59 // We don't typically actually draw with this unittest 62 // We don't typically actually draw with this unittest
60 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType); 63 GrContext* ctx = factory->get(GrContextFactory::kNull_GLContextType);
64
65 // configure our context for maximum stressing of cache and atlas
66 if (stressTest) {
67 GrTest::SetupAlwaysEvictAtlas(ctx);
68 ctx->setTextBlobCacheLimit_ForTesting(0);
69 }
70
61 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre mul_SkAlphaType); 71 SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPre mul_SkAlphaType);
62 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k No_Budgeted, info, 72 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::k No_Budgeted, info,
63 0, &props)); 73 0, &props));
64 REPORTER_ASSERT(reporter, surface); 74 REPORTER_ASSERT(reporter, surface);
65 if (!surface) { 75 if (!surface) {
66 return; 76 return;
67 } 77 }
68 78
69 SkCanvas* canvas = surface->getCanvas(); 79 SkCanvas* canvas = surface->getCanvas();
70 80
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 154
145 ctx->freeGpuResources(); 155 ctx->freeGpuResources();
146 draw(canvasNoLCD, 1, blobs); 156 draw(canvasNoLCD, 1, blobs);
147 157
148 // test draw after abandon 158 // test draw after abandon
149 ctx->abandonContext(); 159 ctx->abandonContext();
150 draw(canvas, 1, blobs); 160 draw(canvas, 1, blobs);
151 } 161 }
152 162
153 DEF_GPUTEST(TextBlobCache, reporter, factory) { 163 DEF_GPUTEST(TextBlobCache, reporter, factory) {
154 text_blob_cache_inner(reporter, factory, 4096, 256, 30, true); 164 text_blob_cache_inner(reporter, factory, 1024, 256, 30, true, false);
165 }
166
167 DEF_GPUTEST(TextBlobStressCache, reporter, factory) {
168 text_blob_cache_inner(reporter, factory, 256, 256, 10, true, true);
155 } 169 }
156 170
157 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) { 171 DEF_GPUTEST(TextBlobAbnormal, reporter, factory) {
158 #ifdef SK_BUILD_FOR_ANDROID 172 text_blob_cache_inner(reporter, factory, 256, 256, 10, false, false);
159 text_blob_cache_inner(reporter, factory, 256, 256, 30, false); 173 }
160 #else 174
161 text_blob_cache_inner(reporter, factory, 512, 256, 30, false); 175 DEF_GPUTEST(TextBlobStressAbnormal, reporter, factory) {
162 #endif 176 text_blob_cache_inner(reporter, factory, 256, 256, 10, false, true);
163 } 177 }
164 #endif 178 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrTextBlobCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698