blob: c23bd31d1ac5b4250fbd01ba892a1a246964d289 [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 {
29 // TODO(b/238781169) update CE to no longer pass refreshStartTime to LayerFE::onPreComposition
30 // and remove this field.
31 nsecs_t refreshStartTime = 0;
32 std::vector<ftl::SharedFuture<FenceResult>> releaseFences;
33 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;
42 bool onPreComposition(nsecs_t refreshStartTime, bool updatingOutputGeometryThisFrame) override;
43 void onLayerDisplayed(ftl::SharedFuture<FenceResult>) override;
44 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();
53
Vishnu Nair8fc721b2022-12-22 20:06:32 +000054 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot;
Vishnu Naire14c6b32022-08-06 04:20:15 +000055
56private:
57 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
58 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
59 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
60 // the settings clears the content with a solid black fill.
61 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
62 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
63 const Rect& layerStackRect) const;
64 void prepareBufferStateClientComposition(
65 compositionengine::LayerFE::LayerSettings&,
66 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
67 void prepareEffectsClientComposition(
68 compositionengine::LayerFE::LayerSettings&,
69 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
70
71 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
72 bool hasBufferOrSidebandStream() const;
73
74 bool fillsColor() const;
75 bool hasBlur() const;
76 bool drawShadows() const;
77
78 const sp<GraphicBuffer> getBuffer() const;
79
80 CompositionResult mCompositionResult;
81 std::string mName;
82};
83
84} // namespace android