add gpu to gm tool
add pass-through read/write pixels API to canvas



git-svn-id: http://skia.googlecode.com/svn/trunk@660 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 5c9dcab..17ed8e4 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -181,12 +181,13 @@
 
 static const struct {
 	SkBitmap::Config	fConfig;
-	bool				fUsePicture;
+	bool				fUseGPU;
 	const char*			fName;
 } gRec[] = {
 	{ SkBitmap::kARGB_8888_Config,	false,	"8888" },
 	{ SkBitmap::kARGB_4444_Config,	false,	"4444" },
 	{ SkBitmap::kRGB_565_Config,	false,	"565" },
+	{ SkBitmap::kARGB_8888_Config,  true,	"gpu" },
 };
 
 int main (int argc, char * const argv[]) {
@@ -242,12 +243,14 @@
 			bitmap.eraseColor(0);
 			SkCanvas canvas(bitmap);
 
-			gm->draw(&canvas);
-            {
+            if (gRec[i].fUseGPU) {
                 SkGpuCanvas gc(context);
                 gc.setDevice(gc.createDevice(bitmap.config(), bitmap.width(), bitmap.height(),
                                              bitmap.isOpaque(), false))->unref(); 
                 gm->draw(&gc);
+                gc.readPixels(&bitmap); // overwrite our previous allocation
+            } else {
+                gm->draw(&canvas);
             }
             SkString name = make_name(gm->shortName(), gRec[i].fName);
 
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index ad5706b..25b2743 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -111,6 +111,20 @@
      */
     SkDevice* setBitmapDevice(const SkBitmap& bitmap, bool forLayer = false);
 
+    /**
+     *  Copy the pixels from the device into bitmap. Returns true on success.
+     *  If false is returned, then the bitmap parameter is left unchanged.
+     */
+    bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
+    bool readPixels(SkBitmap* bitmap);
+
+    /**
+     *  Similar to draw sprite, this method will copy the pixels in bitmap onto
+     *  the device, with the top/left corner specified by (x, y). The pixel
+     *  values in the device are completely replaced: there is no blending.
+     */
+    void writePixels(const SkBitmap& bitmap, int x, int y);
+    
     ///////////////////////////////////////////////////////////////////////////
 
     enum SaveFlags {
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 764e063..0761641 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -549,6 +549,31 @@
     return device;
 }
 
+bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
+    SkDevice* device = this->getDevice();
+    if (!device) {
+        return false;
+    }
+    return device->readPixels(srcRect, bitmap);
+}
+
+bool SkCanvas::readPixels(SkBitmap* bitmap) {
+    SkDevice* device = this->getDevice();
+    if (!device) {
+        return false;
+    }
+    SkIRect bounds;
+    bounds.set(0, 0, device->width(), device->height());
+    return this->readPixels(bounds, bitmap);
+}
+
+void SkCanvas::writePixels(const SkBitmap& bitmap, int x, int y) {
+    SkDevice* device = this->getDevice();
+    if (device) {
+        device->writePixels(bitmap, x, y);
+    }
+}
+
 //////////////////////////////////////////////////////////////////////////////
 
 bool SkCanvas::getViewport(SkIPoint* size) const {