fix issue when replacement bitmap is larger than original.

getTotalClip() returns the canvas bounds even if no explicit clip
was set. This CL fixes that issue by only transfering clips that
were explicitly set to the new canvas.

bug: 8255582
Change-Id: I0144d430e7718151ad93d988fcf20b412f74b256
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 6410bc3..6640555 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -54,6 +54,21 @@
 
 namespace android {
 
+class ClipCopier : public SkCanvas::ClipVisitor {
+public:
+    ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {}
+
+    virtual void clipRect(const SkRect& rect, SkRegion::Op op, bool antialias) {
+        m_dstCanvas->clipRect(rect, op, antialias);
+    }
+    virtual void clipPath(const SkPath& path, SkRegion::Op op, bool antialias) {
+        m_dstCanvas->clipPath(path, op, antialias);
+    }
+
+private:
+    SkCanvas* m_dstCanvas;
+};
+
 class SkCanvasGlue {
 public:
 
@@ -68,13 +83,15 @@
     static void copyCanvasState(JNIEnv* env, jobject clazz,
                                 SkCanvas* srcCanvas, SkCanvas* dstCanvas) {
         if (srcCanvas && dstCanvas) {
-            if (NULL != srcCanvas->getDevice() && NULL != dstCanvas->getDevice()) {
-                dstCanvas->clipRegion(srcCanvas->getTotalClip());
-            }
             dstCanvas->setMatrix(srcCanvas->getTotalMatrix());
+            if (NULL != srcCanvas->getDevice() && NULL != dstCanvas->getDevice()) {
+                ClipCopier copier(dstCanvas);
+                srcCanvas->replayClips(&copier);
+            }
         }
     }
 
+
     static void freeCaches(JNIEnv* env, jobject) {
         // these are called in no particular order
         SkImageRef_GlobalPool::SetRAMUsed(0);