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