summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2022-10-12 19:03:23 +0000
committer Vishnu Nair <vishnun@google.com> 2022-10-20 18:47:10 +0000
commitcb8be5077baca59c45b3a0975ace5944b251937a (patch)
treebf61f3c267fa30fde06764daed87ea59284634b6
parenta61e4fbf1b2276ae43d23d8889f214f40ca13e20 (diff)
SF: Carve out LayerCreationArgs
Move most layer creation logic outside of Layer. Specify layer sequence id via creation args and move ownerUid/ownerPid into the layer creation args so we can share logic between the existing layer class and the new server layer state. Add layer parent and mirror from handles to be used with the new LayerLifecycleManager. Bug: 238781169 Test: presubmit Change-Id: I7cf344181b29f405c070cda2ad45f06233fd1e8c
-rw-r--r--libs/gui/include/gui/LayerMetadata.h3
-rw-r--r--services/surfaceflinger/Android.bp1
-rw-r--r--services/surfaceflinger/Client.cpp4
-rw-r--r--services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp62
-rw-r--r--services/surfaceflinger/FrontEnd/LayerCreationArgs.h56
-rw-r--r--services/surfaceflinger/Layer.cpp38
-rw-r--r--services/surfaceflinger/Layer.h22
-rw-r--r--services/surfaceflinger/LayerRenderArea.cpp1
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp42
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h8
-rw-r--r--services/surfaceflinger/SurfaceFlingerFactory.h2
-rw-r--r--services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp4
-rw-r--r--services/surfaceflinger/tests/unittests/SurfaceFlinger_UpdateLayerMetadataSnapshotTest.cpp58
-rw-r--r--services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h4
14 files changed, 197 insertions, 108 deletions
diff --git a/libs/gui/include/gui/LayerMetadata.h b/libs/gui/include/gui/LayerMetadata.h
index 5af598956b..e16f89c6a5 100644
--- a/libs/gui/include/gui/LayerMetadata.h
+++ b/libs/gui/include/gui/LayerMetadata.h
@@ -30,7 +30,8 @@ enum {
METADATA_ACCESSIBILITY_ID = 5,
METADATA_OWNER_PID = 6,
METADATA_DEQUEUE_TIME = 7,
- METADATA_GAME_MODE = 8
+ METADATA_GAME_MODE = 8,
+ METADATA_CALLING_UID = 9,
};
struct LayerMetadata : public Parcelable {
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index c9c0143c7d..b65f1b48e3 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -155,6 +155,7 @@ filegroup {
"DisplayRenderArea.cpp",
"Effects/Daltonizer.cpp",
"EventLog/EventLog.cpp",
+ "FrontEnd/LayerCreationArgs.cpp",
"FrontEnd/TransactionHandler.cpp",
"FlagManager.cpp",
"FpsReporter.cpp",
diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp
index 30b875967c..7202bef606 100644
--- a/services/surfaceflinger/Client.cpp
+++ b/services/surfaceflinger/Client.cpp
@@ -24,6 +24,7 @@
#include <gui/AidlStatusUtil.h>
#include "Client.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "Layer.h"
#include "SurfaceFlinger.h"
@@ -83,7 +84,8 @@ binder::Status Client::createSurface(const std::string& name, int32_t flags,
sp<IBinder> handle;
LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), name.c_str(),
static_cast<uint32_t>(flags), std::move(metadata));
- const status_t status = mFlinger->createLayer(args, parent, *outResult);
+ args.parentHandle = parent;
+ const status_t status = mFlinger->createLayer(args, *outResult);
return binderStatusFromStatusT(status);
}
diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp
new file mode 100644
index 0000000000..6d492c0f4a
--- /dev/null
+++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "LayerCreationArgs.h"
+#include <binder/IPCThreadState.h>
+#include <private/android_filesystem_config.h>
+#include "Client.h"
+#include "gui/LayerMetadata.h"
+
+namespace android::surfaceflinger {
+
+std::atomic<uint32_t> LayerCreationArgs::sSequence{1};
+
+LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name,
+ uint32_t flags, gui::LayerMetadata metadataArg,
+ std::optional<uint32_t> id)
+ : flinger(flinger),
+ client(std::move(client)),
+ name(std::move(name)),
+ flags(flags),
+ metadata(std::move(metadataArg)) {
+ IPCThreadState* ipc = IPCThreadState::self();
+ ownerPid = ipc->getCallingPid();
+ uid_t callingUid = ipc->getCallingUid();
+ metadata.setInt32(gui::METADATA_CALLING_UID, static_cast<int32_t>(callingUid));
+ ownerUid = callingUid;
+ if (ownerUid == AID_GRAPHICS || ownerUid == AID_SYSTEM) {
+ // System can override the calling UID/PID since it can create layers on behalf of apps.
+ ownerPid = metadata.getInt32(gui::METADATA_OWNER_PID, ownerPid);
+ ownerUid = static_cast<uid_t>(
+ metadata.getInt32(gui::METADATA_OWNER_UID, static_cast<int32_t>(ownerUid)));
+ }
+
+ if (id) {
+ sequence = *id;
+ sSequence = *id + 1;
+ } else {
+ sequence = sSequence++;
+ if (sequence == UNASSIGNED_LAYER_ID) {
+ ALOGW("Layer sequence id rolled over.");
+ sequence = sSequence++;
+ }
+ }
+}
+
+LayerCreationArgs::LayerCreationArgs(const LayerCreationArgs& args)
+ : LayerCreationArgs(args.flinger, args.client, args.name, args.flags, args.metadata) {}
+
+} // namespace android::surfaceflinger
diff --git a/services/surfaceflinger/FrontEnd/LayerCreationArgs.h b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h
new file mode 100644
index 0000000000..7b5a157871
--- /dev/null
+++ b/services/surfaceflinger/FrontEnd/LayerCreationArgs.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <binder/Binder.h>
+#include <gui/LayerMetadata.h>
+#include <utils/StrongPointer.h>
+#include <cstdint>
+#include <limits>
+#include <optional>
+constexpr uint32_t UNASSIGNED_LAYER_ID = std::numeric_limits<uint32_t>::max();
+
+namespace android {
+class SurfaceFlinger;
+class Client;
+} // namespace android
+
+namespace android::surfaceflinger {
+
+struct LayerCreationArgs {
+ static std::atomic<uint32_t> sSequence;
+
+ LayerCreationArgs(android::SurfaceFlinger*, sp<android::Client>, std::string name,
+ uint32_t flags, gui::LayerMetadata,
+ std::optional<uint32_t> id = std::nullopt);
+ LayerCreationArgs(const LayerCreationArgs&);
+
+ android::SurfaceFlinger* flinger;
+ sp<android::Client> client;
+ std::string name;
+ uint32_t flags; // ISurfaceComposerClient flags
+ gui::LayerMetadata metadata;
+ pid_t ownerPid;
+ uid_t ownerUid;
+ uint32_t textureName;
+ uint32_t sequence;
+ bool addToRoot = true;
+ wp<IBinder> parentHandle = nullptr;
+ wp<IBinder> mirrorLayerHandle = nullptr;
+};
+
+} // namespace android::surfaceflinger
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index c2a0e3082d..c79b7f5a08 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -68,6 +68,7 @@
#include "DisplayHardware/HWComposer.h"
#include "FrameTimeline.h"
#include "FrameTracer/FrameTracer.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "LayerProtoHelper.h"
#include "SurfaceFlinger.h"
#include "TimeStats/TimeStats.h"
@@ -131,10 +132,8 @@ using gui::WindowInfo;
using PresentState = frametimeline::SurfaceFrame::PresentState;
-std::atomic<int32_t> Layer::sSequence{1};
-
Layer::Layer(const LayerCreationArgs& args)
- : sequence(args.sequence.value_or(sSequence++)),
+ : sequence(args.sequence),
mFlinger(sp<SurfaceFlinger>::fromExisting(args.flinger)),
mName(base::StringPrintf("%s#%d", args.name.c_str(), sequence)),
mClientRef(args.client),
@@ -153,9 +152,6 @@ Layer::Layer(const LayerCreationArgs& args)
if (args.flags & ISurfaceComposerClient::eSecure) layerFlags |= layer_state_t::eLayerSecure;
if (args.flags & ISurfaceComposerClient::eSkipScreenshot)
layerFlags |= layer_state_t::eLayerSkipScreenshot;
- if (args.sequence) {
- sSequence = *args.sequence + 1;
- }
mDrawingState.flags = layerFlags;
mDrawingState.crop.makeInvalid();
mDrawingState.z = 0;
@@ -200,18 +196,8 @@ Layer::Layer(const LayerCreationArgs& args)
mFrameTracker.setDisplayRefreshPeriod(
args.flinger->mScheduler->getVsyncPeriodFromRefreshRateConfigs());
- mCallingPid = args.callingPid;
- mCallingUid = args.callingUid;
-
- if (mCallingUid == AID_GRAPHICS || mCallingUid == AID_SYSTEM) {
- // If the system didn't send an ownerUid, use the callingUid for the ownerUid.
- mOwnerUid = args.metadata.getInt32(gui::METADATA_OWNER_UID, mCallingUid);
- mOwnerPid = args.metadata.getInt32(gui::METADATA_OWNER_PID, mCallingPid);
- } else {
- // A create layer request from a non system request cannot specify the owner uid
- mOwnerUid = mCallingUid;
- mOwnerPid = mCallingPid;
- }
+ mOwnerUid = args.ownerUid;
+ mOwnerPid = args.ownerPid;
mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied);
mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow;
@@ -268,18 +254,6 @@ Layer::~Layer() {
}
}
-LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name,
- uint32_t flags, LayerMetadata metadata)
- : flinger(flinger),
- client(std::move(client)),
- name(std::move(name)),
- flags(flags),
- metadata(std::move(metadata)) {
- IPCThreadState* ipc = IPCThreadState::self();
- callingPid = ipc->getCallingPid();
- callingUid = ipc->getCallingUid();
-}
-
// ---------------------------------------------------------------------------
// callbacks
// ---------------------------------------------------------------------------
@@ -1498,8 +1472,8 @@ void Layer::getFrameStats(FrameStats* outStats) const {
}
void Layer::dumpCallingUidPid(std::string& result) const {
- StringAppendF(&result, "Layer %s (%s) callingPid:%d callingUid:%d ownerUid:%d\n",
- getName().c_str(), getType(), mCallingPid, mCallingUid, mOwnerUid);
+ StringAppendF(&result, "Layer %s (%s) ownerPid:%d ownerUid:%d\n", getName().c_str(), getType(),
+ mOwnerPid, mOwnerUid);
}
void Layer::onDisconnect() {
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index da8be6b8f0..ba13444532 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -82,24 +82,7 @@ namespace frametimeline {
class SurfaceFrame;
} // namespace frametimeline
-struct LayerCreationArgs {
- LayerCreationArgs(SurfaceFlinger*, sp<Client>, std::string name, uint32_t flags, LayerMetadata);
-
- SurfaceFlinger* flinger;
- const sp<Client> client;
- std::string name;
- uint32_t flags;
- LayerMetadata metadata;
-
- pid_t callingPid;
- uid_t callingUid;
- uint32_t textureName;
- std::optional<uint32_t> sequence = std::nullopt;
- bool addToRoot = true;
-};
-
class Layer : public virtual RefBase {
- static std::atomic<int32_t> sSequence;
// The following constants represent priority of the window. SF uses this information when
// deciding which window has a priority when deciding about the refresh rate of the screen.
// Priority 0 is considered the highest priority. -1 means that the priority is unset.
@@ -1113,11 +1096,6 @@ private:
bool mGetHandleCalled = false;
- // Tracks the process and user id of the caller when creating this layer
- // to help debugging.
- pid_t mCallingPid;
- uid_t mCallingUid;
-
// The current layer is a clone of mClonedFrom. This means that this layer will update it's
// properties based on mClonedFrom. When mClonedFrom latches a new buffer for BufferLayers,
// this layer will update it's buffer. When mClonedFrom updates it's drawing state, children,
diff --git a/services/surfaceflinger/LayerRenderArea.cpp b/services/surfaceflinger/LayerRenderArea.cpp
index 3e6ed416fc..554fae401e 100644
--- a/services/surfaceflinger/LayerRenderArea.cpp
+++ b/services/surfaceflinger/LayerRenderArea.cpp
@@ -18,6 +18,7 @@
#include <ui/Transform.h>
#include "DisplayDevice.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "Layer.h"
#include "LayerRenderArea.h"
#include "SurfaceFlinger.h"
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index a04ceefaf4..a558a99461 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -122,6 +122,7 @@
#include "FpsReporter.h"
#include "FrameTimeline/FrameTimeline.h"
#include "FrameTracer/FrameTracer.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "HdrLayerInfoReporter.h"
#include "Layer.h"
#include "LayerProtoHelper.h"
@@ -3601,9 +3602,9 @@ bool SurfaceFlinger::latchBuffers() {
return !mLayersWithQueuedFrames.empty() && newDataLatched;
}
-status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBinder>& handle,
+status_t SurfaceFlinger::addClientLayer(const LayerCreationArgs& args, const sp<IBinder>& handle,
const sp<Layer>& layer, const wp<Layer>& parent,
- bool addToRoot, uint32_t* outTransformHint) {
+ uint32_t* outTransformHint) {
if (mNumLayers >= MAX_LAYERS) {
ALOGE("AddClientLayer failed, mNumLayers (%zu) >= MAX_LAYERS (%zu)", mNumLayers.load(),
MAX_LAYERS);
@@ -3634,12 +3635,12 @@ status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBind
{
std::scoped_lock<std::mutex> lock(mCreatedLayersLock);
- mCreatedLayers.emplace_back(layer, parent, addToRoot);
+ mCreatedLayers.emplace_back(layer, parent, args.addToRoot);
}
// attach this layer to the client
- if (client != nullptr) {
- client->attachLayer(handle, layer);
+ if (args.client != nullptr) {
+ args.client->attachLayer(handle, layer);
}
setTransactionFlags(eTransactionNeeded);
@@ -4403,8 +4404,10 @@ status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args,
if (!mirrorFrom) {
return NAME_NOT_FOUND;
}
- LayerCreationArgs mirrorArgs = args;
+ LayerCreationArgs mirrorArgs(args);
mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill;
+ mirrorArgs.mirrorLayerHandle = mirrorFromHandle;
+ mirrorArgs.addToRoot = false;
status_t result = createEffectLayer(mirrorArgs, &outResult.handle, &mirrorLayer);
if (result != NO_ERROR) {
return result;
@@ -4420,8 +4423,7 @@ status_t SurfaceFlinger::mirrorLayer(const LayerCreationArgs& args,
mirrorLayer->sequence, args.name,
mirrorFrom->sequence);
}
- return addClientLayer(args.client, outResult.handle, mirrorLayer /* layer */,
- nullptr /* parent */, false /* addToRoot */,
+ return addClientLayer(args, outResult.handle, mirrorLayer /* layer */, nullptr /* parent */,
nullptr /* outTransformHint */);
}
@@ -4447,14 +4449,14 @@ status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationA
}
layerStack = display->getLayerStack();
- LayerCreationArgs mirrorArgs = args;
+ LayerCreationArgs mirrorArgs(args);
mirrorArgs.flags |= ISurfaceComposerClient::eNoColorFill;
+ mirrorArgs.addToRoot = true;
result = createEffectLayer(mirrorArgs, &outResult.handle, &rootMirrorLayer);
outResult.layerId = rootMirrorLayer->sequence;
outResult.layerName = String16(rootMirrorLayer->getDebugName());
- result |= addClientLayer(args.client, outResult.handle, rootMirrorLayer /* layer */,
- nullptr /* parent */, true /* addToRoot */,
- nullptr /* outTransformHint */);
+ result |= addClientLayer(args, outResult.handle, rootMirrorLayer /* layer */,
+ nullptr /* parent */, nullptr /* outTransformHint */);
}
if (result != NO_ERROR) {
@@ -4475,8 +4477,7 @@ status_t SurfaceFlinger::mirrorDisplay(DisplayId displayId, const LayerCreationA
return NO_ERROR;
}
-status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, const sp<IBinder>& parentHandle,
- gui::CreateSurfaceResult& outResult) {
+status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult) {
status_t result = NO_ERROR;
sp<Layer> layer;
@@ -4505,11 +4506,11 @@ status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, const sp<IBinder>&
return result;
}
- bool addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess();
- wp<Layer> parent = fromHandle(parentHandle);
- if (parentHandle != nullptr && parent == nullptr) {
- ALOGE("Invalid parent handle %p.", parentHandle.get());
- addToRoot = false;
+ args.addToRoot = args.addToRoot && callingThreadHasUnscopedSurfaceFlingerAccess();
+ wp<Layer> parent = fromHandle(args.parentHandle.promote());
+ if (args.parentHandle != nullptr && parent == nullptr) {
+ ALOGE("Invalid parent handle %p.", args.parentHandle.promote().get());
+ args.addToRoot = false;
}
int parentId = -1;
@@ -4525,8 +4526,7 @@ status_t SurfaceFlinger::createLayer(LayerCreationArgs& args, const sp<IBinder>&
}
uint32_t outTransformHint;
- result = addClientLayer(args.client, outResult.handle, layer, parent, addToRoot,
- &outTransformHint);
+ result = addClientLayer(args, outResult.handle, layer, parent, &outTransformHint);
if (result != NO_ERROR) {
return result;
}
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index d512841e9f..1d50830ce2 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -65,6 +65,7 @@
#include "DisplayIdGenerator.h"
#include "Effects/Daltonizer.h"
#include "FlagManager.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "FrontEnd/TransactionHandler.h"
#include "LayerVector.h"
#include "Scheduler/RefreshRateConfigs.h"
@@ -755,8 +756,7 @@ private:
/*
* Layer management
*/
- status_t createLayer(LayerCreationArgs& args, const sp<IBinder>& parentHandle,
- gui::CreateSurfaceResult& outResult);
+ status_t createLayer(LayerCreationArgs& args, gui::CreateSurfaceResult& outResult);
status_t createBufferStateLayer(LayerCreationArgs& args, sp<IBinder>* outHandle,
sp<Layer>* outLayer);
@@ -777,8 +777,8 @@ private:
void markLayerPendingRemovalLocked(const sp<Layer>& layer);
// add a layer to SurfaceFlinger
- status_t addClientLayer(const sp<Client>& client, const sp<IBinder>& handle,
- const sp<Layer>& lbc, const wp<Layer>& parentLayer, bool addToRoot,
+ status_t addClientLayer(const LayerCreationArgs& args, const sp<IBinder>& handle,
+ const sp<Layer>& layer, const wp<Layer>& parentLayer,
uint32_t* outTransformHint);
// Traverse through all the layers and compute and cache its bounds.
diff --git a/services/surfaceflinger/SurfaceFlingerFactory.h b/services/surfaceflinger/SurfaceFlingerFactory.h
index d1f21bfb43..41edd22102 100644
--- a/services/surfaceflinger/SurfaceFlingerFactory.h
+++ b/services/surfaceflinger/SurfaceFlingerFactory.h
@@ -44,7 +44,6 @@ class SurfaceFlinger;
class TimeStats;
struct DisplayDeviceCreationArgs;
-struct LayerCreationArgs;
namespace compositionengine {
class CompositionEngine;
@@ -62,6 +61,7 @@ class FrameTimeline;
namespace surfaceflinger {
+struct LayerCreationArgs;
class NativeWindowSurface;
// The interface that SurfaceFlinger uses to create all of the implementations
diff --git a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
index 276b3dad18..033f5b45d9 100644
--- a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
+++ b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp
@@ -213,8 +213,8 @@ bool LayerTraceGenerator::generate(const proto::TransactionTraceFile& traceFile,
gui::CreateSurfaceResult outResult;
LayerCreationArgs args(mFlinger.flinger(), nullptr /* client */, tracingArgs.name,
- tracingArgs.flags, LayerMetadata());
- args.sequence = std::make_optional<int32_t>(tracingArgs.layerId);
+ tracingArgs.flags, LayerMetadata(),
+ std::make_optional<int32_t>(tracingArgs.layerId));
if (tracingArgs.mirrorFromId == -1) {
sp<IBinder> parentHandle = nullptr;
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_UpdateLayerMetadataSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_UpdateLayerMetadataSnapshotTest.cpp
index 0cf3bdf0d5..fed6a1ae56 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_UpdateLayerMetadataSnapshotTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_UpdateLayerMetadataSnapshotTest.cpp
@@ -44,9 +44,11 @@ protected:
std::move(eventThread), std::move(sfEventThread));
}
- sp<Layer> createLayer(const char* name, LayerMetadata layerMetadata) {
- return sp<Layer>::make(
- LayerCreationArgs{mFlinger.flinger(), nullptr, name, 0, layerMetadata});
+ sp<Layer> createLayer(const char* name, LayerMetadata& inOutlayerMetadata) {
+ LayerCreationArgs args =
+ LayerCreationArgs{mFlinger.flinger(), nullptr, name, 0, inOutlayerMetadata};
+ inOutlayerMetadata = args.metadata;
+ return sp<Layer>::make(args);
}
TestableSurfaceFlinger mFlinger;
@@ -90,7 +92,7 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, updatesSnapshotMetadata) {
mFlinger.updateLayerMetadataSnapshot();
- ASSERT_EQ(layer->getLayerSnapshot()->layerMetadata, layerMetadata);
+ EXPECT_EQ(layer->getLayerSnapshot()->layerMetadata, layerMetadata);
}
// Test that snapshot layer metadata is set by merging the child's metadata on top of its
@@ -109,10 +111,10 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, mergesSnapshotMetadata) {
mFlinger.updateLayerMetadataSnapshot();
- ASSERT_EQ(layerA->getLayerSnapshot()->layerMetadata, layerAMetadata);
+ EXPECT_EQ(layerA->getLayerSnapshot()->layerMetadata, layerAMetadata);
auto expectedChildMetadata =
LayerMetadataBuilder(layerAMetadata).setInt32(METADATA_TASK_ID, 3).build();
- ASSERT_EQ(layerB->getLayerSnapshot()->layerMetadata, expectedChildMetadata);
+ EXPECT_EQ(layerB->getLayerSnapshot()->layerMetadata, expectedChildMetadata);
}
// Test that snapshot relative layer metadata is set to the parent's layer metadata merged on top of
@@ -129,8 +131,8 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, updatesRelativeMetadata) {
mFlinger.updateLayerMetadataSnapshot();
- ASSERT_EQ(layerA->getLayerSnapshot()->relativeLayerMetadata, LayerMetadata{});
- ASSERT_EQ(layerB->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
+ EXPECT_EQ(layerA->getLayerSnapshot()->relativeLayerMetadata, LayerMetadata{});
+ EXPECT_EQ(layerB->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
}
// Test that snapshot relative layer metadata is set correctly when a layer is interleaved within
@@ -154,7 +156,8 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, updatesRelativeMetadataInt
.build();
auto layerB = createLayer("layer-b", layerBMetadata);
auto layerBHandle = layerB->getHandle();
- auto layerC = createLayer("layer-c", {});
+ LayerMetadata layerCMetadata;
+ auto layerC = createLayer("layer-c", layerCMetadata);
auto layerDMetadata = LayerMetadataBuilder().setInt32(METADATA_TASK_ID, 4).build();
auto layerD = createLayer("layer-d", layerDMetadata);
auto layerDHandle = layerD->getHandle();
@@ -168,14 +171,18 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, updatesRelativeMetadataInt
mFlinger.updateLayerMetadataSnapshot();
- auto expectedLayerDRelativeMetadata = LayerMetadataBuilder()
- // From layer A, parent of relative parent
- .setInt32(METADATA_OWNER_UID, 1)
- // From layer B, relative parent
- .setInt32(METADATA_TASK_ID, 2)
- .setInt32(METADATA_OWNER_PID, 3)
- .build();
- ASSERT_EQ(layerD->getLayerSnapshot()->relativeLayerMetadata, expectedLayerDRelativeMetadata);
+ auto expectedLayerDRelativeMetadata =
+ LayerMetadataBuilder()
+ // From layer A, parent of relative parent
+ .setInt32(METADATA_OWNER_UID, 1)
+ // From layer B, relative parent
+ .setInt32(METADATA_TASK_ID, 2)
+ .setInt32(METADATA_OWNER_PID, 3)
+ // added by layer creation args
+ .setInt32(gui::METADATA_CALLING_UID,
+ layerDMetadata.getInt32(gui::METADATA_CALLING_UID, 0))
+ .build();
+ EXPECT_EQ(layerD->getLayerSnapshot()->relativeLayerMetadata, expectedLayerDRelativeMetadata);
auto expectedLayerCRelativeMetadata =
LayerMetadataBuilder()
// From layer A, parent of relative parent
@@ -184,8 +191,11 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest, updatesRelativeMetadataInt
.setInt32(METADATA_OWNER_PID, 3)
// From layer D, relative parent
.setInt32(METADATA_TASK_ID, 4)
+ // added by layer creation args
+ .setInt32(gui::METADATA_CALLING_UID,
+ layerDMetadata.getInt32(gui::METADATA_CALLING_UID, 0))
.build();
- ASSERT_EQ(layerC->getLayerSnapshot()->relativeLayerMetadata, expectedLayerCRelativeMetadata);
+ EXPECT_EQ(layerC->getLayerSnapshot()->relativeLayerMetadata, expectedLayerCRelativeMetadata);
}
TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest,
@@ -193,8 +203,10 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest,
auto layerAMetadata = LayerMetadataBuilder().setInt32(METADATA_OWNER_UID, 1).build();
auto layerA = createLayer("layer-a", layerAMetadata);
auto layerAHandle = layerA->getHandle();
- auto layerB = createLayer("layer-b", {});
- auto layerC = createLayer("layer-c", {});
+ LayerMetadata layerBMetadata;
+ auto layerB = createLayer("layer-b", layerBMetadata);
+ LayerMetadata layerCMetadata;
+ auto layerC = createLayer("layer-c", layerCMetadata);
layerB->setRelativeLayer(layerAHandle, 1);
layerC->setRelativeLayer(layerAHandle, 2);
layerA->commitChildList();
@@ -204,9 +216,9 @@ TEST_F(SurfaceFlingerUpdateLayerMetadataSnapshotTest,
mFlinger.updateLayerMetadataSnapshot();
- ASSERT_EQ(layerA->getLayerSnapshot()->relativeLayerMetadata, LayerMetadata{});
- ASSERT_EQ(layerB->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
- ASSERT_EQ(layerC->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
+ EXPECT_EQ(layerA->getLayerSnapshot()->relativeLayerMetadata, LayerMetadata{});
+ EXPECT_EQ(layerB->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
+ EXPECT_EQ(layerC->getLayerSnapshot()->relativeLayerMetadata, layerAMetadata);
}
} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 83d852a1fa..51607b2331 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -33,6 +33,7 @@
#include "DisplayDevice.h"
#include "FakeVsyncConfiguration.h"
#include "FrameTracer/FrameTracer.h"
+#include "FrontEnd/LayerCreationArgs.h"
#include "Layer.h"
#include "NativeWindowSurface.h"
#include "Scheduler/MessageQueue.h"
@@ -469,7 +470,8 @@ public:
auto createLayer(LayerCreationArgs& args, const sp<IBinder>& parentHandle,
gui::CreateSurfaceResult& outResult) {
- return mFlinger->createLayer(args, parentHandle, outResult);
+ args.parentHandle = parentHandle;
+ return mFlinger->createLayer(args, outResult);
}
auto mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle,