• 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 <binder/IInterface.h>
20 #include <binder/Parcel.h>
21 #include <binder/Parcelable.h>
22 #include <binder/SafeInterface.h>
23 
24 #include <ui/Fence.h>
25 #include <utils/Timers.h>
26 
27 #include <cstdint>
28 #include <unordered_map>
29 #include <unordered_set>
30 
31 namespace android {
32 
33 class ITransactionCompletedListener;
34 
35 using CallbackId = int64_t;
36 
37 class SurfaceStats : public Parcelable {
38 public:
39     status_t writeToParcel(Parcel* output) const override;
40     status_t readFromParcel(const Parcel* input) override;
41 
42     SurfaceStats() = default;
SurfaceStats(const sp<IBinder> & sc,nsecs_t time,const sp<Fence> & prevReleaseFence)43     SurfaceStats(const sp<IBinder>& sc, nsecs_t time, const sp<Fence>& prevReleaseFence)
44           : surfaceControl(sc), acquireTime(time), previousReleaseFence(prevReleaseFence) {}
45 
46     sp<IBinder> surfaceControl;
47     nsecs_t acquireTime = -1;
48     sp<Fence> previousReleaseFence;
49 };
50 
51 class TransactionStats : public Parcelable {
52 public:
53     status_t writeToParcel(Parcel* output) const override;
54     status_t readFromParcel(const Parcel* input) override;
55 
56     TransactionStats() = default;
TransactionStats(const std::vector<CallbackId> & ids)57     TransactionStats(const std::vector<CallbackId>& ids) : callbackIds(ids) {}
TransactionStats(const std::unordered_set<CallbackId> & ids)58     TransactionStats(const std::unordered_set<CallbackId>& ids)
59           : callbackIds(ids.begin(), ids.end()) {}
TransactionStats(const std::vector<CallbackId> & ids,nsecs_t latch,const sp<Fence> & present,const std::vector<SurfaceStats> & surfaces)60     TransactionStats(const std::vector<CallbackId>& ids, nsecs_t latch, const sp<Fence>& present,
61                      const std::vector<SurfaceStats>& surfaces)
62           : callbackIds(ids), latchTime(latch), presentFence(present), surfaceStats(surfaces) {}
63 
64     std::vector<CallbackId> callbackIds;
65     nsecs_t latchTime = -1;
66     sp<Fence> presentFence = nullptr;
67     std::vector<SurfaceStats> surfaceStats;
68 };
69 
70 class ListenerStats : public Parcelable {
71 public:
72     status_t writeToParcel(Parcel* output) const override;
73     status_t readFromParcel(const Parcel* input) override;
74 
75     static ListenerStats createEmpty(const sp<ITransactionCompletedListener>& listener,
76                                      const std::unordered_set<CallbackId>& callbackIds);
77 
78     sp<ITransactionCompletedListener> listener;
79     std::vector<TransactionStats> transactionStats;
80 };
81 
82 class ITransactionCompletedListener : public IInterface {
83 public:
84     DECLARE_META_INTERFACE(TransactionCompletedListener)
85 
86     virtual void onTransactionCompleted(ListenerStats stats) = 0;
87 };
88 
89 class BnTransactionCompletedListener : public SafeBnInterface<ITransactionCompletedListener> {
90 public:
BnTransactionCompletedListener()91     BnTransactionCompletedListener()
92           : SafeBnInterface<ITransactionCompletedListener>("BnTransactionCompletedListener") {}
93 
94     status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply,
95                         uint32_t flags = 0) override;
96 };
97 
98 class ListenerCallbacks {
99 public:
ListenerCallbacks(const sp<ITransactionCompletedListener> & listener,const std::unordered_set<CallbackId> & callbacks)100     ListenerCallbacks(const sp<ITransactionCompletedListener>& listener,
101                       const std::unordered_set<CallbackId>& callbacks)
102           : transactionCompletedListener(listener),
103             callbackIds(callbacks.begin(), callbacks.end()) {}
104 
ListenerCallbacks(const sp<ITransactionCompletedListener> & listener,const std::vector<CallbackId> & ids)105     ListenerCallbacks(const sp<ITransactionCompletedListener>& listener,
106                       const std::vector<CallbackId>& ids)
107           : transactionCompletedListener(listener), callbackIds(ids) {}
108 
109     sp<ITransactionCompletedListener> transactionCompletedListener;
110     std::vector<CallbackId> callbackIds;
111 };
112 
113 } // namespace android
114