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 "SkBicubicImageFilter.h" | 8 #include "SkBicubicImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 private: | 65 private: |
66 skiatest::Reporter* fReporter; | 66 skiatest::Reporter* fReporter; |
67 SkMatrix fExpectedMatrix; | 67 SkMatrix fExpectedMatrix; |
68 }; | 68 }; |
69 | 69 |
70 } | 70 } |
71 | 71 |
72 static void make_small_bitmap(SkBitmap& bitmap) { | 72 static void make_small_bitmap(SkBitmap& bitmap) { |
73 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); | 73 bitmap.allocN32Pixels(kBitmapSize, kBitmapSize); |
74 bitmap.allocPixels(); | 74 SkCanvas canvas(bitmap); |
75 SkBitmapDevice device(bitmap); | |
76 SkCanvas canvas(&device); | |
77 canvas.clear(0x00000000); | 75 canvas.clear(0x00000000); |
78 SkPaint darkPaint; | 76 SkPaint darkPaint; |
79 darkPaint.setColor(0xFF804020); | 77 darkPaint.setColor(0xFF804020); |
80 SkPaint lightPaint; | 78 SkPaint lightPaint; |
81 lightPaint.setColor(0xFF244484); | 79 lightPaint.setColor(0xFF244484); |
82 const int i = kBitmapSize / 4; | 80 const int i = kBitmapSize / 4; |
83 for (int y = 0; y < kBitmapSize; y += i) { | 81 for (int y = 0; y < kBitmapSize; y += i) { |
84 for (int x = 0; x < kBitmapSize; x += i) { | 82 for (int x = 0; x < kBitmapSize; x += i) { |
85 canvas.save(); | 83 canvas.save(); |
86 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 84 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 // be expressed as a color filter. | 150 // be expressed as a color filter. |
153 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); | 151 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100)); |
154 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect)
); | 152 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect)
); |
155 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); | 153 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL)); |
156 } | 154 } |
157 | 155 |
158 { | 156 { |
159 // Tests pass by not asserting | 157 // Tests pass by not asserting |
160 SkBitmap bitmap, result; | 158 SkBitmap bitmap, result; |
161 make_small_bitmap(bitmap); | 159 make_small_bitmap(bitmap); |
162 result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); | 160 result.allocN32Pixels(kBitmapSize, kBitmapSize); |
163 result.allocPixels(); | |
164 | 161 |
165 { | 162 { |
166 // This tests for : | 163 // This tests for : |
167 // 1 ) location at (0,0,1) | 164 // 1 ) location at (0,0,1) |
168 SkPoint3 location(0, 0, SK_Scalar1); | 165 SkPoint3 location(0, 0, SK_Scalar1); |
169 // 2 ) location and target at same value | 166 // 2 ) location and target at same value |
170 SkPoint3 target(location.fX, location.fY, location.fZ); | 167 SkPoint3 target(location.fX, location.fY, location.fZ); |
171 // 3 ) large negative specular exponent value | 168 // 3 ) large negative specular exponent value |
172 SkScalar specularExponent = -1000; | 169 SkScalar specularExponent = -1000; |
173 | 170 |
(...skipping 23 matching lines...) Expand all Loading... |
197 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(),
&result, &loc)); | 194 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(),
&result, &loc)); |
198 } | 195 } |
199 } | 196 } |
200 } | 197 } |
201 | 198 |
202 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ | 199 static void test_crop_rects(SkBaseDevice* device, skiatest::Reporter* reporter)
{ |
203 // Check that all filters offset to their absolute crop rect, | 200 // Check that all filters offset to their absolute crop rect, |
204 // unaffected by the input crop rect. | 201 // unaffected by the input crop rect. |
205 // Tests pass by not asserting. | 202 // Tests pass by not asserting. |
206 SkBitmap bitmap; | 203 SkBitmap bitmap; |
207 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 204 bitmap.allocN32Pixels(100, 100); |
208 bitmap.allocPixels(); | |
209 bitmap.eraseARGB(0, 0, 0, 0); | 205 bitmap.eraseARGB(0, 0, 0, 0); |
210 SkDeviceImageFilterProxy proxy(device); | 206 SkDeviceImageFilterProxy proxy(device); |
211 | 207 |
212 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); | 208 SkImageFilter::CropRect inputCropRect(SkRect::MakeXYWH(8, 13, 80, 80)); |
213 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); | 209 SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60)); |
214 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); | 210 SkAutoTUnref<SkImageFilter> input(make_grayscale(NULL, &inputCropRect)); |
215 | 211 |
216 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); | 212 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
SkXfermode::kSrcIn_Mode)); |
217 SkPoint3 location(0, 0, SK_Scalar1); | 213 SkPoint3 location(0, 0, SK_Scalar1); |
218 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); | 214 SkPoint3 target(SK_Scalar1, SK_Scalar1, SK_Scalar1); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); | 249 REPORTER_ASSERT_MESSAGE(reporter, offset.fX == 20 && offset.fY == 30, st
r.c_str()); |
254 } | 250 } |
255 | 251 |
256 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 252 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
257 SkSafeUnref(filters[i]); | 253 SkSafeUnref(filters[i]); |
258 } | 254 } |
259 } | 255 } |
260 | 256 |
261 DEF_TEST(ImageFilterCropRect, reporter) { | 257 DEF_TEST(ImageFilterCropRect, reporter) { |
262 SkBitmap temp; | 258 SkBitmap temp; |
263 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 259 temp.allocN32Pixels(100, 100); |
264 temp.allocPixels(); | |
265 SkBitmapDevice device(temp); | 260 SkBitmapDevice device(temp); |
266 test_crop_rects(&device, reporter); | 261 test_crop_rects(&device, reporter); |
267 } | 262 } |
268 | 263 |
269 DEF_TEST(ImageFilterMatrixTest, reporter) { | 264 DEF_TEST(ImageFilterMatrixTest, reporter) { |
270 SkBitmap temp; | 265 SkBitmap temp; |
271 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 266 temp.allocN32Pixels(100, 100); |
272 temp.allocPixels(); | |
273 SkBitmapDevice device(temp); | 267 SkBitmapDevice device(temp); |
274 SkCanvas canvas(&device); | 268 SkCanvas canvas(&device); |
275 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); | 269 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); |
276 | 270 |
277 SkMatrix expectedMatrix = canvas.getTotalMatrix(); | 271 SkMatrix expectedMatrix = canvas.getTotalMatrix(); |
278 | 272 |
279 SkPicture picture; | 273 SkPicture picture; |
280 SkCanvas* recordingCanvas = picture.beginRecording(100, 100, | 274 SkCanvas* recordingCanvas = picture.beginRecording(100, 100, |
281 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); | 275 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); |
282 | 276 |
(...skipping 16 matching lines...) Expand all Loading... |
299 canvas.drawPicture(picture); | 293 canvas.drawPicture(picture); |
300 } | 294 } |
301 | 295 |
302 #if SK_SUPPORT_GPU | 296 #if SK_SUPPORT_GPU |
303 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 297 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
304 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 298 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
305 SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100); | 299 SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100); |
306 test_crop_rects(&device, reporter); | 300 test_crop_rects(&device, reporter); |
307 } | 301 } |
308 #endif | 302 #endif |
OLD | NEW |