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 | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 19 | #include <compositionengine/OutputLayer.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 20 | #include <compositionengine/impl/CompositionEngine.h> |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 21 | #include <compositionengine/impl/Display.h> |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 22 | #include <compositionengine/impl/Layer.h> |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 23 | #include <renderengine/RenderEngine.h> |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 24 | #include <utils/Trace.h> |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 25 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 26 | #include "DisplayHardware/HWComposer.h" |
| 27 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 28 | namespace android::compositionengine { |
| 29 | |
| 30 | CompositionEngine::~CompositionEngine() = default; |
| 31 | |
| 32 | namespace impl { |
| 33 | |
| 34 | std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() { |
| 35 | return std::make_unique<CompositionEngine>(); |
| 36 | } |
| 37 | |
| 38 | CompositionEngine::CompositionEngine() = default; |
| 39 | CompositionEngine::~CompositionEngine() = default; |
| 40 | |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 41 | std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay( |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame^] | 42 | const DisplayCreationArgs& args) { |
| 43 | return compositionengine::impl::createDisplay(*this, args); |
Lloyd Pique | 45a165a | 2018-10-19 11:54:47 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame^] | 46 | std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer( |
| 47 | const LayerCreationArgs& args) { |
| 48 | return compositionengine::impl::createLayer(args); |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Lloyd Pique | 441d504 | 2018-10-18 16:49:51 -0700 | [diff] [blame] | 51 | HWComposer& CompositionEngine::getHwComposer() const { |
| 52 | return *mHwComposer.get(); |
| 53 | } |
| 54 | |
| 55 | void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) { |
| 56 | mHwComposer = std::move(hwComposer); |
| 57 | } |
| 58 | |
Lloyd Pique | b97e04f | 2018-10-18 17:07:05 -0700 | [diff] [blame] | 59 | renderengine::RenderEngine& CompositionEngine::getRenderEngine() const { |
| 60 | return *mRenderEngine.get(); |
| 61 | } |
| 62 | |
| 63 | void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { |
| 64 | mRenderEngine = std::move(renderEngine); |
| 65 | } |
| 66 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 67 | bool CompositionEngine::needsAnotherUpdate() const { |
| 68 | return mNeedsAnotherUpdate; |
| 69 | } |
| 70 | |
| 71 | nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const { |
| 72 | return mRefreshStartTime; |
| 73 | } |
| 74 | |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 75 | void CompositionEngine::present(CompositionRefreshArgs& args) { |
Lloyd Pique | c29e4c6 | 2019-03-07 21:48:19 -0800 | [diff] [blame] | 76 | ATRACE_CALL(); |
| 77 | ALOGV(__FUNCTION__); |
| 78 | |
| 79 | preComposition(args); |
| 80 | |
| 81 | { |
| 82 | // latchedLayers is used to track the set of front-end layer state that |
| 83 | // has been latched across all outputs for the prepare step, and is not |
| 84 | // needed for anything else. |
| 85 | LayerFESet latchedLayers; |
| 86 | |
| 87 | for (const auto& output : args.outputs) { |
| 88 | output->prepare(args, latchedLayers); |
| 89 | } |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | updateLayerStateFromFE(args); |
| 93 | |
| 94 | for (const auto& output : args.outputs) { |
Lloyd Pique | d7b429f | 2019-03-07 21:11:02 -0800 | [diff] [blame] | 95 | output->present(args); |
| 96 | } |
| 97 | } |
| 98 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 99 | void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) { |
| 100 | std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*> |
| 101 | uniqueVisibleLayers; |
| 102 | |
| 103 | for (const auto& output : args.outputs) { |
| 104 | for (auto& layer : output->getOutputLayersOrderedByZ()) { |
| 105 | if (layer->isHardwareCursor()) { |
| 106 | // Latch the cursor composition state from each front-end layer. |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 107 | layer->getLayerFE().latchCursorCompositionState(layer->getLayer().editFEState()); |
| 108 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 109 | layer->writeCursorPositionToHWC(); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
Lloyd Pique | ab039b5 | 2019-02-13 14:22:42 -0800 | [diff] [blame] | 115 | void CompositionEngine::preComposition(CompositionRefreshArgs& args) { |
| 116 | ATRACE_CALL(); |
| 117 | ALOGV(__FUNCTION__); |
| 118 | |
| 119 | bool needsAnotherUpdate = false; |
| 120 | |
| 121 | mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 122 | |
| 123 | for (auto& layer : args.layers) { |
| 124 | sp<compositionengine::LayerFE> layerFE = layer->getLayerFE(); |
| 125 | if (layerFE && layerFE->onPreComposition(mRefreshStartTime)) { |
| 126 | needsAnotherUpdate = true; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | mNeedsAnotherUpdate = needsAnotherUpdate; |
| 131 | } |
| 132 | |
| 133 | void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) { |
| 134 | mNeedsAnotherUpdate = value; |
| 135 | } |
| 136 | |
Lloyd Pique | 3eb1b21 | 2019-03-07 21:15:40 -0800 | [diff] [blame] | 137 | void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) { |
| 138 | // Update the composition state from each front-end layer |
| 139 | for (const auto& output : args.outputs) { |
| 140 | output->updateLayerStateFromFE(args); |
| 141 | } |
| 142 | } |
| 143 | |
Lloyd Pique | 70d9136 | 2018-10-18 16:02:55 -0700 | [diff] [blame] | 144 | } // namespace impl |
| 145 | } // namespace android::compositionengine |