blob: 030c7039f7c8ccd33eb1c084bea3a8468e55c1f6 [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
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Lloyd Piqueab039b52019-02-13 14:22:42 -080021#include <compositionengine/CompositionRefreshArgs.h>
22#include <compositionengine/LayerFE.h>
Lloyd Piquec7b0c752019-03-07 20:59:59 -080023#include <compositionengine/OutputLayer.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070024#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070025#include <compositionengine/impl/Display.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080026#include <compositionengine/impl/Layer.h>
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070027#include <renderengine/RenderEngine.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080028#include <utils/Trace.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070029
Lloyd Pique441d5042018-10-18 16:49:51 -070030#include "DisplayHardware/HWComposer.h"
31
Lloyd Pique70d91362018-10-18 16:02:55 -070032namespace android::compositionengine {
33
34CompositionEngine::~CompositionEngine() = default;
35
36namespace impl {
37
38std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() {
39 return std::make_unique<CompositionEngine>();
40}
41
42CompositionEngine::CompositionEngine() = default;
43CompositionEngine::~CompositionEngine() = default;
44
Lloyd Pique45a165a2018-10-19 11:54:47 -070045std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay(
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070046 const DisplayCreationArgs& args) {
47 return compositionengine::impl::createDisplay(*this, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070048}
49
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070050std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer(
51 const LayerCreationArgs& args) {
52 return compositionengine::impl::createLayer(args);
Lloyd Piquefeb73d72018-12-04 17:23:44 -080053}
54
Lloyd Pique441d5042018-10-18 16:49:51 -070055HWComposer& CompositionEngine::getHwComposer() const {
56 return *mHwComposer.get();
57}
58
59void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) {
60 mHwComposer = std::move(hwComposer);
61}
62
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070063renderengine::RenderEngine& CompositionEngine::getRenderEngine() const {
64 return *mRenderEngine.get();
65}
66
67void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
68 mRenderEngine = std::move(renderEngine);
69}
70
Alec Mourie4034bb2019-11-19 12:45:54 -080071TimeStats& CompositionEngine::getTimeStats() const {
72 return *mTimeStats.get();
73}
74
75void CompositionEngine::setTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
76 mTimeStats = timeStats;
77}
78
Lloyd Piqueab039b52019-02-13 14:22:42 -080079bool CompositionEngine::needsAnotherUpdate() const {
80 return mNeedsAnotherUpdate;
81}
82
83nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const {
84 return mRefreshStartTime;
85}
86
Lloyd Piqued7b429f2019-03-07 21:11:02 -080087void CompositionEngine::present(CompositionRefreshArgs& args) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -080088 ATRACE_CALL();
89 ALOGV(__FUNCTION__);
90
91 preComposition(args);
92
93 {
94 // latchedLayers is used to track the set of front-end layer state that
95 // has been latched across all outputs for the prepare step, and is not
96 // needed for anything else.
97 LayerFESet latchedLayers;
98
99 for (const auto& output : args.outputs) {
100 output->prepare(args, latchedLayers);
101 }
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800102 }
103
104 updateLayerStateFromFE(args);
105
106 for (const auto& output : args.outputs) {
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800107 output->present(args);
108 }
109}
110
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800111void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
112 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
113 uniqueVisibleLayers;
114
115 for (const auto& output : args.outputs) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700116 for (auto* layer : output->getOutputLayersOrderedByZ()) {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800117 if (layer->isHardwareCursor()) {
118 // Latch the cursor composition state from each front-end layer.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700119 layer->getLayerFE().latchCursorCompositionState(layer->getLayer().editFEState());
120
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800121 layer->writeCursorPositionToHWC();
122 }
123 }
124 }
125}
126
Lloyd Piqueab039b52019-02-13 14:22:42 -0800127void CompositionEngine::preComposition(CompositionRefreshArgs& args) {
128 ATRACE_CALL();
129 ALOGV(__FUNCTION__);
130
131 bool needsAnotherUpdate = false;
132
133 mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
134
135 for (auto& layer : args.layers) {
136 sp<compositionengine::LayerFE> layerFE = layer->getLayerFE();
137 if (layerFE && layerFE->onPreComposition(mRefreshStartTime)) {
138 needsAnotherUpdate = true;
139 }
140 }
141
142 mNeedsAnotherUpdate = needsAnotherUpdate;
143}
144
Lloyd Piquec3cb7292019-05-17 15:25:14 -0700145void CompositionEngine::dump(std::string&) const {
146 // The base class has no state to dump, but derived classes might.
147}
148
Lloyd Piqueab039b52019-02-13 14:22:42 -0800149void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
150 mNeedsAnotherUpdate = value;
151}
152
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800153void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) {
154 // Update the composition state from each front-end layer
155 for (const auto& output : args.outputs) {
156 output->updateLayerStateFromFE(args);
157 }
158}
159
Lloyd Pique70d91362018-10-18 16:02:55 -0700160} // namespace impl
161} // namespace android::compositionengine
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800162
163// TODO(b/129481165): remove the #pragma below and fix conversion issues
164#pragma clang diagnostic pop // ignored "-Wconversion"