1 /* 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 17 #pragma once 18 19 #include <cinttypes> 20 #include <functional> 21 #include <memory> 22 #include <string> 23 24 #include <cutils/compiler.h> 25 #include <utils/StrongPointer.h> 26 27 #include <scheduler/Fps.h> 28 29 namespace android { 30 31 typedef int32_t PixelFormat; 32 33 class BufferQueueLayer; 34 class BufferLayerConsumer; 35 class BufferStateLayer; 36 class ContainerLayer; 37 class DisplayDevice; 38 class EffectLayer; 39 class FrameTracer; 40 class GraphicBuffer; 41 class HWComposer; 42 class IGraphicBufferConsumer; 43 class IGraphicBufferProducer; 44 class Layer; 45 class StartPropertySetThread; 46 class SurfaceFlinger; 47 class SurfaceInterceptor; 48 class TimeStats; 49 50 struct DisplayDeviceCreationArgs; 51 struct LayerCreationArgs; 52 53 namespace compositionengine { 54 class CompositionEngine; 55 } // namespace compositionengine 56 57 namespace scheduler { 58 class VsyncConfiguration; 59 class VsyncController; 60 class RefreshRateConfigs; 61 } // namespace scheduler 62 63 namespace frametimeline { 64 class FrameTimeline; 65 } // namespace frametimeline 66 67 namespace surfaceflinger { 68 69 class NativeWindowSurface; 70 71 // The interface that SurfaceFlinger uses to create all of the implementations 72 // of each interface. 73 class Factory { 74 public: 75 virtual std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) = 0; 76 virtual std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration( 77 Fps currentRefreshRate) = 0; 78 virtual sp<SurfaceInterceptor> createSurfaceInterceptor() = 0; 79 80 virtual sp<StartPropertySetThread> createStartPropertySetThread( 81 bool timestampPropertyValue) = 0; 82 virtual sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&) = 0; 83 virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, 84 PixelFormat format, uint32_t layerCount, 85 uint64_t usage, std::string requestorName) = 0; 86 virtual void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, 87 sp<IGraphicBufferConsumer>* outConsumer, 88 bool consumerIsSurfaceFlinger) = 0; 89 virtual sp<IGraphicBufferProducer> createMonitoredProducer(const sp<IGraphicBufferProducer>&, 90 const sp<SurfaceFlinger>&, 91 const wp<Layer>&) = 0; 92 virtual sp<BufferLayerConsumer> createBufferLayerConsumer(const sp<IGraphicBufferConsumer>&, 93 renderengine::RenderEngine&, 94 uint32_t tex, Layer*) = 0; 95 96 virtual std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface( 97 const sp<IGraphicBufferProducer>&) = 0; 98 99 virtual std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() = 0; 100 101 virtual sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) = 0; 102 virtual sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) = 0; 103 virtual sp<EffectLayer> createEffectLayer(const LayerCreationArgs& args) = 0; 104 virtual sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) = 0; 105 virtual std::unique_ptr<FrameTracer> createFrameTracer() = 0; 106 virtual std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline( 107 std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) = 0; 108 109 protected: 110 ~Factory() = default; 111 }; 112 113 ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger(); 114 115 } // namespace surfaceflinger 116 } // namespace android 117