SF: Flush out SurfaceFlingerFactory
A factory is now passed to the SurfaceFlinger constructor, either one
created specifically to handle normal service initialization, or one
created for the unit tests. SurfaceFlinger uses the factory interface to
construct most of its instances.
This allows (almost) all the top level instances SurfaceFlinger creates
to be replaced as needed by interface-equivalents, such as GMocks in the
case of the unit test.
An older set of factory functions for two specific types is removed in
favor of the new factory interface.
Test: atest libsurfaceflinger_unittest
Test: Marlin boots and appears usable
Bug: None
Change-Id: I070c94effc54ddfe5366978613283525d7a7bf4a
diff --git a/services/surfaceflinger/SurfaceFlingerFactory.h b/services/surfaceflinger/SurfaceFlingerFactory.h
index 65eb797..496bbf0 100644
--- a/services/surfaceflinger/SurfaceFlingerFactory.h
+++ b/services/surfaceflinger/SurfaceFlingerFactory.h
@@ -16,15 +16,76 @@
#pragma once
+#include <cinttypes>
+#include <functional>
+#include <memory>
+#include <string>
+
#include <cutils/compiler.h>
#include <utils/StrongPointer.h>
namespace android {
+typedef int32_t PixelFormat;
+
+class BufferQueueLayer;
+class BufferStateLayer;
+class ColorLayer;
+class ContainerLayer;
+class DisplayDevice;
+class DispSync;
+class EventControlThread;
+class GraphicBuffer;
+class HWComposer;
+class IGraphicBufferConsumer;
+class IGraphicBufferProducer;
+class MessageQueue;
+class Scheduler;
+class StartPropertySetThread;
class SurfaceFlinger;
+class SurfaceInterceptor;
+
+struct DisplayDeviceCreationArgs;
+struct LayerCreationArgs;
namespace surfaceflinger {
+class NativeWindowSurface;
+
+// The interface that SurfaceFlinger uses to create all of the implementations
+// of each interface.
+class Factory {
+public:
+ virtual std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
+ int64_t dispSyncPresentTimeOffset) = 0;
+ virtual std::unique_ptr<EventControlThread> createEventControlThread(
+ std::function<void(bool)> setVSyncEnabled) = 0;
+ virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0;
+ virtual std::unique_ptr<MessageQueue> createMessageQueue() = 0;
+ virtual std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)> callback) = 0;
+ virtual std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger*) = 0;
+
+ virtual sp<StartPropertySetThread> createStartPropertySetThread(
+ bool timestampPropertyValue) = 0;
+ virtual sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&&) = 0;
+ virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height,
+ PixelFormat format, uint32_t layerCount,
+ uint64_t usage, std::string requestorName) = 0;
+ virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
+ sp<IGraphicBufferConsumer>* outConsumer,
+ bool consumerIsSurfaceFlinger) = 0;
+ virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
+ const sp<IGraphicBufferProducer>&) = 0;
+
+ virtual sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) = 0;
+ virtual sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) = 0;
+ virtual sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) = 0;
+ virtual sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) = 0;
+
+protected:
+ ~Factory() = default;
+};
+
ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger();
} // namespace surfaceflinger