blob: 66cb88b20eb190616ab2f9d97809123d94adbce1 [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"
25
26namespace android {
Vishnu Naire14c6b32022-08-06 04:20:15 +000027
28struct CompositionResult {
Vishnu Nair7ee4f462023-04-19 09:54:09 -070029 std::vector<std::pair<ftl::SharedFuture<FenceResult>, ui::LayerStack>> releaseFences;
Vishnu Naire14c6b32022-08-06 04:20:15 +000030 sp<Fence> lastClientCompositionFence = nullptr;
31};
32
33class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
34public:
35 LayerFE(const std::string& name);
36
37 // compositionengine::LayerFE overrides
38 const compositionengine::LayerFECompositionState* getCompositionState() const override;
Melody Hsuc949cde2024-03-12 01:43:34 +000039 bool onPreComposition(bool updatingOutputGeometryThisFrame) override;
Vishnu Nair7ee4f462023-04-19 09:54:09 -070040 void onLayerDisplayed(ftl::SharedFuture<FenceResult>, ui::LayerStack) override;
Vishnu Naire14c6b32022-08-06 04:20:15 +000041 const char* getDebugName() const override;
42 int32_t getSequence() const override;
43 bool hasRoundedCorners() const override;
44 void setWasClientComposed(const sp<Fence>&) override;
45 const gui::LayerMetadata* getMetadata() const override;
46 const gui::LayerMetadata* getRelativeMetadata() const override;
47 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
48 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
49 CompositionResult&& stealCompositionResult();
50
Vishnu Nair8fc721b2022-12-22 20:06:32 +000051 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000052
53private:
54 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
55 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
56 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
57 // the settings clears the content with a solid black fill.
58 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
59 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
60 const Rect& layerStackRect) const;
61 void prepareBufferStateClientComposition(
62 compositionengine::LayerFE::LayerSettings&,
63 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
64 void prepareEffectsClientComposition(
65 compositionengine::LayerFE::LayerSettings&,
66 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
67
68 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
69 bool hasBufferOrSidebandStream() const;
70
71 bool fillsColor() const;
72 bool hasBlur() const;
73 bool drawShadows() const;
74
75 const sp<GraphicBuffer> getBuffer() const;
76
77 CompositionResult mCompositionResult;
78 std::string mName;
79};
80
81} // namespace android