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

Side by Side Diff: gm/tilemodes.cpp

Issue 20204006: Add NPOT version of tilemodes GM (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 /* 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->setFilterBitmap(filter);
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 static const int gWidth = 32;
58 static const int gHeight = 32;
59 57
60 class TilingGM : public skiagm::GM { 58 class TilingGM : public skiagm::GM {
61 SkBlurDrawLooper fLooper; 59 SkBlurDrawLooper fLooper;
62 public: 60 public:
63 TilingGM() 61 TilingGM(bool powerOfTwoSize)
64 : fLooper(SkIntToScalar(1), SkIntToScalar(2), SkIntToScalar(2), 62 : fLooper(SkIntToScalar(1), SkIntToScalar(2), SkIntToScalar(2), 0x88 000000)
65 0x88000000) { 63 , fPowerOfTwoSize(powerOfTwoSize) {
66 } 64 }
67 65
68 SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)]; 66 SkBitmap fTexture[SK_ARRAY_COUNT(gConfigs)];
69 67
70 protected: 68 protected:
69
70 enum {
71 kPOTSize = 32,
72 kNPOTSize = 21,
73 };
74
71 SkString onShortName() { 75 SkString onShortName() {
72 return SkString("tilemodes"); 76 SkString name("tilemodes");
77 if (!fPowerOfTwoSize) {
78 name.append("_npot");
79 }
80 return name;
73 } 81 }
74 82
75 SkISize onISize() { return SkISize::Make(880, 560); } 83 SkISize onISize() { return SkISize::Make(880, 560); }
76 84
77 virtual void onOnceBeforeDraw() SK_OVERRIDE { 85 virtual void onOnceBeforeDraw() SK_OVERRIDE {
86 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
78 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) { 87 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); i++) {
79 makebm(&fTexture[i], gConfigs[i], gWidth, gHeight); 88 makebm(&fTexture[i], gConfigs[i], size, size);
80 } 89 }
81 } 90 }
82 91
83 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 92 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
84 93
85 SkRect r = { 0, 0, SkIntToScalar(gWidth*2), SkIntToScalar(gHeight*2) }; 94 int size = fPowerOfTwoSize ? kPOTSize : kNPOTSize;
95
96 SkRect r = { 0, 0, SkIntToScalar(size*2), SkIntToScalar(size*2) };
86 97
87 static const char* gConfigNames[] = { "8888", "565", "4444" }; 98 static const char* gConfigNames[] = { "8888", "565", "4444" };
88 99
89 static const bool gFilters[] = { false, true }; 100 static const bool gFilters[] = { false, true };
90 static const char* gFilterNames[] = { "point", "bilinear" }; 101 static const char* gFilterNames[] = { "point", "bilinear" };
91 102
92 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode }; 103 static const SkShader::TileMode gModes[] = { SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode };
93 static const char* gModeNames[] = { "C", "R", "M" }; 104 static const char* gModeNames[] = { "C", "R", "M" };
94 105
95 SkScalar y = SkIntToScalar(24); 106 SkScalar y = SkIntToScalar(24);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]); 149 str.printf("%s, %s", gConfigNames[i], gFilterNames[j]);
139 canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p); 150 canvas->drawText(str.c_str(), str.size(), x, y + r.height() * 2 / 3, p);
140 } 151 }
141 152
142 y += r.height() * 4 / 3; 153 y += r.height() * 4 / 3;
143 } 154 }
144 } 155 }
145 } 156 }
146 157
147 private: 158 private:
159 bool fPowerOfTwoSize;
148 typedef skiagm::GM INHERITED; 160 typedef skiagm::GM INHERITED;
149 }; 161 };
150 162
163 static const int gWidth = 32;
164 static const int gHeight = 32;
165
151 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) { 166 static SkShader* make_bm(SkShader::TileMode tx, SkShader::TileMode ty) {
152 SkBitmap bm; 167 SkBitmap bm;
153 makebm(&bm, SkBitmap::kARGB_8888_Config, gWidth, gHeight); 168 makebm(&bm, SkBitmap::kARGB_8888_Config, gWidth, gHeight);
154 return SkShader::CreateBitmapShader(bm, tx, ty); 169 return SkShader::CreateBitmapShader(bm, tx, ty);
155 } 170 }
156 171
157 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) { 172 static SkShader* make_grad(SkShader::TileMode tx, SkShader::TileMode ty) {
158 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} }; 173 SkPoint pts[] = { { 0, 0 }, { SkIntToScalar(gWidth), SkIntToScalar(gHeight)} };
159 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 }; 174 SkPoint center = { SkIntToScalar(gWidth)/2, SkIntToScalar(gHeight)/2 };
160 SkScalar rad = SkIntToScalar(gWidth)/2; 175 SkScalar rad = SkIntToScalar(gWidth)/2;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 y += r.height() * 4 / 3; 256 y += r.height() * 4 / 3;
242 } 257 }
243 } 258 }
244 259
245 private: 260 private:
246 typedef skiagm::GM INHERITED; 261 typedef skiagm::GM INHERITED;
247 }; 262 };
248 263
249 ////////////////////////////////////////////////////////////////////////////// 264 //////////////////////////////////////////////////////////////////////////////
250 265
251 DEF_GM( return new TilingGM; ) 266 DEF_GM( return new TilingGM(true); )
267 DEF_GM( return new TilingGM(false); )
252 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); ) 268 DEF_GM( return new Tiling2GM(make_bm, "bitmap"); )
253 DEF_GM( return new Tiling2GM(make_grad, "gradient"); ) 269 DEF_GM( return new Tiling2GM(make_grad, "gradient"); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698