Split SkDevice into SkBaseDevice and SkBitmapDevice

https://codereview.chromium.org/22978012/



git-svn-id: http://skia.googlecode.com/svn/trunk@10995 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 26896fc..24c3348 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -779,7 +779,7 @@
 
         SkBitmap deferredStore;
         createBitmap(&deferredStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-        SkDevice deferredDevice(deferredStore);
+        SkBitmapDevice deferredDevice(deferredStore);
         SkAutoTUnref<SkDeferredCanvas> deferredCanvas(SkDeferredCanvas::Create(&deferredDevice));
         testStep->setAssertMessageFormat(kDeferredDrawAssertMessageFormat);
         testStep->draw(deferredCanvas, reporter);
@@ -821,7 +821,7 @@
 
     SkBitmap indirectStore;
     createBitmap(&indirectStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice indirectDevice(indirectStore);
+    SkBitmapDevice indirectDevice(indirectStore);
     SkCanvas indirectCanvas(&indirectDevice);
     SkProxyCanvas proxyCanvas(&indirectCanvas);
     testStep->setAssertMessageFormat(kProxyDrawAssertMessageFormat);
@@ -844,12 +844,12 @@
 
     SkBitmap indirectStore1;
     createBitmap(&indirectStore1, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice indirectDevice1(indirectStore1);
+    SkBitmapDevice indirectDevice1(indirectStore1);
     SkCanvas indirectCanvas1(&indirectDevice1);
 
     SkBitmap indirectStore2;
     createBitmap(&indirectStore2, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice indirectDevice2(indirectStore2);
+    SkBitmapDevice indirectDevice2(indirectStore2);
     SkCanvas indirectCanvas2(&indirectDevice2);
 
     SkISize canvasSize = referenceCanvas.getDeviceSize();
@@ -882,7 +882,7 @@
                                          CanvasTestStep* testStep) {
     SkBitmap referenceStore;
     createBitmap(&referenceStore, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice referenceDevice(referenceStore);
+    SkBitmapDevice referenceDevice(referenceStore);
     SkCanvas referenceCanvas(&referenceDevice);
     testStep->setAssertMessageFormat(kCanvasDrawAssertMessageFormat);
     testStep->draw(&referenceCanvas, reporter);
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 15474f5..7593ba8 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -7,9 +7,9 @@
  */
 #include "Test.h"
 #include "SkBitmap.h"
+#include "SkBitmapDevice.h"
 #include "SkBitmapProcShader.h"
 #include "SkDeferredCanvas.h"
-#include "SkDevice.h"
 #include "SkGradientShader.h"
 #include "SkShader.h"
 #include "../src/image/SkSurface_Base.h"
@@ -33,7 +33,7 @@
     SkBitmap store;
 
     create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
 
     canvas->clear(0x00000000);
@@ -259,7 +259,7 @@
     SkBitmap store;
 
     create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
 
     canvas->clear(0x00000000);
@@ -279,7 +279,7 @@
     partialRect.setXYWH(SkIntToScalar(0), SkIntToScalar(0),
         SkIntToScalar(1), SkIntToScalar(1));
     create(&store, SkBitmap::kARGB_8888_Config, 0xFFFFFFFF);
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
 
     // verify that frame is intially fresh
@@ -433,9 +433,9 @@
     }
 }
 
-class MockDevice : public SkDevice {
+class MockDevice : public SkBitmapDevice {
 public:
-    MockDevice(const SkBitmap& bm) : SkDevice(bm) {
+    MockDevice(const SkBitmap& bm) : SkBitmapDevice(bm) {
         fDrawBitmapCallCount = 0;
     }
     virtual void drawBitmap(const SkDraw&, const SkBitmap&,
@@ -502,7 +502,7 @@
     SkBitmap store;
     store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
     store.allocPixels();
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     NotificationCounter notificationCounter;
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
     canvas->setNotificationClient(&notificationCounter);
@@ -585,7 +585,7 @@
     SkBitmap store;
     store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
     store.allocPixels();
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     NotificationCounter notificationCounter;
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
     canvas->setNotificationClient(&notificationCounter);
@@ -606,7 +606,7 @@
     SkBitmap store;
     store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
     store.allocPixels();
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
     // test will fail if nbIterations is not in sync with
     // BITMAPS_TO_KEEP in SkGPipeWrite.cpp
@@ -652,7 +652,7 @@
 
     // 1 under : should not store the image
     {
-        SkDevice device(store);
+        SkBitmapDevice device(store);
         SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
         canvas->setBitmapSizeThreshold(39999);
         canvas->drawBitmap(sourceImage, 0, 0, NULL);
@@ -662,7 +662,7 @@
 
     // exact value : should store the image
     {
-        SkDevice device(store);
+        SkBitmapDevice device(store);
         SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
         canvas->setBitmapSizeThreshold(40000);
         canvas->drawBitmap(sourceImage, 0, 0, NULL);
@@ -672,7 +672,7 @@
 
     // 1 over : should still store the image
     {
-        SkDevice device(store);
+        SkBitmapDevice device(store);
         SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
         canvas->setBitmapSizeThreshold(40001);
         canvas->drawBitmap(sourceImage, 0, 0, NULL);
@@ -807,11 +807,11 @@
     SkBitmap store;
     store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
     store.allocPixels();
-    SkDevice device(store);
+    SkBitmapDevice device(store);
     NotificationCounter notificationCounter;
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(&device));
     canvas->setNotificationClient(&notificationCounter);
-    SkAutoTUnref<SkDevice> secondaryDevice(canvas->createCompatibleDevice(
+    SkAutoTUnref<SkBaseDevice> secondaryDevice(canvas->createCompatibleDevice(
         SkBitmap::kARGB_8888_Config, 10, 10, device.isOpaque()));
     SkCanvas secondaryCanvas(secondaryDevice.get());
     SkRect rect = SkRect::MakeWH(5, 5);
diff --git a/tests/GradientTest.cpp b/tests/GradientTest.cpp
index cf8fbee..24ffb53 100644
--- a/tests/GradientTest.cpp
+++ b/tests/GradientTest.cpp
@@ -6,12 +6,12 @@
  * found in the LICENSE file.
  */
 #include "Test.h"
-#include "SkDevice.h"
-#include "SkTemplates.h"
-#include "SkShader.h"
+#include "SkBitmapDevice.h"
 #include "SkColorShader.h"
 #include "SkEmptyShader.h"
 #include "SkGradientShader.h"
+#include "SkShader.h"
+#include "SkTemplates.h"
 
 struct GradRec {
     int             fColorCount;
@@ -146,7 +146,7 @@
     outBitmap.allocPixels();
     SkPaint paint;
     paint.setShader(s.get());
-    SkDevice device(outBitmap);
+    SkBitmapDevice device(outBitmap);
     SkCanvas canvas(&device);
     canvas.drawPaint(paint);
     SkAutoLockPixels alp(outBitmap);
diff --git a/tests/LayerDrawLooperTest.cpp b/tests/LayerDrawLooperTest.cpp
index daadc86..8b1aa0d 100644
--- a/tests/LayerDrawLooperTest.cpp
+++ b/tests/LayerDrawLooperTest.cpp
@@ -6,9 +6,9 @@
  */
 #include "Test.h"
 #include "SkBitmap.h"
+#include "SkBitmapDevice.h"
 #include "SkCanvas.h"
 #include "SkDraw.h"
-#include "SkDevice.h"
 #include "SkLayerDrawLooper.h"
 #include "SkMatrix.h"
 #include "SkPaint.h"
@@ -19,17 +19,20 @@
 
 namespace {
 
-class FakeDevice : public SkDevice {
+class FakeDevice : public SkBitmapDevice {
 public:
-    FakeDevice() : SkDevice(SkBitmap::kARGB_8888_Config, 100, 100) { }
+    FakeDevice() : SkBitmapDevice(SkBitmap::kARGB_8888_Config, 100, 100, false) { }
 
     virtual void drawRect(const SkDraw& draw, const SkRect& r,
                           const SkPaint& paint) SK_OVERRIDE {
         fLastMatrix = *draw.fMatrix;
-        SkDevice::drawRect(draw, r, paint);
+        INHERITED::drawRect(draw, r, paint);
     }
 
     SkMatrix fLastMatrix;
+
+private:
+    typedef SkBitmapDevice INHERITED;
 };
 
 } // namespace
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index f823806..349560b 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -5,19 +5,19 @@
  * found in the LICENSE file.
  */
 #include "Test.h"
+#include "SkBitmapDevice.h"
 #include "SkCanvas.h"
 #include "SkColorPriv.h"
 #include "SkData.h"
-#include "SkDevice.h"
 #include "SkError.h"
 #include "SkPaint.h"
 #include "SkPicture.h"
+#include "SkPictureUtils.h"
 #include "SkRandom.h"
 #include "SkRRect.h"
 #include "SkShader.h"
 #include "SkStream.h"
 
-#include "SkPictureUtils.h"
 
 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) {
     bm->setConfig(SkBitmap::kARGB_8888_Config, w, h);
@@ -556,7 +556,7 @@
  */
 class ClipCountingCanvas : public SkCanvas {
 public:
-    explicit ClipCountingCanvas(SkDevice* device)
+    explicit ClipCountingCanvas(SkBaseDevice* device)
         : SkCanvas(device)
         , fClipCount(0){
     }
@@ -599,7 +599,7 @@
     p.setColor(SK_ColorBLUE);
     canvas->drawPaint(p);
 
-    SkDevice testDevice(SkBitmap::kNo_Config, 10, 10);
+    SkBitmapDevice testDevice(SkBitmap::kNo_Config, 10, 10);
     ClipCountingCanvas testCanvas(&testDevice);
     picture.draw(&testCanvas);
 
diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp
index 28150d6..79b32f9 100644
--- a/tests/PremulAlphaRoundTripTest.cpp
+++ b/tests/PremulAlphaRoundTripTest.cpp
@@ -41,7 +41,7 @@
 };
 
 void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
-    SkAutoTUnref<SkDevice> device;
+    SkAutoTUnref<SkBaseDevice> device;
     for (int dtype = 0; dtype < 2; ++dtype) {
 
         int glCtxTypeCnt = 1;
@@ -52,10 +52,10 @@
 #endif
         for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
             if (0 == dtype) {
-                device.reset(new SkDevice(SkBitmap::kARGB_8888_Config,
-                                              256,
-                                              256,
-                                              false));
+                device.reset(new SkBitmapDevice(SkBitmap::kARGB_8888_Config,
+                                                256,
+                                                256,
+                                                false));
             } else {
 #if SK_SUPPORT_GPU
                 GrContextFactory::GLContextType type =
diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp
index 24f5954..9cc1074 100644
--- a/tests/ReadPixelsTest.cpp
+++ b/tests/ReadPixelsTest.cpp
@@ -311,9 +311,10 @@
         }
 #endif
         for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
-            SkAutoTUnref<SkDevice> device;
+            SkAutoTUnref<SkBaseDevice> device;
             if (0 == dtype) {
-                device.reset(new SkDevice(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H, false));
+                device.reset(new SkBitmapDevice(SkBitmap::kARGB_8888_Config, 
+                                                DEV_W, DEV_H, false));
             } else {
 #if SK_SUPPORT_GPU
                 GrContextFactory::GLContextType type =
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 7830669..8ae936e 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -82,7 +82,7 @@
         REPORTER_ASSERT(reporter, match);
 
         // Now try writing on the single channel texture
-        SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, texture->asRenderTarget()));
+        SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(context, texture->asRenderTarget()));
         SkCanvas canvas(device);
 
         SkPaint paint;
diff --git a/tests/TileGridTest.cpp b/tests/TileGridTest.cpp
index f4a0af8..ae20cdd 100644
--- a/tests/TileGridTest.cpp
+++ b/tests/TileGridTest.cpp
@@ -7,10 +7,10 @@
  */
 
 #include "Test.h"
+#include "SkBitmapDevice.h"
+#include "SkCanvas.h"
 #include "SkTileGrid.h"
 #include "SkTileGridPicture.h"
-#include "SkCanvas.h"
-#include "SkDevice.h"
 
 enum Tile {
     kTopLeft_Tile = 0x1,
@@ -24,7 +24,7 @@
 namespace {
 class MockCanvas : public SkCanvas {
 public:
-    MockCanvas(SkDevice* device) : SkCanvas(device)
+    MockCanvas(SkBaseDevice* device) : SkCanvas(device)
     {}
 
     virtual void drawRect(const SkRect& rect, const SkPaint&)
@@ -80,14 +80,14 @@
 
         // Test parts of top-left tile
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             picture.draw(&mockCanvas);
             REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
             REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
         }
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-7.99f), SkFloatToScalar(-7.99f));
             picture.draw(&mockCanvas);
@@ -96,7 +96,7 @@
         }
         // Corner overlap
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-9.5f), SkFloatToScalar(-9.5f));
             picture.draw(&mockCanvas);
@@ -106,7 +106,7 @@
         }
         // Intersect bottom right tile, but does not overlap rect 2
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-16.0f));
             picture.draw(&mockCanvas);
@@ -115,7 +115,7 @@
         }
         // Out of bounds queries, snap to border tiles
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(2.0f), SkFloatToScalar(0.0f));
             picture.draw(&mockCanvas);
@@ -123,7 +123,7 @@
             REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
         }
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(0.0f), SkFloatToScalar(2.0f));
             picture.draw(&mockCanvas);
@@ -131,7 +131,7 @@
             REPORTER_ASSERT(reporter, rect1 == mockCanvas.fRects[0]);
         }
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-22.0f), SkFloatToScalar(-16.0f));
             picture.draw(&mockCanvas);
