From: Derek Sollenberger Date: Tue, 11 Apr 2017 17:58:45 +0000 (-0400) Subject: Change behavior of setBitmap to cleanly reset the canvas X-Git-Tag: android-x86-9.0-r1~1044^2~2008^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=eb69cbbe22d993a9ba88a1206853c660f8f43628;p=android-x86%2Fframeworks-base.git Change behavior of setBitmap to cleanly reset the canvas - identity matrix - no save stack - wide-open clip This reverts commit 4f641d1e4586b027969052cc0ad6b65c1158e72e Test: bit CtsGraphicsTestCases:.CanvasTest Bug: 36218535 Change-Id: Id11deb06e37d6df61f1f171d424ab150d812a7a8 --- diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 7289429537fe..2a2e14b2df6d 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -157,10 +157,12 @@ public class Canvas extends BaseCanvas { /** * Specify a bitmap for the canvas to draw into. All canvas state such as - * layers, filters, and the save/restore stack are reset with the exception - * of the current matrix and clip stack. Additionally, as a side-effect + * layers, filters, and the save/restore stack are reset. Additionally, * the canvas' target density is updated to match that of the bitmap. * + * Prior to API level {@value Build.VERSION_CODES#O} the current matrix and + * clip stack were preserved. + * * @param bitmap Specifies a mutable bitmap for the canvas to draw into. * @see #setDensity(int) * @see #getDensity() diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp index 9f649ead2b52..c1cad7dd4923 100644 --- a/libs/hwui/SkiaCanvas.cpp +++ b/libs/hwui/SkiaCanvas.cpp @@ -80,38 +80,12 @@ void SkiaCanvas::reset(SkCanvas* skiaCanvas) { // Canvas state operations: Replace Bitmap // ---------------------------------------------------------------------------- -class ClipCopier : public SkCanvas::ClipVisitor { -public: - explicit ClipCopier(SkCanvas* dstCanvas) : m_dstCanvas(dstCanvas) {} - - virtual void clipRect(const SkRect& rect, SkClipOp op, bool antialias) { - m_dstCanvas->clipRect(rect, op, antialias); - } - virtual void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) { - m_dstCanvas->clipRRect(rrect, op, antialias); - } - virtual void clipPath(const SkPath& path, SkClipOp op, bool antialias) { - m_dstCanvas->clipPath(path, op, antialias); - } - -private: - SkCanvas* m_dstCanvas; -}; - void SkiaCanvas::setBitmap(const SkBitmap& bitmap) { sk_sp cs = bitmap.refColorSpace(); std::unique_ptr newCanvas = std::unique_ptr(new SkCanvas(bitmap)); std::unique_ptr newCanvasWrapper = SkCreateColorSpaceXformCanvas(newCanvas.get(), cs == nullptr ? SkColorSpace::MakeSRGB() : std::move(cs)); - if (!bitmap.isNull()) { - // Copy the canvas matrix & clip state. - newCanvasWrapper->setMatrix(mCanvas->getTotalMatrix()); - - ClipCopier copier(newCanvasWrapper.get()); - mCanvas->replayClips(&copier); - } - // deletes the previously owned canvas (if any) mCanvasOwned = std::move(newCanvas); mCanvasWrapper = std::move(newCanvasWrapper);