blob: 14a74871569cbff9cee442ff6e104b325e2d38ae [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
Marissa Walle2ffb422018-10-12 11:33:52 -070019#include <deque>
Vishnu Nair71fcf912022-10-18 09:14:20 -070020#include <optional>
Marissa Walle2ffb422018-10-12 11:33:52 -070021#include <unordered_map>
22
23#include <android-base/thread_annotations.h>
Marissa Walle2ffb422018-10-12 11:33:52 -070024#include <binder/IBinder.h>
Huihong Luoffee3bc2023-01-17 16:14:35 +000025#include <ftl/future.h>
Patrick Williams7c9fa272024-08-30 12:38:43 +000026#include <gui/BufferReleaseChannel.h>
Huihong Luoffee3bc2023-01-17 16:14:35 +000027#include <gui/ITransactionCompletedListener.h>
Marissa Wallfda30bb2018-10-12 11:34:28 -070028#include <ui/Fence.h>
Patrick Williams2e9748f2022-08-09 22:48:18 +000029#include <ui/FenceResult.h>
Marissa Walle2ffb422018-10-12 11:33:52 -070030
31namespace android {
32
33class CallbackHandle : public RefBase {
34public:
Valerie Hau5de3ad22019-08-20 07:47:43 -070035 CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids,
36 const sp<IBinder>& sc);
Marissa Walle2ffb422018-10-12 11:33:52 -070037
Valerie Hau5de3ad22019-08-20 07:47:43 -070038 sp<IBinder> listener;
Marissa Walle2ffb422018-10-12 11:33:52 -070039 std::vector<CallbackId> callbackIds;
Marissa Wall0e24a832019-07-10 15:32:50 -070040 wp<IBinder> surfaceControl;
Marissa Wallfda30bb2018-10-12 11:34:28 -070041
42 bool releasePreviousBuffer = false;
Sally Qi59a9f502021-10-12 18:53:23 +000043 std::string name;
Marissa Wall5a68a772018-12-22 17:43:42 -080044 sp<Fence> previousReleaseFence;
Melody Hsu793f8362024-01-08 20:00:35 +000045 std::vector<ftl::Future<FenceResult>> previousReleaseFences;
46 std::vector<ftl::SharedFuture<FenceResult>> previousSharedReleaseFences;
Ady Abraham461296a2022-01-21 11:11:31 -080047 std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1;
Marissa Wall5a68a772018-12-22 17:43:42 -080048 nsecs_t latchTime = -1;
Vishnu Nair71fcf912022-10-18 09:14:20 -070049 std::optional<uint32_t> transformHint = std::nullopt;
Ady Abraham899dcdb2021-06-15 16:56:21 -070050 uint32_t currentMaxAcquiredBufferCount = 0;
Valerie Hau871d6352020-01-29 08:44:02 -080051 std::shared_ptr<FenceTime> gpuCompositionDoneFence{FenceTime::NO_FENCE};
52 CompositorTiming compositorTiming;
53 nsecs_t refreshStartTime = 0;
54 nsecs_t dequeueReadyTime = 0;
55 uint64_t frameNumber = 0;
Alec Mouri21d94322023-10-17 19:51:39 +000056 uint64_t previousFrameNumber = 0;
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -070057 ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
Patrick Williams7c9fa272024-08-30 12:38:43 +000058 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel;
Marissa Walle2ffb422018-10-12 11:33:52 -070059};
60
Robert Carr9a803c32021-01-14 16:57:58 -080061class TransactionCallbackInvoker {
Marissa Walle2ffb422018-10-12 11:33:52 -070062public:
Pascal Mütschardd56514e2024-05-24 17:37:13 +020063 status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles);
Robert Carr3d1047b2021-09-20 18:22:32 -070064 status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070065 std::deque<sp<CallbackHandle>>& outRemainingHandles);
Marissa Walle2ffb422018-10-12 11:33:52 -070066
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000067 void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070068
Dominik Laskowski8792c112022-07-12 09:03:39 -070069 void addPresentFence(sp<Fence>);
Marissa Wallfda30bb2018-10-12 11:34:28 -070070
Vishnu Naircd52e2d2021-10-18 08:42:46 -070071 void sendCallbacks(bool onCommitOnly);
Robert Carr3d1047b2021-09-20 18:22:32 -070072 void clearCompletedTransactions() {
73 mCompletedTransactions.clear();
74 }
Marissa Walld600d572019-03-26 15:38:50 -070075
Pascal Mütschardd56514e2024-05-24 17:37:13 +020076 status_t addCallbackHandle(const sp<CallbackHandle>& handle);
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000077
Robert Carr3d1047b2021-09-20 18:22:32 -070078private:
Vishnu Naircd52e2d2021-10-18 08:42:46 -070079 status_t findOrCreateTransactionStats(const sp<IBinder>& listener,
80 const std::vector<CallbackId>& callbackIds,
81 TransactionStats** outTransactionStats);
Marissa Wallefb71af2019-06-27 14:45:53 -070082
Valerie Hau5de3ad22019-08-20 07:47:43 -070083 std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash>
Robert Carr3d1047b2021-09-20 18:22:32 -070084 mCompletedTransactions;
Marissa Walle2ffb422018-10-12 11:33:52 -070085
Patrick Williams7c9fa272024-08-30 12:38:43 +000086 struct BufferRelease {
87 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> channel;
88 ReleaseCallbackId callbackId;
89 sp<Fence> fence;
90 uint32_t currentMaxAcquiredBufferCount;
91 };
92 std::vector<BufferRelease> mBufferReleases;
93
Robert Carr3d1047b2021-09-20 18:22:32 -070094 sp<Fence> mPresentFence;
Marissa Walle2ffb422018-10-12 11:33:52 -070095};
96
97} // namespace android