David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | //#define LOG_NDEBUG 0 |
| 18 | #undef LOG_TAG |
| 19 | #define LOG_TAG "BufferLayer" |
| 20 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 21 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 22 | #include <cmath> |
| 23 | #include <cstdlib> |
| 24 | #include <mutex> |
| 25 | |
| 26 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 27 | #include <compositionengine/Display.h> |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 28 | #include <compositionengine/Layer.h> |
| 29 | #include <compositionengine/LayerCreationArgs.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 30 | #include <compositionengine/OutputLayer.h> |
| 31 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 32 | #include <cutils/compiler.h> |
| 33 | #include <cutils/native_handle.h> |
| 34 | #include <cutils/properties.h> |
| 35 | #include <gui/BufferItem.h> |
| 36 | #include <gui/BufferQueue.h> |
| 37 | #include <gui/LayerDebugInfo.h> |
| 38 | #include <gui/Surface.h> |
| 39 | #include <renderengine/RenderEngine.h> |
| 40 | #include <ui/DebugUtils.h> |
| 41 | #include <utils/Errors.h> |
| 42 | #include <utils/Log.h> |
| 43 | #include <utils/NativeHandle.h> |
| 44 | #include <utils/StopWatch.h> |
| 45 | #include <utils/Trace.h> |
| 46 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 47 | #include "BufferLayer.h" |
| 48 | #include "Colorizer.h" |
| 49 | #include "DisplayDevice.h" |
| 50 | #include "LayerRejecter.h" |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 51 | |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 52 | #include "TimeStats/TimeStats.h" |
| 53 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 54 | namespace android { |
| 55 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 56 | BufferLayer::BufferLayer(const LayerCreationArgs& args) |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 57 | : Layer(args), |
| 58 | mTextureName(args.flinger->getNewTexture()), |
| 59 | mCompositionLayer{mFlinger->getCompositionEngine().createLayer( |
| 60 | compositionengine::LayerCreationArgs{this})} { |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 61 | ALOGV("Creating Layer %s", args.name.string()); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 62 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 63 | mPremultipliedAlpha = !(args.flags & ISurfaceComposerClient::eNonPremultiplied); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 64 | |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 65 | mPotentialCursor = args.flags & ISurfaceComposerClient::eCursorWindow; |
| 66 | mProtectedByApp = args.flags & ISurfaceComposerClient::eProtectedByApp; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | BufferLayer::~BufferLayer() { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 70 | mFlinger->deleteTextureAsync(mTextureName); |
| 71 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 72 | if (destroyAllHwcLayersPlusChildren()) { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 73 | ALOGE("Found stale hardware composer layers when destroying " |
| 74 | "surface flinger layer %s", |
| 75 | mName.string()); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 76 | } |
Yiwei Zhang | dc22404 | 2018-10-18 15:34:00 -0700 | [diff] [blame] | 77 | |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 78 | mFlinger->mTimeStats->onDestroy(getSequence()); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 79 | } |
| 80 | |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 81 | void BufferLayer::useSurfaceDamage() { |
| 82 | if (mFlinger->mForceFullDamage) { |
| 83 | surfaceDamageRegion = Region::INVALID_REGION; |
| 84 | } else { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 85 | surfaceDamageRegion = getDrawingSurfaceDamage(); |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | void BufferLayer::useEmptyDamage() { |
| 90 | surfaceDamageRegion.clear(); |
| 91 | } |
| 92 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 93 | bool BufferLayer::isOpaque(const Layer::State& s) const { |
| 94 | // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the |
| 95 | // layer's opaque flag. |
| 96 | if ((getBE().compositionInfo.hwc.sidebandStream == nullptr) && (mActiveBuffer == nullptr)) { |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | // if the layer has the opaque flag, then we're always opaque, |
| 101 | // otherwise we use the current buffer's format. |
| 102 | return ((s.flags & layer_state_t::eLayerOpaque) != 0) || getOpacityForFormat(getPixelFormat()); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | bool BufferLayer::isVisible() const { |
| 106 | return !(isHiddenByPolicy()) && getAlpha() > 0.0f && |
David Sodman | 0cf8f8d | 2017-12-20 18:19:45 -0800 | [diff] [blame] | 107 | (mActiveBuffer != nullptr || getBE().compositionInfo.hwc.sidebandStream != nullptr); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | bool BufferLayer::isFixedSize() const { |
| 111 | return getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE; |
| 112 | } |
| 113 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 114 | static constexpr mat4 inverseOrientation(uint32_t transform) { |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 115 | const mat4 flipH(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); |
| 116 | const mat4 flipV(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1); |
| 117 | const mat4 rot90(0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 118 | mat4 tr; |
| 119 | |
| 120 | if (transform & NATIVE_WINDOW_TRANSFORM_ROT_90) { |
| 121 | tr = tr * rot90; |
| 122 | } |
| 123 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_H) { |
| 124 | tr = tr * flipH; |
| 125 | } |
| 126 | if (transform & NATIVE_WINDOW_TRANSFORM_FLIP_V) { |
| 127 | tr = tr * flipV; |
| 128 | } |
| 129 | return inverse(tr); |
| 130 | } |
| 131 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 132 | bool BufferLayer::prepareClientLayer(const RenderArea& renderArea, const Region& clip, |
| 133 | bool useIdentityTransform, Region& clearRegion, |
| 134 | renderengine::LayerSettings& layer) { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 135 | ATRACE_CALL(); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 136 | Layer::prepareClientLayer(renderArea, clip, useIdentityTransform, clearRegion, layer); |
David Sodman | 0cf8f8d | 2017-12-20 18:19:45 -0800 | [diff] [blame] | 137 | if (CC_UNLIKELY(mActiveBuffer == 0)) { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 138 | // the texture has not been created yet, this Layer has |
| 139 | // in fact never been drawn into. This happens frequently with |
| 140 | // SurfaceView because the WindowManager can't know when the client |
| 141 | // has drawn the first time. |
| 142 | |
| 143 | // If there is nothing under us, we paint the screen in black, otherwise |
| 144 | // we just skip this update. |
| 145 | |
| 146 | // figure out if there is something below us |
| 147 | Region under; |
| 148 | bool finished = false; |
| 149 | mFlinger->mDrawingState.traverseInZOrder([&](Layer* layer) { |
| 150 | if (finished || layer == static_cast<BufferLayer const*>(this)) { |
| 151 | finished = true; |
| 152 | return; |
| 153 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 154 | under.orSelf(layer->visibleRegion); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 155 | }); |
| 156 | // if not everything below us is covered, we plug the holes! |
| 157 | Region holes(clip.subtract(under)); |
| 158 | if (!holes.isEmpty()) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 159 | clearRegion.orSelf(holes); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 160 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 161 | return false; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 162 | } |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 163 | bool blackOutLayer = isProtected() || (isSecure() && !renderArea.isSecure()); |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 164 | const State& s(getDrawingState()); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 165 | if (!blackOutLayer) { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 166 | layer.source.buffer.buffer = mActiveBuffer; |
| 167 | layer.source.buffer.isOpaque = isOpaque(s); |
| 168 | layer.source.buffer.fence = mActiveBufferFence; |
| 169 | layer.source.buffer.cacheHint = useCachedBufferForClientComposition() |
| 170 | ? renderengine::Buffer::CachingHint::USE_CACHE |
| 171 | : renderengine::Buffer::CachingHint::NO_CACHE; |
| 172 | layer.source.buffer.textureName = mTextureName; |
| 173 | layer.source.buffer.usePremultipliedAlpha = getPremultipledAlpha(); |
| 174 | layer.source.buffer.isY410BT2020 = isHdrY410(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 175 | // TODO: we could be more subtle with isFixedSize() |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 176 | const bool useFiltering = needsFiltering(renderArea.getDisplayDevice()) || |
| 177 | renderArea.needsFiltering() || isFixedSize(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 178 | |
| 179 | // Query the texture matrix given our current filtering mode. |
| 180 | float textureMatrix[16]; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 181 | setFilteringEnabled(useFiltering); |
| 182 | getDrawingTransformMatrix(textureMatrix); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 183 | |
| 184 | if (getTransformToDisplayInverse()) { |
| 185 | /* |
| 186 | * the code below applies the primary display's inverse transform to |
| 187 | * the texture transform |
| 188 | */ |
| 189 | uint32_t transform = DisplayDevice::getPrimaryDisplayOrientationTransform(); |
| 190 | mat4 tr = inverseOrientation(transform); |
| 191 | |
| 192 | /** |
| 193 | * TODO(b/36727915): This is basically a hack. |
| 194 | * |
| 195 | * Ensure that regardless of the parent transformation, |
| 196 | * this buffer is always transformed from native display |
| 197 | * orientation to display orientation. For example, in the case |
| 198 | * of a camera where the buffer remains in native orientation, |
| 199 | * we want the pixels to always be upright. |
| 200 | */ |
| 201 | sp<Layer> p = mDrawingParent.promote(); |
| 202 | if (p != nullptr) { |
| 203 | const auto parentTransform = p->getTransform(); |
| 204 | tr = tr * inverseOrientation(parentTransform.getOrientation()); |
| 205 | } |
| 206 | |
| 207 | // and finally apply it to the original texture matrix |
| 208 | const mat4 texTransform(mat4(static_cast<const float*>(textureMatrix)) * tr); |
| 209 | memcpy(textureMatrix, texTransform.asArray(), sizeof(textureMatrix)); |
| 210 | } |
| 211 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 212 | const Rect win{getBounds()}; |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 213 | const float bufferWidth = getBufferSize(s).getWidth(); |
| 214 | const float bufferHeight = getBufferSize(s).getHeight(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 215 | |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 216 | const float scaleHeight = (float(win.bottom) - float(win.top)) / bufferHeight; |
| 217 | const float scaleWidth = (float(win.right) - float(win.left)) / bufferWidth; |
| 218 | const float translateY = float(win.top) / bufferHeight; |
| 219 | const float translateX = float(win.left) / bufferWidth; |
| 220 | |
| 221 | // Flip y-coordinates because GLConsumer expects OpenGL convention. |
| 222 | mat4 tr = mat4::translate(vec4(.5, .5, 0, 1)) * mat4::scale(vec4(1, -1, 1, 1)) * |
| 223 | mat4::translate(vec4(-.5, -.5, 0, 1)) * |
| 224 | mat4::translate(vec4(translateX, translateY, 0, 1)) * |
| 225 | mat4::scale(vec4(scaleWidth, scaleHeight, 1.0, 1.0)); |
| 226 | |
| 227 | layer.source.buffer.useTextureFiltering = useFiltering; |
| 228 | layer.source.buffer.textureTransform = mat4(static_cast<const float*>(textureMatrix)) * tr; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 229 | } else { |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 230 | // If layer is blacked out, force alpha to 1 so that we draw a black color |
| 231 | // layer. |
| 232 | layer.source.buffer.buffer = nullptr; |
| 233 | layer.alpha = 1.0; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 234 | } |
Alec Mouri | e7d1d4a | 2019-02-05 01:13:46 +0000 | [diff] [blame] | 235 | |
| 236 | return true; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 239 | bool BufferLayer::isHdrY410() const { |
| 240 | // pixel format is HDR Y410 masquerading as RGBA_1010102 |
| 241 | return (mCurrentDataSpace == ui::Dataspace::BT2020_ITU_PQ && |
| 242 | getDrawingApi() == NATIVE_WINDOW_API_MEDIA && |
| 243 | getBE().compositionInfo.mBuffer->getPixelFormat() == HAL_PIXEL_FORMAT_RGBA_1010102); |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 246 | void BufferLayer::setPerFrameData(const sp<const DisplayDevice>& displayDevice, |
| 247 | const ui::Transform& transform, const Rect& viewport, |
| 248 | int32_t supportedPerFrameMetadata) { |
| 249 | RETURN_IF_NO_HWC_LAYER(displayDevice); |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 250 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 251 | // Apply this display's projection's viewport to the visible region |
| 252 | // before giving it to the HWC HAL. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 253 | Region visible = transform.transform(visibleRegion.intersect(viewport)); |
| 254 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 255 | const auto outputLayer = findOutputLayerForDisplay(displayDevice); |
| 256 | LOG_FATAL_IF(!outputLayer || !outputLayer->getState().hwc); |
| 257 | |
| 258 | auto& hwcLayer = (*outputLayer->getState().hwc).hwcLayer; |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 259 | auto error = hwcLayer->setVisibleRegion(visible); |
| 260 | if (error != HWC2::Error::None) { |
| 261 | ALOGE("[%s] Failed to set visible region: %s (%d)", mName.string(), |
| 262 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 263 | visible.dump(LOG_TAG); |
| 264 | } |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 265 | outputLayer->editState().visibleRegion = visible; |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 266 | |
| 267 | error = hwcLayer->setSurfaceDamage(surfaceDamageRegion); |
| 268 | if (error != HWC2::Error::None) { |
| 269 | ALOGE("[%s] Failed to set surface damage: %s (%d)", mName.string(), |
| 270 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 271 | surfaceDamageRegion.dump(LOG_TAG); |
| 272 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 273 | getBE().compositionInfo.hwc.surfaceDamage = surfaceDamageRegion; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 274 | |
| 275 | // Sideband layers |
David Sodman | 0cc6918 | 2017-11-17 12:12:07 -0800 | [diff] [blame] | 276 | if (getBE().compositionInfo.hwc.sidebandStream.get()) { |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 277 | setCompositionType(displayDevice, Hwc2::IComposerClient::Composition::SIDEBAND); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 278 | ALOGV("[%s] Requesting Sideband composition", mName.string()); |
| 279 | error = hwcLayer->setSidebandStream(getBE().compositionInfo.hwc.sidebandStream->handle()); |
| 280 | if (error != HWC2::Error::None) { |
| 281 | ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", mName.string(), |
| 282 | getBE().compositionInfo.hwc.sidebandStream->handle(), to_string(error).c_str(), |
| 283 | static_cast<int32_t>(error)); |
| 284 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 285 | getBE().compositionInfo.compositionType = HWC2::Composition::Sideband; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 286 | return; |
| 287 | } |
| 288 | |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 289 | // Device or Cursor layers |
| 290 | if (mPotentialCursor) { |
| 291 | ALOGV("[%s] Requesting Cursor composition", mName.string()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 292 | setCompositionType(displayDevice, Hwc2::IComposerClient::Composition::CURSOR); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 293 | } else { |
| 294 | ALOGV("[%s] Requesting Device composition", mName.string()); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 295 | setCompositionType(displayDevice, Hwc2::IComposerClient::Composition::DEVICE); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 296 | } |
| 297 | |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 298 | ALOGV("setPerFrameData: dataspace = %d", mCurrentDataSpace); |
| 299 | error = hwcLayer->setDataspace(mCurrentDataSpace); |
| 300 | if (error != HWC2::Error::None) { |
| 301 | ALOGE("[%s] Failed to set dataspace %d: %s (%d)", mName.string(), mCurrentDataSpace, |
| 302 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 303 | } |
| 304 | |
| 305 | const HdrMetadata& metadata = getDrawingHdrMetadata(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 306 | error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata, metadata); |
David Sodman | 1509411 | 2018-10-11 09:39:37 -0700 | [diff] [blame] | 307 | if (error != HWC2::Error::None && error != HWC2::Error::Unsupported) { |
| 308 | ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", mName.string(), |
| 309 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 310 | } |
| 311 | |
| 312 | error = hwcLayer->setColorTransform(getColorTransform()); |
| 313 | if (error != HWC2::Error::None) { |
| 314 | ALOGE("[%s] Failed to setColorTransform: %s (%d)", mName.string(), |
| 315 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 316 | } |
David Sodman | ba34049 | 2018-08-05 21:51:33 -0700 | [diff] [blame] | 317 | getBE().compositionInfo.hwc.dataspace = mCurrentDataSpace; |
| 318 | getBE().compositionInfo.hwc.hdrMetadata = getDrawingHdrMetadata(); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 319 | getBE().compositionInfo.hwc.supportedPerFrameMetadata = supportedPerFrameMetadata; |
Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 320 | getBE().compositionInfo.hwc.colorTransform = getColorTransform(); |
Lloyd Pique | 074e812 | 2018-07-26 12:57:23 -0700 | [diff] [blame] | 321 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 322 | setHwcLayerBuffer(displayDevice); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 325 | bool BufferLayer::onPreComposition(nsecs_t refreshStartTime) { |
| 326 | if (mBufferLatched) { |
| 327 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 328 | mFrameEventHistory.addPreComposition(mCurrentFrameNumber, refreshStartTime); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 329 | } |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 330 | mRefreshPending = false; |
| 331 | return hasReadyFrame(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 334 | bool BufferLayer::onPostComposition(const std::optional<DisplayId>& displayId, |
| 335 | const std::shared_ptr<FenceTime>& glDoneFence, |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 336 | const std::shared_ptr<FenceTime>& presentFence, |
| 337 | const CompositorTiming& compositorTiming) { |
| 338 | // mFrameLatencyNeeded is true when a new frame was latched for the |
| 339 | // composition. |
| 340 | if (!mFrameLatencyNeeded) return false; |
| 341 | |
| 342 | // Update mFrameEventHistory. |
Dan Stoza | 436ccf3 | 2018-06-21 12:10:12 -0700 | [diff] [blame] | 343 | { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 344 | Mutex::Autolock lock(mFrameEventHistoryMutex); |
| 345 | mFrameEventHistory.addPostComposition(mCurrentFrameNumber, glDoneFence, presentFence, |
| 346 | compositorTiming); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 349 | // Update mFrameTracker. |
| 350 | nsecs_t desiredPresentTime = getDesiredPresentTime(); |
| 351 | mFrameTracker.setDesiredPresentTime(desiredPresentTime); |
| 352 | |
Yiwei Zhang | 9689e2f | 2018-05-11 12:33:23 -0700 | [diff] [blame] | 353 | const int32_t layerID = getSequence(); |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 354 | mFlinger->mTimeStats->setDesiredTime(layerID, mCurrentFrameNumber, desiredPresentTime); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 355 | |
| 356 | std::shared_ptr<FenceTime> frameReadyFence = getCurrentFenceTime(); |
| 357 | if (frameReadyFence->isValid()) { |
| 358 | mFrameTracker.setFrameReadyFence(std::move(frameReadyFence)); |
| 359 | } else { |
| 360 | // There was no fence for this frame, so assume that it was ready |
| 361 | // to be presented at the desired present time. |
| 362 | mFrameTracker.setFrameReadyTime(desiredPresentTime); |
Dominik Laskowski | 45de9bd | 2018-06-11 17:44:10 -0700 | [diff] [blame] | 363 | } |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 364 | |
| 365 | if (presentFence->isValid()) { |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 366 | mFlinger->mTimeStats->setPresentFence(layerID, mCurrentFrameNumber, presentFence); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 367 | mFrameTracker.setActualPresentFence(std::shared_ptr<FenceTime>(presentFence)); |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 368 | } else if (displayId && mFlinger->getHwComposer().isConnected(*displayId)) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 369 | // The HWC doesn't support present fences, so use the refresh |
| 370 | // timestamp instead. |
Dominik Laskowski | 075d317 | 2018-05-24 15:50:06 -0700 | [diff] [blame] | 371 | const nsecs_t actualPresentTime = mFlinger->getHwComposer().getRefreshTimestamp(*displayId); |
Yiwei Zhang | 7e666a5 | 2018-11-15 13:33:42 -0800 | [diff] [blame] | 372 | mFlinger->mTimeStats->setPresentTime(layerID, mCurrentFrameNumber, actualPresentTime); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 373 | mFrameTracker.setActualPresentTime(actualPresentTime); |
| 374 | } |
| 375 | |
| 376 | mFrameTracker.advanceFrame(); |
| 377 | mFrameLatencyNeeded = false; |
| 378 | return true; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 381 | bool BufferLayer::latchBuffer(bool& recomputeVisibleRegions, nsecs_t latchTime, |
| 382 | const sp<Fence>& releaseFence) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 383 | ATRACE_CALL(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 384 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 385 | bool refreshRequired = latchSidebandStream(recomputeVisibleRegions); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 386 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 387 | if (refreshRequired) { |
| 388 | return refreshRequired; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 391 | if (!hasReadyFrame()) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 392 | return false; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 393 | } |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 394 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 395 | // if we've already called updateTexImage() without going through |
| 396 | // a composition step, we have to skip this layer at this point |
| 397 | // because we cannot call updateTeximage() without a corresponding |
| 398 | // compositionComplete() call. |
| 399 | // we'll trigger an update in onPreComposition(). |
| 400 | if (mRefreshPending) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 401 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // If the head buffer's acquire fence hasn't signaled yet, return and |
| 405 | // try again later |
| 406 | if (!fenceHasSignaled()) { |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 407 | mFlinger->signalLayerUpdate(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 408 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | // Capture the old state of the layer for comparisons later |
| 412 | const State& s(getDrawingState()); |
| 413 | const bool oldOpacity = isOpaque(s); |
| 414 | sp<GraphicBuffer> oldBuffer = mActiveBuffer; |
| 415 | |
| 416 | if (!allTransactionsSignaled()) { |
| 417 | mFlinger->signalLayerUpdate(); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 418 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Alec Mouri | 86770e5 | 2018-09-24 22:40:58 +0000 | [diff] [blame] | 421 | status_t err = updateTexImage(recomputeVisibleRegions, latchTime, releaseFence); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 422 | if (err != NO_ERROR) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 423 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | err = updateActiveBuffer(); |
| 427 | if (err != NO_ERROR) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 428 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | mBufferLatched = true; |
| 432 | |
| 433 | err = updateFrameNumber(latchTime); |
| 434 | if (err != NO_ERROR) { |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 435 | return false; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | mRefreshPending = true; |
| 439 | mFrameLatencyNeeded = true; |
| 440 | if (oldBuffer == nullptr) { |
| 441 | // the first time we receive a buffer, we need to trigger a |
| 442 | // geometry invalidation. |
| 443 | recomputeVisibleRegions = true; |
| 444 | } |
| 445 | |
| 446 | ui::Dataspace dataSpace = getDrawingDataSpace(); |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 447 | // translate legacy dataspaces to modern dataspaces |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 448 | switch (dataSpace) { |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 449 | case ui::Dataspace::SRGB: |
| 450 | dataSpace = ui::Dataspace::V0_SRGB; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 451 | break; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 452 | case ui::Dataspace::SRGB_LINEAR: |
| 453 | dataSpace = ui::Dataspace::V0_SRGB_LINEAR; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 454 | break; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 455 | case ui::Dataspace::JFIF: |
| 456 | dataSpace = ui::Dataspace::V0_JFIF; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 457 | break; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 458 | case ui::Dataspace::BT601_625: |
| 459 | dataSpace = ui::Dataspace::V0_BT601_625; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 460 | break; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 461 | case ui::Dataspace::BT601_525: |
| 462 | dataSpace = ui::Dataspace::V0_BT601_525; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 463 | break; |
Peiyong Lin | 14724e6 | 2018-12-05 07:27:30 -0800 | [diff] [blame] | 464 | case ui::Dataspace::BT709: |
| 465 | dataSpace = ui::Dataspace::V0_BT709; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 466 | break; |
| 467 | default: |
| 468 | break; |
| 469 | } |
| 470 | mCurrentDataSpace = dataSpace; |
| 471 | |
| 472 | Rect crop(getDrawingCrop()); |
| 473 | const uint32_t transform(getDrawingTransform()); |
| 474 | const uint32_t scalingMode(getDrawingScalingMode()); |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 475 | const bool transformToDisplayInverse(getTransformToDisplayInverse()); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 476 | if ((crop != mCurrentCrop) || (transform != mCurrentTransform) || |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 477 | (scalingMode != mCurrentScalingMode) || |
| 478 | (transformToDisplayInverse != mTransformToDisplayInverse)) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 479 | mCurrentCrop = crop; |
| 480 | mCurrentTransform = transform; |
| 481 | mCurrentScalingMode = scalingMode; |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 482 | mTransformToDisplayInverse = transformToDisplayInverse; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 483 | recomputeVisibleRegions = true; |
| 484 | } |
| 485 | |
| 486 | if (oldBuffer != nullptr) { |
| 487 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 488 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
| 489 | if (bufWidth != uint32_t(oldBuffer->width) || bufHeight != uint32_t(oldBuffer->height)) { |
| 490 | recomputeVisibleRegions = true; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if (oldOpacity != isOpaque(s)) { |
| 495 | recomputeVisibleRegions = true; |
| 496 | } |
| 497 | |
| 498 | // Remove any sync points corresponding to the buffer which was just |
| 499 | // latched |
| 500 | { |
| 501 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 502 | auto point = mLocalSyncPoints.begin(); |
| 503 | while (point != mLocalSyncPoints.end()) { |
| 504 | if (!(*point)->frameIsAvailable() || !(*point)->transactionIsApplied()) { |
| 505 | // This sync point must have been added since we started |
| 506 | // latching. Don't drop it yet. |
| 507 | ++point; |
| 508 | continue; |
| 509 | } |
| 510 | |
| 511 | if ((*point)->getFrameNumber() <= mCurrentFrameNumber) { |
| 512 | point = mLocalSyncPoints.erase(point); |
| 513 | } else { |
| 514 | ++point; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Vishnu Nair | 6194e2e | 2019-02-06 12:58:39 -0800 | [diff] [blame] | 519 | return true; |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | // transaction |
| 523 | void BufferLayer::notifyAvailableFrames() { |
| 524 | auto headFrameNumber = getHeadFrameNumber(); |
| 525 | bool headFenceSignaled = fenceHasSignaled(); |
| 526 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 527 | for (auto& point : mLocalSyncPoints) { |
| 528 | if (headFrameNumber >= point->getFrameNumber() && headFenceSignaled) { |
| 529 | point->setFrameAvailable(); |
| 530 | } |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 534 | bool BufferLayer::hasReadyFrame() const { |
Marissa Wall | 024a191 | 2018-08-13 13:55:35 -0700 | [diff] [blame] | 535 | return hasFrameUpdate() || getSidebandStreamChanged() || getAutoRefresh(); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | uint32_t BufferLayer::getEffectiveScalingMode() const { |
| 539 | if (mOverrideScalingMode >= 0) { |
| 540 | return mOverrideScalingMode; |
| 541 | } |
| 542 | |
| 543 | return mCurrentScalingMode; |
| 544 | } |
| 545 | |
| 546 | bool BufferLayer::isProtected() const { |
| 547 | const sp<GraphicBuffer>& buffer(mActiveBuffer); |
| 548 | return (buffer != 0) && (buffer->getUsage() & GRALLOC_USAGE_PROTECTED); |
| 549 | } |
| 550 | |
| 551 | bool BufferLayer::latchUnsignaledBuffers() { |
| 552 | static bool propertyLoaded = false; |
| 553 | static bool latch = false; |
| 554 | static std::mutex mutex; |
| 555 | std::lock_guard<std::mutex> lock(mutex); |
| 556 | if (!propertyLoaded) { |
| 557 | char value[PROPERTY_VALUE_MAX] = {}; |
| 558 | property_get("debug.sf.latch_unsignaled", value, "0"); |
| 559 | latch = atoi(value); |
| 560 | propertyLoaded = true; |
| 561 | } |
| 562 | return latch; |
| 563 | } |
| 564 | |
| 565 | // h/w composer set-up |
| 566 | bool BufferLayer::allTransactionsSignaled() { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 567 | auto headFrameNumber = getHeadFrameNumber(); |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 568 | bool matchingFramesFound = false; |
| 569 | bool allTransactionsApplied = true; |
| 570 | Mutex::Autolock lock(mLocalSyncPointMutex); |
| 571 | |
| 572 | for (auto& point : mLocalSyncPoints) { |
| 573 | if (point->getFrameNumber() > headFrameNumber) { |
| 574 | break; |
| 575 | } |
| 576 | matchingFramesFound = true; |
| 577 | |
| 578 | if (!point->frameIsAvailable()) { |
| 579 | // We haven't notified the remote layer that the frame for |
| 580 | // this point is available yet. Notify it now, and then |
| 581 | // abort this attempt to latch. |
| 582 | point->setFrameAvailable(); |
| 583 | allTransactionsApplied = false; |
| 584 | break; |
| 585 | } |
| 586 | |
| 587 | allTransactionsApplied = allTransactionsApplied && point->transactionIsApplied(); |
| 588 | } |
| 589 | return !matchingFramesFound || allTransactionsApplied; |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | // As documented in libhardware header, formats in the range |
| 593 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 594 | // are known to have no alpha channel |
| 595 | // TODO: move definition for device-specific range into |
| 596 | // hardware.h, instead of using hard-coded values here. |
| 597 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 598 | |
| 599 | bool BufferLayer::getOpacityForFormat(uint32_t format) { |
| 600 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 601 | return true; |
| 602 | } |
| 603 | switch (format) { |
| 604 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 605 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 606 | case HAL_PIXEL_FORMAT_RGBA_FP16: |
| 607 | case HAL_PIXEL_FORMAT_RGBA_1010102: |
| 608 | return false; |
| 609 | } |
| 610 | // in all other case, we have no blending (also for unknown formats) |
| 611 | return true; |
| 612 | } |
| 613 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame^] | 614 | bool BufferLayer::needsFiltering(const sp<const DisplayDevice>& displayDevice) const { |
| 615 | // If we are not capturing based on the state of a known display device, we |
| 616 | // only return mNeedsFiltering |
| 617 | if (displayDevice == nullptr) { |
| 618 | return mNeedsFiltering; |
| 619 | } |
| 620 | |
| 621 | const auto outputLayer = findOutputLayerForDisplay(displayDevice); |
| 622 | if (outputLayer == nullptr) { |
| 623 | return mNeedsFiltering; |
| 624 | } |
| 625 | |
| 626 | const auto& compositionState = outputLayer->getState(); |
| 627 | const auto displayFrame = compositionState.displayFrame; |
| 628 | const auto sourceCrop = compositionState.sourceCrop; |
Peiyong Lin | c2020ca | 2019-01-10 11:36:12 -0800 | [diff] [blame] | 629 | return mNeedsFiltering || sourceCrop.getHeight() != displayFrame.getHeight() || |
| 630 | sourceCrop.getWidth() != displayFrame.getWidth(); |
Chia-I Wu | 692e083 | 2018-06-05 15:46:58 -0700 | [diff] [blame] | 631 | } |
| 632 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 633 | uint64_t BufferLayer::getHeadFrameNumber() const { |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 634 | if (hasFrameUpdate()) { |
Marissa Wall | fd66862 | 2018-05-10 10:21:13 -0700 | [diff] [blame] | 635 | return getFrameNumber(); |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 636 | } else { |
| 637 | return mCurrentFrameNumber; |
| 638 | } |
| 639 | } |
| 640 | |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 641 | Rect BufferLayer::getBufferSize(const State& s) const { |
| 642 | // If we have a sideband stream, or we are scaling the buffer then return the layer size since |
| 643 | // we cannot determine the buffer size. |
| 644 | if ((s.sidebandStream != nullptr) || |
| 645 | (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) { |
| 646 | return Rect(getActiveWidth(s), getActiveHeight(s)); |
| 647 | } |
| 648 | |
| 649 | if (mActiveBuffer == nullptr) { |
| 650 | return Rect::INVALID_RECT; |
| 651 | } |
| 652 | |
| 653 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 654 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
| 655 | |
| 656 | // Undo any transformations on the buffer and return the result. |
| 657 | if (mCurrentTransform & ui::Transform::ROT_90) { |
| 658 | std::swap(bufWidth, bufHeight); |
| 659 | } |
| 660 | |
Lloyd Pique | 0449b0f | 2018-12-20 16:23:45 -0800 | [diff] [blame] | 661 | if (getTransformToDisplayInverse()) { |
Vishnu Nair | 6035634 | 2018-11-13 13:00:45 -0800 | [diff] [blame] | 662 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform(); |
| 663 | if (invTransform & ui::Transform::ROT_90) { |
| 664 | std::swap(bufWidth, bufHeight); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | return Rect(bufWidth, bufHeight); |
| 669 | } |
| 670 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 671 | std::shared_ptr<compositionengine::Layer> BufferLayer::getCompositionLayer() const { |
| 672 | return mCompositionLayer; |
| 673 | } |
| 674 | |
Vishnu Nair | 4351ad5 | 2019-02-11 14:13:02 -0800 | [diff] [blame] | 675 | FloatRect BufferLayer::computeSourceBounds(const FloatRect& parentBounds) const { |
| 676 | const State& s(getDrawingState()); |
| 677 | |
| 678 | // If we have a sideband stream, or we are scaling the buffer then return the layer size since |
| 679 | // we cannot determine the buffer size. |
| 680 | if ((s.sidebandStream != nullptr) || |
| 681 | (getEffectiveScalingMode() != NATIVE_WINDOW_SCALING_MODE_FREEZE)) { |
| 682 | return FloatRect(0, 0, getActiveWidth(s), getActiveHeight(s)); |
| 683 | } |
| 684 | |
| 685 | if (mActiveBuffer == nullptr) { |
| 686 | return parentBounds; |
| 687 | } |
| 688 | |
| 689 | uint32_t bufWidth = mActiveBuffer->getWidth(); |
| 690 | uint32_t bufHeight = mActiveBuffer->getHeight(); |
| 691 | |
| 692 | // Undo any transformations on the buffer and return the result. |
| 693 | if (mCurrentTransform & ui::Transform::ROT_90) { |
| 694 | std::swap(bufWidth, bufHeight); |
| 695 | } |
| 696 | |
| 697 | if (getTransformToDisplayInverse()) { |
| 698 | uint32_t invTransform = DisplayDevice::getPrimaryDisplayOrientationTransform(); |
| 699 | if (invTransform & ui::Transform::ROT_90) { |
| 700 | std::swap(bufWidth, bufHeight); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | return FloatRect(0, 0, bufWidth, bufHeight); |
| 705 | } |
| 706 | |
David Sodman | 0c69cad | 2017-08-21 12:12:51 -0700 | [diff] [blame] | 707 | } // namespace android |
| 708 | |
| 709 | #if defined(__gl_h_) |
| 710 | #error "don't include gl/gl.h in this file" |
| 711 | #endif |
| 712 | |
| 713 | #if defined(__gl2_h_) |
| 714 | #error "don't include gl2/gl2.h in this file" |
| 715 | #endif |