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