blob: 5eabecd3ca21d975af1e8e60ed20f6ab7cc6eb8a [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 Piquec7b0c752019-03-07 20:59:59 -080019#include <compositionengine/OutputLayer.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070020#include <compositionengine/impl/CompositionEngine.h>
Lloyd Pique45a165a2018-10-19 11:54:47 -070021#include <compositionengine/impl/Display.h>
Lloyd Piquefeb73d72018-12-04 17:23:44 -080022#include <compositionengine/impl/Layer.h>
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070023#include <renderengine/RenderEngine.h>
Lloyd Piqueab039b52019-02-13 14:22:42 -080024#include <utils/Trace.h>
Lloyd Pique70d91362018-10-18 16:02:55 -070025
Lloyd Pique441d5042018-10-18 16:49:51 -070026#include "DisplayHardware/HWComposer.h"
27
Lloyd Pique70d91362018-10-18 16:02:55 -070028namespace android::compositionengine {
29
30CompositionEngine::~CompositionEngine() = default;
31
32namespace impl {
33
34std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() {
35 return std::make_unique<CompositionEngine>();
36}
37
38CompositionEngine::CompositionEngine() = default;
39CompositionEngine::~CompositionEngine() = default;
40
Lloyd Pique45a165a2018-10-19 11:54:47 -070041std::shared_ptr<compositionengine::Display> CompositionEngine::createDisplay(
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070042 const DisplayCreationArgs& args) {
43 return compositionengine::impl::createDisplay(*this, args);
Lloyd Pique45a165a2018-10-19 11:54:47 -070044}
45
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070046std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer(
47 const LayerCreationArgs& args) {
48 return compositionengine::impl::createLayer(args);
Lloyd Piquefeb73d72018-12-04 17:23:44 -080049}
50
Lloyd Pique441d5042018-10-18 16:49:51 -070051HWComposer& CompositionEngine::getHwComposer() const {
52 return *mHwComposer.get();
53}
54
55void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) {
56 mHwComposer = std::move(hwComposer);
57}
58
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070059renderengine::RenderEngine& CompositionEngine::getRenderEngine() const {
60 return *mRenderEngine.get();
61}
62
63void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
64 mRenderEngine = std::move(renderEngine);
65}
66
Alec Mourie4034bb2019-11-19 12:45:54 -080067TimeStats& CompositionEngine::getTimeStats() const {
68 return *mTimeStats.get();
69}
70
71void CompositionEngine::setTimeStats(const std::shared_ptr<TimeStats>& timeStats) {
72 mTimeStats = timeStats;
73}
74
Lloyd Piqueab039b52019-02-13 14:22:42 -080075bool CompositionEngine::needsAnotherUpdate() const {
76 return mNeedsAnotherUpdate;
77}
78
79nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const {
80 return mRefreshStartTime;
81}
82
Lloyd Piqued7b429f2019-03-07 21:11:02 -080083void CompositionEngine::present(CompositionRefreshArgs& args) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -080084 ATRACE_CALL();
85 ALOGV(__FUNCTION__);
86
87 preComposition(args);
88
89 {
90 // latchedLayers is used to track the set of front-end layer state that
91 // has been latched across all outputs for the prepare step, and is not
92 // needed for anything else.
93 LayerFESet latchedLayers;
94
95 for (const auto& output : args.outputs) {
96 output->prepare(args, latchedLayers);
97 }
Lloyd Pique3eb1b212019-03-07 21:15:40 -080098 }
99
100 updateLayerStateFromFE(args);
101
102 for (const auto& output : args.outputs) {
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800103 output->present(args);
104 }
105}
106
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800107void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
108 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
109 uniqueVisibleLayers;
110
111 for (const auto& output : args.outputs) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700112 for (auto* layer : output->getOutputLayersOrderedByZ()) {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800113 if (layer->isHardwareCursor()) {
114 // Latch the cursor composition state from each front-end layer.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700115 layer->getLayerFE().latchCursorCompositionState(layer->getLayer().editFEState());
116
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800117 layer->writeCursorPositionToHWC();
118 }
119 }
120 }
121}
122
Lloyd Piqueab039b52019-02-13 14:22:42 -0800123void CompositionEngine::preComposition(CompositionRefreshArgs& args) {
124 ATRACE_CALL();
125 ALOGV(__FUNCTION__);
126
127 bool needsAnotherUpdate = false;
128
129 mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
130
131 for (auto& layer : args.layers) {
132 sp<compositionengine::LayerFE> layerFE = layer->getLayerFE();
133 if (layerFE && layerFE->onPreComposition(mRefreshStartTime)) {
134 needsAnotherUpdate = true;
135 }
136 }
137
138 mNeedsAnotherUpdate = needsAnotherUpdate;
139}
140
Lloyd Piquec3cb7292019-05-17 15:25:14 -0700141void CompositionEngine::dump(std::string&) const {
142 // The base class has no state to dump, but derived classes might.
143}
144
Lloyd Piqueab039b52019-02-13 14:22:42 -0800145void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
146 mNeedsAnotherUpdate = value;
147}
148
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800149void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) {
150 // Update the composition state from each front-end layer
151 for (const auto& output : args.outputs) {
152 output->updateLayerStateFromFE(args);
153 }
154}
155
Lloyd Pique70d91362018-10-18 16:02:55 -0700156} // namespace impl
157} // namespace android::compositionengine