Skip to content

Commit 1926a93

Browse files
surbhi-kadamAndroid (Google) Code Review
authored andcommitted
Merge "surfaceflinger: Add clientDrawnCornerRadius and clientDrawnShadowLength layer properties" into main
2 parents 0ea3321 + 9674ffa commit 1926a93

13 files changed

Lines changed: 267 additions & 22 deletions

libs/gui/LayerState.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ layer_state_t::layer_state_t()
6666
mask(0),
6767
reserved(0),
6868
cornerRadius(0.0f),
69+
clientDrawnCornerRadius(0.0f),
70+
clientDrawnShadowRadius(0.0f),
6971
backgroundBlurRadius(0),
7072
color(0),
7173
bufferTransform(0),
@@ -140,6 +142,8 @@ status_t layer_state_t::write(Parcel& output) const
140142

141143
SAFE_PARCEL(output.write, colorTransform.asArray(), 16 * sizeof(float));
142144
SAFE_PARCEL(output.writeFloat, cornerRadius);
145+
SAFE_PARCEL(output.writeFloat, clientDrawnCornerRadius);
146+
SAFE_PARCEL(output.writeFloat, clientDrawnShadowRadius);
143147
SAFE_PARCEL(output.writeUint32, backgroundBlurRadius);
144148
SAFE_PARCEL(output.writeParcelable, metadata);
145149
SAFE_PARCEL(output.writeFloat, bgColor.r);
@@ -274,6 +278,8 @@ status_t layer_state_t::read(const Parcel& input)
274278

275279
SAFE_PARCEL(input.read, &colorTransform, 16 * sizeof(float));
276280
SAFE_PARCEL(input.readFloat, &cornerRadius);
281+
SAFE_PARCEL(input.readFloat, &clientDrawnCornerRadius);
282+
SAFE_PARCEL(input.readFloat, &clientDrawnShadowRadius);
277283
SAFE_PARCEL(input.readUint32, &backgroundBlurRadius);
278284
SAFE_PARCEL(input.readParcelable, &metadata);
279285

@@ -596,6 +602,14 @@ void layer_state_t::merge(const layer_state_t& other) {
596602
what |= eCornerRadiusChanged;
597603
cornerRadius = other.cornerRadius;
598604
}
605+
if (other.what & eClientDrawnCornerRadiusChanged) {
606+
what |= eClientDrawnCornerRadiusChanged;
607+
clientDrawnCornerRadius = other.clientDrawnCornerRadius;
608+
}
609+
if (other.what & eClientDrawnShadowsChanged) {
610+
what |= eClientDrawnShadowsChanged;
611+
clientDrawnShadowRadius = other.clientDrawnShadowRadius;
612+
}
599613
if (other.what & eBackgroundBlurRadiusChanged) {
600614
what |= eBackgroundBlurRadiusChanged;
601615
backgroundBlurRadius = other.backgroundBlurRadius;
@@ -809,6 +823,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
809823
}
810824
CHECK_DIFF(diff, eLayerStackChanged, other, layerStack);
811825
CHECK_DIFF(diff, eCornerRadiusChanged, other, cornerRadius);
826+
CHECK_DIFF(diff, eClientDrawnCornerRadiusChanged, other, clientDrawnCornerRadius);
827+
CHECK_DIFF(diff, eClientDrawnShadowsChanged, other, clientDrawnShadowRadius);
812828
CHECK_DIFF(diff, eBackgroundBlurRadiusChanged, other, backgroundBlurRadius);
813829
if (other.what & eBlurRegionsChanged) diff |= eBlurRegionsChanged;
814830
if (other.what & eRelativeLayerChanged) {

libs/gui/SurfaceComposerClient.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,29 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCorne
16951695
return *this;
16961696
}
16971697

