Skip to content

Commit c7f8793

Browse files
author
Anton Ivanov
committed
Provide classes that logically make up a transaction with == and !=.
Primarily this change is intended to support writing test assertions. As a side effect, make some improvements to encapsulation of members. Flag: EXEMPT refactor Bug: 385156191 Test: presubmit Change-Id: I51352c78ccfcb0fc6bff655593d7d31771516668
1 parent c93479c commit c7f8793

16 files changed

Lines changed: 265 additions & 166 deletions

libs/gui/LayerState.cpp

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ namespace android {
5555
using gui::FocusRequest;
5656
using gui::WindowInfoHandle;
5757

58+
namespace {
59+
bool isSameWindowHandle(const sp<WindowInfoHandle>& lhs, const sp<WindowInfoHandle>& rhs) {
60+
if (lhs == rhs) {
61+
return true;
62+
}
63+
64+
if (!lhs || !rhs) {
65+
return false;
66+
}
67+
68+
return *lhs->getInfo() == *rhs->getInfo();
69+
};
70+
71+
bool isSameSurfaceControl(const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs) {
72+
if (lhs == rhs) {
73+
return true;
74+
}
75+
76+
return SurfaceControl::isSameSurface(lhs, rhs);
77+
};
78+
} // namespace
79+
5880
layer_state_t::layer_state_t()
5981
: surface(nullptr),
6082
layerId(-1),
@@ -73,7 +95,6 @@ layer_state_t::layer_state_t()
7395
transformToDisplayInverse(false),
7496
crop({0, 0, -1, -1}),
7597
dataspace(ui::Dataspace::UNKNOWN),
76-
surfaceDamageRegion(),
7798
api(-1),
7899
colorTransform(mat4()),
79100
bgColor(0),
@@ -117,19 +138,21 @@ status_t layer_state_t::write(Parcel& output) const
117138
SAFE_PARCEL(output.writeFloat, crop.left);
118139
SAFE_PARCEL(output.writeFloat, crop.bottom);
119140
SAFE_PARCEL(output.writeFloat, crop.right);
120-
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
121-
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
141+
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output,
142+
mNotDefCmpState.relativeLayerSurfaceControl);
143+
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output,
144+
mNotDefCmpState.parentSurfaceControlForChild);
122145
SAFE_PARCEL(output.writeFloat, color.r);
123146
SAFE_PARCEL(output.writeFloat, color.g);
124147
SAFE_PARCEL(output.writeFloat, color.b);
125148
SAFE_PARCEL(output.writeFloat, color.a);
126-
SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
127-
SAFE_PARCEL(output.write, transparentRegion);
149+
SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->writeToParcel, &output);
150+
SAFE_PARCEL(output.write, mNotDefCmpState.transparentRegion);
128151
SAFE_PARCEL(output.writeUint32, bufferTransform);
129152
SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
130153
SAFE_PARCEL(output.writeUint32, static_cast<uint32_t>(dataspace));
131154
SAFE_PARCEL(output.write, hdrMetadata);
132-
SAFE_PARCEL(output.write, surfaceDamageRegion);
155+
SAFE_PARCEL(output.write, mNotDefCmpState.surfaceDamageRegion);
133156
SAFE_PARCEL(output.writeInt32, api);
134157

135158
if (sidebandStream) {
@@ -241,8 +264,10 @@ status_t layer_state_t::read(const Parcel& input)
241264
SAFE_PARCEL(input.readFloat, &crop.bottom);
242265
SAFE_PARCEL(input.readFloat, &crop.right);
243266

244-
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
245-
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
267+
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
268+
&mNotDefCmpState.relativeLayerSurfaceControl);
269+
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input,
270+
&mNotDefCmpState.parentSurfaceControlForChild);
246271

247272
float tmpFloat = 0;
248273
SAFE_PARCEL(input.readFloat, &tmpFloat);
@@ -254,9 +279,9 @@ status_t layer_state_t::read(const Parcel& input)
254279
SAFE_PARCEL(input.readFloat, &tmpFloat);
255280
color.a = tmpFloat;
256281

257-
SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
282+
SAFE_PARCEL(mNotDefCmpState.windowInfoHandle->readFromParcel, &input);
258283

259-
SAFE_PARCEL(input.read, transparentRegion);
284+
SAFE_PARCEL(input.read, mNotDefCmpState.transparentRegion);
260285
SAFE_PARCEL(input.readUint32, &bufferTransform);
261286
SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
262287

