blob: 7853a9f359b3744dffe147dc86c592e31bf08720 [file] [log] [blame]
Marissa Walle2ffb422018-10-12 11:33:52 -07001/*
2 * Copyright 2018 The Android Open Source Project
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
Satish Yalla4aface12024-08-30 09:25:35 +000019#include <condition_variable>
Marissa Walle2ffb422018-10-12 11:33:52 -070020#include <deque>
Satish Yalla4aface12024-08-30 09:25:35 +000021#include <mutex>
Vishnu Nair71fcf912022-10-18 09:14:20 -070022#include <optional>
Satish Yalla4aface12024-08-30 09:25:35 +000023#include <queue>
24#include <thread>
Marissa Walle2ffb422018-10-12 11:33:52 -070025#include <unordered_map>
Satish Yalla4aface12024-08-30 09:25:35 +000026#include <unordered_set>
Marissa Walle2ffb422018-10-12 11:33:52 -070027
28#include <android-base/thread_annotations.h>
Marissa Walle2ffb422018-10-12 11:33:52 -070029#include <binder/IBinder.h>
Huihong Luoffee3bc2023-01-17 16:14:35 +000030#include <ftl/future.h>
31#include <gui/ITransactionCompletedListener.h>
Marissa Wallfda30bb2018-10-12 11:34:28 -070032#include <ui/Fence.h>
Patrick Williams2e9748f2022-08-09 22:48:18 +000033#include <ui/FenceResult.h>
Marissa Walle2ffb422018-10-12 11:33:52 -070034
35namespace android {
36
37class CallbackHandle : public RefBase {
38public:
Valerie Hau5de3ad22019-08-20 07:47:43 -070039 CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids,
40 const sp<IBinder>& sc);
Marissa Walle2ffb422018-10-12 11:33:52 -070041
Valerie Hau5de3ad22019-08-20 07:47:43 -070042 sp<IBinder> listener;
Marissa Walle2ffb422018-10-12 11:33:52 -070043 std::vector<CallbackId> callbackIds;
Marissa Wall0e24a832019-07-10 15:32:50 -070044 wp<IBinder> surfaceControl;
Marissa Wallfda30bb2018-10-12 11:34:28 -070045
46 bool releasePreviousBuffer = false;
Sally Qi59a9f502021-10-12 18:53:23 +000047 std::string name;
Marissa Wall5a68a772018-12-22 17:43:42 -080048 sp<Fence> previousReleaseFence;
Melody Hsu793f8362024-01-08 20:00:35 +000049 std::vector<ftl::Future<FenceResult>> previousReleaseFences;
50 std::vector<ftl::SharedFuture<FenceResult>> previousSharedReleaseFences;
Ady Abraham461296a2022-01-21 11:11:31 -080051 std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1;
Marissa Wall5a68a772018-12-22 17:43:42 -080052 nsecs_t latchTime = -1;
Vishnu Nair71fcf912022-10-18 09:14:20 -070053 std::optional<uint32_t> transformHint = std::nullopt;
Ady Abraham899dcdb2021-06-15 16:56:21 -070054 uint32_t currentMaxAcquiredBufferCount = 0;
Valerie Hau871d6352020-01-29 08:44:02 -080055 std::shared_ptr<FenceTime> gpuCompositionDoneFence{FenceTime::NO_FENCE};
56 CompositorTiming compositorTiming;
57 nsecs_t refreshStartTime = 0;
58 nsecs_t dequeueReadyTime = 0;
59 uint64_t frameNumber = 0;
Alec Mouri21d94322023-10-17 19:51:39 +000060 uint64_t previousFrameNumber = 0;
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -070061 ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
Marissa Walle2ffb422018-10-12 11:33:52 -070062};
63
Robert Carr9a803c32021-01-14 16:57:58 -080064class TransactionCallbackInvoker {
Marissa Walle2ffb422018-10-12 11:33:52 -070065public:
Pascal Mütschardd56514e2024-05-24 17:37:13 +020066 status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles);
Robert Carr3d1047b2021-09-20 18:22:32 -070067 status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070068 std::deque<sp<CallbackHandle>>& outRemainingHandles);
Marissa Walle2ffb422018-10-12 11:33:52 -070069
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000070 void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070071
Dominik Laskowski8792c112022-07-12 09:03:39 -070072 void addPresentFence(sp<Fence>);
Marissa Wallfda30bb2018-10-12 11:34:28 -070073
Vishnu Naircd52e2d2021-10-18 08:42:46 -070074 void sendCallbacks(bool onCommitOnly);
Robert Carr3d1047b2021-09-20 18:22:32 -070075 void clearCompletedTransactions() {
76 mCompletedTransactions.clear();
77 }
Marissa Walld600d572019-03-26 15:38:50 -070078
Pascal Mütschardd56514e2024-05-24 17:37:13 +020079 status_t addCallbackHandle(const sp<CallbackHandle>& handle);
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000080
Robert Carr3d1047b2021-09-20 18:22:32 -070081private:
Vishnu Naircd52e2d2021-10-18 08:42:46 -070082 status_t findOrCreateTransactionStats(const sp<IBinder>& listener,
83 const std::vector<CallbackId>& callbackIds,
84 TransactionStats** outTransactionStats);
Marissa Wallefb71af2019-06-27 14:45:53 -070085
Valerie Hau5de3ad22019-08-20 07:47:43 -070086 std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash>
Robert Carr3d1047b2021-09-20 18:22:32 -070087 mCompletedTransactions;
Marissa Walle2ffb422018-10-12 11:33:52 -070088
Robert Carr3d1047b2021-09-20 18:22:32 -070089 sp<Fence> mPresentFence;
Marissa Walle2ffb422018-10-12 11:33:52 -070090};
91
92} // namespace android