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 | |
Alec Mouri | f4af03e | 2023-02-11 00:25:24 +0000 | [diff] [blame] | 19 | #include <android/gui/CachingHint.h> |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 20 | #include <gui/LayerMetadata.h> |
Brian Lindahl | f5fdff8 | 2024-11-01 09:28:47 -0600 | [diff] [blame] | 21 | #include <ui/LayerStack.h> |
| 22 | #include <ui/PictureProfileHandle.h> |
| 23 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 24 | #include "FrontEnd/LayerSnapshot.h" |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 25 | #include "compositionengine/LayerFE.h" |
| 26 | #include "compositionengine/LayerFECompositionState.h" |
| 27 | #include "renderengine/LayerSettings.h" |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 28 | |
| 29 | #include <ftl/future.h> |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 30 | |
| 31 | namespace android { |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 32 | |
| 33 | struct CompositionResult { |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 34 | sp<Fence> lastClientCompositionFence = nullptr; |
Brian Lindahl | f5fdff8 | 2024-11-01 09:28:47 -0600 | [diff] [blame] | 35 | bool wasPictureProfileCommitted = false; |
| 36 | // TODO(b/337330263): Why does LayerFE coming from SF have a null composition state? |
| 37 | // It would be better not to duplicate this information |
| 38 | PictureProfileHandle pictureProfileHandle = PictureProfileHandle::NONE; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE { |
| 42 | public: |
| 43 | LayerFE(const std::string& name); |
Melody Hsu | 5aeb816 | 2024-03-25 22:09:10 +0000 | [diff] [blame] | 44 | virtual ~LayerFE(); |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 45 | |
| 46 | // compositionengine::LayerFE overrides |
| 47 | const compositionengine::LayerFECompositionState* getCompositionState() const override; |
Melody Hsu | c949cde | 2024-03-12 01:43:34 +0000 | [diff] [blame] | 48 | bool onPreComposition(bool updatingOutputGeometryThisFrame) override; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 49 | const char* getDebugName() const override; |
| 50 | int32_t getSequence() const override; |
| 51 | bool hasRoundedCorners() const override; |
| 52 | void setWasClientComposed(const sp<Fence>&) override; |
| 53 | const gui::LayerMetadata* getMetadata() const override; |
| 54 | const gui::LayerMetadata* getRelativeMetadata() const override; |
| 55 | std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition( |
| 56 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
Brian Lindahl | f5fdff8 | 2024-11-01 09:28:47 -0600 | [diff] [blame] | 57 | CompositionResult stealCompositionResult(); |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 58 | ftl::Future<FenceResult> createReleaseFenceFuture() override; |
| 59 | void setReleaseFence(const FenceResult& releaseFence) override; |
| 60 | LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override; |
Brian Lindahl | f5fdff8 | 2024-11-01 09:28:47 -0600 | [diff] [blame] | 61 | void onPictureProfileCommitted() override; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 62 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 63 | std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal( |
| 67 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 68 | // Modifies the passed in layer settings to clear the contents. If the blackout flag is set, |
| 69 | // the settings clears the content with a solid black fill. |
| 70 | void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const; |
| 71 | void prepareShadowClientComposition(LayerFE::LayerSettings& caster, |
| 72 | const Rect& layerStackRect) const; |
| 73 | void prepareBufferStateClientComposition( |
| 74 | compositionengine::LayerFE::LayerSettings&, |
| 75 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 76 | void prepareEffectsClientComposition( |
| 77 | compositionengine::LayerFE::LayerSettings&, |
| 78 | compositionengine::LayerFE::ClientCompositionTargetSettings&) const; |
| 79 | |
| 80 | bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); } |
| 81 | bool hasBufferOrSidebandStream() const; |
| 82 | |
| 83 | bool fillsColor() const; |
| 84 | bool hasBlur() const; |
| 85 | bool drawShadows() const; |
| 86 | |
| 87 | const sp<GraphicBuffer> getBuffer() const; |
| 88 | |
| 89 | CompositionResult mCompositionResult; |
| 90 | std::string mName; |
Melody Hsu | 793f836 | 2024-01-08 20:00:35 +0000 | [diff] [blame] | 91 | std::promise<FenceResult> mReleaseFence; |
| 92 | ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED; |
Vishnu Nair | e14c6b3 | 2022-08-06 04:20:15 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | } // namespace android |