blob: 34f6ffc5da92235934bc7bfedbc6cd2037453f12 [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>
Alec Mouridf868ba2025-02-25 16:08:19 -080028#include <renderengine/ExternalTexture.h>
Marissa Wallfda30bb2018-10-12 11:34:28 -070029#include <ui/Fence.h>
Patrick Williams2e9748f2022-08-09 22:48:18 +000030#include <ui/FenceResult.h>
Marissa Walle2ffb422018-10-12 11:33:52 -070031
32namespace android {
33
34class CallbackHandle : public RefBase {
35public:
Valerie Hau5de3ad22019-08-20 07:47:43 -070036 CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids,
37 const sp<IBinder>& sc);
Marissa Walle2ffb422018-10-12 11:33:52 -070038
Valerie Hau5de3ad22019-08-20 07:47:43 -070039 sp<IBinder> listener;
Marissa Walle2ffb422018-10-12 11:33:52 -070040 std::vector<CallbackId> callbackIds;
Marissa Wall0e24a832019-07-10 15:32:50 -070041 wp<IBinder> surfaceControl;
Marissa Wallfda30bb2018-10-12 11:34:28 -070042
43 bool releasePreviousBuffer = false;
Sally Qi59a9f502021-10-12 18:53:23 +000044 std::string name;
Marissa Wall5a68a772018-12-22 17:43:42 -080045 sp<Fence> previousReleaseFence;
Melody Hsu793f8362024-01-08 20:00:35 +000046 std::vector<ftl::Future<FenceResult>> previousReleaseFences;
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;
Alec Mouridf868ba2025-02-25 16:08:19 -080059 std::weak_ptr<renderengine::ExternalTexture> previousBuffer;
Marissa Walle2ffb422018-10-12 11:33:52 -070060};
61
Robert Carr9a803c32021-01-14 16:57:58 -080062class TransactionCallbackInvoker {
Marissa Walle2ffb422018-10-12 11:33:52 -070063public:
Pascal Mütschardd56514e2024-05-24 17:37:13 +020064 status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles);
Robert Carr3d1047b2021-09-20 18:22:32 -070065 status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
Vishnu Nairfc46c1e2021-04-21 08:31:32 -070066 std::deque<sp<CallbackHandle>>& outRemainingHandles);
Marissa Walle2ffb422018-10-12 11:33:52 -070067
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000068 void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks);
Marissa Wall3dad52d2019-03-22 14:03:19 -070069
Dominik Laskowski8792c112022-07-12 09:03:39 -070070 void addPresentFence(sp<Fence>);
Marissa Wallfda30bb2018-10-12 11:34:28 -070071
Vishnu Naircd52e2d2021-10-18 08:42:46 -070072 void sendCallbacks(bool onCommitOnly);
Robert Carr3d1047b2021-09-20 18:22:32 -070073 void clearCompletedTransactions() {
74 mCompletedTransactions.clear();
75 }
Marissa Walld600d572019-03-26 15:38:50 -070076
Pascal Mütschardd56514e2024-05-24 17:37:13 +020077 status_t addCallbackHandle(const sp<CallbackHandle>& handle);
Jiakai Zhanga5505cb2021-11-09 11:46:30 +000078
Robert Carr3d1047b2021-09-20 18:22:32 -070079private:
Vishnu Naircd52e2d2021-10-18 08:42:46 -070080 status_t findOrCreateTransactionStats(const sp<IBinder>& listener,
81 const std::vector<CallbackId>& callbackIds,
82 TransactionStats** outTransactionStats);
Marissa Wallefb71af2019-06-27 14:45:53 -070083
Valerie Hau5de3ad22019-08-20 07:47:43 -070084 std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash>
Robert Carr3d1047b2021-09-20 18:22:32 -070085 mCompletedTransactions;
Marissa Walle2ffb422018-10-12 11:33:52 -070086
Patrick Williams7c9fa272024-08-30 12:38:43 +000087 struct BufferRelease {
Patrick Williamsbb504472024-10-25 13:20:32 -050088 std::string layerName;
Patrick Williams7c9fa272024-08-30 12:38:43 +000089 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> channel;
90 ReleaseCallbackId callbackId;
91 sp<Fence> fence;
92 uint32_t currentMaxAcquiredBufferCount;
93 };
94 std::vector<BufferRelease> mBufferReleases;
95
Robert Carr3d1047b2021-09-20 18:22:32 -070096 sp<Fence> mPresentFence;
Marissa Walle2ffb422018-10-12 11:33:52 -070097};
98
99} // namespace android