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 | |
| 19 | #include <condition_variable> |
| 20 | #include <deque> |
Vladimir Marko | 2109270 | 2021-10-12 12:43:47 +0000 | [diff] [blame] | 21 | #include <mutex> |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 22 | #include <queue> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 23 | #include <thread> |
| 24 | #include <unordered_map> |
Marissa Wall | efb71af | 2019-06-27 14:45:53 -0700 | [diff] [blame] | 25 | #include <unordered_set> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 26 | |
| 27 | #include <android-base/thread_annotations.h> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 28 | #include <binder/IBinder.h> |
Dominik Laskowski | bb448ce | 2022-05-07 15:52:55 -0700 | [diff] [blame] | 29 | #include <compositionengine/FenceResult.h> |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 30 | #include <ftl/future.h> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 31 | #include <gui/ITransactionCompletedListener.h> |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 32 | #include <ui/Fence.h> |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | |
| 36 | class CallbackHandle : public RefBase { |
| 37 | public: |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 38 | CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids, |
| 39 | const sp<IBinder>& sc); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 40 | |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 41 | sp<IBinder> listener; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 42 | std::vector<CallbackId> callbackIds; |
Marissa Wall | 0e24a83 | 2019-07-10 15:32:50 -0700 | [diff] [blame] | 43 | wp<IBinder> surfaceControl; |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 44 | |
| 45 | bool releasePreviousBuffer = false; |
Sally Qi | 59a9f50 | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 46 | std::string name; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 47 | sp<Fence> previousReleaseFence; |
Dominik Laskowski | b17c621 | 2022-05-09 09:36:19 -0700 | [diff] [blame] | 48 | std::vector<ftl::SharedFuture<FenceResult>> previousReleaseFences; |
Ady Abraham | 461296a | 2022-01-21 11:11:31 -0800 | [diff] [blame] | 49 | std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1; |
Marissa Wall | 5a68a77 | 2018-12-22 17:43:42 -0800 | [diff] [blame] | 50 | nsecs_t latchTime = -1; |
Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 51 | uint32_t transformHint = 0; |
Ady Abraham | 899dcdb | 2021-06-15 16:56:21 -0700 | [diff] [blame] | 52 | uint32_t currentMaxAcquiredBufferCount = 0; |
Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 53 | std::shared_ptr<FenceTime> gpuCompositionDoneFence{FenceTime::NO_FENCE}; |
| 54 | CompositorTiming compositorTiming; |
| 55 | nsecs_t refreshStartTime = 0; |
| 56 | nsecs_t dequeueReadyTime = 0; |
| 57 | uint64_t frameNumber = 0; |
Vishnu Nair | 4ba0c2e | 2021-06-24 11:27:17 -0700 | [diff] [blame] | 58 | ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Robert Carr | 9a803c3 | 2021-01-14 16:57:58 -0800 | [diff] [blame] | 61 | class TransactionCallbackInvoker { |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 62 | public: |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 63 | status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles, |
Robert Carr | 3ec2b85 | 2021-09-28 17:46:57 -0700 | [diff] [blame] | 64 | const std::vector<JankData>& jankData); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 65 | status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles, |
Vishnu Nair | fc46c1e | 2021-04-21 08:31:32 -0700 | [diff] [blame] | 66 | std::deque<sp<CallbackHandle>>& outRemainingHandles); |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 67 | |
| 68 | // Adds the Transaction CallbackHandle from a layer that does not need to be relatched and |
| 69 | // presented this frame. |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 70 | status_t registerUnpresentedCallbackHandle(const sp<CallbackHandle>& handle); |
| 71 | void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks); |
Marissa Wall | 3dad52d | 2019-03-22 14:03:19 -0700 | [diff] [blame] | 72 | |
Dominik Laskowski | 8792c11 | 2022-07-12 09:03:39 -0700 | [diff] [blame] | 73 | void addPresentFence(sp<Fence>); |
Marissa Wall | fda30bb | 2018-10-12 11:34:28 -0700 | [diff] [blame] | 74 | |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 75 | void sendCallbacks(bool onCommitOnly); |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 76 | void clearCompletedTransactions() { |
| 77 | mCompletedTransactions.clear(); |
| 78 | } |
Marissa Wall | d600d57 | 2019-03-26 15:38:50 -0700 | [diff] [blame] | 79 | |
Jiakai Zhang | a5505cb | 2021-11-09 11:46:30 +0000 | [diff] [blame] | 80 | status_t addCallbackHandle(const sp<CallbackHandle>& handle, |
| 81 | const std::vector<JankData>& jankData); |
| 82 | |
| 83 | |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 84 | private: |
Vishnu Nair | cd52e2d | 2021-10-18 08:42:46 -0700 | [diff] [blame] | 85 | status_t findOrCreateTransactionStats(const sp<IBinder>& listener, |
| 86 | const std::vector<CallbackId>& callbackIds, |
| 87 | TransactionStats** outTransactionStats); |
Marissa Wall | efb71af | 2019-06-27 14:45:53 -0700 | [diff] [blame] | 88 | |
Valerie Hau | 5de3ad2 | 2019-08-20 07:47:43 -0700 | [diff] [blame] | 89 | std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash> |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 90 | mCompletedTransactions; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 91 | |
Robert Carr | 3d1047b | 2021-09-20 18:22:32 -0700 | [diff] [blame] | 92 | sp<Fence> mPresentFence; |
Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace android |