Clean up usage of SkSurfaceProps

This CL continues cleaning up Skia's usage of SkSurfaceProps. It:

  Removes the duplicate SkSurfaceProps object from SkImageFilter::Proxy.

  Removes a dispreferred ctor from SkCanvas

  Removes the initForRootLayer entry point from SkDevice (since the root device and the canvas should always have the same pixel geometry now).

Review URL: https://codereview.chromium.org/1201983006
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 6afaf3f..42627da 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1290,8 +1290,6 @@
         kConservativeRasterClip_InitFlag    = 1 << 0,
     };
     SkCanvas(const SkIRect& bounds, InitFlags);
-    // TODO: remove this ctor - the basedevice should already have surface props
-    SkCanvas(SkBaseDevice*, const SkSurfaceProps*, InitFlags);
     SkCanvas(SkBaseDevice* device, InitFlags);
 
     void resetForNextPicture(const SkIRect& bounds);
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 7217e2f..daca805 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -359,8 +359,6 @@
         return NULL;
     }
 
-    virtual void initForRootLayer(SkPixelGeometry geo);
-
 private:
     friend class SkCanvas;
     friend struct DeviceCM; //for setMatrixClip
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 3508df5..e0e97b0 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -80,21 +80,17 @@
 
     class Proxy {
     public:
-        Proxy(SkBaseDevice* device, const SkSurfaceProps& props)
-            : fDevice(device)
-            , fProps(props.flags(), kUnknown_SkPixelGeometry)
-        {}
+        Proxy(SkBaseDevice* device) : fDevice(device) { }
         
         SkBaseDevice* createDevice(int width, int height);
-        // returns true if the proxy handled the filter itself. if this returns
+
+        // Returns true if the proxy handled the filter itself. If this returns
         // false then the filter's code will be called.
         bool filterImage(const SkImageFilter*, const SkBitmap& src, const SkImageFilter::Context&,
                          SkBitmap* result, SkIPoint* offset);
-        const SkSurfaceProps& surfaceProps() const { return fProps; }
-        
+
     private:
-        SkBaseDevice*        fDevice;
-        const SkSurfaceProps fProps;
+        SkBaseDevice* fDevice;
     };
     
 
diff --git a/include/core/SkSurfaceProps.h b/include/core/SkSurfaceProps.h
index 9c90d3e..1083599 100644
--- a/include/core/SkSurfaceProps.h
+++ b/include/core/SkSurfaceProps.h
@@ -71,9 +71,6 @@
     bool isDisallowDither() const { return SkToBool(fFlags & kDisallowDither_Flag); }
     bool isUseDistanceFieldFonts() const { return SkToBool(fFlags & kUseDistanceFieldFonts_Flag); }
 
-    // TODO: remove this entry point
-    void setPixelGeometry_dont_use(SkPixelGeometry geo) { fPixelGeometry = geo; }
-
 private:
     SkSurfaceProps();
 
diff --git a/include/effects/SkPictureImageFilter.h b/include/effects/SkPictureImageFilter.h
index d62f03f..8294e1f 100644
--- a/include/effects/SkPictureImageFilter.h
+++ b/include/effects/SkPictureImageFilter.h
@@ -76,7 +76,7 @@
 private:
 
 
-    void drawPictureAtDeviceResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds,
+    void drawPictureAtDeviceResolution(SkBaseDevice*, const SkIRect& deviceBounds,
                                        const Context&) const;
     void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds,
                                       const Context&) const;
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f35727d..fcfb641 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -536,8 +536,8 @@
     fSurfaceBase = NULL;
 
     if (device) {
-        // TODO: remove this - the root device & canvas should always have same surfaceProps
-        device->initForRootLayer(fProps.pixelGeometry());
+        // The root device and the canvas should always have the same pixel geometry
+        SkASSERT(fProps.pixelGeometry() == device->surfaceProps().pixelGeometry());
         if (device->forceConservativeRasterClip()) {
             fConservativeRasterClip = true;
         }
@@ -595,16 +595,6 @@
     this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (bounds, fProps)), flags)->unref();
 }
 
-// TODO: remove this ctor
-SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags flags)
-    : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
-    , fProps(SkSurfacePropsCopyOrDefault(props))
-{
-    inc_canvas();
-
-    this->init(device, flags);
-}
-
 SkCanvas::SkCanvas(SkBaseDevice* device)
     : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage))
     , fProps(device->surfaceProps())
