Lloyd Pique | ea0a5fb | 2018-09-12 15:04:56 -0700 | [diff] [blame] | 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 | |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 17 | #include <ui/GraphicBuffer.h> |
| 18 | |
| 19 | #include "BufferQueueLayer.h" |
| 20 | #include "BufferStateLayer.h" |
| 21 | #include "ColorLayer.h" |
| 22 | #include "ContainerLayer.h" |
| 23 | #include "DisplayDevice.h" |
| 24 | #include "Layer.h" |
| 25 | #include "NativeWindowSurface.h" |
| 26 | #include "StartPropertySetThread.h" |
Lloyd Pique | ea0a5fb | 2018-09-12 15:04:56 -0700 | [diff] [blame] | 27 | #include "SurfaceFlinger.h" |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 28 | #include "SurfaceFlingerFactory.h" |
| 29 | #include "SurfaceInterceptor.h" |
| 30 | |
| 31 | #include "DisplayHardware/ComposerHal.h" |
| 32 | #include "Scheduler/DispSync.h" |
| 33 | #include "Scheduler/EventControlThread.h" |
| 34 | #include "Scheduler/MessageQueue.h" |
| 35 | #include "Scheduler/Scheduler.h" |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame^] | 36 | #include "TimeStats/TimeStats.h" |
Lloyd Pique | ea0a5fb | 2018-09-12 15:04:56 -0700 | [diff] [blame] | 37 | |
| 38 | namespace android::surfaceflinger { |
| 39 | |
| 40 | sp<SurfaceFlinger> createSurfaceFlinger() { |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 41 | class Factory final : public surfaceflinger::Factory { |
| 42 | public: |
| 43 | Factory() = default; |
| 44 | ~Factory() = default; |
| 45 | |
| 46 | std::unique_ptr<DispSync> createDispSync(const char* name, bool hasSyncFramework, |
| 47 | int64_t dispSyncPresentTimeOffset) override { |
| 48 | // Note: We create a local temporary with the real DispSync implementation |
| 49 | // type temporarily so we can initialize it with the configured values, |
| 50 | // before storing it for more generic use using the interface type. |
| 51 | auto primaryDispSync = std::make_unique<android::impl::DispSync>(name); |
| 52 | primaryDispSync->init(hasSyncFramework, dispSyncPresentTimeOffset); |
| 53 | return primaryDispSync; |
| 54 | } |
| 55 | |
| 56 | std::unique_ptr<EventControlThread> createEventControlThread( |
| 57 | std::function<void(bool)> setVSyncEnabled) override { |
| 58 | return std::make_unique<android::impl::EventControlThread>(setVSyncEnabled); |
| 59 | } |
| 60 | |
| 61 | std::unique_ptr<HWComposer> createHWComposer(const std::string& serviceName) override { |
| 62 | return std::make_unique<HWComposer>( |
| 63 | std::make_unique<Hwc2::impl::Composer>(serviceName)); |
| 64 | } |
| 65 | |
| 66 | std::unique_ptr<MessageQueue> createMessageQueue() override { |
| 67 | return std::make_unique<android::impl::MessageQueue>(); |
| 68 | } |
| 69 | |
| 70 | std::unique_ptr<Scheduler> createScheduler(std::function<void(bool)> callback) override { |
| 71 | return std::make_unique<Scheduler>(callback); |
| 72 | } |
| 73 | |
| 74 | std::unique_ptr<SurfaceInterceptor> createSurfaceInterceptor( |
| 75 | SurfaceFlinger* flinger) override { |
| 76 | return std::make_unique<android::impl::SurfaceInterceptor>(flinger); |
| 77 | } |
| 78 | |
| 79 | sp<StartPropertySetThread> createStartPropertySetThread( |
| 80 | bool timestampPropertyValue) override { |
| 81 | return new StartPropertySetThread(timestampPropertyValue); |
| 82 | } |
| 83 | |
| 84 | sp<DisplayDevice> createDisplayDevice(DisplayDeviceCreationArgs&& creationArgs) override { |
| 85 | return new DisplayDevice(std::move(creationArgs)); |
| 86 | } |
| 87 | |
| 88 | sp<GraphicBuffer> createGraphicBuffer(uint32_t width, uint32_t height, PixelFormat format, |
| 89 | uint32_t layerCount, uint64_t usage, |
| 90 | std::string requestorName) override { |
| 91 | return new GraphicBuffer(width, height, format, layerCount, usage, requestorName); |
| 92 | } |
| 93 | |
| 94 | void createBufferQueue(sp<IGraphicBufferProducer>* outProducer, |
| 95 | sp<IGraphicBufferConsumer>* outConsumer, |
| 96 | bool consumerIsSurfaceFlinger) override { |
| 97 | BufferQueue::createBufferQueue(outProducer, outConsumer, consumerIsSurfaceFlinger); |
| 98 | } |
| 99 | |
| 100 | std::unique_ptr<surfaceflinger::NativeWindowSurface> createNativeWindowSurface( |
| 101 | const sp<IGraphicBufferProducer>& producer) override { |
| 102 | return surfaceflinger::impl::createNativeWindowSurface(producer); |
| 103 | } |
| 104 | |
| 105 | sp<ContainerLayer> createContainerLayer(const LayerCreationArgs& args) override { |
| 106 | return new ContainerLayer(args); |
| 107 | } |
| 108 | |
| 109 | sp<BufferQueueLayer> createBufferQueueLayer(const LayerCreationArgs& args) override { |
| 110 | return new BufferQueueLayer(args); |
| 111 | } |
| 112 | |
| 113 | sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) override { |
| 114 | return new BufferStateLayer(args); |
| 115 | } |
| 116 | |
| 117 | sp<ColorLayer> createColorLayer(const LayerCreationArgs& args) override { |
| 118 | return new ColorLayer(args); |
| 119 | } |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame^] | 120 | |
| 121 | std::unique_ptr<TimeStats> createTimeStats() override { |
| 122 | return std::make_unique<TimeStats>(); |
| 123 | } |
Lloyd Pique | 90c115d | 2018-09-18 21:39:42 -0700 | [diff] [blame] | 124 | }; |
| 125 | static Factory factory; |
| 126 | |
| 127 | return new SurfaceFlinger(factory); |
Lloyd Pique | ea0a5fb | 2018-09-12 15:04:56 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | } // namespace android::surfaceflinger |