The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 17 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 18 | #pragma clang diagnostic push |
| 19 | #pragma clang diagnostic ignored "-Wconversion" |
| 20 | |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 21 | // #define LOG_NDEBUG 0 |
| 22 | #undef LOG_TAG |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 23 | #define LOG_TAG "EffectLayer" |
Dan Stoza | 9e56aa0 | 2015-11-02 13:00:03 -0800 | [diff] [blame] | 24 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 25 | #include "EffectLayer.h" |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 26 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <stdint.h> |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 28 | #include <stdlib.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | #include <sys/types.h> |
| 30 | |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 31 | #include <compositionengine/CompositionEngine.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 32 | #include <compositionengine/LayerFECompositionState.h> |
Peiyong Lin | cbc184f | 2018-08-22 13:24:10 -0700 | [diff] [blame] | 33 | #include <renderengine/RenderEngine.h> |
| 34 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include <utils/Errors.h> |
| 36 | #include <utils/Log.h> |
| 37 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 38 | #include "DisplayDevice.h" |
David Sodman | 41fdfc9 | 2017-11-06 16:09:56 -0800 | [diff] [blame] | 39 | #include "SurfaceFlinger.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | // --------------------------------------------------------------------------- |
| 43 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 44 | EffectLayer::EffectLayer(const LayerCreationArgs& args) |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 45 | : Layer(args), |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 46 | mCompositionState{mFlinger->getCompositionEngine().createLayerFECompositionState()} {} |
Lloyd Pique | 42ab75e | 2018-09-12 20:46:03 -0700 | [diff] [blame] | 47 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 48 | EffectLayer::~EffectLayer() = default; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 50 | std::vector<compositionengine::LayerFE::LayerSettings> EffectLayer::prepareClientCompositionList( |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 51 | compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) { |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 52 | std::vector<compositionengine::LayerFE::LayerSettings> results; |
| 53 | std::optional<compositionengine::LayerFE::LayerSettings> layerSettings = |
| 54 | prepareClientComposition(targetSettings); |
| 55 | // Nothing to render. |
| 56 | if (!layerSettings) { |
| 57 | return {}; |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 58 | } |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 59 | |
| 60 | std::optional<compositionengine::LayerFE::LayerSettings> shadowSettings = |
| 61 | prepareShadowClientComposition(*layerSettings, targetSettings.viewport, |
| 62 | targetSettings.dataspace); |
| 63 | if (shadowSettings) { |
| 64 | results.push_back(*shadowSettings); |
| 65 | } |
| 66 | |
| 67 | // If fill bounds are occluded or the fill color is invalid skip the fill settings. |
| 68 | if (targetSettings.realContentIsVisible && fillsColor()) { |
| 69 | // Set color for color fill settings. |
| 70 | layerSettings->source.solidColor = getColor().rgb; |
| 71 | results.push_back(*layerSettings); |
Lucas Dupin | b83097d | 2020-02-18 19:49:27 -0800 | [diff] [blame] | 72 | } else if (hasBlur()) { |
| 73 | results.push_back(*layerSettings); |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | return results; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 79 | bool EffectLayer::isVisible() const { |
Galia Peycheva | e7f6ee7 | 2021-03-08 15:19:23 +0100 | [diff] [blame^] | 80 | return !isHiddenByPolicy() && (getAlpha() > 0.0_hf || hasBlur()) && hasSomethingToDraw(); |
Mathias Agopian | 2f73af9 | 2013-03-05 15:50:58 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 83 | bool EffectLayer::setColor(const half3& color) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 84 | if (mCurrentState.color.r == color.r && mCurrentState.color.g == color.g && |
| 85 | mCurrentState.color.b == color.b) { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | mCurrentState.sequence++; |
| 90 | mCurrentState.color.r = color.r; |
| 91 | mCurrentState.color.g = color.g; |
| 92 | mCurrentState.color.b = color.b; |
| 93 | mCurrentState.modified = true; |
| 94 | setTransactionFlags(eTransactionNeeded); |
| 95 | return true; |
| 96 | } |
| 97 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 98 | bool EffectLayer::setDataspace(ui::Dataspace dataspace) { |
Valerie Hau | b153bab | 2019-03-05 10:47:28 -0800 | [diff] [blame] | 99 | if (mCurrentState.dataspace == dataspace) { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | mCurrentState.sequence++; |
| 104 | mCurrentState.dataspace = dataspace; |
| 105 | mCurrentState.modified = true; |
| 106 | setTransactionFlags(eTransactionNeeded); |
| 107 | return true; |
| 108 | } |
| 109 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 110 | void EffectLayer::preparePerFrameCompositionState() { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 111 | Layer::preparePerFrameCompositionState(); |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 112 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 113 | auto* compositionState = editCompositionState(); |
| 114 | compositionState->color = getColor(); |
| 115 | compositionState->compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 116 | } |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 117 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 118 | sp<compositionengine::LayerFE> EffectLayer::getCompositionEngineLayerFE() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 119 | return asLayerFE(); |
| 120 | } |
| 121 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 122 | compositionengine::LayerFECompositionState* EffectLayer::editCompositionState() { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 123 | return mCompositionState.get(); |
| 124 | } |
| 125 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 126 | const compositionengine::LayerFECompositionState* EffectLayer::getCompositionState() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 127 | return mCompositionState.get(); |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 130 | bool EffectLayer::isOpaque(const Layer::State& s) const { |
Vishnu Nair | 371626c | 2020-01-30 09:28:10 -0800 | [diff] [blame] | 131 | // Consider the layer to be opaque if its opaque flag is set or its effective |
| 132 | // alpha (considering the alpha of its parents as well) is 1.0; |
| 133 | return (s.flags & layer_state_t::eLayerOpaque) != 0 || getAlpha() == 1.0_hf; |
chaviw | 575144f | 2019-08-16 12:37:24 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 136 | ui::Dataspace EffectLayer::getDataSpace() const { |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 137 | return mDrawingState.dataspace; |
| 138 | } |
| 139 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame] | 140 | sp<Layer> EffectLayer::createClone() { |
| 141 | sp<EffectLayer> layer = mFlinger->getFactory().createEffectLayer( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 142 | LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0, |
| 143 | LayerMetadata())); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 144 | layer->setInitialValuesForClone(this); |
| 145 | return layer; |
| 146 | } |
| 147 | |
Vishnu Nair | b87d94f | 2020-02-13 09:17:36 -0800 | [diff] [blame] | 148 | bool EffectLayer::fillsColor() const { |
| 149 | return mDrawingState.color.r >= 0.0_hf && mDrawingState.color.g >= 0.0_hf && |
| 150 | mDrawingState.color.b >= 0.0_hf; |
| 151 | } |
| 152 | |
Lucas Dupin | b83097d | 2020-02-18 19:49:27 -0800 | [diff] [blame] | 153 | bool EffectLayer::hasBlur() const { |
| 154 | return getBackgroundBlurRadius() > 0; |
| 155 | } |
| 156 | |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 157 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 158 | |
| 159 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 160 | #pragma clang diagnostic pop // ignored "-Wconversion" |