Change device factories to take SkImageInfo instead of SkBitmap::Config

patch from issue 167033002

BUG=skia:
R=reed@google.com

Author: reed@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13463 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/dm/DM.cpp b/dm/DM.cpp
index de2bda7..8a4a382 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -53,8 +53,8 @@
                            const DM::Expectations& expectations,
                            DM::Reporter* reporter,
                            DM::TaskRunner* tasks) {
-    const SkBitmap::Config _565 = SkBitmap::kRGB_565_Config;
-    const SkBitmap::Config _8888 = SkBitmap::kARGB_8888_Config;
+    const SkColorType _565 = kRGB_565_SkColorType;
+    const SkColorType _8888 = kPMColor_SkColorType;
     const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
     const GrContextFactory::GLContextType null   = GrContextFactory::kNull_GLContextType;
     const GrContextFactory::GLContextType debug  = GrContextFactory::kDebug_GLContextType;
diff --git a/dm/DMCpuTask.cpp b/dm/DMCpuTask.cpp
index c538f0a..7a82a75 100644
--- a/dm/DMCpuTask.cpp
+++ b/dm/DMCpuTask.cpp
@@ -14,18 +14,18 @@
                  TaskRunner* taskRunner,
                  const Expectations& expectations,
                  skiagm::GMRegistry::Factory gmFactory,
-                 SkBitmap::Config config)
+                 SkColorType colorType)
     : Task(reporter, taskRunner)
     , fGMFactory(gmFactory)
     , fGM(fGMFactory(NULL))
     , fName(UnderJoin(fGM->shortName(), name))
     , fExpectations(expectations)
-    , fConfig(config)
+    , fColorType(colorType)
     {}
 
 void CpuTask::draw() {
     SkBitmap bitmap;
-    SetupBitmap(fConfig, fGM.get(), &bitmap);
+    SetupBitmap(fColorType, fGM.get(), &bitmap);
 
     SkCanvas canvas(bitmap);
     canvas.concat(fGM->getInitialTransform());
@@ -48,7 +48,7 @@
 }
 
 bool CpuTask::shouldSkip() const {
-    if (SkBitmap::kRGB_565_Config == fConfig && (fGM->getFlags() & skiagm::GM::kSkip565_Flag)) {
+    if (kRGB_565_SkColorType == fColorType && (fGM->getFlags() & skiagm::GM::kSkip565_Flag)) {
         return true;
     }
     if (fGM->getFlags() & skiagm::GM::kGPUOnly_Flag) {
diff --git a/dm/DMCpuTask.h b/dm/DMCpuTask.h
index c1ee715..8e7f531 100644
--- a/dm/DMCpuTask.h
+++ b/dm/DMCpuTask.h
@@ -22,7 +22,7 @@
             TaskRunner*,
             const Expectations&,
             skiagm::GMRegistry::Factory,
-            SkBitmap::Config);
+            SkColorType);
 
     virtual void draw() SK_OVERRIDE;
     virtual bool usesGpu() const SK_OVERRIDE { return false; }
@@ -34,7 +34,7 @@
     SkAutoTDelete<skiagm::GM> fGM;
     const SkString fName;
     const Expectations& fExpectations;
-    const SkBitmap::Config fConfig;
+    const SkColorType fColorType;
 };
 
 }  // namespace DM
diff --git a/dm/DMGpuTask.cpp b/dm/DMGpuTask.cpp
index c0502ee..f787e25 100644
--- a/dm/DMGpuTask.cpp
+++ b/dm/DMGpuTask.cpp
@@ -4,7 +4,7 @@
 #include "DMUtil.h"
 #include "DMWriteTask.h"
 #include "SkCommandLineFlags.h"
-#include "SkGpuDevice.h"
+#include "SkSurface.h"
 #include "SkTLS.h"
 
 namespace DM {
@@ -14,14 +14,14 @@
                  TaskRunner* taskRunner,
                  const Expectations& expectations,
                  skiagm::GMRegistry::Factory gmFactory,
-                 SkBitmap::Config config,
+                 SkColorType colorType,
                  GrContextFactory::GLContextType contextType,
                  int sampleCount)
     : Task(reporter, taskRunner)
     , fGM(gmFactory(NULL))
     , fName(UnderJoin(fGM->shortName(), name))
     , fExpectations(expectations)
-    , fConfig(config)
+    , fColorType(colorType)
     , fContextType(contextType)
     , fSampleCount(sampleCount)
     {}
@@ -41,20 +41,19 @@
 
 void GpuTask::draw() {
     GrContext* gr = get_gr_factory()->get(fContextType);  // Will be owned by device.
-    SkGpuDevice device(gr,
-                       fConfig,
-                       SkScalarCeilToInt(fGM->width()),
-                       SkScalarCeilToInt(fGM->height()),
-                       fSampleCount);
-    SkCanvas canvas(&device);
+    SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
+                                         SkScalarCeilToInt(fGM->height()),
+                                         fColorType, kPremul_SkAlphaType);
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSampleCount));
+    SkCanvas* canvas = surface->getCanvas();
 
