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