Revert "Further centralize computation of GrSurface VRAM consumption"

This reverts commit ccd3c8937fce4bb28df19533ed043cad209e277d.

Reason for revert: Blocking Chromium roll: https://codereview.chromium.org/2482643002/

Original change's description:
> Further centralize computation of GrSurface VRAM consumption
> 
> GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4383
> 
> Change-Id: I054b74f2cd15f904f8e05af0fda58d6e8a523eb9
> Reviewed-on: https://skia-review.googlesource.com/4383
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> 

TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=662630

Change-Id: I186db2a41eb2bd789e6f681b3547e32d9ca374cf
Reviewed-on: https://skia-review.googlesource.com/4443
Commit-Queue: Ben Wagner <benjaminwagner@google.com>
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index f15e3b0..2828866 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -84,6 +84,17 @@
     INHERITED::onAbandon();
 }
 
+size_t GrRenderTarget::ComputeSize(const GrSurfaceDesc& desc, int colorValuesPerPixel) {
+    SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
+    SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
+    size_t colorBytes = GrBytesPerPixel(desc.fConfig);
+    SkASSERT(colorBytes > 0);
+
+    size_t rtSize = colorValuesPerPixel * desc.fWidth * desc.fHeight * colorBytes;
+    SkASSERT(rtSize <= WorstCaseSize(desc));
+    return rtSize;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 bool GrRenderTargetPriv::attachStencilAttachment(GrStencilAttachment* stencil) {
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index eb75084..ac8f5ed 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -82,7 +82,7 @@
     }
 
     // TODO: do we have enough information to improve this worst case estimate?
-    return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
+    return GrRenderTarget::ComputeSize(fDesc, fDesc.fSampleCnt+1);
 }
 
 sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps,
diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp
index e06fc01..9fe00de 100644
--- a/src/gpu/GrSurface.cpp
+++ b/src/gpu/GrSurface.cpp
@@ -38,16 +38,15 @@
         }
         SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
         SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
-        size_t colorBytes = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
+        size_t colorBytes = GrBytesPerPixel(desc.fConfig);
         SkASSERT(colorBytes > 0);
 
-        size = colorValuesPerPixel * colorBytes;
-        size += colorBytes/3; // in case we have to mipmap
+        size = (size_t) colorValuesPerPixel * desc.fWidth * desc.fHeight * colorBytes;
     } else {
         if (GrPixelConfigIsCompressed(desc.fConfig)) {
             size = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
         } else {
-            size = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
+            size = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
         }
 
         size += size/3;  // in case we have to mipmap
@@ -56,31 +55,6 @@
     return size;
 }
 
-size_t GrSurface::ComputeSize(const GrSurfaceDesc& desc,
-                              int colorSamplesPerPixel,
-                              bool hasMIPMaps) {
-    size_t colorSize;
-
-    SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
-    if (GrPixelConfigIsCompressed(desc.fConfig)) {
-        colorSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
-    } else {
-        colorSize = desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
-    }
-    SkASSERT(colorSize > 0);
-
-    size_t finalSize = colorSamplesPerPixel * colorSize;
-
-    if (hasMIPMaps) {
-        // We don't have to worry about the mipmaps being a different size than
-        // we'd expect because we never change fDesc.fWidth/fHeight.
-        finalSize += colorSize/3;
-    }
-
-    SkASSERT(finalSize <= WorstCaseSize(desc));
-    return finalSize;
-}
-
 template<typename T> static bool adjust_params(int surfaceWidth,
                                                int surfaceHeight,
                                                size_t bpp,
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index de1135a..91036bc 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -35,8 +35,29 @@
     }
 }
 
+size_t GrTexture::ComputeSize(const GrSurfaceDesc& desc, bool hasMipMaps) {
+    size_t textureSize;
+
+    if (GrPixelConfigIsCompressed(desc.fConfig)) {
+        textureSize = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fHeight);
+    } else {
+        textureSize = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fConfig);
+    }
+
+    if (hasMipMaps) {
+        // We don't have to worry about the mipmaps being a different size than
+        // we'd expect because we never change fDesc.fWidth/fHeight.
+        textureSize += textureSize/3;
+    }
+
+    SkASSERT(!SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag));
+    SkASSERT(textureSize <= WorstCaseSize(desc));
+
+    return textureSize;
+}
+
 size_t GrTexture::onGpuMemorySize() const {
-    return GrSurface::ComputeSize(fDesc, 1, this->texturePriv().hasMipMaps());
+    return ComputeSize(fDesc, this->texturePriv().hasMipMaps());
 }
 
 void GrTexture::validateDesc() const {
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 0a7f767..d60bf90 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -46,7 +46,7 @@
 
     static const bool kHasMipMaps = true;
     // TODO: add tracking of mipmap state to improve the estimate
-    return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps);
+    return GrTexture::ComputeSize(fDesc, kHasMipMaps);
 }
 
 sk_sp<GrTextureProxy> GrTextureProxy::Make(GrTextureProvider* texProvider,
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 9af3acc..d8f383a 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -1642,11 +1642,6 @@
         return return_null_texture();
     }
 
-    bool wasMipMapDataProvided = false;
-    if (texels.count() > 1) {
-        wasMipMapDataProvided = true;
-    }
-
     GrGLTexture* tex;
     if (renderTarget) {
         // unbind the texture from the texture unit before binding it to the frame buffer
@@ -1657,9 +1652,12 @@
             GL_CALL(DeleteTextures(1, &idDesc.fInfo.fID));
             return return_null_texture();
         }
