• 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 #include <compositionengine/impl/CompositionEngine.h>
18 #include <ui/GraphicBuffer.h>
19 
20 #include "BufferQueueLayer.h"
21 #include "BufferStateLayer.h"
22 #include "ColorLayer.h"
23 #include "ContainerLayer.h"
24 #include "DisplayDevice.h"
25 #include "Layer.h"
26 #include "NativeWindowSurface.h"
27 #include "StartPropertySetThread.h"
28 #include "SurfaceFlinger.h"
29 #include "SurfaceFlingerFactory.h"
30 #include "SurfaceInterceptor.h"
31 
32 #include "DisplayHardware/ComposerHal.h"
33 #include "Scheduler/DispSync.h"
34 #include "Scheduler/EventControlThread.h"
35 #include "Scheduler/MessageQueue.h"
36 #include "Scheduler/PhaseOffsets.h"
37 #include "Scheduler/Scheduler.h"
38 #include "TimeStats/TimeStats.h"
39 
40 namespace android::surfaceflinger {
41 
createSurfaceFlinger()42 sp<SurfaceFlinger> createSurfaceFlinger() {
43     class Factory final : public surfaceflinger::Factory {
44     public:
45         Factory() = default;
46         ~Factory() = default;
47 
48         std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
49                                                  int64_t dispSyncPresentTimeOffset) override {
50             // Note: We create a local temporary with the real DispSync implementation
51             // type temporarily so we can initialize it with the configured values,
52             // before storing it for more generic use using the interface type.
53             auto primaryDispSync = std::make_unique<android::impl::DispSync>(name);
54             primaryDispSync->init(hasSyncFramework, dispSyncPresentTimeOffset);
55             return primaryDispSync;
56         }
57 
58         std::unique_ptr<EventControlThread> createEventControlThread(
59                 std::function<void(bool)> setVSyncEnabled) override {
60             return std::make_unique<android::impl::EventControlThread>(setVSyncEnabled);
61         }
62 
63         std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) override {
64             return std::make_unique<android::impl::HWComposer>(
65                     std::make_unique<Hwc2::impl::Composer>(serviceName));
66         }
67 
68         std::unique_ptr<MessageQueue> createMessageQueue() override {
69             return std::make_unique<android::impl::MessageQueue>();
70         }
71 
72         std::unique_ptr<scheduler::PhaseOffsets> createPhaseOffsets() override {
73             return std::make_unique<scheduler::impl::PhaseOffsets>();
74         }
75 
76         std::unique_ptr<Scheduler> createScheduler(
77                 std::function<void(bool)> callback,
78                 const scheduler::RefreshRateConfigs& refreshRateConfig) override {
79             return std::make_unique<Scheduler>(callback, refreshRateConfig);
80         }
81 
82         std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(
83                 SurfaceFlinger* flinger) override {
84             return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
85         }
86 
87         sp<StartPropertySetThread> createStartPropertySetThread(
88                 bool timestampPropertyValue) override {
89             return new StartPropertySetThread(timestampPropertyValue);
90         }
91 
92         sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override {
93             return new DisplayDevice(std::move(creationArgs));
94         }
95 
96         sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
97                                               uint32_t layerCount, uint64_t usage,
98                                               std::string requestorName) override {
99             return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
100         }
101 
102         void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
103                                sp<IGraphicBufferConsumer>* outConsumer,
104                                bool consumerIsSurfaceFlinger) override {
105             BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
106         }
107 
108         std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
109                 const sp<IGraphicBufferProducer>& producer) override {
110             return surfaceflinger::impl::createNativeWindowSurface(producer);
111         }
112 
113         std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
114             return compositionengine::impl::createCompositionEngine();
115         }
116 
117         sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) override {
118             return new ContainerLayer(args);
119         }
120 
121         sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) override {
122             return new BufferQueueLayer(args);
123         }
124 
125         sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) override {
126             return new BufferStateLayer(args);
127         }
128 
129         sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) override {
130             return new ColorLayer(args);
131         }
132 
133         std::shared_ptr<TimeStats> createTimeStats() override {
134             return std::make_shared<android::impl::TimeStats>();
135         }
136     };
137     static Factory factory;
138 
139     return new SurfaceFlinger(factory);
140 }
141 
142 } // namespace android::surfaceflinger
143