1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cutils/compiler.h>
20 #include <utils/StrongPointer.h>
21 
22 #include <cinttypes>
23 #include <functional>
24 #include <memory>
25 #include <string>
26 
27 namespace android {
28 
29 typedef int32_t PixelFormat;
30 
31 class BufferQueueLayer;
32 class BufferStateLayer;
33 class BufferLayerConsumer;
34 class EffectLayer;
35 class ContainerLayer;
36 class DisplayDevice;
37 class DispSync;
38 class EventControlThread;
39 class GraphicBuffer;
40 class HWComposer;
41 class IGraphicBufferConsumer;
42 class IGraphicBufferProducer;
43 class ISchedulerCallback;
44 class Layer;
45 class MessageQueue;
46 class Scheduler;
47 class StartPropertySetThread;
48 class SurfaceFlinger;
49 class SurfaceInterceptor;
50 
51 struct DisplayDeviceCreationArgs;
52 struct LayerCreationArgs;
53 
54 namespace compositionengine {
55 class CompositionEngine;
56 } // namespace compositionengine
57 
58 namespace scheduler {
59 class PhaseConfiguration;
60 class RefreshRateConfigs;
61 } // namespace scheduler
62 
63 namespace surfaceflinger {
64 
65 class NativeWindowSurface;
66 
67 // The interface that SurfaceFlinger uses to create all of the implementations
68 // of each interface.
69 class Factory {
70 public:
71     using SetVSyncEnabled = std::function<void(bool)>;
72 
73     virtual std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework) = 0;
74     virtual std::unique_ptr<EventControlThread> createEventControlThread(SetVSyncEnabled) = 0;
75     virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0;
76     virtual std::unique_ptr<MessageQueue> createMessageQueue() = 0;
77     virtual std::unique_ptr<scheduler::PhaseConfiguration> createPhaseConfiguration(
78             const scheduler::RefreshRateConfigs&) = 0;
79     virtual std::unique_ptr<Scheduler> createScheduler(SetVSyncEnabled,
80                                                        const scheduler::RefreshRateConfigs&,
81                                                        ISchedulerCallback&) = 0;
82     virtual std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger*) = 0;
83 
84     virtual sp<StartPropertySetThread> createStartPropertySetThread(
85             bool timestampPropertyValue) = 0;
86     virtual sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&) = 0;
87     virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height,
88                                                   PixelFormat format, uint32_t layerCount,
89                                                   uint64_t usage, std::string requestorName) = 0;
90     virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
91                                    sp<IGraphicBufferConsumer>* outConsumer,
92                                    bool consumerIsSurfaceFlinger) = 0;
93     virtual sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>&,
94                                                                const sp<SurfaceFlinger>&,
95                                                                const wp<Layer>&) = 0;
96     virtual sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>&,
97                                                               renderengine::RenderEngine&,
98                                                               uint32_t tex, Layer*) = 0;
99 
100     virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
101             const sp<IGraphicBufferProducer>&) = 0;
102 
103     virtual std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() = 0;
104 
105     virtual sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) = 0;
106     virtual sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) = 0;
107     virtual sp<EffectLayer> createEffectLayer(const LayerCreationArgs& args) = 0;
108     virtual sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) = 0;
109 
110 protected:
111     ~Factory() = default;
112 };
113 
114 ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger();
115 
116 } // namespace surfaceflinger
117 } // namespace android
118