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