aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-05-17 13:49:59 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-17 18:17:50 +0000
commitbb5711a5e4b9c83f0fc49f2d4ee19ca1e4592e14 (patch)
treee743c265e75a1dad32c1425bf3b9ed88abad2c52 /src/gpu
parent9f1c403362d8de6038328c7238b6ac56be552324 (diff)
Remove GrSurfaceDesc member from GrSurfaceProxy.
Stores the config, origin, and dimensions in GrSurfaceProxy, sample count in GrRenderTargetProxy, and "was constructed with mip maps" in GrTextureProxy. Change-Id: Iee058674dce49107a991cca9d083cd33e3572809 Reviewed-on: https://skia-review.googlesource.com/17209 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrContext.cpp2
-rw-r--r--src/gpu/GrCoordTransform.cpp2
-rw-r--r--src/gpu/GrDrawOpAtlas.cpp4
-rw-r--r--src/gpu/GrDrawingManager.cpp3
-rw-r--r--src/gpu/GrProcessor.cpp4
-rw-r--r--src/gpu/GrRenderTargetContext.cpp11
-rw-r--r--src/gpu/GrRenderTargetContext.h2
-rw-r--r--src/gpu/GrRenderTargetProxy.cpp53
-rw-r--r--src/gpu/GrResourceProvider.cpp2
-rw-r--r--src/gpu/GrSurface.cpp18
-rw-r--r--src/gpu/GrSurfaceProxy.cpp71
-rw-r--r--src/gpu/GrTexture.cpp3
-rw-r--r--src/gpu/GrTextureProxy.cpp30
-rw-r--r--src/gpu/GrTextureRenderTargetProxy.cpp26
-rw-r--r--src/gpu/GrTextureRenderTargetProxy.h4
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.h6
-rw-r--r--src/gpu/gl/GrGLRenderTarget.cpp6
-rw-r--r--src/gpu/gl/GrGLTextureRenderTarget.h2
-rw-r--r--src/gpu/vk/GrVkRenderTarget.h4
-rw-r--r--src/gpu/vk/GrVkTextureRenderTarget.h4
20 files changed, 142 insertions, 115 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 7862a8223c..1455800cbd 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -380,7 +380,7 @@ bool GrContextPriv::writeSurfacePixels(GrSurfaceContext* dst,
if (tempProxy->priv().hasPendingIO()) {
this->flush(tempProxy.get());
}
- GrTexture* texture = tempProxy->instantiate(fContext->resourceProvider());
+ GrTexture* texture = tempProxy->instantiateTexture(fContext->resourceProvider());
if (!texture) {
return false;
}
diff --git a/src/gpu/GrCoordTransform.cpp b/src/gpu/GrCoordTransform.cpp
index 79d9e98b76..4767e53d69 100644
--- a/src/gpu/GrCoordTransform.cpp
+++ b/src/gpu/GrCoordTransform.cpp
@@ -18,7 +18,7 @@ void GrCoordTransform::reset(GrResourceProvider* resourceProvider, const SkMatri
// MDB TODO: just GrCaps is needed for this method
// MDB TODO: once all the coord transforms take a proxy just store it here and
// instantiate later
- fTexture = proxy->instantiate(resourceProvider);
+ fTexture = proxy->instantiateTexture(resourceProvider);
fNormalize = normalize;
fReverseY = kBottomLeft_GrSurfaceOrigin == proxy->origin();
}
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index f1f29dc9ef..0e8de3c578 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -210,7 +210,7 @@ inline bool GrDrawOpAtlas::updatePlot(GrDrawOp::Target* target, AtlasID* id, Plo
// MDB TODO: this is currently fine since the atlas' proxy is always pre-instantiated.
// Once it is deferred more care must be taken upon instantiation failure.
- GrTexture* texture = fProxy->instantiate(fContext->resourceProvider());
+ GrTexture* texture = fProxy->instantiateTexture(fContext->resourceProvider());
if (!texture) {
return false;
}
@@ -289,7 +289,7 @@ bool GrDrawOpAtlas::addToAtlas(AtlasID* id, GrDrawOp::Target* target, int width,
sk_sp<Plot> plotsp(SkRef(newPlot.get()));
// MDB TODO: this is currently fine since the atlas' proxy is always pre-instantiated.
// Once it is deferred more care must be taken upon instantiation failure.
- GrTexture* texture = fProxy->instantiate(fContext->resourceProvider());
+ GrTexture* texture = fProxy->instantiateTexture(fContext->resourceProvider());
if (!texture) {
return false;
}
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 0c2485b544..b177a43003 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -308,7 +308,8 @@ sk_sp<GrRenderTargetContext> GrDrawingManager::makeRenderTargetContext(
if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
GrFSAAType::kNone != rtp->fsaaType()) {
// TODO: defer stencil buffer attachment for PathRenderingDrawContext
- sk_sp<GrRenderTarget> rt(sk_ref_sp(rtp->instantiate(fContext->resourceProvider())));
+ sk_sp<GrRenderTarget> rt(
+ sk_ref_sp(rtp->instantiateRenderTarget(fContext->resourceProvider())));
if (!rt) {
return nullptr;
}
diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp
index 1533257bad..c20ebabfb5 100644
--- a/src/gpu/GrProcessor.cpp
+++ b/src/gpu/GrProcessor.cpp
@@ -250,7 +250,7 @@ void GrResourceIOProcessor::TextureSampler::reset(GrResourceProvider* resourcePr
// For now, end the deferral at this time. Once all the TextureSamplers are swapped over
// to taking a GrSurfaceProxy just use the IORefs on the proxy
- GrTexture* texture = proxy->instantiate(resourceProvider);
+ GrTexture* texture = proxy->instantiateTexture(resourceProvider);
if (texture) {
fTexture.set(SkRef(texture), kRead_GrIOType);
SkASSERT(texture->texturePriv().highestFilterMode() == proxy->highestFilterMode());
@@ -267,7 +267,7 @@ void GrResourceIOProcessor::TextureSampler::reset(GrResourceProvider* resourcePr
GrShaderFlags visibility) {
// For now, end the deferral at this time. Once all the TextureSamplers are swapped over
// to taking a GrSurfaceProxy just use the IORefs on the proxy
- GrTexture* texture = proxy->instantiate(resourceProvider);
+ GrTexture* texture = proxy->instantiateTexture(resourceProvider);
if (texture) {
fTexture.set(SkRef(texture), kRead_GrIOType);
SkASSERT(texture->texturePriv().highestFilterMode() == proxy->highestFilterMode());
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 0076812845..e58b4bb06e 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -226,10 +226,8 @@ void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor
AutoCheckFlush acf(fRenderTargetContext->drawingManager());
- SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(
- *fRenderTargetContext->caps()),
- fRenderTargetContext->fRenderTargetProxy->worstCaseHeight(
- *fRenderTargetContext->caps()));
+ SkIRect rtRect = SkIRect::MakeWH(fRenderTargetContext->fRenderTargetProxy->worstCaseWidth(),
+ fRenderTargetContext->fRenderTargetProxy->worstCaseHeight());
if (clearRect) {
if (clearRect->contains(rtRect)) {
@@ -1677,7 +1675,8 @@ bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const
if (this->caps()->textureBarrierSupport()) {
if (GrTextureProxy* texProxy = rtProxy->asTextureProxy()) {
// MDB TODO: remove this instantiation. Blocked on making DstTexture be proxy-based
- sk_sp<GrTexture> tex(sk_ref_sp(texProxy->instantiate(fContext->resourceProvider())));
+ sk_sp<GrTexture> tex(
+ sk_ref_sp(texProxy->instantiateTexture(fContext->resourceProvider())));
if (!tex) {
SkDebugf("setupDstTexture: instantiation of src texture failed.\n");
return false; // We have bigger problems now
@@ -1754,7 +1753,7 @@ bool GrRenderTargetContext::setupDstTexture(GrRenderTargetProxy* rtProxy, const
GrTextureProxy* copyProxy = sContext->asTextureProxy();
// MDB TODO: remove this instantiation once DstTexture is proxy-backed
- sk_sp<GrTexture> copy(sk_ref_sp(copyProxy->instantiate(fContext->resourceProvider())));
+ sk_sp<GrTexture> copy(sk_ref_sp(copyProxy->instantiateTexture(fContext->resourceProvider())));
if (!copy) {
SkDebugf("setupDstTexture: instantiation of copied texture failed.\n");
return false;
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index a749046d24..0f9e530b83 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -361,7 +361,7 @@ public:
GrRenderTarget* accessRenderTarget() {
// TODO: usage of this entry point needs to be reduced and potentially eliminated
// since it ends the deferral of the GrRenderTarget's allocation
- return fRenderTargetProxy->instantiate(fContext->resourceProvider());
+ return fRenderTargetProxy->instantiateRenderTarget(fContext->resourceProvider());
}
GrSurfaceProxy* asSurfaceProxy() override { return fRenderTargetProxy.get(); }
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 44f23d484b..099f7e5f8d 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -13,17 +13,19 @@
#include "GrRenderTargetPriv.h"
#include "GrResourceProvider.h"
#include "GrTextureRenderTargetProxy.h"
+#include "SkMathPriv.h"
// Deferred version
// TODO: we can probably munge the 'desc' in both the wrapped and deferred
// cases to make the sampleConfig/numSamples stuff more rational.
GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
- : INHERITED(desc, fit, budgeted, flags)
- , fRenderTargetFlags(GrRenderTarget::Flags::kNone) {
+ : INHERITED(desc, fit, budgeted, flags)
+ , fSampleCnt(desc.fSampleCnt)
+ , fRenderTargetFlags(GrRenderTarget::Flags::kNone) {
// Since we know the newly created render target will be internal, we are able to precompute
// what the flags will ultimately end up being.
- if (caps.usesMixedSamples() && fDesc.fSampleCnt > 0) {
+ if (caps.usesMixedSamples() && fSampleCnt > 0) {
fRenderTargetFlags |= GrRenderTarget::Flags::kMixedSampled;
}
if (caps.maxWindowRectangles() > 0) {
@@ -33,9 +35,9 @@ GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc
// Wrapped version
GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
- : INHERITED(std::move(surf), SkBackingFit::kExact)
- , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
-}
+ : INHERITED(std::move(surf), SkBackingFit::kExact)
+ , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples())
+ , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {}
int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
return (fRenderTargetFlags & GrRenderTarget::Flags::kWindowRectsSupport)
@@ -43,27 +45,48 @@ int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
: 0;
}
-GrRenderTarget* GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
- SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
+GrSurface* GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
+ static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
- GrSurface* surf = INHERITED::instantiate(resourceProvider);
- if (!surf || !surf->asRenderTarget()) {
+ GrSurface* surf = this->instantiateImpl(resourceProvider, fSampleCnt, kFlags,
+ /* isMipped = */ false);
+ if (!surf) {
return nullptr;
}
-
+ SkASSERT(surf->asRenderTarget());
// Check that our a priori computation matched the ultimate reality
SkASSERT(fRenderTargetFlags == surf->asRenderTarget()->renderTargetPriv().flags());
- return surf->asRenderTarget();
+ return surf;
}
-size_t GrRenderTargetProxy::onGpuMemorySize() const {
+int GrRenderTargetProxy::worstCaseWidth() const {
if (fTarget) {
- return fTarget->gpuMemorySize();
+ return fTarget->width();
+ }
+
+ if (SkBackingFit::kExact == fFit) {
+ return fWidth;
}
+ return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fWidth));
+}
+
+int GrRenderTargetProxy::worstCaseHeight() const {
+ if (fTarget) {
+ return fTarget->height();
+ }
+
+ if (SkBackingFit::kExact == fFit) {
+ return fHeight;
+ }
+ return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fHeight));
+}
+size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
+ int colorSamplesPerPixel = this->numColorSamples() + 1;
// TODO: do we have enough information to improve this worst case estimate?
- return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit);
+ return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, false,
+ SkBackingFit::kApprox == fFit);
}
bool GrRenderTargetProxy::refsWrappedObjects() const {
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index ad92abfb77..a46ecb63dd 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -293,7 +293,7 @@ void GrResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextur
return;
}
- GrTexture* texture = proxy->instantiate(this);
+ GrTexture* texture = proxy->instantiateTexture(this);
if (!texture) {
return;
}
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index aae3f23362..26584285b8 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -51,20 +51,22 @@ size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2) {
return size;
}
-size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc,
+size_t GrSurface::ComputeSize(GrPixelConfig config,
+ int width,
+ int height,
int colorSamplesPerPixel,
bool hasMIPMaps,
bool useNextPow2) {
size_t colorSize;
- int width = useNextPow2 ? GrNextPow2(desc.fWidth) : desc.fWidth;
- int height = useNextPow2 ? GrNextPow2(desc.fHeight) : desc.fHeight;
+ width = useNextPow2 ? GrNextPow2(width) : width;
+ height = useNextPow2 ? GrNextPow2(height) : height;
- SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
- if (GrPixelConfigIsCompressed(desc.fConfig)) {
- colorSize = GrCompressedFormatDataSize(desc.fConfig, width, height);
+ SkASSERT(kUnknown_GrPixelConfig != config);
+ if (GrPixelConfigIsCompressed(config)) {
+ colorSize = GrCompressedFormatDataSize(config, width, height);
} else {
- colorSize = (size_t) width * height * GrBytesPerPixel(desc.fConfig);
+ colorSize = (size_t)width * height * GrBytesPerPixel(config);
}
SkASSERT(colorSize > 0);
@@ -75,8 +77,6 @@ size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc,
// we'd expect because we never change fDesc.fWidth/fHeight.
finalSize += colorSize/3;
}
-
- SkASSERT(finalSize <= WorstCaseSize(desc, useNextPow2));
return finalSize;
}
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 43a650fb4e..a9abb16ea9 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -21,15 +21,17 @@
#include "SkMathPriv.h"
GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, SkBackingFit fit)
- : INHERITED(std::move(surface))
- , fDesc(fTarget->desc())
- , fFit(fit)
- , fBudgeted(fTarget->resourcePriv().isBudgeted())
- , fFlags(0)
- , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID!
- , fGpuMemorySize(kInvalidGpuMemorySize)
- , fLastOpList(nullptr) {
-}
+ : INHERITED(std::move(surface))
+ , fConfig(fTarget->config())
+ , fWidth(fTarget->width())
+ , fHeight(fTarget->height())
+ , fOrigin(fTarget->origin())
+ , fFit(fit)
+ , fBudgeted(fTarget->resourcePriv().isBudgeted())
+ , fFlags(0)
+ , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID!
+ , fGpuMemorySize(kInvalidGpuMemorySize)
+ , fLastOpList(nullptr) {}
GrSurfaceProxy::~GrSurfaceProxy() {
// For this to be deleted the opList that held a ref on it (if there was one) must have been
@@ -37,15 +39,24 @@ GrSurfaceProxy::~GrSurfaceProxy() {
SkASSERT(!fLastOpList);
}
-GrSurface* GrSurfaceProxy::instantiate(GrResourceProvider* resourceProvider) {
+GrSurface* GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
+ GrSurfaceFlags flags, bool isMipMapped) {
if (fTarget) {
return fTarget;
}
+ GrSurfaceDesc desc;
+ desc.fConfig = fConfig;
+ desc.fWidth = fWidth;
+ desc.fHeight = fHeight;
+ desc.fOrigin = fOrigin;
+ desc.fSampleCnt = sampleCnt;
+ desc.fIsMipMapped = isMipMapped;
+ desc.fFlags = flags;
if (SkBackingFit::kApprox == fFit) {
- fTarget = resourceProvider->createApproxTexture(fDesc, fFlags);
+ fTarget = resourceProvider->createApproxTexture(desc, fFlags);
} else {
- fTarget = resourceProvider->createTexture(fDesc, fBudgeted, fFlags).release();
+ fTarget = resourceProvider->createTexture(desc, fBudgeted, fFlags).release();
}
if (!fTarget) {
return nullptr;
@@ -63,38 +74,6 @@ GrSurface* GrSurfaceProxy::instantiate(GrResourceProvider* resourceProvider) {
return fTarget;
}
-int GrSurfaceProxy::worstCaseWidth(const GrCaps& caps) const {
- if (fTarget) {
- return fTarget->width();
- }
-
- if (SkBackingFit::kExact == fFit) {
- return fDesc.fWidth;
- }
-
- if (caps.reuseScratchTextures() || fDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
- return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fDesc.fWidth));
- }
-
- return fDesc.fWidth;
-}
-
-int GrSurfaceProxy::worstCaseHeight(const GrCaps& caps) const {
- if (fTarget) {
- return fTarget->height();
- }
-
- if (SkBackingFit::kExact == fFit) {
- return fDesc.fHeight;
- }
-
- if (caps.reuseScratchTextures() || fDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
- return SkTMax(GrResourceProvider::kMinScratchTextureSize, GrNextPow2(fDesc.fHeight));
- }
-
- return fDesc.fHeight;
-}
-
void GrSurfaceProxy::setLastOpList(GrOpList* opList) {
#ifdef SK_DEBUG
if (fLastOpList) {
@@ -303,8 +282,8 @@ void GrSurfaceProxyPriv::exactify() {
// obliterating the area of interest information. This call (exactify) only used
// when converting an SkSpecialImage to an SkImage so the proxy shouldn't be
// used for additional draws.
- fProxy->fDesc.fWidth = fProxy->fTarget->width();
- fProxy->fDesc.fHeight = fProxy->fTarget->height();
+ fProxy->fWidth = fProxy->fTarget->width();
+ fProxy->fHeight = fProxy->fTarget->height();
return;
}
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 6609fa61e3..0aa1ac07a6 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -36,7 +36,8 @@ void GrTexture::dirtyMipMaps(bool mipMapsDirty) {
}
size_t GrTexture::onGpuMemorySize() const {
- return GrSurface::ComputeSize(fDesc, 1, this->texturePriv().hasMipMaps());
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
+ this->texturePriv().hasMipMaps(), false);
}
void GrTexture::validateDesc() const {
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 7557712c12..7ecd50bee8 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -12,21 +12,23 @@
GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
const void* srcData, size_t /*rowBytes*/, uint32_t flags)
- : INHERITED(srcDesc, fit, budgeted, flags) {
- SkASSERT(!srcData); // currently handled in Make()
+ : INHERITED(srcDesc, fit, budgeted, flags)
+ , fIsMipMapped(srcDesc.fIsMipMapped) {
+ SkASSERT(!srcData); // currently handled in Make()
}
GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
- : INHERITED(std::move(surf), SkBackingFit::kExact) {
-}
+ : INHERITED(std::move(surf), SkBackingFit::kExact)
+ , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps()) {}
-GrTexture* GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
- GrSurface* surf = this->INHERITED::instantiate(resourceProvider);
+GrSurface* GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
+ GrSurface* surf =
+ this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped);
if (!surf) {
return nullptr;
}
-
- return fTarget->asTexture();
+ SkASSERT(surf->asTexture());
+ return surf;
}
void GrTextureProxy::setMipColorMode(SkDestinationSurfaceColorMode colorMode) {
@@ -56,12 +58,10 @@ GrSamplerParams::FilterMode GrTextureProxy::highestFilterMode() const {
return GrSamplerParams::kMipMap_FilterMode;
}
-size_t GrTextureProxy::onGpuMemorySize() const {
- if (fTarget) {
- return fTarget->gpuMemorySize();
- }
-
+size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
static const bool kHasMipMaps = true;
- // TODO: add tracking of mipmap state to improve the estimate
- return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps, SkBackingFit::kApprox == fFit);
+ // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
+ // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
+ return GrSurface::ComputeSize(fConfig, fWidth, fHeight, 1, kHasMipMaps,
+ SkBackingFit::kApprox == fFit);
}
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index 432d00854f..4f1c420830 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -32,12 +32,28 @@ GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf)
SkASSERT(surf->asRenderTarget());
}
-size_t GrTextureRenderTargetProxy::onGpuMemorySize() const {
- if (fTarget) {
- return fTarget->gpuMemorySize();
- }
+size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
+ int colorSamplesPerPixel = this->numColorSamples() + 1;
+
+ static const bool kHasMipMaps = true;
+ // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
+ // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
// TODO: do we have enough information to improve this worst case estimate?
- return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, true, SkBackingFit::kApprox == fFit);
+ return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, kHasMipMaps,
+ SkBackingFit::kApprox == fFit);
}
+GrSurface* GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
+ static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
+
+ GrSurface* surf = this->instantiateImpl(resourceProvider, this->numStencilSamples(), kFlags,
+ this->isMipMapped());
+ if (!surf) {
+ return nullptr;
+ }
+ SkASSERT(surf->asRenderTarget());
+ SkASSERT(surf->asTexture());
+
+ return surf;
+}
diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h
index 09aef756e1..992e319770 100644
--- a/src/gpu/GrTextureRenderTargetProxy.h
+++ b/src/gpu/GrTextureRenderTargetProxy.h
@@ -32,7 +32,9 @@ private:
// Wrapped version
GrTextureRenderTargetProxy(sk_sp<GrSurface>);
- size_t onGpuMemorySize() const override;
+ GrSurface* instantiate(GrResourceProvider*) override;
+
+ size_t onUninstantiatedGpuMemorySize() const override;
};
#ifdef SK_BUILD_FOR_WIN
diff --git a/src/gpu/effects/GrSimpleTextureEffect.h b/src/gpu/effects/GrSimpleTextureEffect.h
index 7d5232c3e0..8e0e4b0fb1 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.h
+++ b/src/gpu/effects/GrSimpleTextureEffect.h
@@ -28,7 +28,7 @@ public:
// MDB TODO: remove this instantiation once instantiation is pushed past the
// TextureSamplers. Instantiation failure in the TextureSampler is difficult to
// recover from.
- GrTexture* temp = proxy->instantiate(resourceProvider);
+ GrTexture* temp = proxy->instantiateTexture(resourceProvider);
if (!temp) {
return nullptr;
}
@@ -48,7 +48,7 @@ public:
// MDB TODO: remove this instantiation once instantiation is pushed past the
// TextureSamplers. Instantiation failure in the TextureSampler is difficult to
// recover from.
- GrTexture* temp = proxy->instantiate(resourceProvider);
+ GrTexture* temp = proxy->instantiateTexture(resourceProvider);
if (!temp) {
return nullptr;
}
@@ -67,7 +67,7 @@ public:
// MDB TODO: remove this instantiation once instantiation is pushed past the
// TextureSamplers. Instantiation failure in the TextureSampler is difficult to
// recover from.
- GrTexture* temp = proxy->instantiate(resourceProvider);
+ GrTexture* temp = proxy->instantiateTexture(resourceProvider);
if (!temp) {
return nullptr;
}
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 09c2851d56..7d45ceb619 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -83,7 +83,8 @@ sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
}
size_t GrGLRenderTarget::onGpuMemorySize() const {
- return GrSurface::ComputeSize(fDesc, fNumSamplesOwnedPerPixel, false);
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
+ fNumSamplesOwnedPerPixel, false);
}
bool GrGLRenderTarget::completeStencilAttachment() {
@@ -188,7 +189,8 @@ void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
// Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer
// (have a fMSColorRenderbufferID).
if (fMSColorRenderbufferID) {
- size_t size = GrSurface::ComputeSize(fDesc, this->msaaSamples(), false);
+ size_t size = GrSurface::ComputeSize(this->config(), this->width(), this->height(),
+ this->msaaSamples(), false);
// Due to this resource having both a texture and a renderbuffer component, dump as
// skia/gpu_resources/resource_#/renderbuffer
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 7ff8d490e0..0d3b19daed 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -70,7 +70,7 @@ private:
}
size_t onGpuMemorySize() const override {
- return GrSurface::ComputeSize(fDesc,
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
this->numSamplesOwnedPerPixel(),
this->texturePriv().hasMipMaps());
}
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index cf425fb0a2..272998e317 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -100,7 +100,9 @@ protected:
size_t onGpuMemorySize() const override {
// The plus 1 is to account for the resolve texture.
// TODO: is this still correct?
- return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
+ int numColorSamples = this->numColorSamples() + 1;
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
+ numColorSamples, false);
}
void createFramebuffer(GrVkGpu* gpu);
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index 2877a36265..03f9fdbbb1 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -115,7 +115,9 @@ private:
// GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
size_t onGpuMemorySize() const override {
// The plus 1 is to account for the resolve texture.
- return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, // TODO: this still correct?
+ int numColorSamples = this->numColorSamples() + 1;
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
+ numColorSamples, // TODO: this still correct?
this->texturePriv().hasMipMaps());
}
};