Add missing null device checks in SkCanvas
authordjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 May 2012 16:50:10 +0000 (16:50 +0000)
committerdjsollen@google.com <djsollen@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 1 May 2012 16:50:10 +0000 (16:50 +0000)
Review URL: https://codereview.appspot.com/6092056

git-svn-id: http://skia.googlecode.com/svn/trunk@3810 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkCanvas.cpp

index af559583612117060f6c4f5f3365bb2080e2df6c..b0f85d968b72f02bc177beb0d32c0c2e2047d5dd 100644 (file)
@@ -604,6 +604,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());
@@ -1129,6 +1132,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) {
@@ -1185,6 +1192,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);