Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 <stdint.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <utils/Errors.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 21 | #include <utils/NativeHandle.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 23 | #include <utils/Timers.h> |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 24 | #include <utils/Vector.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 25 | |
| 26 | #include <binder/Parcel.h> |
| 27 | #include <binder/IInterface.h> |
| 28 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 29 | #include <gui/IGraphicBufferProducer.h> |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 30 | #include <gui/IProducerListener.h> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | enum { |
| 36 | REQUEST_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
| 37 | SET_BUFFER_COUNT, |
| 38 | DEQUEUE_BUFFER, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 39 | DETACH_BUFFER, |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 40 | DETACH_NEXT_BUFFER, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 41 | ATTACH_BUFFER, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 42 | QUEUE_BUFFER, |
| 43 | CANCEL_BUFFER, |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 44 | QUERY, |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 45 | CONNECT, |
| 46 | DISCONNECT, |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 47 | SET_SIDEBAND_STREAM, |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame^] | 48 | ALLOCATE_BUFFERS, |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 51 | class BpGraphicBufferProducer : public BpInterface<IGraphicBufferProducer> |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 52 | { |
| 53 | public: |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 54 | BpGraphicBufferProducer(const sp<IBinder>& impl) |
| 55 | : BpInterface<IGraphicBufferProducer>(impl) |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 56 | { |
| 57 | } |
| 58 | |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 59 | virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 60 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 61 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 62 | data.writeInt32(bufferIdx); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 63 | status_t result =remote()->transact(REQUEST_BUFFER, data, &reply); |
| 64 | if (result != NO_ERROR) { |
| 65 | return result; |
| 66 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 67 | bool nonNull = reply.readInt32(); |
| 68 | if (nonNull) { |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 69 | *buf = new GraphicBuffer(); |
Lingyun Zhu | 2aff702 | 2012-11-20 19:24:35 +0800 | [diff] [blame] | 70 | result = reply.read(**buf); |
| 71 | if(result != NO_ERROR) { |
| 72 | (*buf).clear(); |
| 73 | return result; |
| 74 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 75 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 76 | result = reply.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 77 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | virtual status_t setBufferCount(int bufferCount) |
| 81 | { |
| 82 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 83 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 84 | data.writeInt32(bufferCount); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 85 | status_t result =remote()->transact(SET_BUFFER_COUNT, data, &reply); |
| 86 | if (result != NO_ERROR) { |
| 87 | return result; |
| 88 | } |
| 89 | result = reply.readInt32(); |
| 90 | return result; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 93 | virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence, bool async, |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 94 | uint32_t w, uint32_t h, uint32_t format, uint32_t usage) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 95 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 96 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 97 | data.writeInt32(async); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 98 | data.writeInt32(w); |
| 99 | data.writeInt32(h); |
| 100 | data.writeInt32(format); |
| 101 | data.writeInt32(usage); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 102 | status_t result = remote()->transact(DEQUEUE_BUFFER, data, &reply); |
| 103 | if (result != NO_ERROR) { |
| 104 | return result; |
| 105 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 106 | *buf = reply.readInt32(); |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 107 | bool nonNull = reply.readInt32(); |
| 108 | if (nonNull) { |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 109 | *fence = new Fence(); |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 110 | reply.read(**fence); |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 111 | } |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 112 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 113 | return result; |
| 114 | } |
| 115 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 116 | virtual status_t detachBuffer(int slot) { |
| 117 | Parcel data, reply; |
| 118 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 119 | data.writeInt32(slot); |
| 120 | status_t result = remote()->transact(DETACH_BUFFER, data, &reply); |
| 121 | if (result != NO_ERROR) { |
| 122 | return result; |
| 123 | } |
| 124 | result = reply.readInt32(); |
| 125 | return result; |
| 126 | } |
| 127 | |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 128 | virtual status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, |
| 129 | sp<Fence>* outFence) { |
| 130 | if (outBuffer == NULL) { |
| 131 | ALOGE("detachNextBuffer: outBuffer must not be NULL"); |
| 132 | return BAD_VALUE; |
| 133 | } else if (outFence == NULL) { |
| 134 | ALOGE("detachNextBuffer: outFence must not be NULL"); |
| 135 | return BAD_VALUE; |
| 136 | } |
| 137 | Parcel data, reply; |
| 138 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 139 | status_t result = remote()->transact(DETACH_NEXT_BUFFER, data, &reply); |
| 140 | if (result != NO_ERROR) { |
| 141 | return result; |
| 142 | } |
| 143 | result = reply.readInt32(); |
| 144 | if (result == NO_ERROR) { |
| 145 | bool nonNull = reply.readInt32(); |
| 146 | if (nonNull) { |
| 147 | *outBuffer = new GraphicBuffer; |
| 148 | reply.read(**outBuffer); |
| 149 | } |
| 150 | nonNull = reply.readInt32(); |
| 151 | if (nonNull) { |
| 152 | *outFence = new Fence; |
| 153 | reply.read(**outFence); |
| 154 | } |
| 155 | } |
| 156 | return result; |
| 157 | } |
| 158 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 159 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { |
| 160 | Parcel data, reply; |
| 161 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 162 | data.write(*buffer.get()); |
| 163 | status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); |
| 164 | if (result != NO_ERROR) { |
| 165 | return result; |
| 166 | } |
| 167 | *slot = reply.readInt32(); |
| 168 | result = reply.readInt32(); |
| 169 | return result; |
| 170 | } |
| 171 | |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 172 | virtual status_t queueBuffer(int buf, |
| 173 | const QueueBufferInput& input, QueueBufferOutput* output) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 174 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 175 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 176 | data.writeInt32(buf); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 177 | data.write(input); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 178 | status_t result = remote()->transact(QUEUE_BUFFER, data, &reply); |
| 179 | if (result != NO_ERROR) { |
| 180 | return result; |
| 181 | } |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 182 | memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 183 | result = reply.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 184 | return result; |
| 185 | } |
| 186 | |
Jesse Hall | 4c00cc1 | 2013-03-15 21:34:30 -0700 | [diff] [blame] | 187 | virtual void cancelBuffer(int buf, const sp<Fence>& fence) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 188 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 189 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 190 | data.writeInt32(buf); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 191 | data.write(*fence.get()); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 192 | remote()->transact(CANCEL_BUFFER, data, &reply); |
| 193 | } |
| 194 | |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 195 | virtual int query(int what, int* value) { |
| 196 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 197 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 198 | data.writeInt32(what); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 199 | status_t result = remote()->transact(QUERY, data, &reply); |
| 200 | if (result != NO_ERROR) { |
| 201 | return result; |
| 202 | } |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 203 | value[0] = reply.readInt32(); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 204 | result = reply.readInt32(); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 205 | return result; |
| 206 | } |
| 207 | |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 208 | virtual status_t connect(const sp<IProducerListener>& listener, |
Mathias Agopian | 365857d | 2013-09-11 19:35:45 -0700 | [diff] [blame] | 209 | int api, bool producerControlledByApp, QueueBufferOutput* output) { |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 210 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 211 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 212 | if (listener != NULL) { |
| 213 | data.writeInt32(1); |
| 214 | data.writeStrongBinder(listener->asBinder()); |
| 215 | } else { |
| 216 | data.writeInt32(0); |
| 217 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 218 | data.writeInt32(api); |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 219 | data.writeInt32(producerControlledByApp); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 220 | status_t result = remote()->transact(CONNECT, data, &reply); |
| 221 | if (result != NO_ERROR) { |
| 222 | return result; |
| 223 | } |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 224 | memcpy(output, reply.readInplace(sizeof(*output)), sizeof(*output)); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 225 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 226 | return result; |
| 227 | } |
Mathias Agopian | 8072711 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 228 | |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 229 | virtual status_t disconnect(int api) { |
| 230 | Parcel data, reply; |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 231 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 232 | data.writeInt32(api); |
Jamie Gennis | 8a29ff2 | 2011-10-14 15:03:17 -0700 | [diff] [blame] | 233 | status_t result =remote()->transact(DISCONNECT, data, &reply); |
| 234 | if (result != NO_ERROR) { |
| 235 | return result; |
| 236 | } |
| 237 | result = reply.readInt32(); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 238 | return result; |
| 239 | } |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 240 | |
| 241 | virtual status_t setSidebandStream(const sp<NativeHandle>& stream) { |
| 242 | Parcel data, reply; |
| 243 | status_t result; |
| 244 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 245 | if (stream.get()) { |
| 246 | data.writeInt32(true); |
| 247 | data.writeNativeHandle(stream->handle()); |
| 248 | } else { |
| 249 | data.writeInt32(false); |
| 250 | } |
| 251 | if ((result = remote()->transact(SET_SIDEBAND_STREAM, data, &reply)) == NO_ERROR) { |
| 252 | result = reply.readInt32(); |
| 253 | } |
| 254 | return result; |
| 255 | } |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame^] | 256 | |
| 257 | virtual void allocateBuffers(bool async, uint32_t width, uint32_t height, |
| 258 | uint32_t format, uint32_t usage) { |
| 259 | Parcel data, reply; |
| 260 | data.writeInterfaceToken(IGraphicBufferProducer::getInterfaceDescriptor()); |
| 261 | data.writeInt32(static_cast<int32_t>(async)); |
| 262 | data.writeInt32(static_cast<int32_t>(width)); |
| 263 | data.writeInt32(static_cast<int32_t>(height)); |
| 264 | data.writeInt32(static_cast<int32_t>(format)); |
| 265 | data.writeInt32(static_cast<int32_t>(usage)); |
| 266 | status_t result = remote()->transact(ALLOCATE_BUFFERS, data, &reply); |
| 267 | if (result != NO_ERROR) { |
| 268 | ALOGE("allocateBuffers failed to transact: %d", result); |
| 269 | } |
| 270 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 271 | }; |
| 272 | |
Andy McFadden | 466a192 | 2013-01-08 11:25:51 -0800 | [diff] [blame] | 273 | IMPLEMENT_META_INTERFACE(GraphicBufferProducer, "android.gui.IGraphicBufferProducer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 274 | |
| 275 | // ---------------------------------------------------------------------- |
| 276 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 277 | status_t BnGraphicBufferProducer::onTransact( |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 278 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 279 | { |
| 280 | switch(code) { |
| 281 | case REQUEST_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 282 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 283 | int bufferIdx = data.readInt32(); |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 284 | sp<GraphicBuffer> buffer; |
| 285 | int result = requestBuffer(bufferIdx, &buffer); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 286 | reply->writeInt32(buffer != 0); |
| 287 | if (buffer != 0) { |
| 288 | reply->write(*buffer); |
| 289 | } |
Jamie Gennis | 7b305ff | 2011-07-19 12:08:33 -0700 | [diff] [blame] | 290 | reply->writeInt32(result); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 291 | return NO_ERROR; |
| 292 | } break; |
| 293 | case SET_BUFFER_COUNT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 294 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 295 | int bufferCount = data.readInt32(); |
| 296 | int result = setBufferCount(bufferCount); |
| 297 | reply->writeInt32(result); |
| 298 | return NO_ERROR; |
| 299 | } break; |
| 300 | case DEQUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 301 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 302 | bool async = data.readInt32(); |
Mathias Agopian | c04f153 | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 303 | uint32_t w = data.readInt32(); |
| 304 | uint32_t h = data.readInt32(); |
| 305 | uint32_t format = data.readInt32(); |
| 306 | uint32_t usage = data.readInt32(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 307 | int buf; |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 308 | sp<Fence> fence; |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 309 | int result = dequeueBuffer(&buf, &fence, async, w, h, format, usage); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 310 | reply->writeInt32(buf); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 311 | reply->writeInt32(fence != NULL); |
| 312 | if (fence != NULL) { |
Mathias Agopian | ba93b3f | 2013-08-01 15:48:40 -0700 | [diff] [blame] | 313 | reply->write(*fence); |
Jesse Hall | f785754 | 2012-06-14 15:26:33 -0700 | [diff] [blame] | 314 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 315 | reply->writeInt32(result); |
| 316 | return NO_ERROR; |
| 317 | } break; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 318 | case DETACH_BUFFER: { |
| 319 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 320 | int slot = data.readInt32(); |
| 321 | int result = detachBuffer(slot); |
| 322 | reply->writeInt32(result); |
| 323 | return NO_ERROR; |
| 324 | } break; |
Dan Stoza | d9822a3 | 2014-03-28 15:25:31 -0700 | [diff] [blame] | 325 | case DETACH_NEXT_BUFFER: { |
| 326 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 327 | sp<GraphicBuffer> buffer; |
| 328 | sp<Fence> fence; |
| 329 | int32_t result = detachNextBuffer(&buffer, &fence); |
| 330 | reply->writeInt32(result); |
| 331 | if (result == NO_ERROR) { |
| 332 | reply->writeInt32(buffer != NULL); |
| 333 | if (buffer != NULL) { |
| 334 | reply->write(*buffer); |
| 335 | } |
| 336 | reply->writeInt32(fence != NULL); |
| 337 | if (fence != NULL) { |
| 338 | reply->write(*fence); |
| 339 | } |
| 340 | } |
| 341 | return NO_ERROR; |
| 342 | } break; |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 343 | case ATTACH_BUFFER: { |
| 344 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 345 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 346 | data.read(*buffer.get()); |
| 347 | int slot; |
| 348 | int result = attachBuffer(&slot, buffer); |
| 349 | reply->writeInt32(slot); |
| 350 | reply->writeInt32(result); |
| 351 | return NO_ERROR; |
| 352 | } break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 353 | case QUEUE_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 354 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 355 | int buf = data.readInt32(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 356 | QueueBufferInput input(data); |
Mathias Agopian | f0bc2f1 | 2012-04-09 16:14:01 -0700 | [diff] [blame] | 357 | QueueBufferOutput* const output = |
| 358 | reinterpret_cast<QueueBufferOutput *>( |
| 359 | reply->writeInplace(sizeof(QueueBufferOutput))); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 360 | status_t result = queueBuffer(buf, input, output); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 361 | reply->writeInt32(result); |
| 362 | return NO_ERROR; |
| 363 | } break; |
| 364 | case CANCEL_BUFFER: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 365 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 366 | int buf = data.readInt32(); |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 367 | sp<Fence> fence = new Fence(); |
| 368 | data.read(*fence.get()); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 369 | cancelBuffer(buf, fence); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 370 | return NO_ERROR; |
| 371 | } break; |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 372 | case QUERY: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 373 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Mathias Agopian | eafabcd | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 374 | int value; |
| 375 | int what = data.readInt32(); |
| 376 | int res = query(what, &value); |
| 377 | reply->writeInt32(value); |
| 378 | reply->writeInt32(res); |
| 379 | return NO_ERROR; |
| 380 | } break; |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 381 | case CONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 382 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 383 | sp<IProducerListener> listener; |
| 384 | if (data.readInt32() == 1) { |
| 385 | listener = IProducerListener::asInterface(data.readStrongBinder()); |
| 386 | } |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 387 | int api = data.readInt32(); |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 388 | bool producerControlledByApp = data.readInt32(); |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 389 | QueueBufferOutput* const output = |
| 390 | reinterpret_cast<QueueBufferOutput *>( |
| 391 | reply->writeInplace(sizeof(QueueBufferOutput))); |
Dan Stoza | f0eaf25 | 2014-03-21 13:05:51 -0700 | [diff] [blame] | 392 | status_t res = connect(listener, api, producerControlledByApp, output); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 393 | reply->writeInt32(res); |
| 394 | return NO_ERROR; |
| 395 | } break; |
| 396 | case DISCONNECT: { |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 397 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 398 | int api = data.readInt32(); |
Mathias Agopian | 2773004 | 2011-07-14 20:20:58 -0700 | [diff] [blame] | 399 | status_t res = disconnect(api); |
Jamie Gennis | fe0a87b | 2011-07-13 19:12:20 -0700 | [diff] [blame] | 400 | reply->writeInt32(res); |
| 401 | return NO_ERROR; |
| 402 | } break; |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 403 | case SET_SIDEBAND_STREAM: { |
| 404 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 405 | sp<NativeHandle> stream; |
| 406 | if (data.readInt32()) { |
Wonsik Kim | 0ec54e1 | 2014-03-21 10:46:24 +0900 | [diff] [blame] | 407 | stream = NativeHandle::create(data.readNativeHandle(), true); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 408 | } |
| 409 | status_t result = setSidebandStream(stream); |
| 410 | reply->writeInt32(result); |
| 411 | return NO_ERROR; |
| 412 | } break; |
Dan Stoza | 29a3e90 | 2014-06-20 13:13:57 -0700 | [diff] [blame^] | 413 | case ALLOCATE_BUFFERS: |
| 414 | CHECK_INTERFACE(IGraphicBufferProducer, data, reply); |
| 415 | bool async = static_cast<bool>(data.readInt32()); |
| 416 | uint32_t width = static_cast<uint32_t>(data.readInt32()); |
| 417 | uint32_t height = static_cast<uint32_t>(data.readInt32()); |
| 418 | uint32_t format = static_cast<uint32_t>(data.readInt32()); |
| 419 | uint32_t usage = static_cast<uint32_t>(data.readInt32()); |
| 420 | allocateBuffers(async, width, height, format, usage); |
| 421 | return NO_ERROR; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 422 | } |
| 423 | return BBinder::onTransact(code, data, reply, flags); |
| 424 | } |
| 425 | |
| 426 | // ---------------------------------------------------------------------------- |
| 427 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 428 | IGraphicBufferProducer::QueueBufferInput::QueueBufferInput(const Parcel& parcel) { |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 429 | parcel.read(*this); |
| 430 | } |
| 431 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 432 | size_t IGraphicBufferProducer::QueueBufferInput::getFlattenedSize() const { |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 433 | return sizeof(timestamp) |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 434 | + sizeof(isAutoTimestamp) |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 435 | + sizeof(crop) |
| 436 | + sizeof(scalingMode) |
| 437 | + sizeof(transform) |
Mathias Agopian | 7cdd786 | 2013-07-18 22:10:56 -0700 | [diff] [blame] | 438 | + sizeof(async) |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 439 | + fence->getFlattenedSize(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 442 | size_t IGraphicBufferProducer::QueueBufferInput::getFdCount() const { |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 443 | return fence->getFdCount(); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 446 | status_t IGraphicBufferProducer::QueueBufferInput::flatten( |
| 447 | void*& buffer, size_t& size, int*& fds, size_t& count) const |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 448 | { |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 449 | if (size < getFlattenedSize()) { |
| 450 | return NO_MEMORY; |
| 451 | } |
| 452 | FlattenableUtils::write(buffer, size, timestamp); |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 453 | FlattenableUtils::write(buffer, size, isAutoTimestamp); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 454 | FlattenableUtils::write(buffer, size, crop); |
| 455 | FlattenableUtils::write(buffer, size, scalingMode); |
| 456 | FlattenableUtils::write(buffer, size, transform); |
| 457 | FlattenableUtils::write(buffer, size, async); |
| 458 | return fence->flatten(buffer, size, fds, count); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 461 | status_t IGraphicBufferProducer::QueueBufferInput::unflatten( |
| 462 | void const*& buffer, size_t& size, int const*& fds, size_t& count) |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 463 | { |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 464 | size_t minNeeded = |
| 465 | sizeof(timestamp) |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 466 | + sizeof(isAutoTimestamp) |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 467 | + sizeof(crop) |
| 468 | + sizeof(scalingMode) |
| 469 | + sizeof(transform) |
| 470 | + sizeof(async); |
| 471 | |
| 472 | if (size < minNeeded) { |
| 473 | return NO_MEMORY; |
| 474 | } |
| 475 | |
| 476 | FlattenableUtils::read(buffer, size, timestamp); |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 477 | FlattenableUtils::read(buffer, size, isAutoTimestamp); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 478 | FlattenableUtils::read(buffer, size, crop); |
| 479 | FlattenableUtils::read(buffer, size, scalingMode); |
| 480 | FlattenableUtils::read(buffer, size, transform); |
| 481 | FlattenableUtils::read(buffer, size, async); |
| 482 | |
Jamie Gennis | 1df8c34 | 2012-12-20 14:05:45 -0800 | [diff] [blame] | 483 | fence = new Fence(); |
Mathias Agopian | e142428 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 484 | return fence->unflatten(buffer, size, fds, count); |
Jesse Hall | c777b0b | 2012-06-28 12:52:05 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 487 | }; // namespace android |