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>
inline const GrSurfacePriv surfacePriv() const;
static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
- static size_t ComputeSize(const GrSurfaceDesc& desc, int colorSamplesPerPixel,
+ static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
bool hasMIPMaps, bool useNextPow2 = false);
protected:
const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
// Actually instantiate the backing rendertarget, if necessary.
- GrRenderTarget* instantiate(GrResourceProvider* resourceProvider);
-
- /**
- * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
- */
- int numStencilSamples() const { return fDesc.fSampleCnt; }
+ GrSurface* instantiate(GrResourceProvider* resourceProvider) override;
+ GrRenderTarget* instantiateRenderTarget(GrResourceProvider* resourceProvider) {
+ if (auto surf = this->instantiate(resourceProvider)) {
+ return surf->asRenderTarget();
+ }
+ return nullptr;
+ }
GrFSAAType fsaaType() const {
- if (!fDesc.fSampleCnt) {
+ if (!fSampleCnt) {
SkASSERT(!(fRenderTargetFlags & GrRenderTarget::Flags::kMixedSampled));
return GrFSAAType::kNone;
}
? GrFSAAType::kMixedSamples
: GrFSAAType::kUnifiedMSAA;
}
+
+ /**
+ * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
+ */
+ int numStencilSamples() const { return fSampleCnt; }
+
/**
* Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled).
*/
int numColorSamples() const {
- return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fDesc.fSampleCnt;
+ return GrFSAAType::kMixedSamples == this->fsaaType() ? 0 : fSampleCnt;
}
+ int worstCaseWidth() const;
+
+ int worstCaseHeight() const;
+
int maxWindowRectangles(const GrCaps& caps) const;
GrRenderTarget::Flags testingOnly_getFlags() const;
GrRenderTargetProxy(sk_sp<GrSurface>);
private:
- size_t onGpuMemorySize() const override;
+ size_t onUninstantiatedGpuMemorySize() const override;
+ int fSampleCnt;
// 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.
static sk_sp<GrTextureProxy> MakeWrappedBackend(GrContext*, GrBackendTexture&, GrSurfaceOrigin);
GrSurfaceOrigin origin() const {
- SkASSERT(kTopLeft_GrSurfaceOrigin == fDesc.fOrigin ||
- kBottomLeft_GrSurfaceOrigin == fDesc.fOrigin);
- return fDesc.fOrigin;
+ SkASSERT(kTopLeft_GrSurfaceOrigin == fOrigin || kBottomLeft_GrSurfaceOrigin == fOrigin);
+ return fOrigin;
}
- int width() const { return fDesc.fWidth; }
- int height() const { return fDesc.fHeight; }
- GrPixelConfig config() const { return fDesc.fConfig; }
- bool isMipMapped() const { return fDesc.fIsMipMapped; }
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+ GrPixelConfig config() const { return fConfig; }
class UniqueID {
public:
*/
UniqueID uniqueID() const { return fUniqueID; }
- GrSurface* instantiate(GrResourceProvider* resourceProvider);
+ virtual GrSurface* instantiate(GrResourceProvider* resourceProvider) = 0;
/**
* Helper that gets the width and height of the surface as a bounding rectangle.
*/
SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
- int worstCaseWidth(const GrCaps& caps) const;
- int worstCaseHeight(const GrCaps& caps) const;
-
/**
* @return the texture proxy associated with the surface proxy, may be NULL.
*/
* @return the amount of GPU memory used in bytes
*/
size_t gpuMemorySize() const {
+ if (fTarget) {
+ return fTarget->gpuMemorySize();
+ }
if (kInvalidGpuMemorySize == fGpuMemorySize) {
- fGpuMemorySize = this->onGpuMemorySize();
+ fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
}
return fGpuMemorySize;
protected:
// Deferred version
GrSurfaceProxy(const GrSurfaceDesc& desc, SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
- : fDesc(desc)
- , fFit(fit)
- , fBudgeted(budgeted)
- , fFlags(flags)
- // fMipColorMode is only valid for texturable proxies
- , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy)
- , fGpuMemorySize(kInvalidGpuMemorySize)
- , fLastOpList(nullptr) {
+ : fConfig(desc.fConfig)
+ , fWidth(desc.fWidth)
+ , fHeight(desc.fHeight)
+ , fOrigin(desc.fOrigin)
+ , fFit(fit)
+ , fBudgeted(budgeted)
+ , fFlags(flags)
+ // fMipColorMode is only valid for texturable proxies
+ , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy)
+ , fGpuMemorySize(kInvalidGpuMemorySize)
+ , fLastOpList(nullptr) {
// Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
}
return this->internalHasPendingWrite();
}
- // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
- GrSurfaceDesc fDesc;
+ GrSurface* instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
+ GrSurfaceFlags flags, bool isMipMapped);
+
+ // For wrapped resources, 'fConfig', 'fWidth', 'fHeight', and 'fOrigin; will always be filled in
+ // from the wrapped resource.
+ GrPixelConfig fConfig;
+ int fWidth;
+ int fHeight;
+ GrSurfaceOrigin fOrigin;
SkBackingFit fFit; // always exact for wrapped resources
mutable SkBudgeted fBudgeted; // set from the backing resource for wrapped resources
// mutable bc of SkSurface/SkImage wishy-washiness
SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
private:
- virtual size_t onGpuMemorySize() const = 0;
+ virtual size_t onUninstantiatedGpuMemorySize() const = 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.
const GrTextureProxy* asTextureProxy() const override { return this; }
// Actually instantiate the backing texture, if necessary
- GrTexture* instantiate(GrResourceProvider*);
+ GrSurface* instantiate(GrResourceProvider*) override;
+ GrTexture* instantiateTexture(GrResourceProvider* resourceProvider) {
+ if (auto surf = this->instantiate(resourceProvider)) {
+ return surf->asTexture();
+ }
+ return nullptr;
+ }
void setMipColorMode(SkDestinationSurfaceColorMode colorMode);
}
}
+ bool isMipMapped() const { return fIsMipMapped; }
+
protected:
friend class GrSurfaceProxy; // for ctors
GrTextureProxy(sk_sp<GrSurface>);
private:
- size_t onGpuMemorySize() const override;
+ bool fIsMipMapped;
+
+ size_t onUninstantiatedGpuMemorySize() const override;
// For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
// For deferred proxies that pointer will be filled in when we need to instantiate
// Chrome is crashing with proxies when they need to be instantiated.
// Force an instantiation here (where, in olden days, we used to require a GrTexture)
// to see if the input is already un-instantiable.
- GrTexture* temp = srcProxy->instantiate(context->resourceProvider());
+ GrTexture* temp = srcProxy->instantiateTexture(context->resourceProvider());
if (!temp) {
return nullptr;
}
if (tempProxy->priv().hasPendingIO()) {
this->flush(tempProxy.get());
}
- GrTexture* texture = tempProxy->instantiate(fContext->resourceProvider());
+ GrTexture* texture = tempProxy->instantiateTexture(fContext->resourceProvider());
if (!texture) {
return false;
}
// 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();
}
// 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;
}
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;
}
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;
}
// 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());
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());
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)) {
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
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;
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(); }
#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) {
// 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)
: 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 {
return;
}
- GrTexture* texture = proxy->instantiate(this);
+ GrTexture* texture = proxy->instantiateTexture(this);
if (!texture) {
return;
}
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);
// we'd expect because we never change fDesc.fWidth/fHeight.
finalSize += colorSize/3;
}
-
- SkASSERT(finalSize <= WorstCaseSize(desc, useNextPow2));
return finalSize;
}
#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
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;
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) {
// 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;
}
}
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 {
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) {
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);
}
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;
+}
// 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
// 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;
}
// 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;
}
// 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;
}
}
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() {
// 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
}
size_t onGpuMemorySize() const override {
- return GrSurface::ComputeSize(fDesc,
+ return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
this->numSamplesOwnedPerPixel(),
this->texturePriv().hasMipMaps());
}
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);
// 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());
}
};
return nullptr;
}
- return proxy->instantiate(fContext->resourceProvider());
+ return proxy->instantiateTexture(fContext->resourceProvider());
}
bool SkImage_Gpu::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
return codecImage;
}
- sk_sp<GrTexture> texture(sk_ref_sp(proxy->instantiate(context->resourceProvider())));
+ sk_sp<GrTexture> texture(sk_ref_sp(proxy->instantiateTexture(context->resourceProvider())));
if (!texture) {
return codecImage;
}
return fProxy.get();
}
GrTexture* peekTexture() const override {
- return fProxy->instantiate(fContext->resourceProvider());
+ return fProxy->instantiateTexture(fContext->resourceProvider());
}
sk_sp<GrTextureProxy> asTextureProxyRef() const override {
return fProxy;
stack.save();
stack.clipPath(path, m, SkClipOp::kIntersect, true);
sk_sp<GrTextureProxy> mask = GrClipStackClip(&stack).testingOnly_createClipMask(context);
- GrTexture* tex = mask->instantiate(context->resourceProvider());
+ GrTexture* tex = mask->instantiateTexture(context->resourceProvider());
REPORTER_ASSERT(reporter, 0 == strcmp(tex->getUniqueKey().tag(), kTag));
// Make sure mask isn't pinned in cache.
mask.reset(nullptr);
return;
}
- GrTexture* tex = srcProxy->instantiate(context->resourceProvider());
+ GrTexture* tex = srcProxy->instantiateTexture(context->resourceProvider());
if (!tex) {
return;
}
REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
- GrRenderTarget* rt = rtProxy->instantiate(provider);
+ GrRenderTarget* rt = rtProxy->instantiateRenderTarget(provider);
REPORTER_ASSERT(reporter, rt);
REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
SkBackingFit fit,
bool wasWrapped) {
GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
- GrTexture* tex = texProxy->instantiate(provider);
+ GrTexture* tex = texProxy->instantiateTexture(provider);
REPORTER_ASSERT(reporter, tex);
REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);