hide getTotalClip, so we can eventually remove it 
hide getClipType, so we can eventually remove it

patch from issue 189443007

TBR=robertphilips@google.com

Author: reed@chromium.org

Review URL: https://codereview.chromium.org/189883010

git-svn-id: http://skia.googlecode.com/svn/trunk@13715 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/SkNulCanvas.h b/experimental/PdfViewer/SkNulCanvas.h
index af93352..1c12a5b 100644
--- a/experimental/PdfViewer/SkNulCanvas.h
+++ b/experimental/PdfViewer/SkNulCanvas.h
@@ -84,7 +84,9 @@
     virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE {return NULL;}
 
     virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
+#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
     virtual ClipType getClipType() const SK_OVERRIDE { return kRect_ClipType; }
+#endif
     virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
         if (NULL != bounds) {
             bounds->setXYWH(0, 0,
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi
index 1974196..074be78 100644
--- a/gyp/skia_for_chromium_defines.gypi
+++ b/gyp/skia_for_chromium_defines.gypi
@@ -16,6 +16,9 @@
       'SK_SUPPORT_LEGACY_COMPATIBLEDEVICE_CONFIG=1',
       'SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS=1',
       'SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG',
+      'SK_SUPPORT_LEGACY_GETCLIPTYPE',
+      'SK_SUPPORT_LEGACY_GETTOTALCLIP',
     ],
   },
 }
+
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index a987708..093185c 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -19,6 +19,8 @@
 #include "SkXfermode.h"
 
 //#define SK_SUPPORT_LEGACY_WRITEPIXELSCONFIG
+//#define SK_SUPPORT_LEGACY_GETCLIPTYPE
+//#define SK_SUPPORT_LEGACY_GETTOTALCLIP
 
 class SkBounder;
 class SkBaseDevice;
@@ -1057,29 +1059,38 @@
      */
     virtual bool isClipEmpty() const;
 
+    /**
+     *  Returns true if the current clip is just a (non-empty) rectangle.
+     *  Returns false if the clip is empty, or if it is complex.
+     */
+    virtual bool isClipRect() const;
+
     /** Return the current matrix on the canvas.
         This does not account for the translate in any of the devices.
         @return The current matrix on the canvas.
     */
     const SkMatrix& getTotalMatrix() const;
 
+#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
     enum ClipType {
         kEmpty_ClipType = 0,
         kRect_ClipType,
         kComplex_ClipType
     };
-
     /** Returns a description of the total clip; may be cheaper than
         getting the clip and querying it directly.
     */
     virtual ClipType getClipType() const;
+#endif
 
+#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP
     /** DEPRECATED -- need to move this guy to private/friend
      *  Return the current device clip (concatenation of all clip calls).
      *  This does not account for the translate in any of the devices.
      *  @return the current device clip (concatenation of all clip calls).
      */
     const SkRegion& getTotalClip() const;
