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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkBitmapDevice.h" | 9 #include "SkBitmapDevice.h" |
10 #include "SkBitmapSource.h" | 10 #include "SkBitmapSource.h" |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 401 } |
402 } | 402 } |
403 } | 403 } |
404 } | 404 } |
405 | 405 |
406 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { | 406 for (size_t i = 0; i < SK_ARRAY_COUNT(filters); ++i) { |
407 SkSafeUnref(filters[i].fFilter); | 407 SkSafeUnref(filters[i].fFilter); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
| 411 static void drawSaveLayerPicture(int width, int height, int tileSize, SkBBHFacto
ry* factory, SkBitmap* result) { |
| 412 |
| 413 SkMatrix matrix; |
| 414 matrix.setTranslate(SkIntToScalar(50), 0); |
| 415 |
| 416 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE
, SkXfermode::kSrc_Mode)); |
| 417 SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()))
; |
| 418 SkAutoTUnref<SkImageFilter> imageFilter(SkMatrixImageFilter::Create(matrix,
SkPaint::kNone_FilterLevel, cfif.get())); |
| 419 |
| 420 SkPaint paint; |
| 421 paint.setImageFilter(imageFilter.get()); |
| 422 SkPictureRecorder recorder; |
| 423 SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50)); |
| 424 SkCanvas* recordingCanvas = recorder.beginRecording(width, height, factory,
0); |
| 425 recordingCanvas->translate(-55, 0); |
| 426 recordingCanvas->saveLayer(&bounds, &paint); |
| 427 recordingCanvas->restore(); |
| 428 SkAutoTUnref<SkPicture> picture1(recorder.endRecording()); |
| 429 |
| 430 result->allocN32Pixels(width, height); |
| 431 SkCanvas canvas(*result); |
| 432 canvas.clear(0); |
| 433 canvas.clipRect(SkRect::Make(SkIRect::MakeWH(tileSize, tileSize))); |
| 434 canvas.drawPicture(picture1.get()); |
| 435 } |
| 436 |
| 437 DEF_TEST(ImageFilterDrawMatrixBBH, reporter) { |
| 438 // Check that matrix filter when drawn tiled with BBH exactly |
| 439 // matches the same thing drawn without BBH. |
| 440 // Tests pass by not asserting. |
| 441 |
| 442 const int width = 200, height = 200; |
| 443 const int tileSize = 100; |
| 444 SkBitmap result1, result2; |
| 445 SkRTreeFactory factory; |
| 446 |
| 447 drawSaveLayerPicture(width, height, tileSize, &factory, &result1); |
| 448 drawSaveLayerPicture(width, height, tileSize, NULL, &result2); |
| 449 |
| 450 for (int y = 0; y < height; y++) { |
| 451 int diffs = memcmp(result1.getAddr32(0, y), result2.getAddr32(0, y), res
ult1.rowBytes()); |
| 452 REPORTER_ASSERT(reporter, !diffs); |
| 453 if (diffs) { |
| 454 break; |
| 455 } |
| 456 } |
| 457 } |
| 458 |
411 static void drawBlurredRect(SkCanvas* canvas) { | 459 static void drawBlurredRect(SkCanvas* canvas) { |
412 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); | 460 SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(SkIntToScalar(8
), 0)); |
413 SkPaint filterPaint; | 461 SkPaint filterPaint; |
414 filterPaint.setColor(SK_ColorWHITE); | 462 filterPaint.setColor(SK_ColorWHITE); |
415 filterPaint.setImageFilter(filter); | 463 filterPaint.setImageFilter(filter); |
416 canvas->saveLayer(NULL, &filterPaint); | 464 canvas->saveLayer(NULL, &filterPaint); |
417 SkPaint whitePaint; | 465 SkPaint whitePaint; |
418 whitePaint.setColor(SK_ColorWHITE); | 466 whitePaint.setColor(SK_ColorWHITE); |
419 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); | 467 canvas->drawRect(SkRect::Make(SkIRect::MakeWH(4, 4)), whitePaint); |
420 canvas->restore(); | 468 canvas->restore(); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 } | 896 } |
849 | 897 |
850 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { | 898 DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) { |
851 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); | 899 GrContext* context = factory->get(static_cast<GrContextFactory::GLContextTyp
e>(0)); |
852 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, | 900 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context, |
853 SkImageInfo::MakeN32Pre
mul(1, 1), | 901 SkImageInfo::MakeN32Pre
mul(1, 1), |
854 0)); | 902 0)); |
855 test_xfermode_cropped_input(device, reporter); | 903 test_xfermode_cropped_input(device, reporter); |
856 } | 904 } |
857 #endif | 905 #endif |
OLD | NEW |