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