Switch SkImageSource image filter over to new onFilterImage interface
This CL relies on: https://codereview.chromium.org/1762013002/ (Swap over to using SkImageFilter::filterImage instead of filterImageDeprecated) TBR=bsalomon@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1772933002 Review URL: https://codereview.chromium.org/1772933002
This commit is contained in:
parent
8a21c9fe7f
commit
6ac97b7eb9
@ -28,8 +28,8 @@ public:
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&,
|
||||
SkBitmap* result, SkIPoint* offset) const override;
|
||||
SkSpecialImage* onFilterImage(SkSpecialImage* source, const Context&,
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
private:
|
||||
explicit SkImageSource(const SkImage*);
|
||||
|
@ -138,11 +138,25 @@ public:
|
||||
GrTexture* onPeekTexture() const override { return as_IB(fImage.get())->peekTexture(); }
|
||||
|
||||
bool getBitmapDeprecated(SkBitmap* result) const override {
|
||||
return false;
|
||||
#if SK_SUPPORT_GPU
|
||||
if (GrTexture* texture = as_IB(fImage.get())->peekTexture()) {
|
||||
const SkImageInfo info = GrMakeInfoFromTexture(texture,
|
||||
fImage->width(), fImage->height(),
|
||||
fImage->isOpaque());
|
||||
if (!result->setInfo(info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result->setPixelRef(new SkGrPixelRef(info, texture))->unref();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return as_IB(fImage.get())->asBitmapForImageFilters(result);
|
||||
}
|
||||
|
||||
bool testingOnlyOnGetROPixels(SkBitmap* result) const override {
|
||||
return false;
|
||||
return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
|
||||
}
|
||||
|
||||
SkSpecialSurface* onNewSurface(const SkImageInfo& info) const override {
|
||||
@ -178,9 +192,11 @@ static bool rect_fits(const SkIRect& rect, int width, int height) {
|
||||
}
|
||||
#endif
|
||||
|
||||
SkSpecialImage* SkSpecialImage::NewFromImage(const SkIRect& subset, const SkImage* image) {
|
||||
SkSpecialImage* SkSpecialImage::NewFromImage(SkImageFilter::Proxy* proxy,
|
||||
const SkIRect& subset,
|
||||
const SkImage* image) {
|
||||
SkASSERT(rect_fits(subset, image->width(), image->height()));
|
||||
return new SkSpecialImage_Image(nullptr, subset, image);
|
||||
return new SkSpecialImage_Image(proxy, subset, image);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -52,7 +52,9 @@ public:
|
||||
*/
|
||||
void draw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) const;
|
||||
|
||||
static SkSpecialImage* NewFromImage(const SkIRect& subset, const SkImage*);
|
||||
static SkSpecialImage* NewFromImage(SkImageFilter::Proxy*,
|
||||
const SkIRect& subset,
|
||||
const SkImage*);
|
||||
static SkSpecialImage* NewFromRaster(SkImageFilter::Proxy*,
|
||||
const SkIRect& subset,
|
||||
const SkBitmap&);
|
||||
|
@ -8,9 +8,10 @@
|
||||
#include "SkImageSource.h"
|
||||
|
||||
#include "SkCanvas.h"
|
||||
#include "SkDevice.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkReadBuffer.h"
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkSpecialSurface.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
#include "SkString.h"
|
||||
|
||||
@ -64,27 +65,39 @@ void SkImageSource::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeImage(fImage);
|
||||
}
|
||||
|
||||
bool SkImageSource::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, const Context& ctx,
|
||||
SkBitmap* result, SkIPoint* offset) const {
|
||||
SkSpecialImage* SkImageSource::onFilterImage(SkSpecialImage* source, const Context& ctx,
|
||||
SkIPoint* offset) const {
|
||||
SkRect dstRect;
|
||||
ctx.ctm().mapRect(&dstRect, fDstRect);
|
||||
|
||||
SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
|
||||
if (fSrcRect == bounds && dstRect == bounds) {
|
||||
// No regions cropped out or resized; return entire image.
|
||||
offset->fX = offset->fY = 0;
|
||||
return fImage->asLegacyBitmap(result, SkImage::kRO_LegacyBitmapMode);
|
||||
return SkSpecialImage::NewFromImage(source->internal_getProxy(),
|
||||
SkIRect::MakeWH(fImage->width(), fImage->height()),
|
||||
fImage);
|
||||
}
|
||||
|
||||
const SkIRect dstIRect = dstRect.roundOut();
|
||||
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstIRect.width(), dstIRect.height()));
|
||||
if (nullptr == device.get()) {
|
||||
return false;
|
||||
|
||||
const SkImageInfo info = SkImageInfo::MakeN32(dstIRect.width(), dstIRect.height(),
|
||||
kPremul_SkAlphaType);
|
||||
|
||||
SkAutoTUnref<SkSpecialSurface> surf(source->newSurface(info));
|
||||
if (!surf) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkCanvas canvas(device.get());
|
||||
SkCanvas* canvas = surf->getCanvas();
|
||||
SkASSERT(canvas);
|
||||
|
||||
// TODO: it seems like this clear shouldn't be necessary (see skbug.com/5075)
|
||||
canvas->clear(0x0);
|
||||
|
||||
SkPaint paint;
|
||||
|
||||
// Subtract off the integer component of the translation (will be applied in loc, below).
|
||||
// Subtract off the integer component of the translation (will be applied in offset, below).
|
||||
dstRect.offset(-SkIntToScalar(dstIRect.fLeft), -SkIntToScalar(dstIRect.fTop));
|
||||
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
||||
// FIXME: this probably shouldn't be necessary, but drawImageRect asserts
|
||||
@ -92,13 +105,11 @@ bool SkImageSource::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& src, c
|
||||
paint.setFilterQuality(
|
||||
fSrcRect.width() == dstRect.width() && fSrcRect.height() == dstRect.height() ?
|
||||
kNone_SkFilterQuality : fFilterQuality);
|
||||
canvas.drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
canvas->drawImageRect(fImage, fSrcRect, dstRect, &paint, SkCanvas::kStrict_SrcRectConstraint);
|
||||
|
||||
*result = device.get()->accessBitmap(false);
|
||||
offset->fX = dstIRect.fLeft;
|
||||
offset->fY = dstIRect.fTop;
|
||||
|
||||
return true;
|
||||
return surf->newImageSnapshot();
|
||||
}
|
||||
|
||||
void SkImageSource::computeFastBounds(const SkRect& src, SkRect* dst) const {
|
||||
|
@ -152,11 +152,13 @@ DEF_TEST(ImageFilterCache_RasterBacked, reporter) {
|
||||
static void test_image_backed(skiatest::Reporter* reporter, SkImage* srcImage) {
|
||||
const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromImage(full, srcImage));
|
||||
SkAutoTUnref<SkSpecialImage> fullImg(SkSpecialImage::NewFromImage(nullptr, full, srcImage));
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromImage(subset, srcImage));
|
||||
SkAutoTUnref<SkSpecialImage> subsetImg(SkSpecialImage::NewFromImage(nullptr,
|
||||
subset,
|
||||
srcImage));
|
||||
|
||||
test_find_existing(reporter, fullImg, subsetImg);
|
||||
test_dont_find_if_diff_key(reporter, fullImg, subsetImg);
|
||||
|
@ -108,7 +108,7 @@ DEF_TEST(SpecialImage_Image, reporter) {
|
||||
|
||||
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
|
||||
|
||||
SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromImage(subset, fullImage));
|
||||
SkAutoTUnref<SkSpecialImage> img(SkSpecialImage::NewFromImage(nullptr, subset, fullImage));
|
||||
test_image(img, reporter, true, false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user