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 | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 50 | std::optional<compositionengine::LayerFE::LayerSettings> EffectLayer::prepareClientComposition( |
Lloyd Pique | f16688f | 2019-02-19 17:47:57 -0800 | [diff] [blame] | 51 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 60 | bool EffectLayer::isVisible() const { |
Vishnu Nair | 371626c | 2020-01-30 09:28:10 -0800 | [diff] [blame] | 61 | return !isHiddenByPolicy() && getAlpha() > 0.0_hf; |
Mathias Agopian | 2f73af9 | 2013-03-05 15:50:58 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 64 | bool EffectLayer::setColor(const half3& color) { |
Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 65 | 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 Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 79 | bool EffectLayer::setDataspace(ui::Dataspace dataspace) { |
Valerie Hau | b153bab | 2019-03-05 10:47:28 -0800 | [diff] [blame] | 80 | 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 Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 91 | void EffectLayer::preparePerFrameCompositionState() { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 92 | Layer::preparePerFrameCompositionState(); |
Dominik Laskowski | 3415776 | 2018-10-31 13:07:19 -0700 | [diff] [blame] | 93 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 94 | auto* compositionState = editCompositionState(); |
| 95 | compositionState->color = getColor(); |
| 96 | compositionState->compositionType = Hwc2::IComposerClient::Composition::SOLID_COLOR; |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 97 | } |
David Sodman | eb085e0 | 2017-10-05 18:49:04 -0700 | [diff] [blame] | 98 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 99 | sp<compositionengine::LayerFE> EffectLayer::getCompositionEngineLayerFE() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 100 | return asLayerFE(); |
| 101 | } |
| 102 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 103 | compositionengine::LayerFECompositionState* EffectLayer::editCompositionState() { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 104 | return mCompositionState.get(); |
| 105 | } |
| 106 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 107 | const compositionengine::LayerFECompositionState* EffectLayer::getCompositionState() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 108 | return mCompositionState.get(); |
Lloyd Pique | feb73d7 | 2018-12-04 17:23:44 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 111 | bool EffectLayer::isOpaque(const Layer::State& s) const { |
Vishnu Nair | 371626c | 2020-01-30 09:28:10 -0800 | [diff] [blame] | 112 | // 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; |
chaviw | 575144f | 2019-08-16 12:37:24 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 117 | ui::Dataspace EffectLayer::getDataSpace() const { |
chaviw | 4244e03 | 2019-09-04 11:27:49 -0700 | [diff] [blame] | 118 | return mDrawingState.dataspace; |
| 119 | } |
| 120 | |
Vishnu Nair | fa247b1 | 2020-02-11 08:58:26 -0800 | [diff] [blame^] | 121 | sp<Layer> EffectLayer::createClone() { |
| 122 | sp<EffectLayer> layer = mFlinger->getFactory().createEffectLayer( |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 123 | LayerCreationArgs(mFlinger.get(), nullptr, mName + " (Mirror)", 0, 0, 0, |
| 124 | LayerMetadata())); |
chaviw | b4c6e58 | 2019-08-16 14:35:07 -0700 | [diff] [blame] | 125 | layer->setInitialValuesForClone(this); |
| 126 | return layer; |
| 127 | } |
| 128 | |
Dominik Laskowski | 87a07e4 | 2019-10-10 20:38:02 -0700 | [diff] [blame] | 129 | } // namespace android |
Ady Abraham | b0dbdaa | 2020-01-06 16:19:42 -0800 | [diff] [blame] | 130 | |
| 131 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 132 | #pragma clang diagnostic pop // ignored "-Wconversion" |