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