From 347691f8d87157be0eaeca26f4003d8a06a275e3 Mon Sep 17 00:00:00 2001 From: Stan Iliev Date: Thu, 1 Dec 2016 12:25:07 -0500 Subject: [PATCH] Fix a crash in skia pipeline, when empty reorder block is first Fix a crash in skia pipeline, which happens if an empty reorder barrier is inserted at index 0 in a SkiaDisplayList. Add a unit test that repro the bug (unit test is crashing wihtout the fix and passing with the fix). Test: built and ran skia pipeline with angler-eng and run HWUI unit tests. Change-Id: I4aded15021c70cc0ae8daa83bbe8ed0e10a41eef --- libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp | 2 +- libs/hwui/pipeline/skia/ReorderBarrierDrawables.h | 4 ++-- libs/hwui/tests/unit/FrameBuilderTests.cpp | 2 ++ libs/hwui/tests/unit/RenderNodeDrawableTests.cpp | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp index 6973209c4626e..d05e7f660c726 100644 --- a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp +++ b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.cpp @@ -40,7 +40,7 @@ void StartReorderBarrierDrawable::onDraw(SkCanvas* canvas) { //mChildren is allocated and initialized only the first time onDraw is called and cached for //subsequent calls mChildren.reserve(mEndChildIndex - mBeginChildIndex + 1); - for (unsigned int i = mBeginChildIndex; i <= mEndChildIndex; i++) { + for (int i = mBeginChildIndex; i <= mEndChildIndex; i++) { mChildren.push_back(const_cast(&mDisplayList->mChildNodes[i])); } } diff --git a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.h b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.h index 298a7320df640..9f00d23ae9855 100644 --- a/libs/hwui/pipeline/skia/ReorderBarrierDrawables.h +++ b/libs/hwui/pipeline/skia/ReorderBarrierDrawables.h @@ -47,8 +47,8 @@ protected: virtual void onDraw(SkCanvas* canvas) override; private: - size_t mEndChildIndex; - size_t mBeginChildIndex; + int mEndChildIndex; + int mBeginChildIndex; FatVector mChildren; SkiaDisplayList* mDisplayList; diff --git a/libs/hwui/tests/unit/FrameBuilderTests.cpp b/libs/hwui/tests/unit/FrameBuilderTests.cpp index 950b2c45f8930..a1c225f544ddb 100644 --- a/libs/hwui/tests/unit/FrameBuilderTests.cpp +++ b/libs/hwui/tests/unit/FrameBuilderTests.cpp @@ -1530,6 +1530,8 @@ public: RENDERTHREAD_TEST(FrameBuilder, zReorder) { auto parent = TestUtils::createNode(0, 0, 100, 100, [](RenderProperties& props, RecordingCanvas& canvas) { + canvas.insertReorderBarrier(true); + canvas.insertReorderBarrier(false); drawOrderedNode(&canvas, 0, 10.0f); // in reorder=false at this point, so played inorder drawOrderedRect(&canvas, 1); canvas.insertReorderBarrier(true); diff --git a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp index c2df9ecfe7032..f4b686d3b1e23 100644 --- a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp +++ b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp @@ -102,6 +102,8 @@ TEST(RenderNodeDrawable, zReorder) { auto parent = TestUtils::createSkiaNode(0, 0, 100, 100, [](RenderProperties& props, SkiaRecordingCanvas& canvas) { + canvas.insertReorderBarrier(true); + canvas.insertReorderBarrier(false); drawOrderedNode(&canvas, 0, 10.0f); // in reorder=false at this point, so played inorder drawOrderedRect(&canvas, 1); canvas.insertReorderBarrier(true);