blob: 041ff8d722384dd7736500141fe257eb794316ae [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"
Ana Krulec757f63a2019-01-25 10:46:18 -080036#include "Scheduler/PhaseOffsets.h"
Lloyd Pique90c115d2018-09-18 21:39:42 -070037#include "Scheduler/Scheduler.h"
Yiwei Zhang7e666a52018-11-15 13:33:42 -080038#include "TimeStats/TimeStats.h"
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -070039
40namespace android::surfaceflinger {
41
42sp<SurfaceFlinger> createSurfaceFlinger() {
Lloyd Pique90c115d2018-09-18 21:39:42 -070043 class Factory final : public surfaceflinger::Factory {
44 public:
45 Factory() = default;
46 ~Factory() = default;
47
Dominik Laskowski98041832019-08-01 18:35:59 -070048 std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework) override {
49 return std::make_unique<android::impl::DispSync>(name, hasSyncFramework);
Lloyd Pique90c115d2018-09-18 21:39:42 -070050 }
51
52 std::unique_ptr<EventControlThread> createEventControlThread(
Dominik Laskowski98041832019-08-01 18:35:59 -070053 SetVSyncEnabled setVSyncEnabled) override {
54 return std::make_unique<android::impl::EventControlThread>(std::move(setVSyncEnabled));
Lloyd Pique90c115d2018-09-18 21:39:42 -070055 }
56
57 std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) override {
Lloyd Pique441d5042018-10-18 16:49:51 -070058 return std::make_unique<android::impl::HWComposer>(
Lloyd Pique90c115d2018-09-18 21:39:42 -070059 std::make_unique<Hwc2::impl::Composer>(serviceName));
60 }
61
62 std::unique_ptr<MessageQueue> createMessageQueue() override {
63 return std::make_unique<android::impl::MessageQueue>();
64 }
65
Ana Krulec757f63a2019-01-25 10:46:18 -080066 std::unique_ptr<scheduler::PhaseOffsets> createPhaseOffsets() override {
67 return std::make_unique<scheduler::impl::PhaseOffsets>();
68 }
69
Ady Abraham09bd3922019-04-08 10:44:56 -070070 std::unique_ptr<Scheduler> createScheduler(
Dominik Laskowski98041832019-08-01 18:35:59 -070071 SetVSyncEnabled setVSyncEnabled,
72 const scheduler::RefreshRateConfigs& configs) override {
73 return std::make_unique<Scheduler>(std::move(setVSyncEnabled), configs);
Lloyd Pique90c115d2018-09-18 21:39:42 -070074 }
75
76 std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor(
77 SurfaceFlinger* flinger) override {
78 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
79 }
80
81 sp<StartPropertySetThread> createStartPropertySetThread(
82 bool timestampPropertyValue) override {
83 return new StartPropertySetThread(timestampPropertyValue);
84 }
85
86 sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override {
87 return new DisplayDevice(std::move(creationArgs));
88 }
89
90 sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format,
91 uint32_t layerCount, uint64_t usage,
92 std::string requestorName) override {
93 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
94 }
95
96 void createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
97 sp<IGraphicBufferConsumer>* outConsumer,
98 bool consumerIsSurfaceFlinger) override {
99 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
100 }
101
102 std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface(
103 const sp<IGraphicBufferProducer>& producer) override {
104 return surfaceflinger::impl::createNativeWindowSurface(producer);
105 }
106
Lloyd Pique70d91362018-10-18 16:02:55 -0700107 std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override {
108 return compositionengine::impl::createCompositionEngine();
109 }
110
Lloyd Pique90c115d2018-09-18 21:39:42 -0700111 sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) override {
112 return new ContainerLayer(args);
113 }
114
115 sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) override {
116 return new BufferQueueLayer(args);
117 }
118
119 sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) override {
120 return new BufferStateLayer(args);
121 }
122
123 sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) override {
124 return new ColorLayer(args);
125 }
Yiwei Zhang7e666a52018-11-15 13:33:42 -0800126
Alec Mourifb571ea2019-01-24 18:42:10 -0800127 std::shared_ptr<TimeStats> createTimeStats() override {
128 return std::make_shared<android::impl::TimeStats>();
Yiwei Zhang7e666a52018-11-15 13:33:42 -0800129 }
Lloyd Pique90c115d2018-09-18 21:39:42 -0700130 };
131 static Factory factory;
132
133 return new SurfaceFlinger(factory);
Lloyd Piqueea0a5fb2018-09-12 15:04:56 -0700134}
135
136} // namespace android::surfaceflinger