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