xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/LayerFE.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
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 <android/gui/CachingHint.h>
20 #include <gui/LayerMetadata.h>
21 #include <ui/LayerStack.h>
22 #include <ui/PictureProfileHandle.h>
23 
24 #include "FrontEnd/LayerSnapshot.h"
25 #include "compositionengine/LayerFE.h"
26 #include "compositionengine/LayerFECompositionState.h"
27 #include "renderengine/LayerSettings.h"
28 
29 #include <ftl/future.h>
30 
31 namespace android {
32 
33 struct CompositionResult {
34     sp<Fence> lastClientCompositionFence = nullptr;
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;
39 };
40 
41 class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
42 public:
43     LayerFE(const std::string& name);
44     virtual ~LayerFE();
45 
46     // compositionengine::LayerFE overrides
47     const compositionengine::LayerFECompositionState* getCompositionState() const override;
48     bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
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;
57     CompositionResult stealCompositionResult();
58     ftl::Future<FenceResult> createReleaseFenceFuture() override;
59     void setReleaseFence(const FenceResult& releaseFence) override;
60     LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
61     void onPictureProfileCommitted() override;
62 
63     std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
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 
hasEffect()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;
91     std::promise<FenceResult> mReleaseFence;
92     ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
93 };
94 
95 } // namespace android
96