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 <ui/GraphicBuffer.h> 22 #include <ui/LayerStack.h> 23 #include <ui/PictureProfileHandle.h> 24 25 #include "FrontEnd/LayerSnapshot.h" 26 #include "compositionengine/LayerFE.h" 27 #include "compositionengine/LayerFECompositionState.h" 28 #include "renderengine/LayerSettings.h" 29 30 #include <ftl/future.h> 31 32 namespace android { 33 34 struct CompositionResult { 35 sp<Fence> lastClientCompositionFence = nullptr; 36 bool wasPictureProfileCommitted = false; 37 // TODO(b/337330263): Why does LayerFE coming from SF have a null composition state? 38 // It would be better not to duplicate this information 39 PictureProfileHandle pictureProfileHandle = PictureProfileHandle::NONE; 40 }; 41 42 class LayerFE : public virtual RefBase, public virtual compositionengine::LayerFE { 43 public: 44 LayerFE(const std::string& name); 45 virtual ~LayerFE(); 46 47 // compositionengine::LayerFE overrides 48 const compositionengine::LayerFECompositionState* getCompositionState() const override; 49 bool onPreComposition(bool updatingOutputGeometryThisFrame) override; 50 const char* getDebugName() const override; 51 int32_t getSequence() const override; 52 bool hasRoundedCorners() const override; 53 void setWasClientComposed(const sp<Fence>&) override; 54 const gui::LayerMetadata* getMetadata() const override; 55 const gui::LayerMetadata* getRelativeMetadata() const override; 56 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition( 57 compositionengine::LayerFE::ClientCompositionTargetSettings&) const; 58 CompositionResult stealCompositionResult(); 59 ftl::Future<FenceResult> createReleaseFenceFuture() override; 60 void setReleaseFence(const FenceResult& releaseFence) override; 61 LayerFE::ReleaseFencePromiseStatus getReleaseFencePromiseStatus() override; 62 void setReleasedBuffer(sp<GraphicBuffer> buffer) override; 63 void onPictureProfileCommitted() override; 64 65 // Used for debugging purposes, e.g. perfetto tracing, dumpsys. 66 void setLastHwcState(const HwcLayerDebugState &state) override; 67 const HwcLayerDebugState &getLastHwcState() const override; 68 69 std::unique_ptr<surfaceflinger::frontend::LayerSnapshot> mSnapshot; 70 71 private: 72 std::optional<compositionengine::LayerFE::LayerSettings> prepareClientCompositionInternal( 73 compositionengine::LayerFE::ClientCompositionTargetSettings&) const; 74 // Modifies the passed in layer settings to clear the contents. If the blackout flag is set, 75 // the settings clears the content with a solid black fill. 76 void prepareClearClientComposition(LayerFE::LayerSettings&, bool blackout) const; 77 void prepareShadowClientComposition(LayerFE::LayerSettings& caster, 78 const Rect& layerStackRect) const; 79 void prepareBufferStateClientComposition( 80 compositionengine::LayerFE::LayerSettings&, 81 compositionengine::LayerFE::ClientCompositionTargetSettings&) const; 82 void prepareEffectsClientComposition( 83 compositionengine::LayerFE::LayerSettings&, 84 compositionengine::LayerFE::ClientCompositionTargetSettings&) const; 85 hasEffect()86 bool hasEffect() const { return fillsColor() || drawShadows() || hasBlur() || hasOutline(); } 87 bool hasBufferOrSidebandStream() const; 88 89 bool fillsColor() const; 90 bool hasBlur() const; 91 bool drawShadows() const; 92 bool hasOutline() const; 93 94 const sp<GraphicBuffer> getBuffer() const; 95 96 CompositionResult mCompositionResult; 97 std::string mName; 98 std::promise<FenceResult> mReleaseFence; 99 ReleaseFencePromiseStatus mReleaseFencePromiseStatus = ReleaseFencePromiseStatus::UNINITIALIZED; 100 HwcLayerDebugState mLastHwcState; 101 wp<GraphicBuffer> mReleasedBuffer; 102 }; 103 104 } // namespace android 105