aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/private/GrRenderTargetProxy.h11
-rw-r--r--include/private/GrSurfaceProxy.h17
-rw-r--r--include/private/GrTextureProxy.h11
-rw-r--r--include/private/GrTextureRenderTargetProxy.h11
-rw-r--r--src/core/SkSpecialImage.cpp60
-rw-r--r--src/core/SkSpecialImage.h3
-rw-r--r--src/gpu/GrContext.cpp19
-rw-r--r--src/gpu/GrDrawingManager.cpp6
-rw-r--r--src/gpu/GrDrawingManager.h2
-rw-r--r--src/gpu/GrRenderTargetProxy.cpp22
-rw-r--r--src/gpu/GrSurfaceProxy.cpp45
-rw-r--r--src/gpu/GrTextureProxy.cpp34
-rw-r--r--src/gpu/GrTextureRenderTargetProxy.cpp36
-rw-r--r--tests/ProxyConversionTest.cpp90
-rw-r--r--tests/ProxyTest.cpp38
-rw-r--r--tests/SpecialImageTest.cpp9
16 files changed, 204 insertions, 210 deletions
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index 267d7549e3..3c2597b97e 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -20,13 +20,6 @@ class GrTextureProvider;
// the uniqueID of the RenderTarget it represents!
class GrRenderTargetProxy : virtual public GrSurfaceProxy {
public:
- /**
- * The caller gets the creation ref.
- */
- static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, const GrSurfaceDesc&,
- SkBackingFit, SkBudgeted);
- static sk_sp<GrRenderTargetProxy> Make(sk_sp<GrRenderTarget>);
-
GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
@@ -65,11 +58,13 @@ public:
SkDEBUGCODE(void validate(GrContext*) const;)
protected:
+ friend class GrSurfaceProxy; // for ctors
+
// Deferred version
GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted);
// Wrapped version
- GrRenderTargetProxy(sk_sp<GrRenderTarget> rt);
+ GrRenderTargetProxy(sk_sp<GrSurface>);
private:
size_t onGpuMemorySize() const override;
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 539aaf65aa..1e846c5223 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -12,10 +12,12 @@
#include "GrSurface.h"
#include "SkRect.h"
+class GrCaps;
class GrOpList;
class GrTextureProvider;
class GrTextureProxy;
class GrRenderTargetProxy;
+class GrTextureProvider;
// This class replicates the functionality GrIORef<GrSurface> but tracks the
// utilitization for later resource allocation (for the deferred case) and
@@ -75,6 +77,17 @@ protected:
class GrSurfaceProxy : public GrIORefProxy {
public:
+ static sk_sp<GrSurfaceProxy> MakeWrapped(sk_sp<GrSurface>);
+
+ static sk_sp<GrSurfaceProxy> MakeDeferred(const GrCaps&, const GrSurfaceDesc&,
+ SkBackingFit, SkBudgeted);
+
+ // TODO: need to refine ownership semantics of 'srcData' if we're in completely
+ // deferred mode
+ static sk_sp<GrSurfaceProxy> MakeDeferred(const GrCaps&, GrTextureProvider*,
+ const GrSurfaceDesc&, SkBudgeted,
+ const void* srcData, size_t rowBytes);
+
const GrSurfaceDesc& desc() const { return fDesc; }
GrSurfaceOrigin origin() const {
@@ -88,6 +101,8 @@ public:
uint32_t uniqueID() const { return fUniqueID; }
+ GrSurface* instantiate(GrTextureProvider* texProvider);
+
/**
* Helper that gets the width and height of the surface as a bounding rectangle.
*/
@@ -146,8 +161,6 @@ protected:
virtual ~GrSurfaceProxy();
- GrSurface* instantiate(GrTextureProvider* texProvider);
-
// For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
const GrSurfaceDesc fDesc;
const SkBackingFit fFit; // always exact for wrapped resources
diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h
index 75f09de800..a206e76e37 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -17,13 +17,6 @@ class GrTextureProvider;
// This class delays the acquisition of textures until they are actually required
class GrTextureProxy : virtual public GrSurfaceProxy {
public:
- // TODO: need to refine ownership semantics of 'srcData' if we're in completely
- // deferred mode
- static sk_sp<GrTextureProxy> Make(const GrCaps&, GrTextureProvider*, const GrSurfaceDesc&,
- SkBackingFit, SkBudgeted,
- const void* srcData = nullptr, size_t rowBytes = 0);
- static sk_sp<GrTextureProxy> Make(sk_sp<GrTexture>);
-
GrTextureProxy* asTextureProxy() override { return this; }
const GrTextureProxy* asTextureProxy() const override { return this; }
@@ -31,11 +24,13 @@ public:
GrTexture* instantiate(GrTextureProvider*);
protected:
+ friend class GrSurfaceProxy; // for ctors
+
// Deferred version
GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit, SkBudgeted,
const void* srcData, size_t srcRowBytes);
// Wrapped version
- GrTextureProxy(sk_sp<GrTexture> tex);
+ GrTextureProxy(sk_sp<GrSurface>);
private:
size_t onGpuMemorySize() const override;
diff --git a/include/private/GrTextureRenderTargetProxy.h b/include/private/GrTextureRenderTargetProxy.h
index c4d190f94d..b3a9a239fc 100644
--- a/include/private/GrTextureRenderTargetProxy.h
+++ b/include/private/GrTextureRenderTargetProxy.h
@@ -22,19 +22,14 @@
// Beware: the uniqueID of the TextureRenderTargetProxy will usually be different than
// the uniqueID of the RenderTarget/Texture it represents!
class GrTextureRenderTargetProxy : public GrTextureProxy, public GrRenderTargetProxy {
-public:
- static sk_sp<GrTextureRenderTargetProxy> Make(const GrCaps&,
- const GrSurfaceDesc&,
- SkBackingFit, SkBudgeted);
- static sk_sp<GrTextureRenderTargetProxy> Make(sk_sp<GrTexture>);
- static sk_sp<GrTextureRenderTargetProxy> Make(sk_sp<GrRenderTarget>);
-
private:
+ friend class GrSurfaceProxy; // for ctors
+
// Deferred version
GrTextureRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted);
// Wrapped version
- GrTextureRenderTargetProxy(sk_sp<GrRenderTarget> rt);
+ GrTextureRenderTargetProxy(sk_sp<GrSurface>);
size_t onGpuMemorySize() const override;
};
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 239d9a90da..f4577df849 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -250,10 +250,13 @@ public:
sk_sp<GrTextureProxy> onAsTextureProxy(GrContext* context) const override {
if (context) {
- sk_sp<GrTexture> tex(sk_ref_sp(
- GrRefCachedBitmapTexture(context, fBitmap, GrTextureParams::ClampNoFilter(),
- SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)));
- return GrTextureProxy::Make(tex);
+ sk_sp<GrTexture> tex(sk_ref_sp(GrRefCachedBitmapTexture(
+ context,
+ fBitmap,
+ GrTextureParams::ClampNoFilter(),
+ SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware)));
+ sk_sp<GrSurfaceProxy> sProxy = GrSurfaceProxy::MakeWrapped(std::move(tex));
+ return sk_ref_sp(sProxy->asTextureProxy());
}
return nullptr;
@@ -357,15 +360,15 @@ public:
, fAlphaType(at)
, fColorSpace(std::move(colorSpace))
, fAddedRasterVersionToCache(false) {
- fTextureProxy = GrTextureProxy::Make(std::move(tex));
+ fSurfaceProxy = GrSurfaceProxy::MakeWrapped(std::move(tex));
}
SkSpecialImage_Gpu(GrContext* context, const SkIRect& subset,
- uint32_t uniqueID, sk_sp<GrTextureProxy> proxy, SkAlphaType at,
+ uint32_t uniqueID, sk_sp<GrSurfaceProxy> proxy, SkAlphaType at,
sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props)
: INHERITED(subset, uniqueID, props)
, fContext(context)
- , fTextureProxy(std::move(proxy))
+ , fSurfaceProxy(std::move(proxy))
, fAlphaType(at)
, fColorSpace(std::move(colorSpace))
, fAddedRasterVersionToCache(false) {
@@ -379,17 +382,18 @@ public:
SkAlphaType alphaType() const override { return fAlphaType; }
- size_t getSize() const override { return fTextureProxy->gpuMemorySize(); }
+ size_t getSize() const override { return fSurfaceProxy->gpuMemorySize(); }
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
SkRect dst = SkRect::MakeXYWH(x, y,
this->subset().width(), this->subset().height());
// TODO: add GrTextureProxy-backed SkImage_Gpus
- sk_sp<GrTexture> tex = sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider()));
+ GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider());
- auto img = sk_sp<SkImage>(new SkImage_Gpu(fTextureProxy->width(), fTextureProxy->height(),
- this->uniqueID(), fAlphaType, std::move(tex),
+ auto img = sk_sp<SkImage>(new SkImage_Gpu(fSurfaceProxy->width(), fSurfaceProxy->height(),
+ this->uniqueID(), fAlphaType,
+ sk_ref_sp(surf->asTexture()),
fColorSpace, SkBudgeted::kNo));
canvas->drawImageRect(img, this->subset(),
@@ -400,11 +404,13 @@ public:
// This entry point should go away in favor of asTextureProxy
sk_sp<GrTexture> onAsTextureRef(GrContext* context) const override {
- return sk_ref_sp(fTextureProxy->instantiate(context->textureProvider()));
+ GrSurface* surf = fSurfaceProxy->instantiate(context->textureProvider());
+
+ return sk_ref_sp(surf->asTexture());
}
sk_sp<GrTextureProxy> onAsTextureProxy(GrContext*) const override {
- return fTextureProxy;
+ return sk_ref_sp(fSurfaceProxy->asTextureProxy());
}
bool onGetROPixels(SkBitmap* dst) const override {
@@ -423,9 +429,9 @@ public:
}
// Reading back to an SkBitmap ends deferral
- GrTexture* texture = fTextureProxy->instantiate(fContext->textureProvider());
+ GrSurface* surface = fSurfaceProxy->instantiate(fContext->textureProvider());
- if (!texture->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig,
+ if (!surface->readPixels(0, 0, dst->width(), dst->height(), kSkia8888_GrPixelConfig,
dst->getPixels(), dst->rowBytes())) {
return false;
}
@@ -456,7 +462,7 @@ public:
return SkSpecialImage::MakeDeferredFromGpu(fContext,
subset,
this->uniqueID(),
- fTextureProxy,
+ fSurfaceProxy,
fColorSpace,
&this->props(),
fAlphaType);
@@ -464,19 +470,19 @@ public:
sk_sp<SkImage> onMakeTightSubset(const SkIRect& subset) const override {
// TODO: add GrTextureProxy-backed SkImage_Gpus
- sk_sp<GrTexture> tex = sk_ref_sp(fTextureProxy->instantiate(fContext->textureProvider()));
+ GrSurface* surf = fSurfaceProxy->instantiate(fContext->textureProvider());
if (0 == subset.fLeft && 0 == subset.fTop &&
- fTextureProxy->width() == subset.width() &&
- fTextureProxy->height() == subset.height()) {
+ fSurfaceProxy->width() == subset.width() &&
+ fSurfaceProxy->height() == subset.height()) {
// The existing GrTexture is already tight so reuse it in the SkImage
- return sk_make_sp<SkImage_Gpu>(tex->width(), tex->height(),
- kNeedNewImageUniqueID,
- fAlphaType, std::move(tex), fColorSpace,
- SkBudgeted::kYes);
+ return sk_make_sp<SkImage_Gpu>(surf->width(), surf->height(),
+ kNeedNewImageUniqueID, fAlphaType,
+ sk_ref_sp(surf->asTexture()),
+ fColorSpace, SkBudgeted::kYes);
}
- GrSurfaceDesc desc = fTextureProxy->desc();
+ GrSurfaceDesc desc = fSurfaceProxy->desc();
desc.fWidth = subset.width();
desc.fHeight = subset.height();
@@ -484,7 +490,7 @@ public:
if (!subTx) {
return nullptr;
}
- fContext->copySurface(subTx.get(), tex.get(), subset, SkIPoint::Make(0, 0));
+ fContext->copySurface(subTx.get(), surf, subset, SkIPoint::Make(0, 0));
return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID,
fAlphaType, std::move(subTx), fColorSpace, SkBudgeted::kYes);
}
@@ -501,7 +507,7 @@ public:
private:
GrContext* fContext;
- sk_sp<GrTextureProxy> fTextureProxy;
+ sk_sp<GrSurfaceProxy> fSurfaceProxy;
const SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fColorSpace;
mutable SkAtomic<bool> fAddedRasterVersionToCache;
@@ -523,7 +529,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::MakeFromGpu(const SkIRect& subset,
sk_sp<SkSpecialImage> SkSpecialImage::MakeDeferredFromGpu(GrContext* context,
const SkIRect& subset,
uint32_t uniqueID,
- sk_sp<GrTextureProxy> proxy,
+ sk_sp<GrSurfaceProxy> proxy,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* props,
SkAlphaType at) {
diff --git a/src/core/SkSpecialImage.h b/src/core/SkSpecialImage.h
index 99e348920d..12847df115 100644
--- a/src/core/SkSpecialImage.h
+++ b/src/core/SkSpecialImage.h
@@ -16,6 +16,7 @@
#include "SkImageInfo.h" // for SkAlphaType
class GrContext;
+class GrSurfaceProxy;
class GrTexture;
class GrTextureProxy;
class SkBitmap;
@@ -87,7 +88,7 @@ public:
static sk_sp<SkSpecialImage> MakeDeferredFromGpu(GrContext*,
const SkIRect& subset,
uint32_t uniqueID,
- sk_sp<GrTextureProxy>,
+ sk_sp<GrSurfaceProxy>,
sk_sp<SkColorSpace>,
const SkSurfaceProps* = nullptr,
SkAlphaType at = kPremul_SkAlphaType);
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 13d1f3d119..ff8de9da45 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -609,9 +609,9 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeWrappedRenderTargetContext(
const SkSurfaceProps* surfaceProps) {
ASSERT_SINGLE_OWNER_PRIV
- sk_sp<GrRenderTargetProxy> rtp(GrRenderTargetProxy::Make(std::move(rt)));
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(rt)));
- return this->drawingManager()->makeRenderTargetContext(std::move(rtp),
+ return this->drawingManager()->makeRenderTargetContext(std::move(proxy),
std::move(colorSpace),
surfaceProps);
}
@@ -629,10 +629,9 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContex
return nullptr;
}
- sk_sp<GrRenderTargetProxy> rtp(GrRenderTargetProxy::Make(
- sk_ref_sp(surface->asRenderTarget())));
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface)));
- return this->drawingManager()->makeRenderTargetContext(std::move(rtp),
+ return this->drawingManager()->makeRenderTargetContext(std::move(proxy),
std::move(colorSpace), props);
}
@@ -647,9 +646,9 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetC
return nullptr;
}
- sk_sp<GrRenderTargetProxy> rtp(GrRenderTargetProxy::Make(std::move(rt)));
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(rt)));
- return this->drawingManager()->makeRenderTargetContext(std::move(rtp),
+ return this->drawingManager()->makeRenderTargetContext(std::move(proxy),
std::move(colorSpace),
surfaceProps);
}
@@ -666,9 +665,9 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRend
return nullptr;
}
- sk_sp<GrRenderTargetProxy> rtp(GrRenderTargetProxy::Make(sk_ref_sp(surface->asRenderTarget())));
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface)));
- return this->drawingManager()->makeRenderTargetContext(std::move(rtp),
+ return this->drawingManager()->makeRenderTargetContext(std::move(proxy),
std::move(colorSpace),
surfaceProps);
}
@@ -787,7 +786,7 @@ sk_sp<GrRenderTargetContext> GrContext::makeDeferredRenderTargetContext(
desc.fConfig = config;
desc.fSampleCnt = sampleCnt;
- sk_sp<GrRenderTargetProxy> rtp = GrRenderTargetProxy::Make(*this->caps(), desc, fit, budgeted);
+ sk_sp<GrSurfaceProxy> rtp = GrSurfaceProxy::MakeDeferred(*this->caps(), desc, fit, budgeted);
return fDrawingManager->makeRenderTargetContext(std::move(rtp),
std::move(colorSpace),
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index af6a5116ea..f16f861539 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -209,13 +209,15 @@ GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawP
}
sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext(
- sk_sp<GrRenderTargetProxy> rtp,
+ sk_sp<GrSurfaceProxy> sProxy,
sk_sp<SkColorSpace> colorSpace,
const SkSurfaceProps* surfaceProps) {
- if (this->wasAbandoned()) {
+ if (this->wasAbandoned() || !sProxy->asRenderTargetProxy()) {
return nullptr;
}
+ sk_sp<GrRenderTargetProxy> rtp(sk_ref_sp(sProxy->asRenderTargetProxy()));
+
// SkSurface catches bad color space usage at creation. This check handles anything that slips
// by, including internal usage. We allow a null color space here, for read/write pixels and
// other special code paths. If a color space is provided, though, enforce all other rules.
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index fa275d20d7..3816868c75 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -35,7 +35,7 @@ public:
bool wasAbandoned() const { return fAbandoned; }
void freeGpuResources();
- sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrRenderTargetProxy> rtp,
+ sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
sk_sp<SkColorSpace>,
const SkSurfaceProps*);
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index fcc5275002..669f422371 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -31,8 +31,8 @@ GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc
}
// Wrapped version
-GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrRenderTarget> rt)
- : INHERITED(std::move(rt), SkBackingFit::kExact)
+GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
+ : INHERITED(std::move(surf), SkBackingFit::kExact)
, fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
}
@@ -70,21 +70,3 @@ size_t GrRenderTargetProxy::onGpuMemorySize() const {
return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
}
-sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps,
- const GrSurfaceDesc& desc,
- SkBackingFit fit,
- SkBudgeted budgeted) {
- // We know anything we instantiate later from this deferred path will be
- // both texturable and renderable
- return GrTextureRenderTargetProxy::Make(caps, desc, fit, budgeted);
-}
-
-sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(sk_sp<GrRenderTarget> rt) {
- if (rt->asTexture()) {
- return GrTextureRenderTargetProxy::Make(std::move(rt));
- }
-
- // Not texturable
- return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(rt));
-}
-
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<GrSurface> surface, SkBackingFit fit)
: INHERITED(std::move(surface))
@@ -62,3 +63,47 @@ void GrSurfaceProxy::setLastOpList(GrOpList* opList) {
SkRefCnt_SafeAssign(fLastOpList, opList);
}
+
+sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrSurface> surf) {
+ if (surf->asTexture()) {
+ if (surf->asRenderTarget()) {
+ return sk_sp<GrSurfaceProxy>(new GrTextureRenderTargetProxy(std::move(surf)));
+ } else {
+ return sk_sp<GrSurfaceProxy>(new GrTextureProxy(std::move(surf)));
+ }
+ } else {
+ SkASSERT(surf->asRenderTarget());
+
+ // Not texturable
+ return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(surf)));
+ }
+}
+
+sk_sp<GrSurfaceProxy> 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<GrSurfaceProxy>(new GrTextureRenderTargetProxy(caps, desc, fit, budgeted));
+ }
+
+ return sk_sp<GrSurfaceProxy>(new GrTextureProxy(desc, fit, budgeted, nullptr, 0));
+}
+
+sk_sp<GrSurfaceProxy> 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<GrSurface> surf(texProvider->createTexture(desc, budgeted, srcData, rowBytes));
+ return GrSurfaceProxy::MakeWrapped(std::move(surf));
+ }
+
+ return GrSurfaceProxy::MakeDeferred(caps, desc, SkBackingFit::kExact, budgeted);
+}
+
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 5fe43f7125..97987479c6 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -8,7 +8,6 @@
#include "GrTextureProxy.h"
#include "GrTextureProvider.h"
-#include "GrTextureRenderTargetProxy.h"
GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
const void* srcData, size_t /*rowBytes*/)
@@ -16,8 +15,8 @@ GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, S
SkASSERT(!srcData); // currently handled in Make()
}
-GrTextureProxy::GrTextureProxy(sk_sp<GrTexture> tex)
- : INHERITED(std::move(tex), SkBackingFit::kExact) {
+GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
+ : INHERITED(std::move(surf), SkBackingFit::kExact) {
}
GrTexture* GrTextureProxy::instantiate(GrTextureProvider* texProvider) {
@@ -38,32 +37,3 @@ size_t GrTextureProxy::onGpuMemorySize() const {
// TODO: add tracking of mipmap state to improve the estimate
return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps);
}
-
-sk_sp<GrTextureProxy> GrTextureProxy::Make(const GrCaps& caps,
- GrTextureProvider* texProvider,
- const GrSurfaceDesc& desc,
- SkBackingFit fit,
- SkBudgeted budgeted,
- const void* srcData,
- size_t rowBytes) {
- if (srcData) {
- // If we have srcData, for now, we create a wrapped GrTextureProxy
- sk_sp<GrTexture> tex(texProvider->createTexture(desc, budgeted, srcData, rowBytes));
- return GrTextureProxy::Make(std::move(tex));
- }
-
- if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
- return GrTextureRenderTargetProxy::Make(caps, desc, fit, budgeted);
- }
-
- return sk_sp<GrTextureProxy>(new GrTextureProxy(desc, fit, budgeted, nullptr, 0));
-}
-
-sk_sp<GrTextureProxy> GrTextureProxy::Make(sk_sp<GrTexture> tex) {
- if (tex->asRenderTarget()) {
- return GrTextureRenderTargetProxy::Make(std::move(tex));
- }
-
- // Not renderable
- return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex)));
-}
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index 74c3b71f2d..95451e9142 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -22,11 +22,12 @@ GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps,
// Wrapped version
// This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
// GrRenderTargetProxy) so its constructor must be explicitly called.
-GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrRenderTarget> rt)
- : GrSurfaceProxy(rt, SkBackingFit::kExact)
- , GrTextureProxy(sk_ref_sp(rt->asTexture()))
- , GrRenderTargetProxy(rt) {
- SkASSERT(rt->asTexture());
+GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf)
+ : GrSurfaceProxy(surf, SkBackingFit::kExact)
+ , GrTextureProxy(sk_ref_sp(surf->asTexture()))
+ , GrRenderTargetProxy(sk_ref_sp(surf->asRenderTarget())) {
+ SkASSERT(surf->asTexture());
+ SkASSERT(surf->asRenderTarget());
}
size_t GrTextureRenderTargetProxy::onGpuMemorySize() const {
@@ -38,28 +39,3 @@ size_t GrTextureRenderTargetProxy::onGpuMemorySize() const {
return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, true);
}
-sk_sp<GrTextureRenderTargetProxy> GrTextureRenderTargetProxy::Make(const GrCaps& caps,
- const GrSurfaceDesc& desc,
- SkBackingFit fit,
- SkBudgeted budgeted) {
- SkASSERT(desc.fFlags & kRenderTarget_GrSurfaceFlag);
-
- return sk_sp<GrTextureRenderTargetProxy>(new GrTextureRenderTargetProxy(caps, desc,
- fit, budgeted));
-}
-
-sk_sp<GrTextureRenderTargetProxy> GrTextureRenderTargetProxy::Make(sk_sp<GrTexture> tex) {
- SkASSERT(tex->asRenderTarget());
-
- return sk_sp<GrTextureRenderTargetProxy>(new GrTextureRenderTargetProxy(
- sk_ref_sp(tex->asRenderTarget())));
-}
-
-sk_sp<GrTextureRenderTargetProxy> GrTextureRenderTargetProxy::Make(sk_sp<GrRenderTarget> rt) {
- SkASSERT(rt->asTexture());
-
- return sk_sp<GrTextureRenderTargetProxy>(new GrTextureRenderTargetProxy(std::move(rt)));
-}
-
-
-
diff --git a/tests/ProxyConversionTest.cpp b/tests/ProxyConversionTest.cpp
index 8a799f7859..bc7187f5e1 100644
--- a/tests/ProxyConversionTest.cpp
+++ b/tests/ProxyConversionTest.cpp
@@ -14,9 +14,9 @@
#include "GrTextureProxy.h"
#include "GrRenderTargetProxy.h"
-static sk_sp<GrRenderTargetProxy> make_wrapped_FBO0(GrTextureProvider* provider,
- skiatest::Reporter* reporter,
- const GrSurfaceDesc& desc) {
+static sk_sp<GrSurfaceProxy> make_wrapped_FBO0(GrTextureProvider* provider,
+ skiatest::Reporter* reporter,
+ const GrSurfaceDesc& desc) {
GrBackendRenderTargetDesc backendDesc;
backendDesc.fWidth = desc.fWidth;
backendDesc.fHeight = desc.fHeight;
@@ -29,27 +29,26 @@ static sk_sp<GrRenderTargetProxy> make_wrapped_FBO0(GrTextureProvider* provider,
sk_sp<GrRenderTarget> defaultFBO(provider->wrapBackendRenderTarget(backendDesc));
SkASSERT(!defaultFBO->asTexture());
- return GrRenderTargetProxy::Make(std::move(defaultFBO));
+ return GrSurfaceProxy::MakeWrapped(std::move(defaultFBO));
}
-static sk_sp<GrRenderTargetProxy> make_wrapped_offscreen_rt(GrTextureProvider* provider,
- skiatest::Reporter* reporter,
- const GrSurfaceDesc& desc,
- SkBudgeted budgeted) {
+static sk_sp<GrSurfaceProxy> make_wrapped_offscreen_rt(GrTextureProvider* provider,
+ skiatest::Reporter* reporter,
+ const GrSurfaceDesc& desc,
+ SkBudgeted budgeted) {
SkASSERT(kRenderTarget_GrSurfaceFlag == desc.fFlags);
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
- sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
- return GrRenderTargetProxy::Make(std::move(rt));
+ return GrSurfaceProxy::MakeWrapped(std::move(tex));
}
-static sk_sp<GrTextureProxy> make_wrapped_texture(GrTextureProvider* provider,
+static sk_sp<GrSurfaceProxy> make_wrapped_texture(GrTextureProvider* provider,
const GrSurfaceDesc& desc,
SkBudgeted budgeted) {
sk_sp<GrTexture> tex(provider->createTexture(desc, budgeted));
- return GrTextureProxy::Make(std::move(tex));
+ return GrSurfaceProxy::MakeWrapped(std::move(tex));
}
// Test converting between RenderTargetProxies and TextureProxies for wrapped
@@ -65,44 +64,52 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo
if (kOpenGL_GrBackend == ctxInfo.backend()) {
// External on-screen render target.
- sk_sp<GrRenderTargetProxy> rtProxy(make_wrapped_FBO0(provider, reporter, desc));
+ sk_sp<GrSurfaceProxy> sProxy(make_wrapped_FBO0(provider, reporter, desc));
// RenderTarget-only
+ GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
+ REPORTER_ASSERT(reporter, rtProxy);
REPORTER_ASSERT(reporter, !rtProxy->asTextureProxy());
- REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy.get());
+ REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
{
// Internal offscreen render target.
- sk_sp<GrRenderTargetProxy> rtProxy(make_wrapped_offscreen_rt(provider,
- reporter, desc,
- SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(make_wrapped_offscreen_rt(provider,
+ reporter, desc,
+ SkBudgeted::kYes));
// Both RenderTarget and Texture
+ GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
+ REPORTER_ASSERT(reporter, rtProxy);
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
- REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy.get());
- REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy.get());
+ REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
+ REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
{
// Internal offscreen render target - but through GrTextureProxy
- sk_sp<GrTextureProxy> tProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
// Both RenderTarget and Texture
+ GrTextureProxy* tProxy = sProxy->asTextureProxy();
+ REPORTER_ASSERT(reporter, tProxy);
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
- REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy.get());
- REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy.get());
+ REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
+ REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
}
{
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
- sk_sp<GrTextureProxy> tProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(make_wrapped_texture(provider, desc, SkBudgeted::kYes));
// Texture-only
- REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy.get());
+ GrTextureProxy* tProxy = sProxy->asTextureProxy();
+ REPORTER_ASSERT(reporter, tProxy);
+ REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
}
}
@@ -110,7 +117,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyConversionTest, reporter, ctxInfo
// Test converting between RenderTargetProxies and TextureProxies for deferred
// Proxies
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxInfo) {
- GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
const GrCaps& caps = *ctxInfo.grContext()->caps();
GrSurfaceDesc desc;
@@ -120,38 +126,44 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DefferredProxyConversionTest, reporter, ctxIn
desc.fConfig = kRGBA_8888_GrPixelConfig;
{
- sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(caps, desc,
- SkBackingFit::kApprox,
- SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
+ SkBackingFit::kApprox,
+ SkBudgeted::kYes));
// Both RenderTarget and Texture
+ GrRenderTargetProxy* rtProxy = sProxy->asRenderTargetProxy();
+ REPORTER_ASSERT(reporter, rtProxy);
GrTextureProxy* tProxy = rtProxy->asTextureProxy();
REPORTER_ASSERT(reporter, tProxy);
- REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy.get());
- REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy.get());
+ REPORTER_ASSERT(reporter, tProxy->asRenderTargetProxy() == rtProxy);
+ REPORTER_ASSERT(reporter, rtProxy->asRenderTargetProxy() == rtProxy);
}
{
- sk_sp<GrTextureProxy> tProxy(GrTextureProxy::Make(caps, provider, desc,
- SkBackingFit::kApprox,
- SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
+ SkBackingFit::kApprox,
+ SkBudgeted::kYes));
// Both RenderTarget and Texture - but via GrTextureProxy
+ GrTextureProxy* tProxy = sProxy->asTextureProxy();
+ REPORTER_ASSERT(reporter, tProxy);
GrRenderTargetProxy* rtProxy = tProxy->asRenderTargetProxy();
REPORTER_ASSERT(reporter, rtProxy);
- REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy.get());
- REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy.get());
+ REPORTER_ASSERT(reporter, rtProxy->asTextureProxy() == tProxy);
+ REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
}
{
desc.fFlags = kNone_GrSurfaceFlags; // force no-RT
- sk_sp<GrTextureProxy> tProxy(GrTextureProxy::Make(caps, provider, desc,
- SkBackingFit::kApprox,
- SkBudgeted::kYes));
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps, desc,
+ SkBackingFit::kApprox,
+ SkBudgeted::kYes));
// Texture-only
- REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy.get());
+ GrTextureProxy* tProxy = sProxy->asTextureProxy();
+ REPORTER_ASSERT(reporter, tProxy);
+ REPORTER_ASSERT(reporter, tProxy->asTextureProxy() == tProxy);
REPORTER_ASSERT(reporter, !tProxy->asRenderTargetProxy());
}
}
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 270f7873ab..17a3dad3b8 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -104,27 +104,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) {
desc.fSampleCnt = numSamples;
if (renderable) {
- sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(
caps, desc,
fit, budgeted));
- check_surface(reporter, rtProxy.get(), origin,
+ check_surface(reporter, sProxy.get(), origin,
widthHeight, widthHeight, config,
SK_InvalidUniqueID, budgeted);
- check_rendertarget(reporter, provider, rtProxy.get(),
+ check_rendertarget(reporter, provider,
+ sProxy->asRenderTargetProxy(),
numSamples, fit);
}
desc.fFlags = kNone_GrSurfaceFlags;
desc.fSampleCnt = 0;
- sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(caps, provider,
- desc,
- fit,
- budgeted));
- check_surface(reporter, texProxy.get(), origin,
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
+ desc,
+ fit,
+ budgeted));
+ check_surface(reporter, sProxy.get(), origin,
widthHeight, widthHeight, config,
SK_InvalidUniqueID, budgeted);
- check_texture(reporter, provider, texProxy.get(), fit);
+ check_texture(reporter, provider, sProxy->asTextureProxy(), fit);
}
}
}
@@ -168,11 +169,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
REPORTER_ASSERT(reporter,
!defaultFBO->renderTargetPriv().maxWindowRectangles());
- sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(defaultFBO));
- check_surface(reporter, rtProxy.get(), origin,
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
+ check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight, config,
defaultFBO->uniqueID(), SkBudgeted::kNo);
- check_rendertarget(reporter, provider, rtProxy.get(),
+ check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
numSamples, SkBackingFit::kExact);
}
@@ -187,11 +188,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
caps.maxWindowRectangles() ==
rt->renderTargetPriv().maxWindowRectangles());
- sk_sp<GrRenderTargetProxy> rtProxy(GrRenderTargetProxy::Make(rt));
- check_surface(reporter, rtProxy.get(), origin,
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
+ check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight, config,
rt->uniqueID(), budgeted);
- check_rendertarget(reporter, provider, rtProxy.get(),
+ check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
numSamples, SkBackingFit::kExact);
}
@@ -201,10 +202,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) {
tex.reset(provider->createTexture(desc, budgeted));
}
- sk_sp<GrTextureProxy> texProxy(GrTextureProxy::Make(tex));
- check_surface(reporter, texProxy.get(), origin,
+ sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(tex));
+ check_surface(reporter, sProxy.get(), origin,
kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
- check_texture(reporter, provider, texProxy.get(), SkBackingFit::kExact);
+ check_texture(reporter, provider, sProxy->asTextureProxy(),
+ SkBackingFit::kExact);
}
}
}
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index abadb303cb..62a5da6089 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -17,7 +17,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
-#include "GrTextureProxy.h"
+#include "GrSurfaceProxy.h"
#endif
@@ -301,9 +301,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_DeferredGpu, reporter, ctxInfo)
desc.fWidth = kFullSize;
desc.fHeight = kFullSize;
- sk_sp<GrTextureProxy> proxy(GrTextureProxy::Make(*context->caps(), context->textureProvider(),
- desc, SkBackingFit::kExact, SkBudgeted::kNo,
- bm.getPixels(), 0));
+ sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeDeferred(*context->caps(),
+ context->textureProvider(),
+ desc, SkBudgeted::kNo,
+ bm.getPixels(), 0));
if (!proxy) {
return;
}