Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "BufferQueueLayer.h" |
| 18 | #include "LayerRejecter.h" |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 19 | |
| 20 | #include <system/window.h> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | BufferQueueLayer::BufferQueueLayer(SurfaceFlinger* flinger, const sp<Client>& client, |
| 25 | const String8& name, uint32_t w, uint32_t h, uint32_t flags) |
| 26 | : BufferLayer(flinger, client, name, w, h, flags), |
| 27 | mConsumer(nullptr), |
| 28 | mProducer(nullptr), |
| 29 | mFormat(PIXEL_FORMAT_NONE), |
| 30 | mPreviousFrameNumber(0), |
| 31 | mUpdateTexImageFailed(false), |
| 32 | mQueueItemLock(), |
| 33 | mQueueItemCondition(), |
| 34 | mQueueItems(), |
| 35 | mLastFrameNumberReceived(0), |
| 36 | mAutoRefresh(false), |
| 37 | mActiveBufferSlot(BufferQueue::INVALID_BUFFER_SLOT), |
| 38 | mQueuedFrames(0), |
| 39 | mSidebandStreamChanged(false) { |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 40 | mCurrentState.requested_legacy = mCurrentState.active_legacy; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // ----------------------------------------------------------------------- |
| 44 | // Interface implementation for Layer |
| 45 | // ----------------------------------------------------------------------- |
| 46 | |
| 47 | void BufferQueueLayer::onLayerDisplayed(const sp<Fence>& releaseFence) { |
| 48 | mConsumer->setReleaseFence(releaseFence); |
| 49 | } |
| 50 | |
| 51 | void BufferQueueLayer::abandon() { |
| 52 | mConsumer->abandon(); |
| 53 | } |
| 54 | |
| 55 | void BufferQueueLayer::setTransformHint(uint32_t orientation) const { |
| 56 | mConsumer->setTransformHint(orientation); |
| 57 | } |
| 58 | |
| 59 | std::vector<OccupancyTracker::Segment> BufferQueueLayer::getOccupancyHistory(bool forceFlush) { |
| 60 | std::vector<OccupancyTracker::Segment> history; |
| 61 | status_t result = mConsumer->getOccupancyHistory(forceFlush, &history); |
| 62 | if (result != NO_ERROR) { |
| 63 | ALOGW("[%s] Failed to obtain occupancy history (%d)", mName.string(), result); |
| 64 | return {}; |
| 65 | } |
| 66 | return history; |
| 67 | } |
| 68 | |
| 69 | bool BufferQueueLayer::getTransformToDisplayInverse() const { |
| 70 | return mConsumer->getTransformToDisplayInverse(); |
| 71 | } |
| 72 | |
| 73 | void BufferQueueLayer::releasePendingBuffer(nsecs_t dequeueReadyTime) { |
| 74 | if (!mConsumer->releasePendingBuffer()) { |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | auto releaseFenceTime = std::make_shared<FenceTime>(mConsumer->getPrevFinalReleaseFence()); |
| 79 | mReleaseTimeline.updateSignalTimes(); |
| 80 | mReleaseTimeline.push(releaseFenceTime); |
| 81 | |
| 82 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 83 | if (mPreviousFrameNumber != 0) { |
| 84 | mFrameEventHistory.addRelease(mPreviousFrameNumber, dequeueReadyTime, |
| 85 | std::move(releaseFenceTime)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void BufferQueueLayer::setDefaultBufferSize(uint32_t w, uint32_t h) { |
| 90 | mConsumer->setDefaultBufferSize(w, h); |
| 91 | } |
| 92 | |
| 93 | int32_t BufferQueueLayer::getQueuedFrameCount() const { |
| 94 | return mQueuedFrames; |
| 95 | } |
| 96 | |
| 97 | bool BufferQueueLayer::shouldPresentNow(const DispSync& dispSync) const { |
| 98 | if (getSidebandStreamChanged() || getAutoRefresh()) { |
| 99 | return true; |
| 100 | } |
| 101 | |
| 102 | if (!hasDrawingBuffer()) { |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | Mutex::Autolock lock(mQueueItemLock); |
| 107 | |
| 108 | const int64_t addedTime = mQueueItems[0].mTimestamp; |
| 109 | const nsecs_t expectedPresentTime = mConsumer->computeExpectedPresent(dispSync); |
| 110 | |
| 111 | // Ignore timestamps more than a second in the future |
| 112 | const bool isPlausible = addedTime < (expectedPresentTime + s2ns(1)); |
| 113 | ALOGW_IF(!isPlausible, |
| 114 | "[%s] Timestamp %" PRId64 " seems implausible " |
| 115 | "relative to expectedPresent %" PRId64, |
| 116 | mName.string(), addedTime, expectedPresentTime); |
| 117 | |
| 118 | const bool isDue = addedTime < expectedPresentTime; |
| 119 | return isDue || !isPlausible; |
| 120 | } |
| 121 | |
| 122 | // ----------------------------------------------------------------------- |
| 123 | // Interface implementation for BufferLayer |
| 124 | // ----------------------------------------------------------------------- |
| 125 | |
| 126 | bool BufferQueueLayer::fenceHasSignaled() const { |
| 127 | if (latchUnsignaledBuffers()) { |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | if (!hasDrawingBuffer()) { |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | Mutex::Autolock lock(mQueueItemLock); |
| 136 | if (mQueueItems[0].mIsDroppable) { |
| 137 | // Even though this buffer's fence may not have signaled yet, it could |
| 138 | // be replaced by another buffer before it has a chance to, which means |
| 139 | // that it's possible to get into a situation where a buffer is never |
| 140 | // able to be latched. To avoid this, grab this buffer anyway. |
| 141 | return true; |
| 142 | } |
| 143 | return mQueueItems[0].mFenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING; |
| 144 | } |
| 145 | |
| 146 | nsecs_t BufferQueueLayer::getDesiredPresentTime() { |
| 147 | return mConsumer->getTimestamp(); |
| 148 | } |
| 149 | |
| 150 | std::shared_ptr<FenceTime> BufferQueueLayer::getCurrentFenceTime() const { |
| 151 | return mConsumer->getCurrentFenceTime(); |
| 152 | } |
| 153 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 154 | void BufferQueueLayer::getDrawingTransformMatrix(float *matrix) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 155 | return mConsumer->getTransformMatrix(matrix); |
| 156 | } |
| 157 | |
| 158 | // NOTE: SurfaceFlinger's definitions of "Current" and "Drawing" do not neatly map to BufferQueue's |
| 159 | // These functions get the fields for the frame that is currently in SurfaceFlinger's Drawing state |
| 160 | // so the functions start with "getDrawing". The data is retrieved from the BufferQueueConsumer's |
| 161 | // current buffer so the consumer functions start with "getCurrent". |
| 162 | // |
| 163 | // This results in the rather confusing functions below. |
| 164 | uint32_t BufferQueueLayer::getDrawingTransform() const { |
| 165 | return mConsumer->getCurrentTransform(); |
| 166 | } |
| 167 | |
| 168 | ui::Dataspace BufferQueueLayer::getDrawingDataSpace() const { |
| 169 | return mConsumer->getCurrentDataSpace(); |
| 170 | } |
| 171 | |
| 172 | Rect BufferQueueLayer::getDrawingCrop() const { |
| 173 | return mConsumer->getCurrentCrop(); |
| 174 | } |
| 175 | |
| 176 | uint32_t BufferQueueLayer::getDrawingScalingMode() const { |
| 177 | return mConsumer->getCurrentScalingMode(); |
| 178 | } |
| 179 | |
| 180 | Region BufferQueueLayer::getDrawingSurfaceDamage() const { |
| 181 | return mConsumer->getSurfaceDamage(); |
| 182 | } |
| 183 | |
| 184 | const HdrMetadata& BufferQueueLayer::getDrawingHdrMetadata() const { |
| 185 | return mConsumer->getCurrentHdrMetadata(); |
| 186 | } |
| 187 | |
| 188 | int BufferQueueLayer::getDrawingApi() const { |
| 189 | return mConsumer->getCurrentApi(); |
| 190 | } |
| 191 | |
| 192 | PixelFormat BufferQueueLayer::getPixelFormat() const { |
| 193 | return mFormat; |
| 194 | } |
| 195 | |
| 196 | uint64_t BufferQueueLayer::getFrameNumber() const { |
| 197 | Mutex::Autolock lock(mQueueItemLock); |
| 198 | return mQueueItems[0].mFrameNumber; |
| 199 | } |
| 200 | |
| 201 | bool BufferQueueLayer::getAutoRefresh() const { |
| 202 | return mAutoRefresh; |
| 203 | } |
| 204 | |
| 205 | bool BufferQueueLayer::getSidebandStreamChanged() const { |
| 206 | return mSidebandStreamChanged; |
| 207 | } |
| 208 | |
| 209 | std::optional<Region> BufferQueueLayer::latchSidebandStream(bool& recomputeVisibleRegions) { |
| 210 | if (android_atomic_acquire_cas(true, false, &mSidebandStreamChanged) == 0) { |
| 211 | // mSidebandStreamChanged was true |
| 212 | // replicated in LayerBE until FE/BE is ready to be synchronized |
| 213 | getBE().compositionInfo.hwc.sidebandStream = mConsumer->getSidebandStream(); |
| 214 | if (getBE().compositionInfo.hwc.sidebandStream != nullptr) { |
| 215 | setTransactionFlags(eTransactionNeeded); |
| 216 | mFlinger->setTransactionFlags(eTraversalNeeded); |
| 217 | } |
| 218 | recomputeVisibleRegions = true; |
| 219 | |
| 220 | const State& s(getDrawingState()); |
Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 221 | return getTransform().transform(Region(Rect(s.active_legacy.w, s.active_legacy.h))); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 222 | } |
| 223 | return {}; |
| 224 | } |
| 225 | |
| 226 | bool BufferQueueLayer::hasDrawingBuffer() const { |
| 227 | return mQueuedFrames > 0; |
| 228 | } |
| 229 | |
Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 230 | void BufferQueueLayer::setFilteringEnabled(bool enabled) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 231 | return mConsumer->setFilteringEnabled(enabled); |
| 232 | } |
| 233 | |
| 234 | status_t BufferQueueLayer::bindTextureImage() const { |
| 235 | return mConsumer->bindTextureImage(); |
| 236 | } |
| 237 | |
| 238 | status_t BufferQueueLayer::updateTexImage(bool& recomputeVisibleRegions, nsecs_t latchTime) { |
| 239 | // This boolean is used to make sure that SurfaceFlinger's shadow copy |
| 240 | // of the buffer queue isn't modified when the buffer queue is returning |
| 241 | // BufferItem's that weren't actually queued. This can happen in shared |
| 242 | // buffer mode. |
| 243 | bool queuedBuffer = false; |
| 244 | LayerRejecter r(mDrawingState, getCurrentState(), recomputeVisibleRegions, |
| 245 | getProducerStickyTransform() != 0, mName.string(), mOverrideScalingMode, |
| 246 | getTransformToDisplayInverse(), mFreezeGeometryUpdates); |
Lloyd Pique | 41be5d2 | 2018-06-21 13:11:48 -0700 | [diff] [blame] | 247 | status_t updateResult = |
| 248 | mConsumer->updateTexImage(&r, *mFlinger->mPrimaryDispSync, &mAutoRefresh, &queuedBuffer, |
| 249 | mLastFrameNumberReceived); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 250 | if (updateResult == BufferQueue::PRESENT_LATER) { |
| 251 | // Producer doesn't want buffer to be displayed yet. Signal a |
| 252 | // layer update so we check again at the next opportunity. |
| 253 | mFlinger->signalLayerUpdate(); |
| 254 | return BAD_VALUE; |
| 255 | } else if (updateResult == BufferLayerConsumer::BUFFER_REJECTED) { |
| 256 | // If the buffer has been rejected, remove it from the shadow queue |
| 257 | // and return early |
| 258 | if (queuedBuffer) { |
| 259 | Mutex::Autolock lock(mQueueItemLock); |
| 260 | mTimeStats.removeTimeRecord(getName().c_str(), mQueueItems[0].mFrameNumber); |
| 261 | mQueueItems.removeAt(0); |
| 262 | android_atomic_dec(&mQueuedFrames); |
| 263 | } |
| 264 | return BAD_VALUE; |
| 265 | } else if (updateResult != NO_ERROR || mUpdateTexImageFailed) { |
| 266 | // This can occur if something goes wrong when trying to create the |
| 267 | // EGLImage for this buffer. If this happens, the buffer has already |
| 268 | // been released, so we need to clean up the queue and bug out |
| 269 | // early. |
| 270 | if (queuedBuffer) { |
| 271 | Mutex::Autolock lock(mQueueItemLock); |
| 272 | mQueueItems.clear(); |
| 273 | android_atomic_and(0, &mQueuedFrames); |
| 274 | mTimeStats.clearLayerRecord(getName().c_str()); |
| 275 | } |
| 276 | |
| 277 | // Once we have hit this state, the shadow queue may no longer |
| 278 | // correctly reflect the incoming BufferQueue's contents, so even if |
| 279 | // updateTexImage starts working, the only safe course of action is |
| 280 | // to continue to ignore updates. |
| 281 | mUpdateTexImageFailed = true; |
| 282 | |
| 283 | return BAD_VALUE; |
| 284 | } |
| 285 | |
| 286 | if (queuedBuffer) { |
| 287 | // Autolock scope |
| 288 | auto currentFrameNumber = mConsumer->getFrameNumber(); |
| 289 | |
| 290 | Mutex::Autolock lock(mQueueItemLock); |
| 291 | |
| 292 | // Remove any stale buffers that have been dropped during |
| 293 | // updateTexImage |
| 294 | while (mQueueItems[0].mFrameNumber != currentFrameNumber) { |
| 295 | mTimeStats.removeTimeRecord(getName().c_str(), mQueueItems[0].mFrameNumber); |
| 296 | mQueueItems.removeAt(0); |
| 297 | android_atomic_dec(&mQueuedFrames); |
| 298 | } |
| 299 | |
| 300 | const std::string layerName(getName().c_str()); |
| 301 | mTimeStats.setAcquireFence(layerName, currentFrameNumber, mQueueItems[0].mFenceTime); |
| 302 | mTimeStats.setLatchTime(layerName, currentFrameNumber, latchTime); |
| 303 | |
| 304 | mQueueItems.removeAt(0); |
| 305 | } |
| 306 | |
| 307 | // Decrement the queued-frames count. Signal another event if we |
| 308 | // have more frames pending. |
| 309 | if ((queuedBuffer && android_atomic_dec(&mQueuedFrames) > 1) || mAutoRefresh) { |
| 310 | mFlinger->signalLayerUpdate(); |
| 311 | } |
| 312 | |
| 313 | return NO_ERROR; |
| 314 | } |
| 315 | |
| 316 | status_t BufferQueueLayer::updateActiveBuffer() { |
| 317 | // update the active buffer |
| 318 | mActiveBuffer = mConsumer->getCurrentBuffer(&mActiveBufferSlot); |
| 319 | getBE().compositionInfo.mBuffer = mActiveBuffer; |
| 320 | getBE().compositionInfo.mBufferSlot = mActiveBufferSlot; |
| 321 | |
| 322 | if (mActiveBuffer == nullptr) { |
| 323 | // this can only happen if the very first buffer was rejected. |
| 324 | return BAD_VALUE; |
| 325 | } |
| 326 | return NO_ERROR; |
| 327 | } |
| 328 | |
| 329 | status_t BufferQueueLayer::updateFrameNumber(nsecs_t latchTime) { |
| 330 | mPreviousFrameNumber = mCurrentFrameNumber; |
| 331 | mCurrentFrameNumber = mConsumer->getFrameNumber(); |
| 332 | |
| 333 | { |
| 334 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 335 | mFrameEventHistory.addLatch(mCurrentFrameNumber, latchTime); |
| 336 | } |
| 337 | return NO_ERROR; |
| 338 | } |
| 339 | |
| 340 | void BufferQueueLayer::setHwcLayerBuffer(const sp<const DisplayDevice>& display) { |
| 341 | const auto displayId = display->getId(); |
| 342 | auto& hwcInfo = getBE().mHwcLayers[displayId]; |
| 343 | auto& hwcLayer = hwcInfo.layer; |
| 344 | |
| 345 | uint32_t hwcSlot = 0; |
| 346 | sp<GraphicBuffer> hwcBuffer; |
| 347 | hwcInfo.bufferCache.getHwcBuffer(mActiveBufferSlot, mActiveBuffer, &hwcSlot, &hwcBuffer); |
| 348 | |
| 349 | auto acquireFence = mConsumer->getCurrentFence(); |
| 350 | auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence); |
| 351 | if (error != HWC2::Error::None) { |
| 352 | ALOGE("[%s] Failed to set buffer %p: %s (%d)", mName.string(), |
| 353 | getBE().compositionInfo.mBuffer->handle, to_string(error).c_str(), |
| 354 | static_cast<int32_t>(error)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | // ----------------------------------------------------------------------- |
| 359 | // Interface implementation for BufferLayerConsumer::ContentsChangedListener |
| 360 | // ----------------------------------------------------------------------- |
| 361 | |
| 362 | void BufferQueueLayer::onFrameAvailable(const BufferItem& item) { |
| 363 | // Add this buffer from our internal queue tracker |
| 364 | { // Autolock scope |
| 365 | Mutex::Autolock lock(mQueueItemLock); |
| 366 | // Reset the frame number tracker when we receive the first buffer after |
| 367 | // a frame number reset |
| 368 | if (item.mFrameNumber == 1) { |
| 369 | mLastFrameNumberReceived = 0; |
| 370 | } |
| 371 | |
| 372 | // Ensure that callbacks are handled in order |
| 373 | while (item.mFrameNumber != mLastFrameNumberReceived + 1) { |
| 374 | status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500)); |
| 375 | if (result != NO_ERROR) { |
| 376 | ALOGE("[%s] Timed out waiting on callback", mName.string()); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | mQueueItems.push_back(item); |
| 381 | android_atomic_inc(&mQueuedFrames); |
| 382 | |
| 383 | // Wake up any pending callbacks |
| 384 | mLastFrameNumberReceived = item.mFrameNumber; |
| 385 | mQueueItemCondition.broadcast(); |
| 386 | } |
| 387 | |
| 388 | mFlinger->mInterceptor->saveBufferUpdate(this, item.mGraphicBuffer->getWidth(), |
| 389 | item.mGraphicBuffer->getHeight(), item.mFrameNumber); |
| 390 | mFlinger->signalLayerUpdate(); |
| 391 | } |
| 392 | |
| 393 | void BufferQueueLayer::onFrameReplaced(const BufferItem& item) { |
| 394 | { // Autolock scope |
| 395 | Mutex::Autolock lock(mQueueItemLock); |
| 396 | |
| 397 | // Ensure that callbacks are handled in order |
| 398 | while (item.mFrameNumber != mLastFrameNumberReceived + 1) { |
| 399 | status_t result = mQueueItemCondition.waitRelative(mQueueItemLock, ms2ns(500)); |
| 400 | if (result != NO_ERROR) { |
| 401 | ALOGE("[%s] Timed out waiting on callback", mName.string()); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | if (!hasDrawingBuffer()) { |
| 406 | ALOGE("Can't replace a frame on an empty queue"); |
| 407 | return; |
| 408 | } |
| 409 | mQueueItems.editItemAt(mQueueItems.size() - 1) = item; |
| 410 | |
| 411 | // Wake up any pending callbacks |
| 412 | mLastFrameNumberReceived = item.mFrameNumber; |
| 413 | mQueueItemCondition.broadcast(); |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | void BufferQueueLayer::onSidebandStreamChanged() { |
| 418 | if (android_atomic_release_cas(false, true, &mSidebandStreamChanged) == 0) { |
| 419 | // mSidebandStreamChanged was false |
| 420 | mFlinger->signalLayerUpdate(); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | // ----------------------------------------------------------------------- |
| 425 | |
| 426 | void BufferQueueLayer::onFirstRef() { |
Dan Stoza | 7b1b5a8 | 2018-07-31 16:00:21 -0700 | [diff] [blame] | 427 | BufferLayer::onFirstRef(); |
| 428 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 429 | // Creates a custom BufferQueue for SurfaceFlingerConsumer to use |
| 430 | sp<IGraphicBufferProducer> producer; |
| 431 | sp<IGraphicBufferConsumer> consumer; |
| 432 | BufferQueue::createBufferQueue(&producer, &consumer, true); |
| 433 | mProducer = new MonitoredProducer(producer, mFlinger, this); |
| 434 | { |
| 435 | // Grab the SF state lock during this since it's the only safe way to access RenderEngine |
| 436 | Mutex::Autolock lock(mFlinger->mStateLock); |
| 437 | mConsumer = |
| 438 | new BufferLayerConsumer(consumer, mFlinger->getRenderEngine(), mTextureName, this); |
| 439 | } |
| 440 | mConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
| 441 | mConsumer->setContentsChangedListener(this); |
| 442 | mConsumer->setName(mName); |
| 443 | |
| 444 | if (mFlinger->isLayerTripleBufferingDisabled()) { |
| 445 | mProducer->setMaxDequeuedBufferCount(2); |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | status_t BufferQueueLayer::setDefaultBufferProperties(uint32_t w, uint32_t h, PixelFormat format) { |
| 450 | uint32_t const maxSurfaceDims = |
Peiyong Lin | 3db4234 | 2018-08-16 09:15:59 -0700 | [diff] [blame] | 451 | std::min(mFlinger->getMaxTextureSize(), mFlinger->getMaxViewportDims()); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 452 | |
| 453 | // never allow a surface larger than what our underlying GL implementation |
| 454 | // can handle. |
| 455 | if ((uint32_t(w) > maxSurfaceDims) || (uint32_t(h) > maxSurfaceDims)) { |
| 456 | ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h)); |
| 457 | return BAD_VALUE; |
| 458 | } |
| 459 | |
| 460 | mFormat = format; |
| 461 | |
| 462 | setDefaultBufferSize(w, h); |
| 463 | mConsumer->setDefaultBufferFormat(format); |
| 464 | mConsumer->setConsumerUsageBits(getEffectiveUsage(0)); |
| 465 | |
| 466 | return NO_ERROR; |
| 467 | } |
| 468 | |
| 469 | sp<IGraphicBufferProducer> BufferQueueLayer::getProducer() const { |
| 470 | return mProducer; |
| 471 | } |
| 472 | |
| 473 | uint32_t BufferQueueLayer::getProducerStickyTransform() const { |
| 474 | int producerStickyTransform = 0; |
| 475 | int ret = mProducer->query(NATIVE_WINDOW_STICKY_TRANSFORM, &producerStickyTransform); |
| 476 | if (ret != OK) { |
| 477 | ALOGW("%s: Error %s (%d) while querying window sticky transform.", __FUNCTION__, |
| 478 | strerror(-ret), ret); |
| 479 | return 0; |
| 480 | } |
| 481 | return static_cast<uint32_t>(producerStickyTransform); |
| 482 | } |
| 483 | |
| 484 | } // namespace android |