@@ -265,7 +290,7 @@ status_t layer_state_t::read(const Parcel& input)
265290
dataspace = static_cast<ui::Dataspace>(tmpUint32);
266291

267292
SAFE_PARCEL(input.read, hdrMetadata);
268-
SAFE_PARCEL(input.read, surfaceDamageRegion);
293+
SAFE_PARCEL(input.read, mNotDefCmpState.surfaceDamageRegion);
269294
SAFE_PARCEL(input.readInt32, &api);
270295

271296
bool tmpBool = false;
@@ -583,7 +608,7 @@ void layer_state_t::merge(const layer_state_t& other) {
583608
}
584609
if (other.what & eTransparentRegionChanged) {
585610
what |= eTransparentRegionChanged;
586-
transparentRegion = other.transparentRegion;
611+
mNotDefCmpState.transparentRegion = other.mNotDefCmpState.transparentRegion;
587612
}
588613
if (other.what & eFlagsChanged) {
589614
what |= eFlagsChanged;
@@ -615,11 +640,13 @@ void layer_state_t::merge(const layer_state_t& other) {
615640
what |= eRelativeLayerChanged;
616641
what &= ~eLayerChanged;
617642
z = other.z;
618-
relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
643+
mNotDefCmpState.relativeLayerSurfaceControl =
644+
other.mNotDefCmpState.relativeLayerSurfaceControl;
619645
}
620646
if (other.what & eReparent) {
621647
what |= eReparent;
622-
parentSurfaceControlForChild = other.parentSurfaceControlForChild;
648+
mNotDefCmpState.parentSurfaceControlForChild =
649+
other.mNotDefCmpState.parentSurfaceControlForChild;
623650
}
624651
if (other.what & eBufferTransformChanged) {
625652
what |= eBufferTransformChanged;
@@ -665,7 +692,7 @@ void layer_state_t::merge(const layer_state_t& other) {
665692
}
666693
if (other.what & eSurfaceDamageRegionChanged) {
667694
what |= eSurfaceDamageRegionChanged;
668-
surfaceDamageRegion = other.surfaceDamageRegion;
695+
mNotDefCmpState.surfaceDamageRegion = other.mNotDefCmpState.surfaceDamageRegion;
669696
}
670697
if (other.what & eApiChanged) {
671698
what |= eApiChanged;
@@ -684,7 +711,8 @@ void layer_state_t::merge(const layer_state_t& other) {
684711
}
685712
if (other.what & eInputInfoChanged) {
686713
what |= eInputInfoChanged;
687-
windowInfoHandle = sp<WindowInfoHandle>::make(*other.windowInfoHandle);
714+
mNotDefCmpState.windowInfoHandle =
715+
sp<WindowInfoHandle>::make(*other.mNotDefCmpState.windowInfoHandle);
688716
}
689717
if (other.what & eBackgroundColorChanged) {
690718
what |= eBackgroundColorChanged;
@@ -807,7 +835,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
807835
CHECK_DIFF(diff, eAlphaChanged, other, color.a);
808836
CHECK_DIFF(diff, eMatrixChanged, other, matrix);
809837
if (other.what & eTransparentRegionChanged &&
810-
(!transparentRegion.hasSameRects(other.transparentRegion))) {
838+
(!mNotDefCmpState.transparentRegion.hasSameRects(
839+
other.mNotDefCmpState.transparentRegion))) {
811840
diff |= eTransparentRegionChanged;
812841
}
813842
if (other.what & eFlagsChanged) {
@@ -824,8 +853,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
824853
diff &= ~eLayerChanged;
825854
}
826855
if (other.what & eReparent &&
827-
!SurfaceControl::isSameSurface(parentSurfaceControlForChild,
828-
other.parentSurfaceControlForChild)) {
856+
!SurfaceControl::isSameSurface(mNotDefCmpState.parentSurfaceControlForChild,
857+
other.mNotDefCmpState.parentSurfaceControlForChild)) {
829858
diff |= eReparent;
830859
}
831860
CHECK_DIFF(diff, eBufferTransformChanged, other, bufferTransform);
@@ -839,7 +868,8 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const {
839868
CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint);
840869
CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata);
841870
if (other.what & eSurfaceDamageRegionChanged &&
842-
(!surfaceDamageRegion.hasSameRects(other.surfaceDamageRegion))) {
871+
(!mNotDefCmpState.surfaceDamageRegion.hasSameRects(
872+
other.mNotDefCmpState.surfaceDamageRegion))) {
843873
diff |= eSurfaceDamageRegionChanged;
844874
}
845875
CHECK_DIFF(diff, eApiChanged, other, api);
@@ -901,6 +931,38 @@ status_t layer_state_t::matrix22_t::read(const Parcel& input) {
901931
SAFE_PARCEL(input.readFloat, &dsdy);
902932
return NO_ERROR;
903933
}
934+
void layer_state_t::updateTransparentRegion(const Region& transparentRegion) {
935+
what |= eTransparentRegionChanged;
936+
mNotDefCmpState.transparentRegion = transparentRegion;
937+
}
938+
void layer_state_t::updateSurfaceDamageRegion(const Region& surfaceDamageRegion) {
939+
what |= eSurfaceDamageRegionChanged;
940+
mNotDefCmpState.surfaceDamageRegion = surfaceDamageRegion;
941+
}
942+
void layer_state_t::updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z) {
943+
what |= layer_state_t::eRelativeLayerChanged;
944+
what &= ~layer_state_t::eLayerChanged;
945+
mNotDefCmpState.relativeLayerSurfaceControl = relativeTo;
946+
this->z = z;
947+
}
948+
void layer_state_t::updateParentLayer(const sp<SurfaceControl>& newParent) {
949+
what |= layer_state_t::eReparent;
950+
mNotDefCmpState.parentSurfaceControlForChild =
951+
newParent ? newParent->getParentingLayer() : nullptr;
952+
}
953+
void layer_state_t::updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info) {
954+
what |= eInputInfoChanged;
955+
mNotDefCmpState.windowInfoHandle = std::move(info);
956+
}
957+
958+
bool layer_state_t::NotDefaultComparableState::operator==(
959+
const NotDefaultComparableState& rhs) const {
960+
return transparentRegion.hasSameRects(rhs.transparentRegion) &&
961+
surfaceDamageRegion.hasSameRects(rhs.surfaceDamageRegion) &&
962+
isSameWindowHandle(windowInfoHandle, rhs.windowInfoHandle) &&
963+
isSameSurfaceControl(relativeLayerSurfaceControl, rhs.relativeLayerSurfaceControl) &&
964+
isSameSurfaceControl(parentSurfaceControlForChild, rhs.parentSurfaceControlForChild);
965+
}
904966

905967
// ------------------------------- InputWindowCommands ----------------------------------------
906968

@@ -1034,18 +1096,18 @@ status_t BufferData::readFromParcel(const Parcel* input) {
10341096
}
10351097

10361098
status_t TrustedPresentationListener::writeToParcel(Parcel* parcel) const {
1037-
SAFE_PARCEL(parcel->writeStrongBinder, callbackInterface);
1038-
SAFE_PARCEL(parcel->writeInt32, callbackId);
1099+
SAFE_PARCEL(parcel->writeStrongBinder, mState.callbackInterface);
1100+
SAFE_PARCEL(parcel->writeInt32, mState.callbackId);
10391101
return NO_ERROR;
10401102
}
10411103

10421104
status_t TrustedPresentationListener::readFromParcel(const Parcel* parcel) {
10431105
sp<IBinder> tmpBinder = nullptr;
10441106
SAFE_PARCEL(parcel->readNullableStrongBinder, &tmpBinder);
10451107
if (tmpBinder) {
1046-
callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
1108+
mState.callbackInterface = checked_interface_cast<ITransactionCompletedListener>(tmpBinder);
10471109
}
1048-
SAFE_PARCEL(parcel->readInt32, &callbackId);
1110+
SAFE_PARCEL(parcel->readInt32, &mState.callbackId);
10491111
return NO_ERROR;
10501112
}
10511113

libs/gui/SurfaceComposerClient.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,11 +1523,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelat
15231523
mStatus = BAD_INDEX;
15241524
return *this;
15251525
}
1526-
s->what |= layer_state_t::eRelativeLayerChanged;
1527-
s->what &= ~layer_state_t::eLayerChanged;
1528-
s->relativeLayerSurfaceControl = relativeTo;
1529-
s->z = z;
1530-
1526+
s->updateRelativeLayer(relativeTo, z);
15311527
registerSurfaceControlForCallback(sc);
15321528
return *this;
15331529
}
@@ -1557,9 +1553,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setTrans
15571553
mStatus = BAD_INDEX;
15581554
return *this;
15591555
}
1560-
s->what |= layer_state_t::eTransparentRegionChanged;
1561-
s->transparentRegion = transparentRegion;
1562-
1556+
s->updateTransparentRegion(transparentRegion);
15631557
registerSurfaceControlForCallback(sc);
15641558
return *this;
15651559
}
@@ -1721,9 +1715,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent
17211715
if (SurfaceControl::isSameSurface(sc, newParent)) {
17221716
return *this;
17231717
}
1724-
s->what |= layer_state_t::eReparent;
1725-
s->parentSurfaceControlForChild = newParent ? newParent->getParentingLayer() : nullptr;
1726-
1718+
s->updateParentLayer(newParent);
17271719
registerSurfaceControlForCallback(sc);
17281720
return *this;
17291721
}
@@ -2009,9 +2001,7 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setSurfa
20092001
mStatus = BAD_INDEX;
20102002
return *this;
20112003
}
2012-
s->what |= layer_state_t::eSurfaceDamageRegionChanged;
2013-
s->surfaceDamageRegion = surfaceDamageRegion;
2014-
2004+
s->updateSurfaceDamageRegion(surfaceDamageRegion);
20152005
registerSurfaceControlForCallback(sc);
20162006
return *this;
20172007
}
@@ -2130,21 +2120,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setInput
21302120
mStatus = BAD_INDEX;
21312121
return *this;
21322122
}
2133-
s->windowInfoHandle = std::move(info);
2134-
s->what |= layer_state_t::eInputInfoChanged;
2123+
s->updateInputWindowInfo(std::move(info));
21352124
return *this;
21362125
}
21372126

