Add outline alpha
bug:16140822
bug:16566746
This allows background drawables to alter the opacity of a shadow
being cast with their own alpha values.
Change-Id: I49698cc7c1bf4b2b55ffe2f82899543ca62bc61c
diff --git a/libs/hwui/Outline.h b/libs/hwui/Outline.h
index 83426e8..6dacd5ed 100644
--- a/libs/hwui/Outline.h
+++ b/libs/hwui/Outline.h
@@ -28,18 +28,20 @@
Outline()
: mShouldClip(false)
, mType(kOutlineType_None)
- , mRadius(0) {}
+ , mRadius(0)
+ , mAlpha(0.0f) {}
- void setRoundRect(int left, int top, int right, int bottom, float radius) {
+ void setRoundRect(int left, int top, int right, int bottom, float radius, float alpha) {
mType = kOutlineType_RoundRect;
mBounds.set(left, top, right, bottom);
mRadius = radius;
mPath.reset();
mPath.addRoundRect(SkRect::MakeLTRB(left, top, right, bottom),
radius, radius);
+ mAlpha = alpha;
}
- void setConvexPath(const SkPath* outline) {
+ void setConvexPath(const SkPath* outline, float alpha) {
if (!outline) {
setEmpty();
return;
@@ -47,22 +49,29 @@
mType = kOutlineType_ConvexPath;
mPath = *outline;
mBounds.set(outline->getBounds());
+ mAlpha = alpha;
}
void setEmpty() {
mType = kOutlineType_Empty;
mPath.reset();
+ mAlpha = 0.0f;
}
void setNone() {
mType = kOutlineType_None;
mPath.reset();
+ mAlpha = 0.0f;
}
bool isEmpty() const {
return mType == kOutlineType_Empty;
}
+ float getAlpha() const {
+ return mAlpha;
+ }
+
void setShouldClip(bool clip) {
mShouldClip = clip;
}
@@ -103,6 +112,7 @@
OutlineType mType;
Rect mBounds;
float mRadius;
+ float mAlpha;
SkPath mPath;
};
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index 0662ca2..fa1b21d 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -594,7 +594,12 @@
template <class T>
void RenderNode::issueDrawShadowOperation(const Matrix4& transformFromParent, T& handler) {
- if (properties().getAlpha() <= 0.0f || !properties().getOutline().getPath()) return;
+ if (properties().getAlpha() <= 0.0f
+ || properties().getOutline().getAlpha() <= 0.0f
+ || !properties().getOutline().getPath()) {
+ // no shadow to draw
+ return;
+ }
mat4 shadowMatrixXY(transformFromParent);
applyViewPropertyTransforms(shadowMatrixXY);
@@ -607,8 +612,9 @@
const SkPath* revealClipPath = properties().getRevealClip().getPath();
if (revealClipPath && revealClipPath->isEmpty()) return;
+ float casterAlpha = properties().getAlpha() * properties().getOutline().getAlpha();
DisplayListOp* shadowOp = new (handler.allocator()) DrawShadowOp(
- shadowMatrixXY, shadowMatrixZ, properties().getAlpha(),
+ shadowMatrixXY, shadowMatrixZ, casterAlpha,
outlinePath, revealClipPath);
handler(shadowOp, PROPERTY_SAVECOUNT, properties().getClipToBounds());
}