| OLD | NEW |
| 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 25 matching lines...) Expand all Loading... |
| 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.reset(SkImage::NewFromBitmap( |
| 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.reset( |
| 40 SkImage::NewFromBitmap(sk_tool_utils::create_checkerboard_bitmap(96,
64, c1, c2, 8))); | 40 SkImage::NewFromBitmap(sk_tool_utils::create_checkerboard_bitmap(96,
64, c1, c2, 8))); |
| 41 fLargeH.reset(SkImage::NewFromBitmap( | 41 fLargeH.reset(SkImage::NewFromBitmap( |
| 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(500, 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 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 SkDisplacementMapEffect::kG_ChannelSelectorType, | 146 SkDisplacementMapEffect::kG_ChannelSelectorType, |
| 147 SkDisplacementMapEffect::kA_ChannelSelectorType, | 147 SkDisplacementMapEffect::kA_ChannelSelectorType, |
| 148 40.0f, displ, nullptr, &cropRect))->unref(); | 148 40.0f, displ, nullptr, &cropRect))->unref(); |
| 149 drawClippedBitmap(canvas, 300, 300, paint); | 149 drawClippedBitmap(canvas, 300, 300, paint); |
| 150 paint.setImageFilter(SkDisplacementMapEffect::Create( | 150 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 151 SkDisplacementMapEffect::kR_ChannelSelectorType, | 151 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 152 SkDisplacementMapEffect::kA_ChannelSelectorType, | 152 SkDisplacementMapEffect::kA_ChannelSelectorType, |
| 153 40.0f, displ, nullptr, &cropRect))->unref(); | 153 40.0f, displ, nullptr, &cropRect))->unref(); |
| 154 drawClippedBitmap(canvas, 400, 300, paint); | 154 drawClippedBitmap(canvas, 400, 300, paint); |
| 155 | 155 |
| 156 // Test for negative scale. |
| 157 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 158 SkDisplacementMapEffect::kG_ChannelSelectorType, |
| 159 SkDisplacementMapEffect::kA_ChannelSelectorType, |
| 160 -40.0f, displ))->unref(); |
| 161 this->drawClippedBitmap(canvas, 500, 0, paint); |
| 162 |
| 156 // Tests for images of different sizes | 163 // Tests for images of different sizes |
| 157 displ.reset(SkImageSource::Create(fSmall)); | 164 displ.reset(SkImageSource::Create(fSmall)); |
| 158 paint.setImageFilter(SkDisplacementMapEffect::Create( | 165 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 159 SkDisplacementMapEffect::kR_ChannelSelectorType, | 166 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 160 SkDisplacementMapEffect::kG_ChannelSelectorType, | 167 SkDisplacementMapEffect::kG_ChannelSelectorType, |
| 161 40.0f, displ))->unref(); | 168 40.0f, displ))->unref(); |
| 162 drawClippedBitmap(canvas, 0, 400, paint); | 169 drawClippedBitmap(canvas, 0, 400, paint); |
| 163 displ.reset(SkImageSource::Create(fLarge)); | 170 displ.reset(SkImageSource::Create(fLarge)); |
| 164 paint.setImageFilter(SkDisplacementMapEffect::Create( | 171 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 165 SkDisplacementMapEffect::kB_ChannelSelectorType, | 172 SkDisplacementMapEffect::kB_ChannelSelectorType, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 193 SkBitmap fBitmap; | 200 SkBitmap fBitmap; |
| 194 SkAutoTUnref<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; | 201 SkAutoTUnref<SkImage> fCheckerboard, fSmall, fLarge, fLargeW, fLargeH; |
| 195 | 202 |
| 196 typedef GM INHERITED; | 203 typedef GM INHERITED; |
| 197 }; | 204 }; |
| 198 | 205 |
| 199 ////////////////////////////////////////////////////////////////////////////// | 206 ////////////////////////////////////////////////////////////////////////////// |
| 200 | 207 |
| 201 DEF_GM(return new DisplacementMapGM;) | 208 DEF_GM(return new DisplacementMapGM;) |
| 202 } | 209 } |
| OLD | NEW |