diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp index f18e6a7c7c..420b3f1e23 100644 --- a/src/core/SkSpecialImage.cpp +++ b/src/core/SkSpecialImage.cpp @@ -252,10 +252,12 @@ public: #if SK_SUPPORT_GPU GrTexture* texture = as_IB(fImage.get())->peekTexture(); if (texture) { - GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *texture->getContext()->caps()); - desc.fFlags = kRenderTarget_GrSurfaceFlag; + GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *texture->getContext()->caps()); - return SkSpecialSurface::MakeRenderTarget(texture->getContext(), desc); + return SkSpecialSurface::MakeRenderTarget(texture->getContext(), + info.width(), + info.height(), + config); } #endif return SkSpecialSurface::MakeRaster(info, nullptr); @@ -528,10 +530,11 @@ public: return nullptr; } - GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(info, *fTexture->getContext()->caps()); - desc.fFlags = kRenderTarget_GrSurfaceFlag; + GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps()); - return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), desc); + return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(), + info.width(), info.height(), + config); } sk_sp onMakeSubset(const SkIRect& subset) const override { diff --git a/src/core/SkSpecialSurface.cpp b/src/core/SkSpecialSurface.cpp index 2973aa1f9b..eeefb2afa8 100644 --- a/src/core/SkSpecialSurface.cpp +++ b/src/core/SkSpecialSurface.cpp @@ -113,6 +113,7 @@ sk_sp SkSpecialSurface::MakeRaster(const SkImageInfo& info, class SkSpecialSurface_Gpu : public SkSpecialSurface_Base { public: SkSpecialSurface_Gpu(sk_sp texture, + int width, int height, const SkIRect& subset, const SkSurfaceProps* props) : INHERITED(subset, props) @@ -120,13 +121,14 @@ public: SkASSERT(fTexture->asRenderTarget()); - SkAutoTUnref device(SkGpuDevice::Create(fTexture->asRenderTarget(), props, - SkGpuDevice::kUninit_InitContents)); + sk_sp device(SkGpuDevice::Create(fTexture->asRenderTarget(), width, height, + props, + SkGpuDevice::kUninit_InitContents)); if (!device) { return; } - fCanvas.reset(new SkCanvas(device)); + fCanvas.reset(new SkCanvas(device.get())); fCanvas->clipRect(SkRect::Make(subset)); } @@ -146,31 +148,27 @@ private: typedef SkSpecialSurface_Base INHERITED; }; -sk_sp SkSpecialSurface::MakeFromTexture(const SkIRect& subset, - sk_sp texture, - const SkSurfaceProps* props) { - if (!texture->asRenderTarget()) { - return nullptr; - } - - return sk_make_sp(std::move(texture), subset, props); -} - sk_sp SkSpecialSurface::MakeRenderTarget(GrContext* context, - const GrSurfaceDesc& desc, - const SkSurfaceProps* props) { - if (!context || !SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) { + int width, int height, + GrPixelConfig config) { + if (!context) { return nullptr; } - sk_sp temp(context->textureProvider()->createApproxTexture(desc)); - if (!temp) { + GrSurfaceDesc desc; + desc.fFlags = kRenderTarget_GrSurfaceFlag; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; + + sk_sp tex(context->textureProvider()->createApproxTexture(desc)); + if (!tex) { return nullptr; } - const SkIRect subset = SkIRect::MakeWH(desc.fWidth, desc.fHeight); + const SkIRect subset = SkIRect::MakeWH(width, height); - return sk_make_sp(std::move(temp), subset, props); + return sk_make_sp(std::move(tex), width, height, subset, nullptr); } #endif diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h index 2135347e35..d971648202 100644 --- a/src/core/SkSpecialSurface.h +++ b/src/core/SkSpecialSurface.h @@ -51,18 +51,13 @@ public: sk_sp makeImageSnapshot(); #if SK_SUPPORT_GPU - /** - * Use an existing (renderTarget-capable) GrTexture as the backing store. - */ - static sk_sp MakeFromTexture(const SkIRect& subset, sk_sp, - const SkSurfaceProps* = nullptr); - /** * Allocate a new GPU-backed SkSpecialSurface. If the requested surface cannot * be created, nullptr will be returned. */ - static sk_sp MakeRenderTarget(GrContext*, const GrSurfaceDesc&, - const SkSurfaceProps* = nullptr); + static sk_sp MakeRenderTarget(GrContext*, + int width, int height, + GrPixelConfig config); #endif /** diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 54e9a60007..56b3aaf5cd 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -370,12 +370,9 @@ static sk_sp make_blue(sk_sp input, static sk_sp create_empty_special_surface(GrContext* context, int widthHeight) { #if SK_SUPPORT_GPU if (context) { - GrSurfaceDesc desc; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = widthHeight; - desc.fHeight = widthHeight; - return SkSpecialSurface::MakeRenderTarget(context, desc); + return SkSpecialSurface::MakeRenderTarget(context, + widthHeight, widthHeight, + kSkia8888_GrPixelConfig); } else #endif { diff --git a/tests/SpecialSurfaceTest.cpp b/tests/SpecialSurfaceTest.cpp index 8c560fef79..3c351a527c 100644 --- a/tests/SpecialSurfaceTest.cpp +++ b/tests/SpecialSurfaceTest.cpp @@ -79,35 +79,11 @@ DEF_TEST(SpecialSurface_Raster2, reporter) { #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) { - GrSurfaceDesc desc; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = kSmallerSize; - desc.fHeight = kSmallerSize; - - sk_sp surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.fGrContext, desc)); + sk_sp surf(SkSpecialSurface::MakeRenderTarget(ctxInfo.fGrContext, + kSmallerSize, kSmallerSize, + kSkia8888_GrPixelConfig)); test_surface(surf, reporter, 0); } -// test the more flexible factory -DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, ctxInfo) { - GrSurfaceDesc desc; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = kFullSize; - desc.fHeight = kFullSize; - - sk_sp temp(ctxInfo.fGrContext->textureProvider()->createApproxTexture(desc)); - SkASSERT_RELEASE(temp); - - const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); - - sk_sp surf(SkSpecialSurface::MakeFromTexture(subset, std::move(temp))); - - test_surface(surf, reporter, kPad); - - // TODO: check that the clear didn't escape the active region -} - #endif