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