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 17 #include <compositionengine/CompositionRefreshArgs.h> 18 #include <compositionengine/LayerFE.h> 19 #include <compositionengine/LayerFECompositionState.h> 20 #include <compositionengine/OutputLayer.h> 21 #include <compositionengine/impl/CompositionEngine.h> 22 #include <compositionengine/impl/Display.h> 23 24 #include <renderengine/RenderEngine.h> 25 #include <utils/Trace.h> 26 27 // TODO(b/129481165): remove the #pragma below and fix conversion issues 28 #pragma clang diagnostic push 29 #pragma clang diagnostic ignored "-Wconversion" 30 31 #include "DisplayHardware/HWComposer.h" 32 33 // TODO(b/129481165): remove the #pragma below and fix conversion issues 34 #pragma clang diagnostic pop // ignored "-Wconversion" 35 36 namespace android::compositionengine { 37 38 CompositionEngine::~CompositionEngine() = default; 39 40 namespace impl { 41 createCompositionEngine()42std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() { 43 return std::make_unique<CompositionEngine>(); 44 } 45 46 CompositionEngine::CompositionEngine() = default; 47 CompositionEngine::~CompositionEngine() = default; 48 createDisplay(const DisplayCreationArgs & args)49std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay( 50 const DisplayCreationArgs& args) { 51 return compositionengine::impl::createDisplay(*this, args); 52 } 53 54 std::unique_ptr<compositionengine::LayerFECompositionState> createLayerFECompositionState()55CompositionEngine::createLayerFECompositionState() { 56 return std::make_unique<compositionengine::LayerFECompositionState>(); 57 } 58 getHwComposer() const59HWComposer& CompositionEngine::getHwComposer() const { 60 return *mHwComposer.get(); 61 } 62 setHwComposer(std::unique_ptr<HWComposer> hwComposer)63void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) { 64 mHwComposer = std::move(hwComposer); 65 } 66 getRenderEngine() const67renderengine::RenderEngine& CompositionEngine::getRenderEngine() const { 68 return *mRenderEngine.get(); 69 } 70 setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine)71void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) { 72 mRenderEngine = std::move(renderEngine); 73 } 74 getTimeStats() const75TimeStats& CompositionEngine::getTimeStats() const { 76 return *mTimeStats.get(); 77 } 78 setTimeStats(const std::shared_ptr<TimeStats> & timeStats)79void CompositionEngine::setTimeStats(const std::shared_ptr<TimeStats>& timeStats) { 80 mTimeStats = timeStats; 81 } 82 needsAnotherUpdate() const83bool CompositionEngine::needsAnotherUpdate() const { 84 return mNeedsAnotherUpdate; 85 } 86 getLastFrameRefreshTimestamp() const87nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const { 88 return mRefreshStartTime; 89 } 90 present(CompositionRefreshArgs & args)91void CompositionEngine::present(CompositionRefreshArgs& args) { 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 } 106 } 107 108 updateLayerStateFromFE(args); 109 110 for (const auto& output : args.outputs) { 111 output->present(args); 112 } 113 } 114 updateCursorAsync(CompositionRefreshArgs & args)115void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) { 116 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*> 117 uniqueVisibleLayers; 118 119 for (const auto& output : args.outputs) { 120 for (auto* layer : output->getOutputLayersOrderedByZ()) { 121 if (layer->isHardwareCursor()) { 122 // Latch the cursor composition state from each front-end layer. 123 layer->getLayerFE().prepareCompositionState(LayerFE::StateSubset::Cursor); 124 layer->writeCursorPositionToHWC(); 125 } 126 } 127 } 128 } 129 preComposition(CompositionRefreshArgs & args)130void CompositionEngine::preComposition(CompositionRefreshArgs& args) { 131 ATRACE_CALL(); 132 ALOGV(__FUNCTION__); 133 134 bool needsAnotherUpdate = false; 135 136 mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); 137 138 for (auto& layer : args.layers) { 139 if (layer->onPreComposition(mRefreshStartTime)) { 140 needsAnotherUpdate = true; 141 } 142 } 143 144 mNeedsAnotherUpdate = needsAnotherUpdate; 145 } 146 dump(std::string &) const147void CompositionEngine::dump(std::string&) const { 148 // The base class has no state to dump, but derived classes might. 149 } 150 setNeedsAnotherUpdateForTest(bool value)151void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) { 152 mNeedsAnotherUpdate = value; 153 } 154 updateLayerStateFromFE(CompositionRefreshArgs & args)155void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) { 156 // Update the composition state from each front-end layer 157 for (const auto& output : args.outputs) { 158 output->updateLayerStateFromFE(args); 159 } 160 } 161 162 } // namespace impl 163 } // namespace android::compositionengine 164