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 <cinttypes>
20 #include <functional>
21 #include <memory>
22 #include <string>
23 
24 #include <cutils/compiler.h>
25 #include <utils/StrongPointer.h>
26 
27 #include <scheduler/Fps.h>
28 
29 namespace android {
30 
31 typedef int32_t PixelFormat;
32 
33 class BufferLayerConsumer;
34 class DisplayDevice;
35 class FrameTracer;
36 class GraphicBuffer;
37 class HWComposer;
38 class IGraphicBufferConsumer;
39 class IGraphicBufferProducer;
40 class Layer;
41 class LayerFE;
42 class SurfaceFlinger;
43 class TimeStats;
44 
45 struct DisplayDeviceCreationArgs;
46 
47 namespace compositionengine {
48 class CompositionEngine;
49 } // namespace compositionengine
50 
51 namespace scheduler {
52 class VsyncConfiguration;
53 class VsyncController;
54 } // namespace scheduler
55 
56 namespace frametimeline {
57 class FrameTimeline;
58 } // namespace frametimeline
59 
60 namespace surfaceflinger {
61 
62 struct LayerCreationArgs;
63 class NativeWindowSurface;
64 
65 // The interface that SurfaceFlinger uses to create all of the implementations
66 // of each interface.
67 class Factory {
68 public:
69     virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0;
70     virtual std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration(
71             Fps currentRefreshRate) = 0;
72 
73     virtual sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&) = 0;
74     virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height,
75                                                   PixelFormat format, uint32_t layerCount,
76                                                   uint64_t usage, std::string requestorName) = 0;
77     virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
78                                    sp<IGraphicBufferConsumer>* outConsumer,
79                                    bool consumerIsSurfaceFlinger) = 0;
80 
81     virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
82             const sp<IGraphicBufferProducer>&) = 0;
83 
84     virtual std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() = 0;
85 
86     virtual sp<Layer> createBufferStateLayer(const LayerCreationArgs& args) = 0;
87     virtual sp<Layer> createEffectLayer(const LayerCreationArgs& args) = 0;
88     virtual sp<LayerFE> createLayerFE(const std::string& layerName, const Layer* owner) = 0;
89     virtual std::unique_ptr<FrameTracer> createFrameTracer() = 0;
90     virtual std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline(
91             std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) = 0;
92 
93 protected:
94     ~Factory() = default;
95 };
96 
97 ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger();
98 
99 } // namespace surfaceflinger
100 } // namespace android
101