robertphillips 2016-04-05 12:48:34 -07:00 committed by Commit bot
parent d32eac278e
commit 8c0326df5f
10 changed files with 1791 additions and 54 deletions

View File

@ -160,7 +160,7 @@ protected:
SkPaint paint; SkPaint paint;
paint.setImageFilter(SkXfermodeImageFilter::Make( paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), SkXfermode::Make(SkXfermode::kSrcOver_Mode),
colorMorph.get())); std::move(colorMorph)));
DrawClippedImage(canvas, fImage.get(), paint); DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0); canvas->translate(SkIntToScalar(100), 0);
@ -178,7 +178,9 @@ protected:
SkPaint paint; SkPaint paint;
paint.setImageFilter( paint.setImageFilter(
SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), SkXfermodeImageFilter::Make(SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
matrixFilter.get(), offsetFilter.get(), nullptr)); std::move(matrixFilter),
std::move(offsetFilter),
nullptr));
DrawClippedImage(canvas, fImage.get(), paint); DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0); canvas->translate(SkIntToScalar(100), 0);
@ -191,7 +193,8 @@ protected:
SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100))); SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
SkPaint paint; SkPaint paint;
paint.setImageFilter( paint.setImageFilter(
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcIn_Mode), blur.get(), SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcIn_Mode),
std::move(blur),
nullptr, &cropRect)); nullptr, &cropRect));
DrawClippedImage(canvas, fImage.get(), paint); DrawClippedImage(canvas, fImage.get(), paint);
canvas->translate(SkIntToScalar(100), 0); canvas->translate(SkIntToScalar(100), 0);

View File

@ -88,7 +88,7 @@ protected:
sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard)); sk_sp<SkImageFilter> background(SkImageSource::Make(fCheckerboard));
for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) { for (size_t i = 0; i < SK_ARRAY_COUNT(gModes); i++) {
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gModes[i].fMode), paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(gModes[i].fMode),
background.get())); background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y); DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {
@ -98,7 +98,8 @@ protected:
} }
// Test arithmetic mode as image filter // Test arithmetic mode as image filter
paint.setImageFilter(SkXfermodeImageFilter::Make( paint.setImageFilter(SkXfermodeImageFilter::Make(
SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0), background.get())); SkArithmeticMode::Make(0, SK_Scalar1, SK_Scalar1, 0),
background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y); DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {
@ -106,7 +107,7 @@ protected:
y += fBitmap.height() + MARGIN; y += fBitmap.height() + MARGIN;
} }
// Test nullptr mode // Test nullptr mode
paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background.get())); paint.setImageFilter(SkXfermodeImageFilter::Make(nullptr, background));
DrawClippedBitmap(canvas, fBitmap, paint, x, y); DrawClippedBitmap(canvas, fBitmap, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {
@ -126,8 +127,8 @@ protected:
background)); background));
paint.setImageFilter(SkXfermodeImageFilter::Make( paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode), SkXfermode::Make(SkXfermode::kSrcOver_Mode),
offsetBackground.get(), offsetBackground,
offsetForeground.get(), offsetForeground,
nullptr)); nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
@ -137,8 +138,8 @@ protected:
} }
// Test offsets on Darken (uses shader blend) // Test offsets on Darken (uses shader blend)
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kDarken_Mode), paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kDarken_Mode),
offsetBackground.get(), offsetBackground,
offsetForeground.get(), offsetForeground,
nullptr)); nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
@ -161,8 +162,8 @@ protected:
fBitmap.height() + offsets[i][3]); fBitmap.height() + offsets[i][3]);
SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkImageFilter::CropRect rect(SkRect::Make(cropRect));
paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sampledModes[i]), paint.setImageFilter(SkXfermodeImageFilter::Make(SkXfermode::Make(sampledModes[i]),
offsetBackground.get(), offsetBackground,
offsetForeground.get(), offsetForeground,
&rect)); &rect));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
@ -175,8 +176,7 @@ protected:
auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode); auto mode = SkXfermode::Make(SkXfermode::kScreen_Mode);
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60)); SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(10, 10, 60, 60));
sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect)); sk_sp<SkImageFilter> cropped(SkOffsetImageFilter::Make(0, 0, foreground, &cropRect));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped.get(), paint.setImageFilter(SkXfermodeImageFilter::Make(mode, cropped, background, nullptr));
background.get(), nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {
@ -184,8 +184,7 @@ protected:
y += fBitmap.height() + MARGIN; y += fBitmap.height() + MARGIN;
} }
// Test small fg, large bg with Screen (uses shader blend) // Test small fg, large bg with Screen (uses shader blend)
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(), paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background, cropped, nullptr));
cropped.get(), nullptr));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {
@ -197,8 +196,8 @@ protected:
// the region outside the foreground. // the region outside the foreground.
mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode); mode = SkXfermode::Make(SkXfermode::kSrcIn_Mode);
SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80)); SkImageFilter::CropRect cropRectFull(SkRect::MakeXYWH(0, 0, 80, 80));
paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background.get(), paint.setImageFilter(SkXfermodeImageFilter::Make(mode, background,
cropped.get(), &cropRectFull)); cropped, &cropRectFull));
DrawClippedPaint(canvas, clipRect, paint, x, y); DrawClippedPaint(canvas, clipRect, paint, x, y);
x += fBitmap.width() + MARGIN; x += fBitmap.width() + MARGIN;
if (x + fBitmap.width() > WIDTH) { if (x + fBitmap.width() > WIDTH) {

View File

@ -21,16 +21,32 @@ class SK_API SkXfermodeImageFilter : public SkImageFilter {
*/ */
public: public:
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background, static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background,
SkImageFilter* foreground, const CropRect* cropRect); sk_sp<SkImageFilter> foreground, const CropRect* cropRect);
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background) { static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background) {
return Make(std::move(mode), background, nullptr, nullptr); return Make(std::move(mode), std::move(background), nullptr, nullptr);
} }
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR #ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background, static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = NULL, SkImageFilter* foreground = NULL,
const CropRect* cropRect = NULL) { const CropRect* cropRect = NULL) {
return Make(sk_ref_sp(mode), background, foreground, cropRect).release(); return Make(sk_ref_sp(mode),
sk_ref_sp(background),
sk_ref_sp(foreground),
cropRect).release();
}
#endif
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
SkImageFilter* foreground, const CropRect* cropRect) {
return Make(std::move(mode),
sk_ref_sp(background),
sk_ref_sp(foreground),
cropRect);
}
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background) {
return Make(std::move(mode), sk_ref_sp(background));
} }
#endif #endif
@ -49,7 +65,7 @@ public:
#endif #endif
protected: protected:
SkXfermodeImageFilter(sk_sp<SkXfermode> mode, SkImageFilter* inputs[2], SkXfermodeImageFilter(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> inputs[2],
const CropRect* cropRect); const CropRect* cropRect);
void flatten(SkWriteBuffer&) const override; void flatten(SkWriteBuffer&) const override;

