Reduce use of SkImage_Base::peekTexture

Change-Id: I079093c9706df4911d47fba04b786e59240e8cb4
Reviewed-on: https://skia-review.googlesource.com/7792
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2017-01-31 11:31:39 -05:00 committed by Skia Commit-Bot
parent 6d3b7aaf79
commit 6de99041f1
9 changed files with 50 additions and 33 deletions

View File

@ -226,7 +226,7 @@ public:
surface->getCanvas()->translate(-100, -100);
surface->getCanvas()->drawPicture(pic);
sk_sp<SkImage> image(surface->makeImageSnapshot());
fProxy = GrSurfaceProxy::MakeWrapped(sk_ref_sp(as_IB(image)->peekTexture()));
fProxy = as_IB(image)->asTextureProxyRef();
}
}
protected:

View File

@ -23,6 +23,7 @@
#include "GrTextureProxy.h"
#include "SkGr.h"
#include "SkGrPriv.h"
#include "SkImage_Gpu.h"
#endif
// Currently the raster imagefilters can only handle certain imageinfos. Call this to know if
@ -186,8 +187,10 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromImage(const SkIRect& subset,
SkASSERT(rect_fits(subset, image->width(), image->height()));
#if SK_SUPPORT_GPU
if (GrTexture* texture = as_IB(image)->peekTexture()) {
return MakeFromGpu(subset, image->uniqueID(), sk_ref_sp(texture),
if (sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef()) {
GrContext* context = ((SkImage_Gpu*) as_IB(image))->context();
return MakeDeferredFromGpu(context, subset, image->uniqueID(), std::move(proxy),
sk_ref_sp(as_IB(image)->onImageInfo().colorSpace()), props);
} else
#endif
@ -345,7 +348,6 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromRaster(const SkIRect& subset,
#if SK_SUPPORT_GPU
///////////////////////////////////////////////////////////////////////////////
#include "GrTexture.h"
#include "SkImage_Gpu.h"
static sk_sp<SkImage> wrap_proxy_in_image(GrContext* context, GrSurfaceProxy* proxy,
SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace) {

View File

@ -820,7 +820,7 @@ bool SkGpuDevice::shouldTileImage(const SkImage* image, const SkRect* srcRectPtr
const SkMatrix& srcToDstRect) const {
ASSERT_SINGLE_OWNER
// if image is explictly texture backed then just use the texture
if (as_IB(image)->peekTexture()) {
if (image->isTextureBacked()) {
return false;
}
@ -1314,11 +1314,12 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
SkPixmap pm;
if (image->isTextureBacked()) {
GrTexture* texture = as_IB(image)->peekTexture();
sk_sp<GrTextureProxy> proxy = as_IB(image)->asTextureProxyRef();
return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(image->width(), image->height()),
return SkSpecialImage::MakeDeferredFromGpu(fContext.get(),
SkIRect::MakeWH(image->width(), image->height()),
image->uniqueID(),
sk_ref_sp(texture),
std::move(proxy),
as_IB(image)->onImageInfo().refColorSpace(),
&this->surfaceProps());
} else if (image->peekPixels(&pm)) {

View File

@ -14,6 +14,7 @@
#if SK_SUPPORT_GPU
#include "GrTexture.h"
#include "GrTextureProxy.h"
#endif
#include <new>
@ -45,6 +46,7 @@ public:
virtual GrTexture* peekTexture() const { return nullptr; }
#if SK_SUPPORT_GPU
virtual sk_sp<GrTextureProxy> asTextureProxyRef() const { return nullptr; }
virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return nullptr; }
#endif
virtual SkImageCacherator* peekCacherator() const { return nullptr; }

View File

@ -93,8 +93,13 @@ bool SkImage_Gpu::getROPixels(SkBitmap* dst, SkColorSpace* dstColorSpace,
return true;
}
sk_sp<GrSurfaceProxy> SkImage_Gpu::refProxy() const {
return GrSurfaceProxy::MakeWrapped(fTexture);
sk_sp<GrTextureProxy> SkImage_Gpu::asTextureProxyRef() const {
sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(fTexture);
if (!sProxy) {
return nullptr;
}
return sk_ref_sp(sProxy->asTextureProxy());
}
GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& params,
@ -104,7 +109,7 @@ GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrSamplerParams& para
if (texColorSpace) {
*texColorSpace = this->fColorSpace;
}
GrTextureAdjuster adjuster(this->peekTexture(), this->alphaType(), this->bounds(),
GrTextureAdjuster adjuster(fTexture.get(), this->alphaType(), this->bounds(),
this->uniqueID(), this->fColorSpace.get());
return adjuster.refTextureSafeForParams(params, nullptr, scaleAdjust);
}

View File

@ -43,8 +43,8 @@ public:
sk_sp<SkColorSpace>*, SkScalar scaleAdjust[2]) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
sk_sp<GrSurfaceProxy> refProxy() const;
GrTexture* peekTexture() const override { return fTexture.get(); }
sk_sp<GrTextureProxy> asTextureProxyRef() const override;
sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override {
*uniqueID = this->uniqueID();
return fTexture;

View File

@ -138,8 +138,11 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
// image because onCopyOnWrite is only called when there is a cached image.
sk_sp<SkImage> image(this->refCachedImage(SkBudgeted::kNo));
SkASSERT(image);
if (rt->asTexture() == as_IB(image)->peekTexture()) {
this->fDevice->replaceRenderTargetContext(SkSurface::kRetain_ContentChangeMode == mode);
// MDB TODO: this is unfortunate. The snapping of an Image_Gpu from a surface currently
// funnels down to a GrTexture. Once Image_Gpus are proxy-backed we should be able to
// compare proxy uniqueIDs.
if (rt->asTexture()->getTextureHandle() == image->getTextureHandle(false)) {
fDevice->replaceRenderTargetContext(SkSurface::kRetain_ContentChangeMode == mode);
SkTextureImageApplyBudgetedDecision(image.get());
} else if (kDiscard_ContentChangeMode == mode) {
this->SkSurface_Gpu::onDiscard();

View File

@ -51,7 +51,7 @@ static SkBitmap create_bm() {
// Basic test of the SkSpecialImage public API (e.g., peekTexture, peekPixels & draw)
static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* reporter,
GrContext* context, bool peekTextureSucceeds,
GrContext* context, bool isGPUBacked,
int offset, int size) {
const SkIRect subset = img->subset();
REPORTER_ASSERT(reporter, offset == subset.left());
@ -61,7 +61,7 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
//--------------
// Test that peekTexture reports the correct backing type
REPORTER_ASSERT(reporter, peekTextureSucceeds == img->isTextureBacked());
REPORTER_ASSERT(reporter, isGPUBacked == img->isTextureBacked());
#if SK_SUPPORT_GPU
//--------------
@ -118,9 +118,9 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
REPORTER_ASSERT(reporter, tightImg->width() == subset.width());
REPORTER_ASSERT(reporter, tightImg->height() == subset.height());
REPORTER_ASSERT(reporter, peekTextureSucceeds == !!tightImg->getTexture());
REPORTER_ASSERT(reporter, isGPUBacked == !!tightImg->isTextureBacked());
SkPixmap tmpPixmap;
REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightImg->peekPixels(&tmpPixmap));
REPORTER_ASSERT(reporter, isGPUBacked != !!tightImg->peekPixels(&tmpPixmap));
}
{
SkImageFilter::OutputProperties outProps(img->getColorSpace());
@ -128,10 +128,10 @@ static void test_image(const sk_sp<SkSpecialImage>& img, skiatest::Reporter* rep
REPORTER_ASSERT(reporter, tightSurf->width() == subset.width());
REPORTER_ASSERT(reporter, tightSurf->height() == subset.height());
REPORTER_ASSERT(reporter, peekTextureSucceeds ==
REPORTER_ASSERT(reporter, isGPUBacked ==
!!tightSurf->getTextureHandle(SkSurface::kDiscardWrite_BackendHandleAccess));
SkPixmap tmpPixmap;
REPORTER_ASSERT(reporter, peekTextureSucceeds != !!tightSurf->peekPixels(&tmpPixmap));
REPORTER_ASSERT(reporter, isGPUBacked != !!tightSurf->peekPixels(&tmpPixmap));
}
}

View File

@ -415,20 +415,22 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) {
DEF_TEST(SurfaceGetTexture, reporter) {
auto surface(create_surface());
sk_sp<SkImage> image(surface->makeImageSnapshot());
REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr);
REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr);
REPORTER_ASSERT(reporter, !as_IB(image)->isTextureBacked());
}
#if SK_SUPPORT_GPU
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) {
auto surface(surface_func(ctxInfo.grContext(), kPremul_SkAlphaType, nullptr));
sk_sp<SkImage> image(surface->makeImageSnapshot());
GrTexture* texture = as_IB(image)->peekTexture();
REPORTER_ASSERT(reporter, texture);
REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
GrBackendObject textureHandle = image->getTextureHandle(false);
REPORTER_ASSERT(reporter, 0 != textureHandle);
surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == texture);
REPORTER_ASSERT(reporter, as_IB(image)->isTextureBacked());
REPORTER_ASSERT(reporter, textureHandle == image->getTextureHandle(false));
}
}
#endif
@ -441,8 +443,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) {
static SkBudgeted is_budgeted(const sk_sp<SkSurface>& surf) {
SkSurface_Gpu* gsurf = (SkSurface_Gpu*)surf.get();
return gsurf->getDevice()->accessRenderTargetContext()
->accessRenderTarget()->resourcePriv().isBudgeted();
GrRenderTargetProxy* proxy = gsurf->getDevice()->accessRenderTargetContext()
->asRenderTargetProxy();
return proxy->isBudgeted();
}
static SkBudgeted is_budgeted(SkImage* image) {
@ -676,7 +680,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) {
[] (SkSurface* s){
sk_sp<SkImage> i(s->makeImageSnapshot());
SkImage_Gpu* gpuImage = (SkImage_Gpu *) as_IB(i);
sk_sp<GrSurfaceProxy> proxy = gpuImage->refProxy();
sk_sp<GrTextureProxy> proxy = gpuImage->asTextureProxyRef();
GrContext* context = gpuImage->context();
return context->contextPriv().makeWrappedSurfaceContext(std::move(proxy),
gpuImage->refColorSpace());