diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp index ddf0528467e0b..b949411409fc1 100644 --- a/libs/hwui/RecordingCanvas.cpp +++ b/libs/hwui/RecordingCanvas.cpp @@ -564,15 +564,17 @@ void RecordingCanvas::drawRenderNode(RenderNode* renderNode) { getRecordedClip(), renderNode); int opIndex = addOp(op); - int childIndex = mDisplayList->addChild(op); + if (CC_LIKELY(opIndex >= 0)) { + int childIndex = mDisplayList->addChild(op); - // update the chunk's child indices - DisplayList::Chunk& chunk = mDisplayList->chunks.back(); - chunk.endChildIndex = childIndex + 1; + // update the chunk's child indices + DisplayList::Chunk& chunk = mDisplayList->chunks.back(); + chunk.endChildIndex = childIndex + 1; - if (renderNode->stagingProperties().isProjectionReceiver()) { - // use staging property, since recording on UI thread - mDisplayList->projectionReceiveIndex = opIndex; + if (renderNode->stagingProperties().isProjectionReceiver()) { + // use staging property, since recording on UI thread + mDisplayList->projectionReceiveIndex = opIndex; + } } } diff --git a/libs/hwui/tests/unit/RecordingCanvasTests.cpp b/libs/hwui/tests/unit/RecordingCanvasTests.cpp index d35b1f94583d6..c3165bbe9c1f9 100644 --- a/libs/hwui/tests/unit/RecordingCanvasTests.cpp +++ b/libs/hwui/tests/unit/RecordingCanvasTests.cpp @@ -451,6 +451,21 @@ TEST(RecordingCanvas, saveLayer_rotateClipped) { EXPECT_EQ(3, count); } +TEST(RecordingCanvas, drawRenderNode_rejection) { + auto child = TestUtils::createNode(50, 50, 150, 150, + [](RenderProperties& props, RecordingCanvas& canvas) { + SkPaint paint; + paint.setColor(SK_ColorWHITE); + canvas.drawRect(0, 0, 100, 100, paint); + }); + + auto dl = TestUtils::createDisplayList(200, 200, [&child](RecordingCanvas& canvas) { + canvas.clipRect(0, 0, 0, 0, SkRegion::kIntersect_Op); // empty clip, reject node + canvas.drawRenderNode(child.get()); // shouldn't crash when rejecting node... + }); + ASSERT_TRUE(dl->isEmpty()); +} + TEST(RecordingCanvas, drawRenderNode_projection) { sp background = TestUtils::createNode(50, 50, 150, 150, [](RenderProperties& props, RecordingCanvas& canvas) {