blob: 8391458e99765776f5cc726fa64dd4e50d18ec00 [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(
42 DisplayCreationArgs&& args) {
43 return compositionengine::impl::createDisplay(*this, std::move(args));
44}
45
Lloyd Piquefeb73d72018-12-04 17:23:44 -080046std::shared_ptr<compositionengine::Layer> CompositionEngine::createLayer(LayerCreationArgs&& args) {
47 return compositionengine::impl::createLayer(*this, std::move(args));
48}
49
Lloyd Pique441d5042018-10-18 16:49:51 -070050HWComposer& CompositionEngine::getHwComposer() const {
51 return *mHwComposer.get();
52}
53
54void CompositionEngine::setHwComposer(std::unique_ptr<HWComposer> hwComposer) {
55 mHwComposer = std::move(hwComposer);
56}
57
Lloyd Piqueb97e04f2018-10-18 17:07:05 -070058renderengine::RenderEngine& CompositionEngine::getRenderEngine() const {
59 return *mRenderEngine.get();
60}
61
62void CompositionEngine::setRenderEngine(std::unique_ptr<renderengine::RenderEngine> renderEngine) {
63 mRenderEngine = std::move(renderEngine);
64}
65
Lloyd Piqueab039b52019-02-13 14:22:42 -080066bool CompositionEngine::needsAnotherUpdate() const {
67 return mNeedsAnotherUpdate;
68}
69
70nsecs_t CompositionEngine::getLastFrameRefreshTimestamp() const {
71 return mRefreshStartTime;
72}
73
Lloyd Piqued7b429f2019-03-07 21:11:02 -080074void CompositionEngine::present(CompositionRefreshArgs& args) {
Lloyd Piquec29e4c62019-03-07 21:48:19 -080075 ATRACE_CALL();
76 ALOGV(__FUNCTION__);
77
78 preComposition(args);
79
80 {
81 // latchedLayers is used to track the set of front-end layer state that
82 // has been latched across all outputs for the prepare step, and is not
83 // needed for anything else.
84 LayerFESet latchedLayers;
85
86 for (const auto& output : args.outputs) {
87 output->prepare(args, latchedLayers);
88 }
Lloyd Pique3eb1b212019-03-07 21:15:40 -080089 }
90
91 updateLayerStateFromFE(args);
92
93 for (const auto& output : args.outputs) {
Lloyd Piqued7b429f2019-03-07 21:11:02 -080094 output->present(args);
95 }
96}
97
Lloyd Piquec7b0c752019-03-07 20:59:59 -080098void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
99 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
100 uniqueVisibleLayers;
101
102 for (const auto& output : args.outputs) {
103 for (auto& layer : output->getOutputLayersOrderedByZ()) {
104 if (layer->isHardwareCursor()) {
105 // Latch the cursor composition state from each front-end layer.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700106 layer->getLayerFE().latchCursorCompositionState(layer->getLayer().editFEState());
107
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800108 layer->writeCursorPositionToHWC();
109 }
110 }
111 }
112}
113
Lloyd Piqueab039b52019-02-13 14:22:42 -0800114void CompositionEngine::preComposition(CompositionRefreshArgs& args) {
115 ATRACE_CALL();
116 ALOGV(__FUNCTION__);
117
118 bool needsAnotherUpdate = false;
119
120 mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
121
122 for (auto& layer : args.layers) {
123 sp<compositionengine::LayerFE> layerFE = layer->getLayerFE();
124 if (layerFE && layerFE->onPreComposition(mRefreshStartTime)) {
125 needsAnotherUpdate = true;
126 }
127 }
128
129 mNeedsAnotherUpdate = needsAnotherUpdate;
130}
131
132void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
133 mNeedsAnotherUpdate = value;
134}
135
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800136void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) {
137 // Update the composition state from each front-end layer
138 for (const auto& output : args.outputs) {
139 output->updateLayerStateFromFE(args);
140 }
141}
142
Lloyd Pique70d91362018-10-18 16:02:55 -0700143} // namespace impl
144} // namespace android::compositionengine