1698+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setClientDrawnCornerRadius(
1699+
const sp<SurfaceControl>& sc, float clientDrawnCornerRadius) {
1700+
layer_state_t* s = getLayerState(sc);
1701+
if (!s) {
1702+
mStatus = BAD_INDEX;
1703+
return *this;
1704+
}
1705+
s->what |= layer_state_t::eClientDrawnCornerRadiusChanged;
1706+
s->clientDrawnCornerRadius = clientDrawnCornerRadius;
1707+
return *this;
1708+
}
1709+
1710+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setClientDrawnShadowRadius(
1711+
const sp<SurfaceControl>& sc, float clientDrawnShadowRadius) {
1712+
layer_state_t* s = getLayerState(sc);
1713+
if (!s) {
1714+
mStatus = BAD_INDEX;
1715+
return *this;
1716+
}
1717+
s->what |= layer_state_t::eClientDrawnShadowsChanged;
1718+
s->clientDrawnShadowRadius = clientDrawnShadowRadius;
1719+
return *this;
1720+
}
16981721
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBackgroundBlurRadius(
16991722
const sp<SurfaceControl>& sc, int backgroundBlurRadius) {
17001723
layer_state_t* s = getLayerState(sc);

libs/gui/include/gui/LayerState.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ struct layer_state_t {
231231
eBufferReleaseChannelChanged = 0x40000'00000000,
232232
ePictureProfileHandleChanged = 0x80000'00000000,
233233
eAppContentPriorityChanged = 0x100000'00000000,
234+
eClientDrawnCornerRadiusChanged = 0x200000'00000000,
235+
eClientDrawnShadowsChanged = 0x400000'00000000,
234236
};
235237

236238
layer_state_t();
@@ -251,9 +253,9 @@ struct layer_state_t {
251253
// Geometry updates.
252254
static constexpr uint64_t GEOMETRY_CHANGES = layer_state_t::eBufferCropChanged |
253255
layer_state_t::eBufferTransformChanged | layer_state_t::eCornerRadiusChanged |
254-
layer_state_t::eCropChanged | layer_state_t::eDestinationFrameChanged |
255-
layer_state_t::eMatrixChanged | layer_state_t::ePositionChanged |
256-
layer_state_t::eTransformToDisplayInverseChanged |
256+
layer_state_t::eClientDrawnCornerRadiusChanged | layer_state_t::eCropChanged |
257+
layer_state_t::eDestinationFrameChanged | layer_state_t::eMatrixChanged |
258+
layer_state_t::ePositionChanged | layer_state_t::eTransformToDisplayInverseChanged |
257259
layer_state_t::eTransparentRegionChanged | layer_state_t::eEdgeExtensionChanged;
258260

259261
// Buffer and related updates.
@@ -274,8 +276,8 @@ struct layer_state_t {
274276
layer_state_t::eColorSpaceAgnosticChanged | layer_state_t::eColorTransformChanged |
275277
layer_state_t::eCornerRadiusChanged | layer_state_t::eDimmingEnabledChanged |
276278
layer_state_t::eHdrMetadataChanged | layer_state_t::eShadowRadiusChanged |
277-
layer_state_t::eStretchChanged | layer_state_t::ePictureProfileHandleChanged |
278-
layer_state_t::eAppContentPriorityChanged;
279+
layer_state_t::eClientDrawnShadowsChanged | layer_state_t::eStretchChanged |
280+
layer_state_t::ePictureProfileHandleChanged | layer_state_t::eAppContentPriorityChanged;
279281

280282
// Changes which invalidates the layer's visible region in CE.
281283
static constexpr uint64_t CONTENT_DIRTY = layer_state_t::CONTENT_CHANGES |
@@ -328,6 +330,8 @@ struct layer_state_t {
328330
uint8_t reserved;
329331
matrix22_t matrix;
330332
float cornerRadius;
333+
float clientDrawnCornerRadius;
334+
float clientDrawnShadowRadius;
331335
uint32_t backgroundBlurRadius;
332336

333337
sp<SurfaceControl> relativeLayerSurfaceControl;

libs/gui/include/gui/SurfaceComposerClient.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,15 @@ class SurfaceComposerClient : public RefBase
567567
Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop);
568568
Transaction& setCrop(const sp<SurfaceControl>& sc, const FloatRect& crop);
569569
Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius);
570+
// Sets the client drawn corner radius for the layer. If both a corner radius and a client
571+
// radius are sent to SF, the client radius will be used. This indicates that the corner
572+
// radius is drawn by the client and not SurfaceFlinger.
573+
Transaction& setClientDrawnCornerRadius(const sp<SurfaceControl>& sc,
574+
float clientDrawnCornerRadius);
575+
// Sets the client drawn shadow radius for the layer. This indicates that the shadows
576+
// are drawn by the client and not SurfaceFlinger.
577+
Transaction& setClientDrawnShadowRadius(const sp<SurfaceControl>& sc,
578+
float clientDrawnShadowRadius);
570579
Transaction& setBackgroundBlurRadius(const sp<SurfaceControl>& sc,
571580
int backgroundBlurRadius);
572581
Transaction& setBlurRegions(const sp<SurfaceControl>& sc,

libs/ui/include/ui/ShadowSettings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ struct ShadowSettings {
4646
// Length of the cast shadow. If length is <= 0.f no shadows will be drawn.
4747
float length = 0.f;
4848

49+
// Length of the cast shadow that is drawn by the client.
50+
float clientDrawnLength = 0.f;
51+
4952
// If true fill in the casting layer is translucent and the shadow needs to fill the bounds.
5053
// Otherwise the shadow will only be drawn around the edges of the casting layer.
5154
bool casterIsTranslucent = false;
@@ -55,6 +58,7 @@ static inline bool operator==(const ShadowSettings& lhs, const ShadowSettings& r
5558
return lhs.boundaries == rhs.boundaries && lhs.ambientColor == rhs.ambientColor &&
5659
lhs.spotColor == rhs.spotColor && lhs.lightPos == rhs.lightPos &&
5760
lhs.lightRadius == rhs.lightRadius && lhs.length == rhs.length &&
61+
lhs.clientDrawnLength == rhs.clientDrawnLength &&
5862
lhs.casterIsTranslucent == rhs.casterIsTranslucent;
5963
}
6064

services/surfaceflinger/FrontEnd/LayerSnapshot.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,13 @@ void LayerSnapshot::merge(const RequestedLayerState& requested, bool forceUpdate
398398
if (forceUpdate || requested.what & layer_state_t::eSidebandStreamChanged) {
399399
sidebandStream = requested.sidebandStream;
400400
}
401-
if (forceUpdate || requested.what & layer_state_t::eShadowRadiusChanged) {
402-
shadowSettings.length = requested.shadowRadius;
401+
if (forceUpdate || requested.what & layer_state_t::eShadowRadiusChanged ||
402+
requested.what & layer_state_t::eClientDrawnShadowsChanged) {
403+
shadowSettings.length =
404+
requested.clientDrawnShadowRadius > 0 ? 0.f : requested.shadowRadius;
405+
shadowSettings.clientDrawnLength = requested.clientDrawnShadowRadius;
403406
}
407+
404408
if (forceUpdate || requested.what & layer_state_t::eFrameRateSelectionPriority) {
405409
frameRateSelectionPriority = requested.frameRateSelectionPriority;
406410
}

services/surfaceflinger/FrontEnd/LayerSnapshot.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ namespace android::surfaceflinger::frontend {
2828

2929
struct RoundedCornerState {
3030
RoundedCornerState() = default;
31-
RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
32-
: cropRect(cropRect), radius(radius) {}
3331

3432
// Rounded rectangle in local layer coordinate space.
3533
FloatRect cropRect = FloatRect();
36-
// Radius of the rounded rectangle.
34+
// Radius of the rounded rectangle for composition
3735
vec2 radius;
36+
// Requested radius of the rounded rectangle
37+
vec2 requestedRadius;
38+
// Radius drawn by client for the rounded rectangle
39+
vec2 clientDrawnRadius;
40+
bool hasClientDrawnRadius() const {
41+
return clientDrawnRadius.x > 0.0f && clientDrawnRadius.y > 0.0f;
42+
}
43+
bool hasRequestedRadius() const { return requestedRadius.x > 0.0f && requestedRadius.y > 0.0f; }
3844
bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
3945
bool operator==(RoundedCornerState const& rhs) const {
40-
return cropRect == rhs.cropRect && radius == rhs.radius;
46+
return cropRect == rhs.cropRect && radius == rhs.radius &&
47+
clientDrawnRadius == rhs.clientDrawnRadius;
4148
}
4249
};
4350

services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <common/FlagManager.h>
2828
#include <common/trace.h>
2929
#include <ftl/small_map.h>
30+
#include <math/vec2.h>
3031
#include <ui/DisplayMap.h>
3132
#include <ui/FloatRect.h>
3233

@@ -934,7 +935,8 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
934935

935936
if (forceUpdate || snapshot.clientChanges & layer_state_t::eCornerRadiusChanged ||
936937
snapshot.changes.any(RequestedLayerState::Changes::Geometry |
937-
RequestedLayerState::Changes::BufferUsageFlags)) {
938+
RequestedLayerState::Changes::BufferUsageFlags) ||
939+
snapshot.clientChanges & layer_state_t::eClientDrawnCornerRadiusChanged) {
938940
updateRoundedCorner(snapshot, requested, parentSnapshot, args);
939941
}
940942

@@ -974,7 +976,7 @@ void LayerSnapshotBuilder::updateRoundedCorner(LayerSnapshot& snapshot,
974976
}
975977
snapshot.roundedCorner = RoundedCornerState();
976978
RoundedCornerState parentRoundedCorner;
977-
if (parentSnapshot.roundedCorner.hasRoundedCorners()) {
979+
if (parentSnapshot.roundedCorner.hasRequestedRadius()) {
978980
parentRoundedCorner = parentSnapshot.roundedCorner;
979981
ui::Transform t = snapshot.localTransform.inverse();
980982
parentRoundedCorner.cropRect = t.transform(parentRoundedCorner.cropRect);
@@ -983,10 +985,16 @@ void LayerSnapshotBuilder::updateRoundedCorner(LayerSnapshot& snapshot,
983985
}
984986

985987
FloatRect layerCropRect = snapshot.croppedBufferSize;
986-
const vec2 radius(requested.cornerRadius, requested.cornerRadius);
987-
RoundedCornerState layerSettings(layerCropRect, radius);
988-
const bool layerSettingsValid = layerSettings.hasRoundedCorners() && !layerCropRect.isEmpty();
989-
const bool parentRoundedCornerValid = parentRoundedCorner.hasRoundedCorners();
988+
const vec2 requestedRadius(requested.cornerRadius, requested.cornerRadius);
989+
const vec2 clientDrawnRadius(requested.clientDrawnCornerRadius,
990+
requested.clientDrawnCornerRadius);
991+
RoundedCornerState layerSettings;
992+
layerSettings.cropRect = layerCropRect;
993+
layerSettings.requestedRadius = requestedRadius;
994+
layerSettings.clientDrawnRadius = clientDrawnRadius;
995+
996+
const bool layerSettingsValid = layerSettings.hasRequestedRadius() && !layerCropRect.isEmpty();
997+
const bool parentRoundedCornerValid = parentRoundedCorner.hasRequestedRadius();
990998
if (layerSettingsValid && parentRoundedCornerValid) {
991999
// If the parent and the layer have rounded corner settings, use the parent settings if
9921000
// the parent crop is entirely inside the layer crop. This has limitations and cause
@@ -1004,6 +1012,14 @@ void LayerSnapshotBuilder::updateRoundedCorner(LayerSnapshot& snapshot,
10041012
} else if (parentRoundedCornerValid) {
10051013
snapshot.roundedCorner = parentRoundedCorner;
10061014
}
1015+
1016+
if (snapshot.roundedCorner.requestedRadius.x == requested.clientDrawnCornerRadius) {
1017+
// If the client drawn radius matches the requested radius, then surfaceflinger
1018+
// does not need to draw rounded corners for this layer
1019+
snapshot.roundedCorner.radius = vec2(0.f, 0.f);
1020+
} else {
1021+
snapshot.roundedCorner.radius = snapshot.roundedCorner.requestedRadius;
1022+
}
10071023
}
10081024

10091025
/**

services/surfaceflinger/FrontEnd/RequestedLayerState.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
107107
hdrMetadata.validTypes = 0;
108108
surfaceDamageRegion = Region::INVALID_REGION;
109109
cornerRadius = 0.0f;
110+
clientDrawnCornerRadius = 0.0f;
111+
clientDrawnShadowRadius = 0.0f;
110112
backgroundBlurRadius = 0;
111113
api = -1;
112114
hasColorTransform = false;
@@ -348,6 +350,16 @@ void RequestedLayerState::merge(const ResolvedComposerState& resolvedComposerSta
348350
requestedFrameRate.category = category;
349351
changes |= RequestedLayerState::Changes::FrameRate;
350352
}
353+
354+
if (clientState.what & layer_state_t::eClientDrawnCornerRadiusChanged) {
355+
clientDrawnCornerRadius = clientState.clientDrawnCornerRadius;
356+
changes |= RequestedLayerState::Changes::Geometry;
357+
}
358+
359+
if (clientState.what & layer_state_t::eClientDrawnShadowsChanged) {
360+
clientDrawnShadowRadius = clientState.clientDrawnShadowRadius;
361+
changes |= RequestedLayerState::Changes::Geometry;
362+
}
351363
}
352364

353365
ui::Size RequestedLayerState::getUnrotatedBufferSize(uint32_t displayRotationFlags) const {
@@ -624,6 +636,8 @@ bool RequestedLayerState::isSimpleBufferUpdate(const layer_state_t& s) const {
624636
const uint64_t deniedChanges = layer_state_t::ePositionChanged | layer_state_t::eAlphaChanged |
625637
layer_state_t::eColorTransformChanged | layer_state_t::eBackgroundColorChanged |
626638
layer_state_t::eMatrixChanged | layer_state_t::eCornerRadiusChanged |
639+
layer_state_t::eClientDrawnCornerRadiusChanged |
640+
layer_state_t::eClientDrawnShadowsChanged |
627641
layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBufferTransformChanged |
628642
layer_state_t::eTransformToDisplayInverseChanged | layer_state_t::eCropChanged |
629643
layer_state_t::eDataspaceChanged | layer_state_t::eHdrMetadataChanged |

services/surfaceflinger/Layer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,6 @@ class Layer : public virtual RefBase {
516516

517517
bool mGetHandleCalled = false;
518518

519-
// The inherited shadow radius after taking into account the layer hierarchy. This is the
520-
// final shadow radius for this layer. If a shadow is specified for a layer, then effective
521-
// shadow radius is the set shadow radius, otherwise its the parent's shadow radius.
522-
float mEffectiveShadowRadius = 0.f;
523-
524519
// Game mode for the layer. Set by WindowManagerShell and recorded by SurfaceFlingerStats.
525520
gui::GameMode mGameMode = gui::GameMode::Unsupported;
526521

0 commit comments

Comments
 (0)