blob: 375730b26f9b592c4796f49b35e39caf89e150a8 [file] [log] [blame]
Lloyd Pique24f3bfe2019-10-02 19:29:10 -07001/*
2 * Copyright 2019 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>
Ady Abraham9e16a482019-12-03 17:19:41 -080018#include <cutils/properties.h>
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070019#include <ui/GraphicBuffer.h>
20
Lloyd Piquee300b312019-10-03 13:03:45 -070021#include "BufferLayerConsumer.h"
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070022#include "BufferQueueLayer.h"
23#include "BufferStateLayer.h"
24#include "ColorLayer.h"
25#include "ContainerLayer.h"
26#include "DisplayDevice.h"
27#include "Layer.h"
Lloyd Piquee300b312019-10-03 13:03:45 -070028#include "MonitoredProducer.h"
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070029#include "NativeWindowSurface.h"
30#include "StartPropertySetThread.h"
31#include "SurfaceFlingerDefaultFactory.h"
32#include "SurfaceInterceptor.h"
33
34#include "DisplayHardware/ComposerHal.h"
35#include "Scheduler/DispSync.h"
36#include "Scheduler/EventControlThread.h"
37#include "Scheduler/MessageQueue.h"
38#include "Scheduler/PhaseOffsets.h"
39#include "Scheduler/Scheduler.h"
40
41namespace android::surfaceflinger {
42
43DefaultFactory::~DefaultFactory() = default;
44
45std::unique_ptr<DispSync> DefaultFactory::createDispSync(const char* name, bool hasSyncFramework) {
46 return std::make_unique<android::impl::DispSync>(name, hasSyncFramework);
47}
48
49std::unique_ptr<EventControlThread> DefaultFactory::createEventControlThread(
50 SetVSyncEnabled setVSyncEnabled) {
51 return std::make_unique<android::impl::EventControlThread>(std::move(setVSyncEnabled));
52}
53
54std::unique_ptr<HWComposer> DefaultFactory::createHWComposer(const std::string& serviceName) {
55 return std::make_unique<android::impl::HWComposer>(
56 std::make_unique<Hwc2::impl::Composer>(serviceName));
57}
58
59std::unique_ptr<MessageQueue> DefaultFactory::createMessageQueue() {
60 return std::make_unique<android::impl::MessageQueue>();
61}
62
Ady Abraham9e16a482019-12-03 17:19:41 -080063std::unique_ptr<scheduler::PhaseConfiguration> DefaultFactory::createPhaseConfiguration(
64 const scheduler::RefreshRateConfigs& refreshRateConfigs) {
65 if (property_get_bool("debug.sf.use_phase_offsets_as_durations", false)) {
66 return std::make_unique<scheduler::impl::PhaseDurations>(refreshRateConfigs);
67 } else {
68 return std::make_unique<scheduler::impl::PhaseOffsets>(refreshRateConfigs);
69 }
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070070}
71
72std::unique_ptr<Scheduler> DefaultFactory::createScheduler(
Ady Abraham3a77a7b2019-12-02 18:46:59 -080073 SetVSyncEnabled setVSyncEnabled, const scheduler::RefreshRateConfigs& configs,
74 ISchedulerCallback& schedulerCallback) {
75 return std::make_unique<Scheduler>(std::move(setVSyncEnabled), configs, schedulerCallback);
Lloyd Pique24f3bfe2019-10-02 19:29:10 -070076}
77
78std::unique_ptr<SurfaceInterceptor> DefaultFactory::createSurfaceInterceptor(
79 SurfaceFlinger* flinger) {
80 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
81}
82
83sp<StartPropertySetThread> DefaultFactory::createStartPropertySetThread(
84 bool timestampPropertyValue) {
85 return new StartPropertySetThread(timestampPropertyValue);
86}
87
88sp<DisplayDevice> DefaultFactory::createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) {
89 return new DisplayDevice(std::move(creationArgs));
90}
91
92sp<GraphicBuffer> DefaultFactory::createGraphicBuffer(uint32_t width, uint32_t height,
93 PixelFormat format, uint32_t layerCount,
94 uint64_t usage, std::string requestorName) {
95 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
96}
97
98void DefaultFactory::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
99 sp<IGraphicBufferConsumer>* outConsumer,
100 bool consumerIsSurfaceFlinger) {
101 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
102}
103
Lloyd Piquee300b312019-10-03 13:03:45 -0700104sp<IGraphicBufferProducer> DefaultFactory::createMonitoredProducer(
105 const sp<IGraphicBufferProducer>& producer, const sp<SurfaceFlinger>& flinger,
106 const wp<Layer>& layer) {
107 return new MonitoredProducer(producer, flinger, layer);
108}
109
110sp<BufferLayerConsumer> DefaultFactory::createBufferLayerConsumer(
111 const sp<IGraphicBufferConsumer>& consumer, renderengine::RenderEngine& renderEngine,
112 uint32_t textureName, Layer* layer) {
113 return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
114}
115
Lloyd Pique24f3bfe2019-10-02 19:29:10 -0700116std::unique_ptr<surfaceflinger::NativeWindowSurface> DefaultFactory::createNativeWindowSurface(
117 const sp<IGraphicBufferProducer>& producer) {
118 return surfaceflinger::impl::createNativeWindowSurface(producer);
119}
120
121std::unique_ptr<compositionengine::CompositionEngine> DefaultFactory::createCompositionEngine() {
122 return compositionengine::impl::createCompositionEngine();
123}
124
125sp<ContainerLayer> DefaultFactory::createContainerLayer(const LayerCreationArgs& args) {
126 return new ContainerLayer(args);
127}
128
129sp<BufferQueueLayer> DefaultFactory::createBufferQueueLayer(const LayerCreationArgs& args) {
130 return new BufferQueueLayer(args);
131}
132
133sp<BufferStateLayer> DefaultFactory::createBufferStateLayer(const LayerCreationArgs& args) {
134 return new BufferStateLayer(args);
135}
136
137sp<ColorLayer> DefaultFactory::createColorLayer(const LayerCreationArgs& args) {
138 return new ColorLayer(args);
139}
140
141} // namespace android::surfaceflinger