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 "DisplayDevice.h"
26 #include "FrameTracer/FrameTracer.h"
27 #include "Layer.h"
28 #include "NativeWindowSurface.h"
29 #include "SurfaceFlingerDefaultFactory.h"
30 #include "SurfaceFlingerProperties.h"
31 
32 #include "DisplayHardware/ComposerHal.h"
33 #include "FrameTimeline/FrameTimeline.h"
34 #include "Scheduler/Scheduler.h"
35 #include "Scheduler/VsyncConfiguration.h"
36 #include "Scheduler/VsyncController.h"
37 
38 namespace android::surfaceflinger {
39 
40 DefaultFactory::~DefaultFactory() = default;
41 
createHWComposer(const std::string & serviceName)42 std::unique_ptr<HWComposer> DefaultFactory::createHWComposer(const std::string& serviceName) {
43     return std::make_unique<android::impl::HWComposer>(serviceName);
44 }
45 
createVsyncConfiguration(Fps currentRefreshRate)46 std::unique_ptr<scheduler::VsyncConfiguration> DefaultFactory::createVsyncConfiguration(
47         Fps currentRefreshRate) {
48     if (property_get_bool("debug.sf.use_phase_offsets_as_durations", false)) {
49         return std::make_unique<scheduler::impl::WorkDuration>(currentRefreshRate);
50     } else {
51         return std::make_unique<scheduler::impl::PhaseOffsets>(currentRefreshRate);
52     }
53 }
54 
createDisplayDevice(DisplayDeviceCreationArgs & creationArgs)55 sp<DisplayDevice> DefaultFactory::createDisplayDevice(DisplayDeviceCreationArgs& creationArgs) {
56     return sp<DisplayDevice>::make(creationArgs);
57 }
58 
createGraphicBuffer(uint32_t width,uint32_t height,PixelFormat format,uint32_t layerCount,uint64_t usage,std::string requestorName)59 sp<GraphicBuffer> DefaultFactory::createGraphicBuffer(uint32_t width, uint32_t height,
60                                                       PixelFormat format, uint32_t layerCount,
61                                                       uint64_t usage, std::string requestorName) {
62     return sp<GraphicBuffer>::make(width, height, format, layerCount, usage, requestorName);
63 }
64 
createBufferQueue(sp<IGraphicBufferProducer> * outProducer,sp<IGraphicBufferConsumer> * outConsumer,bool consumerIsSurfaceFlinger)65 void DefaultFactory::createBufferQueue(sp<IGraphicBufferProducer>* outProducer,
66                                        sp<IGraphicBufferConsumer>* outConsumer,
67                                        bool consumerIsSurfaceFlinger) {
68     BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger);
69 }
70 
createNativeWindowSurface(const sp<IGraphicBufferProducer> & producer)71 std::unique_ptr<surfaceflinger::NativeWindowSurface> DefaultFactory::createNativeWindowSurface(
72         const sp<IGraphicBufferProducer>& producer) {
73     return surfaceflinger::impl::createNativeWindowSurface(producer);
74 }
75 
createCompositionEngine()76 std::unique_ptr<compositionengine::CompositionEngine> DefaultFactory::createCompositionEngine() {
77     return compositionengine::impl::createCompositionEngine();
78 }
79 
createBufferStateLayer(const LayerCreationArgs & args)80 sp<Layer> DefaultFactory::createBufferStateLayer(const LayerCreationArgs& args) {
81     return sp<Layer>::make(args);
82 }
83 
createEffectLayer(const LayerCreationArgs & args)84 sp<Layer> DefaultFactory::createEffectLayer(const LayerCreationArgs& args) {
85     return sp<Layer>::make(args);
86 }
87 
createLayerFE(const std::string & layerName,const Layer *)88 sp<LayerFE> DefaultFactory::createLayerFE(const std::string& layerName, const Layer* /* owner */) {
89     return sp<LayerFE>::make(layerName);
90 }
91 
createFrameTracer()92 std::unique_ptr<FrameTracer> DefaultFactory::createFrameTracer() {
93     return std::make_unique<FrameTracer>();
94 }
95 
createFrameTimeline(std::shared_ptr<TimeStats> timeStats,pid_t surfaceFlingerPid)96 std::unique_ptr<frametimeline::FrameTimeline> DefaultFactory::createFrameTimeline(
97         std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) {
98     return std::make_unique<frametimeline::impl::FrameTimeline>(timeStats, surfaceFlingerPid);
99 }
100 
101 } // namespace android::surfaceflinger
102 
103 // TODO(b/129481165): remove the #pragma below and fix conversion issues
104 #pragma clang diagnostic pop // ignored "-Wconversion"
105