Remove uses of GrPixelConfig version of GrBytesPerPixel.
Bug: skia:6718
Change-Id: I8421f38644567973f0b8de29b745ca9a471583bf
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247598
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 23cb69f..4051954 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -364,9 +364,6 @@
void storeVkPipelineCacheData();
- static size_t ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped,
- bool useNextPow2 = false);
-
// Returns the gpu memory size of the the texture that backs the passed in SkImage. Returns 0 if
// the SkImage is not texture backed.
static size_t ComputeImageSize(sk_sp<SkImage> image, GrMipMapped, bool useNextPow2 = false);
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 03aaf82..0a97637 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -75,7 +75,8 @@
inline GrSurfacePriv surfacePriv();
inline const GrSurfacePriv surfacePriv() const;
- static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
+ static size_t ComputeSize(GrPixelConfig config, const GrCaps&, const GrBackendFormat&,
+ int width, int height, int colorSamplesPerPixel,
GrMipMapped, bool binSize = false);
/**
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 0876d7e..5ef77ab 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -813,43 +813,6 @@
SkUNREACHABLE;
}
-static constexpr size_t GrBytesPerPixel(GrPixelConfig config) {
- switch (config) {
- case kAlpha_8_GrPixelConfig:
- case kAlpha_8_as_Alpha_GrPixelConfig:
- case kAlpha_8_as_Red_GrPixelConfig:
- case kGray_8_GrPixelConfig:
- case kGray_8_as_Lum_GrPixelConfig:
- case kGray_8_as_Red_GrPixelConfig:
- return 1;
- case kRGB_565_GrPixelConfig:
- case kRGBA_4444_GrPixelConfig:
- case kRG_88_GrPixelConfig:
- case kAlpha_half_GrPixelConfig:
- case kAlpha_half_as_Lum_GrPixelConfig:
- case kAlpha_half_as_Red_GrPixelConfig:
- case kAlpha_16_GrPixelConfig:
- return 2;
- case kRGBA_8888_GrPixelConfig:
- case kRGB_888_GrPixelConfig: // Assuming GPUs store this 4-byte aligned.
- case kRGB_888X_GrPixelConfig:
- case kBGRA_8888_GrPixelConfig:
- case kSRGBA_8888_GrPixelConfig:
- case kRGBA_1010102_GrPixelConfig:
- case kRG_1616_GrPixelConfig:
- case kRG_half_GrPixelConfig:
- return 4;
- case kRGBA_half_GrPixelConfig:
- case kRGBA_half_Clamped_GrPixelConfig:
- case kRGBA_16161616_GrPixelConfig:
- return 8;
- case kUnknown_GrPixelConfig:
- case kRGB_ETC1_GrPixelConfig:
- return 0;
- }
- SkUNREACHABLE;
-}
-
static constexpr bool GrPixelConfigIsOpaque(GrPixelConfig config) {
switch (config) {
case kRGB_565_GrPixelConfig:
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 9731e85..8995196 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -399,7 +399,9 @@
SkColorType colorType() const override { return GrColorTypeToSkColorType(fColorType); }
- size_t getSize() const override { return fTextureProxy->gpuMemorySize(); }
+ size_t getSize() const override {
+ return fTextureProxy->gpuMemorySize(*fContext->priv().caps());
+ }
void onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) const override {
SkRect dst = SkRect::MakeXYWH(x, y,
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index 23e690d..2f06f38 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -193,6 +193,10 @@
// For historical reasons requestedCount==0 is handled identically to requestedCount==1.
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const = 0;
+ // Returns the number of bytes per pixel for the given GrBackendFormat. This is only supported
+ // for "normal" formats. For compressed formats this will return 0.
+ virtual size_t bytesPerPixel(const GrBackendFormat&) const = 0;
+
/**
* Backends may have restrictions on what types of surfaces support GrGpu::writePixels().
* If this returns false then the caller should implement a fallback where a temporary texture
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index f729d09..de0f353 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -14,6 +14,7 @@
#include "src/core/SkMakeUnique.h"
#include "src/core/SkTaskGroup.h"
#include "src/gpu/GrClientMappedBufferManager.h"
+#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrDrawingManager.h"
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrMemoryPool.h"
@@ -31,6 +32,7 @@
#include "src/gpu/effects/GrSkSLFP.h"
#include "src/gpu/text/GrTextBlobCache.h"
#include "src/gpu/text/GrTextContext.h"
+#include "src/image/SkImage_GpuBase.h"
#include "src/image/SkSurface_Gpu.h"
#include <atomic>
@@ -232,20 +234,21 @@
return fResourceCache->getPurgeableBytes();
}
-size_t GrContext::ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped mipMapped,
- bool useNextPow2) {
- int colorSamplesPerPixel = 1;
- return GrSurface::ComputeSize(SkColorType2GrPixelConfig(type), width, height,
- colorSamplesPerPixel, mipMapped, useNextPow2);
-}
-
size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipMapped mipMapped, bool useNextPow2) {
if (!image->isTextureBacked()) {
return 0;
}
+ SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
+ GrTextureProxy* proxy = gpuImage->peekProxy();
+ if (!proxy) {
+ return 0;
+ }
+
+ const GrCaps& caps = *gpuImage->context()->priv().caps();
int colorSamplesPerPixel = 1;
- return GrSurface::ComputeSize(SkColorType2GrPixelConfig(image->colorType()), image->width(),
- image->height(), colorSamplesPerPixel, mipMapped, useNextPow2);
+ return GrSurface::ComputeSize(SkColorType2GrPixelConfig(image->colorType()), caps,
+ proxy->backendFormat(), image->width(), image->height(),
+ colorSamplesPerPixel, mipMapped, useNextPow2);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrDrawOpAtlas.cpp b/src/gpu/GrDrawOpAtlas.cpp
index 1f4bb38..b41d34b 100644
--- a/src/gpu/GrDrawOpAtlas.cpp
+++ b/src/gpu/GrDrawOpAtlas.cpp
@@ -10,11 +10,13 @@
#include "include/gpu/GrContext.h"
#include "include/gpu/GrTexture.h"
#include "src/gpu/GrContextPriv.h"
+#include "src/gpu/GrGpu.h"
#include "src/gpu/GrOnFlushResourceProvider.h"
#include "src/gpu/GrOpFlushState.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRectanizer.h"
#include "src/gpu/GrResourceProvider.h"
+#include "src/gpu/GrResourceProviderPriv.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTracing.h"
@@ -237,8 +239,9 @@
return true;
}
-bool GrDrawOpAtlas::uploadToPage(unsigned int pageIdx, AtlasID* id, GrDeferredUploadTarget* target,
- int width, int height, const void* image, SkIPoint16* loc) {
+bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, AtlasID* id,
+ GrDeferredUploadTarget* target, int width, int height,
+ const void* image, SkIPoint16* loc) {
SkASSERT(fProxies[pageIdx] && fProxies[pageIdx]->isInstantiated());
// look through all allocated plots for one we can share, in Most Recently Refed order
@@ -246,7 +249,7 @@
plotIter.init(fPages[pageIdx].fPlotList, PlotList::Iter::kHead_IterStart);
for (Plot* plot = plotIter.get(); plot; plot = plotIter.next()) {
- SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == plot->bpp());
+ SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == plot->bpp());
if (plot->addSubImage(width, height, image, loc)) {
return this->updatePlot(target, id, plot);
@@ -272,11 +275,13 @@
return ErrorCode::kError;
}
+ const GrCaps& caps = *resourceProvider->caps();
+
// Look through each page to see if we can upload without having to flush
// We prioritize this upload to the first pages, not the most recently used, to make it easier
// to remove unused pages in reverse page order.
for (unsigned int pageIdx = 0; pageIdx < fNumActivePages; ++pageIdx) {
- if (this->uploadToPage(pageIdx, id, target, width, height, image, loc)) {
+ if (this->uploadToPage(caps, pageIdx, id, target, width, height, image, loc)) {
return ErrorCode::kSucceeded;
}
}
@@ -292,7 +297,7 @@
SkASSERT(plot);
if (plot->lastUseToken() < target->tokenTracker()->nextTokenToFlush()) {
this->processEvictionAndResetRects(plot);
- SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == plot->bpp());
+ SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == plot->bpp());
SkDEBUGCODE(bool verify = )plot->addSubImage(width, height, image, loc);
SkASSERT(verify);
if (!this->updatePlot(target, id, plot)) {
@@ -307,7 +312,7 @@
return ErrorCode::kError;
}
- if (this->uploadToPage(fNumActivePages-1, id, target, width, height, image, loc)) {
+ if (this->uploadToPage(caps, fNumActivePages-1, id, target, width, height, image, loc)) {
return ErrorCode::kSucceeded;
} else {
// If we fail to upload to a newly activated page then something has gone terribly
@@ -347,7 +352,7 @@
newPlot.reset(plot->clone());
fPages[pageIdx].fPlotList.addToHead(newPlot.get());
- SkASSERT(GrBytesPerPixel(fProxies[pageIdx]->config()) == newPlot->bpp());
+ SkASSERT(caps.bytesPerPixel(fProxies[pageIdx]->backendFormat()) == newPlot->bpp());
SkDEBUGCODE(bool verify = )newPlot->addSubImage(width, height, image, loc);
SkASSERT(verify);
diff --git a/src/gpu/GrDrawOpAtlas.h b/src/gpu/GrDrawOpAtlas.h
index f488f6e..5056d68 100644
--- a/src/gpu/GrDrawOpAtlas.h
+++ b/src/gpu/GrDrawOpAtlas.h
@@ -372,8 +372,9 @@
// the front and remove from the back there is no need for MRU.
}
- bool uploadToPage(unsigned int pageIdx, AtlasID* id, GrDeferredUploadTarget* target,
- int width, int height, const void* image, SkIPoint16* loc);
+ bool uploadToPage(const GrCaps&, unsigned int pageIdx, AtlasID* id,
+ GrDeferredUploadTarget* target, int width, int height, const void* image,
+ SkIPoint16* loc);
bool createPages(GrProxyProvider*);
bool activateNewPage(GrResourceProvider*);
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 38bc067..bc4e147 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -119,7 +119,7 @@
return surface;
}
-size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
+size_t GrRenderTargetProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
int colorSamplesPerPixel = this->numSamples();
if (colorSamplesPerPixel > 1) {
// Add one for the resolve buffer.
@@ -127,8 +127,9 @@
}
// TODO: do we have enough information to improve this worst case estimate?
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- colorSamplesPerPixel, GrMipMapped::kNo, !this->priv().isExact());
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), colorSamplesPerPixel, GrMipMapped::kNo,
+ !this->priv().isExact());
}
bool GrRenderTargetProxy::refsWrappedObjects() const {
diff --git a/src/gpu/GrRenderTargetProxy.h b/src/gpu/GrRenderTargetProxy.h
index f0b8d27..d4fad64 100644
--- a/src/gpu/GrRenderTargetProxy.h
+++ b/src/gpu/GrRenderTargetProxy.h
@@ -151,7 +151,7 @@
}
bool canChangeStencilAttachment() const;
- size_t onUninstantiatedGpuMemorySize() const override;
+ size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
// WARNING: Be careful when adding or removing fields here. ASAN is likely to trigger warnings
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index 3144837..e8e2664 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -16,6 +16,8 @@
#include "src/gpu/SkGr.h"
size_t GrSurface::ComputeSize(GrPixelConfig config,
+ const GrCaps& caps,
+ const GrBackendFormat& format,
int width,
int height,
int colorSamplesPerPixel,
@@ -30,7 +32,7 @@
if (GrPixelConfigIsCompressed(config)) {
colorSize = GrCompressedFormatDataSize(config, width, height);
} else {
- colorSize = (size_t)width * height * GrBytesPerPixel(config);
+ colorSize = (size_t)width * height * caps.bytesPerPixel(format);
}
SkASSERT(colorSize > 0);
diff --git a/src/gpu/GrSurfaceProxy.h b/src/gpu/GrSurfaceProxy.h
index d2c6a98..2b7395b 100644
--- a/src/gpu/GrSurfaceProxy.h
+++ b/src/gpu/GrSurfaceProxy.h
@@ -273,13 +273,13 @@
*
* @return the amount of GPU memory used in bytes
*/
- size_t gpuMemorySize() const {
+ size_t gpuMemorySize(const GrCaps& caps) const {
SkASSERT(!this->isFullyLazy());
if (fTarget) {
return fTarget->gpuMemorySize();
}
if (kInvalidGpuMemorySize == fGpuMemorySize) {
- fGpuMemorySize = this->onUninstantiatedGpuMemorySize();
+ fGpuMemorySize = this->onUninstantiatedGpuMemorySize(caps);
SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
}
return fGpuMemorySize;
@@ -417,7 +417,7 @@
static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })
- virtual size_t onUninstantiatedGpuMemorySize() const = 0;
+ virtual size_t onUninstantiatedGpuMemorySize(const GrCaps&) const = 0;
bool fIgnoredByResourceAllocator = false;
GrProtected fIsProtected;
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index 18c4ec2..0c56a20 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -31,8 +31,9 @@
}
size_t GrTexture::onGpuMemorySize() const {
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
- this->texturePriv().mipMapped());
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), 1, this->texturePriv().mipMapped());
}
/////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 62a9e6e..3cfbccf 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -143,9 +143,10 @@
return fMipMapped;
}
-size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(), 1,
- this->proxyMipMapped(), !this->priv().isExact());
+size_t GrTextureProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), 1, this->proxyMipMapped(),
+ !this->priv().isExact());
}
bool GrTextureProxy::ProxiesAreCompatibleAsDynamicState(const GrTextureProxy* first,
diff --git a/src/gpu/GrTextureProxy.h b/src/gpu/GrTextureProxy.h
index f756c07..1718794 100644
--- a/src/gpu/GrTextureProxy.h
+++ b/src/gpu/GrTextureProxy.h
@@ -182,7 +182,7 @@
// point, the proxy is instantiated, and this data is used to perform an ASAP upload.
std::unique_ptr<GrDeferredProxyUploader> fDeferredUploader;
- size_t onUninstantiatedGpuMemorySize() const override;
+ size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
// Methods made available via GrTextureProxy::CacheAccess
void setUniqueKey(GrProxyProvider*, const GrUniqueKey&);
diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp
index bada555..e73fe15 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -106,7 +106,7 @@
}
}
-size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
+size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize(const GrCaps& caps) const {
int colorSamplesPerPixel = this->numSamples();
if (colorSamplesPerPixel > 1) {
// Add one to account for the resolve buffer.
@@ -114,8 +114,8 @@
}
// TODO: do we have enough information to improve this worst case estimate?
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- colorSamplesPerPixel, this->proxyMipMapped(),
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), colorSamplesPerPixel, this->proxyMipMapped(),
!this->priv().isExact());
}
diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h
index be86d35..46c273d 100644
--- a/src/gpu/GrTextureRenderTargetProxy.h
+++ b/src/gpu/GrTextureRenderTargetProxy.h
@@ -72,7 +72,7 @@
bool instantiate(GrResourceProvider*) override;
sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
- size_t onUninstantiatedGpuMemorySize() const override;
+ size_t onUninstantiatedGpuMemorySize(const GrCaps&) const override;
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
};
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 35b4723..e0b3414 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3922,6 +3922,15 @@
return count;
}
+size_t GrGLCaps::bytesPerPixel(GrGLFormat format) const {
+ return this->getFormatInfo(format).fBytesPerPixel;
+}
+
+size_t GrGLCaps::bytesPerPixel(const GrBackendFormat& format) const {
+ auto glFormat = format.asGLFormat();
+ return this->bytesPerPixel(glFormat);
+}
+
bool GrGLCaps::canFormatBeFBOColorAttachment(GrGLFormat format) const {
return SkToBool(this->getFormatInfo(format).fFlags & FormatInfo::kFBOColorAttachment_Flag);
}
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index 4ff695a..ac9aa17 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -133,6 +133,9 @@
}
int maxRenderTargetSampleCount(GrGLFormat) const;
+ size_t bytesPerPixel(GrGLFormat) const;
+ size_t bytesPerPixel(const GrBackendFormat&) const override;
+
bool isFormatCopyable(const GrBackendFormat&) const override;
bool canFormatBeFBOColorAttachment(GrGLFormat) const;
@@ -649,7 +652,7 @@
GrGLenum fDefaultExternalFormat = 0;
GrGLenum fDefaultExternalType = 0;
- // This value is only valid for regular formats. Planar and compressed formats will be 0.
+ // This value is only valid for regular formats. Compressed formats will be 0.
GrGLenum fBytesPerPixel = 0;
enum {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 713358b..09897a7 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -3620,7 +3620,7 @@
texels.append(mipLevelCount);
SkTArray<size_t> individualMipOffsets(mipLevelCount);
- size_t bytesPerPixel = GrBytesPerPixel(config);
+ size_t bytesPerPixel = this->glCaps().bytesPerPixel(glFormat);
size_t totalSize = GrComputeTightCombinedBufferSize(
bytesPerPixel, w, h, &individualMipOffsets, mipLevelCount);
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 5dc7e04..bd3188d 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -103,8 +103,9 @@
}
size_t GrGLRenderTarget::onGpuMemorySize() const {
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), fNumSamplesOwnedPerPixel, GrMipMapped::kNo);
}
bool GrGLRenderTarget::completeStencilAttachment() {
@@ -220,8 +221,10 @@
// Log any renderbuffer's contribution to memory.
if (fMSColorRenderbufferID) {
- size_t size = GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- this->msaaSamples(), GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ size_t size = GrSurface::ComputeSize(this->config(), caps, this->backendFormat(),
+ this->width(), this->height(), this->msaaSamples(),
+ GrMipMapped::kNo);
// 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.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index 9473c80..929d657 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -72,6 +72,8 @@
}
size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), this->numSamplesOwnedPerPixel(),
+ this->texturePriv().mipMapped());
}
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 9a6148cc..5f8201e 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -113,6 +113,10 @@
return this->maxRenderTargetSampleCount(format.asMockColorType());
}
+ size_t bytesPerPixel(const GrBackendFormat& format) const override {
+ return GrColorTypeBytesPerPixel(format.asMockColorType());
+ }
+
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
const GrBackendFormat& surfaceFormat,
GrColorType srcColorType) const override {
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index d624de6..f160ed6 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -102,8 +102,9 @@
// Add one to account for the resolve buffer.
++numColorSamples;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples, GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples, GrMipMapped::kNo);
}
GrBackendRenderTarget getBackendRenderTarget() const override {
@@ -186,8 +187,9 @@
// Add one to account for the resolve buffer.
++numColorSamples;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples,
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples,
this->texturePriv().mipMapped());
}
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index 4901c00..7b8f592 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -46,6 +46,7 @@
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
int maxRenderTargetSampleCount(MTLPixelFormat) const;
+ size_t bytesPerPixel(const GrBackendFormat&) const override;
size_t bytesPerPixel(MTLPixelFormat) const;
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
@@ -143,7 +144,7 @@
uint16_t fFlags = 0;
- // This value is only valid for regular formats. Planar and compressed formats will be 0.
+ // This value is only valid for regular formats. Compressed formats will be 0.
size_t fBytesPerPixel = 0;
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm
index 99eb547..a9b25a8 100644
--- a/src/gpu/mtl/GrMtlCaps.mm
+++ b/src/gpu/mtl/GrMtlCaps.mm
@@ -380,6 +380,11 @@
return 1 == requestedCount ? 1 : 0;
}
+size_t GrMtlCaps::bytesPerPixel(const GrBackendFormat& format) const {
+ MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format);
+ return this->bytesPerPixel(mtlFormat);
+}
+
size_t GrMtlCaps::bytesPerPixel(MTLPixelFormat format) const {
return this->getFormatInfo(format).fBytesPerPixel;
}
diff --git a/src/gpu/mtl/GrMtlRenderTarget.h b/src/gpu/mtl/GrMtlRenderTarget.h
index ba225d0..e6fb2c3 100644
--- a/src/gpu/mtl/GrMtlRenderTarget.h
+++ b/src/gpu/mtl/GrMtlRenderTarget.h
@@ -11,6 +11,7 @@
#include "src/gpu/GrRenderTarget.h"
#include "include/gpu/GrBackendSurface.h"
+#include "src/gpu/GrGpu.h"
#import <Metal/Metal.h>
@@ -61,8 +62,9 @@
if (numColorSamples > 1) {
++numColorSamples;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples, GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples, GrMipMapped::kNo);
}
id<MTLTexture> fColorTexture;
diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.h b/src/gpu/mtl/GrMtlTextureRenderTarget.h
index 0340e53..49ba730 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.h
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.h
@@ -77,8 +77,9 @@
if (numColorSamples > 1) {
++numColorSamples;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples, GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples, GrMipMapped::kNo);
}
};
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 7092cbb..f465414 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -1048,7 +1048,10 @@
{
constexpr VkFormat format = VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM;
auto& info = this->getFormatInfo(format);
- info.fBytesPerPixel = 0;
+ // Currently we are just over estimating this value to be used in gpu size calculations even
+ // though the actually size is probably less. We should instead treat planar formats similar
+ // to compressed textures that go through their own special query for calculating size.
+ info.fBytesPerPixel = 3;
if (fSupportsYcbcrConversion) {
info.init(interface, physDev, properties, format);
}
@@ -1069,7 +1072,10 @@
{
constexpr VkFormat format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
auto& info = this->getFormatInfo(format);
- info.fBytesPerPixel = 0;
+ // Currently we are just over estimating this value to be used in gpu size calculations even
+ // though the actually size is probably less. We should instead treat planar formats similar
+ // to compressed textures that go through their own special query for calculating size.
+ info.fBytesPerPixel = 3;
if (fSupportsYcbcrConversion) {
info.init(interface, physDev, properties, format);
}
@@ -1353,6 +1359,18 @@
return table[table.count() - 1];
}
+size_t GrVkCaps::bytesPerPixel(const GrBackendFormat& format) const {
+ VkFormat vkFormat;
+ if (!format.asVkFormat(&vkFormat)) {
+ return 0;
+ }
+ return this->bytesPerPixel(vkFormat);
+}
+
+size_t GrVkCaps::bytesPerPixel(VkFormat format) const {
+ return this->getFormatInfo(format).fBytesPerPixel;
+}
+
static inline size_t align_to_4(size_t v) {
switch (v & 0b11) {
// v is already a multiple of 4.
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 44270d9..1135256 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -53,11 +53,8 @@
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
int maxRenderTargetSampleCount(VkFormat format) const;
- size_t bytesPerPixel(VkFormat format) const {
- // We shouldn't be calling this for compressed or planar formats.
- SkASSERT(this->getFormatInfo(format).fBytesPerPixel);
- return this->getFormatInfo(format).fBytesPerPixel;
- }
+ size_t bytesPerPixel(const GrBackendFormat&) const override;
+ size_t bytesPerPixel(VkFormat format) const;
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
const GrBackendFormat& surfaceFormat,
@@ -273,7 +270,7 @@
uint16_t fLinearFlags = 0;
SkTDArray<int> fColorSampleCounts;
- // This value is only valid for regular formats. Planar and compressed formats will be 0.
+ // This value is only valid for regular formats. Compressed formats will be 0.
size_t fBytesPerPixel = 0;
std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index 92369ba..660a257 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -117,8 +117,9 @@
// Add one to account for the resolved VkImage.
numColorSamples += 1;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples, GrMipMapped::kNo);
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples, GrMipMapped::kNo);
}
void createFramebuffer(GrVkGpu* gpu);
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp
index 50aae23..cc720a1 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -244,7 +244,8 @@
// Add one to account for the resolve VkImage.
++numColorSamples;
}
- return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
- numColorSamples, // TODO: this still correct?
+ const GrCaps& caps = *this->getGpu()->caps();
+ return GrSurface::ComputeSize(this->config(), caps, this->backendFormat(), this->width(),
+ this->height(), numColorSamples, // TODO: this still correct?
this->texturePriv().mipMapped());
}
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 0b7f282..7100e35 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -164,7 +164,7 @@
// instantiated, it checks that the instantiated size is <= to
// the pre-computation. If the proxy never computed its
// pre-instantiation size then the check is skipped.
- proxy->gpuMemorySize();
+ proxy->gpuMemorySize(caps);
check_surface(reporter, proxy.get(), origin,
widthHeight, widthHeight, config, budgeted);
@@ -200,7 +200,7 @@
// instantiated, it checks that the instantiated size is <= to
// the pre-computation. If the proxy never computed its
// pre-instantiation size then the check is skipped.
- proxy->gpuMemorySize();
+ proxy->gpuMemorySize(caps);
check_surface(reporter, proxy.get(), origin,
widthHeight, widthHeight, config, budgeted);
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 3d94c0f..a20c7fa 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -1618,13 +1618,13 @@
sk_sp<GrTextureProxy> proxy;
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, 1);
- size_t size = proxy->gpuMemorySize();
+ size_t size = proxy->gpuMemorySize(*caps);
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
size_t sampleCount = (size_t)caps->getRenderTargetSampleCount(4, proxy->backendFormat());
if (sampleCount >= 4) {
proxy = make_mipmap_proxy(context, GrRenderable::kYes, kSize, kSize, sampleCount);
- size = proxy->gpuMemorySize();
+ size = proxy->gpuMemorySize(*caps);
REPORTER_ASSERT(reporter,
kSize*kSize*4+(kSize*kSize*4)/3 == size || // msaa4 failed
kSize*kSize*4*sampleCount+(kSize*kSize*4)/3 == size || // auto-resolving
@@ -1632,7 +1632,7 @@
}
proxy = make_mipmap_proxy(context, GrRenderable::kNo, kSize, kSize, 1);
- size = proxy->gpuMemorySize();
+ size = proxy->gpuMemorySize(*caps);
REPORTER_ASSERT(reporter, kSize*kSize*4+(kSize*kSize*4)/3 == size);
}
}