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

Side by Side Diff: gm/displacement.cpp

Issue 26531002: Add crop rect support for SkDisplacementMapEffect (raster and GPU paths). (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Update to new CropRect API. Created 7 years, 2 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 | « expectations/gm/ignored-tests.txt ('k') | include/effects/SkDisplacementMapEffect.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 "SkDisplacementMapEffect.h" 9 #include "SkDisplacementMapEffect.h"
10 #include "SkBitmapSource.h" 10 #include "SkBitmapSource.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); 53 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
54 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); 54 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
55 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); 55 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); 56 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
57 canvas.restore(); 57 canvas.restore();
58 } 58 }
59 } 59 }
60 } 60 }
61 61
62 virtual SkISize onISize() { 62 virtual SkISize onISize() {
63 return make_isize(500, 200); 63 return make_isize(500, 400);
64 } 64 }
65 65
66 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { 66 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
67 canvas->save(); 67 canvas->save();
68 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), 68 canvas->translate(x, y);
69 SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()))); 69 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS calar(fBitmap.height())));
70 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); 70 canvas->drawBitmap(fBitmap, 0, 0, &paint);
71 canvas->restore(); 71 canvas->restore();
72 } 72 }
73 73
74 virtual void onDraw(SkCanvas* canvas) { 74 virtual void onDraw(SkCanvas* canvas) {
75 if (!fInitialized) { 75 if (!fInitialized) {
76 make_bitmap(); 76 make_bitmap();
77 make_checkerboard(); 77 make_checkerboard();
78 fInitialized = true; 78 fInitialized = true;
79 } 79 }
80 canvas->clear(0x00000000); 80 canvas->clear(0x00000000);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ)))->u nref(); 114 SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ)))->u nref();
115 drawClippedBitmap(canvas, 200, 100, paint); 115 drawClippedBitmap(canvas, 200, 100, paint);
116 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 116 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
117 (SkDisplacementMapEffect::kG_ChannelSelectorType, 117 (SkDisplacementMapEffect::kG_ChannelSelectorType,
118 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref(); 118 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref();
119 drawClippedBitmap(canvas, 300, 100, paint); 119 drawClippedBitmap(canvas, 300, 100, paint);
120 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect, 120 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
121 (SkDisplacementMapEffect::kR_ChannelSelectorType, 121 (SkDisplacementMapEffect::kR_ChannelSelectorType,
122 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref(); 122 SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ)))->u nref();
123 drawClippedBitmap(canvas, 400, 100, paint); 123 drawClippedBitmap(canvas, 400, 100, paint);
124
125 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40));
126 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
127 (SkDisplacementMapEffect::kR_ChannelSelectorType,
128 SkDisplacementMapEffect::kG_ChannelSelectorType,
129 0.0f, displ, NULL, &cropRect)))->unref();
130 drawClippedBitmap(canvas, 0, 200, paint);
131 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
132 (SkDisplacementMapEffect::kB_ChannelSelectorType,
133 SkDisplacementMapEffect::kA_ChannelSelectorType,
134 16.0f, displ, NULL, &cropRect)))->unref();
135 drawClippedBitmap(canvas, 100, 200, paint);
136 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
137 (SkDisplacementMapEffect::kR_ChannelSelectorType,
138 SkDisplacementMapEffect::kB_ChannelSelectorType,
139 32.0f, displ, NULL, &cropRect)))->unref();
140 drawClippedBitmap(canvas, 200, 200, paint);
141 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
142 (SkDisplacementMapEffect::kG_ChannelSelectorType,
143 SkDisplacementMapEffect::kA_ChannelSelectorType,
144 48.0f, displ, NULL, &cropRect)))->unref();
145 drawClippedBitmap(canvas, 300, 200, paint);
146 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
147 (SkDisplacementMapEffect::kR_ChannelSelectorType,
148 SkDisplacementMapEffect::kA_ChannelSelectorType,
149 64.0f, displ, NULL, &cropRect)))->unref();
150 drawClippedBitmap(canvas, 400, 200, paint);
151
152 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
153 (SkDisplacementMapEffect::kR_ChannelSelectorType,
154 SkDisplacementMapEffect::kG_ChannelSelectorType,
155 40.0f, displ, NULL, &cropRect)))->unref();
156 drawClippedBitmap(canvas, 0, 300, paint);
157 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
158 (SkDisplacementMapEffect::kB_ChannelSelectorType,
159 SkDisplacementMapEffect::kA_ChannelSelectorType,
160 40.0f, displ, NULL, &cropRect)))->unref();
161 drawClippedBitmap(canvas, 100, 300, paint);
162 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
163 (SkDisplacementMapEffect::kR_ChannelSelectorType,
164 SkDisplacementMapEffect::kB_ChannelSelectorType,
165 40.0f, displ, NULL, &cropRect)))->unref();
166 drawClippedBitmap(canvas, 200, 300, paint);
167 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
168 (SkDisplacementMapEffect::kG_ChannelSelectorType,
169 SkDisplacementMapEffect::kA_ChannelSelectorType,
170 40.0f, displ, NULL, &cropRect)))->unref();
171 drawClippedBitmap(canvas, 300, 300, paint);
172 paint.setImageFilter(SkNEW_ARGS(SkDisplacementMapEffect,
173 (SkDisplacementMapEffect::kR_ChannelSelectorType,
174 SkDisplacementMapEffect::kA_ChannelSelectorType,
175 40.0f, displ, NULL, &cropRect)))->unref();
176 drawClippedBitmap(canvas, 400, 300, paint);
124 } 177 }
125 178
126 private: 179 private:
127 typedef GM INHERITED; 180 typedef GM INHERITED;
128 SkBitmap fBitmap, fCheckerboard; 181 SkBitmap fBitmap, fCheckerboard;
129 bool fInitialized; 182 bool fInitialized;
130 }; 183 };
131 184
132 ////////////////////////////////////////////////////////////////////////////// 185 //////////////////////////////////////////////////////////////////////////////
133 186
134 static GM* MyFactory(void*) { return new DisplacementMapGM; } 187 static GM* MyFactory(void*) { return new DisplacementMapGM; }
135 static GMRegistry reg(MyFactory); 188 static GMRegistry reg(MyFactory);
136 189
137 } 190 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | include/effects/SkDisplacementMapEffect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698