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