Workaround for Intel 6xxx clear to opaque black bug
authorBrian Salomon <bsalomon@google.com>
Thu, 11 May 2017 15:39:08 +0000 (11:39 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 11 May 2017 16:35:13 +0000 (16:35 +0000)
Bug: skia:
Change-Id: Id5e29b483c2b6f698219abfc5bbb2d858c4fc117
Reviewed-on: https://skia-review.googlesource.com/16427
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
src/gpu/gl/GrGLCaps.cpp
src/gpu/gl/GrGLCaps.h
src/gpu/gl/GrGLGpu.cpp
src/gpu/gl/GrGLUtil.cpp
src/gpu/gl/GrGLUtil.h

index 2c2f7ec1131172d1fe8c3f309b5d9d577354f1c9..232c013f11e06ce5642cca3b6cd2f393e55794ea 100644 (file)
@@ -53,6 +53,7 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
     fDoManualMipmapping = false;
     fSRGBDecodeDisableSupport = false;
     fSRGBDecodeDisableAffectsMipmaps = false;
+    fClearToOpaqueBlackIsBroken = false;
 
     fBlitFramebufferFlags = kNoSupport_BlitFramebufferFlag;
 
@@ -572,6 +573,13 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
     fSRGBDecodeDisableAffectsMipmaps = fSRGBDecodeDisableSupport &&
         kChromium_GrGLDriver != ctxInfo.driver();
 
+    // See http://crbug.com/710443
+#ifdef SK_BUILD_FOR_MAC
+    if (kIntel6xxx_GrGLRenderer == ctxInfo.renderer()) {
+        fClearToOpaqueBlackIsBroken = true;
+    }
+#endif
+
     // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have
     // already been detected.
     this->initConfigTable(contextOptions, ctxInfo, gli, shaderCaps);
index c32e41916fb2122dd302e398e6b86fa4840317c4..bba4d8e033ef3ac438eec5cded60ddb1eb01c020 100644 (file)
@@ -359,6 +359,7 @@ public:
         return fRGBAToBGRAReadbackConversionsAreSlow;
     }
 
+    bool clearToOpaqueBlackIsBroken() const { return fClearToOpaqueBlackIsBroken; }
     bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
                             bool* rectsMustMatch, bool* disallowSubrect) const override;
 
@@ -430,6 +431,7 @@ private:
     bool fDoManualMipmapping : 1;
     bool fSRGBDecodeDisableSupport : 1;
     bool fSRGBDecodeDisableAffectsMipmaps : 1;
+    bool fClearToOpaqueBlackIsBroken : 1;
 
     uint32_t fBlitFramebufferFlags;
 
index a2eabe4e4671fe0f32d7a9e9bfed6a909e2e2b39..9b507a42a624c59b823461a461209b5dc0518f24 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "GrGLGpu.h"
 
+#include <cmath>
 #include "../private/GrGLSL.h"
 #include "GrBackendSurface.h"
 #include "GrFixedClip.h"
@@ -2104,6 +2105,16 @@ void GrGLGpu::clear(const GrFixedClip& clip, GrColor color, GrRenderTarget* targ
 
     GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
     fHWWriteToColor = kYes_TriState;
+
+    if (this->glCaps().clearToOpaqueBlackIsBroken() && 0 == r && 0 == g && 0 == b && 1 == a) {
+#ifdef SK_BUILD_FOR_ANDROID
+        // Android doesn't have std::nextafter but has nextafter.
+        static const GrGLfloat safeAlpha = nextafter(1.f, 2.f);
+#else
+        static const GrGLfloat safeAlpha = std::nextafter(1.f, 2.f);
+#endif
+        a = safeAlpha;
+    }
     GL_CALL(ClearColor(r, g, b, a));
     GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT));
 }
index 443d77c3ef4225c7c8784de2ad9311bfb1ecff01..58b5860f134971f1f04a857f06904a7ae0abf84f 100644 (file)
@@ -313,6 +313,16 @@ GrGLRenderer GrGLGetRendererFromString(const char* rendererString) {
                 }
             }
         }
+        int intelNumber;
+        n = sscanf(rendererString, "Intel(R) Iris(TM) Graphics %d", &intelNumber);
+        if (1 != n) {
+            n = sscanf(rendererString, "Intel(R) HD Graphics %d", &intelNumber);
+        }
+        if (1 == n) {
+            if (intelNumber >= 6000 && intelNumber < 7000) {
+                return kIntel6xxx_GrGLRenderer;
+            }
+        }
         if (0 == strcmp("Mesa Offscreen", rendererString)) {
             return kOSMesa_GrGLRenderer;
         }
index 7503371097049aebc053aa805eb71dc6b852cc32..25bd68175b2ddcf93f6c0a1fb4dada3f081a03db 100644 (file)
@@ -54,6 +54,8 @@ enum GrGLRenderer {
     kAdreno4xx_GrGLRenderer,
     kAdreno5xx_GrGLRenderer,
     kOSMesa_GrGLRenderer,
+    /** Either HD 6xxx or Iris 6xxx */
+    kIntel6xxx_GrGLRenderer,
     kOther_GrGLRenderer
 };