-        tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc,
-                                          wasMipMapDataProvided);
+        tex = new GrGLTextureRenderTarget(this, budgeted, desc, idDesc, rtIDDesc);
     } else {
+        bool wasMipMapDataProvided = false;
+        if (texels.count() > 1) {
+            wasMipMapDataProvided = true;
+        }
         tex = new GrGLTexture(this, budgeted, desc, idDesc, wasMipMapDataProvided);
     }
     tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 5af5e67..2f92e0a 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -82,7 +82,7 @@
 }
 
 size_t GrGLRenderTarget::onGpuMemorySize() const {
-    return GrSurface::ComputeSize(fDesc, fNumSamplesOwnedPerPixel, false);
+    return GrRenderTarget::ComputeSize(fDesc, fNumSamplesOwnedPerPixel);
 }
 
 bool GrGLRenderTarget::completeStencilAttachment() {
@@ -183,7 +183,7 @@
     // 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 = GrRenderTarget::ComputeSize(fDesc, this->msaaSamples());
 
         // 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/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 11b2347..fc18e30 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -77,7 +77,8 @@
     void onAbandon() override;
     void onRelease() override;
 
-    int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; }
+    // In protected because subclass GrGLTextureRenderTarget calls this version.
+    size_t onGpuMemorySize() const override;
 
 private:
     // Constructor for instances wrapping backend objects.
@@ -88,8 +89,6 @@
     GrGLGpu* getGLGpu() const;
     bool completeStencilAttachment() override;
 
-    size_t onGpuMemorySize() const override;
-
     int msaaSamples() const;
     // The number total number of samples, including both MSAA and resolve texture samples.
     int totalSamples() const;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index ec0ad3b..4653c5b 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -50,10 +50,9 @@
     this->registerWithCacheWrapped();
 }
 
-GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc,
-                         bool wasMipMapDataProvided)
+GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc)
     : GrSurface(gpu, desc)
-    , INHERITED(gpu, desc, sampler_type(idDesc, gpu), wasMipMapDataProvided) {
+    , INHERITED(gpu, desc, sampler_type(idDesc, gpu), false) {
     this->init(desc, idDesc);
 }
 
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 029fd87..ee027d7 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -59,7 +59,7 @@
     static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
 protected:
     // Constructor for subclasses.
-    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
+    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
 
     enum Wrapped { kWrapped };
     // Constructor for instances wrapping backend objects.
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index 9c350f8..9b37fbb 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -49,5 +49,5 @@
     const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
 {
     return sk_sp<GrGLTextureRenderTarget>(
-        new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, false));
+        new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
 }
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 7ff8d49..c5c020f 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -12,7 +12,6 @@
 #include "GrGLGpu.h"
 #include "GrGLTexture.h"
 #include "GrGLRenderTarget.h"
-#include "GrTexturePriv.h"
 
 class GrGLGpu;
 
@@ -30,10 +29,9 @@
                             SkBudgeted budgeted,
                             const GrSurfaceDesc& desc,
                             const GrGLTexture::IDDesc& texIDDesc,
-                            const GrGLRenderTarget::IDDesc& rtIDDesc,
-                            bool wasMipMapDataProvided)
+                            const GrGLRenderTarget::IDDesc& rtIDDesc)
         : GrSurface(gpu, desc)
-        , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
+        , GrGLTexture(gpu, desc, texIDDesc)
         , GrGLRenderTarget(gpu, desc, rtIDDesc) {
         this->registerWithCache(budgeted);
     }
@@ -61,18 +59,16 @@
     GrGLTextureRenderTarget(GrGLGpu* gpu,
                             const GrSurfaceDesc& desc,
                             const GrGLTexture::IDDesc& texIDDesc,
-                            const GrGLRenderTarget::IDDesc& rtIDDesc,
-                            bool wasMipMapDataProvided)
+                            const GrGLRenderTarget::IDDesc& rtIDDesc)
         : GrSurface(gpu, desc)
-        , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided)
+        , GrGLTexture(gpu, desc, texIDDesc)
         , GrGLRenderTarget(gpu, desc, rtIDDesc) {
         this->registerWithCacheWrapped();
     }
 
+    // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory.
     size_t onGpuMemorySize() const override {
-        return GrSurface::ComputeSize(fDesc,
-                                      this->numSamplesOwnedPerPixel(),
-                                      this->texturePriv().hasMipMaps());
+        return GrGLRenderTarget::onGpuMemorySize();
     }
 
 };
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index 3e5c5ea..2e2f60a 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -100,8 +100,7 @@
     // This 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.
-        // TODO: is this still correct?
-        return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false);
+        return GrRenderTarget::ComputeSize(fDesc, fDesc.fSampleCnt+1); // TODO: this still correct?
     }
 
     void createFramebuffer(GrVkGpu* gpu);
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index 2877a36..daa1687 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -13,8 +13,6 @@
 #include "GrVkRenderTarget.h"
 #include "GrVkGpu.h"
 
-#include "GrTexturePriv.h"
-
 #ifdef SK_BUILD_FOR_WIN
 // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance.
 #pragma warning(push)
@@ -114,9 +112,7 @@
 
     // 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?
-                                      this->texturePriv().hasMipMaps());
+        return GrVkRenderTarget::onGpuMemorySize();
     }
 };