Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -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 | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 17 | #include <compositionengine/CompositionRefreshArgs.h> |
| 18 | #include <compositionengine/LayerFE.h> |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 19 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 20 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 23 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 24 | #include <renderengine/RenderEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 25 | #include <utils/Trace.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 26 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 27 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 28 | #pragma clang diagnostic push |
| 29 | #pragma clang diagnostic ignored "-Wconversion" |
| 30 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 31 | #include "DisplayHardware/HWComposer.h" |
| 32 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 33 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 34 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 35 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 36 | namespace android::compositionengine { |
| 37 | |
| 38 | CompositionEngine::~CompositionEngine() = default; |
| 39 | |
| 40 | namespace impl { |
| 41 | |
| 42 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() { |
| 43 | return std::make_unique<CompositionEngine>(); |
| 44 | } |
| 45 | |
| 46 | CompositionEngine::CompositionEngine() = default; |
| 47 | CompositionEngine::~CompositionEngine() = default; |
| 48 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 49 | std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay( |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 50 | const DisplayCreationArgs& args) { |
| 51 | return compositionengine::impl::createDisplay(*this, args); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 54 | std::unique_ptr<compositionengine::LayerFECompositionState> |
| 55 | CompositionEngine::createLayerFECompositionState() { |
| 56 | return std::make_unique<compositionengine::LayerFECompositionState>(); |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 59 | HWComposer& CompositionEngine::getHwComposer() const { |
| 60 | return *mHwComposer.get(); |
| 61 | } |
| 62 | |
| 63 | void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) { |
| 64 | mHwComposer = std::move(hwComposer); |
| 65 | } |
| 66 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 67 | renderengine::RenderEngine& CompositionEngine::getRenderEngine() const { |
| 68 | return *mRenderEngine.get(); |
| 69 | } |
| 70 | |
| 71 | void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
| 72 | mRenderEngine = std::move(renderEngine); |
| 73 | } |
| 74 | |
Alec Mouri | e4034bb | 2019-11-19 12:45:54 -0800 | [diff] [blame] | 75 | TimeStats& CompositionEngine::getTimeStats() const { |
| 76 | return *mTimeStats.get(); |
| 77 | } |
| 78 | |
| 79 | void CompositionEngine::setTimeStats(const std::shared_ptr<TimeStats>& timeStats) { |
| 80 | mTimeStats = timeStats; |
| 81 | } |
| 82 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 83 | bool CompositionEngine::needsAnotherUpdate() const { |
| 84 | return mNeedsAnotherUpdate; |
| 85 | } |
| 86 | |
| 87 | nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const { |
| 88 | return mRefreshStartTime; |
| 89 | } |
| 90 | |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 91 | void CompositionEngine::present(CompositionRefreshArgs& args) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 92 | ATRACE_CALL(); |
| 93 | ALOGV(__FUNCTION__); |
| 94 | |
| 95 | preComposition(args); |
| 96 | |
| 97 | { |
| 98 | // latchedLayers is used to track the set of front-end layer state that |
| 99 | // has been latched across all outputs for the prepare step, and is not |
| 100 | // needed for anything else. |
| 101 | LayerFESet latchedLayers; |
| 102 | |
| 103 | for (const auto& output : args.outputs) { |
| 104 | output->prepare(args, latchedLayers); |
| 105 | } |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 108 | for (const auto& output : args.outputs) { |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 109 | output->present(args); |
| 110 | } |
| 111 | } |
| 112 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 113 | void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) { |
| 114 | std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*> |
| 115 | uniqueVisibleLayers; |
| 116 | |
| 117 | for (const auto& output : args.outputs) { |
Lloyd Pique | 01c77c1 | 2019-04-17 12:48:32 -0700 | [diff] [blame] | 118 | for (auto* layer : output->getOutputLayersOrderedByZ()) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 119 | if (layer->isHardwareCursor()) { |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 120 | layer->writeCursorPositionToHWC(); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 126 | void CompositionEngine::preComposition(CompositionRefreshArgs& args) { |
| 127 | ATRACE_CALL(); |
| 128 | ALOGV(__FUNCTION__); |
| 129 | |
| 130 | bool needsAnotherUpdate = false; |
| 131 | |
| 132 | mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 133 | |
| 134 | for (auto& layer : args.layers) { |
Vishnu Nair | ba35410 | 2022-08-01 00:14:18 +0000 | [diff] [blame] | 135 | if (layer->onPreComposition(mRefreshStartTime, args.updatingOutputGeometryThisFrame)) { |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 136 | needsAnotherUpdate = true; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | mNeedsAnotherUpdate = needsAnotherUpdate; |
| 141 | } |
| 142 | |
Lloyd Pique | c3cb729 | 2019-05-17 15:25:14 -0700 | [diff] [blame] | 143 | void CompositionEngine::dump(std::string&) const { |
| 144 | // The base class has no state to dump, but derived classes might. |
| 145 | } |
| 146 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 147 | void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) { |
| 148 | mNeedsAnotherUpdate = value; |
| 149 | } |
| 150 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 151 | } // namespace impl |
| 152 | } // namespace android::compositionengine |