1 /* 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 <android/gui/CachingHint.h> 20 #include <gui/LayerMetadata.h> 21 #include "FrontEnd/LayerSnapshot.h" 22 #include "compositionengine/LayerFE.h" 23 #include "compositionengine/LayerFECompositionState.h" 24 #include "renderengine/LayerSettings.h" 25 26 namespace android { 27 28 struct 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<std::pair<ftl::SharedFuture<FenceResult>, ui::LayerStack>> releaseFences; 33 sp<Fence> lastClientCompositionFence = nullptr; 34 }; 35 36 class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE { 37 public: 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>, ui::LayerStack) 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 54 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot; 55 56 private: 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 hasEffect()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 85