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 <condition_variable> |
| 20 | #include <memory> |
| 21 | #include <mutex> |
| 22 | #include <vector> |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 23 | #include "FrontEnd/LayerCreationArgs.h" |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 24 | #include "renderengine/ExternalTexture.h" |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 25 | |
Ady Abraham | 7d1e9ce | 2024-05-17 14:51:24 -0700 | [diff] [blame] | 26 | #include <common/FlagManager.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 | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 50 | struct TransactionState { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 51 | TransactionState() = default; |
| 52 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 53 | TransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 54 | std::vector<ResolvedComposerState>& composerStates, |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 55 | const Vector<DisplayState>& displayStates, uint32_t transactionFlags, |
| 56 | const sp<IBinder>& applyToken, const InputWindowCommands& inputWindowCommands, |
| 57 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame] | 58 | std::vector<uint64_t> uncacheBufferIds, int64_t postTime, |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 59 | bool hasListenerCallbacks, std::vector<ListenerCallbacks> listenerCallbacks, |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 60 | int originPid, int originUid, uint64_t transactionId, |
| 61 | std::vector<uint64_t> mergedTransactionIds) |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 62 | : frameTimelineInfo(frameTimelineInfo), |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 63 | states(std::move(composerStates)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 64 | displays(displayStates), |
| 65 | flags(transactionFlags), |
| 66 | applyToken(applyToken), |
| 67 | inputWindowCommands(inputWindowCommands), |
| 68 | desiredPresentTime(desiredPresentTime), |
| 69 | isAutoTimestamp(isAutoTimestamp), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 70 | uncacheBufferIds(std::move(uncacheBufferIds)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 71 | postTime(postTime), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 72 | hasListenerCallbacks(hasListenerCallbacks), |
| 73 | listenerCallbacks(listenerCallbacks), |
| 74 | originPid(originPid), |
| 75 | originUid(originUid), |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 76 | id(transactionId), |
| 77 | mergedTransactionIds(std::move(mergedTransactionIds)) {} |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 78 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 79 | // Invokes `void(const layer_state_t&)` visitor for matching layers. |
| 80 | template <typename Visitor> |
| 81 | void traverseStatesWithBuffers(Visitor&& visitor) const { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 82 | for (const auto& state : states) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 83 | if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 84 | visitor(state.state); |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 88 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 89 | template <typename Visitor> |
Vishnu Nair | 7be2760 | 2024-03-28 20:27:09 -0700 | [diff] [blame] | 90 | void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) NO_THREAD_SAFETY_ANALYSIS { |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 91 | for (auto state = states.begin(); state != states.end();) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 92 | if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) { |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 93 | int result = visitor(*state); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 94 | if (result == STOP_TRAVERSAL) return; |
| 95 | if (result == DELETE_AND_CONTINUE_TRAVERSAL) { |
| 96 | state = states.erase(state); |
| 97 | continue; |
| 98 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 99 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 100 | state++; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 104 | // 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 Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 110 | for (const auto& state : states) { |
Ady Abraham | ceb72e8 | 2023-01-17 17:40:21 -0800 | [diff] [blame] | 111 | const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged; |
Ady Abraham | 7d1e9ce | 2024-05-17 14:51:24 -0700 | [diff] [blame] | 112 | 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 Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
| 131 | return false; |
| 132 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 133 | |
| 134 | FrameTimelineInfo frameTimelineInfo; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 135 | std::vector<ResolvedComposerState> states; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 136 | Vector<DisplayState> displays; |
| 137 | uint32_t flags; |
| 138 | sp<IBinder> applyToken; |
| 139 | InputWindowCommands inputWindowCommands; |
| 140 | int64_t desiredPresentTime; |
| 141 | bool isAutoTimestamp; |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 142 | std::vector<uint64_t> uncacheBufferIds; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 143 | int64_t postTime; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 144 | bool hasListenerCallbacks; |
| 145 | std::vector<ListenerCallbacks> listenerCallbacks; |
| 146 | int originPid; |
| 147 | int originUid; |
| 148 | uint64_t id; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 149 | bool sentFenceTimeoutWarning = false; |
Pablo Gamito | 23780be | 2023-04-18 08:30:00 +0000 | [diff] [blame] | 150 | std::vector<uint64_t> mergedTransactionIds; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 153 | } // namespace android |