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

Side by Side Diff: bench/SkGlyphCacheBench.cpp

Issue 1933393002: Move SkTypeface to sk_sp. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Restore deleted Android code. Created 4 years, 7 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 | « bench/CmapBench.cpp ('k') | bench/TextBench.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 8
9 #include "SkGlyphCache.h" 9 #include "SkGlyphCache.h"
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return fName.c_str(); 46 return fName.c_str();
47 } 47 }
48 48
49 bool isSuitableFor(Backend backend) override { 49 bool isSuitableFor(Backend backend) override {
50 return backend == kNonRendering_Backend; 50 return backend == kNonRendering_Backend;
51 } 51 }
52 52
53 void onDraw(int loops, SkCanvas*) override { 53 void onDraw(int loops, SkCanvas*) override {
54 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); 54 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
55 SkGraphics::SetFontCacheLimit(fCacheSize); 55 SkGraphics::SetFontCacheLimit(fCacheSize);
56 SkTypeface* typeface = sk_tool_utils::create_portable_typeface(
57 "serif", SkTypeface::kItalic);
58 SkPaint paint; 56 SkPaint paint;
59 paint.setAntiAlias(true); 57 paint.setAntiAlias(true);
60 paint.setSubpixelText(true); 58 paint.setSubpixelText(true);
61 paint.setTypeface(typeface); 59 paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkTyp eface::kItalic));
62 60
63 for (int work = 0; work < loops; work++) { 61 for (int work = 0; work < loops; work++) {
64 do_font_stuff(&paint); 62 do_font_stuff(&paint);
65 } 63 }
66 SkGraphics::SetFontCacheLimit(oldCacheLimitSize); 64 SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
67 SkSafeUnref(typeface);
68 } 65 }
69 66
70 private: 67 private:
71 typedef Benchmark INHERITED; 68 typedef Benchmark INHERITED;
72 const size_t fCacheSize; 69 const size_t fCacheSize;
73 SkString fName; 70 SkString fName;
74 }; 71 };
75 72
76 class SkGlyphCacheStressTest : public Benchmark { 73 class SkGlyphCacheStressTest : public Benchmark {
77 public: 74 public:
78 explicit SkGlyphCacheStressTest(int cacheSize) : fCacheSize(cacheSize) { } 75 explicit SkGlyphCacheStressTest(int cacheSize) : fCacheSize(cacheSize) { }
79 76
80 protected: 77 protected:
81 const char* onGetName() override { 78 const char* onGetName() override {
82 fName.printf("SkGlyphCacheStressTest%dK", (int)(fCacheSize >> 10)); 79 fName.printf("SkGlyphCacheStressTest%dK", (int)(fCacheSize >> 10));
83 return fName.c_str(); 80 return fName.c_str();
84 } 81 }
85 82
86 bool isSuitableFor(Backend backend) override { 83 bool isSuitableFor(Backend backend) override {
87 return backend == kNonRendering_Backend; 84 return backend == kNonRendering_Backend;
88 } 85 }
89 86
90 void onDraw(int loops, SkCanvas*) override { 87 void onDraw(int loops, SkCanvas*) override {
91 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); 88 size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
92 SkGraphics::SetFontCacheLimit(fCacheSize); 89 SkGraphics::SetFontCacheLimit(fCacheSize);
93 SkTypeface* typefaces[] = 90 sk_sp<SkTypeface> typefaces[] =
94 {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItali c), 91 {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItali c),
95 sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::k Italic)}; 92 sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::k Italic)};
96 93
97 for (int work = 0; work < loops; work++) { 94 for (int work = 0; work < loops; work++) {
98 SkTaskGroup().batch(16, [&](int threadIndex) { 95 SkTaskGroup().batch(16, [&](int threadIndex) {
99 SkPaint paint; 96 SkPaint paint;
100 paint.setAntiAlias(true); 97 paint.setAntiAlias(true);
101 paint.setSubpixelText(true); 98 paint.setSubpixelText(true);
102 paint.setTypeface(typefaces[threadIndex % 2]); 99 paint.setTypeface(typefaces[threadIndex % 2]);
103 do_font_stuff(&paint); 100 do_font_stuff(&paint);
104 }); 101 });
105 } 102 }
106 SkGraphics::SetFontCacheLimit(oldCacheLimitSize); 103 SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
107 SkSafeUnref(typefaces[0]);
108 SkSafeUnref(typefaces[1]);
109 } 104 }
110 105
111 private: 106 private:
112 typedef Benchmark INHERITED; 107 typedef Benchmark INHERITED;
113 const size_t fCacheSize; 108 const size_t fCacheSize;
114 SkString fName; 109 SkString fName;
115 }; 110 };
116 111
117 DEF_BENCH( return new SkGlyphCacheBasic(256 * 1024); ) 112 DEF_BENCH( return new SkGlyphCacheBasic(256 * 1024); )
118 DEF_BENCH( return new SkGlyphCacheBasic(32 * 1024 * 1024); ) 113 DEF_BENCH( return new SkGlyphCacheBasic(32 * 1024 * 1024); )
119 DEF_BENCH( return new SkGlyphCacheStressTest(256 * 1024); ) 114 DEF_BENCH( return new SkGlyphCacheStressTest(256 * 1024); )
120 DEF_BENCH( return new SkGlyphCacheStressTest(32 * 1024 * 1024); ) 115 DEF_BENCH( return new SkGlyphCacheStressTest(32 * 1024 * 1024); )
OLDNEW
« no previous file with comments | « bench/CmapBench.cpp ('k') | bench/TextBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698