Reapply r1951.



git-svn-id: http://skia.googlecode.com/svn/trunk@1959 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrGLConfig.h b/gpu/include/GrGLConfig.h
index e59fe55..d608775 100644
--- a/gpu/include/GrGLConfig.h
+++ b/gpu/include/GrGLConfig.h
@@ -202,6 +202,24 @@
         GR_GL(GetIntegerv(e, p));   \
     } while (0)
 
+#define GR_GL_GetFramebufferAttachmentParameteriv(t, a, pname, p)   \
+    do {                                                            \
+        *(p) = GR_GL_INIT_ZERO;                                     \
+        GR_GL(GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
+    } while (0)
+
+#define GR_GL_GetRenderbufferParameteriv(t, pname, p)    \
+    do {                                                 \
+        *(p) = GR_GL_INIT_ZERO;                          \
+        GR_GL(GetRenderbufferParameteriv(t, pname, p));  \
+    } while (0)
+
+#define GR_GL_GetTexLevelParameteriv(t, l, pname, p)    \
+    do {                                                \
+        *(p) = GR_GL_INIT_ZERO;                         \
+        GR_GL(GetTexLevelParameteriv(t, l, pname, p));  \
+    } while (0)
+
 ////////////////////////////////////////////////////////////////////////////////
 
 #endif
diff --git a/gpu/include/GrGLDefines.h b/gpu/include/GrGLDefines.h
index 6c2483b..b0366fb 100644
--- a/gpu/include/GrGLDefines.h
+++ b/gpu/include/GrGLDefines.h
@@ -432,11 +432,11 @@
 #define GR_GL_TEXTURE_ENV                   0x2300
 #define GR_GL_TEXTURE_ENV_MODE              0x2200
 #define GR_GL_TEXTURE_1D                    0x0DE0
-#define GR_GL_TEXTURE_2D                    0x0DE1
-/*	GL_TEXTURE_WRAP_S */
-/*	GL_TEXTURE_WRAP_T */
-/*	GL_TEXTURE_MAG_FILTER */
-/*	GL_TEXTURE_MIN_FILTER */
+/* GL_TEXTURE_2D */
+/* GL_TEXTURE_WRAP_S */
+/* GL_TEXTURE_WRAP_T */
+/* GL_TEXTURE_MAG_FILTER */
+/* GL_TEXTURE_MIN_FILTER */
 #define GR_GL_TEXTURE_ENV_COLOR             0x2201
 #define GR_GL_TEXTURE_GEN_S                 0x0C60
 #define GR_GL_TEXTURE_GEN_T                 0x0C61
@@ -452,10 +452,11 @@
 #define GR_GL_TEXTURE_ALPHA_SIZE            0x805F
 #define GR_GL_TEXTURE_LUMINANCE_SIZE        0x8060
 #define GR_GL_TEXTURE_INTENSITY_SIZE        0x8061
-/*	GL_NEAREST_MIPMAP_NEAREST */
-/*	GL_NEAREST_MIPMAP_LINEAR */
-/*	GL_LINEAR_MIPMAP_NEAREST */
-/*	GL_LINEAR_MIPMAP_LINEAR */
+#define GR_GL_TEXTURE_INTERNAL_FORMAT       0x1003
+/* GL_NEAREST_MIPMAP_NEAREST */
+/* GL_NEAREST_MIPMAP_LINEAR */
+/* GL_LINEAR_MIPMAP_NEAREST */
+/* GL_LINEAR_MIPMAP_LINEAR */
 #define GR_GL_OBJECT_LINEAR                 0x2401
 #define GR_GL_OBJECT_PLANE                  0x2501
 #define GR_GL_EYE_LINEAR                    0x2400
@@ -605,6 +606,11 @@
 #define GR_GL_RGB5_A1                        0x8057
 #define GR_GL_RGB565                         0x8D62
 #define GR_GL_RGBA8                          0x8058
+#define GR_GL_RGB8                           0x8051
+#define GR_GL_SRGB                           0x8C40
+#define GR_GL_SRGB8                          0x8C41
+#define GR_GL_SRGB_ALPHA                     0x8C42
+#define GR_GL_SRGB8_ALPHA8                   0x8C43
 #define GR_GL_DEPTH_COMPONENT16              0x81A5
 #define GR_GL_STENCIL_INDEX                  0x1901
 #define GR_GL_STENCIL_INDEX4                 0x8D47
@@ -629,6 +635,13 @@
 #define GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME           0x8CD1
 #define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL         0x8CD2
 #define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER         0x8CD4
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE              0x8212
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE            0x8213
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE             0x8214
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE            0x8215
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE            0x8216
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE          0x8217
 
 #define GR_GL_COLOR_ATTACHMENT0              0x8CE0
 #define GR_GL_DEPTH_ATTACHMENT               0x8D00
diff --git a/gpu/include/GrGLInterface.h b/gpu/include/GrGLInterface.h
index 42ff0c8..c959c36 100644
--- a/gpu/include/GrGLInterface.h
+++ b/gpu/include/GrGLInterface.h
@@ -133,6 +133,7 @@
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
     typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
+    typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameteriv)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
     typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
