From 49edccd775a38d93701ae376df28463d7848fd16 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 23 Mar 2018 15:31:32 -0400 Subject: Remove legacy SkSurface::MakeFromBackendRenderTarget that does not take SkColorType Bug: skia:6718 Change-Id: Iefec5be49bf7450426c5ddb668f5525876f8ec2d Reviewed-on: https://skia-review.googlesource.com/116194 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- dm/DMSrcSink.cpp | 6 ++-- docs/SkSurface_Reference.bmh | 82 ++++++++------------------------------------ include/core/SkSurface.h | 26 -------------- src/image/SkSurface.cpp | 8 ----- src/image/SkSurface_Gpu.cpp | 55 +++++++++++++---------------- 5 files changed, 40 insertions(+), 137 deletions(-) diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 2d8d949e7b..1d8aab1fc1 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1855,9 +1855,9 @@ Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log, auto colorType = SkColorTypeToGrColorType(info.colorType()); backendRT = context->contextPriv().getGpu()->createTestingOnlyBackendRenderTarget( info.width(), info.height(), colorType, srgbEncoded); - surface = SkSurface::MakeFromBackendRenderTarget(context, backendRT, - kBottomLeft_GrSurfaceOrigin, - info.refColorSpace(), &props); + surface = SkSurface::MakeFromBackendRenderTarget( + context, backendRT, kBottomLeft_GrSurfaceOrigin, info.colorType(), + info.refColorSpace(), &props); } break; } diff --git a/docs/SkSurface_Reference.bmh b/docs/SkSurface_Reference.bmh index c579ec49af..a7053f69d3 100644 --- a/docs/SkSurface_Reference.bmh +++ b/docs/SkSurface_Reference.bmh @@ -406,60 +406,6 @@ If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. # ------------------------------------------------------------------------------ -#Method static sk_sp MakeFromBackendRenderTarget(GrContext* context, - const GrBackendRenderTarget& backendRenderTarget, - GrSurfaceOrigin origin, - sk_sp colorSpace, - const SkSurfaceProps* surfaceProps) -#In Constructor -#Line # creates Surface from GPU memory buffer ## - -Wraps a GPU-backed buffer into Surface. Caller must ensure render target is -valid for the lifetime of returned Surface. - -Surface is returned if all parameters are valid. backendRenderTarget is valid if -its pixel configuration agrees with colorSpace and context; for instance, if -backendRenderTarget has an sRGB configuration, then context must support sRGB, -and colorSpace must be present. Further, backendRenderTarget width and height must -not exceed context capabilities, and the context must be able to support -back-end render targets. - -If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. - -#Param context GPU_Context ## -#Param backendRenderTarget GPU intermediate memory buffer ## -#Param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin ## -#Param colorSpace range of colors ## -#Param surfaceProps LCD striping orientation and setting for device independent - fonts; may be nullptr -## - -#Return Surface if all parameters are valid; otherwise, nullptr ## - -#Example -#ToDo remove !fiddle below once backEndTextureRenderTarget is available ## -#Platform !fiddle gpu - SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); - if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); - return; - } - sk_sp gpuSurface = SkSurface::MakeFromBackendRenderTarget(context, - backEndRenderTarget, kTopLeft_GrSurfaceOrigin, nullptr, nullptr); - auto surfaceCanvas = gpuSurface->getCanvas(); - surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); - sk_sp image(gpuSurface->makeImageSnapshot()); - canvas->drawImage(image, 0, 0); -## - -#SeeAlso MakeFromBackendTexture MakeRenderTarget - -#Method ## - -# ------------------------------------------------------------------------------ - #Method static sk_sp MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRenderTarget, GrSurfaceOrigin origin, @@ -558,20 +504,20 @@ If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. #ToDo example is bogus; gpuSurface should not make image ## #Platform gpu #Image 3 - SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); - if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); - return; - } - sk_sp gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( - context, backEndTexture, kTopLeft_GrSurfaceOrigin, 0, - kRGBA_8888_SkColorType, nullptr, nullptr); - auto surfaceCanvas = gpuSurface->getCanvas(); - surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); - sk_sp image(gpuSurface->makeImageSnapshot()); - canvas->drawImage(image, 0, 0); + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, paint); + return; + } + sk_sp gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( + context, backEndTexture, kTopLeft_GrSurfaceOrigin, 0, + kRGBA_8888_SkColorType, nullptr, nullptr); + auto surfaceCanvas = gpuSurface->getCanvas(); + surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); + sk_sp image(gpuSurface->makeImageSnapshot()); + canvas->drawImage(image, 0, 0); ## #SeeAlso MakeFromBackendRenderTarget MakeRenderTarget diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 136fc8b846..419e548f48 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -189,32 +189,6 @@ public: sk_sp colorSpace, const SkSurfaceProps* surfaceProps); - /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure render target is - valid for the lifetime of returned SkSurface. - - SkSurface is returned if all parameters are valid. backendRenderTarget is valid if - its pixel configuration agrees with colorSpace and context; for instance, if - backendRenderTarget has an sRGB configuration, then context must support sRGB, - and colorSpace must be present. Further, backendRenderTarget width and height must - not exceed context capabilities, and the context must be able to support - back-end render targets. - - If SK_SUPPORT_GPU is defined as zero, has no effect and returns nullptr. - - @param context GPU context - @param backendRenderTarget GPU intermediate memory buffer - @param origin one of: kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin - @param colorSpace range of colors - @param surfaceProps LCD striping orientation and setting for device independent - fonts; may be nullptr - @return SkSurface if all parameters are valid; otherwise, nullptr - */ - static sk_sp MakeFromBackendRenderTarget(GrContext* context, - const GrBackendRenderTarget& backendRenderTarget, - GrSurfaceOrigin origin, - sk_sp colorSpace, - const SkSurfaceProps* surfaceProps); - /** Wraps a GPU-backed buffer into SkSurface. Caller must ensure render target is valid for the lifetime of returned SkSurface. diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 3d95e9baef..30a1fa464c 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -284,14 +284,6 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTe return nullptr; } -sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext*, - const GrBackendRenderTarget&, - GrSurfaceOrigin origin, - sk_sp, - const SkSurfaceProps*) { - return nullptr; -} - sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext*, const GrBackendRenderTarget&, GrSurfaceOrigin origin, diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 74169b6548..ace1981bf7 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -381,37 +381,6 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, const GrB return sk_make_sp(std::move(device)); } -sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, - const GrBackendRenderTarget& backendRT, - GrSurfaceOrigin origin, - sk_sp colorSpace, - const SkSurfaceProps* props) { - if (!context) { - return nullptr; - } - if (!SkSurface_Gpu::Valid(context, backendRT.config(), colorSpace.get())) { - return nullptr; - } - - sk_sp rtc( - context->contextPriv().makeBackendRenderTargetRenderTargetContext(backendRT, - origin, - std::move(colorSpace), - props)); - if (!rtc) { - return nullptr; - } - - sk_sp device(SkGpuDevice::Make(context, std::move(rtc), - backendRT.width(), backendRT.height(), - SkGpuDevice::kUninit_InitContents)); - if (!device) { - return nullptr; - } - - return sk_make_sp(std::move(device)); -} - bool validate_backend_render_target(GrContext* ctx, const GrBackendRenderTarget& rt, GrPixelConfig* config, SkColorType ct, sk_sp cs) { // TODO: Create a SkImageColorInfo struct for color, alpha, and color space so we don't need to @@ -446,12 +415,34 @@ sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, if (!context) { return nullptr; } + GrBackendRenderTarget rtCopy = rt; if (!validate_backend_render_target(context, rtCopy, &rtCopy.fConfig, colorType, colorSpace)) { return nullptr; } + if (!SkSurface_Gpu::Valid(context, rtCopy.config(), colorSpace.get())) { + return nullptr; + } + + if (!context) { + return nullptr; + } + + sk_sp rtc( + context->contextPriv().makeBackendRenderTargetRenderTargetContext( + rtCopy, origin, std::move(colorSpace), props)); + if (!rtc) { + return nullptr; + } + + sk_sp device(SkGpuDevice::Make(context, std::move(rtc), rtCopy.width(), + rtCopy.height(), + SkGpuDevice::kUninit_InitContents)); + if (!device) { + return nullptr; + } - return MakeFromBackendRenderTarget(context, rtCopy, origin, colorSpace, props); + return sk_make_sp(std::move(device)); } sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, -- cgit v1.2.3