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