From b66b8bb4a089593ee7c20ad7f59980c16dde9cc9 Mon Sep 17 00:00:00 2001 From: Stan Iliev Date: Thu, 15 Dec 2016 18:17:42 -0500 Subject: Ensure root render node clip cannot expand beyond dirty area Use new Skia API to enfore clip restriction for root render node. This brings Skia pipeline in line with HWUI. Unit test is updated to reflect the new behaviour. Test: Built and ran angler-eng, ran HWUI unit tests. Change-Id: Iffce70fd37b6aff45eb6a23c8b1a64f45b5f1463 --- libs/hwui/pipeline/skia/SkiaPipeline.cpp | 7 +++---- libs/hwui/tests/unit/SkiaPipelineTests.cpp | 7 ++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/libs/hwui/pipeline/skia/SkiaPipeline.cpp b/libs/hwui/pipeline/skia/SkiaPipeline.cpp index 376346f05e1b..430d6bea70c1 100644 --- a/libs/hwui/pipeline/skia/SkiaPipeline.cpp +++ b/libs/hwui/pipeline/skia/SkiaPipeline.cpp @@ -100,7 +100,7 @@ void SkiaPipeline::renderLayersImpl(const LayerUpdateQueue& layers, bool opaque) int saveCount = layerCanvas->save(); SkASSERT(saveCount == 1); - layerCanvas->clipRect(layerDamage.toSkRect(), SkClipOp::kReplace); + layerCanvas->androidFramework_setDeviceClipRestriction(layerDamage.toSkIRect()); auto savedLightCenter = mLightCenter; // map current light center into RenderNode's coordinate space @@ -233,8 +233,8 @@ static Rect nodeBounds(RenderNode& node) { void SkiaPipeline::renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& clip, const std::vector>& nodes, bool opaque, const Rect &contentDrawBounds, SkCanvas* canvas) { - - canvas->clipRect(clip, SkClipOp::kReplace); + SkAutoCanvasRestore saver(canvas, true); + canvas->androidFramework_setDeviceClipRestriction(clip.roundOut()); if (!opaque) { canvas->clear(SK_ColorTRANSPARENT); @@ -242,7 +242,6 @@ void SkiaPipeline::renderFrameImpl(const LayerUpdateQueue& layers, const SkRect& if (1 == nodes.size()) { if (!nodes[0]->nothingToDraw()) { - SkAutoCanvasRestore acr(canvas, true); RenderNodeDrawable root(nodes[0].get(), canvas); root.draw(canvas); } diff --git a/libs/hwui/tests/unit/SkiaPipelineTests.cpp b/libs/hwui/tests/unit/SkiaPipelineTests.cpp index 722faf6268cd..f3a663e802da 100644 --- a/libs/hwui/tests/unit/SkiaPipelineTests.cpp +++ b/libs/hwui/tests/unit/SkiaPipelineTests.cpp @@ -324,11 +324,8 @@ RENDERTHREAD_TEST(SkiaPipeline, clip_replace) { } void onDrawPaint(const SkPaint&) { EXPECT_EQ(0, mDrawCounter++); - //TODO: this unit test is failing on the commented check below, because of a missing - //feature. In Snapshot::applyClip HWUI is intersecting the clip with the clip root, - //even for kReplace_Op clips. We need to implement the same for Skia pipelines. - //EXPECT_EQ(SkRect::MakeLTRB(20, 10, 30, 40), TestUtils::getClipBounds(this)) //got instead 20 0 30 50 - // << "Expect resolved clip to be intersection of viewport clip and clip op"; + EXPECT_EQ(SkRect::MakeLTRB(20, 10, 30, 40), TestUtils::getClipBounds(this)) + << "Expect resolved clip to be intersection of viewport clip and clip op"; } int mDrawCounter = 0; }; -- cgit v1.2.3-59-g8ed1b