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 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 26 | #include <gui/LayerState.h> |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 27 | #include <system/window.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 30 | |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 31 | enum TraverseBuffersReturnValues { |
| 32 | CONTINUE_TRAVERSAL, |
| 33 | STOP_TRAVERSAL, |
| 34 | DELETE_AND_CONTINUE_TRAVERSAL, |
| 35 | }; |
| 36 | |
Brian Lindahl | 439afad | 2022-11-14 11:16:55 -0700 | [diff] [blame] | 37 | // Extends the client side composer state by resolving buffer. |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 38 | class ResolvedComposerState : public ComposerState { |
| 39 | public: |
| 40 | ResolvedComposerState() = default; |
| 41 | ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); } |
| 42 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 43 | uint32_t layerId = UNASSIGNED_LAYER_ID; |
| 44 | uint32_t parentId = UNASSIGNED_LAYER_ID; |
| 45 | uint32_t relativeParentId = UNASSIGNED_LAYER_ID; |
| 46 | uint32_t touchCropId = UNASSIGNED_LAYER_ID; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 49 | struct TransactionState { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 50 | TransactionState() = default; |
| 51 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 52 | TransactionState(const FrameTimelineInfo& frameTimelineInfo, |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 53 | std::vector<ResolvedComposerState>& composerStates, |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 54 | const Vector<DisplayState>& displayStates, uint32_t transactionFlags, |
| 55 | const sp<IBinder>& applyToken, const InputWindowCommands& inputWindowCommands, |
| 56 | int64_t desiredPresentTime, bool isAutoTimestamp, |
Chavi Weingarten | c78f53c | 2023-04-14 18:50:53 +0000 | [diff] [blame^] | 57 | std::vector<uint64_t> uncacheBufferIds, int64_t postTime, |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 58 | bool hasListenerCallbacks, std::vector<ListenerCallbacks> listenerCallbacks, |
| 59 | int originPid, int originUid, uint64_t transactionId) |
| 60 | : frameTimelineInfo(frameTimelineInfo), |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 61 | states(std::move(composerStates)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 62 | displays(displayStates), |
| 63 | flags(transactionFlags), |
| 64 | applyToken(applyToken), |
| 65 | inputWindowCommands(inputWindowCommands), |
| 66 | desiredPresentTime(desiredPresentTime), |
| 67 | isAutoTimestamp(isAutoTimestamp), |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 68 | uncacheBufferIds(std::move(uncacheBufferIds)), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 69 | postTime(postTime), |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 70 | hasListenerCallbacks(hasListenerCallbacks), |
| 71 | listenerCallbacks(listenerCallbacks), |
| 72 | originPid(originPid), |
| 73 | originUid(originUid), |
| 74 | id(transactionId) {} |
| 75 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 76 | // Invokes `void(const layer_state_t&)` visitor for matching layers. |
| 77 | template <typename Visitor> |
| 78 | void traverseStatesWithBuffers(Visitor&& visitor) const { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 79 | for (const auto& state : states) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 80 | if (state.state.hasBufferChanges() && state.externalTexture && state.state.surface) { |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 81 | visitor(state.state); |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 85 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 86 | template <typename Visitor> |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 87 | void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) { |
| 88 | for (auto state = states.begin(); state != states.end();) { |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 89 | if (state->state.hasBufferChanges() && state->externalTexture && state->state.surface) { |
Chavi Weingarten | c8bcb68 | 2023-03-06 22:20:42 +0000 | [diff] [blame] | 90 | int result = visitor(state->state, state->externalTexture); |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 91 | if (result == STOP_TRAVERSAL) return; |
| 92 | if (result == DELETE_AND_CONTINUE_TRAVERSAL) { |
| 93 | state = states.erase(state); |
| 94 | continue; |
| 95 | } |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 96 | } |
liulijun | eb489f6 | 2022-10-17 22:02:14 +0800 | [diff] [blame] | 97 | state++; |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 101 | // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical |
| 102 | // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be |
| 103 | // able to setFrameRate once, rather than for each transaction. |
| 104 | bool isFrameActive() const { |
| 105 | if (!displays.empty()) return true; |
| 106 | |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 107 | for (const auto& state : states) { |
Ady Abraham | ceb72e8 | 2023-01-17 17:40:21 -0800 | [diff] [blame] | 108 | const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged; |
| 109 | if (!frameRateChanged || |
| 110 | state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | return false; |
| 116 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 117 | |
| 118 | FrameTimelineInfo frameTimelineInfo; |
Vishnu Nair | 40fff5c | 2022-11-04 02:46:28 +0000 | [diff] [blame] | 119 | std::vector<ResolvedComposerState> states; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 120 | Vector<DisplayState> displays; |
| 121 | uint32_t flags; |
| 122 | sp<IBinder> applyToken; |
| 123 | InputWindowCommands inputWindowCommands; |
| 124 | int64_t desiredPresentTime; |
| 125 | bool isAutoTimestamp; |
Patrick Williams | 6c6dd3b | 2023-02-13 22:53:06 +0000 | [diff] [blame] | 126 | std::vector<uint64_t> uncacheBufferIds; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 127 | int64_t postTime; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 128 | bool hasListenerCallbacks; |
| 129 | std::vector<ListenerCallbacks> listenerCallbacks; |
| 130 | int originPid; |
| 131 | int originUid; |
| 132 | uint64_t id; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 133 | bool sentFenceTimeoutWarning = false; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 134 | }; |
| 135 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 136 | } // namespace android |