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

Side by Side Diff: gm/displacement.cpp

Issue 101623007: Fixed more issues (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed conflict with senorblanco's cl Created 7 years 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 | « expectations/gm/ignored-tests.txt ('k') | src/effects/SkDisplacementMapEffect.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 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 "SkDisplacementMapEffect.h" 9 #include "SkDisplacementMapEffect.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
11 11
12 namespace skiagm { 12 namespace skiagm {
13 13
14 class DisplacementMapGM : public GM { 14 class DisplacementMapGM : public GM {
15 public: 15 public:
16 DisplacementMapGM() : fInitialized(false) { 16 DisplacementMapGM() : fInitialized(false) {
17 this->setBGColor(0xFF000000); 17 this->setBGColor(0xFF000000);
18 } 18 }
19 19
20 protected: 20 protected:
21 virtual SkString onShortName() { 21 virtual SkString onShortName() {
22 return SkString("displacement"); 22 return SkString("displacement");
23 } 23 }
24 24
25 void make_bitmaps() {
26 make_bitmap();
27 make_checkerboard(&fCheckerboard, 80, 80);
28 make_checkerboard(&fSmall, 64, 64);
29 make_checkerboard(&fLarge, 96, 96);
30 make_checkerboard(&fLargeW, 96, 64);
31 make_checkerboard(&fLargeH, 64, 96);
32 }
33
25 void make_bitmap() { 34 void make_bitmap() {
26 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); 35 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 80, 80);
27 fBitmap.allocPixels(); 36 fBitmap.allocPixels();
28 SkBitmapDevice device(fBitmap); 37 SkBitmapDevice device(fBitmap);
29 SkCanvas canvas(&device); 38 SkCanvas canvas(&device);
30 canvas.clear(0x00000000); 39 canvas.clear(0x00000000);
31 SkPaint paint; 40 SkPaint paint;
32 paint.setAntiAlias(true); 41 paint.setAntiAlias(true);
33 paint.setColor(0xFF884422); 42 paint.setColor(0xFF884422);
34 paint.setTextSize(SkIntToScalar(96)); 43 paint.setTextSize(SkIntToScalar(96));
35 const char* str = "g"; 44 const char* str = "g";
36 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint); 45 canvas.drawText(str, strlen(str), SkIntToScalar(15), SkIntToScalar(55), paint);
37 } 46 }
38 47
39 void make_checkerboard() { 48 void make_checkerboard(SkBitmap* bitmap, int w, int h) {
40 fCheckerboard.setConfig(SkBitmap::kARGB_8888_Config, 80, 80); 49 bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h);
41 fCheckerboard.allocPixels(); 50 bitmap->allocPixels();
42 SkBitmapDevice device(fCheckerboard); 51 SkBitmapDevice device(*bitmap);
43 SkCanvas canvas(&device); 52 SkCanvas canvas(&device);
44 canvas.clear(0x00000000); 53 canvas.clear(0x00000000);
45 SkPaint darkPaint; 54 SkPaint darkPaint;
46 darkPaint.setColor(0xFF804020); 55 darkPaint.setColor(0xFF804020);
47 SkPaint lightPaint; 56 SkPaint lightPaint;
48 lightPaint.setColor(0xFF244484); 57 lightPaint.setColor(0xFF244484);
49 for (int y = 0; y < 80; y += 16) { 58 for (int y = 0; y < h; y += 16) {
50 for (int x = 0; x < 80; x += 16) { 59 for (int x = 0; x < w; x += 16) {
51 canvas.save(); 60 canvas.save();
52 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); 61 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
53 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); 62 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
54 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); 63 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
55 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); 64 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 65 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
57 canvas.restore(); 66 canvas.restore();
58 } 67 }
59 } 68 }
60 } 69 }
61 70
62 virtual SkISize onISize() { 71 virtual SkISize onISize() {
63 return make_isize(500, 400); 72 return make_isize(500, 500);
64 } 73 }
65 74
66 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { 75 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
67 canvas->save(); 76 canvas->save();
68 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 77 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
69 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS calar(fBitmap.height()))); 78 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS calar(fBitmap.height())));
70 canvas->drawBitmap(fBitmap, 0, 0, &paint); 79 canvas->drawBitmap(fBitmap, 0, 0, &paint);
71 canvas->restore(); 80 canvas->restore();
72 } 81 }
73 82
74 virtual void onDraw(SkCanvas* canvas) { 83 virtual void onDraw(SkCanvas* canvas) {
75 if (!fInitialized) { 84 if (!fInitialized) {
76 make_bitmap(); 85 make_bitmaps();
77 make_checkerboard();
78 fInitialized = true; 86 fInitialized = true;
79 } 87 }
80 canvas->clear(0x00000000); 88 canvas->clear(0x00000000);
81 SkPaint paint; 89 SkPaint paint;
82 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard))); 90 SkAutoTUnref<SkImageFilter> displ(SkNEW_ARGS(SkBitmapSource, (fCheckerbo ard)));
83 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 91 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
84 (SkDisplacementMapEffect::kR_ChannelSelectorType, 92 (SkDisplacementMapEffect::kR_ChannelSelectorType,
85 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref(); 93 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ)))->un ref();
86 drawClippedBitmap(canvas, 0, 0, paint); 94 drawClippedBitmap(canvas, 0, 0, paint);
87 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 95 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 175 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
168 (SkDisplacementMapEffect::kG_ChannelSelectorType, 176 (SkDisplacementMapEffect::kG_ChannelSelectorType,
169 SkDisplacementMapEffect::kA_ChannelSelectorType, 177 SkDisplacementMapEffect::kA_ChannelSelectorType,
170 40.0f, displ, NULL, &cropRect)))->unref(); 178 40.0f, displ, NULL, &cropRect)))->unref();
171 drawClippedBitmap(canvas, 300, 300, paint); 179 drawClippedBitmap(canvas, 300, 300, paint);
172 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 180 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
173 (SkDisplacementMapEffect::kR_ChannelSelectorType, 181 (SkDisplacementMapEffect::kR_ChannelSelectorType,
174 SkDisplacementMapEffect::kA_ChannelSelectorType, 182 SkDisplacementMapEffect::kA_ChannelSelectorType,
175 40.0f, displ, NULL, &cropRect)))->unref(); 183 40.0f, displ, NULL, &cropRect)))->unref();
176 drawClippedBitmap(canvas, 400, 300, paint); 184 drawClippedBitmap(canvas, 400, 300, paint);
185
186 displ.reset(SkNEW_ARGS(SkBitmapSource, (fSmall)));
187 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
188 (SkDisplacementMapEffect::kR_ChannelSelectorType,
189 SkDisplacementMapEffect::kG_ChannelSelectorType,
190 40.0f, displ)))->unref();
191 drawClippedBitmap(canvas, 0, 400, paint);
192 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLarge)));
193 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
194 (SkDisplacementMapEffect::kB_ChannelSelectorType,
195 SkDisplacementMapEffect::kA_ChannelSelectorType,
196 40.0f, displ)))->unref();
197 drawClippedBitmap(canvas, 100, 400, paint);
198 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeW)));
199 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
200 (SkDisplacementMapEffect::kR_ChannelSelectorType,
201 SkDisplacementMapEffect::kB_ChannelSelectorType,
202 40.0f, displ)))->unref();
203 drawClippedBitmap(canvas, 200, 400, paint);
204 displ.reset(SkNEW_ARGS(SkBitmapSource, (fLargeH)));
205 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
206 (SkDisplacementMapEffect::kG_ChannelSelectorType,
207 SkDisplacementMapEffect::kA_ChannelSelectorType,
208 40.0f, displ)))->unref();
209 drawClippedBitmap(canvas, 300, 400, paint);
177 } 210 }
178 211
179 private: 212 private:
180 typedef GM INHERITED; 213 typedef GM INHERITED;
181 SkBitmap fBitmap, fCheckerboard; 214 SkBitmap fBitmap, fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
182 bool fInitialized; 215 bool fInitialized;
183 }; 216 };
184 217
185 ////////////////////////////////////////////////////////////////////////////// 218 //////////////////////////////////////////////////////////////////////////////
186 219
187 static GM* MyFactory(void*) { return new DisplacementMapGM; } 220 static GM* MyFactory(void*) { return new DisplacementMapGM; }
188 static GMRegistry reg(MyFactory); 221 static GMRegistry reg(MyFactory);
189 222
190 } 223 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | src/effects/SkDisplacementMapEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698