blob: 3cbfe811eacd2524e24ca0a87bdf3d2aaa9593b1 [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>
23
Vishnu Nair6b591152021-10-08 11:45:14 -070024#include <gui/LayerState.h>
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070025#include <system/window.h>
Vishnu Nair6b591152021-10-08 11:45:14 -070026
27namespace android {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070028
Vishnu Nair6b591152021-10-08 11:45:14 -070029struct TransactionState {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070030 TransactionState() = default;
31
Vishnu Nair6b591152021-10-08 11:45:14 -070032 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 Laskowski1f6fc702022-03-21 08:34:50 -070057 // 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 Nair6b591152021-10-08 11:45:14 -070066
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070067 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 Laskowski1f6fc702022-03-21 08:34:50 -070076 // 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 Nair6b591152021-10-08 11:45:14 -070090
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 Carr4c1b6462021-12-21 10:30:50 -0800107 bool sentFenceTimeoutWarning = false;
Vishnu Nair6b591152021-10-08 11:45:14 -0700108};
109
Vishnu Nair6b591152021-10-08 11:45:14 -0700110} // namespace android