blob: 5025c4935cbb9abdb13cb778e924c1419ba8f234 [file] [log] [blame]
Vishnu Nair6b591152021-10-08 11:45:14 -07001/*
Dominik Laskowski1f6fc702022-03-21 08:34:50 -07002 * Copyright 2021 The Android Open Source Project
Vishnu Nair6b591152021-10-08 11:45:14 -07003 *
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 Laskowski1f6fc702022-03-21 08:34:50 -070019#include <condition_variable>
20#include <memory>
21#include <mutex>
22#include <vector>
Vishnu Nair40fff5c2022-11-04 02:46:28 +000023#include "renderengine/ExternalTexture.h"
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070024
Vishnu Nair6b591152021-10-08 11:45:14 -070025#include <gui/LayerState.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070026#include <system/window.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070027
28namespace android {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070029
Brian Lindahl439afad2022-11-14 11:16:55 -070030// Extends the client side composer state by resolving buffer.
Vishnu Nair40fff5c2022-11-04 02:46:28 +000031class ResolvedComposerState : public ComposerState {
32public:
33 ResolvedComposerState() = default;
34 ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); }
35 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
36};
37
Vishnu Nair6b591152021-10-08 11:45:14 -070038struct TransactionState {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070039 TransactionState() = default;
40
Vishnu Nair6b591152021-10-08 11:45:14 -070041 TransactionState(const FrameTimelineInfo& frameTimelineInfo,
Vishnu Nair40fff5c2022-11-04 02:46:28 +000042 std::vector<ResolvedComposerState>& composerStates,
Vishnu Nair6b591152021-10-08 11:45:14 -070043 const Vector<DisplayState>& displayStates, uint32_t transactionFlags,
44 const sp<IBinder>& applyToken, const InputWindowCommands& inputWindowCommands,
45 int64_t desiredPresentTime, bool isAutoTimestamp,
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000046 std::vector<uint64_t> uncacheBufferIds, int64_t postTime, uint32_t permissions,
Vishnu Nair6b591152021-10-08 11:45:14 -070047 bool hasListenerCallbacks, std::vector<ListenerCallbacks> listenerCallbacks,
48 int originPid, int originUid, uint64_t transactionId)
49 : frameTimelineInfo(frameTimelineInfo),
Vishnu Nair40fff5c2022-11-04 02:46:28 +000050 states(std::move(composerStates)),
Vishnu Nair6b591152021-10-08 11:45:14 -070051 displays(displayStates),
52 flags(transactionFlags),
53 applyToken(applyToken),
54 inputWindowCommands(inputWindowCommands),
55 desiredPresentTime(desiredPresentTime),
56 isAutoTimestamp(isAutoTimestamp),
Patrick Williams6c6dd3b2023-02-13 22:53:06 +000057 uncacheBufferIds(std::move(uncacheBufferIds)),
Vishnu Nair6b591152021-10-08 11:45:14 -070058 postTime(postTime),
59 permissions(permissions),
60 hasListenerCallbacks(hasListenerCallbacks),
61 listenerCallbacks(listenerCallbacks),
62 originPid(originPid),
63 originUid(originUid),
64 id(transactionId) {}
65
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070066 // Invokes `void(const layer_state_t&)` visitor for matching layers.
67 template <typename Visitor>
68 void traverseStatesWithBuffers(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000069 for (const auto& state : states) {
70 if (state.state.hasBufferChanges() && state.state.hasValidBuffer() &&
71 state.state.surface) {
72 visitor(state.state);
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070073 }
74 }
75 }
Vishnu Nair6b591152021-10-08 11:45:14 -070076
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070077 template <typename Visitor>
78 void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000079 for (const auto& state : states) {
80 if (state.state.hasBufferChanges() && state.state.hasValidBuffer() &&
81 state.state.surface) {
82 if (!visitor(state.state)) return;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070083 }
84 }
85 }
86
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070087 // TODO(b/185535769): Remove FrameHint. Instead, reset the idle timer (of the relevant physical
88 // display) on the main thread if commit leads to composite. Then, RefreshRateOverlay should be
89 // able to setFrameRate once, rather than for each transaction.
90 bool isFrameActive() const {
91 if (!displays.empty()) return true;
92
Vishnu Nair40fff5c2022-11-04 02:46:28 +000093 for (const auto& state : states) {
Ady Abrahamceb72e82023-01-17 17:40:21 -080094 const bool frameRateChanged = state.state.what & layer_state_t::eFrameRateChanged;
95 if (!frameRateChanged ||
96 state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070097 return true;
98 }
99 }
100
101 return false;
102 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700103
104 FrameTimelineInfo frameTimelineInfo;
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000105 std::vector<ResolvedComposerState> states;
Vishnu Nair6b591152021-10-08 11:45:14 -0700106 Vector<DisplayState> displays;
107 uint32_t flags;
108 sp<IBinder> applyToken;
109 InputWindowCommands inputWindowCommands;
110 int64_t desiredPresentTime;
111 bool isAutoTimestamp;
Patrick Williams6c6dd3b2023-02-13 22:53:06 +0000112 std::vector<uint64_t> uncacheBufferIds;
Vishnu Nair6b591152021-10-08 11:45:14 -0700113 int64_t postTime;
114 uint32_t permissions;
115 bool hasListenerCallbacks;
116 std::vector<ListenerCallbacks> listenerCallbacks;
117 int originPid;
118 int originUid;
119 uint64_t id;
Robert Carr4c1b6462021-12-21 10:30:50 -0800120 bool sentFenceTimeoutWarning = false;
Vishnu Nair6b591152021-10-08 11:45:14 -0700121};
122
Vishnu Nair6b591152021-10-08 11:45:14 -0700123} // namespace android