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

Side by Side Diff: gm/displacement.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage Created 4 years, 9 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 | « gm/dftext.cpp ('k') | gm/drawatlas.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 "SkDisplacementMapEffect.h" 8 #include "SkDisplacementMapEffect.h"
9 #include "SkImage.h" 9 #include "SkImage.h"
10 #include "SkImageSource.h" 10 #include "SkImageSource.h"
(...skipping 12 matching lines...) Expand all
23 SkString onShortName() override { 23 SkString onShortName() override {
24 return SkString("displacement"); 24 return SkString("displacement");
25 } 25 }
26 26
27 void onOnceBeforeDraw() override { 27 void onOnceBeforeDraw() override {
28 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xFF884422, 15, 55 , 96, "g"); 28 fBitmap = sk_tool_utils::create_string_bitmap(80, 80, 0xFF884422, 15, 55 , 96, "g");
29 29
30 SkColor c1 = sk_tool_utils::color_to_565(0xFF244484); 30 SkColor c1 = sk_tool_utils::color_to_565(0xFF244484);
31 SkColor c2 = sk_tool_utils::color_to_565(0xFF804020); 31 SkColor c2 = sk_tool_utils::color_to_565(0xFF804020);
32 32
33 fCheckerboard.reset(SkImage::NewFromBitmap( 33 fCheckerboard = SkImage::MakeFromBitmap(
34 sk_tool_utils::create_checkerboard_bitmap(80, 80, c1, c2, 8))); 34 sk_tool_utils::create_checkerboard_bitmap(80, 80, c1, c2, 8));
35 fSmall.reset(SkImage::NewFromBitmap( 35 fSmall = SkImage::MakeFromBitmap(
36 sk_tool_utils::create_checkerboard_bitmap(64, 64, c1, c2, 8))); 36 sk_tool_utils::create_checkerboard_bitmap(64, 64, c1, c2, 8));
37 fLarge.reset(SkImage::NewFromBitmap( 37 fLarge = SkImage::MakeFromBitmap(
38 sk_tool_utils::create_checkerboard_bitmap(96, 96, c1, c2, 8))); 38 sk_tool_utils::create_checkerboard_bitmap(96, 96, c1, c2, 8));
39 fLargeW.reset( 39 fLargeW =
40 SkImage::NewFromBitmap(sk_tool_utils::create_checkerboard_bitmap(96, 64, c1, c2, 8))); 40 SkImage::MakeFromBitmap(sk_tool_utils::create_checkerboard_bitmap(96 , 64, c1, c2, 8));
41 fLargeH.reset(SkImage::NewFromBitmap( 41 fLargeH = SkImage::MakeFromBitmap(
42 sk_tool_utils::create_checkerboard_bitmap(64, 96, c1, c2, 8))); 42 sk_tool_utils::create_checkerboard_bitmap(64, 96, c1, c2, 8));
43 } 43 }
44 44
45 SkISize onISize() override { 45 SkISize onISize() override {
46 return SkISize::Make(600, 500); 46 return SkISize::Make(600, 500);
47 } 47 }
48 48
49 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) const { 49 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) const {
50 canvas->save(); 50 canvas->save();
51 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 51 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
52 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS calar(fBitmap.height()))); 52 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), SkIntToS calar(fBitmap.height())));
53 canvas->drawBitmap(fBitmap, 0, 0, &paint); 53 canvas->drawBitmap(fBitmap, 0, 0, &paint);
54 canvas->restore(); 54 canvas->restore();
55 } 55 }
56 56
57 void onDraw(SkCanvas* canvas) override { 57 void onDraw(SkCanvas* canvas) override {
58 canvas->clear(SK_ColorBLACK); 58 canvas->clear(SK_ColorBLACK);
59 SkPaint paint; 59 SkPaint paint;
60 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard)); 60 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.ge t()));
61 paint.setImageFilter(SkDisplacementMapEffect::Create( 61 paint.setImageFilter(SkDisplacementMapEffect::Create(
62 SkDisplacementMapEffect::kR_ChannelSelectorType, 62 SkDisplacementMapEffect::kR_ChannelSelectorType,
63 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f(); 63 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre f();
64 drawClippedBitmap(canvas, 0, 0, paint); 64 drawClippedBitmap(canvas, 0, 0, paint);
65 paint.setImageFilter(SkDisplacementMapEffect::Create( 65 paint.setImageFilter(SkDisplacementMapEffect::Create(
66 SkDisplacementMapEffect::kB_ChannelSelectorType, 66 SkDisplacementMapEffect::kB_ChannelSelectorType,
67 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef(); 67 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr ef();
68 drawClippedBitmap(canvas, 100, 0, paint); 68 drawClippedBitmap(canvas, 100, 0, paint);
69 paint.setImageFilter(SkDisplacementMapEffect::Create( 69 paint.setImageFilter(SkDisplacementMapEffect::Create(
70 SkDisplacementMapEffect::kR_ChannelSelectorType, 70 SkDisplacementMapEffect::kR_ChannelSelectorType,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 drawClippedBitmap(canvas, 400, 300, paint); 154 drawClippedBitmap(canvas, 400, 300, paint);
155 155
156 // Test for negative scale. 156 // Test for negative scale.
157 paint.setImageFilter(SkDisplacementMapEffect::Create( 157 paint.setImageFilter(SkDisplacementMapEffect::Create(
158 SkDisplacementMapEffect::kG_ChannelSelectorType, 158 SkDisplacementMapEffect::kG_ChannelSelectorType,
159 SkDisplacementMapEffect::kA_ChannelSelectorType, 159 SkDisplacementMapEffect::kA_ChannelSelectorType,
160 -40.0f, displ))->unref(); 160 -40.0f, displ))->unref();
161 this->drawClippedBitmap(canvas, 500, 0, paint); 161 this->drawClippedBitmap(canvas, 500, 0, paint);
162 162
163 // Tests for images of different sizes 163 // Tests for images of different sizes
164 displ.reset(SkImageSource::Create(fSmall)); 164 displ.reset(SkImageSource::Create(fSmall.get()));
165 paint.setImageFilter(SkDisplacementMapEffect::Create( 165 paint.setImageFilter(SkDisplacementMapEffect::Create(
166 SkDisplacementMapEffect::kR_ChannelSelectorType, 166 SkDisplacementMapEffect::kR_ChannelSelectorType,
167 SkDisplacementMapEffect::kG_ChannelSelectorType, 167 SkDisplacementMapEffect::kG_ChannelSelectorType,
168 40.0f, displ))->unref(); 168 40.0f, displ))->unref();
169 drawClippedBitmap(canvas, 0, 400, paint); 169 drawClippedBitmap(canvas, 0, 400, paint);
170 displ.reset(SkImageSource::Create(fLarge)); 170 displ.reset(SkImageSource::Create(fLarge.get()));
171 paint.setImageFilter(SkDisplacementMapEffect::Create( 171 paint.setImageFilter(SkDisplacementMapEffect::Create(
172 SkDisplacementMapEffect::kB_ChannelSelectorType, 172 SkDisplacementMapEffect::kB_ChannelSelectorType,
173 SkDisplacementMapEffect::kA_ChannelSelectorType, 173 SkDisplacementMapEffect::kA_ChannelSelectorType,
174 40.0f, displ))->unref(); 174 40.0f, displ))->unref();
175 drawClippedBitmap(canvas, 100, 400, paint); 175 drawClippedBitmap(canvas, 100, 400, paint);
176 displ.reset(SkImageSource::Create(fLargeW)); 176 displ.reset(SkImageSource::Create(fLargeW.get()));
177 paint.setImageFilter(SkDisplacementMapEffect::Create( 177 paint.setImageFilter(SkDisplacementMapEffect::Create(
178 SkDisplacementMapEffect::kR_ChannelSelectorType, 178 SkDisplacementMapEffect::kR_ChannelSelectorType,
179 SkDisplacementMapEffect::kB_ChannelSelectorType, 179 SkDisplacementMapEffect::kB_ChannelSelectorType,
180 40.0f, displ))->unref(); 180 40.0f, displ))->unref();
181 drawClippedBitmap(canvas, 200, 400, paint); 181 drawClippedBitmap(canvas, 200, 400, paint);
182 displ.reset(SkImageSource::Create(fLargeH)); 182 displ.reset(SkImageSource::Create(fLargeH.get()));
183 paint.setImageFilter(SkDisplacementMapEffect::Create( 183 paint.setImageFilter(SkDisplacementMapEffect::Create(
184 SkDisplacementMapEffect::kG_ChannelSelectorType, 184 SkDisplacementMapEffect::kG_ChannelSelectorType,
185 SkDisplacementMapEffect::kA_ChannelSelectorType, 185 SkDisplacementMapEffect::kA_ChannelSelectorType,
186 40.0f, displ))->unref(); 186 40.0f, displ))->unref();
187 drawClippedBitmap(canvas, 300, 400, paint); 187 drawClippedBitmap(canvas, 300, 400, paint);
188 188
189 // Test for no given displacement input. In this case, both displacement 189 // Test for no given displacement input. In this case, both displacement
190 // and color should use the same bitmap, given to SkCanvas::drawBitmap() 190 // and color should use the same bitmap, given to SkCanvas::drawBitmap()
191 // as an input argument. 191 // as an input argument.
192 paint.setImageFilter(SkDisplacementMapEffect::Create( 192 paint.setImageFilter(SkDisplacementMapEffect::Create(
193 SkDisplacementMapEffect::kG_ChannelSelectorType, 193 SkDisplacementMapEffect::kG_ChannelSelectorType,
194 SkDisplacementMapEffect::kA_ChannelSelectorType, 194 SkDisplacementMapEffect::kA_ChannelSelectorType,
195 40.0f, nullptr))->unref(); 195 40.0f, nullptr))->unref();
196 drawClippedBitmap(canvas, 400, 400, paint); 196 drawClippedBitmap(canvas, 400, 400, paint);
197 } 197 }
198 198
199 private: 199 private:
200 SkBitmap fBitmap; 200 SkBitmap fBitmap;
201 SkAutoTUnref<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; 201 sk_sp<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH;
202 202
203 typedef GM INHERITED; 203 typedef GM INHERITED;
204 }; 204 };
205 205
206 ////////////////////////////////////////////////////////////////////////////// 206 //////////////////////////////////////////////////////////////////////////////
207 207
208 DEF_GM(return new DisplacementMapGM;) 208 DEF_GM(return new DisplacementMapGM;)
209 } 209 }
OLDNEW
« no previous file with comments | « gm/dftext.cpp ('k') | gm/drawatlas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698