blob: 822bcb7a94183907f8acefb71d88d083599e8329 [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
19#include <gui/LayerMetadata.h>
20
21#include "compositionengine/LayerFE.h"
22#include "compositionengine/LayerFECompositionState.h"
23#include "renderengine/LayerSettings.h"
24
25namespace android {
26struct RoundedCornerState {
27 RoundedCornerState() = default;
28 RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
29 : cropRect(cropRect), radius(radius) {}
30
31 // Rounded rectangle in local layer coordinate space.
32 FloatRect cropRect = FloatRect();
33 // Radius of the rounded rectangle.
34 vec2 radius;
35 bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
36};
37
38// LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
39// Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
40// passed to Render Engine are created using properties stored on this struct.
41struct LayerSnapshot : public compositionengine::LayerFECompositionState {
42 int32_t sequence;
43 std::string name;
44 uint32_t textureName;
45 bool contentOpaque;
46 RoundedCornerState roundedCorner;
47 StretchEffect stretchEffect;
48 FloatRect transformedBounds;
49 renderengine::ShadowSettings shadowSettings;
50 bool premultipliedAlpha;
51 bool isHdrY410;
52 bool bufferNeedsFiltering;
53 ui::Transform transform;
54 Rect bufferSize;
55 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
56 gui::LayerMetadata layerMetadata;
57 gui::LayerMetadata relativeLayerMetadata;
58 bool contentDirty;
59 bool hasReadyFrame;
Vishnu Naire7613db2022-11-04 00:07:06 -070060 ui::Transform blurRegionTransform;
Vishnu Naire14c6b32022-08-06 04:20:15 +000061};
62
63struct CompositionResult {
64 // TODO(b/238781169) update CE to no longer pass refreshStartTime to LayerFE::onPreComposition
65 // and remove this field.
66 nsecs_t refreshStartTime = 0;
67 std::vector<ftl::SharedFuture<FenceResult>> releaseFences;
68 sp<Fence> lastClientCompositionFence = nullptr;
69};
70
71class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
72public:
73 LayerFE(const std::string& name);
74
75 // compositionengine::LayerFE overrides
76 const compositionengine::LayerFECompositionState* getCompositionState() const override;
77 bool onPreComposition(nsecs_t refreshStartTime, bool updatingOutputGeometryThisFrame) override;
78 void onLayerDisplayed(ftl::SharedFuture<FenceResult>) override;
79 const char* getDebugName() const override;
80 int32_t getSequence() const override;
81 bool hasRoundedCorners() const override;
82 void setWasClientComposed(const sp<Fence>&) override;
83 const gui::LayerMetadata* getMetadata() const override;
84 const gui::LayerMetadata* getRelativeMetadata() const override;
85 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
86 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
87 CompositionResult&& stealCompositionResult();
88
89 std::unique_ptr<LayerSnapshot> mSnapshot;
90
91private:
92 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
93 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
94 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
95 // the settings clears the content with a solid black fill.
96 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
97 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
98 const Rect& layerStackRect) const;
99 void prepareBufferStateClientComposition(
100 compositionengine::LayerFE::LayerSettings&,
101 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
102 void prepareEffectsClientComposition(
103 compositionengine::LayerFE::LayerSettings&,
104 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
105
106 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
107 bool hasBufferOrSidebandStream() const;
108
109 bool fillsColor() const;
110 bool hasBlur() const;
111 bool drawShadows() const;
112
113 const sp<GraphicBuffer> getBuffer() const;
114
115 CompositionResult mCompositionResult;
116 std::string mName;
117};
118
119} // namespace android