blob: d161c510fd3c2fdd5605e7b1020c4ca988dc39b1 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Abrahamb0dbdaa2020-01-06 16:19:42 -080017// TODO(b/129481165): remove the #pragma below and fix conversion issues
18#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wconversion"
20
Dan Stoza9e56aa02015-11-02 13:00:03 -080021// #define LOG_NDEBUG 0
22#undef LOG_TAG
Vishnu Nairfa247b12020-02-11 08:58:26 -080023#define LOG_TAG "EffectLayer"
Dan Stoza9e56aa02015-11-02 13:00:03 -080024
Vishnu Nairfa247b12020-02-11 08:58:26 -080025#include "EffectLayer.h"
Lloyd Piquef5275482019-01-29 18:42:42 -080026
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <stdint.h>
David Sodman41fdfc92017-11-06 16:09:56 -080028#include <stdlib.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <sys/types.h>
30
Lloyd Piquefeb73d72018-12-04 17:23:44 -080031#include <compositionengine/CompositionEngine.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080032#include <compositionengine/LayerFECompositionState.h>
Peiyong Lincbc184f2018-08-22 13:24:10 -070033#include <renderengine/RenderEngine.h>
34#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include <utils/Errors.h>
36#include <utils/Log.h>
37
Mathias Agopian0f2f5ff2012-07-31 23:09:07 -070038#include "DisplayDevice.h"
David Sodman41fdfc92017-11-06 16:09:56 -080039#include "SurfaceFlinger.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
41namespace android {
42// ---------------------------------------------------------------------------
43
Vishnu Nairfa247b12020-02-11 08:58:26 -080044EffectLayer::EffectLayer(const LayerCreationArgs& args)
Lloyd Piquefeb73d72018-12-04 17:23:44 -080045 : Layer(args),
Lloyd Piquede196652020-01-22 17:29:58 -080046 mCompositionState{mFlinger->getCompositionEngine().createLayerFECompositionState()} {}
Lloyd Pique42ab75e2018-09-12 20:46:03 -070047
Vishnu Nairfa247b12020-02-11 08:58:26 -080048EffectLayer::~EffectLayer() = default;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049
Patrick Williams16d8b2c2022-08-08 17:29:05 +000050std::optional<compositionengine::LayerFE::LayerSettings> EffectLayer::prepareClientComposition(
51 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) const {
Vishnu Nairb87d94f2020-02-13 09:17:36 -080052 std::optional<compositionengine::LayerFE::LayerSettings> layerSettings =
Patrick Williams16d8b2c2022-08-08 17:29:05 +000053 Layer::prepareClientComposition(targetSettings);
Vishnu Nairb87d94f2020-02-13 09:17:36 -080054 // Nothing to render.
55 if (!layerSettings) {
56 return {};
Lloyd Piquef16688f2019-02-19 17:47:57 -080057 }
Vishnu Nairb87d94f2020-02-13 09:17:36 -080058
Derek Sollenbergerc31985e2021-05-18 16:38:17 -040059 // set the shadow for the layer if needed
60 prepareShadowClientComposition(*layerSettings, targetSettings.viewport);
Vishnu Nairb87d94f2020-02-13 09:17:36 -080061
62 // If fill bounds are occluded or the fill color is invalid skip the fill settings.
63 if (targetSettings.realContentIsVisible && fillsColor()) {
64 // Set color for color fill settings.
65 layerSettings->source.solidColor = getColor().rgb;
Patrick Williams16d8b2c2022-08-08 17:29:05 +000066 return layerSettings;
Derek Sollenbergerc31985e2021-05-18 16:38:17 -040067 } else if (hasBlur() || drawShadows()) {
Lucas Dupin0fe42e52021-05-27 17:27:15 -070068 layerSettings->skipContentDraw = true;
Patrick Williams16d8b2c2022-08-08 17:29:05 +000069 return layerSettings;
Vishnu Nairb87d94f2020-02-13 09:17:36 -080070 }
71
Patrick Williams16d8b2c2022-08-08 17:29:05 +000072 return {};
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073}
74
Vishnu Nairfa247b12020-02-11 08:58:26 -080075bool EffectLayer::isVisible() const {
Vishnu Nair29810f72022-07-01 16:38:41 +000076 return hasSomethingToDraw() && !isHiddenByPolicy() && (getAlpha() > 0.0_hf || hasBlur());
Mathias Agopian2f73af92013-03-05 15:50:58 -080077}
78
Vishnu Nairfa247b12020-02-11 08:58:26 -080079bool EffectLayer::setColor(const half3& color) {
Robert Carr6a160312021-05-17 12:08:20 -070080 if (mDrawingState.color.r == color.r && mDrawingState.color.g == color.g &&
81 mDrawingState.color.b == color.b) {
Valerie Haudd0b7572019-01-29 14:59:27 -080082 return false;
83 }
84
Robert Carr6a160312021-05-17 12:08:20 -070085 mDrawingState.sequence++;
86 mDrawingState.color.r = color.r;
87 mDrawingState.color.g = color.g;
88 mDrawingState.color.b = color.b;
89 mDrawingState.modified = true;
Valerie Haudd0b7572019-01-29 14:59:27 -080090 setTransactionFlags(eTransactionNeeded);
91 return true;
92}
93
Vishnu Nairfa247b12020-02-11 08:58:26 -080094bool EffectLayer::setDataspace(ui::Dataspace dataspace) {
Robert Carr6a160312021-05-17 12:08:20 -070095 if (mDrawingState.dataspace == dataspace) {
Valerie Haub153bab2019-03-05 10:47:28 -080096 return false;
97 }
98
Robert Carr6a160312021-05-17 12:08:20 -070099 mDrawingState.sequence++;
100 mDrawingState.dataspace = dataspace;
101 mDrawingState.modified = true;
Valerie Haub153bab2019-03-05 10:47:28 -0800102 setTransactionFlags(eTransactionNeeded);
103 return true;
104}
105
Vishnu Nairfa247b12020-02-11 08:58:26 -0800106void EffectLayer::preparePerFrameCompositionState() {
Lloyd Piquede196652020-01-22 17:29:58 -0800107 Layer::preparePerFrameCompositionState();
Dominik Laskowski34157762018-10-31 13:07:19 -0700108
Lloyd Piquede196652020-01-22 17:29:58 -0800109 auto* compositionState = editCompositionState();
110 compositionState->color = getColor();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500111 compositionState->compositionType =
112 aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR;
David Sodmaneb085e02017-10-05 18:49:04 -0700113}
David Sodmaneb085e02017-10-05 18:49:04 -0700114
Vishnu Nairfa247b12020-02-11 08:58:26 -0800115sp<compositionengine::LayerFE> EffectLayer::getCompositionEngineLayerFE() const {
chaviwa3c4d372022-04-05 13:22:04 -0500116 // There's no need to get a CE Layer if the EffectLayer isn't going to draw anything. In that
117 // case, it acts more like a ContainerLayer so returning a null CE Layer makes more sense
118 if (hasSomethingToDraw()) {
119 return asLayerFE();
120 } else {
121 return nullptr;
122 }
Lloyd Piquede196652020-01-22 17:29:58 -0800123}
124
Vishnu Nairfa247b12020-02-11 08:58:26 -0800125compositionengine::LayerFECompositionState* EffectLayer::editCompositionState() {
Lloyd Piquede196652020-01-22 17:29:58 -0800126 return mCompositionState.get();
127}
128
Vishnu Nairfa247b12020-02-11 08:58:26 -0800129const compositionengine::LayerFECompositionState* EffectLayer::getCompositionState() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800130 return mCompositionState.get();
Lloyd Piquefeb73d72018-12-04 17:23:44 -0800131}
132
Vishnu Nairfa247b12020-02-11 08:58:26 -0800133bool EffectLayer::isOpaque(const Layer::State& s) const {
Vishnu Nair371626c2020-01-30 09:28:10 -0800134 // Consider the layer to be opaque if its opaque flag is set or its effective
135 // alpha (considering the alpha of its parents as well) is 1.0;
Lucas Dupin0fe42e52021-05-27 17:27:15 -0700136 return (s.flags & layer_state_t::eLayerOpaque) != 0 || (fillsColor() && getAlpha() == 1.0_hf);
chaviw575144f2019-08-16 12:37:24 -0700137}
138
Vishnu Nairfa247b12020-02-11 08:58:26 -0800139ui::Dataspace EffectLayer::getDataSpace() const {
chaviw4244e032019-09-04 11:27:49 -0700140 return mDrawingState.dataspace;
141}
142
Vishnu Nairfa247b12020-02-11 08:58:26 -0800143sp<Layer> EffectLayer::createClone() {
144 sp<EffectLayer> layer = mFlinger->getFactory().createEffectLayer(
Vishnu Nair7fb9e5a2021-11-08 12:44:05 -0800145 LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, LayerMetadata()));
Ady Abrahamd11bade2022-08-01 16:18:03 -0700146 layer->setInitialValuesForClone(sp<Layer>::fromExisting(this));
chaviwb4c6e582019-08-16 14:35:07 -0700147 return layer;
148}
149
Vishnu Nairb87d94f2020-02-13 09:17:36 -0800150bool EffectLayer::fillsColor() const {
151 return mDrawingState.color.r >= 0.0_hf && mDrawingState.color.g >= 0.0_hf &&
152 mDrawingState.color.b >= 0.0_hf;
153}
154
Lucas Dupinb83097d2020-02-18 19:49:27 -0800155bool EffectLayer::hasBlur() const {
Lucas Dupin0fe42e52021-05-27 17:27:15 -0700156 return getBackgroundBlurRadius() > 0 || getDrawingState().blurRegions.size() > 0;
Lucas Dupinb83097d2020-02-18 19:49:27 -0800157}
158
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700159} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800160
161// TODO(b/129481165): remove the #pragma below and fix conversion issues
162#pragma clang diagnostic pop // ignored "-Wconversion"