blob: 86683da26c74c4c12b75335856329d78bafacc7c [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>
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 Nair3f0c7232024-12-17 15:57:50 -080050struct QueuedTransactionState {
51 QueuedTransactionState() = default;
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070052
Vishnu Nair3f0c7232024-12-17 15:57:50 -080053 QueuedTransactionState(const FrameTimelineInfo& frameTimelineInfo,
54 std::vector<ResolvedComposerState>& composerStates,
55 const Vector<DisplayState>& displayStates, uint32_t transactionFlags,
56 const sp<IBinder>& applyToken,
57 const InputWindowCommands& inputWindowCommands,
58 int64_t desiredPresentTime, bool isAutoTimestamp,
59 std::vector<uint64_t> uncacheBufferIds, int64_t postTime,
60 bool hasListenerCallbacks,
61 std::vector<ListenerCallbacks> listenerCallbacks, int originPid,
62 int originUid, uint64_t transactionId,
63 std::vector<uint64_t> mergedTransactionIds)
Vishnu Nair6b591152021-10-08 11:45:14 -070064 : frameTimelineInfo(frameTimelineInfo),
Vishnu Nair40fff5c2022-11-04 02:46:28 +000065 states(std::move(composerStates)),
Vishnu Nair6b591152021-10-08 11:45:14 -070066 displays(displayStates),
67 flags(transactionFlags),
68 applyToken(applyToken),
69 inputWindowCommands(inputWindowCommands),
70 desiredPresentTime(desiredPresentTime),
71 isAutoTimestamp(isAutoTimestamp),
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000072 uncacheBufferIds(std::move(uncacheBufferIds)),
Vishnu Nair6b591152021-10-08 11:45:14 -070073 postTime(postTime),
Vishnu Nair6b591152021-10-08 11:45:14 -070074 hasListenerCallbacks(hasListenerCallbacks),
75 listenerCallbacks(listenerCallbacks),
76 originPid(originPid),
77 originUid(originUid),
Pablo Gamito23780be2023-04-18 08:30:00 +000078 id(transactionId),
79 mergedTransactionIds(std::move(mergedTransactionIds)) {}
Vishnu Nair6b591152021-10-08 11:45:14 -070080
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070081 // Invokes `void(const layer_state_t&)` visitor for matching layers.
82 template <typename Visitor>
83 void traverseStatesWithBuffers(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000084 for (const auto& state : states) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070085 if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000086 visitor(state.state);
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070087 }
88 }
89 }
Vishnu Nair6b591152021-10-08 11:45:14 -070090
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070091 template <typename Visitor>
Vishnu Nair7be27602024-03-28 20:27:09 -070092 void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) NO_THREAD_SAFETY_ANALYSIS {
liulijuneb489f62022-10-17 22:02:14 +080093 for (auto state = states.begin(); state != states.end();) {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070094 if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) {
Vishnu Nair4d9cef92023-06-24 22:34:41 +000095 int result = visitor(*state);
liulijuneb489f62022-10-17 22:02:14 +080096 if (result == STOP_TRAVERSAL) return;
97 if (result == DELETE_AND_CONTINUE_TRAVERSAL) {
98 state = states.erase(state);
99 continue;
100 }
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700101 }
liulijuneb489f62022-10-17 22:02:14 +0800102 state++;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -0700103 }
104 }
105
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700106 // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical
107 // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be
108 // able to setFrameRate once, rather than for each transaction.
109 bool isFrameActive() const {
110 if (!displays.empty()) return true;
111
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000112 for (const auto& state : states) {
Ady Abrahamceb72e82023-01-17 17:40:21 -0800113 const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged;
Ady Abraham7d1e9ce2024-05-17 14:51:24 -0700114 if (FlagManager::getInstance().vrr_bugfix_24q4()) {
115 const bool frameRateIsNoVote = frameRateChanged &&
116 state.state.frameRateCompatibility == ANATIVEWINDOW_FRAME_RATE_NO_VOTE;
117 const bool frameRateCategoryChanged =
118 state.state.what & layer_state_t::eFrameRateCategoryChanged;
119 const bool frameRateCategoryIsNoPreference = frameRateCategoryChanged &&
120 state.state.frameRateCategory ==
121 ANATIVEWINDOW_FRAME_RATE_CATEGORY_NO_PREFERENCE;
122 if (!frameRateIsNoVote && !frameRateCategoryIsNoPreference) {
123 return true;
124 }
125 } else {
126 if (!frameRateChanged ||
127 state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) {
128 return true;
129 }
Dominik Laskowski1f6fc702022-03-21 08:34:50 -0700130 }
131 }
132
133 return false;
134 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700135
136 FrameTimelineInfo frameTimelineInfo;
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000137 std::vector<ResolvedComposerState> states;
Vishnu Nair6b591152021-10-08 11:45:14 -0700138 Vector<DisplayState> displays;
139 uint32_t flags;
140 sp<IBinder> applyToken;
141 InputWindowCommands inputWindowCommands;
142 int64_t desiredPresentTime;
143 bool isAutoTimestamp;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000144 std::vector<uint64_t> uncacheBufferIds;
Vishnu Nair6b591152021-10-08 11:45:14 -0700145 int64_t postTime;
Vishnu Nair6b591152021-10-08 11:45:14 -0700146 bool hasListenerCallbacks;
147 std::vector<ListenerCallbacks> listenerCallbacks;
148 int originPid;
149 int originUid;
150 uint64_t id;
Robert Carr4c1b6462021-12-21 10:30:50 -0800151 bool sentFenceTimeoutWarning = false;
Pablo Gamito23780be2023-04-18 08:30:00 +0000152 std::vector<uint64_t> mergedTransactionIds;
Vishnu Nair734f2882024-12-19 17:04:57 -0800153 ftl::Flags<adpf::Workload> workloadHint;
Vishnu Nair6b591152021-10-08 11:45:14 -0700154};
155
Vishnu Nair6b591152021-10-08 11:45:14 -0700156} // namespace android