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