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