+#endif
 
     /** Return the clip stack. The clip stack stores all the individual
      *  clips organized by the save/restore frame in which they were
@@ -1145,6 +1156,11 @@
         bool              fDone;
     };
 
+    // don't call
+    const SkRegion& internal_private_getTotalClip() const;
+    // don't call
+    void internal_private_getTotalClipAsPath(SkPath*) const;
+
 protected:
     // default impl defers to getDevice()->newSurface(info)
     virtual SkSurface* onNewSurface(const SkImageInfo&);
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 58ec8fd..9dcbfdb 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1526,7 +1526,7 @@
     // construct clipRgn from the clipstack
     const SkBaseDevice* device = this->getDevice();
     if (!device) {
-        SkASSERT(this->getTotalClip().isEmpty());
+        SkASSERT(this->isClipEmpty());
         return;
     }
 
@@ -1553,12 +1553,6 @@
             }
         }
     }
-
-#if 0   // enable this locally for testing
-    // now compare against the current rgn
-    const SkRegion& rgn = this->getTotalClip();
-    SkASSERT(rgn == tmpClip);
-#endif
 }
 #endif
 
@@ -1591,6 +1585,10 @@
     return fMCRec->fRasterClip->isEmpty();
 }
 
+bool SkCanvas::isClipRect() const {
+    return fMCRec->fRasterClip->isRect();
+}
+
 bool SkCanvas::quickReject(const SkRect& rect) const {
 
     if (!rect.isFinite())
@@ -1671,6 +1669,7 @@
     return *fMCRec->fMatrix;
 }
 
+#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
 SkCanvas::ClipType SkCanvas::getClipType() const {
     if (fMCRec->fRasterClip->isEmpty()) {
         return kEmpty_ClipType;
@@ -1680,10 +1679,27 @@
     }
     return kComplex_ClipType;
 }
+#endif
 
+#ifdef SK_SUPPORT_LEGACY_GETTOTALCLIP
 const SkRegion& SkCanvas::getTotalClip() const {
     return fMCRec->fRasterClip->forceGetBW();
 }
+#endif
+
+const SkRegion& SkCanvas::internal_private_getTotalClip() const {
+    return fMCRec->fRasterClip->forceGetBW();
+}
+
+void SkCanvas::internal_private_getTotalClipAsPath(SkPath* path) const {
+    path->reset();
+
+    const SkRegion& rgn = fMCRec->fRasterClip->forceGetBW();
+    if (rgn.isEmpty()) {
+        return;
+    }
+    (void)rgn.getBoundaryPath(path);
+}
 
 SkBaseDevice* SkCanvas::createLayerDevice(const SkImageInfo& info) {
     SkBaseDevice* device = this->getTopDevice();
diff --git a/src/utils/SkCanvasStateUtils.cpp b/src/utils/SkCanvasStateUtils.cpp
index 4b8868b..c5b558a 100644
--- a/src/utils/SkCanvasStateUtils.cpp
+++ b/src/utils/SkCanvasStateUtils.cpp
@@ -194,7 +194,8 @@
     SkAutoTDelete<SkCanvasState> canvasState(SkNEW_ARGS(SkCanvasState, (canvas)));
 
     // decompose the total matrix and clip
-    setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(), canvas->getTotalClip());
+    setup_MC_state(&canvasState->mcState, canvas->getTotalMatrix(),
+                   canvas->internal_private_getTotalClip());
 
     /*
      * decompose the layers
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index 066d7a6..08e6d94 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -328,7 +328,9 @@
         canvas->restore();
     }
     fMatrix = canvas->getTotalMatrix();
-    fClip = canvas->getTotalClip().getBounds();
+    if (!canvas->getClipDeviceBounds(&fClip)) {
+        fClip.setEmpty();
+    }
     fIndex = index;
 }
 
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index b978036..0bbb640 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -226,9 +226,12 @@
     static const int kVizImageWidth = 256;
 
     virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
+    virtual bool isClipRect() const SK_OVERRIDE { return true; }
+#ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
     virtual ClipType getClipType() const SK_OVERRIDE {
         return kRect_ClipType;
     }
+#endif
     virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
         if (NULL != bounds) {
             bounds->setXYWH(0, 0,
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index b3a63f1..4b6f0fa 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -64,6 +64,20 @@
 #include "SkTDArray.h"
 #include "Test.h"
 
+static bool equal_clips(const SkCanvas& a, const SkCanvas& b) {
+    if (a.isClipEmpty()) {
+        return b.isClipEmpty();
+    }
+    if (!a.isClipRect()) {
+        // this is liberally true, since we don't expose a way to know this exactly (for non-rects)
+        return !b.isClipRect();
+    }
+    SkIRect ar, br;
+    a.getClipDeviceBounds(&ar);
+    b.getClipDeviceBounds(&br);
+    return ar == br;
+}
+
 class Canvas2CanvasClipVisitor : public SkCanvas::ClipVisitor {
 public:
     Canvas2CanvasClipVisitor(SkCanvas* target) : fTarget(target) {}
@@ -92,7 +106,7 @@
     Canvas2CanvasClipVisitor visitor(&c);
     canvas->replayClips(&visitor);
 
-    REPORTER_ASSERT(reporter, c.getTotalClip() == canvas->getTotalClip());
+    REPORTER_ASSERT(reporter, equal_clips(c, *canvas));
 }
 
 static const int kWidth = 2;
@@ -369,8 +383,7 @@
         testStep->assertMessage());
     REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(),
         testStep->assertMessage());
-    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion,
-        testStep->assertMessage());
+//    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() == kTestRegion, testStep->assertMessage());
 }
 TEST_STEP(SaveMatrix, SaveMatrixStep);
 
@@ -386,8 +399,7 @@
         testStep->assertMessage());
     REPORTER_ASSERT_MESSAGE(reporter, !canvas->getTotalMatrix().isIdentity(),
         testStep->assertMessage());
-    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion,
-        testStep->assertMessage());
+//    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, testStep->assertMessage());
 }
 TEST_STEP(SaveClip, SaveClipStep);
 
@@ -403,8 +415,7 @@
         testStep->assertMessage());
     REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalMatrix().isIdentity(),
         testStep->assertMessage());
-    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion,
-        testStep->assertMessage());
+//    REPORTER_ASSERT_MESSAGE(reporter, canvas->getTotalClip() != kTestRegion, testStep->assertMessage());
 }
 TEST_STEP(SaveMatrixClip, SaveMatrixClipStep);
 
@@ -628,10 +639,7 @@
         canvas2->getBounder(), testStep->assertMessage());
     REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() ==
         canvas2->getTotalMatrix(), testStep->assertMessage());
-    REPORTER_ASSERT_MESSAGE(reporter, canvas1->getClipType() ==
-        canvas2->getClipType(), testStep->assertMessage());
-    REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalClip() ==
-        canvas2->getTotalClip(), testStep->assertMessage());
+    REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep->assertMessage());
 
     // The following test code is commented out because the test fails when
     // the canvas is an SkPictureRecord or SkDeferredCanvas