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> |
| 23 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 24 | #include <gui/LayerState.h> |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 25 | #include <system/window.h> |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 28 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 29 | struct TransactionState { |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 30 | TransactionState() = default; |
| 31 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 32 | TransactionState(const FrameTimelineInfo& frameTimelineInfo, |
| 33 | const Vector<ComposerState>& composerStates, |
| 34 | const Vector<DisplayState>& displayStates, uint32_t transactionFlags, |
| 35 | const sp<IBinder>& applyToken, const InputWindowCommands& inputWindowCommands, |
| 36 | int64_t desiredPresentTime, bool isAutoTimestamp, |
| 37 | const client_cache_t& uncacheBuffer, int64_t postTime, uint32_t permissions, |
| 38 | bool hasListenerCallbacks, std::vector<ListenerCallbacks> listenerCallbacks, |
| 39 | int originPid, int originUid, uint64_t transactionId) |
| 40 | : frameTimelineInfo(frameTimelineInfo), |
| 41 | states(composerStates), |
| 42 | displays(displayStates), |
| 43 | flags(transactionFlags), |
| 44 | applyToken(applyToken), |
| 45 | inputWindowCommands(inputWindowCommands), |
| 46 | desiredPresentTime(desiredPresentTime), |
| 47 | isAutoTimestamp(isAutoTimestamp), |
| 48 | buffer(uncacheBuffer), |
| 49 | postTime(postTime), |
| 50 | permissions(permissions), |
| 51 | hasListenerCallbacks(hasListenerCallbacks), |
| 52 | listenerCallbacks(listenerCallbacks), |
| 53 | originPid(originPid), |
| 54 | originUid(originUid), |
| 55 | id(transactionId) {} |
| 56 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 57 | // Invokes `void(const layer_state_t&)` visitor for matching layers. |
| 58 | template <typename Visitor> |
| 59 | void traverseStatesWithBuffers(Visitor&& visitor) const { |
| 60 | for (const auto& [state] : states) { |
| 61 | if (state.hasBufferChanges() && state.hasValidBuffer() && state.surface) { |
| 62 | visitor(state); |
| 63 | } |
| 64 | } |
| 65 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 66 | |
Vishnu Nair | 59f6d2d | 2022-10-05 16:59:56 -0700 | [diff] [blame] | 67 | template <typename Visitor> |
| 68 | void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) const { |
| 69 | for (const auto& [state] : states) { |
| 70 | if (state.hasBufferChanges() && state.hasValidBuffer() && state.surface) { |
| 71 | if (!visitor(state)) return; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
Dominik Laskowski | 1f6fc70 | 2022-03-21 08:34:50 -0700 | [diff] [blame] | 76 | // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical |
| 77 | // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be |
| 78 | // able to setFrameRate once, rather than for each transaction. |
| 79 | bool isFrameActive() const { |
| 80 | if (!displays.empty()) return true; |
| 81 | |
| 82 | for (const auto& [state] : states) { |
| 83 | if (state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) { |
| 84 | return true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return false; |
| 89 | } |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 90 | |
| 91 | FrameTimelineInfo frameTimelineInfo; |
| 92 | Vector<ComposerState> states; |
| 93 | Vector<DisplayState> displays; |
| 94 | uint32_t flags; |
| 95 | sp<IBinder> applyToken; |
| 96 | InputWindowCommands inputWindowCommands; |
| 97 | int64_t desiredPresentTime; |
| 98 | bool isAutoTimestamp; |
| 99 | client_cache_t buffer; |
| 100 | int64_t postTime; |
| 101 | uint32_t permissions; |
| 102 | bool hasListenerCallbacks; |
| 103 | std::vector<ListenerCallbacks> listenerCallbacks; |
| 104 | int originPid; |
| 105 | int originUid; |
| 106 | uint64_t id; |
Robert Carr | 4c1b646 | 2021-12-21 10:30:50 -0800 | [diff] [blame] | 107 | bool sentFenceTimeoutWarning = false; |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 108 | }; |
| 109 | |
Vishnu Nair | 6b59115 | 2021-10-08 11:45:14 -0700 | [diff] [blame] | 110 | } // namespace android |