Replace SkSpecialImage::makeTightSubset with asImage (take 2)
This is a reland of https://skia-review.googlesource.com/c/8498/ (Replace SkSpecialImage::makeTightSubset with asImage) It must wait on https://codereview.chromium.org/2702703002/ (Add suppressions for upcoming Skia DEPS roll) due to minor layout test changes This should allow the relanding of: https://skia-review.googlesource.com/c/8450/ (Remove asTextureRef from SkSpecialImage & update effects accordingly (take 2)) Change-Id: I7086a419869dbeb62d9b9e9714c796d54e75ee49 Reviewed-on: https://skia-review.googlesource.com/8701 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
bae888e652
commit
a5fdc974a9
@ -18,6 +18,7 @@
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#include "GrSurfaceContext.h"
|
||||
#include "GrSurfaceProxyPriv.h"
|
||||
#include "GrTexture.h"
|
||||
#include "GrSamplerParams.h"
|
||||
#include "GrTextureProxy.h"
|
||||
@ -59,7 +60,7 @@ public:
|
||||
virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
|
||||
const SkISize& size, SkAlphaType at) const = 0;
|
||||
|
||||
virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0;
|
||||
virtual sk_sp<SkImage> onAsImage(const SkIRect* subset) const = 0;
|
||||
|
||||
virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
|
||||
const SkISize& size, SkAlphaType at) const = 0;
|
||||
@ -170,10 +171,11 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
|
||||
return as_SIB(this)->onMakeSubset(subset);
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const {
|
||||
return as_SIB(this)->onMakeTightSubset(subset);
|
||||
sk_sp<SkImage> SkSpecialImage::asImage(const SkIRect* subset) const {
|
||||
return as_SIB(this)->onAsImage(subset);
|
||||
}
|
||||
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
static bool rect_fits(const SkIRect& rect, int width, int height) {
|
||||
if (0 == width && 0 == height) {
|
||||
@ -299,14 +301,18 @@ public:
|
||||
&this->props());
|
||||
}
|
||||
|
||||
sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override {
|
||||
SkBitmap subsetBM;
|
||||
sk_sp<SkImage> onAsImage(const SkIRect* subset) const override {
|
||||
if (subset) {
|
||||
SkBitmap subsetBM;
|
||||
|
||||
if (!fBitmap.extractSubset(&subsetBM, subset)) {
|
||||
return nullptr;
|
||||
if (!fBitmap.extractSubset(&subsetBM, *subset)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return SkImage::MakeFromBitmap(subsetBM);
|
||||
}
|
||||
|
||||
return SkImage::MakeFromBitmap(subsetBM);
|
||||
return SkImage::MakeFromBitmap(fBitmap);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
|
||||
@ -362,7 +368,9 @@ static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrTextureProxy* pr
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sk_make_sp<SkImage_Gpu>(proxy->width(), proxy->height(),
|
||||
// Note that we're explicitly using the GrTexture's width & height here b.c. SkImages
|
||||
// must be tight.
|
||||
return sk_make_sp<SkImage_Gpu>(tex->width(), tex->height(),
|
||||
kNeedNewImageUniqueID, alphaType,
|
||||
sk_ref_sp(tex),
|
||||
std::move(colorSpace), SkBudgeted::kYes);
|
||||
@ -497,20 +505,25 @@ public:
|
||||
}
|
||||
|
||||
// TODO: move all the logic here into the subset-flavor GrSurfaceProxy::copy?
|
||||
sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override {
|
||||
// TODO: this is problematic since the surfaceProxy could be loose
|
||||
if (0 == subset.fLeft && 0 == subset.fTop &&
|
||||
fTextureProxy->width() == subset.width() &&
|
||||
fTextureProxy->height() == subset.height()) {
|
||||
// The existing GrTexture is already tight so reuse it in the SkImage
|
||||
return wrap_proxy_in_image(fContext, fTextureProxy.get(),
|
||||
fAlphaType, fColorSpace);
|
||||
sk_sp<SkImage> onAsImage(const SkIRect* subset) const override {
|
||||
if (subset) {
|
||||
// TODO: if this becomes a bottle neck we could base this logic on what the size
|
||||
// will be when it is finally instantiated - but that is more fraught.
|
||||
if (//fSurfaceProxy->priv().isExact() &&
|
||||
0 == subset->fLeft && 0 == subset->fTop &&
|
||||
fTextureProxy->width() == subset->width() &&
|
||||
fTextureProxy->height() == subset->height()) {
|
||||
// The existing GrTexture is already tight so reuse it in the SkImage
|
||||
return wrap_proxy_in_image(fContext, fTextureProxy.get(), fAlphaType, fColorSpace);
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> subsetProxy(GrSurfaceProxy::Copy(fContext, fTextureProxy.get(),
|
||||
*subset, SkBudgeted::kYes));
|
||||
|
||||
return wrap_proxy_in_image(fContext, subsetProxy.get(), fAlphaType, fColorSpace);
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> subsetProxy(GrSurfaceProxy::Copy(fContext, fTextureProxy.get(),
|
||||
subset, SkBudgeted::kYes));
|
||||
|
||||
return wrap_proxy_in_image(fContext, subsetProxy.get(), fAlphaType, fColorSpace);
|
||||
return wrap_proxy_in_image(fContext, fTextureProxy.get(), fAlphaType, fColorSpace);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
|
||||
|
@ -117,11 +117,14 @@ public:
|
||||
sk_sp<SkSpecialImage> makeSubset(const SkIRect& subset) const;
|
||||
|
||||
/**
|
||||
* Extract a subset of this special image and return it as an SkImage.
|
||||
* Create an SkImage from the contents of this special image optionally extracting a subset.
|
||||
* It may or may not point to the same backing memory.
|
||||
* TODO: switch this to makeSurface once we resolved the naming issue
|
||||
* Note: when no 'subset' parameter is specified the the entire SkSpecialImage will be
|
||||
* returned - including whatever extra padding may have resulted from a loose fit!
|
||||
* When the 'subset' parameter is specified the returned image will be tight even if that
|
||||
* entails a copy!
|
||||
*/
|
||||
sk_sp<SkImage> makeTightSubset(const SkIRect& subset) const;
|
||||
sk_sp<SkImage> asImage(const SkIRect* subset = nullptr) const;
|
||||
|
||||
// TODO: hide this when GrLayerHoister uses SkSpecialImages more fully (see skbug.com/5063)
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ sk_sp<SkSpecialImage> SkTileImageFilter::onFilterImage(SkSpecialImage* source,
|
||||
// We create an SkImage here b.c. it needs to be a tight fit for the tiling
|
||||
sk_sp<SkImage> subset;
|
||||
if (inputBounds.contains(srcIRect)) {
|
||||
subset = input->makeTightSubset(srcIRect);
|
||||
subset = input->asImage(&srcIRect);
|
||||
if (!subset) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -266,6 +266,7 @@ sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize&
|
||||
matrix, paint, bitDepth,
|
||||
std::move(colorSpace)));
|
||||
}
|
||||
|
||||
sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRect& subset,
|
||||
const SkIRect& clipBounds, SkIRect* outSubset,
|
||||
SkIPoint* offset) const {
|
||||
@ -284,32 +285,21 @@ sk_sp<SkImage> SkImage::makeWithFilter(const SkImageFilter* filter, const SkIRec
|
||||
SkImageFilter::OutputProperties outputProperties(colorSpace);
|
||||
SkImageFilter::Context context(SkMatrix::I(), clipBounds, cache.get(), outputProperties);
|
||||
|
||||
sk_sp<SkSpecialImage> result =
|
||||
filter->filterImage(srcSpecialImage.get(), context, offset);
|
||||
|
||||
sk_sp<SkSpecialImage> result = filter->filterImage(srcSpecialImage.get(), context, offset);
|
||||
if (!result) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkIRect fullSize = SkIRect::MakeWH(result->width(), result->height());
|
||||
#if SK_SUPPORT_GPU
|
||||
if (result->isTextureBacked()) {
|
||||
GrContext* context = result->getContext();
|
||||
sk_sp<GrTexture> texture = result->asTextureRef(context);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
}
|
||||
fullSize = SkIRect::MakeWH(texture->width(), texture->height());
|
||||
}
|
||||
#endif
|
||||
*outSubset = SkIRect::MakeWH(result->width(), result->height());
|
||||
if (!outSubset->intersect(clipBounds.makeOffset(-offset->x(), -offset->y()))) {
|
||||
return nullptr;
|
||||
}
|
||||
offset->fX += outSubset->x();
|
||||
offset->fY += outSubset->y();
|
||||
// This isn't really a "tight" subset, but includes any texture padding.
|
||||
return result->makeTightSubset(fullSize);
|
||||
|
||||
// Note that here we're returning the special image's entire backing store, loose padding
|
||||
// and all!
|
||||
return result->asImage();
|
||||
}
|
||||
|
||||
bool SkImage::isLazyGenerated() const {
|
||||
|
@ -1750,7 +1750,7 @@ DEF_TEST(ImageFilterBlurLargeImage, reporter) {
|
||||
}
|
||||
|
||||
static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* context) {
|
||||
sk_sp<SkSurface> surface(create_surface(context, 100, 100));
|
||||
sk_sp<SkSurface> surface(create_surface(context, 192, 128));
|
||||
surface->getCanvas()->clear(SK_ColorRED);
|
||||
SkPaint bluePaint;
|
||||
bluePaint.setColor(SK_ColorBLUE);
|
||||
@ -1795,6 +1795,17 @@ static void test_make_with_filter(skiatest::Reporter* reporter, GrContext* conte
|
||||
SkIRect destRect = SkIRect::MakeXYWH(offset.x(), offset.y(),
|
||||
outSubset.width(), outSubset.height());
|
||||
REPORTER_ASSERT(reporter, clipBounds.contains(destRect));
|
||||
|
||||
// In GPU-mode, this case creates a special image with a backing size that differs from
|
||||
// the content size
|
||||
{
|
||||
clipBounds.setXYWH(0, 0, 170, 100);
|
||||
subset.setXYWH(0, 0, 160, 90);
|
||||
|
||||
filter = SkXfermodeImageFilter::Make(SkBlendMode::kSrc, nullptr);
|
||||
result = sourceImage->makeWithFilter(filter.get(), subset, clipBounds, &outSubset, &offset);
|
||||
REPORTER_ASSERT(reporter, result);
|
||||
}
|
||||
}
|
||||
|
||||
DEF_TEST(ImageFilterMakeWithFilter, reporter) {
|
||||
|
@ -110,11 +110,11 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
|
||||
kSmallerSize+kPad));
|
||||
|
||||
//--------------
|
||||
// Test that makeTightSubset & makeTightSurface return appropriately sized objects
|
||||
// Test that asImage & makeTightSurface return appropriately sized objects
|
||||
// of the correct backing type
|
||||
SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height());
|
||||
{
|
||||
sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset));
|
||||
sk_sp<SkImage> tightImg(img->asImage(&newSubset));
|
||||
|
||||
REPORTER_ASSERT(reporter, tightImg->width() == subset.width());
|
||||
REPORTER_ASSERT(reporter, tightImg->height() == subset.height());
|
||||
|
Loading…
Reference in New Issue
Block a user