aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/private/GrRenderTargetProxy.h2
-rw-r--r--include/private/GrSurfaceProxy.h29
-rw-r--r--include/private/GrTextureProxy.h7
3 files changed, 36 insertions, 2 deletions
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index 7d36bf642d..27e0492d9e 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -72,6 +72,8 @@ private:
// Wrapped version
GrRenderTargetProxy(const GrCaps&, sk_sp<GrRenderTarget> rt);
+ size_t onGpuMemorySize() const override;
+
// For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
// For deferred proxies that pointer is filled in when we need to instantiate the
// deferred resource.
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index d57c2f5993..37669fee19 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -112,6 +112,25 @@ public:
void setLastOpList(GrOpList* opList);
GrOpList* getLastOpList() { return fLastOpList; }
+ /**
+ * Retrieves the amount of GPU memory that will be or currently is used by this resource
+ * in bytes. It is approximate since we aren't aware of additional padding or copies made
+ * by the driver.
+ *
+ * @return the amount of GPU memory used in bytes
+ */
+ size_t gpuMemorySize() const {
+ if (fTarget) {
+ return fTarget->gpuMemorySize();
+ }
+
+ if (kInvalidGpuMemorySize == fGpuMemorySize) {
+ fGpuMemorySize = this->onGpuMemorySize();
+ SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
+ }
+ return fGpuMemorySize;
+ }
+
protected:
// Deferred version
GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted)
@@ -119,6 +138,7 @@ protected:
, fFit(fit)
, fBudgeted(budgeted)
, fUniqueID(GrGpuResource::CreateUniqueID())
+ , fGpuMemorySize(kInvalidGpuMemorySize)
, fLastOpList(nullptr) {
}
@@ -133,7 +153,16 @@ protected:
const SkBudgeted fBudgeted; // set from the backing resource for wrapped resources
const uint32_t fUniqueID; // set from the backing resource for wrapped resources
+ static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
+ // This entry is lazily evaluated so, when the proxy wraps a resource, the resource
+ // will be called but, when the proxy is deferred, it will compute the answer itself.
+ // If the proxy computes its own answer that answer is checked (in debug mode) in
+ // the instantiation method.
+ mutable size_t fGpuMemorySize;
+
private:
+ virtual size_t onGpuMemorySize() const = 0;
+
// The last opList that wrote to or is currently going to write to this surface
// The opList can be closed (e.g., no render target context is currently bound
// to this renderTarget).
diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h
index 5b4eeef7bc..b85302feea 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -18,7 +18,8 @@ class GrTextureProxy : public GrSurfaceProxy {
public:
// TODO: need to refine ownership semantics of 'srcData' if we're in completely
// deferred mode
- static sk_sp<GrTextureProxy> Make(const GrSurfaceDesc&, SkBackingFit, SkBudgeted,
+ static sk_sp<GrTextureProxy> Make(GrTextureProvider*, const GrSurfaceDesc&,
+ SkBackingFit, SkBudgeted,
const void* srcData = nullptr, size_t rowBytes = 0);
static sk_sp<GrTextureProxy> Make(sk_sp<GrTexture>);
@@ -27,7 +28,7 @@ public:
const GrTextureProxy* asTextureProxy() const override { return this; }
// Actually instantiate the backing texture, if necessary
- GrTexture* instantiate(GrTextureProvider* texProvider);
+ GrTexture* instantiate(GrTextureProvider*);
private:
// Deferred version
@@ -36,6 +37,8 @@ private:
// Wrapped version
GrTextureProxy(sk_sp<GrTexture> tex);
+ size_t onGpuMemorySize() const override;
+
// For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
// For deferred proxies that pointer will be filled n when we need to instantiate
// the deferred resource