blob: 7bde2c1e23f451eecf8df6aa6e2f7fb3a554dcc8 [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
Vishnu Nair40fff5c2022-11-04 02:46:28 +000030// Extends the client side composer state by resolving buffer cache ids.
31class ResolvedComposerState : public ComposerState {
32public:
33 ResolvedComposerState() = default;
34 ResolvedComposerState(ComposerState&& source) { state = std::move(source.state); }
35 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
Vishnu Nairc6086dd2022-11-04 04:39:35 +000036 int hwcBufferSlot = 0;
Vishnu Nair40fff5c2022-11-04 02:46:28 +000037};
38
Vishnu Nair6b591152021-10-08 11:45:14 -070039struct TransactionState {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070040 TransactionState() = default;
41
Vishnu Nair6b591152021-10-08 11:45:14 -070042 TransactionState(const FrameTimelineInfo& frameTimelineInfo,
Vishnu Nair40fff5c2022-11-04 02:46:28 +000043 std::vector<ResolvedComposerState>& composerStates,
Vishnu Nair6b591152021-10-08 11:45:14 -070044 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 Nair40fff5c2022-11-04 02:46:28 +000051 states(std::move(composerStates)),
Vishnu Nair6b591152021-10-08 11:45:14 -070052 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 Laskowski1f6fc702022-03-21 08:34:50 -070067 // Invokes `void(const layer_state_t&)` visitor for matching layers.
68 template <typename Visitor>
69 void traverseStatesWithBuffers(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000070 for (const auto& state : states) {
71 if (state.state.hasBufferChanges() && state.state.hasValidBuffer() &&
72 state.state.surface) {
73 visitor(state.state);
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070074 }
75 }
76 }
Vishnu Nair6b591152021-10-08 11:45:14 -070077
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070078 template <typename Visitor>
79 void traverseStatesWithBuffersWhileTrue(Visitor&& visitor) const {
Vishnu Nair40fff5c2022-11-04 02:46:28 +000080 for (const auto& state : states) {
81 if (state.state.hasBufferChanges() && state.state.hasValidBuffer() &&
82 state.state.surface) {
83 if (!visitor(state.state)) return;
Vishnu Nair59f6d2d2022-10-05 16:59:56 -070084 }
85 }
86 }
87
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070088 // 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 Nair40fff5c2022-11-04 02:46:28 +000094 for (const auto& state : states) {
95 if (state.state.frameRateCompatibility != ANATIVEWINDOW_FRAME_RATE_NO_VOTE) {
Dominik Laskowski1f6fc702022-03-21 08:34:50 -070096 return true;
97 }
98 }
99
100 return false;
101 }
Vishnu Nair6b591152021-10-08 11:45:14 -0700102
103 FrameTimelineInfo frameTimelineInfo;
Vishnu Nair40fff5c2022-11-04 02:46:28 +0000104 std::vector<ResolvedComposerState> states;
Vishnu Nair6b591152021-10-08 11:45:14 -0700105 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 Carr4c1b6462021-12-21 10:30:50 -0800119 bool sentFenceTimeoutWarning = false;
Vishnu Nair6b591152021-10-08 11:45:14 -0700120};
121
Vishnu Nair6b591152021-10-08 11:45:14 -0700122} // namespace android