@@ -190,6 +191,8 @@
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
+    typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
+    typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
 
     // Multisampling Extension Functions
@@ -283,6 +286,7 @@
     GrGLGetShaderInfoLogProc fGetShaderInfoLog;
     GrGLGetShaderivProc fGetShaderiv;
     GrGLGetStringProc fGetString;
+    GrGLGetTexLevelParameteriv fGetTexLevelParameteriv;
     GrGLGetUniformLocationProc fGetUniformLocation;
     GrGLLineWidthProc fLineWidth;
     GrGLLinkProgramProc fLinkProgram;
@@ -340,6 +344,8 @@
     GrGLFramebufferTexture2DProc fFramebufferTexture2D;
     GrGLGenFramebuffersProc fGenFramebuffers;
     GrGLGenRenderbuffersProc fGenRenderbuffers;
+    GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
+    GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
     GrGLRenderbufferStorageProc fRenderbufferStorage;
 
     // Multisampling Extension Functions
diff --git a/gpu/include/GrGLTexture.h b/gpu/include/GrGLTexture.h
index fe2fa28..53dcd22 100644
--- a/gpu/include/GrGLTexture.h
+++ b/gpu/include/GrGLTexture.h
@@ -67,6 +67,7 @@
     GrGLRenderTarget(GrGpuGL* gpu,
                      const GLRenderTargetIDs& ids,
                      GrGLTexID* texID,
+                     GrPixelConfig config,
                      GrGLuint stencilBits,
                      bool isMultisampled,
                      const GrGLIRect& fViewport,
@@ -177,7 +178,7 @@
                                    int height,
                                    const void* srcData,
                                    size_t rowBytes);
-    virtual intptr_t getTextureHandle();
+    virtual intptr_t getTextureHandle() const;
 
     const TexParams& getTexParams() const { return fTexParams; }
     void setTexParams(const TexParams& texParams) { fTexParams = texParams; }
