SurfaceFlingerFactory.cpp 5.6 KB

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