Pass surface control instead of handle as reference to layers in
LayerState
Allows us to have access to the layer id stored in surface control so that it can be dumped when tracing the transaction merges
Test: Existing tests
Change-Id: I3e466c69585937d8ce74a29a49fdbb7b3353a460
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 4a57b1b..a4de66e 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -18,16 +18,55 @@
#include <inttypes.h>
-#include <utils/Errors.h>
#include <binder/Parcel.h>
-#include <gui/ISurfaceComposerClient.h>
#include <gui/IGraphicBufferProducer.h>
+#include <gui/ISurfaceComposerClient.h>
#include <gui/LayerState.h>
+#include <utils/Errors.h>
#include <cmath>
namespace android {
+layer_state_t::layer_state_t()
+ : what(0),
+ x(0),
+ y(0),
+ z(0),
+ w(0),
+ h(0),
+ layerStack(0),
+ alpha(0),
+ flags(0),
+ mask(0),
+ reserved(0),
+ crop_legacy(Rect::INVALID_RECT),
+ cornerRadius(0.0f),
+ backgroundBlurRadius(0),
+ barrierFrameNumber(0),
+ overrideScalingMode(-1),
+ transform(0),
+ transformToDisplayInverse(false),
+ crop(Rect::INVALID_RECT),
+ orientedDisplaySpaceRect(Rect::INVALID_RECT),
+ dataspace(ui::Dataspace::UNKNOWN),
+ surfaceDamageRegion(),
+ api(-1),
+ colorTransform(mat4()),
+ bgColorAlpha(0),
+ bgColorDataspace(ui::Dataspace::UNKNOWN),
+ colorSpaceAgnostic(false),
+ shadowRadius(0.0f),
+ frameRateSelectionPriority(-1),
+ frameRate(0.0f),
+ frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
+ fixedTransformHint(ui::Transform::ROT_INVALID),
+ frameNumber(0) {
+ matrix.dsdx = matrix.dtdy = 1.0f;
+ matrix.dsdy = matrix.dtdx = 0.0f;
+ hdrMetadata.validTypes = 0;
+}
+
status_t layer_state_t::write(Parcel& output) const
{
SAFE_PARCEL(output.writeStrongBinder, surface);
@@ -44,13 +83,13 @@
SAFE_PARCEL(output.writeUint32, mask);
SAFE_PARCEL(matrix.write, output);
SAFE_PARCEL(output.write, crop_legacy);
- SAFE_PARCEL(output.writeStrongBinder, barrierHandle_legacy);
- SAFE_PARCEL(output.writeStrongBinder, reparentHandle);
+ SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, barrierSurfaceControl_legacy);
+ SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
SAFE_PARCEL(output.writeUint64, barrierFrameNumber);
SAFE_PARCEL(output.writeInt32, overrideScalingMode);
SAFE_PARCEL(output.writeStrongBinder, IInterface::asBinder(barrierGbp_legacy));
- SAFE_PARCEL(output.writeStrongBinder, relativeLayerHandle);
- SAFE_PARCEL(output.writeStrongBinder, parentHandleForChild);
+ SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
+ SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
SAFE_PARCEL(output.writeFloat, color.r);
SAFE_PARCEL(output.writeFloat, color.g);
SAFE_PARCEL(output.writeFloat, color.b);
@@ -135,8 +174,8 @@
SAFE_PARCEL(matrix.read, input);
SAFE_PARCEL(input.read, crop_legacy);
- SAFE_PARCEL(input.readNullableStrongBinder, &barrierHandle_legacy);
- SAFE_PARCEL(input.readNullableStrongBinder, &reparentHandle);
+ SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &barrierSurfaceControl_legacy);
+ SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
SAFE_PARCEL(input.readUint64, &barrierFrameNumber);
SAFE_PARCEL(input.readInt32, &overrideScalingMode);
@@ -144,9 +183,10 @@
SAFE_PARCEL(input.readNullableStrongBinder, &tmpBinder);
barrierGbp_legacy = interface_cast<IGraphicBufferProducer>(tmpBinder);
+ SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
+ SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
+
float tmpFloat = 0;
- SAFE_PARCEL(input.readNullableStrongBinder, &relativeLayerHandle);
- SAFE_PARCEL(input.readNullableStrongBinder, &parentHandleForChild);
SAFE_PARCEL(input.readFloat, &tmpFloat);
color.r = tmpFloat;
SAFE_PARCEL(input.readFloat, &tmpFloat);
@@ -342,7 +382,7 @@
}
if (other.what & eDeferTransaction_legacy) {
what |= eDeferTransaction_legacy;
- barrierHandle_legacy = other.barrierHandle_legacy;
+ barrierSurfaceControl_legacy = other.barrierSurfaceControl_legacy;
barrierGbp_legacy = other.barrierGbp_legacy;
barrierFrameNumber = other.barrierFrameNumber;
}
@@ -352,7 +392,7 @@
}
if (other.what & eReparentChildren) {
what |= eReparentChildren;
- reparentHandle = other.reparentHandle;
+ reparentSurfaceControl = other.reparentSurfaceControl;
}
if (other.what & eDetachChildren) {
what |= eDetachChildren;
@@ -361,11 +401,11 @@
what |= eRelativeLayerChanged;
what &= ~eLayerChanged;
z = other.z;
- relativeLayerHandle = other.relativeLayerHandle;
+ relativeLayerSurfaceControl = other.relativeLayerSurfaceControl;
}
if (other.what & eReparent) {
what |= eReparent;
- parentHandleForChild = other.parentHandleForChild;
+ parentSurfaceControlForChild = other.parentSurfaceControlForChild;
}
if (other.what & eDestroySurface) {
what |= eDestroySurface;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 2f6a34b..99d9eba 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -875,8 +875,8 @@
return *this;
}
-SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(const sp<SurfaceControl>& sc, const sp<IBinder>& relativeTo,
- int32_t z) {
+SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setRelativeLayer(
+ const sp<SurfaceControl>& sc, const sp<SurfaceControl>& relativeTo, int32_t z) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
@@ -884,7 +884,7 @@
}
s->what |= layer_state_t::eRelativeLayerChanged;
s->what &= ~layer_state_t::eLayerChanged;
- s->relativeLayerHandle = relativeTo;
+ s->relativeLayerSurfaceControl = relativeTo;
s->z = z;
registerSurfaceControlForCallback(sc);
@@ -1028,16 +1028,16 @@
}
SurfaceComposerClient::Transaction&
-SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
- const sp<IBinder>& handle,
- uint64_t frameNumber) {
+SurfaceComposerClient::Transaction::deferTransactionUntil_legacy(
+ const sp<SurfaceControl>& sc, const sp<SurfaceControl>& barrierSurfaceControl,
+ uint64_t frameNumber) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
return *this;
}
s->what |= layer_state_t::eDeferTransaction_legacy;
- s->barrierHandle_legacy = handle;
+ s->barrierSurfaceControl_legacy = barrierSurfaceControl;
s->barrierFrameNumber = frameNumber;
registerSurfaceControlForCallback(sc);
@@ -1062,30 +1062,28 @@
}
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparentChildren(
- const sp<SurfaceControl>& sc,
- const sp<IBinder>& newParentHandle) {
+ const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
return *this;
}
s->what |= layer_state_t::eReparentChildren;
- s->reparentHandle = newParentHandle;
+ s->reparentSurfaceControl = newParent;
registerSurfaceControlForCallback(sc);
return *this;
}
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::reparent(
- const sp<SurfaceControl>& sc,
- const sp<IBinder>& newParentHandle) {
+ const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent) {
layer_state_t* s = getLayerState(sc);
if (!s) {
mStatus = BAD_INDEX;
return *this;
}
s->what |= layer_state_t::eReparent;
- s->parentHandleForChild = newParentHandle;
+ s->parentSurfaceControlForChild = newParent;
registerSurfaceControlForCallback(sc);
return *this;
diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp
index e37ff89..e842382 100644
--- a/libs/gui/SurfaceControl.cpp
+++ b/libs/gui/SurfaceControl.cpp
@@ -24,6 +24,7 @@
#include <android/native_window.h>
#include <utils/Errors.h>
+#include <utils/KeyedVector.h>
#include <utils/Log.h>
#include <utils/threads.h>
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 65fd9ab..06598e1 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -49,6 +49,7 @@
#include <gui/ISurfaceComposer.h>
#include <gui/LayerMetadata.h>
+#include <gui/SurfaceControl.h>
#include <math/vec3.h>
#include <ui/GraphicTypes.h>
#include <ui/Rect.h>
@@ -128,44 +129,7 @@
eFrameNumberChanged = 0x400'00000000,
};
- layer_state_t()
- : what(0),
- x(0),
- y(0),
- z(0),
- w(0),
- h(0),
- layerStack(0),
- alpha(0),
- flags(0),
- mask(0),
- reserved(0),
- crop_legacy(Rect::INVALID_RECT),
- cornerRadius(0.0f),
- backgroundBlurRadius(0),
- barrierFrameNumber(0),
- overrideScalingMode(-1),
- transform(0),
- transformToDisplayInverse(false),
- crop(Rect::INVALID_RECT),
- orientedDisplaySpaceRect(Rect::INVALID_RECT),
- dataspace(ui::Dataspace::UNKNOWN),
- surfaceDamageRegion(),
- api(-1),
- colorTransform(mat4()),
- bgColorAlpha(0),
- bgColorDataspace(ui::Dataspace::UNKNOWN),
- colorSpaceAgnostic(false),
- shadowRadius(0.0f),
- frameRateSelectionPriority(-1),
- frameRate(0.0f),
- frameRateCompatibility(ANATIVEWINDOW_FRAME_RATE_COMPATIBILITY_DEFAULT),
- fixedTransformHint(ui::Transform::ROT_INVALID),
- frameNumber(0) {
- matrix.dsdx = matrix.dtdy = 1.0f;
- matrix.dsdy = matrix.dtdx = 0.0f;
- hdrMetadata.validTypes = 0;
- }
+ layer_state_t();
void merge(const layer_state_t& other);
status_t write(Parcel& output) const;
@@ -196,16 +160,16 @@
Rect crop_legacy;
float cornerRadius;
uint32_t backgroundBlurRadius;
- sp<IBinder> barrierHandle_legacy;
- sp<IBinder> reparentHandle;
+ sp<SurfaceControl> barrierSurfaceControl_legacy;
+ sp<SurfaceControl> reparentSurfaceControl;
uint64_t barrierFrameNumber;
int32_t overrideScalingMode;
sp<IGraphicBufferProducer> barrierGbp_legacy;
- sp<IBinder> relativeLayerHandle;
+ sp<SurfaceControl> relativeLayerSurfaceControl;
- sp<IBinder> parentHandleForChild;
+ sp<SurfaceControl> parentSurfaceControlForChild;
half3 color;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index cc82502..f366c29 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -424,7 +424,7 @@
// If the relative is removed, the Surface will have no layer and be
// invisible, until the next time set(Relative)Layer is called.
Transaction& setRelativeLayer(const sp<SurfaceControl>& sc,
- const sp<IBinder>& relativeTo, int32_t z);
+ const sp<SurfaceControl>& relativeTo, int32_t z);
Transaction& setFlags(const sp<SurfaceControl>& sc,
uint32_t flags, uint32_t mask);
Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc,
@@ -444,7 +444,8 @@
// by handle is removed, then we will apply this transaction regardless of
// what frame number has been reached.
Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
- const sp<IBinder>& handle, uint64_t frameNumber);
+ const sp<SurfaceControl>& barrierSurfaceControl,
+ uint64_t frameNumber);
// A variant of deferTransactionUntil_legacy which identifies the Layer we wait for by
// Surface instead of Handle. Useful for clients which may not have the
// SurfaceControl for some of their Surfaces. Otherwise behaves identically.
@@ -453,13 +454,12 @@
uint64_t frameNumber);
// Reparents all children of this layer to the new parent handle.
Transaction& reparentChildren(const sp<SurfaceControl>& sc,
- const sp<IBinder>& newParentHandle);
+ const sp<SurfaceControl>& newParent);
/// Reparents the current layer to the new parent handle. The new parent must not be null.
// This can be used instead of reparentChildren if the caller wants to
// only re-parent a specific child.
- Transaction& reparent(const sp<SurfaceControl>& sc,
- const sp<IBinder>& newParentHandle);
+ Transaction& reparent(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent);
Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color);
diff --git a/libs/gui/include/gui/SurfaceControl.h b/libs/gui/include/gui/SurfaceControl.h
index c0dfcdb..35bdfc1 100644
--- a/libs/gui/include/gui/SurfaceControl.h
+++ b/libs/gui/include/gui/SurfaceControl.h
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <sys/types.h>
-#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/threads.h>
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index ef4d870..483f171 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -381,7 +381,7 @@
childSurface->doTransaction([&](auto &t, auto &sc) {
t.setPosition(sc, -5, -5);
- t.reparent(sc, parentSurface->mSurfaceControl->getHandle());
+ t.reparent(sc, parentSurface->mSurfaceControl);
});
injectTap(106, 106);