remove (dumb) canvas::NewRaster, and rename surface::NewRasterPMColor to N32Premul

patch from issue 781403002 at patchset 20001 (http://crrev.com/781403002#ps20001)

BUG=skia:

Review URL: https://codereview.chromium.org/790733003
diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp
index ba6fffe..176c7bf 100644
--- a/gm/fatpathfill.cpp
+++ b/gm/fatpathfill.cpp
@@ -16,7 +16,7 @@
 #define REPEAT_LOOP 5
 
 static SkSurface* new_surface(int width, int height) {
-    return SkSurface::NewRasterPMColor(width, height);
+    return SkSurface::NewRasterN32Premul(width, height);
 }
 
 static void draw_pixel_centers(SkCanvas* canvas) {
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi
index aee4112..e2e85ac 100644
--- a/gyp/skia_for_chromium_defines.gypi
+++ b/gyp/skia_for_chromium_defines.gypi
@@ -15,6 +15,7 @@
     'skia_for_chromium_defines': [
       'SK_SUPPORT_LEGACY_TEXTRENDERMODE',
       'SK_IGNORE_GPU_LAYER_HOISTING',
+      'SK_SUPPORT_LEGACY_NewRasterPMColor',
     ],
   },
 }
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index ff60c57..46dc377 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -62,35 +62,6 @@
     SK_DECLARE_INST_COUNT(SkCanvas)
 
     /**
-     *  Attempt to allocate an offscreen raster canvas, matching the ImageInfo.
-     *  On success, return a new canvas that will draw into that offscreen.
-     *
-     *  The caller can access the pixels after drawing into this canvas by
-     *  calling readPixels() or peekPixels().
-     *
-     *  If the requested ImageInfo is opaque (either the colortype is
-     *  intrinsically opaque like RGB_565, or the info's alphatype is kOpaque)
-     *  then the pixel memory may be uninitialized. Otherwise, the pixel memory
-     *  will be initialized to 0, which is interpreted as transparent.
-     *
-     *  On failure, return NULL. This can fail for several reasons:
-     *  1. the memory allocation failed (e.g. request is too large)
-     *  2. invalid ImageInfo (e.g. negative dimensions)
-     *  3. unsupported ImageInfo for a canvas
-     *      - kUnknown_SkColorType, kIndex_8_SkColorType
-     *      - kIgnore_SkAlphaType
-     *      - this list is not complete, so others may also be unsupported
-     *
-     *  Note: it is valid to request a supported ImageInfo, but with zero
-     *  dimensions.
-     */
-    static SkCanvas* NewRaster(const SkImageInfo&);
-
-    static SkCanvas* NewRasterN32(int width, int height) {
-        return NewRaster(SkImageInfo::MakeN32Premul(width, height));
-    }
-
-    /**
      *  Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
      *  specified pixels. To access the pixels after drawing to them, the caller should call
      *  flush() or call peekPixels(...).
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 0e238f8..7563d09 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -61,9 +61,14 @@
      *  specified width and height, and populates the rest of info to match
      *  pixels in SkPMColor format.
      */
+#ifdef SK_SUPPORT_LEGACY_NewRasterPMColor
     static SkSurface* NewRasterPMColor(int width, int height, const SkSurfaceProps* props = NULL) {
         return NewRaster(SkImageInfo::MakeN32Premul(width, height), props);
     }