21382127
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setFocusedWindow(
21392128
const FocusRequest& request) {
2140-
mInputWindowCommands.focusRequests.push_back(request);
2129+
mInputWindowCommands.addFocusRequest(request);
21412130
return *this;
21422131
}
21432132

21442133
SurfaceComposerClient::Transaction&
21452134
SurfaceComposerClient::Transaction::addWindowInfosReportedListener(
21462135
sp<gui::IWindowInfosReportedListener> windowInfosReportedListener) {
2147-
mInputWindowCommands.windowInfosReportedListeners.insert(windowInfosReportedListener);
2136+
mInputWindowCommands.addWindowInfosReportedListener(windowInfosReportedListener);
21482137
return *this;
21492138
}
21502139

@@ -2572,8 +2561,9 @@ SurfaceComposerClient::Transaction::setTrustedPresentationCallback(
25722561
}
25732562
s->what |= layer_state_t::eTrustedPresentationInfoChanged;
25742563
s->trustedPresentationThresholds = thresholds;
2575-
s->trustedPresentationListener.callbackInterface = TransactionCompletedListener::getIInstance();
2576-
s->trustedPresentationListener.callbackId = sc->getLayerId();
2564+
s->trustedPresentationListener.configure(
2565+
{.callbackInterface = TransactionCompletedListener::getIInstance(),
2566+
.callbackId = sc->getLayerId()});
25772567