View File

@ -588,15 +588,12 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
case DOWN_SAMPLE: case DOWN_SAMPLE:
filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scalar())); filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scalar()));
break; break;
case XFERMODE: { case XFERMODE:
sk_sp<SkImageFilter> subFilter1(make_image_filter());
sk_sp<SkImageFilter> subFilter2(make_image_filter());
filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()), filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()),
subFilter1.get(), make_image_filter(),
subFilter2.get(), make_image_filter(),
nullptr); nullptr);
break; break;
}
case OFFSET: case OFFSET:
filter = SkOffsetImageFilter::Make(make_scalar(), make_scalar(), make_image_filter()); filter = SkOffsetImageFilter::Make(make_scalar(), make_scalar(), make_image_filter());
break; break;

View File

@ -23,24 +23,25 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
sk_sp<SkImageFilter> SkXfermodeImageFilter::Make(sk_sp<SkXfermode> mode, SkImageFilter* background, sk_sp<SkImageFilter> SkXfermodeImageFilter::Make(sk_sp<SkXfermode> mode,
SkImageFilter* foreground, sk_sp<SkImageFilter> background,
sk_sp<SkImageFilter> foreground,
const CropRect* cropRect) { const CropRect* cropRect) {
SkImageFilter* inputs[2] = { background, foreground }; sk_sp<SkImageFilter> inputs[2] = { std::move(background), std::move(foreground) };
return sk_sp<SkImageFilter>(new SkXfermodeImageFilter(mode, inputs, cropRect)); return sk_sp<SkImageFilter>(new SkXfermodeImageFilter(mode, inputs, cropRect));
} }
SkXfermodeImageFilter::SkXfermodeImageFilter(sk_sp<SkXfermode> mode, SkXfermodeImageFilter::SkXfermodeImageFilter(sk_sp<SkXfermode> mode,
SkImageFilter* inputs[2], sk_sp<SkImageFilter> inputs[2],
const CropRect* cropRect) const CropRect* cropRect)
: INHERITED(2, inputs, cropRect) : INHERITED(inputs, 2, cropRect)
, fMode(std::move(mode)) , fMode(std::move(mode))
{} {}
sk_sp<SkFlattenable> SkXfermodeImageFilter::CreateProc(SkReadBuffer& buffer) { sk_sp<SkFlattenable> SkXfermodeImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2); SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
sk_sp<SkXfermode> mode(buffer.readXfermode()); sk_sp<SkXfermode> mode(buffer.readXfermode());
return Make(std::move(mode), common.getInput(0).get(), common.getInput(1).get(), return Make(std::move(mode), common.getInput(0), common.getInput(1),
&common.cropRect()); &common.cropRect());
} }