+#endif
+    static SkSurface* NewRasterN32Premul(int width, int height, const SkSurfaceProps* props = NULL) {
+        return NewRaster(SkImageInfo::MakeN32Premul(width, height), props);
+    }
 
     /**
      *  Return a new surface using the specified render target.
diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp
index df0c369..453624e 100644
--- a/samplecode/SamplePictFile.cpp
+++ b/samplecode/SamplePictFile.cpp
@@ -136,12 +136,6 @@
                 SkDebugf("coun't load picture at \"path\"\n", path);
             }
 
-            if (false) {
-                SkSurface* surf = SkSurface::NewRasterPMColor(SkScalarCeilToInt(pic->cullRect().width()), 
-                                                              SkScalarCeilToInt(pic->cullRect().height()));
-                surf->getCanvas()->drawPicture(pic);
-                surf->unref();
-            }
             if (false) { // re-record
                 SkPictureRecorder recorder;
                 pic->playback(recorder.beginRecording(pic->cullRect().width(),
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index a6f263f..8351a52 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2529,23 +2529,6 @@
     return true;
 }
 
-SkCanvas* SkCanvas::NewRaster(const SkImageInfo& info) {
-    if (!supported_for_raster_canvas(info)) {
-        return NULL;
-    }
-
-    SkBitmap bitmap;
-    if (!bitmap.tryAllocPixels(info)) {
-        return NULL;
-    }
-
-    // should this functionality be moved into allocPixels()?
-    if (!bitmap.info().isOpaque()) {
-        bitmap.eraseColor(0);
-    }
-    return SkNEW_ARGS(SkCanvas, (bitmap));
-}
-
 SkCanvas* SkCanvas::NewRasterDirect(const SkImageInfo& info, void* pixels, size_t rowBytes) {
     if (!supported_for_raster_canvas(info)) {
         return NULL;
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index d5ddfe6..1f8f276 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -73,7 +73,7 @@
 }
 
 static SkSurface* createSurface(SkColor color) {
-    SkSurface* surface = SkSurface::NewRasterPMColor(kWidth, kHeight);
+    SkSurface* surface = SkSurface::NewRasterN32Premul(kWidth, kHeight);
     surface->getCanvas()->clear(color);
     return surface;
 }
@@ -748,7 +748,13 @@
 
 static void test_newraster(skiatest::Reporter* reporter) {
     SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
-    SkCanvas* canvas = SkCanvas::NewRaster(info);
+    const size_t minRowBytes = info.minRowBytes();
+    const size_t size = info.getSafeSize(minRowBytes);
+    SkAutoMalloc storage(size);
+    SkPMColor* baseAddr = static_cast<SkPMColor*>(storage.get());
+    sk_bzero(baseAddr, size);
+
+    SkCanvas* canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
     REPORTER_ASSERT(reporter, canvas);
 
     SkImageInfo info2;
@@ -756,6 +762,7 @@
     const SkPMColor* addr = (const SkPMColor*)canvas->peekPixels(&info2, &rowBytes);
     REPORTER_ASSERT(reporter, addr);
     REPORTER_ASSERT(reporter, info == info2);
+    REPORTER_ASSERT(reporter, minRowBytes == rowBytes);
     for (int y = 0; y < info.height(); ++y) {
         for (int x = 0; x < info.width(); ++x) {
             REPORTER_ASSERT(reporter, 0 == addr[x]);
@@ -766,19 +773,19 @@
 
     // now try a deliberately bad info
     info = info.makeWH(-1, info.height());
-    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info));
+    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
 
     // too big
     info = info.makeWH(1 << 30, 1 << 30);
-    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info));
+    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
 
     // not a valid pixel type
     info = SkImageInfo::Make(10, 10, kUnknown_SkColorType, info.alphaType());
-    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRaster(info));
+    REPORTER_ASSERT(reporter, NULL == SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes));
 
     // We should succeed with a zero-sized valid info
     info = SkImageInfo::MakeN32Premul(0, 0);
-    canvas = SkCanvas::NewRaster(info);
+    canvas = SkCanvas::NewRasterDirect(info, baseAddr, minRowBytes);
     REPORTER_ASSERT(reporter, canvas);
     SkDELETE(canvas);
 }
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 043fe33..1c1970a 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -32,7 +32,7 @@
 }
 
 static SkSurface* createSurface(SkColor color) {
-    SkSurface* surface = SkSurface::NewRasterPMColor(gWidth, gHeight);
+    SkSurface* surface = SkSurface::NewRasterN32Premul(gWidth, gHeight);
     surface->getCanvas()->clear(color);
     return surface;
 }
@@ -451,7 +451,7 @@
 // Verifies that the deferred canvas triggers a flush when its memory
 // limit is exceeded
 static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
 
     NotificationCounter notificationCounter;
@@ -486,7 +486,7 @@
 }
 
 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
 
     NotificationCounter notificationCounter;
@@ -566,7 +566,7 @@
 }
 
 static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
 
     NotificationCounter notificationCounter;
@@ -585,7 +585,7 @@
     // This test covers a code path that inserts bitmaps into the bitmap heap through the
     // flattening of SkBitmapProcShaders. The refcount in the bitmap heap is maintained through
     // the flattening and unflattening of the shader.
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
     // test will fail if nbIterations is not in sync with
     // BITMAPS_TO_KEEP in SkGPipeWrite.cpp
@@ -620,7 +620,7 @@
 }
 
 static void TestDeferredCanvasBitmapSizeThreshold(skiatest::Reporter* reporter) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
 
     SkBitmap sourceImage;
     // 100 by 100 image, takes 40,000 bytes in memory
@@ -811,7 +811,7 @@
 }
 
 static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporter) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
 
     NotificationCounter notificationCounter;
@@ -842,7 +842,7 @@
 
     SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
-    SkSurface* newSurface = SkSurface::NewRasterPMColor(4, 4);
+    SkSurface* newSurface = SkSurface::NewRasterN32Premul(4, 4);
     SkAutoTUnref<SkSurface> aur(newSurface);
 
     for (int i = 0; i < 2; ++i) {
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index 71ad2cf..c1e34a2 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -43,7 +43,7 @@
     REPORTER_ASSERT(reporter, installSuccess);
     // now our bitmap has a pixelref, but we know it will fail to lock
 
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(200, 200));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200));
     SkCanvas* canvas = surface->getCanvas();
 
     const SkPaint::FilterLevel levels[] = {
diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp
index 2af4224..67af755 100644
--- a/tests/DrawPathTest.cpp
+++ b/tests/DrawPathTest.cpp
@@ -17,7 +17,7 @@
     SkPMColor pixel[1];
     output.installPixels(SkImageInfo::MakeN32Premul(1, 1), pixel, 4);
 
-    SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300);
+    SkSurface* surf = SkSurface::NewRasterN32Premul(300, 33300);
     SkCanvas* canvas = surf->getCanvas();
 
     SkRect r = { 0, 33000, 300, 33300 };
@@ -94,11 +94,11 @@
     moveToH(&path, &data[0]);
     cubicToH(&path, &data[2]);
 
-    SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
 
     SkPaint paint;
     paint.setAntiAlias(true);
-    canvas->drawPath(path, paint);
+    surface->getCanvas()->drawPath(path, paint);
 }
 
 // This used to assert in debug builds (and crash writing bad memory in release)
@@ -125,38 +125,36 @@
 static void test_inversepathwithclip() {
     SkPath path;
 
-    path.moveTo(0, SkIntToScalar(20));
-    path.quadTo(SkIntToScalar(10), SkIntToScalar(10),
-                SkIntToScalar(20), SkIntToScalar(20));
+    path.moveTo(0, 20);
+    path.quadTo(10, 10, 20, 20);
     path.toggleInverseFillType();
 
     SkPaint paint;
 
-    SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
-    canvas.get()->save();
-    canvas.get()->clipRect(SkRect::MakeWH(SkIntToScalar(19), SkIntToScalar(11)));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
+    SkCanvas* canvas = surface->getCanvas();
+    canvas->save();
+    canvas->clipRect(SkRect::MakeWH(19, 11));
 
     paint.setAntiAlias(false);
-    canvas.get()->drawPath(path, paint);
+    canvas->drawPath(path, paint);
     paint.setAntiAlias(true);
-    canvas.get()->drawPath(path, paint);
+    canvas->drawPath(path, paint);
 
-    canvas.get()->restore();
+    canvas->restore();
 
     // Now do the test again, with the path flipped, so we only draw in the
     // top half of our bounds, and have the clip intersect our bounds at the
     // bottom.
     path.reset();   // preserves our filltype
-    path.moveTo(0, SkIntToScalar(10));
-    path.quadTo(SkIntToScalar(10), SkIntToScalar(20),
-                SkIntToScalar(20), SkIntToScalar(10));
-    canvas.get()->clipRect(SkRect::MakeXYWH(SkIntToScalar(0), SkIntToScalar(19),
-                                            SkIntToScalar(19), SkIntToScalar(11)));
+    path.moveTo(0, 10);
+    path.quadTo(10, 20, 20, 10);
+    canvas->clipRect(SkRect::MakeXYWH(0, 19, 19, 11));
 
     paint.setAntiAlias(false);
-    canvas.get()->drawPath(path, paint);
+    canvas->drawPath(path, paint);
     paint.setAntiAlias(true);
-    canvas.get()->drawPath(path, paint);
+    canvas->drawPath(path, paint);
 }
 
 static void test_bug533() {
@@ -172,8 +170,8 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
-    canvas.get()->drawPath(path, paint);
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
+    surface->getCanvas()->drawPath(path, paint);
 }
 
 static void test_crbug_140642() {
@@ -214,8 +212,8 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(640, 480));
-    canvas.get()->drawPath(path, paint);
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
+    surface->getCanvas()->drawPath(path, paint);
 }
 
 // we used to assert if the bounds of the device (clip) was larger than 32K
@@ -224,13 +222,13 @@
 static void test_giantaa() {
     const int W = 400;
     const int H = 400;
-    SkAutoTUnref<SkCanvas> canvas(SkCanvas::NewRasterN32(33000, 10));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(33000, 10));
 
     SkPaint paint;
     paint.setAntiAlias(true);
     SkPath path;
     path.addOval(SkRect::MakeXYWH(-10, -10, 20 + W, 20 + H));
-    canvas.get()->drawPath(path, paint);
+    surface->getCanvas()->drawPath(path, paint);
 }
 
 // Extremely large path_length/dash_length ratios may cause infinite looping
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 4588619..d09f8a2 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -54,7 +54,7 @@
 static void test_path_crbug364224() {
     SkPath path;
     SkPaint paint;
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
     SkCanvas* canvas = surface->getCanvas();
 
     make_path_crbug364224_simplified(&path);
@@ -299,7 +299,7 @@
 
     SkPaint paint;
     paint.setAntiAlias(true);
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
     surface->getCanvas()->drawPath(path, paint);
 }
 
@@ -418,7 +418,7 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
 
     build_path_simple_170666(path);
     surface->getCanvas()->drawPath(path, paint);
@@ -497,7 +497,7 @@
 }
 
 static void test_clipped_cubic() {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
 
     // This path used to assert, because our cubic-chopping code incorrectly
     // moved control points after the chop. This test should be run in SK_DEBUG
@@ -533,7 +533,7 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkSurface* surface = SkSurface::NewRasterPMColor(19, 130);
+    SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130);
     surface->getCanvas()->drawPath(path, paint);
     surface->unref();
 }
diff --git a/tests/RecordDrawTest.cpp b/tests/RecordDrawTest.cpp
index 30be24c..2d9e90d 100644
--- a/tests/RecordDrawTest.cpp
+++ b/tests/RecordDrawTest.cpp
@@ -286,7 +286,7 @@
         bool fDrawImageRectCalled;
     };
 
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(10, 10));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10));
     surface->getCanvas()->clear(SK_ColorGREEN);
     SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
 
diff --git a/tests/RecorderTest.cpp b/tests/RecorderTest.cpp
index d81bf05..7a27556 100644
--- a/tests/RecorderTest.cpp
+++ b/tests/RecorderTest.cpp
@@ -155,7 +155,7 @@
 
     SkAutoTUnref<SkImage> image;
     {
-        SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
+        SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
         surface->getCanvas()->clear(SK_ColorGREEN);
         image.reset(surface->newImageSnapshot());
     }
diff --git a/tests/SkResourceCacheTest.cpp b/tests/SkResourceCacheTest.cpp
index 0e94175..e1f8a65 100644
--- a/tests/SkResourceCacheTest.cpp
+++ b/tests/SkResourceCacheTest.cpp
@@ -11,6 +11,7 @@
 #include "SkDiscardableMemoryPool.h"
 #include "SkGraphics.h"
 #include "SkResourceCache.h"
+#include "SkSurface.h"
 
 static const int kCanvasSize = 1;
 static const int kBitmapSize = 16;
@@ -27,8 +28,8 @@
 
 // Draw a scaled bitmap, then return true iff it has been cached.
 static bool test_scaled_image_cache_useage() {
-    SkAutoTUnref<SkCanvas> canvas(
-            SkCanvas::NewRasterN32(kCanvasSize, kCanvasSize));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kCanvasSize, kCanvasSize));
+    SkCanvas* canvas = surface->getCanvas();
     SkBitmap bitmap;
     bitmap.allocN32Pixels(kBitmapSize, kBitmapSize);
     bitmap.eraseColor(0xFFFFFFFF);
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index 55748d2..9f05434 100644
--- a/tools/skhello.cpp
+++ b/tools/skhello.cpp
@@ -33,7 +33,7 @@
 
 static bool do_surface(int w, int h, const char path[], const char text[],
                        const SkPaint& paint) {
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(w, h));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(w, h));
     doDraw(surface->getCanvas(), paint, text);
 
     SkAutoTUnref<SkImage> image(surface->newImageSnapshot());