blob: 9483aebafab404501f76c47e4088c654146ac223 [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>
Brian Lindahlf5fdff82024-11-01 09:28:47 -060021#include <ui/LayerStack.h>
22#include <ui/PictureProfileHandle.h>
23
Vishnu Nair8fc721b2022-12-22 20:06:32 +000024#include "FrontEnd/LayerSnapshot.h"
Vishnu Naire14c6b32022-08-06 04:20:15 +000025#include "compositionengine/LayerFE.h"
26#include "compositionengine/LayerFECompositionState.h"
27#include "renderengine/LayerSettings.h"
Melody Hsu793f8362024-01-08 20:00:35 +000028
29#include <ftl/future.h>
Vishnu Naire14c6b32022-08-06 04:20:15 +000030
31namespace android {
Vishnu Naire14c6b32022-08-06 04:20:15 +000032
33struct CompositionResult {
Vishnu Naire14c6b32022-08-06 04:20:15 +000034 sp<Fence> lastClientCompositionFence = nullptr;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060035 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;
Vishnu Naire14c6b32022-08-06 04:20:15 +000039};
40
41class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
42public:
43 LayerFE(const std::string& name);
Melody Hsu5aeb8162024-03-25 22:09:10 +000044 virtual ~LayerFE();
Vishnu Naire14c6b32022-08-06 04:20:15 +000045
46 // compositionengine::LayerFE overrides
47 const compositionengine::LayerFECompositionState* getCompositionState() const override;
Melody Hsuc949cde2024-03-12 01:43:34 +000048 bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000049 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;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060057 CompositionResult stealCompositionResult();
Melody Hsu793f8362024-01-08 20:00:35 +000058 ftl::Future<FenceResult> createReleaseFenceFuture() override;
59 void setReleaseFence(const FenceResult& releaseFence) override;
60 LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override;
Brian Lindahlf5fdff82024-11-01 09:28:47 -060061 void onPictureProfileCommitted() override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000062
Vishnu Nair8fc721b2022-12-22 20:06:32 +000063 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000064
65private:
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
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;
Melody Hsu793f8362024-01-08 20:00:35 +000091 std::promise<FenceResult> mReleaseFence;
92 ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED;
Vishnu Naire14c6b32022-08-06 04:20:15 +000093};
94
95} // namespace android