blob: 808e3369f1340e3d04dc064104f8e863d968ebe2 [file] [log] [blame]
Dan Stozaf0eaf252014-03-21 13:05:51 -07001/*
2 * Copyright 2014 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 <binder/Parcel.h>
Pawin Vongmasae672cd02019-02-14 16:01:29 -080018#include <gui/bufferqueue/1.0/H2BProducerListener.h>
19#include <gui/bufferqueue/2.0/H2BProducerListener.h>
Dan Stozaf0eaf252014-03-21 13:05:51 -070020#include <gui/IProducerListener.h>
21
22namespace android {
23
24enum {
25 ON_BUFFER_RELEASED = IBinder::FIRST_CALL_TRANSACTION,
Matthew Bouyack3b8e6b22016-10-03 16:24:26 -070026 NEEDS_RELEASE_NOTIFY,
Shuzhen Wang8a9d62f2019-08-14 10:41:12 -070027 ON_BUFFERS_DISCARDED,
Dan Stozaf0eaf252014-03-21 13:05:51 -070028};
29
30class BpProducerListener : public BpInterface<IProducerListener>
31{
32public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070033 explicit BpProducerListener(const sp<IBinder>& impl)
Dan Stozaf0eaf252014-03-21 13:05:51 -070034 : BpInterface<IProducerListener>(impl) {}
35
Dan Stozad723bd72014-11-18 10:24:03 -080036 virtual ~BpProducerListener();
37
Dan Stozaf0eaf252014-03-21 13:05:51 -070038 virtual void onBufferReleased() {
39 Parcel data, reply;
40 data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
41 remote()->transact(ON_BUFFER_RELEASED, data, &reply, IBinder::FLAG_ONEWAY);
42 }
Matthew Bouyack3b8e6b22016-10-03 16:24:26 -070043
44 virtual bool needsReleaseNotify() {
45 bool result;
46 Parcel data, reply;
47 data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
48 status_t err = remote()->transact(NEEDS_RELEASE_NOTIFY, data, &reply);
49 if (err != NO_ERROR) {
50 ALOGE("IProducerListener: binder call \'needsReleaseNotify\' failed");
51 return true;
52 }
53 err = reply.readBool(&result);
54 if (err != NO_ERROR) {
55 ALOGE("IProducerListener: malformed binder reply");
56 return true;
57 }
58 return result;
59 }
Shuzhen Wang8a9d62f2019-08-14 10:41:12 -070060
61 virtual void onBuffersDiscarded(const std::vector<int>& discardedSlots) {
62 Parcel data, reply;
63 data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
64 data.writeInt32Vector(discardedSlots);
65 remote()->transact(ON_BUFFERS_DISCARDED, data, &reply, IBinder::FLAG_ONEWAY);
66 }
Dan Stozaf0eaf252014-03-21 13:05:51 -070067};
68
Dan Stozad723bd72014-11-18 10:24:03 -080069// Out-of-line virtual method definition to trigger vtable emission in this
70// translation unit (see clang warning -Wweak-vtables)
71BpProducerListener::~BpProducerListener() {}
72
Pawin Vongmasae672cd02019-02-14 16:01:29 -080073class HpProducerListener : public HpInterface<
74 BpProducerListener,
75 hardware::graphics::bufferqueue::V1_0::utils::H2BProducerListener,
76 hardware::graphics::bufferqueue::V2_0::utils::H2BProducerListener> {
77public:
78 explicit HpProducerListener(const sp<IBinder>& base) : PBase{base} {}
79
80 virtual void onBufferReleased() override {
81 mBase->onBufferReleased();
82 }
83
84 virtual bool needsReleaseNotify() override {
85 return mBase->needsReleaseNotify();
86 }
Shuzhen Wang8a9d62f2019-08-14 10:41:12 -070087
88 virtual void onBuffersDiscarded(const std::vector<int32_t>& discardedSlots) override {
89 return mBase->onBuffersDiscarded(discardedSlots);
90 }
Pawin Vongmasae672cd02019-02-14 16:01:29 -080091};
92
93IMPLEMENT_HYBRID_META_INTERFACE(ProducerListener,
94 "android.gui.IProducerListener")
Dan Stozaf0eaf252014-03-21 13:05:51 -070095
96status_t BnProducerListener::onTransact(uint32_t code, const Parcel& data,
97 Parcel* reply, uint32_t flags) {
98 switch (code) {
99 case ON_BUFFER_RELEASED:
100 CHECK_INTERFACE(IProducerListener, data, reply);
101 onBufferReleased();
102 return NO_ERROR;
Matthew Bouyack3b8e6b22016-10-03 16:24:26 -0700103 case NEEDS_RELEASE_NOTIFY:
104 CHECK_INTERFACE(IProducerListener, data, reply);
105 reply->writeBool(needsReleaseNotify());
106 return NO_ERROR;
Shuzhen Wang8a9d62f2019-08-14 10:41:12 -0700107 case ON_BUFFERS_DISCARDED: {
108 CHECK_INTERFACE(IProducerListener, data, reply);
109 std::vector<int32_t> discardedSlots;
110 status_t result = data.readInt32Vector(&discardedSlots);
111 if (result != NO_ERROR) {
112 ALOGE("ON_BUFFERS_DISCARDED failed to read discardedSlots: %d", result);
113 return result;
114 }
115 onBuffersDiscarded(discardedSlots);
116 return NO_ERROR;
117 }
Dan Stozaf0eaf252014-03-21 13:05:51 -0700118 }
119 return BBinder::onTransact(code, data, reply, flags);
120}
121
Colin Cross97b64db2016-09-26 13:48:02 -0700122ProducerListener::~ProducerListener() = default;
123
124DummyProducerListener::~DummyProducerListener() = default;
125
Matthew Bouyack3b8e6b22016-10-03 16:24:26 -0700126bool BnProducerListener::needsReleaseNotify() {
127 return true;
128}
129
Shuzhen Wang8a9d62f2019-08-14 10:41:12 -0700130void BnProducerListener::onBuffersDiscarded(const std::vector<int32_t>& /*discardedSlots*/) {
131}
132
Dan Stozaf0eaf252014-03-21 13:05:51 -0700133} // namespace android