add canvas::isDrawingToLayer(), as a fast query for chrome; faster than
setting up a drawiter and counting the layers.



git-svn-id: http://skia.googlecode.com/svn/trunk@2875 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f382893..353c92c 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -404,6 +404,7 @@
     fLocalBoundsCompareTypeDirtyBW = true;
     fLastDeviceToGainFocus = NULL;
     fDeviceCMDirty = false;
+    fLayerCount = 0;
 
     fMCRec = (MCRec*)fMCStack.push_back();
     new (fMCRec) MCRec(NULL, 0);
@@ -443,6 +444,8 @@
 SkCanvas::~SkCanvas() {
     // free up the contents of our deque
     this->restoreToCount(1);    // restore everything but the last
+    SkASSERT(0 == fLayerCount);
+
     this->internalRestore();    // restore the last, since we're going away
 
     SkSafeUnref(fBounder);
@@ -747,6 +750,7 @@
     fMCRec->fLayer = layer;
     fMCRec->fTopLayer = layer;    // this field is NOT an owner of layer
 
+    fLayerCount += 1;
     return count;
 }
 
@@ -797,6 +801,9 @@
                              layer->fPaint);
             // reset this, since drawDevice will have set it to true
             fDeviceCMDirty = true;
+
+            SkASSERT(fLayerCount > 0);
+            fLayerCount -= 1;
         }
         SkDELETE(layer);
     }
@@ -820,6 +827,10 @@
     }
 }
 
+bool SkCanvas::isDrawingToLayer() const {
+    return fLayerCount > 0;
+}
+
 /////////////////////////////////////////////////////////////////////////////
 
 // can't draw it if its empty, or its too big for a fixed-point width or height