diff options
-rw-r--r-- | include/core/SkSize.h | 4 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 10 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 6 |
3 files changed, 17 insertions, 3 deletions
diff --git a/include/core/SkSize.h b/include/core/SkSize.h index 2efcfb59dc..153335da68 100644 --- a/include/core/SkSize.h +++ b/include/core/SkSize.h @@ -21,6 +21,10 @@ template <typename T> struct SkTSize { return s; } + static SkTSize MakeEmpty() { + return {0, 0}; + } + void set(T w, T h) { fWidth = w; fHeight = h; diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 6140bcc400..6ce38eaaad 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -57,9 +57,12 @@ class SkNoPixelsDevice : public SkBaseDevice { public: SkNoPixelsDevice(const SkIRect& bounds, const SkSurfaceProps& props) : SkBaseDevice(SkImageInfo::MakeUnknown(bounds.width(), bounds.height()), props) - {} + { + SkASSERT(bounds.width() >= 0 && bounds.height() >= 0); + } void resetForNextPicture(const SkIRect& bounds) { + SkASSERT(bounds.width() >= 0 && bounds.height() >= 0); this->privateResize(bounds.width(), bounds.height()); } @@ -688,7 +691,7 @@ SkCanvas::SkCanvas(int width, int height, const SkSurfaceProps* props) { inc_canvas(); - this->init(new SkNoPixelsDevice(SkIRect::MakeWH(width, height), fProps), + this->init(new SkNoPixelsDevice(SkIRect::MakeWH(SkTMax(width, 0), SkTMax(height, 0)), fProps), kDefault_InitFlags)->unref(); } @@ -698,7 +701,8 @@ SkCanvas::SkCanvas(const SkIRect& bounds, InitFlags flags) { inc_canvas(); - this->init(new SkNoPixelsDevice(bounds, fProps), flags)->unref(); + SkIRect r = bounds.isEmpty() ? SkIRect::MakeEmpty() : bounds; + this->init(new SkNoPixelsDevice(r, fProps), flags)->unref(); } SkCanvas::SkCanvas(SkBaseDevice* device) diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index e84b7ba374..c35e7b0522 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -93,6 +93,12 @@ DEF_TEST(canvas_clipbounds, reporter) { REPORTER_ASSERT(reporter, rect == SkRect::MakeEmpty()); REPORTER_ASSERT(reporter, !canvas.getLocalClipBounds(&rect2)); REPORTER_ASSERT(reporter, rect == rect2); + + // Test for wacky sizes that we (historically) have guarded against + { + SkCanvas c(-10, -20); + REPORTER_ASSERT(reporter, c.getBaseLayerSize() == SkISize::MakeEmpty()); + } } static const int kWidth = 2, kHeight = 2; |