blob: 855507eec4ddd8e0161c21f7b652eefd9118289b [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
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800108 for (const auto& output : args.outputs) {
Lloyd Piqued7b429f2019-03-07 21:11:02 -0800109 output->present(args);
110 }
111}
112
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800113void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) {
114 std::unordered_map<compositionengine::LayerFE*, compositionengine::LayerFECompositionState*>
115 uniqueVisibleLayers;
116
117 for (const auto& output : args.outputs) {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700118 for (auto* layer : output->getOutputLayersOrderedByZ()) {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800119 if (layer->isHardwareCursor()) {
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800120 layer->writeCursorPositionToHWC();
121 }
122 }
123 }
124}
125
Lloyd Piqueab039b52019-02-13 14:22:42 -0800126void CompositionEngine::preComposition(CompositionRefreshArgs& args) {
127 ATRACE_CALL();
128 ALOGV(__FUNCTION__);
129
130 bool needsAnotherUpdate = false;
131
132 mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC);
133
134 for (auto& layer : args.layers) {
Vishnu Nairba354102022-08-01 00:14:18 +0000135 if (layer->onPreComposition(mRefreshStartTime, args.updatingOutputGeometryThisFrame)) {
Lloyd Piqueab039b52019-02-13 14:22:42 -0800136 needsAnotherUpdate = true;
137 }
138 }
139
140 mNeedsAnotherUpdate = needsAnotherUpdate;
141}
142
Lloyd Piquec3cb7292019-05-17 15:25:14 -0700143void CompositionEngine::dump(std::string&) const {
144 // The base class has no state to dump, but derived classes might.
145}
146
Lloyd Piqueab039b52019-02-13 14:22:42 -0800147void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) {
148 mNeedsAnotherUpdate = value;
149}
150
Lloyd Pique70d91362018-10-18 16:02:55 -0700151} // namespace impl
152} // namespace android::compositionengine