• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "FrameTracer/FrameTracer.h"
32 #include "Layer.h"
33 #include "MonitoredProducer.h"
34 #include "NativeWindowSurface.h"
35 #include "StartPropertySetThread.h"
36 #include "SurfaceFlingerDefaultFactory.h"
37 #include "SurfaceFlingerProperties.h"
38 #include "SurfaceInterceptor.h"
39 
40 #include "DisplayHardware/ComposerHal.h"
41 #include "Scheduler/Scheduler.h"
42 #include "Scheduler/VsyncConfiguration.h"
43 #include "Scheduler/VsyncController.h"
44 
45 namespace android::surfaceflinger {
46 
47 DefaultFactory::~DefaultFactory() = default;
48 
createHWComposer(const std::string & serviceName)49 std::unique_ptr<HWComposer> DefaultFactory::createHWComposer(const std::string& serviceName) {
50     return std::make_unique<android::impl::HWComposer>(serviceName);
51 }
52 
createVsyncConfiguration(Fps currentRefreshRate)53 std::unique_ptr<scheduler::VsyncConfiguration> DefaultFactory::createVsyncConfiguration(
54         Fps currentRefreshRate) {
55     if (property_get_bool("debug.sf.use_phase_offsets_as_durations", false)) {
56         return std::make_unique<scheduler::impl::WorkDuration>(currentRefreshRate);
57     } else {
58         return std::make_unique<scheduler::impl::PhaseOffsets>(currentRefreshRate);
59     }
60 }
61 
createSurfaceInterceptor()62 sp<SurfaceInterceptor> DefaultFactory::createSurfaceInterceptor() {
63     return new android::impl::SurfaceInterceptor();
64 }
65 
createStartPropertySetThread(bool timestampPropertyValue)66 sp<StartPropertySetThread> DefaultFactory::createStartPropertySetThread(
67         bool timestampPropertyValue) {
68     return new StartPropertySetThread(timestampPropertyValue);
69 }
70 
createDisplayDevice(DisplayDeviceCreationArgs & creationArgs)71 sp<DisplayDevice> DefaultFactory::createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) {
72     return new DisplayDevice(creationArgs);
73 }
74 
createGraphicBuffer(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,std::string requestorName)75 sp<GraphicBuffer> DefaultFactory::createGraphicBuffer(uint32_t width, uint32_t height,
76                                                       PixelFormat format, uint32_t layerCount,
77                                                       uint64_t usage, std::string requestorName) {
78     return new GraphicBuffer(width, height, format, layerCount, usage, requestorName);
79 }
80 
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,bool consumerIsSurfaceFlinger)81 void DefaultFactory::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
82                                        sp<IGraphicBufferConsumer>* outConsumer,
83                                        bool consumerIsSurfaceFlinger) {
84     BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
85 }
86 
createMonitoredProducer(const sp<IGraphicBufferProducer> & producer,const sp<SurfaceFlinger> & flinger,const wp<Layer> & layer)87 sp<IGraphicBufferProducer> DefaultFactory::createMonitoredProducer(
88         const sp<IGraphicBufferProducer>& producer, const sp<SurfaceFlinger>& flinger,
89         const wp<Layer>& layer) {
90     return new MonitoredProducer(producer, flinger, layer);
91 }
92 
createBufferLayerConsumer(const sp<IGraphicBufferConsumer> & consumer,renderengine::RenderEngine & renderEngine,uint32_t textureName,Layer * layer)93 sp<BufferLayerConsumer> DefaultFactory::createBufferLayerConsumer(
94         const sp<IGraphicBufferConsumer>& consumer, renderengine::RenderEngine& renderEngine,
95         uint32_t textureName, Layer* layer) {
96     return new BufferLayerConsumer(consumer, renderEngine, textureName, layer);
97 }
98 
createNativeWindowSurface(const sp<IGraphicBufferProducer> & producer)99 std::unique_ptr<surfaceflinger::NativeWindowSurface> DefaultFactory::createNativeWindowSurface(
100         const sp<IGraphicBufferProducer>& producer) {
101     return surfaceflinger::impl::createNativeWindowSurface(producer);
102 }
103 
createCompositionEngine()104 std::unique_ptr<compositionengine::CompositionEngine> DefaultFactory::createCompositionEngine() {
105     return compositionengine::impl::createCompositionEngine();
106 }
107 
createContainerLayer(const LayerCreationArgs & args)108 sp<ContainerLayer> DefaultFactory::createContainerLayer(const LayerCreationArgs& args) {
109     return new ContainerLayer(args);
110 }
111 
createBufferQueueLayer(const LayerCreationArgs & args)112 sp<BufferQueueLayer> DefaultFactory::createBufferQueueLayer(const LayerCreationArgs& args) {
113     return new BufferQueueLayer(args);
114 }
115 
createBufferStateLayer(const LayerCreationArgs & args)116 sp<BufferStateLayer> DefaultFactory::createBufferStateLayer(const LayerCreationArgs& args) {
117     return new BufferStateLayer(args);
118 }
119 
createEffectLayer(const LayerCreationArgs & args)120 sp<EffectLayer> DefaultFactory::createEffectLayer(const LayerCreationArgs& args) {
121     return new EffectLayer(args);
122 }
123 
createFrameTracer()124 std::unique_ptr<FrameTracer> DefaultFactory::createFrameTracer() {
125     return std::make_unique<FrameTracer>();
126 }
127 
createFrameTimeline(std::shared_ptr<TimeStats> timeStats,pid_t surfaceFlingerPid)128 std::unique_ptr<frametimeline::FrameTimeline> DefaultFactory::createFrameTimeline(
129         std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) {
130     return std::make_unique<frametimeline::impl::FrameTimeline>(timeStats, surfaceFlingerPid);
131 }
132 
133 } // namespace android::surfaceflinger
134 
135 // TODO(b/129481165): remove the #pragma below and fix conversion issues
136 #pragma clang diagnostic pop // ignored "-Wconversion"
137