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