blob: e5d648194fba026c6bd1baa41059477c90e61836 [file] [log] [blame]
Vishnu Nair6b591152021-10-08 11:45:14 -07001/*
Dominik Laskowski1f6fc702022-03-21 08:34:50 -07002 * Copyright 2021 The Android Open Source Project
Vishnu Nair6b591152021-10-08 11:45:14 -07003 *
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
17#pragma once
18
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070019#include <condition_variable>
20#include <memory>
21#include <mutex>
22#include <vector>
Vishnu Nair1391de22023-03-05 19:56:14 -080023#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair40fff5c2022-11-04 02:46:28 +000024#include "renderengine/ExternalTexture.h"
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070025
Ady Abraham7d1e9ce2024-05-17 14:51:24 -070026#include <common/FlagManager.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070027#include <gui/LayerState.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070028#include <system/window.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070029
30namespace android {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070031
liulijuneb489f62022-10-17 22:02:14 +080032enum TraverseBuffersReturnValues {
33 CONTINUE_TRAVERSAL,
34 STOP_TRAVERSAL,
35 DELETE_AND_CONTINUE_TRAVERSAL,
36};
37
Brian Lindahl439afad2022-11-14 11:16:55 -070038// Extends the client side composer state by resolving buffer.
Vishnu Nair40fff5c2022-11-04 02:46:28 +000039class ResolvedComposerState : public ComposerState {
40public:
41 ResolvedComposerState() = default;
42 ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); }
43 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
Vishnu Nair1391de22023-03-05 19:56:14 -080044 uint32_t layerId = UNASSIGNED_LAYER_ID;
45 uint32_t parentId = UNASSIGNED_LAYER_ID;
46 uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
47 uint32_t touchCropId = UNASSIGNED_LAYER_ID;
Vishnu Nair40fff5c2022-11-04 02:46:28 +000048};
49
Vishnu Nair6b591152021-10-08 11:45:14 -070050struct TransactionState {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070051 TransactionState() = default;
52
Vishnu Nair6b591152021-10-08 11:45:14 -070053 TransactionState(const FrameTimelineInfo& frameTimelineInfo,
Vishnu Nair40fff5c2022-11-04 02:46:28 +000054 std::vector<ResolvedComposerState>& composerStates,
Vishnu Nair6b591152021-10-08 11:45:14 -070055 const Vector<DisplayState>& displayStates, uint32_t transactionFlags,
56 const sp<IBinder>& applyToken, const InputWindowCommands& inputWindowCommands,
57 int64_t desiredPresentTime, bool isAutoTimestamp,
Chavi Weingartenc78f53c2023-04-14 18:50:53 +000058 std::vector<uint64_t> uncacheBufferIds, int64_t postTime,
Vishnu Nair6b591152021-10-08 11:45:14 -070059 bool hasListenerCallbacks, std::vector<ListenerCallbacks> listenerCallbacks,
Pablo Gamito23780be2023-04-18 08:30:00 +000060 int originPid, int originUid, uint64_t transactionId,
61 std::vector<uint64_t> mergedTransactionIds)
Vishnu Nair6b591152021-10-08 11:45:14 -070062 : frameTimelineInfo(frameTimelineInfo),
Vishnu Nair40fff5c2022-11-04 02:46:28 +000063 states(std::move(composerStates)),
Vishnu Nair6b591152021-10-08 11:45:14 -070064 displays(displayStates),
65 flags(transactionFlags),
66 applyToken(applyToken),
67 inputWindowCommands(inputWindowCommands),
68 desiredPresentTime(desiredPresentTime),
69 isAutoTimestamp(isAutoTimestamp),
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000070 uncacheBufferIds(std::move(uncacheBufferIds)),
Vishnu Nair6b591152021-10-08 11:45:14 -070071 postTime(postTime),
Vishnu Nair6b591152021-10-08 11:45:14 -070072 hasListenerCallbacks(hasListenerCallbacks),
73 listenerCallbacks(listenerCallbacks),
74 originPid(originPid),
75 originUid(originUid),
Pablo Gamito23780be2023-04-18 08:30:00 +000076 id(transactionId),
77 mergedTransactionIds(std::move(mergedTransactionIds)) {}
Vishnu Nair6b591152021-10-08 11:45:14 -070078
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070079 // Invokes `void(const layer_state_t&)` visitor for matching layers.
80 template <typename Visitor>
81 void traverseStatesWithBuffers(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000082 for (const auto& state : states) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070083 if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000084 visitor(state.state);
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070085 }
86 }
87 }
Vishnu Nair6b591152021-10-08 11:45:14 -070088
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070089 template <typename Visitor>
Vishnu Nair7be27602024-03-28 20:27:09 -070090 void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) NO_THREAD_SAFETY_ANALYSIS {
liulijuneb489f62022-10-17 22:02:14 +080091 for (auto state = states.begin(); state != states.end();) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070092 if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) {
Vishnu Nair4d9cef92023-06-24 22:34:41 +000093 int result = visitor(*state);
liulijuneb489f62022-10-17 22:02:14 +080094 if (result == STOP_TRAVERSAL) return;
95 if (result == DELETE_AND_CONTINUE_TRAVERSAL) {
96 state = states.erase(state);
97 continue;
98 }
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070099 }
liulijuneb489f62022-10-17 22:02:14 +0800100 state++;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700101 }
102 }
103
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700104 // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical
105 // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be
106 // able to setFrameRate once, rather than for each transaction.
107 bool isFrameActive() const {
108 if (!displays.empty()) return true;
109
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000110 for (const auto& state : states) {
Ady Abrahamceb72e82023-01-17 17:40:21 -0800111 const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged;
Ady Abraham7d1e9ce2024-05-17 14:51:24 -0700112 if (FlagManager::getInstance().vrr_bugfix_24q4()) {
113 const bool frameRateIsNoVote = frameRateChanged &&
114 state.state.frameRateCompatibility == ANATIVEWINDOW_FRAME_RATE_NO_VOTE;
115 const bool frameRateCategoryChanged =
116 state.state.what & layer_state_t::eFrameRateCategoryChanged;
117 const bool frameRateCategoryIsNoPreference = frameRateCategoryChanged &&
118 state.state.frameRateCategory ==
119 ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE;
120 if (!frameRateIsNoVote && !frameRateCategoryIsNoPreference) {
121 return true;
122 }
123 } else {
124 if (!frameRateChanged ||
125 state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) {
126 return true;
127 }
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700128 }
129 }
130
131 return false;
132 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700133
134 FrameTimelineInfo frameTimelineInfo;
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000135 std::vector<ResolvedComposerState> states;
Vishnu Nair6b591152021-10-08 11:45:14 -0700136 Vector<DisplayState> displays;
137 uint32_t flags;
138 sp<IBinder> applyToken;
139 InputWindowCommands inputWindowCommands;
140 int64_t desiredPresentTime;
141 bool isAutoTimestamp;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000142 std::vector<uint64_t> uncacheBufferIds;
Vishnu Nair6b591152021-10-08 11:45:14 -0700143 int64_t postTime;
Vishnu Nair6b591152021-10-08 11:45:14 -0700144 bool hasListenerCallbacks;
145 std::vector<ListenerCallbacks> listenerCallbacks;
146 int originPid;
147 int originUid;
148 uint64_t id;
Robert Carr4c1b6462021-12-21 10:30:50 -0800149 bool sentFenceTimeoutWarning = false;
Pablo Gamito23780be2023-04-18 08:30:00 +0000150 std::vector<uint64_t> mergedTransactionIds;
Vishnu Nair6b591152021-10-08 11:45:14 -0700151};
152
Vishnu Nair6b591152021-10-08 11:45:14 -0700153} // namespace android