1 /*
2 * Copyright (C) 2013 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 #include <gui/IConsumerListener.h>
18
19 #include <gui/BufferItem.h>
20
21 namespace android {
22
23 namespace { // Anonymous
24
25 enum class Tag : uint32_t {
26 ON_DISCONNECT = IBinder::FIRST_CALL_TRANSACTION,
27 ON_FRAME_AVAILABLE,
28 ON_FRAME_REPLACED,
29 ON_BUFFERS_RELEASED,
30 ON_SIDEBAND_STREAM_CHANGED,
31 ON_FRAME_DEQUEUED,
32 ON_FRAME_CANCELLED,
33 ON_FRAME_DETACHED,
34 LAST = ON_FRAME_DETACHED,
35 };
36
37 } // Anonymous namespace
38
39 class BpConsumerListener : public SafeBpInterface<IConsumerListener> {
40 public:
BpConsumerListener(const sp<IBinder> & impl)41 explicit BpConsumerListener(const sp<IBinder>& impl)
42 : SafeBpInterface<IConsumerListener>(impl, "BpConsumerListener") {}
43
44 ~BpConsumerListener() override;
45
onDisconnect()46 void onDisconnect() override {
47 callRemoteAsync<decltype(&IConsumerListener::onDisconnect)>(Tag::ON_DISCONNECT);
48 }
49
onFrameDequeued(const uint64_t bufferId)50 void onFrameDequeued(const uint64_t bufferId) override {
51 callRemoteAsync<decltype(&IConsumerListener::onFrameDequeued)>(Tag::ON_FRAME_DEQUEUED,
52 bufferId);
53 }
54
onFrameDetached(const uint64_t bufferId)55 void onFrameDetached(const uint64_t bufferId) override {
56 callRemoteAsync<decltype(&IConsumerListener::onFrameDetached)>(Tag::ON_FRAME_DETACHED,
57 bufferId);
58 }
59
onFrameCancelled(const uint64_t bufferId)60 void onFrameCancelled(const uint64_t bufferId) override {
61 callRemoteAsync<decltype(&IConsumerListener::onFrameCancelled)>(Tag::ON_FRAME_CANCELLED,
62 bufferId);
63 }
64
onFrameAvailable(const BufferItem & item)65 void onFrameAvailable(const BufferItem& item) override {
66 callRemoteAsync<decltype(&IConsumerListener::onFrameAvailable)>(Tag::ON_FRAME_AVAILABLE,
67 item);
68 }
69
onFrameReplaced(const BufferItem & item)70 void onFrameReplaced(const BufferItem& item) override {
71 callRemoteAsync<decltype(&IConsumerListener::onFrameReplaced)>(Tag::ON_FRAME_REPLACED,
72 item);
73 }
74
onBuffersReleased()75 void onBuffersReleased() override {
76 callRemoteAsync<decltype(&IConsumerListener::onBuffersReleased)>(Tag::ON_BUFFERS_RELEASED);
77 }
78
onSidebandStreamChanged()79 void onSidebandStreamChanged() override {
80 callRemoteAsync<decltype(&IConsumerListener::onSidebandStreamChanged)>(
81 Tag::ON_SIDEBAND_STREAM_CHANGED);
82 }
83
addAndGetFrameTimestamps(const NewFrameEventsEntry *,FrameEventHistoryDelta *)84 void addAndGetFrameTimestamps(const NewFrameEventsEntry* /*newTimestamps*/,
85 FrameEventHistoryDelta* /*outDelta*/) override {
86 LOG_ALWAYS_FATAL("IConsumerListener::addAndGetFrameTimestamps cannot be proxied");
87 }
88 };
89
90 // Out-of-line virtual method definitions to trigger vtable emission in this translation unit (see
91 // clang warning -Wweak-vtables)
92 BpConsumerListener::~BpConsumerListener() = default;
93
94 IMPLEMENT_META_INTERFACE(ConsumerListener, "android.gui.IConsumerListener");
95
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)96 status_t BnConsumerListener::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
97 uint32_t flags) {
98 if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
99 return BBinder::onTransact(code, data, reply, flags);
100 }
101 auto tag = static_cast<Tag>(code);
102 switch (tag) {
103 case Tag::ON_DISCONNECT:
104 return callLocalAsync(data, reply, &IConsumerListener::onDisconnect);
105 case Tag::ON_FRAME_AVAILABLE:
106 return callLocalAsync(data, reply, &IConsumerListener::onFrameAvailable);
107 case Tag::ON_FRAME_REPLACED:
108 return callLocalAsync(data, reply, &IConsumerListener::onFrameReplaced);
109 case Tag::ON_BUFFERS_RELEASED:
110 return callLocalAsync(data, reply, &IConsumerListener::onBuffersReleased);
111 case Tag::ON_SIDEBAND_STREAM_CHANGED:
112 return callLocalAsync(data, reply, &IConsumerListener::onSidebandStreamChanged);
113 case Tag::ON_FRAME_DEQUEUED:
114 return callLocalAsync(data, reply, &IConsumerListener::onFrameDequeued);
115 case Tag::ON_FRAME_CANCELLED:
116 return callLocalAsync(data, reply, &IConsumerListener::onFrameCancelled);
117 case Tag::ON_FRAME_DETACHED:
118 return callLocalAsync(data, reply, &IConsumerListener::onFrameDetached);
119 }
120 }
121
122 } // namespace android
123