Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 1 | /* |
| 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 Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 19 | #include <deque> |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 20 | #include <optional> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 21 | #include <unordered_map> |
| 22 | |
| 23 | #include <android-base/thread_annotations.h> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 24 | #include <binder/IBinder.h> |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 25 | #include <ftl/future.h> |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 26 | #include <gui/BufferReleaseChannel.h> |
Huihong Luo | ffee3bc | 2023-01-17 16:14:35 +0000 | [diff] [blame] | 27 | #include <gui/ITransactionCompletedListener.h> |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 28 | #include <ui/Fence.h> |
Patrick Williams | 2e9748f | 2022-08-09 22:48:18 +0000 | [diff] [blame] | 29 | #include <ui/FenceResult.h> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | class CallbackHandle : public RefBase { |
| 34 | public: |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 35 | CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids, |
| 36 | const sp<IBinder>& sc); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 37 | |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 38 | sp<IBinder> listener; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 39 | std::vector<CallbackId> callbackIds; |
Marissa Wall | 0e24a83 | 2019-07-10 15:32:50 -0700 | [diff] [blame] | 40 | wp<IBinder> surfaceControl; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 41 | |
| 42 | bool releasePreviousBuffer = false; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 43 | std::string name; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 44 | sp<Fence> previousReleaseFence; |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 45 | std::vector<ftl::Future<FenceResult>> previousReleaseFences; |
Ady Abraham | 461296a | 2022-01-21 11:11:31 -0800 | [diff] [blame] | 46 | std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 47 | nsecs_t latchTime = -1; |
Vishnu Nair | 71fcf91 | 2022-10-18 09:14:20 -0700 | [diff] [blame] | 48 | std::optional<uint32_t> transformHint = std::nullopt; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 49 | uint32_t currentMaxAcquiredBufferCount = 0; |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 50 | 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 Mouri | 21d9432 | 2023-10-17 19:51:39 +0000 | [diff] [blame] | 55 | uint64_t previousFrameNumber = 0; |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 56 | ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID; |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 57 | std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
Robert Carr | 9a803c3 | 2021-01-14 16:57:58 -0800 | [diff] [blame] | 60 | class TransactionCallbackInvoker { |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 61 | public: |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 62 | status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 63 | status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles, |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 64 | std::deque<sp<CallbackHandle>>& outRemainingHandles); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 65 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 66 | void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks); |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 67 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 68 | void addPresentFence(sp<Fence>); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 69 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 70 | void sendCallbacks(bool onCommitOnly); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 71 | void clearCompletedTransactions() { |
| 72 | mCompletedTransactions.clear(); |
| 73 | } |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 74 | |
Pascal Mütschard | d56514e | 2024-05-24 17:37:13 +0200 | [diff] [blame] | 75 | status_t addCallbackHandle(const sp<CallbackHandle>& handle); |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 76 | |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 77 | private: |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 78 | status_t findOrCreateTransactionStats(const sp<IBinder>& listener, |
| 79 | const std::vector<CallbackId>& callbackIds, |
| 80 | TransactionStats** outTransactionStats); |
Marissa Wall | efb71af | 2019-06-27 14:45:53 -0700 | [diff] [blame] | 81 | |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 82 | std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash> |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 83 | mCompletedTransactions; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 84 | |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 85 | struct BufferRelease { |
Patrick Williams | bb50447 | 2024-10-25 13:20:32 -0500 | [diff] [blame] | 86 | std::string layerName; |
Patrick Williams | 7c9fa27 | 2024-08-30 12:38:43 +0000 | [diff] [blame] | 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 Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 94 | sp<Fence> mPresentFence; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // namespace android |