diff --git a/gpu/include/GrGeometryBuffer.h b/gpu/include/GrGeometryBuffer.h
index 98f58bd..d7dc177 100644
--- a/gpu/include/GrGeometryBuffer.h
+++ b/gpu/include/GrGeometryBuffer.h
@@ -26,12 +26,6 @@
  */
 class GrGeometryBuffer : public GrResource {
 public:
-    /**
-     * Retrieves the size of the buffer
-     *
-     * @return the size of the buffer in bytes
-     */
-    size_t size() const { return fSizeInBytes; }
 
     /**
      *Retrieves whether the buffer was created with the dynamic flag
@@ -94,6 +88,10 @@
     virtual bool updateSubData(const void* src,
                                size_t srcSizeInBytes,
                                size_t offset) = 0;
+
+    // GrResource overrides
+    virtual size_t sizeInBytes() const { return fSizeInBytes; }
+
 protected:
     GrGeometryBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
         : INHERITED(gpu)
diff --git a/gpu/include/GrIndexBuffer.h b/gpu/include/GrIndexBuffer.h
index 366640e..23078c3 100644
--- a/gpu/include/GrIndexBuffer.h
+++ b/gpu/include/GrIndexBuffer.h
@@ -27,7 +27,9 @@
          * from the index buffer (using kTriangles_PrimitiveType).
          * @return the maximum number of quads using full size of index buffer.
          */
-        int maxQuads() const { return size() / (sizeof(uint16_t) * 6); }
+        int maxQuads() const {
+            return this->sizeInBytes() / (sizeof(uint16_t) * 6);
+        }
 protected:
     GrIndexBuffer(GrGpu* gpu, size_t sizeInBytes, bool dynamic)
         : INHERITED(gpu, sizeInBytes, dynamic) {}
diff --git a/gpu/include/GrResource.h b/gpu/include/GrResource.h
index 8cc4d57..eee1a81 100644
--- a/gpu/include/GrResource.h
+++ b/gpu/include/GrResource.h
@@ -54,6 +54,14 @@
      */
     bool isValid() const { return NULL != fGpu; }
 
+    /**
+     * Retrieves the size of the object in GPU memory. This is approximate since
+     * we aren't aware of additional padding or copies made by the driver.
+     *
+     * @return the size of the buffer in bytes
+     */
+     virtual size_t sizeInBytes() const = 0;
+
 protected:
 
     virtual void onRelease() = 0;
diff --git a/gpu/include/GrTexture.h b/gpu/include/GrTexture.h
index 50ed35d..cadf0f2 100644
--- a/gpu/include/GrTexture.h
+++ b/gpu/include/GrTexture.h
@@ -44,6 +44,13 @@
     int height() const { return fHeight; }
 
     /**
+     * @return the pixel config. Can be kUnknown_GrPixelConfig
+     * if client asked us to render to a target that has a pixel
+     * config that isn't equivalent with one of our configs.
+     */
+    int config() const { return fConfig; }
+
+    /**
      * @return the number of stencil bits in the rendertarget
      */
     int stencilBits() const { return fStencilBits; }
@@ -105,6 +112,9 @@
      */
     const GrIRect& getResolveRect() const { return fResolveRect; }
 
+    // GrResource overrides
+    virtual size_t sizeInBytes() const;
+
     /**
      * Reads a rectangle of pixels from the render target.
      * @param left          left edge of the rectangle to read (inclusive)
@@ -135,12 +145,14 @@
                    GrTexture* texture,
                    int width,
                    int height,
+                   GrPixelConfig config,
                    int stencilBits,
                    bool isMultisampled)
         : INHERITED(gpu)
         , fTexture(texture)
         , fWidth(width)
         , fHeight(height)
+        , fConfig(config)
         , fStencilBits(stencilBits)
         , fIsMultisampled(isMultisampled)
     {
@@ -160,11 +172,12 @@
 
 private:
     GrTexture* fTexture; // not ref'ed
-    int        fWidth;
-    int        fHeight;
-    int        fStencilBits;
-    bool       fIsMultisampled;
-    GrIRect    fResolveRect;
+    int             fWidth;
+    int             fHeight;
+    GrPixelConfig   fConfig;
+    int             fStencilBits;
+    bool            fIsMultisampled;
+    GrIRect         fResolveRect;
 
     // GrGpu keeps a cached clip in the render target to avoid redundantly
     // rendering the clip into the same stencil buffer.
@@ -208,7 +221,7 @@
     /**
      *  Approximate number of bytes used by the texture
      */
-    size_t sizeInBytes() const {
+    virtual size_t sizeInBytes() const {
         return fWidth * fHeight * GrBytesPerPixel(fConfig);
     }
 
@@ -273,7 +286,7 @@
      *  Return the native ID or handle to the texture, depending on the
      *  platform. e.g. on opengl, return the texture ID.
      */
-    virtual intptr_t getTextureHandle() = 0;
+    virtual intptr_t getTextureHandle() const = 0;
 
 #if GR_DEBUG
     void validate() const {
@@ -301,7 +314,7 @@
         fShiftFixedX = 31 - Gr_clz(fWidth);
         fShiftFixedY = 31 - Gr_clz(fHeight);
     }
-    
+
     // GrResource overrides
     virtual void onRelease() {
         releaseRenderTarget();