1 /*
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 // TODO(b/129481165): remove the #pragma below and fix conversion issues
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wconversion"
20
21 #include <compositionengine/impl/CompositionEngine.h>
22 #include <cutils/properties.h>
23 #include <ui/GraphicBuffer.h>
24
25 #include "BufferLayerConsumer.h"
26 #include "BufferQueueLayer.h"
27 #include "BufferStateLayer.h"
28 #include "ContainerLayer.h"
29 #include "DisplayDevice.h"
30 #include "EffectLayer.h"
31 #include "Layer.h"
32 #include "MonitoredProducer.h"
33 #include "NativeWindowSurface.h"
34 #include "StartPropertySetThread.h"
35 #include "SurfaceFlingerDefaultFactory.h"
36 #include "SurfaceFlingerProperties.h"
37 #include "SurfaceInterceptor.h"
38
39 #include "DisplayHardware/ComposerHal.h"
40 #include "Scheduler/DispSync.h"
41 #include "Scheduler/EventControlThread.h"
42 #include "Scheduler/MessageQueue.h"
43 #include "Scheduler/PhaseOffsets.h"
44 #include "Scheduler/Scheduler.h"
45
46 namespace android::surfaceflinger {
47
48 DefaultFactory::~DefaultFactory() = default;
49
createDispSync(const char * name,bool hasSyncFramework)50 std::unique_ptr<DispSync> DefaultFactory::createDispSync(const char* name, bool hasSyncFramework) {
51 return std::make_unique<android::impl::DispSync>(name, hasSyncFramework);
52 }
53
createEventControlThread(SetVSyncEnabled setVSyncEnabled)54 std::unique_ptr<EventControlThread> DefaultFactory::createEventControlThread(
55 SetVSyncEnabled setVSyncEnabled) {
56 return std::make_unique<android::impl::EventControlThread>(std::move(setVSyncEnabled));
57 }
58
createHWComposer(const std::string & serviceName)59 std::unique_ptr<HWComposer> DefaultFactory::createHWComposer(const std::string& serviceName) {
60 return std::make_unique<android::impl::HWComposer>(serviceName);
61 }
62
createMessageQueue()63 std::unique_ptr<MessageQueue> DefaultFactory::createMessageQueue() {
64 return std::make_unique<android::impl::MessageQueue>();
65 }
66
createPhaseConfiguration(const scheduler::RefreshRateConfigs & refreshRateConfigs)67 std::unique_ptr<scheduler::PhaseConfiguration> DefaultFactory::createPhaseConfiguration(
68 const scheduler::RefreshRateConfigs& refreshRateConfigs) {
69 if (property_get_bool("debug.sf.use_phase_offsets_as_durations", false)) {
70 return std::make_unique<scheduler::impl::PhaseDurations>(refreshRateConfigs);
71 } else {
72 return std::make_unique<scheduler::impl::PhaseOffsets>(refreshRateConfigs);
73 }
74 }
75
createScheduler(SetVSyncEnabled setVSyncEnabled,const scheduler::RefreshRateConfigs & configs,ISchedulerCallback & schedulerCallback)76 std::unique_ptr<Scheduler> DefaultFactory::createScheduler(
77 SetVSyncEnabled setVSyncEnabled, const scheduler::RefreshRateConfigs& configs,
78 ISchedulerCallback& schedulerCallback) {
79 return std::make_unique<Scheduler>(std::move(setVSyncEnabled), configs, schedulerCallback,
80 property_get_bool("debug.sf.use_content_detection_v2", true),
81 sysprop::use_content_detection_for_refresh_rate(false));
82 }
83
createSurfaceInterceptor(SurfaceFlinger * flinger)84 std::unique_ptr<SurfaceInterceptor> DefaultFactory::createSurfaceInterceptor(
85 SurfaceFlinger* flinger) {
86 return std::make_unique<android::impl::SurfaceInterceptor>(flinger);
87 }
88
createStartPropertySetThread(bool timestampPropertyValue)89 sp<StartPropertySetThread> DefaultFactory::createStartPropertySetThread(
90 bool timestampPropertyValue) {
91 return new StartPropertySetThread(timestampPropertyValue);
92 }
93
createDisplayDevice(DisplayDeviceCreationArgs & creationArgs)94 sp<DisplayDevice> DefaultFactory::createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) {
95 return new DisplayDevice(creationArgs);
96 }
97
createGraphicBuffer(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,std::string requestorName)98 sp<GraphicBuffer> DefaultFactory::createGraphicBuffer(uint32_t width, uint32_t height,
99 PixelFormat format, uint32_t layerCount,
100 uint64_t usage, std::string requestorName) {
101 return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
102 }
103
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,bool consumerIsSurfaceFlinger)104 void DefaultFactory::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
105 sp<IGraphicBufferConsumer>* outConsumer,
106 bool consumerIsSurfaceFlinger) {
107 BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
108 }
109
createMonitoredProducer(const sp<IGraphicBufferProducer> & producer,const sp<SurfaceFlinger> & flinger,const wp<Layer> & layer)110 sp<IGraphicBufferProducer> DefaultFactory::createMonitoredProducer(
111 const sp<IGraphicBufferProducer>& producer, const sp<SurfaceFlinger>& flinger,
112 const wp<Layer>& layer) {
113 return new MonitoredProducer(producer, flinger, layer);
114 }
115
createBufferLayerConsumer(const sp<IGraphicBufferConsumer> & consumer,renderengine::RenderEngine & renderEngine,uint32_t textureName,Layer * layer)116 sp<BufferLayerConsumer> DefaultFactory::createBufferLayerConsumer(
117 const sp<IGraphicBufferConsumer>& consumer, renderengine::RenderEngine& renderEngine,
118 uint32_t textureName, Layer* layer) {
119 return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
120 }
121
createNativeWindowSurface(const sp<IGraphicBufferProducer> & producer)122 std::unique_ptr<surfaceflinger::NativeWindowSurface> DefaultFactory::createNativeWindowSurface(
123 const sp<IGraphicBufferProducer>& producer) {
124 return surfaceflinger::impl::createNativeWindowSurface(producer);
125 }
126
createCompositionEngine()127 std::unique_ptr<compositionengine::CompositionEngine> DefaultFactory::createCompositionEngine() {
128 return compositionengine::impl::createCompositionEngine();
129 }
130
createContainerLayer(const LayerCreationArgs & args)131 sp<ContainerLayer> DefaultFactory::createContainerLayer(const LayerCreationArgs& args) {
132 return new ContainerLayer(args);
133 }
134
createBufferQueueLayer(const LayerCreationArgs & args)135 sp<BufferQueueLayer> DefaultFactory::createBufferQueueLayer(const LayerCreationArgs& args) {
136 return new BufferQueueLayer(args);
137 }
138
createBufferStateLayer(const LayerCreationArgs & args)139 sp<BufferStateLayer> DefaultFactory::createBufferStateLayer(const LayerCreationArgs& args) {
140 return new BufferStateLayer(args);
141 }
142
createEffectLayer(const LayerCreationArgs & args)143 sp<EffectLayer> DefaultFactory::createEffectLayer(const LayerCreationArgs& args) {
144 return new EffectLayer(args);
145 }
146
147 } // namespace android::surfaceflinger
148
149 // TODO(b/129481165): remove the #pragma below and fix conversion issues
150 #pragma clang diagnostic pop // ignored "-Wconversion"
151