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/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) {