blob: 019fa227371981f1d735e8c3f64d90ed0deb2a07 [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#include "ui/LayerStack.h"
26
27#include <ftl/future.h>
Vishnu Naire14c6b32022-08-06 04:20:15 +000028
29namespace android {
Vishnu Naire14c6b32022-08-06 04:20:15 +000030
31struct CompositionResult {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070032 std::vector<std::pair<ftl::SharedFuture<FenceResult>, ui::LayerStack>> releaseFences;
Vishnu Naire14c6b32022-08-06 04:20:15 +000033 sp<Fence> lastClientCompositionFence = nullptr;
34};
35
36class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
37public:
38 LayerFE(const std::string& name);
39
40 // compositionengine::LayerFE overrides
41 const compositionengine::LayerFECompositionState* getCompositionState() const override;
Melody Hsuc949cde2024-03-12 01:43:34 +000042 bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
Vishnu Nair7ee4f462023-04-19 09:54:09 -070043 void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack) override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000044 const char* getDebugName() const override;
45 int32_t getSequence() const override;
46 bool hasRoundedCorners() const override;
47 void setWasClientComposed(const sp<Fence>&) override;
48 const gui::LayerMetadata* getMetadata() const override;
49 const gui::LayerMetadata* getRelativeMetadata() const override;
50 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
51 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
52 CompositionResult&& stealCompositionResult();
Melody Hsu793f8362024-01-08 20:00:35 +000053 ftl::Future<FenceResult> createReleaseFenceFuture() override;
54 void setReleaseFence(const FenceResult& releaseFence) override;
55 LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000056
Vishnu Nair8fc721b2022-12-22 20:06:32 +000057 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000058
59private:
60 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
61 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
62 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
63 // the settings clears the content with a solid black fill.
64 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
65 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
66 const Rect& layerStackRect) const;
67 void prepareBufferStateClientComposition(
68 compositionengine::LayerFE::LayerSettings&,
69 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
70 void prepareEffectsClientComposition(
71 compositionengine::LayerFE::LayerSettings&,
72 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
73
74 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
75 bool hasBufferOrSidebandStream() const;
76
77 bool fillsColor() const;
78 bool hasBlur() const;
79 bool drawShadows() const;
80
81 const sp<GraphicBuffer> getBuffer() const;
82
83 CompositionResult mCompositionResult;
84 std::string mName;
Melody Hsu793f8362024-01-08 20:00:35 +000085 std::promise<FenceResult> mReleaseFence;
86 ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
Vishnu Naire14c6b32022-08-06 04:20:15 +000087};
88
89} // namespace android