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