Add more pre-checks to surfaceProxy creation
authorRobert Phillips <robertphillips@google.com>
Tue, 31 Jan 2017 22:25:29 +0000 (17:25 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 1 Feb 2017 12:56:35 +0000 (12:56 +0000)
Chrome is seeing crashes in GrProcessor::TextureSampler::reset when
the textures are being instantiated. This CL moves more potential
failures cases up-stack.

BUG=687174

Change-Id: I014acff9730ffd1e8ac178611372ed4dedbd82f3
Reviewed-on: https://skia-review.googlesource.com/7828
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

src/gpu/GrSurfaceProxy.cpp

index e5cf769..eda0a45 100644 (file)
@@ -135,11 +135,38 @@ sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeDeferred(const GrCaps& caps,
                                                    const GrSurfaceDesc& desc,
                                                    SkBackingFit fit,
                                                    SkBudgeted budgeted) {
-    if (desc.fWidth > caps.maxTextureSize() || desc.fHeight > caps.maxTextureSize()) {
+    // TODO: share this testing code with check_texture_creation_params
+    if (SkBackingFit::kApprox == fit && GrPixelConfigIsCompressed(desc.fConfig)) {
+        // we don't allow scratch compressed textures
         return nullptr;
     }
 
-    if (kRenderTarget_GrSurfaceFlag & desc.fFlags) {
+    if (!caps.isConfigTexturable(desc.fConfig)) {
+        return nullptr;
+    }
+
+    bool willBeRT = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag);
+    if (willBeRT && !caps.isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
+        return nullptr;
+    }
+
+    // We currently do not support multisampled textures
+    if (!willBeRT && desc.fSampleCnt > 0) {
+        return nullptr;
+    }
+
+    int maxSize;
+    if (willBeRT) {
+        maxSize = caps.maxRenderTargetSize();
+    } else {
+        maxSize = caps.maxTextureSize();
+    }
+
+    if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
+        return nullptr;
+    }
+
+    if (willBeRT) {
         // We know anything we instantiate later from this deferred path will be
         // both texturable and renderable
         return sk_sp<GrSurfaceProxy>(new GrTextureRenderTargetProxy(caps, desc, fit, budgeted));