Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | #pragma once |
| 18 | |
| 19 | #include <gui/LayerMetadata.h> |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 20 | #include "FrontEnd/LayerSnapshot.h" |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 21 | #include "compositionengine/LayerFE.h" |
| 22 | #include "compositionengine/LayerFECompositionState.h" |
| 23 | #include "renderengine/LayerSettings.h" |
| 24 | |
| 25 | namespace android { |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 26 | |
| 27 | struct CompositionResult { |
| 28 | // TODO(b/238781169) update CE to no longer pass refreshStartTime to LayerFE::onPreComposition |
| 29 | // and remove this field. |
| 30 | nsecs_t refreshStartTime = 0; |
| 31 | std::vector<ftl::SharedFuture<FenceResult>> releaseFences; |
| 32 | sp<Fence> lastClientCompositionFence = nullptr; |
| 33 | }; |
| 34 | |
| 35 | class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE { |
| 36 | public: |
| 37 | LayerFE(const std::string& name); |
| 38 | |
| 39 | // compositionengine::LayerFE overrides |
| 40 | const compositionengine::LayerFECompositionState* getCompositionState() const override; |
| 41 | bool onPreComposition(nsecs_t refreshStartTime, bool updatingOutputGeometryThisFrame) override; |
| 42 | void onLayerDisplayed(ftl::SharedFuture<FenceResult>) override; |
| 43 | const char* getDebugName() const override; |
| 44 | int32_t getSequence() const override; |
| 45 | bool hasRoundedCorners() const override; |
| 46 | void setWasClientComposed(const sp<Fence>&) override; |
| 47 | const gui::LayerMetadata* getMetadata() const override; |
| 48 | const gui::LayerMetadata* getRelativeMetadata() const override; |
| 49 | std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition( |
| 50 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 51 | CompositionResult&& stealCompositionResult(); |
| 52 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 53 | std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal( |
| 57 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 58 | // Modifies the passed in layer settings to clear the contents. If the blackout flag is set, |
| 59 | // the settings clears the content with a solid black fill. |
| 60 | void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const; |
| 61 | void prepareShadowClientComposition(LayerFE::LayerSettings& caster, |
| 62 | const Rect& layerStackRect) const; |
| 63 | void prepareBufferStateClientComposition( |
| 64 | compositionengine::LayerFE::LayerSettings&, |
| 65 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 66 | void prepareEffectsClientComposition( |
| 67 | compositionengine::LayerFE::LayerSettings&, |
| 68 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 69 | |
| 70 | bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); } |
| 71 | bool hasBufferOrSidebandStream() const; |
| 72 | |
| 73 | bool fillsColor() const; |
| 74 | bool hasBlur() const; |
| 75 | bool drawShadows() const; |
| 76 | |
| 77 | const sp<GraphicBuffer> getBuffer() const; |
| 78 | |
| 79 | CompositionResult mCompositionResult; |
| 80 | std::string mName; |
| 81 | }; |
| 82 | |
| 83 | } // namespace android |