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