Avoid throwing when 0 size layer requested
bug:30032790
Change-Id: I8553af0d0b0d59fea6535d03479c4e7134a9f4f9
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index f8797bf..6facf20 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -301,7 +301,10 @@
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 696cc29..3952798 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -611,9 +611,7 @@
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 9001098..85655fc 100644
--- a/libs/hwui/tests/unit/RenderPropertiesTests.cpp
+++ b/libs/hwui/tests/unit/RenderPropertiesTests.cpp
@@ -42,7 +42,7 @@
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());
}