aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-06-22 12:06:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-22 12:06:08 -0700
commitefbffedd68636e94d4379e84a2585bce80f6fb8f (patch)
treefbddc37d43f72b35701a73af6df9b0eee9298271
parent343c7d15c831a3c3d8a6984c1a1b524b414012df (diff)
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
-rw-r--r--include/core/SkCanvas.h2
-rw-r--r--include/core/SkDevice.h2
-rw-r--r--include/core/SkImageFilter.h14
-rw-r--r--include/core/SkSurfaceProps.h3
-rw-r--r--include/effects/SkPictureImageFilter.h2
-rw-r--r--src/core/SkCanvas.cpp18
-rw-r--r--src/core/SkDevice.cpp9
-rw-r--r--src/effects/SkPictureImageFilter.cpp29
-rw-r--r--src/gpu/GrLayerHoister.cpp2
-rw-r--r--src/gpu/SkGpuDevice.cpp4
-rw-r--r--src/utils/SkDeferredCanvas.cpp2
-rw-r--r--tests/ImageFilterTest.cpp35
12 files changed, 46 insertions, 76 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 6afaf3f319..42627daf51 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1290,8 +1290,6 @@ private:
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 7217e2fa65..daca805416 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -359,8 +359,6 @@ protected:
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 3508df50ce..e0e97b0ad2 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -80,21 +80,17 @@ public:
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 9c90d3ef2a..108359922f 100644
--- a/include/core/SkSurfaceProps.h
+++ b/include/core/SkSurfaceProps.h
@@ -71,9 +71,6 @@ public:
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 d62f03f8a3..8294e1fff2 100644
--- a/include/effects/SkPictureImageFilter.h
+++ b/include/effects/SkPictureImageFilter.h
@@ -76,7 +76,7 @@ protected:
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 f35727d6f6..fcfb641407 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -536,8 +536,8 @@ SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) {
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 @@ SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags)
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 @@ void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y,
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 @@ void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint*
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 4e9d4a21e8..15cd7eef3b 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -70,15 +70,6 @@ SkPixelGeometry SkBaseDevice::CreateInfo::AdjustGeometry(const SkImageInfo& info
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 91f4dc9f29..bf1ba8d7eb 100644
--- a/src/effects/SkPictureImageFilter.cpp
+++ b/src/effects/SkPictureImageFilter.cpp
@@ -110,9 +110,9 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co
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 @@ bool SkPictureImageFilter::onFilterImage(Proxy* proxy, const SkBitmap&, const Co
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 @@ void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
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 @@ void SkPictureImageFilter::drawPictureAtLocalResolution(Proxy* proxy, SkBaseDevi
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 7693328d12..1f01e1a983 100644
--- a/src/gpu/GrLayerHoister.cpp
+++ b/src/gpu/GrLayerHoister.cpp
@@ -313,7 +313,7 @@ void GrLayerHoister::FilterLayer(GrContext* context,
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 a67b2c2ecc..1603cd64f1 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1229,9 +1229,7 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
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 dd22cf951f..5b6a06863a 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -491,7 +491,7 @@ SkBaseDevice* SkDeferredDevice::onCreateDevice(const CreateInfo& cinfo, const Sk
// 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 63e3aaa6f0..9bdd910f1b 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -400,7 +400,7 @@ DEF_TEST(TestNegativeBlurSigma, reporter) {
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 @@ DEF_TEST(ImageFilterCropRect, reporter) {
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 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) {
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 @@ DEF_TEST(ComposedImageFilterOffset, reporter) {
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 @@ DEF_TEST(ComposedImageFilterOffset, reporter) {
}
#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 @@ DEF_GPUTEST(HugeBlurImageFilterGPU, reporter, factory) {
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 @@ DEF_GPUTEST(XfermodeImageFilterCroppedInputGPU, reporter, factory) {
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 @@ DEF_GPUTEST(TestNegativeBlurSigmaGPU, reporter, factory) {
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);
}