Move renderable config list to GrDrawTargetCaps

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/26342006

git-svn-id: http://skia.googlecode.com/svn/trunk/src@11756 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/GrContext.cpp b/gpu/GrContext.cpp
index 91e8286..66a86f3 100644
--- a/gpu/GrContext.cpp
+++ b/gpu/GrContext.cpp
@@ -1689,7 +1689,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 bool GrContext::isConfigRenderable(GrPixelConfig config) const {
-    return fGpu->isConfigRenderable(config);
+    return fGpu->caps()->isConfigRenderable(config);
 }
 
 static inline intptr_t setOrClear(intptr_t bits, int shift, intptr_t pred) {
diff --git a/gpu/GrDrawTarget.cpp b/gpu/GrDrawTarget.cpp
index fa2223d..fc3014e 100644
--- a/gpu/GrDrawTarget.cpp
+++ b/gpu/GrDrawTarget.cpp
@@ -981,6 +981,8 @@
     fMaxRenderTargetSize = 0;
     fMaxTextureSize = 0;
     fMaxSampleCount = 0;
+
+    memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
 }
 
 GrDrawTargetCaps& GrDrawTargetCaps::operator=(const GrDrawTargetCaps& other) {
@@ -1001,6 +1003,8 @@
     fMaxTextureSize = other.fMaxTextureSize;
     fMaxSampleCount = other.fMaxSampleCount;
 
+    memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport));
+
     return *this;
 }
 
@@ -1021,4 +1025,29 @@
     GrPrintf("Max Texture Size            : %d\n", fMaxTextureSize);
     GrPrintf("Max Render Target Size      : %d\n", fMaxRenderTargetSize);
     GrPrintf("Max Sample Count            : %d\n", fMaxSampleCount);
+
+    static const char* kConfigNames[] = {
+        "Unknown",  // kUnknown_GrPixelConfig
+        "Alpha8",   // kAlpha_8_GrPixelConfig,
+        "Index8",   // kIndex_8_GrPixelConfig,
+        "RGB565",   // kRGB_565_GrPixelConfig,
+        "RGBA444",  // kRGBA_4444_GrPixelConfig,
+        "RGBA8888", // kRGBA_8888_GrPixelConfig,
+        "BGRA8888", // kBGRA_8888_GrPixelConfig,
+    };
+    GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
+    GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
+    GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
+    GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
+    GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
+    GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
+    GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
+    GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
+
+    SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig]);
+    for (size_t i = 0; i < SK_ARRAY_COUNT(kConfigNames); ++i)  {
+        if (i != kUnknown_GrPixelConfig) {
+            GrPrintf("%s is renderable: %s\n", kConfigNames[i], gNY[fConfigRenderSupport[i]]);
+        }
+    }
 }
diff --git a/gpu/GrDrawTargetCaps.h b/gpu/GrDrawTargetCaps.h
index 111b35b..11347e3 100644
--- a/gpu/GrDrawTargetCaps.h
+++ b/gpu/GrDrawTargetCaps.h
@@ -7,6 +7,7 @@
  */
 
 #include "SkRefCnt.h"
+#include "GrTypes.h"
 
 #ifndef GrDrawTargetCaps_DEFINED
 #define GrDrawTargetCaps_DEFINED
@@ -43,6 +44,14 @@
     // Will be 0 if MSAA is not supported
     int maxSampleCount() const { return fMaxSampleCount; }
 
+    /**
+     * Can the provided configuration act as a render target?
+     */
+    bool isConfigRenderable(GrPixelConfig config) const {
+        SkASSERT(kGrPixelConfigCnt > config);
+        return fConfigRenderSupport[config];
+    }
+
 protected:
     bool f8BitPaletteSupport        : 1;
     bool fNPOTTextureTileSupport    : 1;
@@ -61,6 +70,8 @@
     int fMaxTextureSize;
     int fMaxSampleCount;
 
+    bool fConfigRenderSupport[kGrPixelConfigCnt];
+
     typedef SkRefCnt INHERITED;
 };
 
diff --git a/gpu/GrGpu.cpp b/gpu/GrGpu.cpp
index 7677b7c..186091f 100644
--- a/gpu/GrGpu.cpp
+++ b/gpu/GrGpu.cpp
@@ -47,10 +47,6 @@
     poolState.fPoolIndexBuffer = (GrIndexBuffer*)DEBUG_INVAL_BUFFER;
     poolState.fPoolStartIndex = DEBUG_INVAL_START_IDX;
 #endif
