Adding virtual overload of isDrawingToLayer() to SkGPipe
authorjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Jul 2012 20:22:52 +0000 (20:22 +0000)
committerjunov@chromium.org <junov@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 18 Jul 2012 20:22:52 +0000 (20:22 +0000)
This change is to make The SkGPipe port of SkDeferredCanvas pass the CanvasTest unit test
Review URL: https://codereview.appspot.com/6426046

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

src/pipe/SkGPipeWrite.cpp

index fc40006e66fa54c611558b91a219c57a2114592e..dff3e1423e3153355431e923e850472e54deea5d 100644 (file)
@@ -357,6 +357,7 @@ public:
     virtual int saveLayer(const SkRect* bounds, const SkPaint*,
                           SaveFlags) SK_OVERRIDE;
     virtual void restore() SK_OVERRIDE;
+    virtual bool isDrawingToLayer() const SK_OVERRIDE;
     virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
     virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
     virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
@@ -403,7 +404,11 @@ public:
     virtual void drawData(const void*, size_t) SK_OVERRIDE;
 
 private:
-    SharedHeap fSharedHeap;
+    enum {
+        kNoSaveLayer = -1,
+    };
+    int         fFirstSaveLayerStackLevel;
+    SharedHeap  fSharedHeap;
     SkGPipeController* fController;
     SkWriter32& fWriter;
     size_t      fBlockSize; // amount allocated for writer
@@ -523,6 +528,7 @@ SkGPipeCanvas::SkGPipeCanvas(SkGPipeController* controller,
     fDone = false;
     fBlockSize = 0; // need first block from controller
     fBytesNotified = 0;
+    fFirstSaveLayerStackLevel = kNoSaveLayer;
     sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex));
 
     // we need a device to limit our clip
@@ -615,6 +621,9 @@ int SkGPipeCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
         }
     }
 
+    if (kNoSaveLayer == fFirstSaveLayerStackLevel){
+        fFirstSaveLayerStackLevel = this->getSaveCount();
+    }
     // we just pass on the save, so we don't create a layer
     return this->INHERITED::save(saveFlags);
 }
@@ -624,7 +633,16 @@ void SkGPipeCanvas::restore() {
     if (this->needOpBytes()) {
         this->writeOp(kRestore_DrawOp);
     }
+
     this->INHERITED::restore();
+
+    if (this->getSaveCount() == fFirstSaveLayerStackLevel){
+        fFirstSaveLayerStackLevel = kNoSaveLayer;
+    }
+}
+
+bool SkGPipeCanvas::isDrawingToLayer() const {
+    return kNoSaveLayer != fFirstSaveLayerStackLevel;
 }
 
 bool SkGPipeCanvas::translate(SkScalar dx, SkScalar dy) {