Revert "Revert "Remove GrSurfaceDesc member from GrSurface.""

This reverts commit 4b30a96a3e96b7f051e25025f4f17f3c54e04153.

Bug: skia:
Change-Id: I14d5b402c87df8fffbc29f16686fcfa18474fc48
Reviewed-on: https://skia-review.googlesource.com/17408
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index a46ecb6..2eb8271 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -49,6 +49,28 @@
     return proxy->priv().isExact() || (SkIsPow2(proxy->width()) && SkIsPow2(proxy->height()));
 }
 
+bool validate_desc(const GrSurfaceDesc& desc, const GrCaps& caps, int levelCount = 0) {
+    if (desc.fWidth <= 0 || desc.fHeight <= 0) {
+        return false;
+    }
+    if (!caps.isConfigTexturable(desc.fConfig)) {
+        return false;
+    }
+    if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
+        if (!caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+            return false;
+        }
+    } else {
+        if (desc.fSampleCnt) {
+            return false;
+        }
+    }
+    if (levelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
+        return false;
+    }
+    return true;
+}
+
 // MDB TODO: this should probably be a factory on GrSurfaceProxy
 sk_sp<GrTextureProxy> GrResourceProvider::createMipMappedTexture(
                                                       const GrSurfaceDesc& desc,
@@ -74,11 +96,7 @@
         return nullptr;
     }
 
-    if (mipLevelCount > 1 && GrPixelConfigIsSint(desc.fConfig)) {
-        return nullptr;
-    }
-    if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
-        !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+    if (!validate_desc(desc, *fCaps, mipLevelCount)) {
         return nullptr;
     }
 
@@ -133,6 +151,10 @@
         return nullptr;
     }
 
+    if (!validate_desc(desc, *fCaps)) {
+        return nullptr;
+    }
+
     GrContext* context = fGpu->getContext();
 
     if (!GrPixelConfigIsCompressed(desc.fConfig)) {
@@ -166,8 +188,7 @@
         return nullptr;
     }
 
-    if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
-        !fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+    if (!validate_desc(desc, *fCaps)) {
         return nullptr;
     }
 
@@ -195,15 +216,18 @@
         return nullptr;
     }
 
+    if (!validate_desc(desc, *fCaps)) {
+        return nullptr;
+    }
+
     return this->refScratchTexture(desc, flags);
 }
 
-GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc,
-                                                 uint32_t flags) {
+GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc, uint32_t flags) {
     ASSERT_SINGLE_OWNER
     SkASSERT(!this->isAbandoned());
     SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
-    SkASSERT(inDesc.fWidth > 0 && inDesc.fHeight > 0);
+    SkASSERT(validate_desc(inDesc, *fCaps));
 
     SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);