Allow using custom widths and colors for layer borders.
Update the enableBorder API in SurfaceComposerClient so
that width and color can be specified for the border.
The information propagates through the pipe all the
way to the render engine so it can render the correct color
and width for the border
Test:go/wm-smoke.
Test: LayerBorder_test
Bug: 226529222
Change-Id: Id3ab853d5b4d6899a915f729b0d7be701cb5b167
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 0d3b412..7f0f638 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -102,6 +102,11 @@
SAFE_PARCEL(output.writeUint32, transform);
SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
SAFE_PARCEL(output.writeBool, borderEnabled);
+ SAFE_PARCEL(output.writeFloat, borderWidth);
+ SAFE_PARCEL(output.writeFloat, borderColor.r);
+ SAFE_PARCEL(output.writeFloat, borderColor.g);
+ SAFE_PARCEL(output.writeFloat, borderColor.b);
+ SAFE_PARCEL(output.writeFloat, borderColor.a);
SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
SAFE_PARCEL(output.write, hdrMetadata);
SAFE_PARCEL(output.write, surfaceDamageRegion);
@@ -202,6 +207,16 @@
SAFE_PARCEL(input.readUint32, &transform);
SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
SAFE_PARCEL(input.readBool, &borderEnabled);
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ borderWidth = tmpFloat;
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ borderColor.r = tmpFloat;
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ borderColor.g = tmpFloat;
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ borderColor.b = tmpFloat;
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ borderColor.a = tmpFloat;
uint32_t tmpUint32 = 0;
SAFE_PARCEL(input.readUint32, &tmpUint32);
@@ -555,6 +570,8 @@
if (other.what & eRenderBorderChanged) {
what |= eRenderBorderChanged;
borderEnabled = other.borderEnabled;
+ borderWidth = other.borderWidth;
+ borderColor = other.borderColor;
}
if (other.what & eFrameRateSelectionPriority) {
what |= eFrameRateSelectionPriority;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index caab506..6fc813b 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1940,7 +1940,7 @@
}
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::enableBorder(
- const sp<SurfaceControl>& sc, bool shouldEnable) {
+ const sp<SurfaceControl>& sc, bool shouldEnable, float width, const half4& color) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
@@ -1949,6 +1949,8 @@
s->what |= layer_state_t::eRenderBorderChanged;
s->borderEnabled = shouldEnable;
+ s->borderWidth = width;
+ s->borderColor = color;
registerSurfaceControlForCallback(sc);
return *this;
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 4621d2b..37a1595 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -295,6 +295,9 @@
// Flag to indicate if border needs to be enabled on the layer
bool borderEnabled;
+ float borderWidth;
+ half4 borderColor;
+
// Stretch effect to be applied to this layer
StretchEffect stretchEffect;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 2b24c3f..569dbf8 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -625,7 +625,8 @@
const Rect& destinationFrame);
Transaction& setDropInputMode(const sp<SurfaceControl>& sc, gui::DropInputMode mode);
- Transaction& enableBorder(const sp<SurfaceControl>& sc, bool shouldEnable);
+ Transaction& enableBorder(const sp<SurfaceControl>& sc, bool shouldEnable, float width,
+ const half4& color);
status_t setDisplaySurface(const sp<IBinder>& token,
const sp<IGraphicBufferProducer>& bufferProducer);
diff --git a/libs/renderengine/include/renderengine/BorderRenderInfo.h b/libs/renderengine/include/renderengine/BorderRenderInfo.h
index 85d55fc..0ee6661 100644
--- a/libs/renderengine/include/renderengine/BorderRenderInfo.h
+++ b/libs/renderengine/include/renderengine/BorderRenderInfo.h
@@ -22,10 +22,13 @@
namespace renderengine {
struct BorderRenderInfo {
+ float width = 0;
+ half4 color;
Region combinedRegion;
bool operator==(const BorderRenderInfo& rhs) const {
- return (combinedRegion.hasSameRects(rhs.combinedRegion));
+ return (width == rhs.width && color == rhs.color &&
+ combinedRegion.hasSameRects(rhs.combinedRegion));
}
};
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index ec9ad54..c9f9ec3 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -1247,15 +1247,11 @@
}
for (const auto& borderRenderInfo : display.borderInfoList) {
SkPaint p;
- // TODO (b/225977175): Use specified color
- p.setColor(SkColor4f{.fR = 255 / 255.0f,
- .fG = 128 / 255.0f,
- .fB = 0 / 255.0f,
- .fA = 255 / 255.0f});
+ p.setColor(SkColor4f{borderRenderInfo.color.r, borderRenderInfo.color.g,
+ borderRenderInfo.color.b, borderRenderInfo.color.a});
p.setAntiAlias(true);
p.setStyle(SkPaint::kStroke_Style);
- // TODO (b/225977175): Use specified width
- p.setStrokeWidth(20);
+ p.setStrokeWidth(borderRenderInfo.width);
SkRegion sk_region;
SkPath path;
diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp
index df1b985..61af698 100644
--- a/libs/renderengine/tests/RenderEngineTest.cpp
+++ b/libs/renderengine/tests/RenderEngineTest.cpp
@@ -2433,6 +2433,8 @@
display.borderInfoList.clear();
renderengine::BorderRenderInfo info;
info.combinedRegion = Region(Rect(99, 99, 199, 199));
+ info.width = 20.0f;
+ info.color = half4{1.0f, 128.0f / 255.0f, 0.0f, 1.0f};
display.borderInfoList.emplace_back(info);
const auto greenBuffer = allocateAndFillSourceBuffer(1, 1, ubyte4(0, 255, 0, 255));