Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 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> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 22 | |
| 23 | #include <binder/Parcel.h> |
| 24 | #include <binder/IInterface.h> |
| 25 | |
Dan Stoza | de7100a | 2015-03-11 16:38:47 -0700 | [diff] [blame^] | 26 | #include <gui/BufferItem.h> |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 27 | #include <gui/IConsumerListener.h> |
| 28 | #include <gui/IGraphicBufferConsumer.h> |
| 29 | |
| 30 | #include <ui/GraphicBuffer.h> |
| 31 | #include <ui/Fence.h> |
| 32 | |
| 33 | #include <system/window.h> |
| 34 | |
| 35 | namespace android { |
| 36 | // --------------------------------------------------------------------------- |
| 37 | |
| 38 | IGraphicBufferConsumer::BufferItem::BufferItem() : |
| 39 | mTransform(0), |
| 40 | mScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), |
| 41 | mTimestamp(0), |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 42 | mIsAutoTimestamp(false), |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 43 | mDataSpace(HAL_DATASPACE_UNKNOWN), |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 44 | mFrameNumber(0), |
| 45 | mBuf(INVALID_BUFFER_SLOT), |
| 46 | mIsDroppable(false), |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 47 | mAcquireCalled(false), |
| 48 | mTransformToDisplayInverse(false) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 49 | mCrop.makeInvalid(); |
| 50 | } |
| 51 | |
| 52 | size_t IGraphicBufferConsumer::BufferItem::getPodSize() const { |
| 53 | size_t c = sizeof(mCrop) + |
| 54 | sizeof(mTransform) + |
| 55 | sizeof(mScalingMode) + |
| 56 | sizeof(mTimestamp) + |
Andy McFadden | 3c25621 | 2013-08-16 14:55:39 -0700 | [diff] [blame] | 57 | sizeof(mIsAutoTimestamp) + |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 58 | sizeof(mDataSpace) + |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 59 | sizeof(mFrameNumber) + |
| 60 | sizeof(mBuf) + |
| 61 | sizeof(mIsDroppable) + |
Mathias Agopian | c1c05de | 2013-09-17 23:45:22 -0700 | [diff] [blame] | 62 | sizeof(mAcquireCalled) + |
| 63 | sizeof(mTransformToDisplayInverse); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 64 | return c; |
| 65 | } |
| 66 | |
| 67 | size_t IGraphicBufferConsumer::BufferItem::getFlattenedSize() const { |
| 68 | size_t c = 0; |
| 69 | if (mGraphicBuffer != 0) { |
| 70 | c += mGraphicBuffer->getFlattenedSize(); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 71 | c = FlattenableUtils::align<4>(c); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 72 | } |
| 73 | if (mFence != 0) { |
| 74 | c += mFence->getFlattenedSize(); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 75 | c = FlattenableUtils::align<4>(c); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 76 | } |
| 77 | return sizeof(int32_t) + c + getPodSize(); |
| 78 | } |
| 79 | |
| 80 | size_t IGraphicBufferConsumer::BufferItem::getFdCount() const { |
| 81 | size_t c = 0; |
| 82 | if (mGraphicBuffer != 0) { |
| 83 | c += mGraphicBuffer->getFdCount(); |
| 84 | } |
| 85 | if (mFence != 0) { |
| 86 | c += mFence->getFdCount(); |
| 87 | } |
| 88 | return c; |
| 89 | } |
| 90 | |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 91 | static void writeBoolAsInt(void*& buffer, size_t& size, bool b) { |
| 92 | FlattenableUtils::write(buffer, size, static_cast<int32_t>(b)); |
| 93 | } |
| 94 | |
| 95 | static bool readBoolFromInt(void const*& buffer, size_t& size) { |
| 96 | int32_t i; |
| 97 | FlattenableUtils::read(buffer, size, i); |
| 98 | return static_cast<bool>(i); |
| 99 | } |
| 100 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 101 | status_t IGraphicBufferConsumer::BufferItem::flatten( |
| 102 | void*& buffer, size_t& size, int*& fds, size_t& count) const { |
| 103 | |
| 104 | // make sure we have enough space |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 105 | if (size < BufferItem::getFlattenedSize()) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 106 | return NO_MEMORY; |
| 107 | } |
| 108 | |
| 109 | // content flags are stored first |
| 110 | uint32_t& flags = *static_cast<uint32_t*>(buffer); |
| 111 | |
| 112 | // advance the pointer |
| 113 | FlattenableUtils::advance(buffer, size, sizeof(uint32_t)); |
| 114 | |
| 115 | flags = 0; |
| 116 | if (mGraphicBuffer != 0) { |
| 117 | status_t err = mGraphicBuffer->flatten(buffer, size, fds, count); |
| 118 | if (err) return err; |
| 119 | size -= FlattenableUtils::align<4>(buffer); |
| 120 | flags |= 1; |
| 121 | } |
| 122 | if (mFence != 0) { |
| 123 | status_t err = mFence->flatten(buffer, size, fds, count); |
| 124 | if (err) return err; |
| 125 | size -= FlattenableUtils::align<4>(buffer); |
| 126 | flags |= 2; |
| 127 | } |
| 128 | |
| 129 | // check we have enough space (in case flattening the fence/graphicbuffer lied to us) |
| 130 | if (size < getPodSize()) { |
| 131 | return NO_MEMORY; |
| 132 | } |
| 133 | |
| 134 | FlattenableUtils::write(buffer, size, mCrop); |
| 135 | FlattenableUtils::write(buffer, size, mTransform); |
| 136 | FlattenableUtils::write(buffer, size, mScalingMode); |
| 137 | FlattenableUtils::write(buffer, size, mTimestamp); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 138 | writeBoolAsInt(buffer, size, mIsAutoTimestamp); |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 139 | FlattenableUtils::write(buffer, size, mDataSpace); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 140 | FlattenableUtils::write(buffer, size, mFrameNumber); |
| 141 | FlattenableUtils::write(buffer, size, mBuf); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 142 | writeBoolAsInt(buffer, size, mIsDroppable); |
| 143 | writeBoolAsInt(buffer, size, mAcquireCalled); |
| 144 | writeBoolAsInt(buffer, size, mTransformToDisplayInverse); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 145 | |
| 146 | return NO_ERROR; |
| 147 | } |
| 148 | |
| 149 | status_t IGraphicBufferConsumer::BufferItem::unflatten( |
| 150 | void const*& buffer, size_t& size, int const*& fds, size_t& count) { |
| 151 | |
| 152 | if (size < sizeof(uint32_t)) |
| 153 | return NO_MEMORY; |
| 154 | |
| 155 | uint32_t flags = 0; |
| 156 | FlattenableUtils::read(buffer, size, flags); |
| 157 | |
| 158 | if (flags & 1) { |
| 159 | mGraphicBuffer = new GraphicBuffer(); |
| 160 | status_t err = mGraphicBuffer->unflatten(buffer, size, fds, count); |
| 161 | if (err) return err; |
| 162 | size -= FlattenableUtils::align<4>(buffer); |
| 163 | } |
| 164 | |
| 165 | if (flags & 2) { |
| 166 | mFence = new Fence(); |
| 167 | status_t err = mFence->unflatten(buffer, size, fds, count); |
| 168 | if (err) return err; |
| 169 | size -= FlattenableUtils::align<4>(buffer); |
| 170 | } |
| 171 | |
| 172 | // check we have enough space |
| 173 | if (size < getPodSize()) { |
| 174 | return NO_MEMORY; |
| 175 | } |
| 176 | |
| 177 | FlattenableUtils::read(buffer, size, mCrop); |
| 178 | FlattenableUtils::read(buffer, size, mTransform); |
| 179 | FlattenableUtils::read(buffer, size, mScalingMode); |
| 180 | FlattenableUtils::read(buffer, size, mTimestamp); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 181 | mIsAutoTimestamp = readBoolFromInt(buffer, size); |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 182 | FlattenableUtils::read(buffer, size, mDataSpace); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 183 | FlattenableUtils::read(buffer, size, mFrameNumber); |
| 184 | FlattenableUtils::read(buffer, size, mBuf); |
Dan Stoza | 1a0b861 | 2014-03-20 15:36:31 -0700 | [diff] [blame] | 185 | mIsDroppable = readBoolFromInt(buffer, size); |
| 186 | mAcquireCalled = readBoolFromInt(buffer, size); |
| 187 | mTransformToDisplayInverse = readBoolFromInt(buffer, size); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 188 | |
| 189 | return NO_ERROR; |
| 190 | } |
| 191 | |
| 192 | // --------------------------------------------------------------------------- |
| 193 | |
| 194 | enum { |
| 195 | ACQUIRE_BUFFER = IBinder::FIRST_CALL_TRANSACTION, |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 196 | DETACH_BUFFER, |
| 197 | ATTACH_BUFFER, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 198 | RELEASE_BUFFER, |
| 199 | CONSUMER_CONNECT, |
| 200 | CONSUMER_DISCONNECT, |
| 201 | GET_RELEASED_BUFFERS, |
| 202 | SET_DEFAULT_BUFFER_SIZE, |
| 203 | SET_DEFAULT_MAX_BUFFER_COUNT, |
| 204 | DISABLE_ASYNC_BUFFER, |
| 205 | SET_MAX_ACQUIRED_BUFFER_COUNT, |
| 206 | SET_CONSUMER_NAME, |
| 207 | SET_DEFAULT_BUFFER_FORMAT, |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 208 | SET_DEFAULT_BUFFER_DATA_SPACE, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 209 | SET_CONSUMER_USAGE_BITS, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 210 | SET_TRANSFORM_HINT, |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 211 | GET_SIDEBAND_STREAM, |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 212 | DUMP, |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | |
| 216 | class BpGraphicBufferConsumer : public BpInterface<IGraphicBufferConsumer> |
| 217 | { |
| 218 | public: |
| 219 | BpGraphicBufferConsumer(const sp<IBinder>& impl) |
| 220 | : BpInterface<IGraphicBufferConsumer>(impl) |
| 221 | { |
| 222 | } |
| 223 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 224 | virtual ~BpGraphicBufferConsumer(); |
| 225 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 226 | virtual status_t acquireBuffer(BufferItem *buffer, nsecs_t presentWhen) { |
| 227 | Parcel data, reply; |
| 228 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 229 | data.writeInt64(presentWhen); |
| 230 | status_t result = remote()->transact(ACQUIRE_BUFFER, data, &reply); |
| 231 | if (result != NO_ERROR) { |
| 232 | return result; |
| 233 | } |
| 234 | result = reply.read(*buffer); |
| 235 | if (result != NO_ERROR) { |
| 236 | return result; |
| 237 | } |
| 238 | return reply.readInt32(); |
| 239 | } |
| 240 | |
Dan Stoza | de7100a | 2015-03-11 16:38:47 -0700 | [diff] [blame^] | 241 | virtual status_t acquireBuffer(android::BufferItem* buffer, |
| 242 | nsecs_t presentWhen) { |
| 243 | if (buffer == nullptr) { |
| 244 | return BAD_VALUE; |
| 245 | } |
| 246 | |
| 247 | BufferItem item; |
| 248 | status_t result = acquireBuffer(&item, presentWhen); |
| 249 | if (result != NO_ERROR) { |
| 250 | return result; |
| 251 | } |
| 252 | *buffer = item; |
| 253 | return NO_ERROR; |
| 254 | } |
| 255 | |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 256 | virtual status_t detachBuffer(int slot) { |
| 257 | Parcel data, reply; |
| 258 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 259 | data.writeInt32(slot); |
| 260 | status_t result = remote()->transact(DETACH_BUFFER, data, &reply); |
| 261 | if (result != NO_ERROR) { |
| 262 | return result; |
| 263 | } |
| 264 | result = reply.readInt32(); |
| 265 | return result; |
| 266 | } |
| 267 | |
| 268 | virtual status_t attachBuffer(int* slot, const sp<GraphicBuffer>& buffer) { |
| 269 | Parcel data, reply; |
| 270 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 271 | data.write(*buffer.get()); |
| 272 | status_t result = remote()->transact(ATTACH_BUFFER, data, &reply); |
| 273 | if (result != NO_ERROR) { |
| 274 | return result; |
| 275 | } |
| 276 | *slot = reply.readInt32(); |
| 277 | result = reply.readInt32(); |
| 278 | return result; |
| 279 | } |
| 280 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 281 | virtual status_t releaseBuffer(int buf, uint64_t frameNumber, |
Igor Murashkin | 7d2d160 | 2013-11-12 18:02:20 -0800 | [diff] [blame] | 282 | EGLDisplay display __attribute__((unused)), EGLSyncKHR fence __attribute__((unused)), |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 283 | const sp<Fence>& releaseFence) { |
| 284 | Parcel data, reply; |
| 285 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 286 | data.writeInt32(buf); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 287 | data.writeInt64(static_cast<int64_t>(frameNumber)); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 288 | data.write(*releaseFence); |
| 289 | status_t result = remote()->transact(RELEASE_BUFFER, data, &reply); |
| 290 | if (result != NO_ERROR) { |
| 291 | return result; |
| 292 | } |
| 293 | return reply.readInt32(); |
| 294 | } |
| 295 | |
| 296 | virtual status_t consumerConnect(const sp<IConsumerListener>& consumer, bool controlledByApp) { |
| 297 | Parcel data, reply; |
| 298 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 299 | data.writeStrongBinder(IInterface::asBinder(consumer)); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 300 | data.writeInt32(controlledByApp); |
| 301 | status_t result = remote()->transact(CONSUMER_CONNECT, data, &reply); |
| 302 | if (result != NO_ERROR) { |
| 303 | return result; |
| 304 | } |
| 305 | return reply.readInt32(); |
| 306 | } |
| 307 | |
| 308 | virtual status_t consumerDisconnect() { |
| 309 | Parcel data, reply; |
| 310 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 311 | status_t result = remote()->transact(CONSUMER_DISCONNECT, data, &reply); |
| 312 | if (result != NO_ERROR) { |
| 313 | return result; |
| 314 | } |
| 315 | return reply.readInt32(); |
| 316 | } |
| 317 | |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 318 | virtual status_t getReleasedBuffers(uint64_t* slotMask) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 319 | Parcel data, reply; |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 320 | if (slotMask == NULL) { |
| 321 | ALOGE("getReleasedBuffers: slotMask must not be NULL"); |
| 322 | return BAD_VALUE; |
| 323 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 324 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 325 | status_t result = remote()->transact(GET_RELEASED_BUFFERS, data, &reply); |
| 326 | if (result != NO_ERROR) { |
| 327 | return result; |
| 328 | } |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 329 | *slotMask = static_cast<uint64_t>(reply.readInt64()); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 330 | return reply.readInt32(); |
| 331 | } |
| 332 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 333 | virtual status_t setDefaultBufferSize(uint32_t width, uint32_t height) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 334 | Parcel data, reply; |
| 335 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 336 | data.writeUint32(width); |
| 337 | data.writeUint32(height); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 338 | status_t result = remote()->transact(SET_DEFAULT_BUFFER_SIZE, data, &reply); |
| 339 | if (result != NO_ERROR) { |
| 340 | return result; |
| 341 | } |
| 342 | return reply.readInt32(); |
| 343 | } |
| 344 | |
| 345 | virtual status_t setDefaultMaxBufferCount(int bufferCount) { |
| 346 | Parcel data, reply; |
| 347 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 348 | data.writeInt32(bufferCount); |
| 349 | status_t result = remote()->transact(SET_DEFAULT_MAX_BUFFER_COUNT, data, &reply); |
| 350 | if (result != NO_ERROR) { |
| 351 | return result; |
| 352 | } |
| 353 | return reply.readInt32(); |
| 354 | } |
| 355 | |
| 356 | virtual status_t disableAsyncBuffer() { |
| 357 | Parcel data, reply; |
| 358 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 359 | status_t result = remote()->transact(DISABLE_ASYNC_BUFFER, data, &reply); |
| 360 | if (result != NO_ERROR) { |
| 361 | return result; |
| 362 | } |
| 363 | return reply.readInt32(); |
| 364 | } |
| 365 | |
| 366 | virtual status_t setMaxAcquiredBufferCount(int maxAcquiredBuffers) { |
| 367 | Parcel data, reply; |
| 368 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 369 | data.writeInt32(maxAcquiredBuffers); |
| 370 | status_t result = remote()->transact(SET_MAX_ACQUIRED_BUFFER_COUNT, data, &reply); |
| 371 | if (result != NO_ERROR) { |
| 372 | return result; |
| 373 | } |
| 374 | return reply.readInt32(); |
| 375 | } |
| 376 | |
| 377 | virtual void setConsumerName(const String8& name) { |
| 378 | Parcel data, reply; |
| 379 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 380 | data.writeString8(name); |
| 381 | remote()->transact(SET_CONSUMER_NAME, data, &reply); |
| 382 | } |
| 383 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 384 | virtual status_t setDefaultBufferFormat(PixelFormat defaultFormat) { |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 385 | Parcel data, reply; |
| 386 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 387 | data.writeInt32(static_cast<int32_t>(defaultFormat)); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 388 | status_t result = remote()->transact(SET_DEFAULT_BUFFER_FORMAT, data, &reply); |
| 389 | if (result != NO_ERROR) { |
| 390 | return result; |
| 391 | } |
| 392 | return reply.readInt32(); |
| 393 | } |
| 394 | |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 395 | virtual status_t setDefaultBufferDataSpace( |
| 396 | android_dataspace defaultDataSpace) { |
| 397 | Parcel data, reply; |
| 398 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 399 | data.writeInt32(static_cast<int32_t>(defaultDataSpace)); |
| 400 | status_t result = remote()->transact(SET_DEFAULT_BUFFER_DATA_SPACE, |
| 401 | data, &reply); |
| 402 | if (result != NO_ERROR) { |
| 403 | return result; |
| 404 | } |
| 405 | return reply.readInt32(); |
| 406 | } |
| 407 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 408 | virtual status_t setConsumerUsageBits(uint32_t usage) { |
| 409 | Parcel data, reply; |
| 410 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 411 | data.writeUint32(usage); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 412 | status_t result = remote()->transact(SET_CONSUMER_USAGE_BITS, data, &reply); |
| 413 | if (result != NO_ERROR) { |
| 414 | return result; |
| 415 | } |
| 416 | return reply.readInt32(); |
| 417 | } |
| 418 | |
| 419 | virtual status_t setTransformHint(uint32_t hint) { |
| 420 | Parcel data, reply; |
| 421 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 422 | data.writeUint32(hint); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 423 | status_t result = remote()->transact(SET_TRANSFORM_HINT, data, &reply); |
| 424 | if (result != NO_ERROR) { |
| 425 | return result; |
| 426 | } |
| 427 | return reply.readInt32(); |
| 428 | } |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 429 | |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 430 | virtual sp<NativeHandle> getSidebandStream() const { |
| 431 | Parcel data, reply; |
| 432 | status_t err; |
| 433 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 434 | if ((err = remote()->transact(GET_SIDEBAND_STREAM, data, &reply)) != NO_ERROR) { |
| 435 | return NULL; |
| 436 | } |
| 437 | sp<NativeHandle> stream; |
| 438 | if (reply.readInt32()) { |
Wonsik Kim | 0ec54e1 | 2014-03-21 10:46:24 +0900 | [diff] [blame] | 439 | stream = NativeHandle::create(reply.readNativeHandle(), true); |
Jesse Hall | 399184a | 2014-03-03 15:42:54 -0800 | [diff] [blame] | 440 | } |
| 441 | return stream; |
| 442 | } |
| 443 | |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 444 | virtual void dump(String8& result, const char* prefix) const { |
| 445 | Parcel data, reply; |
| 446 | data.writeInterfaceToken(IGraphicBufferConsumer::getInterfaceDescriptor()); |
| 447 | data.writeString8(result); |
| 448 | data.writeString8(String8(prefix ? prefix : "")); |
| 449 | remote()->transact(DUMP, data, &reply); |
| 450 | reply.readString8(); |
| 451 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 452 | }; |
| 453 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 454 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 455 | // translation unit (see clang warning -Wweak-vtables) |
| 456 | BpGraphicBufferConsumer::~BpGraphicBufferConsumer() {} |
| 457 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 458 | IMPLEMENT_META_INTERFACE(GraphicBufferConsumer, "android.gui.IGraphicBufferConsumer"); |
| 459 | |
| 460 | // ---------------------------------------------------------------------- |
| 461 | |
| 462 | status_t BnGraphicBufferConsumer::onTransact( |
| 463 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 464 | { |
| 465 | switch(code) { |
| 466 | case ACQUIRE_BUFFER: { |
| 467 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 468 | BufferItem item; |
| 469 | int64_t presentWhen = data.readInt64(); |
| 470 | status_t result = acquireBuffer(&item, presentWhen); |
| 471 | status_t err = reply->write(item); |
| 472 | if (err) return err; |
| 473 | reply->writeInt32(result); |
| 474 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 475 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 476 | case DETACH_BUFFER: { |
| 477 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 478 | int slot = data.readInt32(); |
| 479 | int result = detachBuffer(slot); |
| 480 | reply->writeInt32(result); |
| 481 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 482 | } |
Dan Stoza | 9f3053d | 2014-03-06 15:14:33 -0800 | [diff] [blame] | 483 | case ATTACH_BUFFER: { |
| 484 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 485 | sp<GraphicBuffer> buffer = new GraphicBuffer(); |
| 486 | data.read(*buffer.get()); |
| 487 | int slot; |
| 488 | int result = attachBuffer(&slot, buffer); |
| 489 | reply->writeInt32(slot); |
| 490 | reply->writeInt32(result); |
| 491 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 492 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 493 | case RELEASE_BUFFER: { |
| 494 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 495 | int buf = data.readInt32(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 496 | uint64_t frameNumber = static_cast<uint64_t>(data.readInt64()); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 497 | sp<Fence> releaseFence = new Fence(); |
| 498 | status_t err = data.read(*releaseFence); |
| 499 | if (err) return err; |
| 500 | status_t result = releaseBuffer(buf, frameNumber, |
| 501 | EGL_NO_DISPLAY, EGL_NO_SYNC_KHR, releaseFence); |
| 502 | reply->writeInt32(result); |
| 503 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 504 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 505 | case CONSUMER_CONNECT: { |
| 506 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 507 | sp<IConsumerListener> consumer = IConsumerListener::asInterface( data.readStrongBinder() ); |
| 508 | bool controlledByApp = data.readInt32(); |
| 509 | status_t result = consumerConnect(consumer, controlledByApp); |
| 510 | reply->writeInt32(result); |
| 511 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 512 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 513 | case CONSUMER_DISCONNECT: { |
| 514 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 515 | status_t result = consumerDisconnect(); |
| 516 | reply->writeInt32(result); |
| 517 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 518 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 519 | case GET_RELEASED_BUFFERS: { |
| 520 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | febd4f4 | 2014-04-09 16:14:51 -0700 | [diff] [blame] | 521 | uint64_t slotMask; |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 522 | status_t result = getReleasedBuffers(&slotMask); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 523 | reply->writeInt64(static_cast<int64_t>(slotMask)); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 524 | reply->writeInt32(result); |
| 525 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 526 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 527 | case SET_DEFAULT_BUFFER_SIZE: { |
| 528 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 529 | uint32_t width = data.readUint32(); |
| 530 | uint32_t height = data.readUint32(); |
| 531 | status_t result = setDefaultBufferSize(width, height); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 532 | reply->writeInt32(result); |
| 533 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 534 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 535 | case SET_DEFAULT_MAX_BUFFER_COUNT: { |
| 536 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 537 | int bufferCount = data.readInt32(); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 538 | status_t result = setDefaultMaxBufferCount(bufferCount); |
| 539 | reply->writeInt32(result); |
| 540 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 541 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 542 | case DISABLE_ASYNC_BUFFER: { |
| 543 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 544 | status_t result = disableAsyncBuffer(); |
| 545 | reply->writeInt32(result); |
| 546 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 547 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 548 | case SET_MAX_ACQUIRED_BUFFER_COUNT: { |
| 549 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 550 | int maxAcquiredBuffers = data.readInt32(); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 551 | status_t result = setMaxAcquiredBufferCount(maxAcquiredBuffers); |
| 552 | reply->writeInt32(result); |
| 553 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 554 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 555 | case SET_CONSUMER_NAME: { |
| 556 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 557 | setConsumerName( data.readString8() ); |
| 558 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 559 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 560 | case SET_DEFAULT_BUFFER_FORMAT: { |
| 561 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 562 | PixelFormat defaultFormat = static_cast<PixelFormat>(data.readInt32()); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 563 | status_t result = setDefaultBufferFormat(defaultFormat); |
| 564 | reply->writeInt32(result); |
| 565 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 566 | } |
Eino-Ville Talvala | 5b75a51 | 2015-02-19 16:10:43 -0800 | [diff] [blame] | 567 | case SET_DEFAULT_BUFFER_DATA_SPACE: { |
| 568 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 569 | android_dataspace defaultDataSpace = |
| 570 | static_cast<android_dataspace>(data.readInt32()); |
| 571 | status_t result = setDefaultBufferDataSpace(defaultDataSpace); |
| 572 | reply->writeInt32(result); |
| 573 | return NO_ERROR; |
| 574 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 575 | case SET_CONSUMER_USAGE_BITS: { |
| 576 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 577 | uint32_t usage = data.readUint32(); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 578 | status_t result = setConsumerUsageBits(usage); |
| 579 | reply->writeInt32(result); |
| 580 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 581 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 582 | case SET_TRANSFORM_HINT: { |
| 583 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 584 | uint32_t hint = data.readUint32(); |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 585 | status_t result = setTransformHint(hint); |
| 586 | reply->writeInt32(result); |
| 587 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 588 | } |
Mathias Agopian | db89edc | 2013-08-02 01:40:18 -0700 | [diff] [blame] | 589 | case DUMP: { |
| 590 | CHECK_INTERFACE(IGraphicBufferConsumer, data, reply); |
| 591 | String8 result = data.readString8(); |
| 592 | String8 prefix = data.readString8(); |
| 593 | static_cast<IGraphicBufferConsumer*>(this)->dump(result, prefix); |
| 594 | reply->writeString8(result); |
| 595 | return NO_ERROR; |
| 596 | } |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 597 | } |
| 598 | return BBinder::onTransact(code, data, reply, flags); |
| 599 | } |
| 600 | |
| 601 | }; // namespace android |