25782568
return *this;
25792569
}
@@ -2589,8 +2579,7 @@ SurfaceComposerClient::Transaction::clearTrustedPresentationCallback(const sp<Su
25892579
}
25902580
s->what |= layer_state_t::eTrustedPresentationInfoChanged;
25912581
s->trustedPresentationThresholds = TrustedPresentationThresholds();
2592-
s->trustedPresentationListener.callbackInterface = nullptr;
2593-
s->trustedPresentationListener.callbackId = -1;
2582+
s->trustedPresentationListener.clear();
25942583

25952584
return *this;
25962585
}

libs/gui/include/gui/LayerMetadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ struct LayerMetadata : public Parcelable {
4444
LayerMetadata& operator=(const LayerMetadata& other);
4545
LayerMetadata& operator=(LayerMetadata&& other);
4646

47+
// Note: `default` is not feasible because Parcelable does not provide ==.
48+
bool operator==(const LayerMetadata& rhs) const { return mMap == rhs.mMap; }
49+
bool operator!=(const LayerMetadata&) const = default;
50+
4751
// Merges other into this LayerMetadata. If eraseEmpty is true, any entries in
4852
// in this whose keys are paired with empty values in other will be erased.
4953
bool merge(const LayerMetadata& other, bool eraseEmpty = false);

0 commit comments

Comments
 (0)