@@ -1256,7 +1246,7 @@
         SkImageFilter* filter = paint->getImageFilter();
         SkIPoint pos = { x - iter.getX(), y - iter.getY() };
         if (filter && !dstDev->canHandleImageFilter(filter)) {
-            SkImageFilter::Proxy proxy(dstDev, fProps);
+            SkImageFilter::Proxy proxy(dstDev);
             SkBitmap dst;
             SkIPoint offset = SkIPoint::Make(0, 0);
             const SkBitmap& src = srcDev->accessBitmap(false);
@@ -1308,7 +1298,7 @@
         SkImageFilter* filter = paint->getImageFilter();
         SkIPoint pos = { x - iter.getX(), y - iter.getY() };
         if (filter && !iter.fDevice->canHandleImageFilter(filter)) {
-            SkImageFilter::Proxy proxy(iter.fDevice, fProps);
+            SkImageFilter::Proxy proxy(iter.fDevice);
             SkBitmap dst;
             SkIPoint offset = SkIPoint::Make(0, 0);
             SkMatrix matrix = *iter.fMatrix;
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 4e9d4a2..15cd7ee 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -70,15 +70,6 @@
     return geo;
 }
 
-void SkBaseDevice::initForRootLayer(SkPixelGeometry geo) {
-    // For now we don't expect to change the geometry for the root-layer, but we make the call
-    // anyway to document logically what is going on.
-    //
-    fSurfaceProps.setPixelGeometry_dont_use(CreateInfo::AdjustGeometry(this->imageInfo(),
-                                                                       kPossible_TileUsage,
-                                                                       geo));
-}
-
 void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
                               const SkRRect& inner, const SkPaint& paint) {
     SkPath path;
diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp
index 91f4dc9..bf1ba8d 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -110,9 +110,9 @@
 
     if (kDeviceSpace_PictureResolution == fPictureResolution || 
         0 == (ctx.ctm().getType() & ~SkMatrix::kTranslate_Mask)) {
-        drawPictureAtDeviceResolution(proxy, device.get(), bounds, ctx);        
+        this->drawPictureAtDeviceResolution(device.get(), bounds, ctx);        
     } else {
-        drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
+        this->drawPictureAtLocalResolution(proxy, device.get(), bounds, ctx);
     }
 
     *result = device.get()->accessBitmap(false);
@@ -121,13 +121,10 @@
     return true;
 }
 
-void SkPictureImageFilter::drawPictureAtDeviceResolution(Proxy* proxy, SkBaseDevice* device,
+void SkPictureImageFilter::drawPictureAtDeviceResolution(SkBaseDevice* device,
                                                          const SkIRect& deviceBounds,
                                                          const Context& ctx) const {
-    // Pass explicit surface props, as the simplified canvas constructor discards device properties.
-    // FIXME: switch back to the public constructor (and unfriend) after
-    //        https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
-    SkCanvas canvas(device, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
+    SkCanvas canvas(device);
 
     canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
     canvas.concat(ctx.ctm());
@@ -138,26 +135,23 @@
                                                         const SkIRect& deviceBounds,
                                                         const Context& ctx) const {
     SkMatrix inverseCtm;
-    if (!ctx.ctm().invert(&inverseCtm))
+    if (!ctx.ctm().invert(&inverseCtm)) {
         return;
+    }
+
     SkRect localBounds = SkRect::Make(ctx.clipBounds());
     inverseCtm.mapRect(&localBounds);
-    if (!localBounds.intersect(fCropRect))
+    if (!localBounds.intersect(fCropRect)) {
         return;
+    }
     SkIRect localIBounds = localBounds.roundOut();
     SkAutoTUnref<SkBaseDevice> localDevice(proxy->createDevice(localIBounds.width(), localIBounds.height()));
 
-    // Pass explicit surface props, as the simplified canvas constructor discards device properties.
-    // FIXME: switch back to the public constructor (and unfriend) after
-    //        https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
-    SkCanvas localCanvas(localDevice, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
+    SkCanvas localCanvas(localDevice);
     localCanvas.translate(-SkIntToScalar(localIBounds.fLeft), -SkIntToScalar(localIBounds.fTop));
     localCanvas.drawPicture(fPicture);
 
-    // Pass explicit surface props, as the simplified canvas constructor discards device properties.
-    // FIXME: switch back to the public constructor (and unfriend) after
-    //        https://code.google.com/p/skia/issues/detail?id=3142 is fixed.
-    SkCanvas canvas(device, &proxy->surfaceProps(), SkCanvas::kDefault_InitFlags);
+    SkCanvas canvas(device);
 
     canvas.translate(-SkIntToScalar(deviceBounds.fLeft), -SkIntToScalar(deviceBounds.fTop));
     canvas.concat(ctx.ctm());
@@ -165,7 +159,6 @@
     paint.setFilterQuality(fFilterQuality);
     canvas.drawBitmap(localDevice.get()->accessBitmap(false), SkIntToScalar(localIBounds.fLeft),
                       SkIntToScalar(localIBounds.fTop), &paint);
-    //canvas.drawPicture(fPicture);
 }
 
 #ifndef SK_IGNORE_TO_STRING
diff --git a/src/gpu/GrLayerHoister.cpp b/src/gpu/GrLayerHoister.cpp
index 7693328..1f01e1a 100644
--- a/src/gpu/GrLayerHoister.cpp
+++ b/src/gpu/GrLayerHoister.cpp
@@ -313,7 +313,7 @@
     SkAutoTUnref<SkImageFilter::Cache> cache(SkImageFilter::Cache::Create(kDefaultCacheSize));
     SkImageFilter::Context filterContext(totMat, clipBounds, cache);
 
-    SkImageFilter::Proxy proxy(device, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
+    SkImageFilter::Proxy proxy(device);
     const SkBitmap src = wrap_texture(layer->texture());
 
     if (!layer->filter()->filterImage(&proxy, src, filterContext, &filteredBitmap, &offset)) {
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a67b2c2..1603cd6 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1229,9 +1229,7 @@
                                 SkBitmap* result, SkIPoint* offset) {
     SkASSERT(filter);
 
-    // FIXME: plumb actual surface props such that we don't have to lie about the flags here
-    //        (https://code.google.com/p/skia/issues/detail?id=3148).
-    SkImageFilter::Proxy proxy(this, SkSurfaceProps(0, this->surfaceProps().pixelGeometry()));
+    SkImageFilter::Proxy proxy(this);
 
     if (filter->canFilterImageGPU()) {
         return filter->filterImageGPU(&proxy, wrap_texture(texture, width, height),
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index dd22cf95..5b6a068 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -491,7 +491,7 @@
     // will not be used with a deferred canvas (there is no API for that).
     // And connecting a SkDeferredDevice to non-deferred canvas can result
     // in unpredictable behavior.
-    return immediateDevice()->onCreateDevice(cinfo, layerPaint);
+    return this->immediateDevice()->onCreateDevice(cinfo, layerPaint);
 }
 
 SkSurface* SkDeferredDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 63e3aaa..9bdd910 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -400,7 +400,7 @@
     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
 
     SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
-    SkImageFilter::Proxy proxy(device, props);
+    SkImageFilter::Proxy proxy(device);
 
     test_negative_blur_sigma(&proxy, reporter);
 }
@@ -773,7 +773,7 @@
     const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
 
     SkAutoTUnref<SkBaseDevice> device(SkBitmapDevice::Create(info, props));
-    SkImageFilter::Proxy proxy(device, props);
+    SkImageFilter::Proxy proxy(device);
 
     test_crop_rects(&proxy, reporter);
 }
@@ -885,8 +885,9 @@
     SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), NULL);
     SkBitmap bitmap;
     bitmap.allocN32Pixels(2, 2);
-    SkBitmapDevice device(bitmap, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
-    SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+    SkBitmapDevice device(bitmap, props);
+    SkImageFilter::Proxy proxy(&device);
     REPORTER_ASSERT(reporter, !imageFilter->filterImage(&proxy, bitmap, ctx, &result, &offset));
 }
 
@@ -1123,8 +1124,9 @@
     SkBitmap bitmap;
     bitmap.allocN32Pixels(100, 100);
     bitmap.eraseARGB(0, 0, 0, 0);
-    SkBitmapDevice device(bitmap, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
-    SkImageFilter::Proxy proxy(&device, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType));
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+    SkBitmapDevice device(bitmap, props);
+    SkImageFilter::Proxy proxy(&device);
 
     SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(1, 0, 20, 20));
     SkAutoTUnref<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(0, 0, NULL, &cropRect));
