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