View File

@ -261,8 +261,7 @@ public:
cropRect).release()); cropRect).release());
} }
this->addFilter("xfermode", SkXfermodeImageFilter::Make( this->addFilter("xfermode", SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrc_Mode), input.get(), input.get(), SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
cropRect).release());
} }
int count() const { return fFilters.count(); } int count() const { return fFilters.count(); }
SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); } SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
@ -911,7 +910,7 @@ DEF_TEST(ImageFilterUnionBounds, reporter) {
// Regardless of which order they appear in, the image filter bounds should // Regardless of which order they appear in, the image filter bounds should
// be combined correctly. // be combined correctly.
{ {
sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offset.get())); sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, offset));
SkRect bounds = SkRect::MakeWH(100, 100); SkRect bounds = SkRect::MakeWH(100, 100);
// Intentionally aliasing here, as that's what the real callers do. // Intentionally aliasing here, as that's what the real callers do.
bounds = composite->computeFastBounds(bounds); bounds = composite->computeFastBounds(bounds);
@ -919,7 +918,7 @@ DEF_TEST(ImageFilterUnionBounds, reporter) {
} }
{ {
sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, nullptr, sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, nullptr,
offset.get(), nullptr)); offset, nullptr));
SkRect bounds = SkRect::MakeWH(100, 100); SkRect bounds = SkRect::MakeWH(100, 100);
// Intentionally aliasing here, as that's what the real callers do. // Intentionally aliasing here, as that's what the real callers do.
bounds = composite->computeFastBounds(bounds); bounds = composite->computeFastBounds(bounds);
@ -1357,17 +1356,16 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
// Check that an xfermode image filter whose input has been cropped out still draws the other // 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. // input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode); sk_sp<SkXfermode> mode(SkXfermode::Make(SkXfermode::kSrcOver_Mode));
auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, sk_sp<SkImageFilter> xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter,
greenFilter.get(), croppedOut.get(), nullptr)); croppedOut, nullptr));
auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, sk_sp<SkImageFilter> xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut,
croppedOut.get(), greenFilter.get(), nullptr)); greenFilter, nullptr));
auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, sk_sp<SkImageFilter> xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut,
croppedOut.get(), croppedOut, nullptr));
croppedOut.get(), nullptr));
SkPaint paint; SkPaint paint;
paint.setImageFilter(xfermodeNoFg); paint.setImageFilter(std::move(xfermodeNoFg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
uint32_t pixel; uint32_t pixel;
@ -1375,12 +1373,12 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
canvas->readPixels(info, &pixel, 4, 0, 0); canvas->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(xfermodeNoBg); paint.setImageFilter(std::move(xfermodeNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->readPixels(info, &pixel, 4, 0, 0); canvas->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(xfermodeNoFgNoBg); paint.setImageFilter(std::move(xfermodeNoFgNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->readPixels(info, &pixel, 4, 0, 0); canvas->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN); REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,20 @@
*************** public:
*** 231,237 ****
cropRect).release());
}
this->addFilter("xfermode", SkXfermodeImageFilter::Make(
- SkXfermode::Make(SkXfermode::kSrc_Mode), input, input, cropRect).release());
}
int count() const { return fFilters.count(); }
SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }
--- 231,240 ----
cropRect).release());
}
this->addFilter("xfermode", SkXfermodeImageFilter::Make(
+ SkXfermode::Make(SkXfermode::kSrc_Mode),
+ sk_ref_sp<SkImageFilter>(input),
+ sk_ref_sp<SkImageFilter>(input),
+ cropRect).release());
}
int count() const { return fFilters.count(); }
SkImageFilter* getFilter(int index) const { return fFilters[index].fFilter.get(); }

View File

@ -248,7 +248,8 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
sk_sp<SkImageFilter> invalidBitmapSource(SkImageSource::Make(std::move(invalidImage))); sk_sp<SkImageFilter> invalidBitmapSource(SkImageSource::Make(std::move(invalidImage)));
sk_sp<SkImageFilter> xfermodeImageFilter( sk_sp<SkImageFilter> xfermodeImageFilter(
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode), SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode),
invalidBitmapSource.get(), validBitmapSource.get(), nullptr)); std::move(invalidBitmapSource),
std::move(validBitmapSource), nullptr));
SkAutoTUnref<SkImageFilter> deserializedFilter( SkAutoTUnref<SkImageFilter> deserializedFilter(
TestFlattenableSerialization<SkImageFilter>( TestFlattenableSerialization<SkImageFilter>(