blob: b897a90687e9047cc0e3eb62439da2410b21a134 [file] [log] [blame]
Vishnu Naire14c6b32022-08-06 04:20:15 +00001/*
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 Mourif4af03e2023-02-11 00:25:24 +000019#include <android/gui/CachingHint.h>
Vishnu Naire14c6b32022-08-06 04:20:15 +000020#include <gui/LayerMetadata.h>
Alec Mouridf868ba2025-02-25 16:08:19 -080021#include <ui/GraphicBuffer.h>
Brian Lindahlf5fdff82024-11-01 09:28:47 -060022#include <ui/LayerStack.h>
23#include <ui/PictureProfileHandle.h>
24
Vishnu Nair8fc721b2022-12-22 20:06:32 +000025#include "FrontEnd/LayerSnapshot.h"
Vishnu Naire14c6b32022-08-06 04:20:15 +000026#include "compositionengine/LayerFE.h"
27#include "compositionengine/LayerFECompositionState.h"
28#include "renderengine/LayerSettings.h"
Melody Hsu793f8362024-01-08 20:00:35 +000029
30#include <ftl/future.h>
Vishnu Naire14c6b32022-08-06 04:20:15 +000031
32namespace android {
Vishnu Naire14c6b32022-08-06 04:20:15 +000033
34struct CompositionResult {
Vishnu Naire14c6b32022-08-06 04:20:15 +000035 sp<Fence> lastClientCompositionFence = nullptr;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060036 bool wasPictureProfileCommitted = false;
37 // TODO(b/337330263): Why does LayerFE coming from SF have a null composition state?
38 // It would be better not to duplicate this information
39 PictureProfileHandle pictureProfileHandle = PictureProfileHandle::NONE;
Vishnu Naire14c6b32022-08-06 04:20:15 +000040};
41
42class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
43public:
44 LayerFE(const std::string& name);
Melody Hsu5aeb8162024-03-25 22:09:10 +000045 virtual ~LayerFE();
Vishnu Naire14c6b32022-08-06 04:20:15 +000046
47 // compositionengine::LayerFE overrides
48 const compositionengine::LayerFECompositionState* getCompositionState() const override;
Melody Hsuc949cde2024-03-12 01:43:34 +000049 bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000050 const char* getDebugName() const override;
51 int32_t getSequence() const override;
52 bool hasRoundedCorners() const override;
53 void setWasClientComposed(const sp<Fence>&) override;
54 const gui::LayerMetadata* getMetadata() const override;
55 const gui::LayerMetadata* getRelativeMetadata() const override;
56 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
57 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060058 CompositionResult stealCompositionResult();
Melody Hsu793f8362024-01-08 20:00:35 +000059 ftl::Future<FenceResult> createReleaseFenceFuture() override;
60 void setReleaseFence(const FenceResult& releaseFence) override;
61 LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
Alec Mouridf868ba2025-02-25 16:08:19 -080062 void setReleasedBuffer(sp<GraphicBuffer> buffer) override;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060063 void onPictureProfileCommitted() override;
Cairn Overturfad9d5142025-02-05 11:11:50 -080064
65 // Used for debugging purposes, e.g. perfetto tracing, dumpsys.
66 void setLastHwcState(const HwcLayerDebugState &state) override;
67 const HwcLayerDebugState &getLastHwcState() const override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000068
Vishnu Nair8fc721b2022-12-22 20:06:32 +000069 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000070
71private:
72 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
73 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
74 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
75 // the settings clears the content with a solid black fill.
76 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
77 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
78 const Rect& layerStackRect) const;
79 void prepareBufferStateClientComposition(
80 compositionengine::LayerFE::LayerSettings&,
81 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
82 void prepareEffectsClientComposition(
83 compositionengine::LayerFE::LayerSettings&,
84 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
85
YCairn Overturf65fb1c62025-02-24 22:57:09 +000086 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur() || hasOutline(); }
Vishnu Naire14c6b32022-08-06 04:20:15 +000087 bool hasBufferOrSidebandStream() const;
88
89 bool fillsColor() const;
90 bool hasBlur() const;
91 bool drawShadows() const;
YCairn Overturf65fb1c62025-02-24 22:57:09 +000092 bool hasOutline() const;
Vishnu Naire14c6b32022-08-06 04:20:15 +000093
94 const sp<GraphicBuffer> getBuffer() const;
95
96 CompositionResult mCompositionResult;
97 std::string mName;
Melody Hsu793f8362024-01-08 20:00:35 +000098 std::promise<FenceResult> mReleaseFence;
99 ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
Cairn Overturfad9d5142025-02-05 11:11:50 -0800100 HwcLayerDebugState mLastHwcState;
Alec Mouridf868ba2025-02-25 16:08:19 -0800101 wp<GraphicBuffer> mReleasedBuffer;
Vishnu Naire14c6b32022-08-06 04:20:15 +0000102};
103
104} // namespace android