Revert "Replace SkSpecialImage::makeTightSubset with asImage"

This reverts commit 5df6db15dc.

Reason for revert: Possibly blocking Chrome DEPS roll

Original change's description:
> Replace SkSpecialImage::makeTightSubset with asImage
> 
> This should allow the relanding of:
> 
> https://skia-review.googlesource.com/c/8450/ (Remove asTextureRef from SkSpecialImage & update effects accordingly (take 2))
> 
> Change-Id: I517af11036e3f44a280bbe6b9275f6c38f4a86a4
> Reviewed-on: https://skia-review.googlesource.com/8498
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> 

TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Ib5bebda78b2323e65a73504a61af918872ad231f
Reviewed-on: https://skia-review.googlesource.com/8607
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-02-17 13:28:47 +00:00 committed by Skia Commit-Bot
parent 2028625f9b
commit e14349a754
6 changed files with 44 additions and 61 deletions

View File

@ -18,7 +18,6 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrSurfaceContext.h"
#include "GrSurfaceProxyPriv.h"
#include "GrTexture.h"
#include "GrSamplerParams.h"
#include "GrTextureProxy.h"
@ -60,7 +59,7 @@ public:
virtual sk_sp<SkSpecialSurface> onMakeSurface(const SkImageFilter::OutputProperties& outProps,
const SkISize& size, SkAlphaType at) const = 0;
virtual sk_sp<SkImage> onAsImage(const SkIRect* subset) const = 0;
virtual sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const = 0;
virtual sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
const SkISize& size, SkAlphaType at) const = 0;
@ -171,11 +170,10 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeSubset(const SkIRect& subset) const {
return as_SIB(this)->onMakeSubset(subset);
}
sk_sp<SkImage> SkSpecialImage::asImage(const SkIRect* subset) const {
return as_SIB(this)->onAsImage(subset);
sk_sp<SkImage> SkSpecialImage::makeTightSubset(const SkIRect& subset) const {
return as_SIB(this)->onMakeTightSubset(subset);
}
#ifdef SK_DEBUG
static bool rect_fits(const SkIRect& rect, int width, int height) {
if (0 == width && 0 == height) {
@ -303,18 +301,14 @@ public:
&this->props());
}
sk_sp<SkImage> onAsImage(const SkIRect* subset) const override {
if (subset) {
SkBitmap subsetBM;
sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override {
SkBitmap subsetBM;
if (!fBitmap.extractSubset(&subsetBM, *subset)) {
return nullptr;
}
return SkImage::MakeFromBitmap(subsetBM);
if (!fBitmap.extractSubset(&subsetBM, subset)) {
return nullptr;
}
return SkImage::MakeFromBitmap(fBitmap);
return SkImage::MakeFromBitmap(subsetBM);
}
sk_sp<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,
@ -370,9 +364,7 @@ static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrTextureProxy* pr
return nullptr;
}
// 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(),
return sk_make_sp<SkImage_Gpu>(proxy->width(), proxy->height(),
kNeedNewImageUniqueID, alphaType,
sk_ref_sp(tex),
std::move(colorSpace), SkBudgeted::kYes);
@ -507,25 +499,20 @@ public:
}
// TODO: move all the logic here into the subset-flavor GrSurfaceProxy::copy?
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<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);
}
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<SkSurface> onMakeTightSurface(const SkImageFilter::OutputProperties& outProps,

View File

@ -117,14 +117,11 @@ public:
sk_sp<SkSpecialImage> makeSubset(const SkIRect& subset) const;
/**
* Create an SkImage from the contents of this special image optionally extracting a subset.
* Extract a subset of this special image and return it as an SkImage.
* It may or may not point to the same backing memory.
* 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!
* TODO: switch this to makeSurface once we resolved the naming issue
*/
sk_sp<SkImage> asImage(const SkIRect* subset = nullptr) const;
sk_sp<SkImage> makeTightSubset(const SkIRect& subset) const;
// TODO: hide this when GrLayerHoister uses SkSpecialImages more fully (see skbug.com/5063)
/**

View File

@ -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->asImage(&srcIRect);
subset = input->makeTightSubset(srcIRect);
if (!subset) {
return nullptr;
}

View File

@ -266,7 +266,6 @@ 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 {
@ -285,21 +284,32 @@ 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();
// Note that here we're returning the special image's entire backing store, loose padding
// and all!
return result->asImage();
// This isn't really a "tight" subset, but includes any texture padding.
return result->makeTightSubset(fullSize);
}
bool SkImage::isLazyGenerated() const {

View File

@ -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, 192, 128));
sk_sp<SkSurface> surface(create_surface(context, 100, 100));
surface->getCanvas()->clear(SK_ColorRED);
SkPaint bluePaint;
bluePaint.setColor(SK_ColorBLUE);
@ -1795,17 +1795,6 @@ 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) {

View File

@ -110,11 +110,11 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
kSmallerSize+kPad));
//--------------
// Test that asImage & makeTightSurface return appropriately sized objects
// Test that makeTightSubset & makeTightSurface return appropriately sized objects
// of the correct backing type
SkIRect newSubset = SkIRect::MakeWH(subset.width(), subset.height());
{
sk_sp<SkImage> tightImg(img->asImage(&newSubset));
sk_sp<SkImage> tightImg(img->makeTightSubset(newSubset));
REPORTER_ASSERT(reporter, tightImg->width() == subset.width());
REPORTER_ASSERT(reporter, tightImg->height() == subset.height());