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

@ -45,7 +45,7 @@ static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
class ColorFilterBaseBench : public Benchmark {
public:
ColorFilterBaseBench(bool small) : fIsSmall(small) {}
ColorFilterBaseBench(bool small) : fIsSmall(small) { }
protected:
SkRect getFilterRect() const {

View File

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

View File

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

View File

@ -21,19 +21,35 @@ class SK_API SkXfermodeImageFilter : public SkImageFilter {
*/
public:
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
SkImageFilter* foreground, const CropRect* cropRect);
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, SkImageFilter* background) {
return Make(std::move(mode), background, nullptr, nullptr);
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background,
sk_sp<SkImageFilter> foreground, const CropRect* cropRect);
static sk_sp<SkImageFilter> Make(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> background) {
return Make(std::move(mode), std::move(background), nullptr, nullptr);
}
#ifdef SK_SUPPORT_LEGACY_XFERMODE_PTR
static SkImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
SkImageFilter* foreground = 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
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
@ -49,7 +65,7 @@ public:
#endif
protected:
SkXfermodeImageFilter(sk_sp<SkXfermode> mode, SkImageFilter* inputs[2],
SkXfermodeImageFilter(sk_sp<SkXfermode> mode, sk_sp<SkImageFilter> inputs[2],
const CropRect* cropRect);
void flatten(SkWriteBuffer&) const override;

View File

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

View File

@ -23,24 +23,25 @@
///////////////////////////////////////////////////////////////////////////////
sk_sp<SkImageFilter> SkXfermodeImageFilter::Make(sk_sp<SkXfermode> mode, SkImageFilter* background,
SkImageFilter* foreground,
sk_sp<SkImageFilter> SkXfermodeImageFilter::Make(sk_sp<SkXfermode> mode,
sk_sp<SkImageFilter> background,
sk_sp<SkImageFilter> foreground,
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));
}
SkXfermodeImageFilter::SkXfermodeImageFilter(sk_sp<SkXfermode> mode,
SkImageFilter* inputs[2],
sk_sp<SkImageFilter> inputs[2],
const CropRect* cropRect)
: INHERITED(2, inputs, cropRect)
: INHERITED(inputs, 2, cropRect)
, fMode(std::move(mode))
{}
sk_sp<SkFlattenable> SkXfermodeImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
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());
}

View File

@ -261,8 +261,7 @@ public:
cropRect).release());
}
this->addFilter("xfermode", SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrc_Mode), input.get(), input.get(),
cropRect).release());
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(); }
@ -911,7 +910,7 @@ DEF_TEST(ImageFilterUnionBounds, reporter) {
// Regardless of which order they appear in, the image filter bounds should
// 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);
// Intentionally aliasing here, as that's what the real callers do.
bounds = composite->computeFastBounds(bounds);
@ -919,7 +918,7 @@ DEF_TEST(ImageFilterUnionBounds, reporter) {
}
{
sk_sp<SkImageFilter> composite(SkXfermodeImageFilter::Make(nullptr, nullptr,
offset.get(), nullptr));
offset, nullptr));
SkRect bounds = SkRect::MakeWH(100, 100);
// Intentionally aliasing here, as that's what the real callers do.
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
// 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));
sk_sp<SkXfermode> mode(SkXfermode::Make(SkXfermode::kSrcOver_Mode));
sk_sp<SkImageFilter> xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter,
croppedOut, nullptr));
sk_sp<SkImageFilter> xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut,
greenFilter, nullptr));
sk_sp<SkImageFilter> xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut,
croppedOut, nullptr));
SkPaint paint;
paint.setImageFilter(xfermodeNoFg);
paint.setImageFilter(std::move(xfermodeNoFg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
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);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(xfermodeNoBg);
paint.setImageFilter(std::move(xfermodeNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->readPixels(info, &pixel, 4, 0, 0);
REPORTER_ASSERT(reporter, pixel == SK_ColorGREEN);
paint.setImageFilter(xfermodeNoFgNoBg);
paint.setImageFilter(std::move(xfermodeNoFgNoBg));
canvas->drawBitmap(bitmap, 0, 0, &paint); // drawSprite
canvas->readPixels(info, &pixel, 4, 0, 0);
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> xfermodeImageFilter(
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode),
invalidBitmapSource.get(), validBitmapSource.get(), nullptr));
std::move(invalidBitmapSource),
std::move(validBitmapSource), nullptr));
SkAutoTUnref<SkImageFilter> deserializedFilter(
TestFlattenableSerialization<SkImageFilter>(