blob: e928c57929b4b625ec1f1a808cc0198260575459 [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
Vishnu Nairfa247b12020-02-11 08:58:26 -080050std::optional<compositionengine::LayerFE::LayerSettings> EffectLayer::prepareClientComposition(
Lloyd Piquef16688f2019-02-19 17:47:57 -080051 compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
52 auto result = Layer::prepareClientComposition(targetSettings);
53 if (!result) {
54 return result;
55 }
56 result->source.solidColor = getColor().rgb;
57 return result;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058}
59
Vishnu Nairfa247b12020-02-11 08:58:26 -080060bool EffectLayer::isVisible() const {
Vishnu Nair371626c2020-01-30 09:28:10 -080061 return !isHiddenByPolicy() && getAlpha() > 0.0_hf;
Mathias Agopian2f73af92013-03-05 15:50:58 -080062}
63
Vishnu Nairfa247b12020-02-11 08:58:26 -080064bool EffectLayer::setColor(const half3& color) {
Valerie Haudd0b7572019-01-29 14:59:27 -080065 if (mCurrentState.color.r == color.r && mCurrentState.color.g == color.g &&
66 mCurrentState.color.b == color.b) {
67 return false;
68 }
69
70 mCurrentState.sequence++;
71 mCurrentState.color.r = color.r;
72 mCurrentState.color.g = color.g;
73 mCurrentState.color.b = color.b;
74 mCurrentState.modified = true;
75 setTransactionFlags(eTransactionNeeded);
76 return true;
77}
78
Vishnu Nairfa247b12020-02-11 08:58:26 -080079bool EffectLayer::setDataspace(ui::Dataspace dataspace) {
Valerie Haub153bab2019-03-05 10:47:28 -080080 if (mCurrentState.dataspace == dataspace) {
81 return false;
82 }
83
84 mCurrentState.sequence++;
85 mCurrentState.dataspace = dataspace;
86 mCurrentState.modified = true;
87 setTransactionFlags(eTransactionNeeded);
88 return true;
89}
90
Vishnu Nairfa247b12020-02-11 08:58:26 -080091void EffectLayer::preparePerFrameCompositionState() {
Lloyd Piquede196652020-01-22 17:29:58 -080092 Layer::preparePerFrameCompositionState();
Dominik Laskowski34157762018-10-31 13:07:19 -070093
Lloyd Piquede196652020-01-22 17:29:58 -080094 auto* compositionState = editCompositionState();
95 compositionState->color = getColor();
96 compositionState->compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR;
David Sodmaneb085e02017-10-05 18:49:04 -070097}
David Sodmaneb085e02017-10-05 18:49:04 -070098
Vishnu Nairfa247b12020-02-11 08:58:26 -080099sp<compositionengine::LayerFE> EffectLayer::getCompositionEngineLayerFE() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800100 return asLayerFE();
101}
102
Vishnu Nairfa247b12020-02-11 08:58:26 -0800103compositionengine::LayerFECompositionState* EffectLayer::editCompositionState() {
Lloyd Piquede196652020-01-22 17:29:58 -0800104 return mCompositionState.get();
105}
106
Vishnu Nairfa247b12020-02-11 08:58:26 -0800107const compositionengine::LayerFECompositionState* EffectLayer::getCompositionState() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800108 return mCompositionState.get();
Lloyd Piquefeb73d72018-12-04 17:23:44 -0800109}
110
Vishnu Nairfa247b12020-02-11 08:58:26 -0800111bool EffectLayer::isOpaque(const Layer::State& s) const {
Vishnu Nair371626c2020-01-30 09:28:10 -0800112 // Consider the layer to be opaque if its opaque flag is set or its effective
113 // alpha (considering the alpha of its parents as well) is 1.0;
114 return (s.flags & layer_state_t::eLayerOpaque) != 0 || getAlpha() == 1.0_hf;
chaviw575144f2019-08-16 12:37:24 -0700115}
116
Vishnu Nairfa247b12020-02-11 08:58:26 -0800117ui::Dataspace EffectLayer::getDataSpace() const {
chaviw4244e032019-09-04 11:27:49 -0700118 return mDrawingState.dataspace;
119}
120
Vishnu Nairfa247b12020-02-11 08:58:26 -0800121sp<Layer> EffectLayer::createClone() {
122 sp<EffectLayer> layer = mFlinger->getFactory().createEffectLayer(
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700123 LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0,
124 LayerMetadata()));
chaviwb4c6e582019-08-16 14:35:07 -0700125 layer->setInitialValuesForClone(this);
126 return layer;
127}
128
Dominik Laskowski87a07e42019-10-10 20:38:02 -0700129} // namespace android
Ady Abrahamb0dbdaa2020-01-06 16:19:42 -0800130
131// TODO(b/129481165): remove the #pragma below and fix conversion issues
132#pragma clang diagnostic pop // ignored "-Wconversion"