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

Unified Diff: tests/ImageFilterTest.cpp.orig

Issue 1852123002: Update SkXfermodeImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Overload Make methods 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/ImageFilterTest.cpp ('k') | tests/ImageFilterTest.cpp.rej » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp.orig
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp.orig
similarity index 93%
copy from tests/ImageFilterTest.cpp
copy to tests/ImageFilterTest.cpp.orig
index 42613a35c50257500c01a42dd7a039a09b355005..49455c9481629453cc344a6b324573127697adcc 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp.orig
@@ -164,7 +164,7 @@ public:
SkXfermode::kSrcIn_Mode));
this->addFilter("color filter",
- SkColorFilterImageFilter::Make(cf, input, cropRect).release());
+ SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect));
}
{
@@ -333,33 +333,30 @@ static sk_sp<SkImage> make_small_image() {
return surface->makeImageSnapshot();
}
-static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) {
+static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
SkScalar s = amount;
SkScalar matrix[20] = { s, 0, 0, 0, 0,
0, s, 0, 0, 0,
0, 0, s, 0, 0,
0, 0, 0, s, 0 };
- sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+ auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Create(filter.get(), input);
}
-static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input,
- const SkImageFilter::CropRect* cropRect) {
+static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
SkScalar matrix[20];
memset(matrix, 0, 20 * sizeof(SkScalar));
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
- sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
+ auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
}
-static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
- const SkImageFilter::CropRect* cropRect) {
- sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
- SkXfermode::kSrcIn_Mode));
- return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
+static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
+ auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
+ return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
}
static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
@@ -398,8 +395,8 @@ static sk_sp<SkSpecialImage> create_empty_special_image(GrContext* context,
DEF_TEST(ImageFilter, reporter) {
{
// Check that two non-clipping color-matrice-filters concatenate into a single filter.
- sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, nullptr));
- sk_sp<SkImageFilter> quarterBrightness(make_scale(0.5f, std::move(halfBrightness)));
+ SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f));
+ SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrightness));
REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0));
SkColorFilter* cf;
REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf));
@@ -410,8 +407,8 @@ DEF_TEST(ImageFilter, reporter) {
{
// Check that a clipping color-matrice-filter followed by a color-matrice-filters
// concatenates into a single filter, but not a matrixfilter (due to clamping).
- sk_sp<SkImageFilter> doubleBrightness(make_scale(2.0f, nullptr));
- sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, std::move(doubleBrightness)));
+ SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f));
+ SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBrightness));
REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0));
SkColorFilter* cf;
REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf));
@@ -422,25 +419,25 @@ DEF_TEST(ImageFilter, reporter) {
{
// Check that a color filter image filter without a crop rect can be
// expressed as a color filter.
- sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
+ SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
}
{
// Check that a colorfilterimage filter without a crop rect but with an input
// that is another colorfilterimage can be expressed as a colorfilter (composed).
- sk_sp<SkImageFilter> mode(make_blue(nullptr, nullptr));
- sk_sp<SkImageFilter> gray(make_grayscale(std::move(mode), nullptr));
+ SkAutoTUnref<SkImageFilter> mode(make_blue(nullptr, nullptr));
+ SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, nullptr));
REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
}
{
// Test that if we exceed the limit of what ComposeColorFilter can combine, we still
// can build the DAG and won't assert if we call asColorFilter.
- sk_sp<SkImageFilter> filter(make_blue(nullptr, nullptr));
+ SkAutoTUnref<SkImageFilter> filter(make_blue(nullptr, nullptr));
const int kWayTooManyForComposeColorFilter = 100;
for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) {
- filter = make_blue(filter, nullptr);
+ filter.reset(make_blue(filter, nullptr));
// the first few of these will succeed, but after we hit the internal limit,
// it will then return false.
(void)filter->asColorFilter(nullptr);
@@ -451,7 +448,7 @@ DEF_TEST(ImageFilter, reporter) {
// Check that a color filter image filter with a crop rect cannot
// be expressed as a color filter.
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
- sk_sp<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
+ SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr));
}
@@ -462,19 +459,17 @@ DEF_TEST(ImageFilter, reporter) {
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
SkScalar redToGreenMatrix[20] = { 0 };
redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
- sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
- sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(blueToRed),
- nullptr));
- sk_sp<SkColorFilter> redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
- sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(redToGreen),
- std::move(filter1)));
+ auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
+ SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blueToRed.get()));
+ auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
+ SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get()));
SkBitmap result;
result.allocN32Pixels(kBitmapSize, kBitmapSize);
SkPaint paint;
paint.setColor(SK_ColorBLUE);
- paint.setImageFilter(std::move(filter2));
+ paint.setImageFilter(filter2.get());
SkCanvas canvas(result);
canvas.clear(0x0);
SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize));
@@ -719,8 +714,8 @@ static void test_fail_affects_transparent_black(SkImageFilter::Proxy* proxy,
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr);
sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
SkASSERT(green->affectsTransparentBlack());
- sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(green),
- std::move(failFilter)));
+ sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get(),
+ failFilter.get()));
SkIPoint offset;
sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &offset));
REPORTER_ASSERT(reporter, nullptr != result.get());
@@ -800,14 +795,12 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(50), 0);
- sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
- sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
- sk_sp<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix,
- kNone_SkFilterQuality,
- cfif.get()));
+ auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
+ SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
+ SkAutoTUnref<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality, cfif.get()));
SkPaint paint;
- paint.setImageFilter(std::move(imageFilter));
+ paint.setImageFilter(imageFilter.get());
SkPictureRecorder recorder;
SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
@@ -1227,11 +1220,11 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
SkRTreeFactory factory;
SkPictureRecorder recorder;
- sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
- SkXfermode::kSrc_Mode));
- sk_sp<SkImageFilter> imageFilter(SkColorFilterImageFilter::Make(green, nullptr));
+ auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
+ SkAutoTUnref<SkImageFilter> imageFilter(
+ SkColorFilterImageFilter::Create(green.get()));
SkPaint imageFilterPaint;
- imageFilterPaint.setImageFilter(std::move(imageFilter));
+ imageFilterPaint.setImageFilter(imageFilter.get());
SkPaint colorFilterPaint;
colorFilterPaint.setColorFilter(green);
@@ -1349,22 +1342,18 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
bitmap.allocN32Pixels(1, 1);
bitmap.eraseARGB(255, 255, 255, 255);
- sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
- SkXfermode::kSrcIn_Mode));
- sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(green, nullptr));
+ auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
+ SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get()));
SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
- sk_sp<SkImageFilter> croppedOut(SkColorFilterImageFilter::Make(green, nullptr, &cropRect));
+ SkAutoTUnref<SkImageFilter> croppedOut(
+ SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
// Check that an xfermode image filter whose input has been cropped out still draws the other
// input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
- auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode,
- greenFilter.get(), croppedOut.get(), nullptr));
- auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode,
- croppedOut.get(), greenFilter.get(), nullptr));
- auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode,
- croppedOut.get(),
- croppedOut.get(), nullptr));
+ auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
+ auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
+ auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedOut, nullptr));
SkPaint paint;
paint.setImageFilter(xfermodeNoFg);
@@ -1523,7 +1512,7 @@ static void test_partial_crop_rect(SkImageFilter::Proxy* proxy,
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge);
- sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
+ SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
@@ -1575,7 +1564,7 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
0, 0, 0, 0, 0,
0, 0, 0, 0, 1 };
sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
- sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullptr));
+ sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get()));
REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
@@ -1591,15 +1580,13 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
allOne[i] = 255;
}
- sk_sp<SkColorFilter> identityCF(SkTableColorFilter::MakeARGB(identity, identity,
- identity, allOne));
- sk_sp<SkImageFilter> identityFilter(SkColorFilterImageFilter::Make(identityCF, nullptr));
+ auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne));
+ SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(identityCF.get()));
REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
- sk_sp<SkColorFilter> forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity,
- identity, identity));
- sk_sp<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueCF, nullptr));
+ auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity));
+ SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get()));
REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
}
« no previous file with comments | « tests/ImageFilterTest.cpp ('k') | tests/ImageFilterTest.cpp.rej » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698