-
-    for (int i = 0; i < kGrPixelConfigCnt; ++i) {
-        fConfigRenderSupport[i] = false;
-    };
 }
 
 GrGpu::~GrGpu() {
diff --git a/gpu/GrGpu.h b/gpu/GrGpu.h
index b449f9e..48caf7c 100644
--- a/gpu/GrGpu.h
+++ b/gpu/GrGpu.h
@@ -291,14 +291,6 @@
     }
 
     /**
-     * Can the provided configuration act as a color render target?
-     */
-    bool isConfigRenderable(GrPixelConfig config) const {
-        SkASSERT(kGrPixelConfigCnt > config);
-        return fConfigRenderSupport[config];
-    }
-
-    /**
      * These methods are called by the clip manager's setupClipping function
      * which (called as part of GrGpu's implementation of onDraw and
      * onStencilPath member functions.) The GrGpu subclass should flush the
@@ -401,10 +393,6 @@
     // The final stencil settings to use as determined by the clip manager.
     GrStencilSettings fStencilSettings;
 
-    // Derived classes need access to this so they can fill it out in their
-    // constructors
-    bool    fConfigRenderSupport[kGrPixelConfigCnt];
-
     // Helpers for setting up geometry state
     void finalizeReservedVertices();
     void finalizeReservedIndices();
diff --git a/gpu/gl/GrGLCaps.cpp b/gpu/gl/GrGLCaps.cpp
index 17a4743..eb0b245 100644
--- a/gpu/gl/GrGLCaps.cpp
+++ b/gpu/gl/GrGLCaps.cpp
@@ -334,6 +334,67 @@
     } else if (GrGLCaps::kNone_MSFBOType != fMSFBOType) {
         GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
     }
+
+    this->initConfigRenderableTable(ctxInfo);
+}
+
+void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) {
+
+    // OpenGL < 3.0
+    //  no support for render targets unless the GL_ARB_framebuffer_object
+    //  extension is supported (in which case we get ALPHA, RED, RG, RGB,
+    //  RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
+    //  probably don't get R8 in this case.
+
+    // OpenGL 3.0
+    //  base color renderable: ALPHA, RED, RG, RGB, and RGBA
+    //  sized derivatives: ALPHA8, R8, RGBA4, RGBA8
+
+    // >= OpenGL 3.1
+    //  base color renderable: RED, RG, RGB, and RGBA
+    //  sized derivatives: R8, RGBA4, RGBA8
+    //  if the GL_ARB_compatibility extension is supported then we get back
+    //  support for GL_ALPHA and ALPHA8
+
+    // GL_EXT_bgra adds BGRA render targets to any version
+
+    // ES 2.0
+    //  color renderable: RGBA4, RGB5_A1, RGB565
+    //  GL_EXT_texture_rg adds support for R8 as a color render target
+    //  GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
+    //  GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
+
+    // ES 3.0
+    // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
+    // below already account for this).
+
+    if (kDesktop_GrGLBinding == ctxInfo.binding()) {
+        // Post 3.0 we will get R8
+        // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
+        if (ctxInfo.version() >= GR_GL_VER(3,0) ||
+            ctxInfo.hasExtension("GL_ARB_framebuffer_object")) {
+            fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true;
+        }
+    } else {
+        // On ES we can only hope for R8
+        fConfigRenderSupport[kAlpha_8_GrPixelConfig] = fTextureRedSupport;
+    }
+
+    if (kDesktop_GrGLBinding != ctxInfo.binding()) {
+        // only available in ES
+        fConfigRenderSupport[kRGB_565_GrPixelConfig] = true;
+    }
+
+    // we no longer support 444 as a render target
+    fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false;
+
+    if (this->fRGBA8RenderbufferSupport) {
+        fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true;
+    }
+
+    if (this->fBGRAFormatSupport) {
+        fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true;
+    }
 }
 
 bool GrGLCaps::readPixelsSupported(const GrGLInterface* intf,
diff --git a/gpu/gl/GrGLCaps.h b/gpu/gl/GrGLCaps.h
index 1eaae22..548e7f7 100644
--- a/gpu/gl/GrGLCaps.h
+++ b/gpu/gl/GrGLCaps.h
@@ -286,8 +286,9 @@
         }
     };
 
-    void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
-    void initStencilFormats(const GrGLContextInfo& ctxInfo);
+    void initFSAASupport(const GrGLContextInfo&, const GrGLInterface*);
+    void initStencilFormats(const GrGLContextInfo&);
+    void initConfigRenderableTable(const GrGLContextInfo&);
 
     // tracks configs that have been verified to pass the FBO completeness when
     // used as a color attachment
diff --git a/gpu/gl/GrGpuGL.cpp b/gpu/gl/GrGpuGL.cpp
index d313167..cdf9be9 100644
--- a/gpu/gl/GrGpuGL.cpp
+++ b/gpu/gl/GrGpuGL.cpp
@@ -127,9 +127,6 @@
     fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits());
     fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords());
 
-    fillInConfigRenderableTable();
-
-
     GrGLClearErr(fGLContext.interface());
 
     if (gPrintStartupSpew) {
@@ -177,65 +174,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-void GrGpuGL::fillInConfigRenderableTable() {
-
-    // OpenGL < 3.0
-    //  no support for render targets unless the GL_ARB_framebuffer_object
-    //  extension is supported (in which case we get ALPHA, RED, RG, RGB,
-    //  RGBA (ALPHA8, RGBA4, RGBA8) for OpenGL > 1.1). Note that we
-    //  probably don't get R8 in this case.
-
-    // OpenGL 3.0
-    //  base color renderable: ALPHA, RED, RG, RGB, and RGBA
-    //  sized derivatives: ALPHA8, R8, RGBA4, RGBA8
-
-    // >= OpenGL 3.1
-    //  base color renderable: RED, RG, RGB, and RGBA
-    //  sized derivatives: R8, RGBA4, RGBA8
-    //  if the GL_ARB_compatibility extension is supported then we get back
-    //  support for GL_ALPHA and ALPHA8
-
-    // GL_EXT_bgra adds BGRA render targets to any version
-
-    // ES 2.0
-    //  color renderable: RGBA4, RGB5_A1, RGB565
-    //  GL_EXT_texture_rg adds support for R8 as a color render target
-    //  GL_OES_rgb8_rgba8 and/or GL_ARM_rgba8 adds support for RGBA8
-    //  GL_EXT_texture_format_BGRA8888 and/or GL_APPLE_texture_format_BGRA8888 added BGRA support
-
-    // ES 3.0
-    // Same as ES 2.0 except R8 and RGBA8 are supported without extensions (the functions called
-    // below already account for this).
-
-    if (kDesktop_GrGLBinding == this->glBinding()) {
-        // Post 3.0 we will get R8
-        // Prior to 3.0 we will get ALPHA8 (with GL_ARB_framebuffer_object)
-        if (this->glVersion() >= GR_GL_VER(3,0) ||
-            this->hasExtension("GL_ARB_framebuffer_object")) {
-            fConfigRenderSupport[kAlpha_8_GrPixelConfig] = true;
-        }
-    } else {
-        // On ES we can only hope for R8
-        fConfigRenderSupport[kAlpha_8_GrPixelConfig] =
-                                this->glCaps().textureRedSupport();
-    }
-
-    if (kDesktop_GrGLBinding != this->glBinding()) {
-        // only available in ES
-        fConfigRenderSupport[kRGB_565_GrPixelConfig] = true;
-    }
-
-    // we no longer support 444 as a render target
-    fConfigRenderSupport[kRGBA_4444_GrPixelConfig] = false;
-
-    if (this->glCaps().rgba8RenderbufferSupport()) {
-        fConfigRenderSupport[kRGBA_8888_GrPixelConfig] = true;
-    }
-
-    if (this->glCaps().bgraFormatSupport()) {
-        fConfigRenderSupport[kBGRA_8888_GrPixelConfig] = true;
-    }
-}
 
 GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig,
                                                  GrPixelConfig surfaceConfig) const {
@@ -2460,8 +2398,8 @@
                                  const GrSurface* src,
                                  const GrGpuGL* gpu,
                                  bool* wouldNeedTempFBO = NULL) {
-    if (gpu->isConfigRenderable(dst->config()) &&
-        gpu->isConfigRenderable(src->config()) &&
+    if (gpu->glCaps().isConfigRenderable(dst->config()) &&
+        gpu->glCaps().isConfigRenderable(src->config()) &&
         gpu->glCaps().usesMSAARenderBuffers()) {
         // ES3 doesn't allow framebuffer blits when the src has MSAA and the configs don't match
         // or the rects are not the same (not just the same size but have the same edges).
@@ -2501,7 +2439,7 @@
     if (NULL != srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) {
         return false;
     }
-    if (gpu->isConfigRenderable(src->config()) && NULL != dst->asTexture() &&
+    if (gpu->glCaps().isConfigRenderable(src->config()) && NULL != dst->asTexture() &&
         dst->origin() == src->origin() && kIndex_8_GrPixelConfig != src->config()) {
         if (NULL != wouldNeedTempFBO) {
             *wouldNeedTempFBO = NULL == src->asRenderTarget();
diff --git a/gpu/gl/GrGpuGL.h b/gpu/gl/GrGpuGL.h
index 17699ef..aa3f017 100644
--- a/gpu/gl/GrGpuGL.h
+++ b/gpu/gl/GrGpuGL.h
@@ -261,8 +261,6 @@
                                    GrGLuint texID,
                                    GrGLRenderTarget::Desc* desc);
 
-    void fillInConfigRenderableTable();
-
     GrGLContext fGLContext;
 
     // GL program-related state