blob: 6203dc6737cb491a8a957e05367400883660b046 [file] [log] [blame]
Lloyd Pique70d91362018-10-18 16:02:55 -07001/*
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 Piqueab039b52019-02-13 14:22:42 -080017#include <compositionengine/CompositionRefreshArgs.h>
18#include <compositionengine/LayerFE.h>
Lloyd Piquede196652020-01-22 17:29:58 -080019#include <compositionengine/LayerFECompositionState.h>
Lloyd Piquec7b0c752019-03-07 20:59:59 -080020#include <compositionengine/OutputLayer.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070021#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070022#include <compositionengine/impl/Display.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080023
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070024#include <renderengine/RenderEngine.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080025#include <utils/Trace.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070026
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080027// TODO(b/129481165): remove the #pragma below and fix conversion issues
28#pragma clang diagnostic push
29#pragma clang diagnostic ignored "-Wconversion"
30
Lloyd Pique441d5042018-10-18 16:49:51 -070031#include "DisplayHardware/HWComposer.h"
32
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080033// TODO(b/129481165): remove the #pragma below and fix conversion issues
34#pragma clang diagnostic pop // ignored "-Wconversion"
35
Lloyd Pique70d91362018-10-18 16:02:55 -070036namespace android::compositionengine {
37
38CompositionEngine::~CompositionEngine() = default;
39
40namespace impl {
41
42std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() {
43 return std::make_unique<CompositionEngine>();
44}
45
46CompositionEngine::CompositionEngine() = default;
47CompositionEngine::~CompositionEngine() = default;
48
Lloyd Pique45a165a2018-10-19 11:54:47 -070049std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay(
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070050 const DisplayCreationArgs& args) {
51 return compositionengine::impl::createDisplay(*this, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070052}
53
Lloyd Piquede196652020-01-22 17:29:58 -080054std::unique_ptr<compositionengine::LayerFECompositionState>
55CompositionEngine::createLayerFECompositionState() {
56 return std::make_unique<compositionengine::LayerFECompositionState>();
Lloyd Piquefeb73d72018-12-04 17:23:44 -080057}
58
Lloyd Pique441d5042018-10-18 16:49:51 -070059HWComposer& CompositionEngine::getHwComposer() const {
60 return *mHwComposer.get();
61}
62
63void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) {
64 mHwComposer = std::move(hwComposer);
65}
66
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070067renderengine::RenderEngine& CompositionEngine::getRenderEngine() const {
68 return *mRenderEngine.get();
69}
70
71void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
72 mRenderEngine = std::move(renderEngine);
73}
74
Alec Mourie4034bb2019-11-19 12:45:54 -080075TimeStats& CompositionEngine::getTimeStats() const {
76 return *mTimeStats.get();
77}
78
79void CompositionEngine::setTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
80 mTimeStats = timeStats;
81}
82
Lloyd Piqueab039b52019-02-13 14:22:42 -080083bool CompositionEngine::needsAnotherUpdate() const {
84 return mNeedsAnotherUpdate;
85}
86
87nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const {
88 return mRefreshStartTime;
89}
90
Lloyd Piqued7b429f2019-03-07 21:11:02 -080091void CompositionEngine::present(CompositionRefreshArgs& args) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -080092 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 Pique3eb1b212019-03-07 21:15:40 -0800106 }
107
108 updateLayerStateFromFE(args);
109
110 for (const auto& output : args.outputs) {
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800111 output->present(args);
112 }
113}
114
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800115void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
116 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
117 uniqueVisibleLayers;
118
119 for (const auto& output : args.outputs) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700120 for (auto* layer : output->getOutputLayersOrderedByZ()) {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800121 if (layer->isHardwareCursor()) {
122 // Latch the cursor composition state from each front-end layer.
Lloyd Piquede196652020-01-22 17:29:58 -0800123 layer->getLayerFE().prepareCompositionState(LayerFE::StateSubset::Cursor);
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800124 layer->writeCursorPositionToHWC();
125 }
126 }
127 }
128}
129
Lloyd Piqueab039b52019-02-13 14:22:42 -0800130void 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) {
Lloyd Piquede196652020-01-22 17:29:58 -0800139 if (layer->onPreComposition(mRefreshStartTime)) {
Lloyd Piqueab039b52019-02-13 14:22:42 -0800140 needsAnotherUpdate = true;
141 }
142 }
143
144 mNeedsAnotherUpdate = needsAnotherUpdate;
145}
146
Lloyd Piquec3cb7292019-05-17 15:25:14 -0700147void CompositionEngine::dump(std::string&) const {
148 // The base class has no state to dump, but derived classes might.
149}
150
Lloyd Piqueab039b52019-02-13 14:22:42 -0800151void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
152 mNeedsAnotherUpdate = value;
153}
154
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800155void 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
Lloyd Pique70d91362018-10-18 16:02:55 -0700162} // namespace impl
163} // namespace android::compositionengine