@@ -1138,19 +1140,20 @@
 }
 
 #if SK_SUPPORT_GPU
-const SkSurfaceProps gProps = SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
 
 DEF_GPUTEST(ImageFilterCropRectGPU, reporter, factory) {
     GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(0));
     if (NULL == context) {
         return;
     }
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+
     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
                                                          SkSurface::kNo_Budgeted,
                                                          SkImageInfo::MakeN32Premul(100, 100),
                                                          0,
-                                                         &gProps));
-    SkImageFilter::Proxy proxy(device, gProps);
+                                                         &props));
+    SkImageFilter::Proxy proxy(device);
 
     test_crop_rects(&proxy, reporter);
 }
@@ -1160,11 +1163,13 @@
     if (NULL == context) {
         return;
     }
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+
     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
                                                          SkSurface::kNo_Budgeted,
                                                          SkImageInfo::MakeN32Premul(100, 100),
                                                          0,
-                                                         &gProps));
+                                                         &props));
     SkCanvas canvas(device);
 
     test_huge_blur(&canvas, reporter);
@@ -1175,11 +1180,13 @@
     if (NULL == context) {
         return;
     }
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+
     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
                                                          SkSurface::kNo_Budgeted,
                                                          SkImageInfo::MakeN32Premul(1, 1),
                                                          0,
-                                                         &gProps));
+                                                         &props));
     SkCanvas canvas(device);
 
     test_xfermode_cropped_input(&canvas, reporter);
@@ -1190,12 +1197,14 @@
     if (NULL == context) {
         return;
     }
+    const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
+
     SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
                                                          SkSurface::kNo_Budgeted,
                                                          SkImageInfo::MakeN32Premul(1, 1),
                                                          0,
-                                                         &gProps));
-    SkImageFilter::Proxy proxy(device, gProps);
+                                                         &props));
+    SkImageFilter::Proxy proxy(device);
 
     test_negative_blur_sigma(&proxy, reporter);
 }