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