blob: 178ddbbe79cf9b440a976793db3a4f8e568fa7fe [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;
Ady Abraham461296a2022-01-21 11:11:31 -080046 std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1;
Marissa Wall5a68a772018-12-22 17:43:42 -080047 nsecs_t latchTime = -1;
Vishnu Nair71fcf912022-10-18 09:14:20 -070048 std::optional<uint32_t> transformHint = std::nullopt;
Ady Abraham899dcdb2021-06-15 16:56:21 -070049 uint32_t currentMaxAcquiredBufferCount = 0;
Valerie Hau871d6352020-01-29 08:44:02 -080050 std::shared_ptr<FenceTime> gpuCompositionDoneFence{FenceTime::NO_FENCE};
51 CompositorTiming compositorTiming;
52 nsecs_t refreshStartTime = 0;
53 nsecs_t dequeueReadyTime = 0;
54 uint64_t frameNumber = 0;
Alec Mouri21d94322023-10-17 19:51:39 +000055 uint64_t previousFrameNumber = 0;
Vishnu Nair4ba0c2e2021-06-24 11:27:17 -070056 ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
Patrick Williams7c9fa272024-08-30 12:38:43 +000057 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel;
Marissa Walle2ffb422018-10-12 11:33:52 -070058};
59
Robert Carr9a803c32021-01-14 16:57:58 -080060class TransactionCallbackInvoker {
Marissa Walle2ffb422018-10-12 11:33:52 -070061public:
Pascal Mütschardd56514e2024-05-24 17:37:13 +020062 status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles);
Robert Carr3d1047b2021-09-20 18:22:32 -070063 status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070064 std::deque<sp<CallbackHandle>>& outRemainingHandles);
Marissa Walle2ffb422018-10-12 11:33:52 -070065
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000066 void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070067
Dominik Laskowski8792c112022-07-12 09:03:39 -070068 void addPresentFence(sp<Fence>);
Marissa Wallfda30bb2018-10-12 11:34:28 -070069
Vishnu Naircd52e2d2021-10-18 08:42:46 -070070 void sendCallbacks(bool onCommitOnly);
Robert Carr3d1047b2021-09-20 18:22:32 -070071 void clearCompletedTransactions() {
72 mCompletedTransactions.clear();
73 }
Marissa Walld600d572019-03-26 15:38:50 -070074
Pascal Mütschardd56514e2024-05-24 17:37:13 +020075 status_t addCallbackHandle(const sp<CallbackHandle>& handle);
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000076
Robert Carr3d1047b2021-09-20 18:22:32 -070077private:
Vishnu Naircd52e2d2021-10-18 08:42:46 -070078 status_t findOrCreateTransactionStats(const sp<IBinder>& listener,
79 const std::vector<CallbackId>& callbackIds,
80 TransactionStats** outTransactionStats);
Marissa Wallefb71af2019-06-27 14:45:53 -070081
Valerie Hau5de3ad22019-08-20 07:47:43 -070082 std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash>
Robert Carr3d1047b2021-09-20 18:22:32 -070083 mCompletedTransactions;
Marissa Walle2ffb422018-10-12 11:33:52 -070084
Patrick Williams7c9fa272024-08-30 12:38:43 +000085 struct BufferRelease {
Patrick Williamsbb504472024-10-25 13:20:32 -050086 std::string layerName;
Patrick Williams7c9fa272024-08-30 12:38:43 +000087 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