@@ -139,7 +139,7 @@
             REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
         }
         {
-            SkDevice device(store);
+            SkBitmapDevice device(store);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-16.0f), SkFloatToScalar(-22.0f));
             picture.draw(&mockCanvas);
@@ -185,7 +185,7 @@
         {
             // The offset should cancel the top and left borders of the top left tile
             // So a look-up at interval 0-10 should be grid aligned,
-            SkDevice device(tileBitmap);
+            SkBitmapDevice device(tileBitmap);
             MockCanvas mockCanvas(&device);
             picture.draw(&mockCanvas);
             REPORTER_ASSERT(reporter, 1 == mockCanvas.fRects.count());
@@ -193,7 +193,7 @@
         }
         {
             // Encroaching border by one pixel
-            SkDevice device(moreThanATileBitmap);
+            SkBitmapDevice device(moreThanATileBitmap);
             MockCanvas mockCanvas(&device);
             picture.draw(&mockCanvas);
             REPORTER_ASSERT(reporter, 2 == mockCanvas.fRects.count());
@@ -204,7 +204,7 @@
             // Tile stride is 8 (tileWidth - 2 * border pixels
             // so translating by 8, should make query grid-aligned
             // with middle tile.
-            SkDevice device(tileBitmap);
+            SkBitmapDevice device(tileBitmap);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkIntToScalar(-8), SkIntToScalar(-8));
             picture.draw(&mockCanvas);
