Adds read pixels to GrTexture and GrRenderTarget
Adds SkGrRenderTargetPixelRef for SkBitmaps that are backed by RTs that aren't textures.
Adds onReadPixels implementations for SkGr pixel ref types



git-svn-id: http://skia.googlecode.com/svn/trunk@1056 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrTexture.h b/gpu/include/GrTexture.h
index d1853e3..2aa80ab 100644
--- a/gpu/include/GrTexture.h
+++ b/gpu/include/GrTexture.h
@@ -52,6 +52,21 @@
      */
     GrTexture* asTexture() {return fTexture;}
 
+    /**
+     * Reads a rectangle of pixels from the render target.
+     * @param left          left edge of the rectangle to read (inclusive)
+     * @param top           top edge of the rectangle to read (inclusive)
+     * @param width         width of rectangle to read in pixels.
+     * @param height        height of rectangle to read in pixels.
+     * @param config        the pixel config of the destination buffer
+     * @param buffer        memory to read the rectangle into.
+     *
+     * @return true if the read succeeded, false if not. The read can fail
+     *              because of a unsupported pixel config.
+     */
+    bool readPixels(int left, int top, int width, int height,
+                    GrPixelConfig config, void* buffer);
+
 protected:
     GrRenderTarget(GrGpu* gpu,
                    GrTexture* texture,
@@ -81,25 +96,11 @@
 };
 
 class GrTexture : public GrResource {
-public:
-    enum PixelConfig {
-        kUnknown_PixelConfig,
-        kAlpha_8_PixelConfig,
-        kIndex_8_PixelConfig,
-        kRGB_565_PixelConfig,
-        kRGBA_4444_PixelConfig, //!< premultiplied
-        kRGBA_8888_PixelConfig, //!< premultiplied
-        kRGBX_8888_PixelConfig, //!< treat the alpha channel as opaque
-    };
-    static size_t BytesPerPixel(PixelConfig);
-    static bool PixelConfigIsOpaque(PixelConfig);
-    static bool PixelConfigIsAlphaOnly(PixelConfig);
-
 protected:
     GrTexture(GrGpu* gpu,
               int width,
               int height,
-              PixelConfig config)
+              GrPixelConfig config)
     : INHERITED(gpu)
     , fWidth(width)
     , fHeight(height)
@@ -138,13 +139,13 @@
     /**
      * Retrieves the pixel config specified when the texture was created.
      */
-    PixelConfig config() const { return fConfig; }
+    GrPixelConfig config() const { return fConfig; }
 
     /**
      *  Approximate number of bytes used by the texture
      */
     size_t sizeInBytes() const {
-        return fWidth * fHeight * BytesPerPixel(fConfig);
+        return fWidth * fHeight * GrBytesPerPixel(fConfig);
     }
 
     /**
@@ -164,6 +165,21 @@
                                    const void* srcData) = 0;
 
     /**
+     * Reads a rectangle of pixels from the texture.
+     * @param left          left edge of the rectangle to read (inclusive)
+     * @param top           top edge of the rectangle to read (inclusive)
+     * @param width         width of rectangle to read in pixels.
+     * @param height        height of rectangle to read in pixels.
+     * @param config        the pixel config of the destination buffer
+     * @param buffer        memory to read the rectangle into.
+     *
+     * @return true if the read succeeded, false if not. The read can fail
+     *              because of a unsupported pixel config.
+     */
+    bool readPixels(int left, int top, int width, int height,
+                    GrPixelConfig config, void* buffer);
+
+    /**
      * Retrieves the render target underlying this texture that can be passed to
      * GrGpu::setRenderTarget().
      *
@@ -200,7 +216,8 @@
     // for this texture if the texture is power of two sized.
     int      fShiftFixedX;
     int      fShiftFixedY;
-    PixelConfig fConfig;
+
+    GrPixelConfig fConfig;
 
     typedef GrResource INHERITED;
 };