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