From e3e481df762747c5f01bbd1503800fa29457fc1b Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Mon, 11 Jul 2016 12:20:51 -0700 Subject: [PATCH] Avoid throwing when 0 size layer requested bug:30032790 Change-Id: I8553af0d0b0d59fea6535d03479c4e7134a9f4f9 --- libs/hwui/RenderNode.cpp | 5 ++++- libs/hwui/RenderProperties.h | 4 +--- libs/hwui/tests/unit/RenderPropertiesTests.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp index f8797bf634421..6facf20b025cf 100644 --- a/libs/hwui/RenderNode.cpp +++ b/libs/hwui/RenderNode.cpp @@ -301,7 +301,10 @@ void RenderNode::pushLayerUpdate(TreeInfo& info) { LayerType layerType = properties().effectiveLayerType(); // If we are not a layer OR we cannot be rendered (eg, view was detached) // we need to destroy any Layers we may have had previously - if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable())) { + if (CC_LIKELY(layerType != LayerType::RenderLayer) + || CC_UNLIKELY(!isRenderable()) + || CC_UNLIKELY(properties().getWidth() == 0) + || CC_UNLIKELY(properties().getHeight() == 0)) { if (CC_UNLIKELY(mLayer)) { destroyLayer(mLayer); mLayer = nullptr; diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h index 696cc29de3a4f..395279806adb3 100644 --- a/libs/hwui/RenderProperties.h +++ b/libs/hwui/RenderProperties.h @@ -611,9 +611,7 @@ public: bool fitsOnLayer() const { const DeviceInfo* deviceInfo = DeviceInfo::get(); return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() - && mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize() - && mPrimitiveFields.mWidth > 0 - && mPrimitiveFields.mHeight > 0; + && mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize(); } bool promotedToLayer() const { diff --git a/libs/hwui/tests/unit/RenderPropertiesTests.cpp b/libs/hwui/tests/unit/RenderPropertiesTests.cpp index 90010983f1547..85655fc2728a3 100644 --- a/libs/hwui/tests/unit/RenderPropertiesTests.cpp +++ b/libs/hwui/tests/unit/RenderPropertiesTests.cpp @@ -42,7 +42,7 @@ TEST(RenderProperties, layerValidity) { props.setLeftTopRightBottom(0, 0, maxTextureSize + 1, maxTextureSize + 1); ASSERT_FALSE(props.fitsOnLayer()); - // Too small - can't have 0 dimen layer + // Too small, but still 'fits'. Not fitting is an error case, so don't report empty as such. props.setLeftTopRightBottom(0, 0, 100, 0); - ASSERT_FALSE(props.fitsOnLayer()); + ASSERT_TRUE(props.fitsOnLayer()); }