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

Side by Side Diff: tests/ImageFilterTest.cpp

Issue 1832223002: switch xfermodes over to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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
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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (!cropRect) { 184 if (!cropRect) {
185 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter( 185 this->addFilter("matrix", SkImageFilter::CreateMatrixFilter(
186 matrix, kLow_SkFilterQuality, input)); 186 matrix, kLow_SkFilterQuality, input));
187 } 187 }
188 this->addFilter("blur and offset", SkOffsetImageFilter::Create( 188 this->addFilter("blur and offset", SkOffsetImageFilter::Create(
189 five, five, blur.get(), cropRect)); 189 five, five, blur.get(), cropRect));
190 this->addFilter("picture and blur", SkBlurImageFilter::Create( 190 this->addFilter("picture and blur", SkBlurImageFilter::Create(
191 five, five, pictureFilter.get(), cropRect)); 191 five, five, pictureFilter.get(), cropRect));
192 this->addFilter("paint and blur", SkBlurImageFilter::Create( 192 this->addFilter("paint and blur", SkBlurImageFilter::Create(
193 five, five, paintFilter.get(), cropRect)); 193 five, five, paintFilter.get(), cropRect));
194 this->addFilter("xfermode", SkXfermodeImageFilter::Create( 194 this->addFilter("xfermode", SkXfermodeImageFilter::Make(
195 SkXfermode::Create(SkXfermode::kSrc_Mode), input, input, cropRect)); 195 SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).rel ease());
196 } 196 }
197 int count() const { return fFilters.count(); } 197 int count() const { return fFilters.count(); }
198 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); } 198 SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.g et(); }
199 const char* getName(int index) const { return fFilters[index].fName; } 199 const char* getName(int index) const { return fFilters[index].fName; }
200 private: 200 private:
201 struct Filter { 201 struct Filter {
202 Filter() : fName(nullptr), fFilter(nullptr) {} 202 Filter() : fName(nullptr), fFilter(nullptr) {}
203 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {} 203 Filter(const char* name, SkImageFilter* filter) : fName(name), fFilter(f ilter) {}
204 const char* fName; 204 const char* fName;
205 sk_sp<SkImageFilter> fFilter; 205 sk_sp<SkImageFilter> fFilter;
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc); 792 SkRect boundsDst = composedFilter->computeFastBounds(boundsSrc);
793 793
794 REPORTER_ASSERT(reporter, boundsDst == expectedBounds); 794 REPORTER_ASSERT(reporter, boundsDst == expectedBounds);
795 } 795 }
796 796
797 DEF_TEST(ImageFilterUnionBounds, reporter) { 797 DEF_TEST(ImageFilterUnionBounds, reporter) {
798 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0)); 798 SkAutoTUnref<SkImageFilter> offset(SkOffsetImageFilter::Create(50, 0));
799 // Regardless of which order they appear in, the image filter bounds should 799 // Regardless of which order they appear in, the image filter bounds should
800 // be combined correctly. 800 // be combined correctly.
801 { 801 {
802 SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( 802 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offs et.get()));
803 nullptr, offset.get(), nullptr));
804 SkRect bounds = SkRect::MakeWH(100, 100); 803 SkRect bounds = SkRect::MakeWH(100, 100);
805 // Intentionally aliasing here, as that's what the real callers do. 804 // Intentionally aliasing here, as that's what the real callers do.
806 bounds = composite->computeFastBounds(bounds); 805 bounds = composite->computeFastBounds(bounds);
807 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); 806 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
808 } 807 }
809 { 808 {
810 SkAutoTUnref<SkImageFilter> composite(SkXfermodeImageFilter::Create( 809 sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, null ptr,
811 nullptr, nullptr, offset.get())); 810 offset.get(), nullptr));
812 SkRect bounds = SkRect::MakeWH(100, 100); 811 SkRect bounds = SkRect::MakeWH(100, 100);
813 // Intentionally aliasing here, as that's what the real callers do. 812 // Intentionally aliasing here, as that's what the real callers do.
814 bounds = composite->computeFastBounds(bounds); 813 bounds = composite->computeFastBounds(bounds);
815 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100)); 814 REPORTER_ASSERT(reporter, bounds == SkRect::MakeWH(150, 100));
816 } 815 }
817 } 816 }
818 817
819 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy, 818 static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
820 skiatest::Reporter* reporter, 819 skiatest::Reporter* reporter,
821 GrContext* context) { 820 GrContext* context) {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 bitmap.eraseARGB(255, 255, 255, 255); 1241 bitmap.eraseARGB(255, 255, 255, 255);
1243 1242
1244 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M ode)); 1243 auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_M ode));
1245 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre en.get())); 1244 SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(gre en.get()));
1246 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty()); 1245 SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
1247 SkAutoTUnref<SkImageFilter> croppedOut( 1246 SkAutoTUnref<SkImageFilter> croppedOut(
1248 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect)); 1247 SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
1249 1248
1250 // Check that an xfermode image filter whose input has been cropped out stil l draws the other 1249 // Check that an xfermode image filter whose input has been cropped out stil l draws the other
1251 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning. 1250 // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
1252 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrcOver_Mode); 1251 auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
1253 SkAutoTUnref<SkImageFilter> xfermodeNoFg( 1252 auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
1254 SkXfermodeImageFilter::Create(mode, greenFilter, croppedOut)); 1253 auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
1255 SkAutoTUnref<SkImageFilter> xfermodeNoBg( 1254 auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedO ut, nullptr));
1256 SkXfermodeImageFilter::Create(mode, croppedOut, greenFilter));
1257 SkAutoTUnref<SkImageFilter> xfermodeNoFgNoBg(
1258 SkXfermodeImageFilter::Create(mode, croppedOut, croppedOut));
1259 1255
1260 SkPaint paint; 1256 SkPaint paint;
1261 paint.setImageFilter(xfermodeNoFg); 1257 paint.setImageFilter(xfermodeNoFg);
1262 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite 1258 canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
1263 1259
1264 uint32_t pixel; 1260 uint32_t pixel;
1265 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType); 1261 SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, kUnpremul _SkAlphaType);
1266 canvas->readPixels(info, &pixel, 4, 0, 0); 1262 canvas->readPixels(info, &pixel, 4, 0, 0);
1267 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); 1263 REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
1268 1264
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 1585
1590 test_xfermode_cropped_input(&canvas, reporter); 1586 test_xfermode_cropped_input(&canvas, reporter);
1591 } 1587 }
1592 1588
1593 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { 1589 DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
1594 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, 1590 auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
1595 SkImageInfo::MakeN32Premul(100, 100 ))); 1591 SkImageInfo::MakeN32Premul(100, 100 )));
1596 test_large_blur_input(reporter, surface->getCanvas()); 1592 test_large_blur_input(reporter, surface->getCanvas());
1597 } 1593 }
1598 #endif 1594 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698