blob: 77679e32282b642da2a88d6d2357ab74e28e1c6c [file] [log] [blame]
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -07001/*
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
Lloyd Pique70d91362018-10-18 16:02:55 -070017#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique90c115d2018-09-18 21:39:42 -070018#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"
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -070028#include "SurfaceFlinger.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070029#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/Scheduler.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080037#include "TimeStats/TimeStats.h"
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -070038
39namespace android::surfaceflinger {
40
41sp<SurfaceFlinger> createSurfaceFlinger() {
Lloyd Pique90c115d2018-09-18 21:39:42 -070042 class Factory final : public surfaceflinger::Factory {
43 public:
44 Factory() = default;
45 ~Factory() = default;
46
47 std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework,
48 int64_t dispSyncPresentTimeOffset) override {
49 // Note: We create a local temporary with the real DispSync implementation
50 // type temporarily so we can initialize it with the configured values,
51 // before storing it for more generic use using the interface type.
52 auto primaryDispSync = std::make_unique<android::impl::DispSync>(name);
53 primaryDispSync->init(hasSyncFramework, dispSyncPresentTimeOffset);
54 return primaryDispSync;
55 }
56
57 std::unique_ptr<EventControlThread> createEventControlThread(
58 std::function<void(bool)> setVSyncEnabled) override {
59 return std::make_unique<android::impl::EventControlThread>(setVSyncEnabled);
60 }
61
62 std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) override {
Lloyd Pique441d5042018-10-18 16:49:51 -070063 return std::make_unique<android::impl::HWComposer>(
Lloyd Pique90c115d2018-09-18 21:39:42 -070064 std::make_unique<Hwc2::impl::Composer>(serviceName));
65 }
66
67 std::unique_ptr<MessageQueue> createMessageQueue() override {
68 return std::make_unique<android::impl::MessageQueue>();
69 }
70
71 std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)> callback) override {
72 return std::make_unique<Scheduler>(callback);
73 }
74
75 std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(
76 SurfaceFlinger* flinger) override {
77 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
78 }
79
80 sp<StartPropertySetThread> createStartPropertySetThread(
81 bool timestampPropertyValue) override {
82 return new StartPropertySetThread(timestampPropertyValue);
83 }
84
85 sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override {
86 return new DisplayDevice(std::move(creationArgs));
87 }
88
89 sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
90 uint32_t layerCount, uint64_t usage,
91 std::string requestorName) override {
92 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
93 }
94
95 void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
96 sp<IGraphicBufferConsumer>* outConsumer,
97 bool consumerIsSurfaceFlinger) override {
98 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
99 }
100
101 std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
102 const sp<IGraphicBufferProducer>& producer) override {
103 return surfaceflinger::impl::createNativeWindowSurface(producer);
104 }
105
Lloyd Pique70d91362018-10-18 16:02:55 -0700106 std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
107 return compositionengine::impl::createCompositionEngine();
108 }
109
Lloyd Pique90c115d2018-09-18 21:39:42 -0700110 sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) override {
111 return new ContainerLayer(args);
112 }
113
114 sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) override {
115 return new BufferQueueLayer(args);
116 }
117
118 sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) override {
119 return new BufferStateLayer(args);
120 }
121
122 sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) override {
123 return new ColorLayer(args);
124 }
Yiwei Zhang7e666a52018-11-15 13:33:42 -0800125
126 std::unique_ptr<TimeStats> createTimeStats() override {
127 return std::make_unique<TimeStats>();
128 }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700129 };
130 static Factory factory;
131
132 return new SurfaceFlinger(factory);
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -0700133}
134
135} // namespace android::surfaceflinger