Update SkImageSource to sk_sp
TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1842243002 Review URL: https://codereview.chromium.org/1842243002
This commit is contained in:
parent
f27002947d
commit
549c899195
@ -102,11 +102,11 @@ protected:
|
||||
|
||||
void onDraw(int loops, SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard));
|
||||
// No displacement effect
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))->unref();
|
||||
|
||||
for (int i = 0; i < loops; i++) {
|
||||
this->drawClippedBitmap(canvas, 0, 0, paint);
|
||||
@ -129,11 +129,11 @@ protected:
|
||||
|
||||
void onDraw(int loops, SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard));
|
||||
// Displacement, with 1 alpha component (which isn't pre-multiplied)
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref();
|
||||
for (int i = 0; i < loops; i++) {
|
||||
drawClippedBitmap(canvas, 100, 0, paint);
|
||||
}
|
||||
@ -155,11 +155,11 @@ protected:
|
||||
|
||||
void onDraw(int loops, SkCanvas* canvas) override {
|
||||
SkPaint paint;
|
||||
SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard));
|
||||
// Displacement, with 2 non-alpha components
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get()))->unref();
|
||||
for (int i = 0; i < loops; ++i) {
|
||||
this->drawClippedBitmap(canvas, 200, 0, paint);
|
||||
}
|
||||
|
@ -80,9 +80,8 @@ protected:
|
||||
|
||||
private:
|
||||
sk_sp<SkImageFilter> mergeBitmaps() {
|
||||
sk_sp<SkImageFilter> first(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> second(SkImageSource::Create(fImage.get()));
|
||||
return SkMergeImageFilter::Make(std::move(first), std::move(second));
|
||||
return SkMergeImageFilter::Make(SkImageSource::Make(fCheckerboard),
|
||||
SkImageSource::Make(fImage));
|
||||
}
|
||||
|
||||
bool fIsSmall;
|
||||
|
@ -54,13 +54,15 @@ protected:
|
||||
{
|
||||
SkPaint p;
|
||||
|
||||
SkRect bound = SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight));
|
||||
sk_sp<SkImageFilter> imageSource(SkImageSource::Create(fRedImage.get()));
|
||||
SkAutoTUnref<SkImageFilter> tif(SkTileImageFilter::Create(
|
||||
SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)),
|
||||
SkRect::MakeWH(SkIntToScalar(kWidth), SkIntToScalar(kHeight)),
|
||||
imageSource.get()));
|
||||
p.setImageFilter(tif);
|
||||
const SkRect bound = SkRect::MakeIWH(kWidth, kHeight);
|
||||
sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fRedImage));
|
||||
|
||||
sk_sp<SkImageFilter> tif(SkTileImageFilter::Create(
|
||||
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
||||
SkRect::MakeIWH(kWidth, kHeight),
|
||||
imageSource.get()));
|
||||
|
||||
p.setImageFilter(std::move(tif));
|
||||
|
||||
canvas->saveLayer(&bound, &p);
|
||||
canvas->restore();
|
||||
@ -69,13 +71,14 @@ protected:
|
||||
{
|
||||
SkPaint p2;
|
||||
|
||||
SkRect bound2 = SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize));
|
||||
const SkRect bound2 = SkRect::MakeIWH(kBitmapSize, kBitmapSize);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> tif2(SkTileImageFilter::Create(
|
||||
SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)),
|
||||
SkRect::MakeWH(SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize)),
|
||||
nullptr));
|
||||
p2.setImageFilter(tif2);
|
||||
sk_sp<SkImageFilter> tif(SkTileImageFilter::Create(
|
||||
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
||||
SkRect::MakeIWH(kBitmapSize, kBitmapSize),
|
||||
nullptr));
|
||||
|
||||
p2.setImageFilter(std::move(tif));
|
||||
|
||||
canvas->translate(320, 320);
|
||||
canvas->saveLayer(&bound2, &p2);
|
||||
|
@ -57,133 +57,133 @@ protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard));
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 0, 0, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 100, 0, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 200, 0, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 48.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 300, 0, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 64.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 400, 0, paint);
|
||||
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType, 40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 0, 100, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 100, 100, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType, 40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 200, 100, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 300, 100, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ))->unref();
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType, 40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 400, 100, paint);
|
||||
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(30, 30, 40, 40));
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
0.0f, displ, nullptr, &cropRect))->unref();
|
||||
0.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 0, 200, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
16.0f, displ, nullptr, &cropRect))->unref();
|
||||
16.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 100, 200, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
32.0f, displ, nullptr, &cropRect))->unref();
|
||||
32.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 200, 200, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
48.0f, displ, nullptr, &cropRect))->unref();
|
||||
48.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 300, 200, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
64.0f, displ, nullptr, &cropRect))->unref();
|
||||
64.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 400, 200, paint);
|
||||
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
40.0f, displ, nullptr, &cropRect))->unref();
|
||||
40.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 0, 300, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
40.0f, displ, nullptr, &cropRect))->unref();
|
||||
40.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 100, 300, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
40.0f, displ, nullptr, &cropRect))->unref();
|
||||
40.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 200, 300, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
40.0f, displ, nullptr, &cropRect))->unref();
|
||||
40.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 300, 300, paint);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
40.0f, displ, nullptr, &cropRect))->unref();
|
||||
40.0f, displ.get(), nullptr, &cropRect))->unref();
|
||||
drawClippedBitmap(canvas, 400, 300, paint);
|
||||
|
||||
// Test for negative scale.
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
-40.0f, displ))->unref();
|
||||
-40.0f, displ.get()))->unref();
|
||||
this->drawClippedBitmap(canvas, 500, 0, paint);
|
||||
|
||||
// Tests for images of different sizes
|
||||
displ.reset(SkImageSource::Create(fSmall.get()));
|
||||
displ = SkImageSource::Make(fSmall);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
40.0f, displ))->unref();
|
||||
40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 0, 400, paint);
|
||||
displ.reset(SkImageSource::Create(fLarge.get()));
|
||||
displ = SkImageSource::Make(fLarge);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
40.0f, displ))->unref();
|
||||
40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 100, 400, paint);
|
||||
displ.reset(SkImageSource::Create(fLargeW.get()));
|
||||
displ = SkImageSource::Make(fLargeW);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kR_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kB_ChannelSelectorType,
|
||||
40.0f, displ))->unref();
|
||||
40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 200, 400, paint);
|
||||
displ.reset(SkImageSource::Create(fLargeH.get()));
|
||||
displ = SkImageSource::Make(fLargeH);
|
||||
paint.setImageFilter(SkDisplacementMapEffect::Create(
|
||||
SkDisplacementMapEffect::kG_ChannelSelectorType,
|
||||
SkDisplacementMapEffect::kA_ChannelSelectorType,
|
||||
40.0f, displ))->unref();
|
||||
40.0f, displ.get()))->unref();
|
||||
drawClippedBitmap(canvas, 300, 400, paint);
|
||||
|
||||
// Test for no given displacement input. In this case, both displacement
|
||||
|
@ -277,10 +277,10 @@ protected:
|
||||
}
|
||||
|
||||
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
||||
SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(image.get()));
|
||||
sk_sp<SkImageFilter> imageSource(SkImageSource::Make(std::move(image)));
|
||||
|
||||
SkTArray<SkPaint> bmsPaints;
|
||||
create_paints(imageSource, &bmsPaints);
|
||||
create_paints(imageSource.get(), &bmsPaints);
|
||||
|
||||
//-----------
|
||||
SkASSERT(paints.count() == kNumVertTiles);
|
||||
|
@ -26,6 +26,41 @@
|
||||
#define RESIZE_FACTOR_X SkIntToScalar(2)
|
||||
#define RESIZE_FACTOR_Y SkIntToScalar(5)
|
||||
|
||||
static sk_sp<SkImage> make_gradient_circle(int width, int height) {
|
||||
SkScalar x = SkIntToScalar(width / 2);
|
||||
SkScalar y = SkIntToScalar(height / 2);
|
||||
SkScalar radius = SkMinScalar(x, y) * 0.8f;
|
||||
auto surface(SkSurface::MakeRasterN32Premul(width, height));
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
canvas->clear(0x00000000);
|
||||
SkColor colors[2];
|
||||
colors[0] = SK_ColorWHITE;
|
||||
colors[1] = SK_ColorBLACK;
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
|
||||
2, SkShader::kClamp_TileMode));
|
||||
canvas->drawCircle(x, y, radius, paint);
|
||||
return surface->makeImageSnapshot();
|
||||
}
|
||||
|
||||
static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i,
|
||||
const SkRect& primBounds, const SkRect& clipBounds) {
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
paint.setImageFilter(filter);
|
||||
paint.setAntiAlias(true);
|
||||
canvas->save();
|
||||
canvas->clipRect(clipBounds);
|
||||
if (5 == i) {
|
||||
canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
|
||||
} else if (6 == i) {
|
||||
canvas->scale(SkScalarInvert(RESIZE_FACTOR_X), SkScalarInvert(RESIZE_FACTOR_Y));
|
||||
}
|
||||
canvas->drawCircle(primBounds.centerX(), primBounds.centerY(),
|
||||
primBounds.width() * 2 / 5, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
namespace skiagm {
|
||||
|
||||
class ImageFiltersClippedGM : public GM {
|
||||
@ -43,55 +78,17 @@ protected:
|
||||
return SkISize::Make(860, 500);
|
||||
}
|
||||
|
||||
void makeGradientCircle(int width, int height) {
|
||||
SkScalar x = SkIntToScalar(width / 2);
|
||||
SkScalar y = SkIntToScalar(height / 2);
|
||||
SkScalar radius = SkMinScalar(x, y) * 0.8f;
|
||||
auto surface(SkSurface::MakeRasterN32Premul(width, height));
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
canvas->clear(0x00000000);
|
||||
SkColor colors[2];
|
||||
colors[0] = SK_ColorWHITE;
|
||||
colors[1] = SK_ColorBLACK;
|
||||
SkPaint paint;
|
||||
paint.setShader(SkGradientShader::MakeRadial(SkPoint::Make(x, y), radius, colors, nullptr,
|
||||
2, SkShader::kClamp_TileMode));
|
||||
canvas->drawCircle(x, y, radius, paint);
|
||||
fGradientCircle = surface->makeImageSnapshot();
|
||||
}
|
||||
|
||||
static void draw_clipped_filter(SkCanvas* canvas, SkImageFilter* filter, size_t i,
|
||||
const SkRect& primBounds, const SkRect& clipBounds) {
|
||||
SkPaint paint;
|
||||
paint.setColor(SK_ColorWHITE);
|
||||
paint.setImageFilter(filter);
|
||||
paint.setAntiAlias(true);
|
||||
canvas->save();
|
||||
canvas->clipRect(clipBounds);
|
||||
if (5 == i) {
|
||||
canvas->translate(SkIntToScalar(16), SkIntToScalar(-32));
|
||||
} else if (6 == i) {
|
||||
canvas->scale(SkScalarInvert(RESIZE_FACTOR_X),
|
||||
SkScalarInvert(RESIZE_FACTOR_Y));
|
||||
}
|
||||
canvas->drawCircle(primBounds.centerX(), primBounds.centerY(),
|
||||
primBounds.width() * 2 / 5, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
fCheckerboard = SkImage::MakeFromBitmap
|
||||
(sk_tool_utils::create_checkerboard_bitmap(64, 64, 0xFFA0A0A0, 0xFF404040, 8));
|
||||
this->makeGradientCircle(64, 64);
|
||||
fGradientCircle = make_gradient_circle(64, 64);
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get()));
|
||||
SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkShader> noise(SkPerlinNoiseShader::MakeFractalNoise(
|
||||
SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
|
||||
sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle));
|
||||
sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard));
|
||||
SkMatrix resizeMatrix;
|
||||
resizeMatrix.setScale(RESIZE_FACTOR_X, RESIZE_FACTOR_Y);
|
||||
SkPoint3 pointLocation = SkPoint3::Make(32, 32, SkIntToScalar(10));
|
||||
@ -112,7 +109,8 @@ protected:
|
||||
SkIntToScalar(32),
|
||||
nullptr).release(),
|
||||
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1, SkIntToScalar(2), checkerboard.get()),
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, SK_ColorWHITE, SK_Scalar1,
|
||||
SkIntToScalar(2), checkerboard.get()),
|
||||
|
||||
};
|
||||
|
||||
@ -139,7 +137,8 @@ protected:
|
||||
}
|
||||
|
||||
SkPaint noisePaint;
|
||||
noisePaint.setShader(noise);
|
||||
noisePaint.setShader(SkPerlinNoiseShader::MakeFractalNoise(0.1f, 0.05f, 1, 0));
|
||||
|
||||
sk_sp<SkImageFilter> rectFilter(SkPaintImageFilter::Make(noisePaint));
|
||||
canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
|
||||
for (int xOffset = 0; xOffset < 80; xOffset += 16) {
|
||||
|
@ -48,8 +48,7 @@ protected:
|
||||
SkBitmap checkerboard;
|
||||
MakeCheckerboard(&checkerboard);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> gradientCircleSource(
|
||||
SkImageSource::Create(gradientCircle.get()));
|
||||
sk_sp<SkImageFilter> gradientCircleSource(SkImageSource::Make(std::move(gradientCircle)));
|
||||
sk_sp<SkImageFilter> noopCropped(SkOffsetImageFilter::Make(0, 0, nullptr, &cropRect));
|
||||
SkScalar sk255 = SkIntToScalar(255);
|
||||
SkScalar matrix[20] = { 1, 0, 0, 0, 0,
|
||||
|
@ -118,7 +118,7 @@ protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
{
|
||||
sk_sp<SkImageFilter> bitmapSource(SkImageSource::Create(fImage.get()));
|
||||
sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage));
|
||||
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0f, bitmapSource.get()));
|
||||
|
@ -52,8 +52,8 @@ protected:
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get()));
|
||||
SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle));
|
||||
sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard));
|
||||
sk_sp<SkShader> noise(SkPerlinNoiseShader::MakeFractalNoise(
|
||||
SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
|
||||
SkPaint noisePaint;
|
||||
|
@ -63,8 +63,8 @@ protected:
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkAutoTUnref<SkImageFilter> gradient(SkImageSource::Create(fGradientCircle.get()));
|
||||
SkAutoTUnref<SkImageFilter> checkerboard(SkImageSource::Create(fCheckerboard.get()));
|
||||
sk_sp<SkImageFilter> gradient(SkImageSource::Make(fGradientCircle));
|
||||
sk_sp<SkImageFilter> checkerboard(SkImageSource::Make(fCheckerboard));
|
||||
SkImageFilter* filters[] = {
|
||||
SkBlurImageFilter::Create(12, 0),
|
||||
SkDropShadowImageFilter::Create(0, 15, 8, 0, SK_ColorGREEN,
|
||||
|
@ -12,6 +12,17 @@
|
||||
|
||||
// This GM exercises the SkImageSource ImageFilter class.
|
||||
|
||||
static void fill_rect_filtered(SkCanvas* canvas,
|
||||
const SkRect& clipRect,
|
||||
sk_sp<SkImageFilter> filter) {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(std::move(filter));
|
||||
canvas->save();
|
||||
canvas->clipRect(clipRect);
|
||||
canvas->drawPaint(paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
class ImageSourceGM : public skiagm::GM {
|
||||
public:
|
||||
ImageSourceGM() { }
|
||||
@ -28,44 +39,39 @@ protected:
|
||||
fImage = SkImage::MakeFromBitmap(bm);
|
||||
}
|
||||
|
||||
static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(filter);
|
||||
canvas->save();
|
||||
canvas->clipRect(clipRect);
|
||||
canvas->drawPaint(paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
|
||||
const SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
|
||||
const SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
|
||||
const SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
|
||||
const SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
|
||||
|
||||
{
|
||||
SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
|
||||
SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
|
||||
SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
|
||||
SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
|
||||
SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fImage.get()));
|
||||
SkAutoTUnref<SkImageFilter> imageSourceSrcRect(
|
||||
SkImageSource::Create(fImage.get(), srcRect, srcRect, kHigh_SkFilterQuality));
|
||||
SkAutoTUnref<SkImageFilter> imageSourceSrcRectDstRect(
|
||||
SkImageSource::Create(fImage.get(), srcRect, dstRect, kHigh_SkFilterQuality));
|
||||
SkAutoTUnref<SkImageFilter> imageSourceDstRectOnly(
|
||||
SkImageSource::Create(fImage.get(), bounds, dstRect, kHigh_SkFilterQuality));
|
||||
|
||||
// Draw an unscaled bitmap.
|
||||
FillRectFiltered(canvas, clipRect, imageSource);
|
||||
sk_sp<SkImageFilter> imageSource(SkImageSource::Make(fImage));
|
||||
fill_rect_filtered(canvas, clipRect, std::move(imageSource));
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
}
|
||||
{
|
||||
// Draw an unscaled subset of the source bitmap (srcRect -> srcRect).
|
||||
FillRectFiltered(canvas, clipRect, imageSourceSrcRect);
|
||||
sk_sp<SkImageFilter> imageSourceSrcRect(
|
||||
SkImageSource::Make(fImage, srcRect, srcRect, kHigh_SkFilterQuality));
|
||||
fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRect));
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
}
|
||||
{
|
||||
// Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect).
|
||||
FillRectFiltered(canvas, clipRect, imageSourceSrcRectDstRect);
|
||||
sk_sp<SkImageFilter> imageSourceSrcRectDstRect(
|
||||
SkImageSource::Make(fImage, srcRect, dstRect, kHigh_SkFilterQuality));
|
||||
fill_rect_filtered(canvas, clipRect, std::move(imageSourceSrcRectDstRect));
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
}
|
||||
{
|
||||
// Draw the entire bitmap scaled to a destination rect (bounds -> dstRect).
|
||||
FillRectFiltered(canvas, clipRect, imageSourceDstRectOnly);
|
||||
sk_sp<SkImageFilter> imageSourceDstRectOnly(
|
||||
SkImageSource::Make(fImage, bounds, dstRect, kHigh_SkFilterQuality));
|
||||
fill_rect_filtered(canvas, clipRect, std::move(imageSourceDstRectOnly));
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
}
|
||||
}
|
||||
|
@ -60,15 +60,13 @@ protected:
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkRect srcRect = SkRect::MakeLTRB(0, 0,
|
||||
SkIntToScalar(kImageSize), SkIntToScalar(kImageSize));
|
||||
SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> filter(
|
||||
SkImageSource::Create(fImage.get(), srcRect, dstRect, fFilter));
|
||||
const SkRect srcRect = SkRect::MakeLTRB(0, 0,
|
||||
SkIntToScalar(kImageSize),
|
||||
SkIntToScalar(kImageSize));
|
||||
const SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
|
||||
|
||||
SkPaint p;
|
||||
p.setImageFilter(filter);
|
||||
p.setImageFilter(SkImageSource::Make(fImage, srcRect, dstRect, fFilter));
|
||||
|
||||
canvas->saveLayer(nullptr, &p);
|
||||
canvas->restore();
|
||||
|
@ -47,17 +47,17 @@ protected:
|
||||
SkPaint paint;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap;
|
||||
SkIRect cropRect = SkIRect::MakeXYWH(i * 12,
|
||||
i * 8,
|
||||
image->width() - i * 8,
|
||||
image->height() - i * 12);
|
||||
SkImageFilter::CropRect rect(SkRect::Make(cropRect));
|
||||
sk_sp<SkImageFilter> tileInput(SkImageSource::Create(image));
|
||||
sk_sp<SkImageFilter> tileInput(SkImageSource::Make(image));
|
||||
SkScalar dx = SkIntToScalar(i*5);
|
||||
SkScalar dy = SkIntToScalar(i*10);
|
||||
paint.setImageFilter(SkOffsetImageFilter::Make(dx, dy, std::move(tileInput), &rect));
|
||||
DrawClippedImage(canvas, image, paint, 1, cropRect);
|
||||
DrawClippedImage(canvas, image.get(), paint, 1, cropRect);
|
||||
canvas->translate(SkIntToScalar(image->width() + MARGIN), 0);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() {
|
||||
SkString onShortName() override {
|
||||
return SkString("resizeimagefilter");
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ protected:
|
||||
const SkRect& rect,
|
||||
const SkSize& deviceSize,
|
||||
SkFilterQuality filterQuality,
|
||||
SkImageFilter* input = nullptr) {
|
||||
sk_sp<SkImageFilter> input) {
|
||||
SkRect dstRect;
|
||||
canvas->getTotalMatrix().mapRect(&dstRect, rect);
|
||||
canvas->save();
|
||||
@ -38,12 +38,12 @@ protected:
|
||||
canvas->scale(deviceScaleX, deviceScaleY);
|
||||
canvas->translate(-rect.x(), -rect.y());
|
||||
SkMatrix matrix;
|
||||
matrix.setScale(SkScalarInvert(deviceScaleX),
|
||||
SkScalarInvert(deviceScaleY));
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(
|
||||
SkImageFilter::CreateMatrixFilter(matrix, filterQuality, input));
|
||||
matrix.setScale(SkScalarInvert(deviceScaleX), SkScalarInvert(deviceScaleY));
|
||||
sk_sp<SkImageFilter> filter(SkImageFilter::CreateMatrixFilter(matrix,
|
||||
filterQuality,
|
||||
input.get()));
|
||||
SkPaint filteredPaint;
|
||||
filteredPaint.setImageFilter(imageFilter.get());
|
||||
filteredPaint.setImageFilter(std::move(filter));
|
||||
canvas->saveLayer(&rect, &filteredPaint);
|
||||
SkPaint paint;
|
||||
paint.setColor(0xFF00FF00);
|
||||
@ -54,40 +54,44 @@ protected:
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
SkISize onISize() override {
|
||||
return SkISize::Make(520, 100);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
|
||||
SkRect srcRect = SkRect::MakeWH(96, 96);
|
||||
|
||||
SkSize deviceSize = SkSize::Make(16, 16);
|
||||
draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kNone_SkFilterQuality);
|
||||
this->draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kNone_SkFilterQuality,
|
||||
nullptr);
|
||||
|
||||
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
|
||||
draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kLow_SkFilterQuality);
|
||||
this->draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kLow_SkFilterQuality,
|
||||
nullptr);
|
||||
|
||||
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
|
||||
draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kMedium_SkFilterQuality);
|
||||
this->draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kMedium_SkFilterQuality,
|
||||
nullptr);
|
||||
|
||||
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
|
||||
draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kHigh_SkFilterQuality);
|
||||
this->draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kHigh_SkFilterQuality,
|
||||
nullptr);
|
||||
|
||||
auto surface(SkSurface::MakeRasterN32Premul(16, 16));
|
||||
sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(16, 16));
|
||||
SkCanvas* surfaceCanvas = surface->getCanvas();
|
||||
surfaceCanvas->clear(0x000000);
|
||||
{
|
||||
@ -100,14 +104,14 @@ protected:
|
||||
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
||||
SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20);
|
||||
SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120);
|
||||
SkAutoTUnref<SkImageFilter> source(
|
||||
SkImageSource::Create(image.get(), inRect, outRect, kHigh_SkFilterQuality));
|
||||
sk_sp<SkImageFilter> source(
|
||||
SkImageSource::Make(std::move(image), inRect, outRect, kHigh_SkFilterQuality));
|
||||
canvas->translate(srcRect.width() + SkIntToScalar(10), 0);
|
||||
draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kHigh_SkFilterQuality,
|
||||
source.get());
|
||||
this->draw(canvas,
|
||||
srcRect,
|
||||
deviceSize,
|
||||
kHigh_SkFilterQuality,
|
||||
std::move(source));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -116,7 +120,6 @@ private:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static GM* MyFactory(void*) { return new ResizeGM; }
|
||||
static GMRegistry reg(MyFactory);
|
||||
DEF_GM(return new ResizeGM; )
|
||||
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ protected:
|
||||
|
||||
int x = 0, y = 0;
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
SkImage* image = (i & 0x01) ? fCheckerboard.get() : fBitmap.get();
|
||||
sk_sp<SkImage> image = (i & 0x01) ? fCheckerboard : fBitmap;
|
||||
SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(image->width()/4),
|
||||
SkIntToScalar(image->height()/4),
|
||||
SkIntToScalar(image->width()/(i+1)),
|
||||
@ -65,13 +65,12 @@ protected:
|
||||
SkIntToScalar(i * 4),
|
||||
SkIntToScalar(image->width() - i * 12),
|
||||
SkIntToScalar(image->height()) - i * 12);
|
||||
SkAutoTUnref<SkImageFilter> tileInput(SkImageSource::Create(image));
|
||||
SkAutoTUnref<SkImageFilter> filter(
|
||||
SkTileImageFilter::Create(srcRect, dstRect, tileInput));
|
||||
sk_sp<SkImageFilter> tileInput(SkImageSource::Make(image));
|
||||
sk_sp<SkImageFilter> filter(SkTileImageFilter::Create(srcRect, dstRect, tileInput.get()));
|
||||
canvas->save();
|
||||
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(filter);
|
||||
paint.setImageFilter(std::move(filter));
|
||||
canvas->drawImage(fBitmap.get(), 0, 0, &paint);
|
||||
canvas->drawRect(srcRect, red);
|
||||
canvas->drawRect(dstRect, blue);
|
||||
|
@ -85,7 +85,7 @@ protected:
|
||||
};
|
||||
|
||||
int x = 0, y = 0;
|
||||
sk_sp<SkImageFilter> background(SkImageSource::Create(fCheckerboard.get()));
|
||||
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()));
|
||||
@ -98,8 +98,7 @@ 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.get()));
|
||||
DrawClippedBitmap(canvas, fBitmap, paint, x, y);
|
||||
x += fBitmap.width() + MARGIN;
|
||||
if (x + fBitmap.width() > WIDTH) {
|
||||
@ -118,7 +117,7 @@ protected:
|
||||
SkIntToScalar(fBitmap.height() + 4));
|
||||
// Test offsets on SrcMode (uses fixed-function blend)
|
||||
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(fBitmap));
|
||||
sk_sp<SkImageFilter> foreground(SkImageSource::Create(bitmapImage.get()));
|
||||
sk_sp<SkImageFilter> foreground(SkImageSource::Make(std::move(bitmapImage)));
|
||||
sk_sp<SkImageFilter> offsetForeground(SkOffsetImageFilter::Make(SkIntToScalar(4),
|
||||
SkIntToScalar(-4),
|
||||
foreground));
|
||||
|
@ -13,17 +13,43 @@
|
||||
|
||||
class SK_API SkImageSource : public SkImageFilter {
|
||||
public:
|
||||
static SkImageFilter* Create(SkImage*);
|
||||
static SkImageFilter* Create(SkImage*,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality);
|
||||
static sk_sp<SkImageFilter> Make(sk_sp<SkImage> image) {
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_sp<SkImageFilter>(new SkImageSource(std::move(image)));
|
||||
}
|
||||
static sk_sp<SkImageFilter> Make(sk_sp<SkImage> image,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_sp<SkImageFilter>(new SkImageSource(std::move(image),
|
||||
srcRect, dstRect,
|
||||
filterQuality));
|
||||
}
|
||||
|
||||
SkRect computeFastBounds(const SkRect& src) const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageSource)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(SkImage* image) {
|
||||
return Make(sk_ref_sp<SkImage>(image)).release();
|
||||
}
|
||||
static SkImageFilter* Create(SkImage* image,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
return Make(sk_ref_sp<SkImage>(image), srcRect, dstRect, filterQuality).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
@ -31,8 +57,8 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
private:
|
||||
explicit SkImageSource(SkImage*);
|
||||
SkImageSource(SkImage*,
|
||||
explicit SkImageSource(sk_sp<SkImage>);
|
||||
SkImageSource(sk_sp<SkImage>,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality);
|
||||
|
@ -726,12 +726,12 @@ static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
|
||||
case BITMAP: {
|
||||
sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
|
||||
if (R(2) == 1) {
|
||||
filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get(),
|
||||
make_rect(),
|
||||
make_rect(),
|
||||
kHigh_SkFilterQuality));
|
||||
filter = SkImageSource::Make(std::move(image),
|
||||
make_rect(),
|
||||
make_rect(),
|
||||
kHigh_SkFilterQuality);
|
||||
} else {
|
||||
filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get()));
|
||||
filter = SkImageSource::Make(std::move(image));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -15,33 +15,25 @@
|
||||
#include "SkWriteBuffer.h"
|
||||
#include "SkString.h"
|
||||
|
||||
SkImageFilter* SkImageSource::Create(SkImage* image) {
|
||||
return image ? new SkImageSource(image) : nullptr;
|
||||
}
|
||||
|
||||
SkImageFilter* SkImageSource::Create(SkImage* image,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
return image ? new SkImageSource(image, srcRect, dstRect, filterQuality) : nullptr;
|
||||
}
|
||||
|
||||
SkImageSource::SkImageSource(SkImage* image)
|
||||
SkImageSource::SkImageSource(sk_sp<SkImage> image)
|
||||
: INHERITED(0, nullptr)
|
||||
, fImage(SkRef(image))
|
||||
, fSrcRect(SkRect::MakeIWH(image->width(), image->height()))
|
||||
, fImage(std::move(image))
|
||||
, fSrcRect(SkRect::MakeIWH(fImage->width(), fImage->height()))
|
||||
, fDstRect(fSrcRect)
|
||||
, fFilterQuality(kHigh_SkFilterQuality) { }
|
||||
, fFilterQuality(kHigh_SkFilterQuality) {
|
||||
}
|
||||
|
||||
SkImageSource::SkImageSource(SkImage* image,
|
||||
SkImageSource::SkImageSource(sk_sp<SkImage> image,
|
||||
const SkRect& srcRect,
|
||||
const SkRect& dstRect,
|
||||
SkFilterQuality filterQuality)
|
||||
: INHERITED(0, nullptr)
|
||||
, fImage(SkRef(image))
|
||||
, fImage(std::move(image))
|
||||
, fSrcRect(srcRect)
|
||||
, fDstRect(dstRect)
|
||||
, fFilterQuality(filterQuality) { }
|
||||
, fFilterQuality(filterQuality) {
|
||||
}
|
||||
|
||||
SkFlattenable* SkImageSource::CreateProc(SkReadBuffer& buffer) {
|
||||
SkFilterQuality filterQuality = (SkFilterQuality)buffer.readInt();
|
||||
@ -50,12 +42,12 @@ SkFlattenable* SkImageSource::CreateProc(SkReadBuffer& buffer) {
|
||||
buffer.readRect(&src);
|
||||
buffer.readRect(&dst);
|
||||
|
||||
SkAutoTUnref<SkImage> image(buffer.readImage());
|
||||
sk_sp<SkImage> image(buffer.readImage());
|
||||
if (!image) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return SkImageSource::Create(image, src, dst, filterQuality);
|
||||
return SkImageSource::Make(std::move(image), src, dst, filterQuality).release();
|
||||
}
|
||||
|
||||
void SkImageSource::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -29,5 +29,5 @@ SkFlattenable* SkBitmapSourceDeserializer::CreateProc(SkReadBuffer& buffer) {
|
||||
}
|
||||
bitmap.setImmutable();
|
||||
|
||||
return SkImageSource::Create(SkImage::MakeFromBitmap(bitmap).get(), src, dst, filterQuality);
|
||||
return SkImageSource::Make(SkImage::MakeFromBitmap(bitmap), src, dst, filterQuality).release();
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
const SkScalar five = SkIntToScalar(5);
|
||||
|
||||
sk_sp<SkImage> gradientImage(SkImage::MakeFromBitmap(make_gradient_circle(64, 64)));
|
||||
SkAutoTUnref<SkImageFilter> gradientSource(SkImageSource::Create(gradientImage.get()));
|
||||
sk_sp<SkImageFilter> gradientSource(SkImageSource::Make(std::move(gradientImage)));
|
||||
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(five, five, input));
|
||||
SkMatrix matrix;
|
||||
|
||||
@ -430,12 +430,12 @@ DEF_TEST(ImageFilter, reporter) {
|
||||
// 3 ) large negative specular exponent value
|
||||
SkScalar specularExponent = -1000;
|
||||
|
||||
SkAutoTUnref<SkImageFilter> bmSrc(SkImageSource::Create(image.get()));
|
||||
sk_sp<SkImageFilter> bmSrc(SkImageSource::Make(std::move(image)));
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
|
||||
location, target, specularExponent, 180,
|
||||
0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
|
||||
bmSrc))->unref();
|
||||
bmSrc.get()))->unref();
|
||||
SkCanvas canvas(result);
|
||||
SkRect r = SkRect::MakeWH(SkIntToScalar(kBitmapSize),
|
||||
SkIntToScalar(kBitmapSize));
|
||||
@ -829,7 +829,7 @@ static void test_imagefilter_merge_result_size(SkImageFilter::Proxy* proxy,
|
||||
greenBM.allocN32Pixels(20, 20);
|
||||
greenBM.eraseColor(SK_ColorGREEN);
|
||||
sk_sp<SkImage> greenImage(SkImage::MakeFromBitmap(greenBM));
|
||||
sk_sp<SkImageFilter> source(SkImageSource::Create(greenImage.get()));
|
||||
sk_sp<SkImageFilter> source(SkImageSource::Make(std::move(greenImage)));
|
||||
sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(source, source));
|
||||
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 1));
|
||||
@ -1495,10 +1495,10 @@ DEF_TEST(ImageFilterImageSourceSerialization, reporter) {
|
||||
auto surface(SkSurface::MakeRasterN32Premul(10, 10));
|
||||
surface->getCanvas()->clear(SK_ColorGREEN);
|
||||
sk_sp<SkImage> image(surface->makeImageSnapshot());
|
||||
SkAutoTUnref<SkImageFilter> filter(SkImageSource::Create(image.get()));
|
||||
sk_sp<SkImageFilter> filter(SkImageSource::Make(std::move(image)));
|
||||
|
||||
SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
|
||||
SkAutoTUnref<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
|
||||
sk_sp<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
|
||||
sk_sp<SkFlattenable> flattenable(SkValidatingDeserializeFlattenable(
|
||||
data->data(), data->size(), SkImageFilter::GetFlattenableType()));
|
||||
SkImageFilter* unflattenedFilter = static_cast<SkImageFilter*>(flattenable.get());
|
||||
REPORTER_ASSERT(reporter, unflattenedFilter);
|
||||
@ -1539,20 +1539,20 @@ static void test_large_blur_input(skiatest::Reporter* reporter, SkCanvas* canvas
|
||||
return;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkImageFilter> largeSource(SkImageSource::Create(largeImage.get()));
|
||||
sk_sp<SkImageFilter> largeSource(SkImageSource::Make(std::move(largeImage)));
|
||||
if (!largeSource) {
|
||||
ERRORF(reporter, "Failed to create large SkImageSource.");
|
||||
return;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, largeSource));
|
||||
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(10.f, 10.f, largeSource.get()));
|
||||
if (!blur) {
|
||||
ERRORF(reporter, "Failed to create SkBlurImageFilter.");
|
||||
return;
|
||||
}
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blur);
|
||||
paint.setImageFilter(std::move(blur));
|
||||
|
||||
// This should not crash (http://crbug.com/570479).
|
||||
canvas->drawRect(SkRect::MakeIWH(largeW, largeH), paint);
|
||||
|
@ -243,12 +243,12 @@ static void TestBitmapSerialization(const SkBitmap& validBitmap,
|
||||
bool shouldSucceed,
|
||||
skiatest::Reporter* reporter) {
|
||||
sk_sp<SkImage> validImage(SkImage::MakeFromBitmap(validBitmap));
|
||||
SkAutoTUnref<SkImageFilter> validBitmapSource(SkImageSource::Create(validImage.get()));
|
||||
sk_sp<SkImageFilter> validBitmapSource(SkImageSource::Make(std::move(validImage)));
|
||||
sk_sp<SkImage> invalidImage(SkImage::MakeFromBitmap(invalidBitmap));
|
||||
SkAutoTUnref<SkImageFilter> invalidBitmapSource(SkImageSource::Create(invalidImage.get()));
|
||||
sk_sp<SkImageFilter> invalidBitmapSource(SkImageSource::Make(std::move(invalidImage)));
|
||||
sk_sp<SkImageFilter> xfermodeImageFilter(
|
||||
SkXfermodeImageFilter::Make(SkXfermode::Make(SkXfermode::kSrcOver_Mode),
|
||||
invalidBitmapSource, validBitmapSource, nullptr));
|
||||
invalidBitmapSource.get(), validBitmapSource.get(), nullptr));
|
||||
|
||||
SkAutoTUnref<SkImageFilter> deserializedFilter(
|
||||
TestFlattenableSerialization<SkImageFilter>(
|
||||
|
Loading…
Reference in New Issue
Block a user