blob: e4f68897628334027b01def29a0091d377d3a8d2 [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;
60};
61
62struct CompositionResult {
63 // TODO(b/238781169) update CE to no longer pass refreshStartTime to LayerFE::onPreComposition
64 // and remove this field.
65 nsecs_t refreshStartTime = 0;
66 std::vector<ftl::SharedFuture<FenceResult>> releaseFences;
67 sp<Fence> lastClientCompositionFence = nullptr;
68};
69
70class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE {
71public:
72 LayerFE(const std::string& name);
73
74 // compositionengine::LayerFE overrides
75 const compositionengine::LayerFECompositionState* getCompositionState() const override;
76 bool onPreComposition(nsecs_t refreshStartTime, bool updatingOutputGeometryThisFrame) override;
77 void onLayerDisplayed(ftl::SharedFuture<FenceResult>) override;
78 const char* getDebugName() const override;
79 int32_t getSequence() const override;
80 bool hasRoundedCorners() const override;
81 void setWasClientComposed(const sp<Fence>&) override;
82 const gui::LayerMetadata* getMetadata() const override;
83 const gui::LayerMetadata* getRelativeMetadata() const override;
84 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition(
85 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
86 CompositionResult&& stealCompositionResult();
87
88 std::unique_ptr<LayerSnapshot> mSnapshot;
89
90private:
91 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal(
92 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
93 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set,
94 // the settings clears the content with a solid black fill.
95 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const;
96 void prepareShadowClientComposition(LayerFE::LayerSettings& caster,
97 const Rect& layerStackRect) const;
98 void prepareBufferStateClientComposition(
99 compositionengine::LayerFE::LayerSettings&,
100 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
101 void prepareEffectsClientComposition(
102 compositionengine::LayerFE::LayerSettings&,
103 compositionengine::LayerFE::ClientCompositionTargetSettings&) const;
104
105 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur(); }
106 bool hasBufferOrSidebandStream() const;
107
108 bool fillsColor() const;
109 bool hasBlur() const;
110 bool drawShadows() const;
111
112 const sp<GraphicBuffer> getBuffer() const;
113
114 CompositionResult mCompositionResult;
115 std::string mName;
116};
117
118} // namespace android