blob: 6a17a0d0cb8507a8c3ecc9416d5c0f1e232a4f2d [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 <memory>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070020#include <vector>
Vishnu Nair1391de22023-03-05 19:56:14 -080021#include "FrontEnd/LayerCreationArgs.h"
Vishnu Nair40fff5c2022-11-04 02:46:28 +000022#include "renderengine/ExternalTexture.h"
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070023
Vishnu Nair734f2882024-12-19 17:04:57 -080024#include <PowerAdvisor/Workload.h>
Ady Abraham7d1e9ce2024-05-17 14:51:24 -070025#include <common/FlagManager.h>
Vishnu Nair734f2882024-12-19 17:04:57 -080026#include <ftl/flags.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070027#include <gui/LayerState.h>
Anton Ivanovd7b71ac2025-03-18 13:41:02 -070028#include <gui/TransactionState.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070029#include <system/window.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070030
31namespace android {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070032
liulijuneb489f62022-10-17 22:02:14 +080033enum TraverseBuffersReturnValues {
34 CONTINUE_TRAVERSAL,
35 STOP_TRAVERSAL,
36 DELETE_AND_CONTINUE_TRAVERSAL,
37};
38
Brian Lindahl439afad2022-11-14 11:16:55 -070039// Extends the client side composer state by resolving buffer.
Vishnu Nair40fff5c2022-11-04 02:46:28 +000040class ResolvedComposerState : public ComposerState {
41public:
42 ResolvedComposerState() = default;
43 ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); }
44 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
Vishnu Nair1391de22023-03-05 19:56:14 -080045 uint32_t layerId = UNASSIGNED_LAYER_ID;
46 uint32_t parentId = UNASSIGNED_LAYER_ID;
47 uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
48 uint32_t touchCropId = UNASSIGNED_LAYER_ID;
Vishnu Nair40fff5c2022-11-04 02:46:28 +000049};
50
Vishnu Nair3f0c7232024-12-17 15:57:50 -080051struct QueuedTransactionState {
52 QueuedTransactionState() = default;
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070053
Anton Ivanovd7b71ac2025-03-18 13:41:02 -070054 QueuedTransactionState(TransactionState&& transactionState,
55 std::vector<ResolvedComposerState>&& composerStates,
56 std::vector<uint64_t>&& uncacheBufferIds, int64_t postTime,
57 int originPid, int originUid)
58 : frameTimelineInfo(std::move(transactionState.mFrameTimelineInfo)),
59 states(composerStates),
60 displays(std::move(transactionState.mDisplayStates)),
61 flags(transactionState.mFlags),
62 applyToken(transactionState.mApplyToken),
63 inputWindowCommands(std::move(transactionState.mInputWindowCommands)),
64 desiredPresentTime(transactionState.mDesiredPresentTime),
65 isAutoTimestamp(transactionState.mIsAutoTimestamp),
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000066 uncacheBufferIds(std::move(uncacheBufferIds)),
Vishnu Nair6b591152021-10-08 11:45:14 -070067 postTime(postTime),
Anton Ivanovd7b71ac2025-03-18 13:41:02 -070068 hasListenerCallbacks(transactionState.mHasListenerCallbacks),
69 listenerCallbacks(std::move(transactionState.mListenerCallbacks)),
Vishnu Nair6b591152021-10-08 11:45:14 -070070 originPid(originPid),
71 originUid(originUid),
Anton Ivanovd7b71ac2025-03-18 13:41:02 -070072 id(transactionState.getId()),
73 mergedTransactionIds(std::move(transactionState.mMergedTransactionIds)) {}
Vishnu Nair6b591152021-10-08 11:45:14 -070074
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070075 // Invokes `void(const layer_state_t&)` visitor for matching layers.
76 template <typename Visitor>
77 void traverseStatesWithBuffers(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000078 for (const auto& state : states) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070079 if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000080 visitor(state.state);
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070081 }
82 }
83 }
Vishnu Nair6b591152021-10-08 11:45:14 -070084
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070085 template <typename Visitor>
Vishnu Nair7be27602024-03-28 20:27:09 -070086 void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) NO_THREAD_SAFETY_ANALYSIS {
liulijuneb489f62022-10-17 22:02:14 +080087 for (auto state = states.begin(); state != states.end();) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070088 if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) {
Vishnu Nair4d9cef92023-06-24 22:34:41 +000089 int result = visitor(*state);
liulijuneb489f62022-10-17 22:02:14 +080090 if (result == STOP_TRAVERSAL) return;
91 if (result == DELETE_AND_CONTINUE_TRAVERSAL) {
92 state = states.erase(state);
93 continue;
94 }
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070095 }
liulijuneb489f62022-10-17 22:02:14 +080096 state++;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070097 }
98 }
99
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700100 // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical
101 // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be
102 // able to setFrameRate once, rather than for each transaction.
103 bool isFrameActive() const {
104 if (!displays.empty()) return true;
105
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000106 for (const auto& state : states) {
Ady Abrahamceb72e82023-01-17 17:40:21 -0800107 const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged;
Ady Abraham7d1e9ce2024-05-17 14:51:24 -0700108 if (FlagManager::getInstance().vrr_bugfix_24q4()) {
109 const bool frameRateIsNoVote = frameRateChanged &&
110 state.state.frameRateCompatibility == ANATIVEWINDOW_FRAME_RATE_NO_VOTE;
111 const bool frameRateCategoryChanged =
112 state.state.what & layer_state_t::eFrameRateCategoryChanged;
113 const bool frameRateCategoryIsNoPreference = frameRateCategoryChanged &&
114 state.state.frameRateCategory ==
115 ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE;
116 if (!frameRateIsNoVote && !frameRateCategoryIsNoPreference) {
117 return true;
118 }
119 } else {
120 if (!frameRateChanged ||
121 state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) {
122 return true;
123 }
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700124 }
125 }
126
127 return false;
128 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700129
130 FrameTimelineInfo frameTimelineInfo;
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000131 std::vector<ResolvedComposerState> states;
Anton Ivanovd7b71ac2025-03-18 13:41:02 -0700132 std::vector<DisplayState> displays;
Vishnu Nair6b591152021-10-08 11:45:14 -0700133 uint32_t flags;
134 sp<IBinder> applyToken;
135 InputWindowCommands inputWindowCommands;
136 int64_t desiredPresentTime;
137 bool isAutoTimestamp;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000138 std::vector<uint64_t> uncacheBufferIds;
Vishnu Nair6b591152021-10-08 11:45:14 -0700139 int64_t postTime;
Vishnu Nair6b591152021-10-08 11:45:14 -0700140 bool hasListenerCallbacks;
141 std::vector<ListenerCallbacks> listenerCallbacks;
142 int originPid;
143 int originUid;
144 uint64_t id;
Robert Carr4c1b6462021-12-21 10:30:50 -0800145 bool sentFenceTimeoutWarning = false;
Pablo Gamito23780be2023-04-18 08:30:00 +0000146 std::vector<uint64_t> mergedTransactionIds;
Vishnu Nair734f2882024-12-19 17:04:57 -0800147 ftl::Flags<adpf::Workload> workloadHint;
Vishnu Nair6b591152021-10-08 11:45:14 -0700148};
149
Vishnu Nair6b591152021-10-08 11:45:14 -0700150} // namespace android