diff options
author | Derek Sollenberger <djsollen@google.com> | 2012-05-01 12:54:21 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2012-05-01 12:54:21 -0400 |
commit | d9689beb7fce225abbaa78063d46717ec92b19fd (patch) | |
tree | 0a8afa4909cc41fb8d3b9055e585aad96507336f | |
parent | c0b4fa78738acf9ad587eb9fcbc2021be9a3ee77 (diff) | |
download | external_skia-d9689beb7fce225abbaa78063d46717ec92b19fd.zip external_skia-d9689beb7fce225abbaa78063d46717ec92b19fd.tar.gz external_skia-d9689beb7fce225abbaa78063d46717ec92b19fd.tar.bz2 |
Fix SkNWayCanvas to prevent crashes by setting up a device
This is a cherry-pick of two CL's from upstream Skia:
https://codereview.appspot.com/6092056/
https://codereview.appspot.com/6131062/
bug: 6400332
Change-Id: Ia833e7c0d4fd6e21a06980653450095176f5bd42
-rw-r--r-- | include/utils/SkNWayCanvas.h | 2 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 12 | ||||
-rw-r--r-- | src/utils/SkNWayCanvas.cpp | 6 | ||||
-rw-r--r-- | tests/CanvasTest.cpp | 3 |
4 files changed, 20 insertions, 3 deletions
diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h index 69c1fcf..dbf4a58 100644 --- a/include/utils/SkNWayCanvas.h +++ b/include/utils/SkNWayCanvas.h @@ -13,7 +13,7 @@ class SkNWayCanvas : public SkCanvas { public: - SkNWayCanvas(); + SkNWayCanvas(int width, int height); virtual ~SkNWayCanvas(); void addCanvas(SkCanvas*); diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index aa92dd0..7861636 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -573,6 +573,9 @@ bool SkCanvas::readPixels(SkBitmap* bitmap, bool SkCanvas::readPixels(const SkIRect& srcRect, SkBitmap* bitmap) { SkDevice* device = this->getDevice(); + if (!device) { + return false; + } SkIRect bounds; bounds.set(0, 0, device->width(), device->height()); @@ -1058,6 +1061,10 @@ static bool clipPathHelper(const SkCanvas* canvas, SkRasterClip* currClip, } } else { const SkDevice* device = canvas->getDevice(); + if (!device) { + return currClip->setEmpty(); + } + base.setRect(0, 0, device->width(), device->height()); if (SkRegion::kReplace_Op == op) { @@ -1114,6 +1121,11 @@ bool SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) { void SkCanvas::validateClip() const { // construct clipRgn from the clipstack const SkDevice* device = this->getDevice(); + if (!device) { + SkASSERT(this->getTotalClip().isEmpty()); + return; + } + SkIRect ir; ir.set(0, 0, device->width(), device->height()); SkRasterClip tmpClip(ir); diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp index 06cf32d..9f6ebc6 100644 --- a/src/utils/SkNWayCanvas.cpp +++ b/src/utils/SkNWayCanvas.cpp @@ -7,7 +7,11 @@ */ #include "SkNWayCanvas.h" -SkNWayCanvas::SkNWayCanvas() {} +SkNWayCanvas::SkNWayCanvas(int width, int height) { + SkBitmap bm; + bm.setConfig(SkBitmap::kNo_Config, width, height); + this->setBitmapDevice(bm); +} SkNWayCanvas::~SkNWayCanvas() { this->removeAll(); diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp index 7cafda2..76573ed 100644 --- a/tests/CanvasTest.cpp +++ b/tests/CanvasTest.cpp @@ -691,7 +691,8 @@ static void TestNWayCanvasStateConsistency( SkDevice indirectDevice2(indirectStore2); SkCanvas indirectCanvas2(&indirectDevice2); - SkNWayCanvas nWayCanvas; + SkISize canvasSize = referenceCanvas.getDeviceSize(); + SkNWayCanvas nWayCanvas(canvasSize.width(), canvasSize.height()); nWayCanvas.addCanvas(&indirectCanvas1); nWayCanvas.addCanvas(&indirectCanvas2); |