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

Side by Side Diff: gm/fontcache.cpp

Issue 517123005: Revert Jim's CL. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: undo Created 6 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 | « no previous file | src/gpu/GrBitmapTextContext.h » ('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 2013 Google Inc. 2 * Copyright 2013 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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
11 #include "SkTypeface.h" 11 #include "SkTypeface.h"
12 12
13 // GM to stress the GPU font cache 13 // GM to stress the GPU font cache
14 14
15 const char* gFamilyNames[] = { 15 const char* gFamilyNames[] = {
16 "sans-serif", "serif" 16 "sans-serif", "serif", "monospace"
17 }; 17 };
18 18
19 const SkTypeface::Style gStyles[] = { 19 const SkTypeface::Style gStyles[] = {
20 SkTypeface::kNormal, SkTypeface::kItalic, SkTypeface::kBold 20 SkTypeface::kNormal, SkTypeface::kItalic
21 }; 21 };
22 22
23 const SkScalar gTextSizes[] = { 23 const SkScalar gTextSizes[] = {
24 192, 194, 196, 198, 200, 202, 204, 206 24 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
25 }; 25 };
26 26
27 #define TYPEFACE_COUNT (SK_ARRAY_COUNT(gFamilyNames)*SK_ARRAY_COUNT(gStyles)) 27 #define TYPEFACE_COUNT (SK_ARRAY_COUNT(gFamilyNames)*SK_ARRAY_COUNT(gStyles))
28 28
29 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, 29 static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
30 SkScalar y, const SkPaint& paint) { 30 SkScalar y, const SkPaint& paint) {
31 canvas->drawText(text.c_str(), text.size(), x, y, paint); 31 canvas->drawText(text.c_str(), text.size(), x, y, paint);
32 return x + paint.measureText(text.c_str(), text.size()); 32 return x + paint.measureText(text.c_str(), text.size());
33 } 33 }
34 34
(...skipping 10 matching lines...) Expand all
45 SkSafeUnref(fTypefaces[i]); 45 SkSafeUnref(fTypefaces[i]);
46 } 46 }
47 } 47 }
48 48
49 protected: 49 protected:
50 virtual SkString onShortName() SK_OVERRIDE { 50 virtual SkString onShortName() SK_OVERRIDE {
51 return SkString("fontcache"); 51 return SkString("fontcache");
52 } 52 }
53 53
54 virtual SkISize onISize() SK_OVERRIDE { 54 virtual SkISize onISize() SK_OVERRIDE {
55 return SkISize::Make(1280, 640); 55 return SkISize::Make(640, 320);
56 } 56 }
57 57
58 virtual void onOnceBeforeDraw() SK_OVERRIDE { 58 virtual void onOnceBeforeDraw() SK_OVERRIDE {
59 int typefaceCount = 0; 59 int typefaceCount = 0;
60 for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) { 60 for (size_t i = 0; i < SK_ARRAY_COUNT(gFamilyNames); ++i) {
61 for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) { 61 for (size_t j = 0; j < SK_ARRAY_COUNT(gStyles); ++j) {
62 fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typ eface(gFamilyNames[i], 62 fTypefaces[typefaceCount++] = sk_tool_utils::create_portable_typ eface(gFamilyNames[i],
63 g Styles[j]); 63 g Styles[j]);
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 68 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
69 SkScalar y = 32; 69 SkScalar y = 32;
70 SkPaint paint; 70 SkPaint paint;
71 paint.setAntiAlias(true); 71 paint.setAntiAlias(true);
72 paint.setLCDRenderText(true); 72 paint.setLCDRenderText(true);
73 paint.setSubpixelText(true); 73 paint.setSubpixelText(true);
74 74
75 SkString text("H"); 75 SkString text("Ham");
76 76
77 // draw enough to overflow the cache 77 // draw some initial text to partially fill the GPU cache
78 for (size_t i = 0; i < 2; ++i) {
79 paint.setTypeface(fTypefaces[i]);
80 SkScalar x = 20;
81
82 for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
83 paint.setTextSize(gTextSizes[j]);
84 x = draw_string(canvas, text, x, y, paint) + 19;
85 }
86 y += 32;
87 }
88
89 // force a flush
90 canvas->flush();
91
92 // draw again, and more to overflow the cache
78 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) { 93 for (size_t i = 0; i < TYPEFACE_COUNT; ++i) {
79 paint.setTypeface(fTypefaces[i]); 94 paint.setTypeface(fTypefaces[i]);
80 SkScalar x = 20; 95 SkScalar x = 20;
81 96
82 for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) { 97 for (size_t j = 0; j < SK_ARRAY_COUNT(gTextSizes); ++j) {
83 paint.setTextSize(gTextSizes[j]); 98 paint.setTextSize(gTextSizes[j]);
84 x = draw_string(canvas, text, x, y, paint) + 10; 99 x = draw_string(canvas, text, x, y, paint) + 19;
85 } 100 }
86 y += 128; 101 y += 32;
87 } 102 }
103
88 } 104 }
89 105
90 virtual uint32_t onGetFlags() const SK_OVERRIDE { 106 virtual uint32_t onGetFlags() const SK_OVERRIDE {
91 // this GM is meant only for the GPU 107 // this GM is meant only for the GPU
92 return kGPUOnly_Flag; 108 return kGPUOnly_Flag;
93 } 109 }
94 110
95 private: 111 private:
96 SkTypeface* fTypefaces[TYPEFACE_COUNT]; 112 SkTypeface* fTypefaces[TYPEFACE_COUNT];
97 typedef GM INHERITED; 113 typedef GM INHERITED;
98 }; 114 };
99 115
100 116
101 ////////////////////////////////////////////////////////////////////////////// 117 //////////////////////////////////////////////////////////////////////////////
102 118
103 DEF_GM( return SkNEW(FontCacheGM); ) 119 DEF_GM( return SkNEW(FontCacheGM); )
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrBitmapTextContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698