remove SkCanvas::createCompatibleDevice, and add SkCanvas::newSurface

BUG=skia:
R=bsalomon@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13319 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 4b4f453..5e70b1a 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -10,6 +10,7 @@
 #include "SkDraw.h"
 #include "SkRasterClip.h"
 #include "SkShader.h"
+#include "SkSurface.h"
 
 #define CHECK_FOR_ANNOTATION(paint) \
     do { if (paint.getAnnotation()) { return; } } while (0)
@@ -381,6 +382,10 @@
     draw.drawSprite(src, x, y, paint);
 }
 
+SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info) {
+    return SkSurface::NewRaster(info);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 bool SkBitmapDevice::filterTextFlags(const SkPaint& paint, TextFlags* flags) {
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 08b09e8..6f4e88d 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -832,6 +832,26 @@
     return this->internalSaveLayer(bounds, paint, flags, false);
 }
 
+static SkBaseDevice* createCompatibleDevice(SkCanvas* canvas,
+                                            SkBitmap::Config config,
+                                            int width, int height,
+                                            bool isOpaque) {
+    SkBaseDevice* device = canvas->getDevice();
+    if (device) {
+        return device->createCompatibleDevice(config, width, height, isOpaque);
+    } else {
+        return NULL;
+    }
+}
+
+#ifdef SK_SUPPORT_LEGACY_CANVAS_CREATECOMPATIBLEDEVICE
+SkBaseDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config,
+                                               int width, int height,
+                                               bool isOpaque) {
+    return createCompatibleDevice(this, config, width, height, isOpaque);
+}
+#endif
+
 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint,
                                 SaveFlags flags, bool justForImageFilter) {
     // do this before we create the layer. We don't call the public save() since
@@ -864,8 +884,8 @@
 
     SkBaseDevice* device;
     if (paint && paint->getImageFilter()) {
-        device = this->createCompatibleDevice(config, ir.width(), ir.height(),
-                                              isOpaque);
+        device = createCompatibleDevice(this, config, ir.width(), ir.height(),
+                                        isOpaque);
     } else {
         device = this->createLayerDevice(config, ir.width(), ir.height(),
                                          isOpaque);
@@ -964,6 +984,15 @@
     return fSaveLayerCount > 0;
 }
 
+SkSurface* SkCanvas::newSurface(const SkImageInfo& info) {
+    return this->onNewSurface(info);
+}
+
+SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info) {
+    SkBaseDevice* dev = this->getDevice();
+    return dev ? dev->newSurface(info) : NULL;
+}
+
 /////////////////////////////////////////////////////////////////////////////
 
 // can't draw it if its empty, or its too big for a fixed-point width or height
@@ -1548,17 +1577,6 @@
     }
 }
 
-SkBaseDevice* SkCanvas::createCompatibleDevice(SkBitmap::Config config,
-                                           int width, int height,
-                                           bool isOpaque) {
-    SkBaseDevice* device = this->getDevice();
-    if (device) {
-        return device->createCompatibleDevice(config, width, height, isOpaque);
-    } else {
-        return NULL;
-    }
-}
-
 GrContext* SkCanvas::getGrContext() {
 #if SK_SUPPORT_GPU
     SkBaseDevice* device = this->getTopDevice();
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index c08ae26..9ce8b6b 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
@@ -18,6 +17,7 @@
 #endif
 
 ///////////////////////////////////////////////////////////////////////////////
+
 SkBaseDevice::SkBaseDevice()
     : fLeakyProperties(SkDeviceProperties::MakeDefault())
 #ifdef SK_DEBUG
@@ -115,3 +115,5 @@
     }
     return result;
 }
+
+SkSurface* SkBaseDevice::newSurface(const SkImageInfo&) { return NULL; }
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 3bf9851..5ce35d6 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -1,10 +1,10 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "SkPictureRecord.h"
 #include "SkTSearch.h"
 #include "SkPixelRef.h"
@@ -12,6 +12,7 @@
 #include "SkBBoxHierarchy.h"
 #include "SkDevice.h"
 #include "SkPictureStateTree.h"
+#include "SkSurface.h"
 
 #define HEAP_BLOCK_SIZE 4096
 
@@ -1316,6 +1317,10 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info) {
+    return SkSurface::NewPicture(info.fWidth, info.fHeight);
+}
+
 void SkPictureRecord::addBitmap(const SkBitmap& bitmap) {
     const int index = fBitmapHeap->insert(bitmap);
     // In debug builds, a bad return value from insert() will crash, allowing for debugging. In
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 3832516..6d14c62 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -1,10 +1,10 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #ifndef SkPictureRecord_DEFINED
 #define SkPictureRecord_DEFINED
 
@@ -215,6 +215,8 @@
 #endif
 
 protected:
+    virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE;
+
     // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been
     // tweaked by paint.computeFastBounds().
     static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index da56009..8c272f9 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -27,6 +27,7 @@
 #include "SkPathEffect.h"
 #include "SkRRect.h"
 #include "SkStroke.h"
+#include "SkSurface.h"
 #include "SkTLazy.h"
 #include "SkUtils.h"
 #include "SkErrorInternals.h"
@@ -1913,6 +1914,10 @@
     }
 }
 
+SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) {
+    return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples());
+}
+
 SkGpuDevice::SkGpuDevice(GrContext* context,
                          GrTexture* texture,
                          bool needClear)
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 1cb6d37..efc6546 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -173,6 +173,8 @@
     virtual void writePixels(const SkBitmap& bitmap, int x, int y,
                                 SkCanvas::Config8888 config8888) SK_OVERRIDE;
 
+    virtual SkSurface* newSurface(const SkImageInfo&) SK_OVERRIDE;
+
 protected:
     virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE;
     virtual bool onReadPixels(const SkBitmap& bitmap,
@@ -495,6 +497,10 @@
     return immediateDevice()->createCompatibleDevice(config, width, height, isOpaque);
 }
 
+SkSurface* DeferredDevice::newSurface(const SkImageInfo& info) {
+    return this->immediateDevice()->newSurface(info);
+}
+
 bool DeferredDevice::onReadPixels(
     const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) {
     this->flushPendingCommands(kNormal_PlaybackMode);