• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace android {
28 
29 typedef int32_t PixelFormat;
30 
31 class BufferQueueLayer;
32 class BufferStateLayer;
33 class ColorLayer;
34 class ContainerLayer;
35 class DisplayDevice;
36 class DispSync;
37 class EventControlThread;
38 class GraphicBuffer;
39 class HWComposer;
40 class IGraphicBufferConsumer;
41 class IGraphicBufferProducer;
42 class MessageQueue;
43 class Scheduler;
44 class StartPropertySetThread;
45 class SurfaceFlinger;
46 class SurfaceInterceptor;
47 class TimeStats;
48 
49 struct DisplayDeviceCreationArgs;
50 struct LayerCreationArgs;
51 
52 namespace compositionengine {
53 class CompositionEngine;
54 } // namespace compositionengine
55 
56 namespace scheduler {
57 class PhaseOffsets;
58 } // namespace scheduler
59 namespace surfaceflinger {
60 
61 class NativeWindowSurface;
62 
63 // The interface that SurfaceFlinger uses to create all of the implementations
64 // of each interface.
65 class Factory {
66 public:
67     virtual std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
68                                                      int64_t dispSyncPresentTimeOffset) = 0;
69     virtual std::unique_ptr<EventControlThread> createEventControlThread(
70             std::function<void(bool)> setVSyncEnabled) = 0;
71     virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0;
72     virtual std::unique_ptr<MessageQueue> createMessageQueue() = 0;
73     virtual std::unique_ptr<scheduler::PhaseOffsets> createPhaseOffsets() = 0;
74     virtual std::unique_ptr<Scheduler> createScheduler(
75             std::function<void(bool)> callback,
76             const scheduler::RefreshRateConfigs& refreshRateConfig) = 0;
77     virtual std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(SurfaceFlinger*) = 0;
78 
79     virtual sp<StartPropertySetThread> createStartPropertySetThread(
80             bool timestampPropertyValue) = 0;
81     virtual sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&&) = 0;
82     virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height,
83                                                   PixelFormat format, uint32_t layerCount,
84                                                   uint64_t usage, std::string requestorName) = 0;
85     virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
86                                    sp<IGraphicBufferConsumer>* outConsumer,
87                                    bool consumerIsSurfaceFlinger) = 0;
88     virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
89             const sp<IGraphicBufferProducer>&) = 0;
90 
91     virtual std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() = 0;
92 
93     virtual sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) = 0;
94     virtual sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) = 0;
95     virtual sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) = 0;
96     virtual sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) = 0;
97 
98     virtual std::shared_ptr<TimeStats> createTimeStats() = 0;
99 
100 protected:
101     ~Factory() = default;
102 };
103 
104 ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger();
105 
106 } // namespace surfaceflinger
107 } // namespace android
108