/* * Copyright 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace android::compositionengine { struct LayerFECompositionState; namespace impl { // The implementation class contains the common implementation, but does not // actually contain the final layer state. class OutputLayer : public virtual compositionengine::OutputLayer { public: ~OutputLayer() override; void setHwcLayer(std::shared_ptr) override; void updateCompositionState(bool includeGeometry, bool forceClientComposition, ui::Transform::RotationFlags) override; void writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z, bool zIsOverridden, bool isPeekingThrough) override; void writeCursorPositionToHWC() const override; HWC2::Layer* getHwcLayer() const override; bool requiresClientComposition() const override; bool isHardwareCursor() const override; void applyDeviceCompositionTypeChange( aidl::android::hardware::graphics::composer3::Composition) override; void prepareForDeviceLayerRequests() override; void applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) override; bool needsFiltering() const override; std::vector getOverrideCompositionList() const override; void dump(std::string&) const override; virtual FloatRect calculateOutputSourceCrop(uint32_t internalDisplayRotationFlags) const; virtual Rect calculateOutputDisplayFrame() const; virtual uint32_t calculateOutputRelativeBufferTransform( uint32_t internalDisplayRotationFlags) const; protected: // Implemented by the final implementation for the final state it uses. virtual void dumpState(std::string&) const = 0; private: Rect calculateInitialCrop() const; void writeOutputDependentGeometryStateToHWC( HWC2::Layer*, aidl::android::hardware::graphics::composer3::Composition, uint32_t z); void writeOutputIndependentGeometryStateToHWC(HWC2::Layer*, const LayerFECompositionState&, bool skipLayer); void writeOutputDependentPerFrameStateToHWC(HWC2::Layer*); void writeOutputIndependentPerFrameStateToHWC( HWC2::Layer*, const LayerFECompositionState&, aidl::android::hardware::graphics::composer3::Composition compositionType, bool skipLayer); void writeSolidColorStateToHWC(HWC2::Layer*, const LayerFECompositionState&); void writeSidebandStateToHWC(HWC2::Layer*, const LayerFECompositionState&); void writeBufferStateToHWC(HWC2::Layer*, const LayerFECompositionState&, bool skipLayer); void writeCompositionTypeToHWC(HWC2::Layer*, aidl::android::hardware::graphics::composer3::Composition, bool isPeekingThrough, bool skipLayer); void detectDisallowedCompositionTypeChange( aidl::android::hardware::graphics::composer3::Composition from, aidl::android::hardware::graphics::composer3::Composition to) const; bool isClientCompositionForced(bool isPeekingThrough) const; }; // This template factory function standardizes the implementation details of the // final class using the types actually required by the implementation. This is // not possible to do in the base class as those types may not even be visible // to the base code. template std::unique_ptr createOutputLayerTemplated(const Output& output, sp layerFE) { class OutputLayer final : public BaseOutputLayer { public: // Clang incorrectly complains that these are unused. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-local-typedef" using OutputLayerCompositionState = std::remove_const_t< std::remove_reference_t().getState())>>; using Output = std::remove_const_t< std::remove_reference_t().getOutput())>>; using LayerFE = std::remove_reference_t().getLayerFE())>; #pragma clang diagnostic pop OutputLayer(const Output& output, const sp& layerFE) : mOutput(output), mLayerFE(layerFE) { char value[PROPERTY_VALUE_MAX]; property_get("vendor.hwc.video_buf_cache_max_size", value, "0"); mCacheLimitSize = atoi(value); } ~OutputLayer() override = default; private: // compositionengine::OutputLayer overrides const Output& getOutput() const override { return mOutput; } LayerFE& getLayerFE() const override { return *mLayerFE; } const OutputLayerCompositionState& getState() const override { return mState; } OutputLayerCompositionState& editState() override { return mState; } // compositionengine::impl::OutputLayer overrides void dumpState(std::string& out) const override { mState.dump(out); } int32_t getCacheLimitSize() override { return mCacheLimitSize; } const Output& mOutput; const sp mLayerFE; OutputLayerCompositionState mState; int32_t mCacheLimitSize; }; return std::make_unique(output, layerFE); } std::unique_ptr createOutputLayer(const compositionengine::Output&, const sp&); } // namespace impl } // namespace android::compositionengine