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

Side by Side Diff: tests/ImageFilterTest.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 | « tests/ImageFilterCacheTest.cpp ('k') | tests/ImageFrom565Bitmap.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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return new MatrixTestImageFilter(reporter, matrix); 89 return new MatrixTestImageFilter(reporter, matrix);
90 } 90 }
91 91
92 #ifndef SK_IGNORE_TO_STRING 92 #ifndef SK_IGNORE_TO_STRING
93 void MatrixTestImageFilter::toString(SkString* str) const { 93 void MatrixTestImageFilter::toString(SkString* str) const {
94 str->appendf("MatrixTestImageFilter: ("); 94 str->appendf("MatrixTestImageFilter: (");
95 str->append(")"); 95 str->append(")");
96 } 96 }
97 #endif 97 #endif
98 98
99 static SkImage* make_small_image() { 99 static sk_sp<SkImage> make_small_image() {
100 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kBitmapSize, k BitmapSize)); 100 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kBitmapSize, k BitmapSize));
101 SkCanvas* canvas = surface->getCanvas(); 101 SkCanvas* canvas = surface->getCanvas();
102 canvas->clear(0x00000000); 102 canvas->clear(0x00000000);
103 SkPaint darkPaint; 103 SkPaint darkPaint;
104 darkPaint.setColor(0xFF804020); 104 darkPaint.setColor(0xFF804020);
105 SkPaint lightPaint; 105 SkPaint lightPaint;
106 lightPaint.setColor(0xFF244484); 106 lightPaint.setColor(0xFF244484);
107 const int i = kBitmapSize / 4; 107 const int i = kBitmapSize / 4;
108 for (int y = 0; y < kBitmapSize; y += i) { 108 for (int y = 0; y < kBitmapSize; y += i) {
109 for (int x = 0; x < kBitmapSize; x += i) { 109 for (int x = 0; x < kBitmapSize; x += i) {
(...skipping 11 matching lines...) Expand all
121 SkIntToScalar(i), 121 SkIntToScalar(i),
122 SkIntToScalar(i)), lightPaint); 122 SkIntToScalar(i)), lightPaint);
123 canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i), 123 canvas->drawRect(SkRect::MakeXYWH(SkIntToScalar(i),
124 SkIntToScalar(i), 124 SkIntToScalar(i),
125 SkIntToScalar(i), 125 SkIntToScalar(i),
126 SkIntToScalar(i)), darkPaint); 126 SkIntToScalar(i)), darkPaint);
127 canvas->restore(); 127 canvas->restore();
128 } 128 }
129 } 129 }
130 130
131 return surface->newImageSnapshot(); 131 return surface->makeImageSnapshot();
132 } 132 }
133 133
134 static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) { 134 static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
135 SkScalar s = amount; 135 SkScalar s = amount;
136 SkScalar matrix[20] = { s, 0, 0, 0, 0, 136 SkScalar matrix[20] = { s, 0, 0, 0, 0,
137 0, s, 0, 0, 0, 137 0, s, 0, 0, 0,
138 0, 0, s, 0, 0, 138 0, 0, s, 0, 0,
139 0, 0, 0, s, 0 }; 139 0, 0, 0, s, 0 };
140 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix)); 140 SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
141 return SkColorFilterImageFilter::Create(filter, input); 141 return SkColorFilterImageFilter::Create(filter, input);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 canvas.clear(0x0); 273 canvas.clear(0x0);
274 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize)); 274 SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize));
275 canvas.drawRect(rect, paint); 275 canvas.drawRect(rect, paint);
276 uint32_t pixel = *result.getAddr32(0, 0); 276 uint32_t pixel = *result.getAddr32(0, 0);
277 // The result here should be green, since we have effectively shifted bl ue to green. 277 // The result here should be green, since we have effectively shifted bl ue to green.
278 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 278 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
279 } 279 }
280 280
281 { 281 {
282 // Tests pass by not asserting 282 // Tests pass by not asserting
283 SkAutoTUnref<SkImage> image(make_small_image()); 283 sk_sp<SkImage> image(make_small_image());
284 SkBitmap result; 284 SkBitmap result;
285 result.allocN32Pixels(kBitmapSize, kBitmapSize); 285 result.allocN32Pixels(kBitmapSize, kBitmapSize);
286 286
287 { 287 {
288 // This tests for : 288 // This tests for :
289 // 1 ) location at (0,0,1) 289 // 1 ) location at (0,0,1)
290 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 290 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
291 // 2 ) location and target at same value 291 // 2 ) location and target at same value
292 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location. fZ); 292 SkPoint3 target = SkPoint3::Make(location.fX, location.fY, location. fZ);
293 // 3 ) large negative specular exponent value 293 // 3 ) large negative specular exponent value
294 SkScalar specularExponent = -1000; 294 SkScalar specularExponent = -1000;
295 295
296 SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image)); 296 SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image.get()) );
297 SkPaint paint; 297 SkPaint paint;
298 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular( 298 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
299 location, target, specularExponent, 180, 299 location, target, specularExponent, 180,
300 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1, 300 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
301 bmSrc))->unref(); 301 bmSrc))->unref();
302 SkCanvas canvas(result); 302 SkCanvas canvas(result);
303 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize), 303 SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
304 SkIntToScalar(kBitmapSize)); 304 SkIntToScalar(kBitmapSize));
305 canvas.drawRect(r, paint); 305 canvas.drawRect(r, paint);
306 } 306 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1); 567 SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
568 SkScalar kernel[9] = { 568 SkScalar kernel[9] = {
569 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 569 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
570 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1), 570 SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
571 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1), 571 SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
572 }; 572 };
573 const SkISize kernelSize = SkISize::Make(3, 3); 573 const SkISize kernelSize = SkISize::Make(3, 3);
574 const SkScalar gain = SK_Scalar1, bias = 0; 574 const SkScalar gain = SK_Scalar1, bias = 0;
575 const SkScalar five = SkIntToScalar(5); 575 const SkScalar five = SkIntToScalar(5);
576 576
577 SkAutoTUnref<SkImage> gradientImage(SkImage::NewFromBitmap(make_gradient_cir cle(64, 64))); 577 sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64 , 64)));
578 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientIma ge)); 578 SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientIma ge.get()));
579 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five)); 579 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(five, five));
580 SkMatrix matrix; 580 SkMatrix matrix;
581 581
582 matrix.setTranslate(SK_Scalar1, SK_Scalar1); 582 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
583 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1); 583 matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
584 584
585 SkRTreeFactory factory; 585 SkRTreeFactory factory;
586 SkPictureRecorder recorder; 586 SkPictureRecorder recorder;
587 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0); 587 SkCanvas* recordingCanvas = recorder.beginRecording(64, 64, &factory, 0);
588 588
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 795
796 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); 796 REPORTER_ASSERT(reporter, boundsDst == expectedBounds);
797 } 797 }
798 798
799 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, 799 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
800 skiatest::Reporter* reporter, 800 skiatest::Reporter* reporter,
801 GrContext* context) { 801 GrContext* context) {
802 SkBitmap greenBM; 802 SkBitmap greenBM;
803 greenBM.allocN32Pixels(20, 20); 803 greenBM.allocN32Pixels(20, 20);
804 greenBM.eraseColor(SK_ColorGREEN); 804 greenBM.eraseColor(SK_ColorGREEN);
805 SkAutoTUnref<SkImage> greenImage(SkImage::NewFromBitmap(greenBM)); 805 sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM));
806 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get())); 806 SkAutoTUnref<SkImageFilter> source(SkImageSource::Create(greenImage.get()));
807 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s ource.get())); 807 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(source.get(), s ource.get()));
808 808
809 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 1)); 809 SkAutoTUnref<SkSpecialImage> srcImg(create_empty_special_image(context, prox y, 1));
810 810
811 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr); 811 SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 100, 100), nullptr);
812 SkIPoint offset; 812 SkIPoint offset;
813 813
814 SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg, ctx, &offs et)); 814 SkAutoTUnref<SkSpecialImage> resultImg(merge->filterImage(srcImg, ctx, &offs et));
815 REPORTER_ASSERT(reporter, resultImg); 815 REPORTER_ASSERT(reporter, resultImg);
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 SkTableColorFilter::CreateARGB(allOne, identity, identity, identity)); 1426 SkTableColorFilter::CreateARGB(allOne, identity, identity, identity));
1427 SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for ceOpaqueCF.get())); 1427 SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(for ceOpaqueCF.get()));
1428 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack()); 1428 REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
1429 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds()); 1429 REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
1430 } 1430 }
1431 1431
1432 // Verify that SkImageSource survives serialization 1432 // Verify that SkImageSource survives serialization
1433 DEF_TEST(ImageFilterImageSourceSerialization, reporter) { 1433 DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
1434 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); 1434 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10));
1435 surface->getCanvas()->clear(SK_ColorGREEN); 1435 surface->getCanvas()->clear(SK_ColorGREEN);
1436 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 1436 sk_sp<SkImage> image(surface->makeImageSnapshot());
1437 SkAutoTUnref<SkImageFilter> filter(SkImageSource::Create(image)); 1437 SkAutoTUnref<SkImageFilter> filter(SkImageSource::Create(image.get()));
1438 1438
1439 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter)); 1439 SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
1440 SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable( 1440 SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
1441 data->data(), data->size(), SkImageFilter::GetFlattenableType())); 1441 data->data(), data->size(), SkImageFilter::GetFlattenableType()));
1442 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.g et()); 1442 SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.g et());
1443 REPORTER_ASSERT(reporter, unflattenedFilter); 1443 REPORTER_ASSERT(reporter, unflattenedFilter);
1444 1444
1445 SkBitmap bm; 1445 SkBitmap bm;
1446 bm.allocN32Pixels(10, 10); 1446 bm.allocN32Pixels(10, 10);
1447 bm.eraseColor(SK_ColorBLUE); 1447 bm.eraseColor(SK_ColorBLUE);
(...skipping 17 matching lines...) Expand all
1465 } 1465 }
1466 #endif 1466 #endif
1467 1467
1468 largeBmp.allocN32Pixels(largeW, largeH); 1468 largeBmp.allocN32Pixels(largeW, largeH);
1469 largeBmp.eraseColor(0); 1469 largeBmp.eraseColor(0);
1470 if (!largeBmp.getPixels()) { 1470 if (!largeBmp.getPixels()) {
1471 ERRORF(reporter, "Failed to allocate large bmp."); 1471 ERRORF(reporter, "Failed to allocate large bmp.");
1472 return; 1472 return;
1473 } 1473 }
1474 1474
1475 SkAutoTUnref<SkImage> largeImage(SkImage::NewFromBitmap(largeBmp)); 1475 sk_sp<SkImage> largeImage(SkImage::MakeFromBitmap(largeBmp));
1476 if (!largeImage) { 1476 if (!largeImage) {
1477 ERRORF(reporter, "Failed to create large image."); 1477 ERRORF(reporter, "Failed to create large image.");
1478 return; 1478 return;
1479 } 1479 }
1480 1480
1481 SkAutoTUnref<SkImageFilter> largeSource(SkImageSource::Create(largeImage)); 1481 SkAutoTUnref<SkImageFilter> largeSource(SkImageSource::Create(largeImage.get ()));
1482 if (!largeSource) { 1482 if (!largeSource) {
1483 ERRORF(reporter, "Failed to create large SkImageSource."); 1483 ERRORF(reporter, "Failed to create large SkImageSource.");
1484 return; 1484 return;
1485 } 1485 }
1486 1486
1487 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, large Source)); 1487 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, large Source));
1488 if (!blur) { 1488 if (!blur) {
1489 ERRORF(reporter, "Failed to create SkBlurImageFilter."); 1489 ERRORF(reporter, "Failed to create SkBlurImageFilter.");
1490 return; 1490 return;
1491 } 1491 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 test_xfermode_cropped_input(&canvas, reporter); 1532 test_xfermode_cropped_input(&canvas, reporter);
1533 } 1533 }
1534 1534
1535 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1535 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1536 SkAutoTUnref<SkSurface> surface( 1536 SkAutoTUnref<SkSurface> surface(
1537 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, 1537 SkSurface::NewRenderTarget(context, SkBudgeted::kYes,
1538 SkImageInfo::MakeN32Premul(100, 100))); 1538 SkImageInfo::MakeN32Premul(100, 100)));
1539 test_large_blur_input(reporter, surface->getCanvas()); 1539 test_large_blur_input(reporter, surface->getCanvas());
1540 } 1540 }
1541 #endif 1541 #endif
OLDNEW
« no previous file with comments | « tests/ImageFilterCacheTest.cpp ('k') | tests/ImageFrom565Bitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698