Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 1 | /* |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 2 | * Copyright 2021 The Android Open Source Project |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 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 | |
| 17 | #pragma once |
| 18 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 19 | #include <memory> |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 20 | #include <vector> |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 21 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 22 | #include "renderengine/ExternalTexture.h" |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 23 | |
Vishnu Nair | 734f288 | 2024-12-19 17:04:57 -0800 | [diff] [blame^] | 24 | #include <PowerAdvisor/Workload.h> |
Ady Abraham | 7d1e9ce | 2024-05-17 14:51:24 -0700 | [diff] [blame] | 25 | #include <common/FlagManager.h> |
Vishnu Nair | 734f288 | 2024-12-19 17:04:57 -0800 | [diff] [blame^] | 26 | #include <ftl/flags.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 27 | #include <gui/LayerState.h> |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 28 | #include <system/window.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 31 | |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 32 | enum TraverseBuffersReturnValues { |
| 33 | CONTINUE_TRAVERSAL, |
| 34 | STOP_TRAVERSAL, |
| 35 | DELETE_AND_CONTINUE_TRAVERSAL, |
| 36 | }; |
| 37 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 38 | // Extends the client side composer state by resolving buffer. |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 39 | class ResolvedComposerState : public ComposerState { |
| 40 | public: |
| 41 | ResolvedComposerState() = default; |
| 42 | ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); } |
| 43 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 44 | 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 Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
Vishnu Nair | 3f0c723 | 2024-12-17 15:57:50 -0800 | [diff] [blame] | 50 | struct QueuedTransactionState { |
| 51 | QueuedTransactionState() = default; |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 52 | |
Vishnu Nair | 3f0c723 | 2024-12-17 15:57:50 -0800 | [diff] [blame] | 53 | 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 Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 64 | : frameTimelineInfo(frameTimelineInfo), |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 65 | states(std::move(composerStates)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 66 | displays(displayStates), |
| 67 | flags(transactionFlags), |
| 68 | applyToken(applyToken), |
| 69 | inputWindowCommands(inputWindowCommands), |
| 70 | desiredPresentTime(desiredPresentTime), |
| 71 | isAutoTimestamp(isAutoTimestamp), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 72 | uncacheBufferIds(std::move(uncacheBufferIds)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 73 | postTime(postTime), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 74 | hasListenerCallbacks(hasListenerCallbacks), |
| 75 | listenerCallbacks(listenerCallbacks), |
| 76 | originPid(originPid), |
| 77 | originUid(originUid), |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 78 | id(transactionId), |
| 79 | mergedTransactionIds(std::move(mergedTransactionIds)) {} |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 80 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 81 | // Invokes `void(const layer_state_t&)` visitor for matching layers. |
| 82 | template <typename Visitor> |
| 83 | void traverseStatesWithBuffers(Visitor&& visitor) const { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 84 | for (const auto& state : states) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 85 | if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 86 | visitor(state.state); |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 90 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 91 | template <typename Visitor> |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 92 | void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) NO_THREAD_SAFETY_ANALYSIS { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 93 | for (auto state = states.begin(); state != states.end();) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 94 | if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 95 | int result = visitor(*state); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 96 | if (result == STOP_TRAVERSAL) return; |
| 97 | if (result == DELETE_AND_CONTINUE_TRAVERSAL) { |
| 98 | state = states.erase(state); |
| 99 | continue; |
| 100 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 101 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 102 | state++; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 106 | // 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 Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 112 | for (const auto& state : states) { |
Ady Abraham | ceb72e8 | 2023-01-17 17:40:21 -0800 | [diff] [blame] | 113 | const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged; |
Ady Abraham | 7d1e9ce | 2024-05-17 14:51:24 -0700 | [diff] [blame] | 114 | 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 Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | return false; |
| 134 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 135 | |
| 136 | FrameTimelineInfo frameTimelineInfo; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 137 | std::vector<ResolvedComposerState> states; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 138 | Vector<DisplayState> displays; |
| 139 | uint32_t flags; |
| 140 | sp<IBinder> applyToken; |
| 141 | InputWindowCommands inputWindowCommands; |
| 142 | int64_t desiredPresentTime; |
| 143 | bool isAutoTimestamp; |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 144 | std::vector<uint64_t> uncacheBufferIds; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 145 | int64_t postTime; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 146 | bool hasListenerCallbacks; |
| 147 | std::vector<ListenerCallbacks> listenerCallbacks; |
| 148 | int originPid; |
| 149 | int originUid; |
| 150 | uint64_t id; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 151 | bool sentFenceTimeoutWarning = false; |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 152 | std::vector<uint64_t> mergedTransactionIds; |
Vishnu Nair | 734f288 | 2024-12-19 17:04:57 -0800 | [diff] [blame^] | 153 | ftl::Flags<adpf::Workload> workloadHint; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 156 | } // namespace android |