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

Side by Side Diff: bench/SkGlyphCacheBench.cpp

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

Powered by Google App Engine
This is Rietveld 408576698