From 3743013f755d23c215d852af7d829c3cd74f34a2 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 9 Nov 2016 06:50:43 -0500 Subject: Consolidate GrSurfaceProxy Make methods I think GrSurfaceDesc is still the most compact way to communicate the deferred GrSurface's settings to the Proxy but this CL, at least, reduces where it is used. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4559 Change-Id: Ica599c28a5aef1ed4094f47a4ac119e2d204d652 Reviewed-on: https://skia-review.googlesource.com/4559 Commit-Queue: Robert Phillips Reviewed-by: Brian Salomon --- src/gpu/GrSurfaceProxy.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/gpu/GrSurfaceProxy.cpp') diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index b6d0e11cbb..da552c917e 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -10,6 +10,7 @@ #include "GrGpuResourcePriv.h" #include "GrOpList.h" #include "GrTextureProvider.h" +#include "GrTextureRenderTargetProxy.h" GrSurfaceProxy::GrSurfaceProxy(sk_sp surface, SkBackingFit fit) : INHERITED(std::move(surface)) @@ -62,3 +63,47 @@ void GrSurfaceProxy::setLastOpList(GrOpList* opList) { SkRefCnt_SafeAssign(fLastOpList, opList); } + +sk_sp GrSurfaceProxy::MakeWrapped(sk_sp surf) { + if (surf->asTexture()) { + if (surf->asRenderTarget()) { + return sk_sp(new GrTextureRenderTargetProxy(std::move(surf))); + } else { + return sk_sp(new GrTextureProxy(std::move(surf))); + } + } else { + SkASSERT(surf->asRenderTarget()); + + // Not texturable + return sk_sp(new GrRenderTargetProxy(std::move(surf))); + } +} + +sk_sp GrSurfaceProxy::MakeDeferred(const GrCaps& caps, + const GrSurfaceDesc& desc, + SkBackingFit fit, + SkBudgeted budgeted) { + if (kRenderTarget_GrSurfaceFlag & desc.fFlags) { + // We know anything we instantiate later from this deferred path will be + // both texturable and renderable + return sk_sp(new GrTextureRenderTargetProxy(caps, desc, fit, budgeted)); + } + + return sk_sp(new GrTextureProxy(desc, fit, budgeted, nullptr, 0)); +} + +sk_sp GrSurfaceProxy::MakeDeferred(const GrCaps& caps, + GrTextureProvider* texProvider, + const GrSurfaceDesc& desc, + SkBudgeted budgeted, + const void* srcData, + size_t rowBytes) { + if (srcData) { + // If we have srcData, for now, we create a wrapped GrTextureProxy + sk_sp surf(texProvider->createTexture(desc, budgeted, srcData, rowBytes)); + return GrSurfaceProxy::MakeWrapped(std::move(surf)); + } + + return GrSurfaceProxy::MakeDeferred(caps, desc, SkBackingFit::kExact, budgeted); +} + -- cgit v1.2.3