Add new public api on GrContext for computing image size.

This api will replace ComputeTextureSize.

Change-Id: I9befd8706f44250805315bdb13a559cf81c7142d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/247337
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 02e64f8..3bb9b0e 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -10,6 +10,8 @@
 Milestone 79
 
 [Insert new notes here.]
+  * Added new api on GrContext ComputeImageSize. This replaces the hold static helper
+    ComputeTextureSize.
 
   * New versions of SkSurface async-rescale-and read APIs that allow client to extend
     the lifetime of the result data. Old versions are deprecated.
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index ef3fc0d..23cb69f 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -367,6 +367,10 @@
     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);
+
     /*
      * Retrieve the default GrBackendFormat for a given SkColorType and renderability.
      * It is guaranteed that this backend format will be the one used by the following
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b5c96d1..f729d09 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -239,6 +239,15 @@
                                   colorSamplesPerPixel, mipMapped, useNextPow2);
 }
 
+size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipMapped mipMapped, bool useNextPow2) {
+    if (!image->isTextureBacked()) {
+        return 0;
+    }
+    int colorSamplesPerPixel = 1;
+    return GrSurface::ComputeSize(SkColorType2GrPixelConfig(image->colorType()), image->width(),
+                                  image->height(), colorSamplesPerPixel, mipMapped, useNextPow2);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 
 int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); }