xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/LayerFE.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <android/gui/CachingHint.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <gui/LayerMetadata.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <ui/LayerStack.h>
22*38e8c45fSAndroid Build Coastguard Worker #include <ui/PictureProfileHandle.h>
23*38e8c45fSAndroid Build Coastguard Worker 
24*38e8c45fSAndroid Build Coastguard Worker #include "FrontEnd/LayerSnapshot.h"
25*38e8c45fSAndroid Build Coastguard Worker #include "compositionengine/LayerFE.h"
26*38e8c45fSAndroid Build Coastguard Worker #include "compositionengine/LayerFECompositionState.h"
27*38e8c45fSAndroid Build Coastguard Worker #include "renderengine/LayerSettings.h"
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker #include <ftl/future.h>
30*38e8c45fSAndroid Build Coastguard Worker 
31*38e8c45fSAndroid Build Coastguard Worker namespace android {
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker struct CompositionResult {
34*38e8c45fSAndroid Build Coastguard Worker     sp<Fence> lastClientCompositionFence = nullptr;
35*38e8c45fSAndroid Build Coastguard Worker     bool wasPictureProfileCommitted = false;
36*38e8c45fSAndroid Build Coastguard Worker     // TODO(b/337330263): Why does LayerFE coming from SF have a null composition state?
37*38e8c45fSAndroid Build Coastguard Worker     // It would be better not to duplicate this information
38*38e8c45fSAndroid Build Coastguard Worker     PictureProfileHandle pictureProfileHandle = PictureProfileHandle::NONE;
39*38e8c45fSAndroid Build Coastguard Worker };
40*38e8c45fSAndroid Build Coastguard Worker 
41*38e8c45fSAndroid Build Coastguard Worker class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
42*38e8c45fSAndroid Build Coastguard Worker public:
43*38e8c45fSAndroid Build Coastguard Worker     LayerFE(const std::string& name);
44*38e8c45fSAndroid Build Coastguard Worker     virtual ~LayerFE();
45*38e8c45fSAndroid Build Coastguard Worker 
46*38e8c45fSAndroid Build Coastguard Worker     // compositionengine::LayerFE overrides
47*38e8c45fSAndroid Build Coastguard Worker     const compositionengine::LayerFECompositionState* getCompositionState() const override;
48*38e8c45fSAndroid Build Coastguard Worker     bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
49*38e8c45fSAndroid Build Coastguard Worker     const char* getDebugName() const override;
50*38e8c45fSAndroid Build Coastguard Worker     int32_t getSequence() const override;
51*38e8c45fSAndroid Build Coastguard Worker     bool hasRoundedCorners() const override;
52*38e8c45fSAndroid Build Coastguard Worker     void setWasClientComposed(const sp<Fence>&) override;
53*38e8c45fSAndroid Build Coastguard Worker     const gui::LayerMetadata* getMetadata() const override;
54*38e8c45fSAndroid Build Coastguard Worker     const gui::LayerMetadata* getRelativeMetadata() const override;
55*38e8c45fSAndroid Build Coastguard Worker     std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
56*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
57*38e8c45fSAndroid Build Coastguard Worker     CompositionResult stealCompositionResult();
58*38e8c45fSAndroid Build Coastguard Worker     ftl::Future<FenceResult> createReleaseFenceFuture() override;
59*38e8c45fSAndroid Build Coastguard Worker     void setReleaseFence(const FenceResult& releaseFence) override;
60*38e8c45fSAndroid Build Coastguard Worker     LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
61*38e8c45fSAndroid Build Coastguard Worker     void onPictureProfileCommitted() override;
62*38e8c45fSAndroid Build Coastguard Worker 
63*38e8c45fSAndroid Build Coastguard Worker     std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
64*38e8c45fSAndroid Build Coastguard Worker 
65*38e8c45fSAndroid Build Coastguard Worker private:
66*38e8c45fSAndroid Build Coastguard Worker     std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
67*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
68*38e8c45fSAndroid Build Coastguard Worker     // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
69*38e8c45fSAndroid Build Coastguard Worker     // the settings clears the content with a solid black fill.
70*38e8c45fSAndroid Build Coastguard Worker     void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
71*38e8c45fSAndroid Build Coastguard Worker     void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
72*38e8c45fSAndroid Build Coastguard Worker                                         const Rect& layerStackRect) const;
73*38e8c45fSAndroid Build Coastguard Worker     void prepareBufferStateClientComposition(
74*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::LayerSettings&,
75*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
76*38e8c45fSAndroid Build Coastguard Worker     void prepareEffectsClientComposition(
77*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::LayerSettings&,
78*38e8c45fSAndroid Build Coastguard Worker             compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
79*38e8c45fSAndroid Build Coastguard Worker 
hasEffect()80*38e8c45fSAndroid Build Coastguard Worker     bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
81*38e8c45fSAndroid Build Coastguard Worker     bool hasBufferOrSidebandStream() const;
82*38e8c45fSAndroid Build Coastguard Worker 
83*38e8c45fSAndroid Build Coastguard Worker     bool fillsColor() const;
84*38e8c45fSAndroid Build Coastguard Worker     bool hasBlur() const;
85*38e8c45fSAndroid Build Coastguard Worker     bool drawShadows() const;
86*38e8c45fSAndroid Build Coastguard Worker 
87*38e8c45fSAndroid Build Coastguard Worker     const sp<GraphicBuffer> getBuffer() const;
88*38e8c45fSAndroid Build Coastguard Worker 
89*38e8c45fSAndroid Build Coastguard Worker     CompositionResult mCompositionResult;
90*38e8c45fSAndroid Build Coastguard Worker     std::string mName;
91*38e8c45fSAndroid Build Coastguard Worker     std::promise<FenceResult> mReleaseFence;
92*38e8c45fSAndroid Build Coastguard Worker     ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
93*38e8c45fSAndroid Build Coastguard Worker };
94*38e8c45fSAndroid Build Coastguard Worker 
95*38e8c45fSAndroid Build Coastguard Worker } // namespace android
96