@@ -212,7 +212,7 @@
             REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[0]);
         }
         {
-            SkDevice device(tileBitmap);
+            SkBitmapDevice device(tileBitmap);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-7.9f), SkFloatToScalar(-7.9f));
             picture.draw(&mockCanvas);
@@ -221,7 +221,7 @@
             REPORTER_ASSERT(reporter, rect2 == mockCanvas.fRects[1]);
         }
         {
-            SkDevice device(tileBitmap);
+            SkBitmapDevice device(tileBitmap);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-8.1f), SkFloatToScalar(-8.1f));
             picture.draw(&mockCanvas);
@@ -233,7 +233,7 @@
             // Regression test for crbug.com/234688
             // Once the 2x2 device region is inset by margin, it yields an empty
             // adjusted region, sitting right on top of the tile boundary.
-            SkDevice device(tinyBitmap);
+            SkBitmapDevice device(tinyBitmap);
             MockCanvas mockCanvas(&device);
             mockCanvas.translate(SkFloatToScalar(-8.0f), SkFloatToScalar(-8.0f));
             picture.draw(&mockCanvas);
diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp
index 202bfd6..3db3a2a 100644
--- a/tests/WritePixelsTest.cpp
+++ b/tests/WritePixelsTest.cpp
@@ -227,7 +227,7 @@
                 const SkBitmap& bitmap,
                 int writeX, int writeY,
                 SkCanvas::Config8888 config8888) {
-    SkDevice* dev = canvas->getDevice();
+    SkBaseDevice* dev = canvas->getDevice();
     if (!dev) {
         return false;
     }
@@ -305,7 +305,7 @@
 #endif
 };
 
-SkDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) {
+SkBaseDevice* createDevice(const CanvasConfig& c, GrContext* grCtx) {
     switch (c.fDevType) {
         case kRaster_DevType: {
             SkBitmap bmp;
@@ -320,7 +320,7 @@
                 SkAutoLockPixels alp(bmp);
                 memset(bmp.getPixels(), DEV_PAD, bmp.getSafeSize());
             }
-            return new SkDevice(bmp);
+            return new SkBitmapDevice(bmp);
         }
 #if SK_SUPPORT_GPU
         case kGpu_BottomLeft_DevType:
@@ -435,7 +435,7 @@
             }
 #endif
 
-            SkAutoTUnref<SkDevice> device(createDevice(gCanvasConfigs[i], context));
+            SkAutoTUnref<SkBaseDevice> device(createDevice(gCanvasConfigs[i], context));
             SkCanvas canvas(device);
 
             static const SkCanvas::Config8888 gSrcConfigs[] = {