Promote RenderProperties with an alpha to have a RenderLayer
bug:20254728
Change-Id: I0bd1d440fe46683b291d4c8ab07a630c34b2eadc
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index e009451..ac4c0d0 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -138,7 +138,7 @@
}
void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
- LayerType layerType = properties().layerProperties().type();
+ LayerType layerType = properties().effectiveLayerType();
if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) {
// Damage applied so far needs to affect our parent, but does not require
// the layer to be updated. So we pop/push here to clear out the current
@@ -153,7 +153,7 @@
}
void RenderNode::pushLayerUpdate(TreeInfo& info) {
- LayerType layerType = properties().layerProperties().type();
+ 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())) {
@@ -384,33 +384,16 @@
renderer.concatMatrix(*properties().getTransformMatrix());
}
}
- const bool isLayer = properties().layerProperties().type() != LayerType::None;
+ const bool isLayer = properties().effectiveLayerType() != LayerType::None;
int clipFlags = properties().getClippingFlags();
if (properties().getAlpha() < 1) {
if (isLayer) {
clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer
renderer.setOverrideLayerAlpha(properties().getAlpha());
- } else if (!properties().getHasOverlappingRendering()) {
- renderer.scaleAlpha(properties().getAlpha());
} else {
- Rect layerBounds(0, 0, getWidth(), getHeight());
- int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
- if (clipFlags) {
- saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
- properties().getClippingRectForFlags(clipFlags, &layerBounds);
- clipFlags = 0; // all clipping done by saveLayer
- }
-
- ATRACE_FORMAT("%s alpha caused %ssaveLayer %dx%d", getName(),
- (saveFlags & SkCanvas::kClipToLayer_SaveFlag) ? "" : "unclipped ",
- static_cast<int>(layerBounds.getWidth()),
- static_cast<int>(layerBounds.getHeight()));
-
- SaveLayerOp* op = new (handler.allocator()) SaveLayerOp(
- layerBounds.left, layerBounds.top, layerBounds.right, layerBounds.bottom,
- properties().getAlpha() * 255, saveFlags);
- handler(op, PROPERTY_SAVECOUNT, properties().getClipToBounds());
+ LOG_ALWAYS_FATAL_IF(properties().getHasOverlappingRendering());
+ renderer.scaleAlpha(properties().getAlpha());
}
}
if (clipFlags) {
diff --git a/libs/hwui/RenderProperties.cpp b/libs/hwui/RenderProperties.cpp
index 9f1ceed..0ed3c47 100644
--- a/libs/hwui/RenderProperties.cpp
+++ b/libs/hwui/RenderProperties.cpp
@@ -144,27 +144,16 @@
}
}
- const bool isLayer = layerProperties().type() != LayerType::None;
+ const bool isLayer = effectiveLayerType() != LayerType::None;
int clipFlags = getClippingFlags();
if (mPrimitiveFields.mAlpha < 1) {
if (isLayer) {
clipFlags &= ~CLIP_TO_BOUNDS; // bounds clipping done by layer
ALOGD("%*sSetOverrideLayerAlpha %.2f", level * 2, "", mPrimitiveFields.mAlpha);
- } else if (!mPrimitiveFields.mHasOverlappingRendering) {
- ALOGD("%*sScaleAlpha %.2f", level * 2, "", mPrimitiveFields.mAlpha);
} else {
- Rect layerBounds(0, 0, getWidth(), getHeight());
- int saveFlags = SkCanvas::kHasAlphaLayer_SaveFlag;
- if (clipFlags) {
- saveFlags |= SkCanvas::kClipToLayer_SaveFlag;
- getClippingRectForFlags(clipFlags, &layerBounds);
- clipFlags = 0; // all clipping done by saveLayer
- }
-
- ALOGD("%*sSaveLayerAlpha %d, %d, %d, %d, %d, 0x%x", level * 2, "",
- (int)layerBounds.left, (int)layerBounds.top, (int)layerBounds.right, (int)layerBounds.bottom,
- (int)(mPrimitiveFields.mAlpha * 255), saveFlags);
+ LOG_ALWAYS_FATAL_IF(mPrimitiveFields.mHasOverlappingRendering);
+ ALOGD("%*sScaleAlpha %.2f", level * 2, "", mPrimitiveFields.mAlpha);
}
}
if (clipFlags) {
diff --git a/libs/hwui/RenderProperties.h b/libs/hwui/RenderProperties.h
index 61e98d2..a43566d 100644
--- a/libs/hwui/RenderProperties.h
+++ b/libs/hwui/RenderProperties.h
@@ -73,10 +73,6 @@
return false;
}
- LayerType type() const {
- return mType;
- }
-
bool setOpaque(bool opaque) {
return RP_SET(mOpaque, opaque);
}
@@ -122,6 +118,11 @@
~LayerProperties();
void reset();
+ // Private since external users should go through properties().effectiveLayerType()
+ LayerType type() const {
+ return mType;
+ }
+
friend class RenderProperties;
LayerType mType = LayerType::None;
@@ -575,6 +576,17 @@
&& getOutline().getAlpha() != 0.0f;
}
+ LayerType effectiveLayerType() const {
+ LayerType type = mLayerProperties.mType;
+ if (type == LayerType::None
+ && !MathUtils::isZero(mPrimitiveFields.mAlpha)
+ && mPrimitiveFields.mAlpha < 1
+ && mPrimitiveFields.mHasOverlappingRendering) {
+ return LayerType::RenderLayer;
+ }
+ return type;
+ }
+
private:
// Rendering properties
struct PrimitiveFields {