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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1852273002: Revert of Update SkXfermodeImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « src/effects/SkXfermodeImageFilter.cpp ('k') | tests/SerializationTest.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 * 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 "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 { 224 {
225 SkPaint paint; 225 SkPaint paint;
226 paint.setShader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, SK_S calar1, 1, 0)); 226 paint.setShader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, SK_S calar1, 1, 0));
227 sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint)); 227 sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint));
228 228
229 this->addFilter("paint and blur", SkBlurImageFilter::Make(five, five , 229 this->addFilter("paint and blur", SkBlurImageFilter::Make(five, five ,
230 std::move( paintFilter), 230 std::move( paintFilter),
231 cropRect). release()); 231 cropRect). release());
232 } 232 }
233 this->addFilter("xfermode", SkXfermodeImageFilter::Make( 233 this->addFilter("xfermode", SkXfermodeImageFilter::Make(
234 SkXfermode::Make(SkXfermode::kSrc_Mo de), 234 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel ease());
235 sk_ref_sp<SkImageFilter>(input),
236 sk_ref_sp<SkImageFilter>(input),
237 cropRect).release());
238 } 235 }
239 int count() const { return fFilters.count(); } 236 int count() const { return fFilters.count(); }
240 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); } 237 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); }
241 const char* getName(int index) const { return fFilters[index].fName; } 238 const char* getName(int index) const { return fFilters[index].fName; }
242 private: 239 private:
243 struct Filter { 240 struct Filter {
244 Filter() : fName(nullptr), fFilter(nullptr) {} 241 Filter() : fName(nullptr), fFilter(nullptr) {}
245 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {} 242 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {}
246 const char* fName; 243 const char* fName;
247 sk_sp<SkImageFilter> fFilter; 244 sk_sp<SkImageFilter> fFilter;
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); 832 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc);
836 833
837 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); 834 REPORTER_ASSERT(reporter, boundsDst == expectedBounds);
838 } 835 }
839 836
840 DEF_TEST(ImageFilterUnionBounds, reporter) { 837 DEF_TEST(ImageFilterUnionBounds, reporter) {
841 sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(50, 0, nullptr)); 838 sk_sp<SkImageFilter> offset(SkOffsetImageFilter::Make(50, 0, nullptr));
842 // Regardless of which order they appear in, the image filter bounds should 839 // Regardless of which order they appear in, the image filter bounds should
843 // be combined correctly. 840 // be combined correctly.
844 { 841 {
845 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs et)); 842 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs et.get()));
846 SkRect bounds = SkRect::MakeWH(100, 100); 843 SkRect bounds = SkRect::MakeWH(100, 100);
847 // Intentionally aliasing here, as that's what the real callers do. 844 // Intentionally aliasing here, as that's what the real callers do.
848 bounds = composite->computeFastBounds(bounds); 845 bounds = composite->computeFastBounds(bounds);
849 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); 846 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
850 } 847 }
851 { 848 {
852 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null ptr, 849 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null ptr,
853 offset, nullp tr)); 850 offset.get(), nullptr));
854 SkRect bounds = SkRect::MakeWH(100, 100); 851 SkRect bounds = SkRect::MakeWH(100, 100);
855 // Intentionally aliasing here, as that's what the real callers do. 852 // Intentionally aliasing here, as that's what the real callers do.
856 bounds = composite->computeFastBounds(bounds); 853 bounds = composite->computeFastBounds(bounds);
857 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); 854 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
858 } 855 }
859 } 856 }
860 857
861 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, 858 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
862 skiatest::Reporter* reporter, 859 skiatest::Reporter* reporter,
863 GrContext* context) { 860 GrContext* context) {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 REPORTER_ASSERT(reporter, nullptr == conv.get()); 1270 REPORTER_ASSERT(reporter, nullptr == conv.get());
1274 } 1271 }
1275 1272
1276 static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re porter) { 1273 static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re porter) {
1277 canvas->clear(0); 1274 canvas->clear(0);
1278 1275
1279 SkBitmap bitmap; 1276 SkBitmap bitmap;
1280 bitmap.allocN32Pixels(1, 1); 1277 bitmap.allocN32Pixels(1, 1);
1281 bitmap.eraseARGB(255, 255, 255, 255); 1278 bitmap.eraseARGB(255, 255, 255, 255);
1282 1279
1283 sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, 1280 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M ode));
1284 SkXfermode::kSrcIn_ Mode)); 1281 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre en.get()));
1285 sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get( )));
1286 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); 1282 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
1287 sk_sp<SkImageFilter> croppedOut( 1283 SkAutoTUnref<SkImageFilter> croppedOut(
1288 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect)); 1284 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
1289 1285
1290 // Check that an xfermode image filter whose input has been cropped out stil l draws the other 1286 // Check that an xfermode image filter whose input has been cropped out stil l draws the other
1291 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning. 1287 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
1292 sk_sp<SkXfermode> mode(SkXfermode::Make(SkXfermode::kSrcOver_Mode)); 1288 auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
1293 sk_sp<SkImageFilter> xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFil ter, 1289 auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
1294 croppedOut, nu llptr)); 1290 auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
1295 sk_sp<SkImageFilter> xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedO ut, 1291 auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedO ut, nullptr));
1296 greenFilter, n ullptr));
1297 sk_sp<SkImageFilter> xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, crop pedOut,
1298 croppedOut , nullptr));
1299 1292
1300 SkPaint paint; 1293 SkPaint paint;
1301 paint.setImageFilter(std::move(xfermodeNoFg)); 1294 paint.setImageFilter(xfermodeNoFg);
1302 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite 1295 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
1303 1296
1304 uint32_t pixel; 1297 uint32_t pixel;
1305 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType); 1298 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType);
1306 canvas->readPixels(info, &pixel, 4, 0, 0); 1299 canvas->readPixels(info, &pixel, 4, 0, 0);
1307 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1300 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1308 1301
1309 paint.setImageFilter(std::move(xfermodeNoBg)); 1302 paint.setImageFilter(xfermodeNoBg);
1310 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite 1303 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
1311 canvas->readPixels(info, &pixel, 4, 0, 0); 1304 canvas->readPixels(info, &pixel, 4, 0, 0);
1312 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1305 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1313 1306
1314 paint.setImageFilter(std::move(xfermodeNoFgNoBg)); 1307 paint.setImageFilter(xfermodeNoFgNoBg);
1315 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite 1308 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
1316 canvas->readPixels(info, &pixel, 4, 0, 0); 1309 canvas->readPixels(info, &pixel, 4, 0, 0);
1317 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1310 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1318 } 1311 }
1319 1312
1320 DEF_TEST(ImageFilterNestedSaveLayer, reporter) { 1313 DEF_TEST(ImageFilterNestedSaveLayer, reporter) {
1321 SkBitmap temp; 1314 SkBitmap temp;
1322 temp.allocN32Pixels(50, 50); 1315 temp.allocN32Pixels(50, 50);
1323 SkCanvas canvas(temp); 1316 SkCanvas canvas(temp);
1324 canvas.clear(0x0); 1317 canvas.clear(0x0);
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 1628
1636 test_xfermode_cropped_input(&canvas, reporter); 1629 test_xfermode_cropped_input(&canvas, reporter);
1637 } 1630 }
1638 1631
1639 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1632 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1640 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 1633 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
1641 SkImageInfo::MakeN32Premul(100, 100 ))); 1634 SkImageInfo::MakeN32Premul(100, 100 )));
1642 test_large_blur_input(reporter, surface->getCanvas()); 1635 test_large_blur_input(reporter, surface->getCanvas());
1643 } 1636 }
1644 #endif 1637 #endif
OLDNEW
« no previous file with comments | « src/effects/SkXfermodeImageFilter.cpp ('k') | tests/SerializationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698