• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
21 #include <mutex>
22 #include <queue>
23 #include <thread>
24 #include <unordered_map>
25 #include <unordered_set>
26 
27 #include <android-base/thread_annotations.h>
28 #include <binder/IBinder.h>
29 #include <compositionengine/FenceResult.h>
30 #include <ftl/future.h>
31 #include <gui/ITransactionCompletedListener.h>
32 #include <ui/Fence.h>
33 
34 namespace android {
35 
36 class CallbackHandle : public RefBase {
37 public:
38     CallbackHandle(const sp<IBinder>& transactionListener, const std::vector<CallbackId>& ids,
39                    const sp<IBinder>& sc);
40 
41     sp<IBinder> listener;
42     std::vector<CallbackId> callbackIds;
43     wp<IBinder> surfaceControl;
44 
45     bool releasePreviousBuffer = false;
46     std::string name;
47     sp<Fence> previousReleaseFence;
48     std::vector<ftl::SharedFuture<FenceResult>> previousReleaseFences;
49     std::variant<nsecs_t, sp<Fence>> acquireTimeOrFence = -1;
50     nsecs_t latchTime = -1;
51     uint32_t transformHint = 0;
52     uint32_t currentMaxAcquiredBufferCount = 0;
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;
58     ReleaseCallbackId previousReleaseCallbackId = ReleaseCallbackId::INVALID_ID;
59 };
60 
61 class TransactionCallbackInvoker {
62 public:
63     status_t addCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
64                                 const std::vector<JankData>& jankData);
65     status_t addOnCommitCallbackHandles(const std::deque<sp<CallbackHandle>>& handles,
66                                              std::deque<sp<CallbackHandle>>& outRemainingHandles);
67 
68     // Adds the Transaction CallbackHandle from a layer that does not need to be relatched and
69     // presented this frame.
70     status_t registerUnpresentedCallbackHandle(const sp<CallbackHandle>& handle);
71     void addEmptyTransaction(const ListenerCallbacks& listenerCallbacks);
72 
73     void addPresentFence(const sp<Fence>& presentFence);
74 
75     void sendCallbacks(bool onCommitOnly);
clearCompletedTransactions()76     void clearCompletedTransactions() {
77         mCompletedTransactions.clear();
78     }
79 
80     status_t addCallbackHandle(const sp<CallbackHandle>& handle,
81                                const std::vector<JankData>& jankData);
82 
83 
84 private:
85     status_t findOrCreateTransactionStats(const sp<IBinder>& listener,
86                                           const std::vector<CallbackId>& callbackIds,
87                                           TransactionStats** outTransactionStats);
88 
89     std::unordered_map<sp<IBinder>, std::deque<TransactionStats>, IListenerHash>
90         mCompletedTransactions;
91 
92     sp<Fence> mPresentFence;
93 };
94 
95 } // namespace android
96