| 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" |
| 11 #include "SkBitmapSource.h" | 11 #include "SkBitmapSource.h" |
| 12 #include "SkBlurImageFilter.h" | 12 #include "SkBlurImageFilter.h" |
| 13 #include "SkCanvas.h" | 13 #include "SkCanvas.h" |
| 14 #include "SkColorFilterImageFilter.h" | 14 #include "SkColorFilterImageFilter.h" |
| 15 #include "SkColorMatrixFilter.h" | 15 #include "SkColorMatrixFilter.h" |
| 16 #include "SkDeviceImageFilterProxy.h" | 16 #include "SkDeviceImageFilterProxy.h" |
| 17 #include "SkDisplacementMapEffect.h" | 17 #include "SkDisplacementMapEffect.h" |
| 18 #include "SkDropShadowImageFilter.h" | 18 #include "SkDropShadowImageFilter.h" |
| 19 #include "SkFlattenableBuffers.h" |
| 19 #include "SkLightingImageFilter.h" | 20 #include "SkLightingImageFilter.h" |
| 20 #include "SkMatrixConvolutionImageFilter.h" | 21 #include "SkMatrixConvolutionImageFilter.h" |
| 21 #include "SkMergeImageFilter.h" | 22 #include "SkMergeImageFilter.h" |
| 22 #include "SkMorphologyImageFilter.h" | 23 #include "SkMorphologyImageFilter.h" |
| 23 #include "SkOffsetImageFilter.h" | 24 #include "SkOffsetImageFilter.h" |
| 25 #include "SkPicture.h" |
| 24 #include "SkRect.h" | 26 #include "SkRect.h" |
| 25 #include "SkTileImageFilter.h" | 27 #include "SkTileImageFilter.h" |
| 26 #include "SkXfermodeImageFilter.h" | 28 #include "SkXfermodeImageFilter.h" |
| 27 #include "Test.h" | 29 #include "Test.h" |
| 28 | 30 |
| 29 #if SK_SUPPORT_GPU | 31 #if SK_SUPPORT_GPU |
| 30 #include "GrContextFactory.h" | 32 #include "GrContextFactory.h" |
| 31 #include "SkGpuDevice.h" | 33 #include "SkGpuDevice.h" |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 static const int kBitmapSize = 4; | 36 static const int kBitmapSize = 4; |
| 35 | 37 |
| 38 namespace { |
| 39 |
| 40 class MatrixTestImageFilter : public SkImageFilter { |
| 41 public: |
| 42 MatrixTestImageFilter(skiatest::Reporter* reporter, const SkMatrix& expected
Matrix) |
| 43 : SkImageFilter(0), fReporter(reporter), fExpectedMatrix(expectedMatrix) { |
| 44 } |
| 45 |
| 46 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm, |
| 47 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE { |
| 48 REPORTER_ASSERT(fReporter, ctm == fExpectedMatrix); |
| 49 return true; |
| 50 } |
| 51 |
| 52 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(MatrixTestImageFilter) |
| 53 |
| 54 protected: |
| 55 explicit MatrixTestImageFilter(SkReadBuffer& buffer) : SkImageFilter(0) { |
| 56 fReporter = static_cast<skiatest::Reporter*>(buffer.readFunctionPtr()); |
| 57 buffer.readMatrix(&fExpectedMatrix); |
| 58 } |
| 59 |
| 60 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE { |
| 61 buffer.writeFunctionPtr(fReporter); |
| 62 buffer.writeMatrix(fExpectedMatrix); |
| 63 } |
| 64 |
| 65 private: |
| 66 skiatest::Reporter* fReporter; |
| 67 SkMatrix fExpectedMatrix; |
| 68 }; |
| 69 |
| 70 } |
| 71 |
| 36 static void make_small_bitmap(SkBitmap& bitmap) { | 72 static void make_small_bitmap(SkBitmap& bitmap) { |
| 37 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); | 73 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize); |
| 38 bitmap.allocPixels(); | 74 bitmap.allocPixels(); |
| 39 SkBitmapDevice device(bitmap); | 75 SkBitmapDevice device(bitmap); |
| 40 SkCanvas canvas(&device); | 76 SkCanvas canvas(&device); |
| 41 canvas.clear(0x00000000); | 77 canvas.clear(0x00000000); |
| 42 SkPaint darkPaint; | 78 SkPaint darkPaint; |
| 43 darkPaint.setColor(0xFF804020); | 79 darkPaint.setColor(0xFF804020); |
| 44 SkPaint lightPaint; | 80 SkPaint lightPaint; |
| 45 lightPaint.setColor(0xFF244484); | 81 lightPaint.setColor(0xFF244484); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 259 } |
| 224 | 260 |
| 225 DEF_TEST(ImageFilterCropRect, reporter) { | 261 DEF_TEST(ImageFilterCropRect, reporter) { |
| 226 SkBitmap temp; | 262 SkBitmap temp; |
| 227 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 263 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 228 temp.allocPixels(); | 264 temp.allocPixels(); |
| 229 SkBitmapDevice device(temp); | 265 SkBitmapDevice device(temp); |
| 230 test_crop_rects(&device, reporter); | 266 test_crop_rects(&device, reporter); |
| 231 } | 267 } |
| 232 | 268 |
| 269 DEF_TEST(ImageFilterMatrixTest, reporter) { |
| 270 SkBitmap temp; |
| 271 temp.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 272 temp.allocPixels(); |
| 273 SkBitmapDevice device(temp); |
| 274 SkCanvas canvas(&device); |
| 275 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); |
| 276 |
| 277 SkMatrix expectedMatrix = canvas.getTotalMatrix(); |
| 278 |
| 279 SkPicture picture; |
| 280 SkCanvas* recordingCanvas = picture.beginRecording(100, 100, |
| 281 SkPicture::kOptimizeForClippedPlayback_RecordingFlag); |
| 282 |
| 283 SkPaint paint; |
| 284 SkAutoTUnref<MatrixTestImageFilter> imageFilter( |
| 285 new MatrixTestImageFilter(reporter, expectedMatrix)); |
| 286 paint.setImageFilter(imageFilter.get()); |
| 287 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>( |
| 288 SkCanvas::kHasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag); |
| 289 recordingCanvas->saveLayer(NULL, &paint, saveFlags); |
| 290 SkPaint solidPaint; |
| 291 solidPaint.setColor(0xFFFFFFFF); |
| 292 recordingCanvas->save(); |
| 293 recordingCanvas->scale(SkIntToScalar(10), SkIntToScalar(10)); |
| 294 recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(100, 100)), solidPain
t); |
| 295 recordingCanvas->restore(); // scale |
| 296 recordingCanvas->restore(); // saveLayer |
| 297 picture.endRecording(); |
| 298 |
| 299 canvas.drawPicture(picture); |
| 300 } |
| 301 |
| 233 #if SK_SUPPORT_GPU | 302 #if SK_SUPPORT_GPU |
| 234 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { | 303 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) { |
| 235 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 304 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
| 236 SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100); | 305 SkGpuDevice device(context, SkBitmap::kARGB_8888_Config, 100, 100); |
| 237 test_crop_rects(&device, reporter); | 306 test_crop_rects(&device, reporter); |
| 238 } | 307 } |
| 239 #endif | 308 #endif |
| OLD | NEW |