diff options
-rw-r--r-- | libs/hwui/DeviceInfo.h | 1 | ||||
-rw-r--r-- | libs/hwui/RenderNode.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/RenderProperties.h | 3 | ||||
-rw-r--r-- | libs/hwui/renderthread/CanvasContext.cpp | 5 | ||||
-rw-r--r-- | libs/hwui/tests/unit/RenderPropertiesTests.cpp | 8 |
5 files changed, 15 insertions, 4 deletions
diff --git a/libs/hwui/DeviceInfo.h b/libs/hwui/DeviceInfo.h index fb58a69747b3..b72e066e64ae 100644 --- a/libs/hwui/DeviceInfo.h +++ b/libs/hwui/DeviceInfo.h @@ -84,6 +84,7 @@ public: // this value is only valid after the GPU has been initialized and there is a valid graphics // context or if you are using the HWUI_NULL_GPU int maxTextureSize() const; + bool hasMaxTextureSize() const { return mMaxTextureSize > 0; } sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; } SkColorType getWideColorType() { static std::once_flag kFlag; diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp index 2c23864317a4..4801bd1038a3 100644 --- a/libs/hwui/RenderNode.cpp +++ b/libs/hwui/RenderNode.cpp @@ -186,7 +186,7 @@ void RenderNode::pushLayerUpdate(TreeInfo& info) { // 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()) || - CC_UNLIKELY(properties().getWidth() == 0) || CC_UNLIKELY(properties().getHeight() == 0) || + CC_UNLIKELY(properties().getWidth() <= 0) || CC_UNLIKELY(properties().getHeight() <= 0) || CC_UNLIKELY(!properties().fitsOnLayer())) { if (CC_UNLIKELY(hasLayer())) { this->setLayerSurface(nullptr); diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h index b1ad8b2eb1b9..4dc57004e401 100644 --- a/libs/hwui/RenderProperties.h +++ b/libs/hwui/RenderProperties.h @@ -545,7 +545,8 @@ public: bool fitsOnLayer() const { const DeviceInfo* deviceInfo = DeviceInfo::get(); return mPrimitiveFields.mWidth <= deviceInfo->maxTextureSize() && - mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize(); + mPrimitiveFields.mHeight <= deviceInfo->maxTextureSize() && + mPrimitiveFields.mWidth > 0 && mPrimitiveFields.mHeight > 0; } bool promotedToLayer() const { diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp index 8ec04304a808..b36b8be10779 100644 --- a/libs/hwui/renderthread/CanvasContext.cpp +++ b/libs/hwui/renderthread/CanvasContext.cpp @@ -418,6 +418,11 @@ void CanvasContext::prepareTree(TreeInfo& info, int64_t* uiFrameInfo, int64_t sy RenderNode* target) { mRenderThread.removeFrameCallback(this); + // Make sure we have a valid device info + if (!DeviceInfo::get()->hasMaxTextureSize()) { + (void)mRenderThread.requireGrContext(); + } + // If the previous frame was dropped we don't need to hold onto it, so // just keep using the previous frame's structure instead const auto reason = wasSkipped(mCurrentFrameInfo); diff --git a/libs/hwui/tests/unit/RenderPropertiesTests.cpp b/libs/hwui/tests/unit/RenderPropertiesTests.cpp index 3e8e0576bf49..6ec042cf23b0 100644 --- a/libs/hwui/tests/unit/RenderPropertiesTests.cpp +++ b/libs/hwui/tests/unit/RenderPropertiesTests.cpp @@ -40,7 +40,11 @@ TEST(RenderProperties, layerValidity) { props.setLeftTopRightBottom(0, 0, maxTextureSize + 1, maxTextureSize + 1); ASSERT_FALSE(props.fitsOnLayer()); - // Too small, but still 'fits'. Not fitting is an error case, so don't report empty as such. + // Too small, we can't create a layer for a 0 width or height props.setLeftTopRightBottom(0, 0, 100, 0); - ASSERT_TRUE(props.fitsOnLayer()); + ASSERT_FALSE(props.fitsOnLayer()); + + // Can't create a negative-sized layer + props.setLeftTopRightBottom(0, 0, -100, 300); + ASSERT_FALSE(props.fitsOnLayer()); } |