blob: 5081e102b8b8b761d39d636ec509372cb2d7ce55 [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>
Vishnu Nair8fc721b2022-12-22 20:06:32 +000021#include "FrontEnd/LayerSnapshot.h"
Vishnu Naire14c6b32022-08-06 04:20:15 +000022#include "compositionengine/LayerFE.h"
23#include "compositionengine/LayerFECompositionState.h"
24#include "renderengine/LayerSettings.h"
Melody Hsu793f8362024-01-08 20:00:35 +000025
26#include <ftl/future.h>
Vishnu Naire14c6b32022-08-06 04:20:15 +000027
28namespace android {
Vishnu Naire14c6b32022-08-06 04:20:15 +000029
30struct CompositionResult {
Vishnu Naire14c6b32022-08-06 04:20:15 +000031 sp<Fence> lastClientCompositionFence = nullptr;
32};
33
34class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
35public:
36 LayerFE(const std::string& name);
Melody Hsu5aeb8162024-03-25 22:09:10 +000037 virtual ~LayerFE();
Vishnu Naire14c6b32022-08-06 04:20:15 +000038
39 // compositionengine::LayerFE overrides
40 const compositionengine::LayerFECompositionState* getCompositionState() const override;
Melody Hsuc949cde2024-03-12 01:43:34 +000041 bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000042 const char* getDebugName() const override;
43 int32_t getSequence() const override;
44 bool hasRoundedCorners() const override;
45 void setWasClientComposed(const sp<Fence>&) override;
46 const gui::LayerMetadata* getMetadata() const override;
47 const gui::LayerMetadata* getRelativeMetadata() const override;
48 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
49 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
50 CompositionResult&& stealCompositionResult();
Melody Hsu793f8362024-01-08 20:00:35 +000051 ftl::Future<FenceResult> createReleaseFenceFuture() override;
52 void setReleaseFence(const FenceResult& releaseFence) override;
53 LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000054
Vishnu Nair8fc721b2022-12-22 20:06:32 +000055 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000056
57private:
58 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
59 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
60 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
61 // the settings clears the content with a solid black fill.
62 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
63 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
64 const Rect& layerStackRect) const;
65 void prepareBufferStateClientComposition(
66 compositionengine::LayerFE::LayerSettings&,
67 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
68 void prepareEffectsClientComposition(
69 compositionengine::LayerFE::LayerSettings&,
70 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
71
72 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
73 bool hasBufferOrSidebandStream() const;
74
75 bool fillsColor() const;
76 bool hasBlur() const;
77 bool drawShadows() const;
78
79 const sp<GraphicBuffer> getBuffer() const;
80
81 CompositionResult mCompositionResult;
82 std::string mName;
Melody Hsu793f8362024-01-08 20:00:35 +000083 std::promise<FenceResult> mReleaseFence;
84 ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
Vishnu Naire14c6b32022-08-06 04:20:15 +000085};
86
87} // namespace android