SF: Start restructuring display creation
Create the compositionengine::Display first thing, outside of
DisplayDevice, and pass it in as part of creating the DisplayDevice,
rather than creating it internal to DisplayDevice.
Also to start, move the logic to allocate a DisplayId for a HWC backed
virtual display into the CompositionEngine class.
This is a first step to moving the internal setup of the display to
CompositionEngine, and eventually eliminating DisplayDevice entirely, as
it is but a thin wrapper around the other class.
DisplayTransactionTest is adjusted so the dummy created DisplayDevices
have an appropriate compositionengine::Display.
Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 142831417
Change-Id: I8417682f4ead7b550a8973d4716c627e31b07b6e
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 557feaf..53525f3 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -20,6 +20,7 @@
#include <compositionengine/LayerFECompositionState.h>
#include <compositionengine/OutputLayer.h>
#include <compositionengine/impl/CompositionEngine.h>
+#include <compositionengine/impl/Display.h>
#include <compositionengine/impl/OutputLayerCompositionState.h>
#include <compositionengine/mock/DisplaySurface.h>
@@ -97,8 +98,8 @@
return new StartPropertySetThread(timestampPropertyValue);
}
- sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override {
- return new DisplayDevice(std::move(creationArgs));
+ sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) override {
+ return new DisplayDevice(creationArgs);
}
sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
@@ -277,13 +278,14 @@
auto resetDisplayState() { return mFlinger->resetDisplayState(); }
- auto setupNewDisplayDeviceInternal(const wp<IBinder>& displayToken,
- const std::optional<DisplayId>& displayId,
- const DisplayDeviceState& state,
- const sp<compositionengine::DisplaySurface>& dispSurface,
- const sp<IGraphicBufferProducer>& producer) {
- return mFlinger->setupNewDisplayDeviceInternal(displayToken, displayId, state, dispSurface,
- producer);
+ auto setupNewDisplayDeviceInternal(
+ const wp<IBinder>& displayToken,
+ std::shared_ptr<compositionengine::Display> compositionDisplay,
+ const DisplayDeviceState& state,
+ const sp<compositionengine::DisplaySurface>& dispSurface,
+ const sp<IGraphicBufferProducer>& producer) {
+ return mFlinger->setupNewDisplayDeviceInternal(displayToken, compositionDisplay, state,
+ dispSurface, producer);
}
auto handleTransactionLocked(uint32_t transactionFlags) {
@@ -360,6 +362,7 @@
auto& getHwComposer() const {
return static_cast<impl::HWComposer&>(mFlinger->getHwComposer());
}
+ auto& getCompositionEngine() const { return mFlinger->getCompositionEngine(); }
const auto& getCompositorTiming() const { return mFlinger->getBE().mCompositorTiming; }
@@ -544,10 +547,11 @@
class FakeDisplayDeviceInjector {
public:
FakeDisplayDeviceInjector(TestableSurfaceFlinger& flinger,
- std::optional<DisplayId> displayId,
+ std::shared_ptr<compositionengine::Display> compositionDisplay,
std::optional<DisplayConnectionType> connectionType,
bool isPrimary)
- : mFlinger(flinger), mCreationArgs(flinger.mFlinger.get(), mDisplayToken, displayId) {
+ : mFlinger(flinger),
+ mCreationArgs(flinger.mFlinger.get(), mDisplayToken, compositionDisplay) {
mCreationArgs.connectionType = connectionType;
mCreationArgs.isPrimary = isPrimary;
}
@@ -610,16 +614,17 @@
}
sp<DisplayDevice> inject() {
+ const auto displayId = mCreationArgs.compositionDisplay->getDisplayId();
+
DisplayDeviceState state;
if (const auto type = mCreationArgs.connectionType) {
- const auto id = mCreationArgs.displayId;
- LOG_ALWAYS_FATAL_IF(!id);
- state.physical = {*id, *type};
+ LOG_ALWAYS_FATAL_IF(!displayId);
+ state.physical = {*displayId, *type};
}
state.isSecure = mCreationArgs.isSecure;
- sp<DisplayDevice> device = new DisplayDevice(std::move(mCreationArgs));
+ sp<DisplayDevice> device = new DisplayDevice(mCreationArgs);
mFlinger.mutableDisplays().emplace(mDisplayToken, device);
mFlinger.mutableCurrentState().displays.add(mDisplayToken, state);
mFlinger.mutableDrawingState().displays.add(mDisplayToken, state);