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

Side by Side Diff: gm/tilemodes_scaled.cpp

Issue 23779003: first cut at HQ GPU scaling; refactored existing bicubic scaler (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: final version for trybots Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gyp/effects.gyp » ('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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkRegion.h" 10 #include "SkRegion.h"
(...skipping 25 matching lines...) Expand all
36 // um = new SkDiscreteMapper(12); 36 // um = new SkDiscreteMapper(12);
37 37
38 SkAutoUnref au(um); 38 SkAutoUnref au(um);
39 39
40 paint.setDither(true); 40 paint.setDither(true);
41 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, 41 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
42 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref() ; 42 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref() ;
43 canvas.drawPaint(paint); 43 canvas.drawPaint(paint);
44 } 44 }
45 45
46 static void setup(SkPaint* paint, const SkBitmap& bm, bool filter, 46 static void setup(SkPaint* paint, const SkBitmap& bm, SkPaint::FilterLevel filte r_level,
47 SkShader::TileMode tmx, SkShader::TileMode tmy) { 47 SkShader::TileMode tmx, SkShader::TileMode tmy) {
48 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy); 48 SkShader* shader = SkShader::CreateBitmapShader(bm, tmx, tmy);
49 paint->setShader(shader)->unref(); 49 paint->setShader(shader)->unref();
50 paint->setFilterBitmap(filter); 50 paint->setFilterLevel(filter_level);
51 } 51 }
52 52
53 static const SkBitmap::Config gConfigs[] = { 53 static const SkBitmap::Config gConfigs[] = {
54 SkBitmap::kARGB_8888_Config, 54 SkBitmap::kARGB_8888_Config,
55 SkBitmap::kRGB_565_Config, 55 SkBitmap::kRGB_565_Config,
56 }; 56 };
57 57
58 class TilingGM : public skiagm::GM { 58 class ScaledTilingGM : public skiagm::GM {
59 SkBlurDrawLooper fLooper;
59 public: 60 public:
60 TilingGM(bool powerOfTwoSize) 61 ScaledTilingGM(bool powerOfTwoSize)
61 : fPowerOfTwoSize(powerOfTwoSize) { 62 : fLooper(SkIntToScalar(1), SkIntToScalar(2), SkIntToScalar(2), 0x88 000000)
63 , fPowerOfTwoSize(powerOfTwoSize) {
62 } 64 }
63 65
64 SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)]; 66 SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)];
65 67
66 protected: 68 protected:
67 69
68 enum { 70 enum {
69 kPOTSize = 32, 71 kPOTSize = 4,
70 kNPOTSize = 21, 72 kNPOTSize = 3,
71 }; 73 };
72 74
73 SkString onShortName() { 75 SkString onShortName() {
74 SkString name("tilemodes"); 76 SkString name("scaled_tilemodes");
75 if (!fPowerOfTwoSize) { 77 if (!fPowerOfTwoSize) {
76 name.append("_npot"); 78 name.append("_npot");
77 } 79 }
78 return name; 80 return name;
79 } 81 }
80 82
81 SkISize onISize() { return SkISize::Make(880, 560); } 83 SkISize onISize() { return SkISize::Make(880, 760); }
82 84
83 virtual void onOnceBeforeDraw() SK_OVERRIDE { 85 virtual void onOnceBeforeDraw() SK_OVERRIDE {
84 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; 86 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
85 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { 87 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
86 makebm(&fTexture[i], gConfigs[i], size, size); 88 makebm(&fTexture[i], gConfigs[i], size, size);
87 } 89 }
88 } 90 }
89 91
90 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 92 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
93
94 float scale = 32.f/kPOTSize;
91 95
92 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize; 96 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
93 97
94 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) }; 98 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) };
95 99
96 static const char* gConfigNames[] = { "8888", "565", "4444" }; 100 static const char* gConfigNames[] = { "8888" , "565", "4444" };
97 101
98 static const bool gFilters[] = { false, true }; 102 static const SkPaint::FilterLevel gFilterLevels[] =
99 static const char* gFilterNames[] = { "point", "bilinear" }; 103 { SkPaint::kNone_FilterLevel,
104 SkPaint::kLow_FilterLevel,
105 SkPaint::kMedium_FilterLevel,
106 SkPaint::kHigh_FilterLevel };
107 static const char* gFilterNames[] = { "None", "Low", "Medium", "High" };
100 108
101 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; 109 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode };
102 static const char* gModeNames[] = { "C", "R", "M" }; 110 static const char* gModeNames[] = { "C", "R", "M" };
103 111
104 SkScalar y = SkIntToScalar(24); 112 SkScalar y = SkIntToScalar(24);
105 SkScalar x = SkIntToScalar(10); 113 SkScalar x = SkIntToScalar(10)/scale;
106 114
107 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 115 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
108 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 116 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
109 SkPaint p; 117 SkPaint p;
110 SkString str; 118 SkString str;
111 p.setAntiAlias(true); 119 p.setAntiAlias(true);
112 p.setDither(true); 120 p.setDither(true);
121 p.setLooper(&fLooper);
113 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]); 122 str.printf("[%s,%s]", gModeNames[kx], gModeNames[ky]);
114 123
115 p.setTextAlign(SkPaint::kCenter_Align); 124 p.setTextAlign(SkPaint::kCenter_Align);
116 canvas->drawText(str.c_str(), str.size(), x + r.width()/2, y, p) ; 125 canvas->drawText(str.c_str(), str.size(), scale*(x + r.width()/2 ), y, p);
117 126
118 x += r.width() * 4 / 3; 127 x += r.width() * 4 / 3;
119 } 128 }
120 } 129 }
121 130
122 y += SkIntToScalar(16); 131 y = SkIntToScalar(40) / scale;
123 132
124 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { 133 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
125 for (size_t j = 0; j < SK_ARRAY_COUNT(gFilters); j++) { 134 for (size_t j = 0; j < SK_ARRAY_COUNT(gFilterLevels); j++) {
126 x = SkIntToScalar(10); 135 x = SkIntToScalar(10)/scale;
127 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) { 136 for (size_t kx = 0; kx < SK_ARRAY_COUNT(gModes); kx++) {
128 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) { 137 for (size_t ky = 0; ky < SK_ARRAY_COUNT(gModes); ky++) {
129 SkPaint paint; 138 SkPaint paint;
130 #if 1 // Temporary change to regen bitmap before each draw. This may help tracki ng down an issue 139 #if 1 // Temporary change to regen bitmap before each draw. This may help tracki ng down an issue
131 // on SGX where resizing NPOT textures to POT textures exhibits a driver b ug. 140 // on SGX where resizing NPOT textures to POT textures exhibits a driver b ug.
132 if (!fPowerOfTwoSize) { 141 if (!fPowerOfTwoSize) {
133 makebm(&fTexture[i], gConfigs[i], size, size); 142 makebm(&fTexture[i], gConfigs[i], size, size);
134 } 143 }
135 #endif 144 #endif
136 setup(&paint, fTexture[i], gFilters[j], gModes[kx], gMod es[ky]); 145 setup(&paint, fTexture[i], gFilterLevels[j], gModes[kx], gModes[ky]);
137 paint.setDither(true); 146 paint.setDither(true);
138 147
139 canvas->save(); 148 canvas->save();
149 canvas->scale(scale,scale);
140 canvas->translate(x, y); 150 canvas->translate(x, y);
141 canvas->drawRect(r, paint); 151 canvas->drawRect(r, paint);
142 canvas->restore(); 152 canvas->restore();
143 153
144 x += r.width() * 4 / 3; 154 x += r.width() * 4 / 3;
145 } 155 }
146 } 156 }
147 { 157 {
148 SkPaint p; 158 SkPaint p;
149 SkString str; 159 SkString str;
150 p.setAntiAlias(true); 160 p.setAntiAlias(true);
161 p.setLooper(&fLooper);
151 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); 162 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]);
152 canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); 163 canvas->drawText(str.c_str(), str.size(), scale*x, scale*(y + r.height() * 2 / 3), p);
153 } 164 }
154 165
155 y += r.height() * 4 / 3; 166 y += r.height() * 4 / 3;
156 } 167 }
157 } 168 }
158 } 169 }
159 170
160 private: 171 private:
161 bool fPowerOfTwoSize; 172 bool fPowerOfTwoSize;
162 typedef skiagm::GM INHERITED; 173 typedef skiagm::GM INHERITED;
(...skipping 22 matching lines...) Expand all
185 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_ ARRAY_COUNT(colors), tx); 196 return SkGradientShader::CreateRadial(center, rad, colors, NULL, SK_ ARRAY_COUNT(colors), tx);
186 case 2: 197 case 2:
187 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N ULL, SK_ARRAY_COUNT(colors)); 198 return SkGradientShader::CreateSweep(center.fX, center.fY, colors, N ULL, SK_ARRAY_COUNT(colors));
188 } 199 }
189 200
190 return NULL; 201 return NULL;
191 } 202 }
192 203
193 typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode); 204 typedef SkShader* (*ShaderProc)(SkShader::TileMode, SkShader::TileMode);
194 205
195 class Tiling2GM : public skiagm::GM { 206 class ScaledTiling2GM : public skiagm::GM {
196 ShaderProc fProc; 207 ShaderProc fProc;
197 SkString fName; 208 SkString fName;
198 public: 209 public:
199 Tiling2GM(ShaderProc proc, const char name[]) : fProc(proc) { 210 ScaledTiling2GM(ShaderProc proc, const char name[]) : fProc(proc) {
200 fName.printf("tilemode_%s", name); 211 fName.printf("scaled_tilemode_%s", name);
201 } 212 }
202 213
203 protected: 214 protected:
204 SkString onShortName() { 215 SkString onShortName() {
205 return fName; 216 return fName;
206 } 217 }
207 218
208 SkISize onISize() { return SkISize::Make(880, 560); } 219 SkISize onISize() { return SkISize::Make(880, 560); }
209 220
210 virtual void onDraw(SkCanvas* canvas) { 221 virtual void onDraw(SkCanvas* canvas) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 y += r.height() * 4 / 3; 269 y += r.height() * 4 / 3;
259 } 270 }
260 } 271 }
261 272
262 private: 273 private:
263 typedef skiagm::GM INHERITED; 274 typedef skiagm::GM INHERITED;
264 }; 275 };
265 276
266 ////////////////////////////////////////////////////////////////////////////// 277 //////////////////////////////////////////////////////////////////////////////
267 278
268 DEF_GM( return new TilingGM(true); ) 279 DEF_GM( return new ScaledTilingGM(true); )
269 DEF_GM( return new TilingGM(false); ) 280 DEF_GM( return new ScaledTilingGM(false); )
270 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) 281 DEF_GM( return new ScaledTiling2GM(make_bm, "bitmap"); )
271 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) 282 DEF_GM( return new ScaledTiling2GM(make_grad, "gradient"); )
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698