-    canvas.concat(fGM->getInitialTransform());
-    fGM->draw(&canvas);
-    canvas.flush();
+    canvas->concat(fGM->getInitialTransform());
+    fGM->draw(canvas);
+    canvas->flush();
 
     SkBitmap bitmap;
-    bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
-    canvas.readPixels(&bitmap, 0, 0);
+    bitmap.setConfig(info);
+    canvas->readPixels(&bitmap, 0, 0);
 
 #if GR_CACHE_STATS
     gr->printCacheStats();
diff --git a/dm/DMGpuTask.h b/dm/DMGpuTask.h
index aa350c9..a3fe52b 100644
--- a/dm/DMGpuTask.h
+++ b/dm/DMGpuTask.h
@@ -22,7 +22,7 @@
             TaskRunner*,
             const Expectations&,
             skiagm::GMRegistry::Factory,
-            SkBitmap::Config,
+            SkColorType,
             GrContextFactory::GLContextType,
             int sampleCount);
 
@@ -35,7 +35,7 @@
     SkAutoTDelete<skiagm::GM> fGM;
     const SkString fName;
     const Expectations& fExpectations;
-    const SkBitmap::Config fConfig;
+    const SkColorType fColorType;
     const GrContextFactory::GLContextType fContextType;
     const int fSampleCount;
 };
diff --git a/dm/DMPipeTask.cpp b/dm/DMPipeTask.cpp
index de3897a..163f1e6 100644
--- a/dm/DMPipeTask.cpp
+++ b/dm/DMPipeTask.cpp
@@ -47,7 +47,7 @@
 
 void PipeTask::draw() {
     SkBitmap bitmap;
-    SetupBitmap(fReference.config(), fGM.get(), &bitmap);
+    SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
 
     SkCanvas canvas(bitmap);
     PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
diff --git a/dm/DMReplayTask.cpp b/dm/DMReplayTask.cpp
index af8669b..3b47962 100644
--- a/dm/DMReplayTask.cpp
+++ b/dm/DMReplayTask.cpp
@@ -27,7 +27,7 @@
     RecordPicture(fGM.get(), &recorded, flags);
 
     SkBitmap bitmap;
-    SetupBitmap(fReference.config(), fGM.get(), &bitmap);
+    SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
     DrawPicture(&recorded, &bitmap);
     if (!BitmapsEqual(bitmap, fReference)) {
         this->fail();
diff --git a/dm/DMSerializeTask.cpp b/dm/DMSerializeTask.cpp
index 3359f2e..7e45d49 100644
--- a/dm/DMSerializeTask.cpp
+++ b/dm/DMSerializeTask.cpp
@@ -29,7 +29,7 @@
     SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
 
     SkBitmap bitmap;
-    SetupBitmap(fReference.config(), fGM.get(), &bitmap);
+    SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
     DrawPicture(reconstructed, &bitmap);
     if (!BitmapsEqual(bitmap, fReference)) {
         this->fail();
diff --git a/dm/DMTileGridTask.cpp b/dm/DMTileGridTask.cpp
index cd3c7b7..beffbb0 100644
--- a/dm/DMTileGridTask.cpp
+++ b/dm/DMTileGridTask.cpp
@@ -34,12 +34,12 @@
     RecordPicture(fGM.get(), &recorded, SkPicture::kUsePathBoundsForClip_RecordingFlag);
 
     SkBitmap full;
-    SetupBitmap(fReference.config(), fGM.get(), &full);
+    SetupBitmap(fReference.colorType(), fGM.get(), &full);
     SkCanvas fullCanvas(full);
 
     SkBitmap tile;
-    tile.setConfig(fReference.config(), fTileSize.width(), fTileSize.height());
-    tile.allocPixels();
+    tile.allocPixels(SkImageInfo::Make(fTileSize.width(), fTileSize.height(),
+                                       fReference.colorType(), kPremul_SkAlphaType));
     SkCanvas tileCanvas(tile);
 
     SkPaint paint;
diff --git a/dm/DMUtil.cpp b/dm/DMUtil.cpp
index 52efda3..849d1bf 100644
--- a/dm/DMUtil.cpp
+++ b/dm/DMUtil.cpp
@@ -19,10 +19,10 @@
     picture->endRecording();
 }
 
-void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) {
+void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) {
     const SkISize size = gm->getISize();
-    bitmap->setConfig(config, size.width(), size.height());
-    bitmap->allocPixels();
+    bitmap->allocPixels(SkImageInfo::Make(size.width(), size.height(),
+                                          ct, kPremul_SkAlphaType));
     bitmap->eraseColor(0x00000000);
 }
 
diff --git a/dm/DMUtil.h b/dm/DMUtil.h
index b887d82..a791649 100644
--- a/dm/DMUtil.h
+++ b/dm/DMUtil.h
@@ -16,7 +16,7 @@
 void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags = 0);
 
 // Prepare bitmap to have gm draw into it with this config.
-void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap);
+void SetupBitmap(const SkColorType, skiagm::GM* gm, SkBitmap* bitmap);
 
 // Draw picture to bitmap.
 void DrawPicture(SkPicture* picture, SkBitmap* bitmap);