LayerRejecter.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Copyright (C) 2011 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. #include "LayerRejecter.h"
  17. #include <gui/BufferItem.h>
  18. #include <system/window.h>
  19. #define DEBUG_RESIZE 0
  20. namespace android {
  21. LayerRejecter::LayerRejecter(Layer::State& front,
  22. Layer::State& current,
  23. bool& recomputeVisibleRegions,
  24. bool stickySet,
  25. const char* name,
  26. int32_t overrideScalingMode,
  27. bool transformToDisplayInverse,
  28. bool& freezePositionUpdates)
  29. : mFront(front),
  30. mCurrent(current),
  31. mRecomputeVisibleRegions(recomputeVisibleRegions),
  32. mStickyTransformSet(stickySet),
  33. mName(name),
  34. mOverrideScalingMode(overrideScalingMode),
  35. mTransformToDisplayInverse(transformToDisplayInverse),
  36. mFreezeGeometryUpdates(freezePositionUpdates) {}
  37. bool LayerRejecter::reject(const sp<GraphicBuffer>& buf, const BufferItem& item) {
  38. if (buf == nullptr) {
  39. return false;
  40. }
  41. uint32_t bufWidth = buf->getWidth();
  42. uint32_t bufHeight = buf->getHeight();
  43. // check that we received a buffer of the right size
  44. // (Take the buffer's orientation into account)
  45. if (item.mTransform & ui::Transform::ROT_90) {
  46. std::swap(bufWidth, bufHeight);
  47. }
  48. if (mTransformToDisplayInverse) {
  49. uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform();
  50. if (invTransform & ui::Transform::ROT_90) {
  51. std::swap(bufWidth, bufHeight);
  52. }
  53. }
  54. int actualScalingMode = mOverrideScalingMode >= 0 ? mOverrideScalingMode : item.mScalingMode;
  55. bool isFixedSize = actualScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE;
  56. if (mFront.active_legacy != mFront.requested_legacy) {
  57. if (isFixedSize ||
  58. (bufWidth == mFront.requested_legacy.w && bufHeight == mFront.requested_legacy.h)) {
  59. // Here we pretend the transaction happened by updating the
  60. // current and drawing states. Drawing state is only accessed
  61. // in this thread, no need to have it locked
  62. mFront.active_legacy = mFront.requested_legacy;
  63. // We also need to update the current state so that
  64. // we don't end-up overwriting the drawing state with
  65. // this stale current state during the next transaction
  66. //
  67. // NOTE: We don't need to hold the transaction lock here
  68. // because State::active_legacy is only accessed from this thread.
  69. mCurrent.active_legacy = mFront.active_legacy;
  70. mCurrent.modified = true;
  71. // recompute visible region
  72. mRecomputeVisibleRegions = true;
  73. mFreezeGeometryUpdates = false;
  74. if (mFront.crop_legacy != mFront.requestedCrop_legacy) {
  75. mFront.crop_legacy = mFront.requestedCrop_legacy;
  76. mCurrent.crop_legacy = mFront.requestedCrop_legacy;
  77. mRecomputeVisibleRegions = true;
  78. }
  79. }
  80. ALOGD_IF(DEBUG_RESIZE,
  81. "[%s] latchBuffer/reject: buffer (%ux%u, tr=%02x), scalingMode=%d\n"
  82. " drawing={ active_legacy ={ wh={%4u,%4u} crop_legacy={%4d,%4d,%4d,%4d} "
  83. "(%4d,%4d) "
  84. "}\n"
  85. " requested_legacy={ wh={%4u,%4u} }}\n",
  86. mName, bufWidth, bufHeight, item.mTransform, item.mScalingMode,
  87. mFront.active_legacy.w, mFront.active_legacy.h, mFront.crop_legacy.left,
  88. mFront.crop_legacy.top, mFront.crop_legacy.right, mFront.crop_legacy.bottom,
  89. mFront.crop_legacy.getWidth(), mFront.crop_legacy.getHeight(),
  90. mFront.requested_legacy.w, mFront.requested_legacy.h);
  91. }
  92. if (!isFixedSize && !mStickyTransformSet) {
  93. if (mFront.active_legacy.w != bufWidth || mFront.active_legacy.h != bufHeight) {
  94. // reject this buffer
  95. ALOGE("[%s] rejecting buffer: "
  96. "bufWidth=%d, bufHeight=%d, front.active_legacy.{w=%d, h=%d}",
  97. mName, bufWidth, bufHeight, mFront.active_legacy.w, mFront.active_legacy.h);
  98. return true;
  99. }
  100. }
  101. // if the transparent region has changed (this test is
  102. // conservative, but that's fine, worst case we're doing
  103. // a bit of extra work), we latch the new one and we
  104. // trigger a visible-region recompute.
  105. //
  106. // We latch the transparent region here, instead of above where we latch
  107. // the rest of the geometry because it is only content but not necessarily
  108. // resize dependent.
  109. if (!mFront.activeTransparentRegion_legacy.isTriviallyEqual(
  110. mFront.requestedTransparentRegion_legacy)) {
  111. mFront.activeTransparentRegion_legacy = mFront.requestedTransparentRegion_legacy;
  112. // We also need to update the current state so that
  113. // we don't end-up overwriting the drawing state with
  114. // this stale current state during the next transaction
  115. //
  116. // NOTE: We don't need to hold the transaction lock here
  117. // because State::active_legacy is only accessed from this thread.
  118. mCurrent.activeTransparentRegion_legacy = mFront.activeTransparentRegion_legacy;
  119. // recompute visible region
  120. mRecomputeVisibleRegions = true;
  121. }
  122. return false;
  123. }
  124. } // namespace android