From 4af9edeed6d3bd8bf924a12afb371929ec61dfd4 Mon Sep 17 00:00:00 2001 From: tttaaaooo Date: Sat, 19 Jul 2025 16:12:17 +0800 Subject: [PATCH 01/12] Add RsLayer part update for multi pipeline. Signed-off-by: tttaaaooo --- interfaces/inner_api/common/graphic_common.h | 1 + .../inner_api/common/graphic_common_c.h | 14 + .../composer_base/rs_layer_cmd_def.in | 16 ++ .../composer_base/rs_layer_property_def.in | 16 ++ .../composer_base/rs_render_layer_cmd.cpp | 85 ++++++ .../composer_base/rs_render_layer_cmd.h | 82 ++++++ .../rs_render_layer_property.cpp | 40 +++ .../composer_base/rs_render_layer_property.h | 110 +++++++ .../composer/composer_client/rs_layer.h | 142 +++++++++ .../composer_client/rs_layer_alpha_cmd.h | 44 +++ .../composer/composer_client/rs_layer_cmd.cpp | 46 +++ .../composer/composer_client/rs_layer_cmd.h | 68 +++++ .../composer_client/rs_layer_cmd_type.h | 54 ++++ .../composer_client/rs_layer_impl.cpp | 125 ++++++++ .../composer/composer_client/rs_layer_impl.h | 272 ++++++++++++++++++ .../composer_client/rs_layer_property.h | 84 ++++++ .../transactiondata/compositor_connection.cpp | 71 +++++ .../transactiondata/compositor_connection.h | 59 ++++ .../compositor_connection_proxy.cpp | 73 +++++ .../compositor_connection_proxy.h | 43 +++ .../compositor_connection_stub.cpp | 58 ++++ .../compositor_connection_stub.h | 38 +++ .../transactiondata/icompositor_connection.h | 45 +++ .../rs_render_service_connection.cpp | 15 + .../rs_render_service_connection.h | 6 + .../rs_uni_render_composer_adapter.cpp | 31 +- .../rs_uni_render_composer_adapter.h | 1 + .../rs_render_service_connection_stub.cpp | 40 +++ .../ohos/rs_irender_service_connection.h | 5 + ...er_service_connection_ipc_interface_code.h | 1 + .../rs_render_service_connection_proxy.cpp | 60 +++- .../ohos/rs_render_service_connection_proxy.h | 5 + 32 files changed, 1728 insertions(+), 22 deletions(-) create mode 100644 rosen/modules/composer/composer_base/rs_layer_cmd_def.in create mode 100644 rosen/modules/composer/composer_base/rs_layer_property_def.in create mode 100644 rosen/modules/composer/composer_base/rs_render_layer_cmd.cpp create mode 100644 rosen/modules/composer/composer_base/rs_render_layer_cmd.h create mode 100644 rosen/modules/composer/composer_base/rs_render_layer_property.cpp create mode 100644 rosen/modules/composer/composer_base/rs_render_layer_property.h create mode 100644 rosen/modules/composer/composer_client/rs_layer.h create mode 100644 rosen/modules/composer/composer_client/rs_layer_alpha_cmd.h create mode 100644 rosen/modules/composer/composer_client/rs_layer_cmd.cpp create mode 100644 rosen/modules/composer/composer_client/rs_layer_cmd.h create mode 100644 rosen/modules/composer/composer_client/rs_layer_cmd_type.h create mode 100644 rosen/modules/composer/composer_client/rs_layer_impl.cpp create mode 100644 rosen/modules/composer/composer_client/rs_layer_impl.h create mode 100644 rosen/modules/composer/composer_client/rs_layer_property.h create mode 100644 rosen/modules/composer/transactiondata/compositor_connection.cpp create mode 100644 rosen/modules/composer/transactiondata/compositor_connection.h create mode 100644 rosen/modules/composer/transactiondata/compositor_connection_proxy.cpp create mode 100644 rosen/modules/composer/transactiondata/compositor_connection_proxy.h create mode 100644 rosen/modules/composer/transactiondata/compositor_connection_stub.cpp create mode 100644 rosen/modules/composer/transactiondata/compositor_connection_stub.h create mode 100644 rosen/modules/composer/transactiondata/icompositor_connection.h diff --git a/interfaces/inner_api/common/graphic_common.h b/interfaces/inner_api/common/graphic_common.h index 7966e63c0c..586e9ee914 100644 --- a/interfaces/inner_api/common/graphic_common.h +++ b/interfaces/inner_api/common/graphic_common.h @@ -117,6 +117,7 @@ inline bool operator !=(GSError a, GSError b) using WMError = GSError; using SurfaceError = GSError; using VsyncError = GSError; +using CompositorError = GSError; } // namespace OHOS #endif // __cplusplus diff --git a/interfaces/inner_api/common/graphic_common_c.h b/interfaces/inner_api/common/graphic_common_c.h index 8ecda1e1c1..8c4641f801 100644 --- a/interfaces/inner_api/common/graphic_common_c.h +++ b/interfaces/inner_api/common/graphic_common_c.h @@ -124,5 +124,19 @@ typedef enum { VSYNC_ERROR_NOT_SUPPORT = GSERROR_NOT_SUPPORT, VSYNC_ERROR_NOT_INIT = GSERROR_NOT_INIT, VSYNC_ERROR_UNKOWN = GSERROR_INTERNAL, + + COMPOSITOR_ERROR_OK = GSERROR_OK, + COMPOSITOR_ERROR_API_FAILED = GSERROR_API_FAILED, + COMPOSITOR_ERROR_INVALID_OPERATING = GSERROR_INVALID_OPERATING, + COMPOSITOR_ERROR_NULLPTR = GSERROR_INVALID_ARGUMENTS, + COMPOSITOR_ERROR_BINDER_ERROR = GSERROR_BINDER, + COMPOSITOR_ERROR_SAMGR = GSERROR_CONNOT_CONNECT_SAMGR, + COMPOSITOR_ERROR_SERVICE_NOT_FOUND = GSERROR_SERVER_ERROR, + COMPOSITOR_ERROR_PROXY_NOT_INCLUDE = GSERROR_PROXY_NOT_INCLUDE, + COMPOSITOR_ERROR_INNER = GSERROR_INTERNAL, + COMPOSITOR_ERROR_INVALID_ARGUMENTS = GSERROR_INVALID_ARGUMENTS, + COMPOSITOR_ERROR_NOT_SUPPORT = GSERROR_NOT_SUPPORT, + COMPOSITOR_ERROR_NOT_INIT = GSERROR_NOT_INIT, + COMPOSITOR_ERROR_UNKOWN = GSERROR_INTERNAL, } GSError; #endif // INTERFACES_INNERKITS_COMMON_GRAPHIC_COMMON_H diff --git a/rosen/modules/composer/composer_base/rs_layer_cmd_def.in b/rosen/modules/composer/composer_base/rs_layer_cmd_def.in new file mode 100644 index 0000000000..46612c3654 --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_layer_cmd_def.in @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +DECLARE_RSLAYER_CMD(Alpha, float, ALPHA, Multiply, COARSE) diff --git a/rosen/modules/composer/composer_base/rs_layer_property_def.in b/rosen/modules/composer/composer_base/rs_layer_property_def.in new file mode 100644 index 0000000000..a5162d0b40 --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_layer_property_def.in @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +DECLARE_RSLAYER_PROPERTY(float, ALPHA) diff --git a/rosen/modules/composer/composer_base/rs_render_layer_cmd.cpp b/rosen/modules/composer/composer_base/rs_render_layer_cmd.cpp new file mode 100644 index 0000000000..fe370877ea --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_render_layer_cmd.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#include "rsrenderlayer_cmd.h" + +namespace OHOS { +namespace Rosen { + +using ModifierUnmarshallingFunc = RSRenderLayerCmd* (*)(Parcel& parcel); + +#define DECLARE_RSLAYER_CMD(CMD_NAME, TYPE, CMD_TYPE, DELTA_OP, THRESHOLD_TYPE) \ + { \ + RSLayerCmdType::CMD_TYPE, \ + [](Parcel& parcel) -> RSRenderLayerCmd* { \ + std::shared_ptr> prop; \ + if (!RSMarshallingHelper::Unmarshalling(parcel, prop)) { \ + return nullptr; \ + } \ + auto command = new RSRender##CMD_NAME##Cmd(prop); \ + return command; \ + }, \ + }, + +static std::unordered_map funcLUT = { +#include "rslayer_cmd_def.in" +}; +#undef DECLARE_RSLAYER_CMD + +RSRenderLayerCmd* RSRenderLayerCmd::Unmarshalling(Parcel& parcel) +{ + int16_t type = 0; + if (!parcel.ReadInt16(type)) { + ROSEN_LOGE("RSRenderLayerCmd::Unmarshalling ReadInt16 failed"); + return nullptr; + } + auto it = funcLUT.find(static_cast(type)); + if (it == funcLUT.end()) { + ROSEN_LOGE("RSRenderLayerCmd Unmarshalling cannot find func in lut %{public}d", type); + return nullptr; + } + return it->second(parcel); +} + +#define DECLARE_RSLAYER_CMD(CMD_NAME, TYPE, CMD_TYPE, DELTA_OP, THRESHOLD_TYPE) \ + bool RSRender##CMD_NAME##Cmd::Marshalling(Parcel& parcel) \ + { \ + auto renderProperty = std::static_pointer_cast>(property_); \ + bool flag = parcel.WriteInt16(static_cast(RSLayerCmdType::CMD_TYPE)) && \ + RSMarshallingHelper::Marshalling(parcel, renderProperty); \ + if (!flag) { \ + ROSEN_LOGE("RSRenderLayerCmd::Marshalling WriteInt16 or Marshalling failed"); \ + } \ + return flag; \ + } \ + void RSRender##CMD_NAME##Cmd::Apply(RSLayerContext& context) const \ + { \ + auto renderProperty = std::static_pointer_cast>(property_); \ + context.properties_.Set##CMD_NAME( \ + DELTA_OP(context.properties_.Get##CMD_NAME(), renderProperty->Get())); \ + } \ + void RSRender##CMD_NAME##Cmd::Update(const std::shared_ptr& prop, bool isDelta) \ + { \ + if (auto property = std::static_pointer_cast>(prop)) { \ + auto renderProperty = std::static_pointer_cast>(property_); \ + renderProperty->Set(isDelta ? (renderProperty->Get() + property->Get()) : property->Get()); \ + } \ + } + +#include "rslayer_cmd_def.in" + +#undef DECLARE_RSLAYER_CMD +} // namespace Rosen +} // namespace OHOS diff --git a/rosen/modules/composer/composer_base/rs_render_layer_cmd.h b/rosen/modules/composer/composer_base/rs_render_layer_cmd.h new file mode 100644 index 0000000000..eab981835c --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_render_layer_cmd.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_RENDER_LAYER_CMD_H +#define COMPOSER_CLIENT_RS_RENDER_LAYER_CMD_H + +#include + +#include "parcel.h" +#include "rslayer_cmd_type.h" + +namespace OHOS { +namespace Rosen { + +class RSLayerContext { +public: + RSLayerContext() = default; + ~RSLayerContext() = default; +}; + +class RSC_EXPORT RSRenderLayerCmd { +public: + RSRenderLayerCmd(const RSRenderLayerCmd&) = delete; + RSRenderLayerCmd(const RSRenderLayerCmd&&) = delete; + RSRenderLayerCmd& operator=(const RSRenderLayerCmd&) = delete; + RSRenderLayerCmd& operator=(const RSRenderLayerCmd&&) = delete; + virtual ~RSRenderLayerCmd() = default; + + virtual PropertyId GetPropertyId() = 0; + virtual std::shared_ptr GetProperty() const = 0; + + virtual RSLayerCmdType GetRsRenderLayerCmdType() const + { + return RSLayerCmdType::INVALID; + } + + virtual void Apply(RSLayerContext& context) const = 0; + virtual void Update(const std::shared_ptr& prop, bool isDelta) = 0; + virtual bool Marshalling(Parcel& parcel) = 0; + [[nodiscard]] static RSRenderLayerCmd* Unmarshalling(Parcel& parcel); + +protected: + std::shared_ptr property_; +}; + +#define DECLARE_RSLAYER_CMD(CMD_NAME, TYPE, CMD_TYPE, DELTA_OP, THRESHOLD_TYPE) \ + class RSB_EXPORT RSRender##CMD_NAME##Cmd : public RSRenderLayerCmd { \ + public: \ + RSRender##CMD_NAME##Cmd(const std::shared_ptr& property) \ + : RSRenderLayerCmd(property) \ + { \ + property->SetModifierType(RSLayerCmdType::CMD_TYPE); \ + } \ + virtual ~RSRender##CMD_NAME##Cmd() = default; \ + void Apply(RSLayerContext& context) const override; \ + void Update(const std::shared_ptr& prop, bool isDelta) override; \ + bool Marshalling(Parcel& parcel) override; \ + RSLayerCmdType GetRsRenderLayerCmdType() override \ + { \ + return (RSLayerCmdType::CMD_TYPE); \ + } \ \ + }; + +#include "rslayer_cmd_def.in" + +#undef DECLARE_RSLAYER_CMD +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_RENDER_LAYER_CMD_H \ No newline at end of file diff --git a/rosen/modules/composer/composer_base/rs_render_layer_property.cpp b/rosen/modules/composer/composer_base/rs_render_layer_property.cpp new file mode 100644 index 0000000000..d57ea81266 --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_render_layer_property.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#include "rsrenderlayer_property.h" + +namespace OHOS { +namespace Rosen { + +template +bool RSRenderLayerProperty::OnUnmarshalling(Parcel& parcel, std::shared_ptr& val) +{ + auto ret = new RSRenderLayerProperty(); + if (ret == nullptr) { + ROSEN_LOGE("%s Creating property failed", __PRETTY_FUNCTION__); + return false; + } + if (!RSMarshallingHelper::UnmarshallingPidPlusId(parcel, ret->id_) || + !RSMarshallingHelper::Unmarshalling(parcel, ret->stagingValue_)) { + ROSEN_LOGE("%s Unmarshalling failed", __PRETTY_FUNCTION__); + delete ret; + return false; + } + val.reset(ret); + return true; +} + +} // namespace Rosen +} // namespace OHOS diff --git a/rosen/modules/composer/composer_base/rs_render_layer_property.h b/rosen/modules/composer/composer_base/rs_render_layer_property.h new file mode 100644 index 0000000000..f01b476a41 --- /dev/null +++ b/rosen/modules/composer/composer_base/rs_render_layer_property.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_RENDER_LAYER_PROPERTY_H +#define COMPOSER_CLIENT_RS_RENDER_LAYER_PROPERTY_H + +#include +#include + +#include "rslayer_cmd_type.h" + +namespace OHOS { +namespace Rosen { + +enum class RSLayerPropertyType : uint8_t { + INVALID = 0, + BOOL, + INT, + SHORT, + FLOAT, + + MAX_RS_LAYER_PROPERTY_TYPE = 255, +}; + +template +class RSC_EXPORT RSRenderLayerProperty : public std::enable_shared_from_this { +public: + RSRenderLayerProperty() = default; + + explicit RSRenderLayerProperty(const T& value) + { + stagingValue_ = value; + } + + ~RSRenderLayerProperty() = default; + + using ValueType = T; + + virtual void Set(const T& value) + { + if (ROSEN_EQ(value, stagingValue_) || !IsValid(value)) { + return; + } + stagingValue_ = value; + } + + virtual T Get() const + { + return stagingValue_; + } + + std::shared_ptr GetRsRenderLayerProperty() + { + return std::make_shared>(stagingValue_); + } + +protected: + bool IsValid(const T& value) + { + return true; + } + + RSLayerCmdType type_ { RSLayerCmdType::INVALID }; + + T stagingValue_ {}; + + bool Marshalling(Parcel& parcel) override + { + if constexpr (RSRenderLayerProperty::type_ == RSLayerPropertyType::INVALID) { + return false; + } + + auto result = RSMarshallingHelper::Marshalling(parcel, type_) && + RSMarshallingHelper::Marshalling(parcel, false) && // for non-animatable properties + RSMarshallingHelper::Marshalling(parcel, GetId()) && + RSMarshallingHelper::Marshalling(parcel, stagingValue_); + return result; + } + + static bool OnUnmarshalling(Parcel& parcel, std::shared_ptr& val); + inline static RSPropertyUnmarshallingFuncRegister unmarshallingFuncRegister_ { false, type_, OnUnmarshalling }; + + friend class RSMarshallingHelper; +}; + +#define DECLARE_RSLAYER_PROPERTY(T, TYPE_ENUM) \ + template<> \ + inline const RSLayerPropertyType RSRenderLayerProperty::type_ = RSLayerPropertyType::TYPE_ENUM; \ + template class RSRenderLayerProperty + +#include "modifier/rs_property_def.in" + +#undef DECLARE_RSLAYER_PROPERTY + +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_RENDER_LAYER_PROPERTY_H \ No newline at end of file diff --git a/rosen/modules/composer/composer_client/rs_layer.h b/rosen/modules/composer/composer_client/rs_layer.h new file mode 100644 index 0000000000..0d0394932c --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer.h @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_LAYER_H +#define COMPOSER_CLIENT_RS_LAYER_H + +#include +#include "iconsumer_surface.h" +#include +#include +#include "graphic_error.h" +#include "hdi_display_type.h" +#include "common/rs_anco_type.h" + +namespace OHOS { +namespace Rosen { +class RSC_EXPORT RSLayer : public std::enable_shared_from_this { +public: + RSLayer() = default; + virtual ~RSLayer() = default; + + /* create or update rslayer info */ + virtual bool CreateRsLayer(); + bool DestroyRsLayer(); + void SetSurface(const sptr &surface); + void SetBuffer(const sptr &sbuffer, const sptr &acquireFence); + void SetPreBuffer(const sptr &buffer); + void SetZorder(int32_t zOrder); + void SetType(const GraphicLayerType& layerType); + GraphicLayerType GetType() const; + virtual void SetAlpha(const GraphicLayerAlpha &alpha); + void SetTransform(GraphicTransformType type); + void SetCompositionType(GraphicCompositionType type); + void SetVisibleRegions(const std::vector &visibleRegions); + void SetDirtyRegions(const std::vector &dirtyRegions); + void SetBlendType(GraphicBlendType type); + void SetCropRect(const GraphicIRect &crop); + void SetPreMulti(bool preMulti); + void SetLayerSize(const GraphicIRect &layerRect); + void SetBoundSize(const GraphicIRect &boundRect); + void SetLayerColor(GraphicLayerColor layerColor); + void SetBackgroundColor(GraphicLayerColor backgroundColor); + void SetCornerRadiusInfoForDRM(const std::vector& drmCornerRadiusInfo); + void SetColorTransform(const std::vector &matrix); + void SetColorDataSpace(GraphicColorDataSpace colorSpace); + void SetMetaData(const std::vector &metaData); + void SetMetaDataSet(const GraphicHDRMetaDataSet &metaDataSet); + void SetMatrix(GraphicMatrix matrix); + void SetGravity(int32_t gravity); + void SetUniRenderFlag(bool isUniRender); + void SetTunnelHandleChange(bool change); + void SetTunnelHandle(const sptr &handle); + void SetTunnelLayerId(const uint64_t &tunnelLayerId); + uint64_t GetTunnelLayerId() const; + void SetTunnelLayerProperty(uint32_t tunnelLayerProperty); + uint32_t GetTunnelLayerProperty() const; + bool IsSupportedPresentTimestamp() const; + const GraphicPresentTimestamp &GetPresentTimestamp(); + /* create or update rslayer info */ + + /* get rslayer info */ + sptr GetSurface() const; + sptr GetBuffer() const; + sptr GetPreBuffer() const; + uint32_t GetZorder() const; + sptr GetAcquireFence() const; + const GraphicLayerAlpha &GetAlpha(); + GraphicTransformType GetTransformType() const; + GraphicCompositionType GetCompositionType() const; + const std::vector &GetVisibleRegions(); + const std::vector &GetDirtyRegions(); + GraphicBlendType GetBlendType() const; + const GraphicIRect &GetCropRect(); + const GraphicIRect &GetLayerSize(); + GraphicIRect GetBoundSize() const; + GraphicMatrix GetMatrix() const; + int32_t GetGravity() const; + bool GetUniRenderFlag() const; + bool IsPreMulti() const; + void SetWindowsName(std::vectorstd::string& windowsName); + const std::vectorstd::string& GetWindowsName(); + const std::vector &GetColorTransform(); + GraphicColorDataSpace GetColorDataSpace() const; + GraphicLayerColor GetLayerColor() const; + GraphicLayerColor GetBackgroundColor() const; + const std::vector& GetCornerRadiusInfoForDRM() const; + std::vector &GetMetaData(); + GraphicHDRMetaDataSet &GetMetaDataSet(); + bool GetTunnelHandleChange() const; + sptr GetTunnelHandle() const; + void SetIsSupportedPresentTimestamp(bool isSupported); + void SetPresentTimestamp(const GraphicPresentTimestamp ×tamp); + float GetSdrNit() const; + float GetDisplayNit() const; + float GetBrightnessRatio() const; + void SetSdrNit(float sdrNit); + void SetDisplayNit(float displayNit); + void SetBrightnessRatio(float brightnessRatio); + const std::vector& GetLayerLinearMatrix() const; + void SetLayerLinearMatrix(const std::vector& layerLinearMatrix); + // source crop tuning + int32_t GetLayerSourceTuning() const; + void SetLayerSourceTuning(int32_t layerSouce); + void SetRotationFixed(bool rotationFixed); + bool GetRotationFixed() const; + void SetLayerArsr(bool arsrTag); + bool GetLayerArsr() const; + void SetLayerCopybit(bool copybitTag); + bool GetLayerCopybit() const; + void SetNeedBilinearInterpolation(bool need); + bool GetNeedBilinearInterpolation() const; + void SetIsMaskLayer(bool isMaskLayer); + bool IsMaskLayer() const; + + void CopyLayerInfo(const std::shared_ptr &layerInfo); + void Dump(std::string &result) const; + void DumpCurrentFrameLayer() const; + RosenError SetLayerMaskInfo(LayerMask mask); + LayerMask GetLayerMaskInfo(); + inline uint64_t GetNodeId(); + void SetNodeId(uint64_t nodeId); + void SetAncoFlags(const uint32_t ancoFlags); + uint32_t GetAncoFlags() const; + bool IsAncoNative() const; + /* get rslayer info */ +}; +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_LAYER_H \ No newline at end of file diff --git a/rosen/modules/composer/composer_client/rs_layer_alpha_cmd.h b/rosen/modules/composer/composer_client/rs_layer_alpha_cmd.h new file mode 100644 index 0000000000..0e3a19a113 --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_alpha_cmd.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_LAYER_PROPERTY_ALPHA_CMD_H +#define COMPOSER_CLIENT_RS_LAYER_PROPERTY_ALPHA_CMD_H + +#include "rslayer_cmd.h" + +namespace OHOS { +namespace Rosen { + +/** + * @class RslayerAlphaCmd + * @brief The class for alpha RslayerCmd. + */ +class RSC_EXPORT RslayerAlphaCmd : public RslayerCmd { +public: + RslayerAlphaCmd() = default; + ~RslayerAlphaCmd() = default; + + static inline constexpr auto Type = RSLayerCmdType::ALPHA; + + RSLayerCmdType GetRsLayerCmdType() const override + { + return Type; + } +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_LAYER_PROPERTY_ALPHA_CMD_H diff --git a/rosen/modules/composer/composer_client/rs_layer_cmd.cpp b/rosen/modules/composer/composer_client/rs_layer_cmd.cpp new file mode 100644 index 0000000000..659006594f --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_cmd.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#include "rslayer_cmd.h" +#include "rsrenderlayer_cmd.h" + +namespace OHOS { +namespace Rosen { + +#define DECLARE_RSLAYER_CMD_CREATE(CMD_NAME) \ + std::shared_ptr RSLayer##CMD_NAME##Cmd::CreateRenderLayerCmd() const \ + { \ + auto renderProperty = GetRsRenderLayerProperty(); \ + auto renderLayerCmd = std::make_shared(renderProperty); \ + return renderLayerCmd; \ + } + +#define DECLARE_RSLAYER_CMD(CMD_NAME, TYPE, CMD_TYPE, DELTA_OP, THRESHOLD_TYPE) \ + RSLayer##CMD_NAME##Cmd::RSLayer##CMD_NAME##Cmd(const std::shared_ptr& property) \ + : RSLayerCmd(property, RSLayerCmdType::CMD_TYPE) \ + { \ + rsLayerProperty_->SetThresholdType(); \ + } \ + RSLayerCmdType RSLayer##CMD_NAME##Cmd::GetRsLayerCmdType() const \ + { \ + return RSLayerCmdType::CMD_TYPE; \ + } \ + DECLARE_RSLAYER_CMD_CREATE(CMD_NAME) + +#include "rslayer_cmd_def.in" + +#undef DECLARE_RSLAYER_CMD +} // namespace Rosen +} // namespace OHOS diff --git a/rosen/modules/composer/composer_client/rs_layer_cmd.h b/rosen/modules/composer/composer_client/rs_layer_cmd.h new file mode 100644 index 0000000000..3ca050b3ef --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_cmd.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_LAYER_CMD_H +#define COMPOSER_CLIENT_RS_LAYER_CMD_H + +#include "rslayer_property.h" + +namespace OHOS { +namespace Rosen { + +/** + * @class RSLayerCmd + * @brief The base class for all modifiers. + */ +class RSC_EXPORT RSLayerCmd : public std::enable_shared_from_this { +public: + explicit RSLayerCmd(const std::shared_ptr& property) + : rsLayerProperty_(property ? property : std::make_shared()) + {} + + RSLayerCmd(const std::shared_ptr& property, const RSLayerCmdType type) + : property_(property ? property : std::make_shared>()) + { + rsLayerProperty_->type_ = type; + } + + virtual ~RSLayerCmd() = default; + + void SetThresholdType() {} + + std::shared_ptr GetRSLayerProperty() + { + return rsLayerProperty_; + } + + virtual RSLayerCmdType GetRsLayerCmdType() const + { + return RSLayerCmdType::INVALID; + } + + std::shared_ptr GetRsRenderLayerProperty() const + { + return rsLayerProperty_->GetRsRenderLayerProperty(); + } + + virtual std::shared_ptr CreateRenderLayerCmd(); + +protected: + std::shared_ptr rsLayerProperty_; +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_LAYER_CMD_H \ No newline at end of file diff --git a/rosen/modules/composer/composer_client/rs_layer_cmd_type.h b/rosen/modules/composer/composer_client/rs_layer_cmd_type.h new file mode 100644 index 0000000000..49b5c38f89 --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_cmd_type.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_LAYER_CMD_TYPE_H +#define COMPOSER_CLIENT_RS_LAYER_CMD_TYPE_H + +#include +#include + +namespace OHOS { +namespace Rosen { +enum class RSLayerCmdType : uint16_t { + INVALID = 0, + BOUNDS = 1, + FRAME = 2, + POSITION_Z = 3, + POSITION_Z_APPLICABLE_CAMERA3D = 4, + PIVOT = 5, + PIVOT_Z = 6, + QUATERNION = 7, + ROTATION = 8, + ROTATION_X = 9, + ROTATION_Y = 10, + CAMERA_DISTANCE = 11, + SCALE = 12, + SCALE_Z = 13, + SKEW = 14, + PERSP = 15, + TRANSLATE = 16, + TRANSLATE_Z = 17, + SUBLAYER_TRANSFORM = 18, + CORNER_RADIUS = 19, + ALPHA = 20, + ALPHA_OFFSCREEN = 21, + + MAX_RS_LAYER_CMD_TYPE = 255, +}; + +} // namespace Rosen +} // namespace OHOS + +#endif // COMPOSER_CLIENT_RS_LAYER_CMD_TYPE_H \ No newline at end of file diff --git a/rosen/modules/composer/composer_client/rs_layer_impl.cpp b/rosen/modules/composer/composer_client/rs_layer_impl.cpp new file mode 100644 index 0000000000..53a15e6982 --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_impl.cpp @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#include "rslayer_impl.h" + +namespace OHOS { +namespace Rosen { + +std::shared_ptr RSLayerImpl::GetRSTransaction() const +{ + // adapt transaction +} + +bool RSLayerImpl::AddCommand(std::unique_ptr& command, + FollowType followType, LayerId layerId) const +{ + auto transaction = GetRSTransaction(); + if (transaction != nullptr) { + transaction->AddCommand(command, followType, layerId); + } + return true; +} + +void RSLayerImpl::AddRsLayerCmd(const std::shared_ptr layerCmd) +{ + { + std::unique_lock lock(propertyMutex_); + if (!layerCmd || commands_.count(layerCmd->GetPropertyId())) { + return; + } + layerCmd->AttachToLayer(shared_from_this()); + commands_.emplace(layerCmd->GetPropertyId(), layerCmd); + commandsTypeMap_.emplace((int16_t)layerCmd->GetRsLayerCmdType(), layerCmd); + } + if (layerCmd->GetRsLayerCmdType() == RSLayerCmdType::NODE_MODIFIER) { + return; + } + CheckLayerCmdType(layerCmd->GetRsLayerCmdType()); + std::unique_ptr command = std::make_unique(GetId(), layerCmd->CreateRenderModifier()); + AddCommand(command, GetFollowType(), GetId()); +} + +template +void RSLayerImpl::SetRsLayerCmd(RSLayerCmdType RSLayerCmdType, T value) +{ + std::unique_lockstd::recursive_mutex lock(propertyMutex_); + auto iter = rsLayerCmds_.find(RSLayerCmdType); + if (iter != rsLayerCmds_.end()) { + auto property = std::static_pointer_cast(iter->second->GetProperty()); + if (property == nullptr) { + ROSEN_LOGE("RSLayer::SetRsLayerCmd: failed to set property, property is null!"); + return; + } + property->Set(value); + return; + } + auto property = std::make_shared(value); + auto rsLayerCmd = std::make_shared(property); + rsLayerCmds_.emplace(RSLayerCmdType, rsLayerCmd); + AddRsLayerCmd(rsLayerCmd); +} + +void RSLayerImpl::UpdateProperty(const LayerInfoPtr& layerInfo) +{ + std::lock_guard lock(mutex_); + SetZorder(layerInfo->GetZorder()); + SetLayerSize(layerInfo->GetLayerSize()); + SetBoundSize(layerInfo->GetBoundSize()); + SetVisibleRegions(layerInfo->GetVisibleRegions()); + SetDirtyRegions(layerInfo->GetDirtyRegions()); + SetCropRect(layerInfo->GetCropRect()); + SetMatrix(layerInfo->GetMatrix()); + SetGravity(layerInfo->GetGravity()); + SetAlpha(layerInfo->GetAlpha()); + SetTransformType(layerInfo->GetTransformType()); + SetCompositionType(layerInfo->GetCompositionType()); + SetBlendType(layerInfo->GetBlendType()); + SetColorTransform(layerInfo->GetColorTransform()); + SetColorDataSpace(layerInfo->GetColorDataSpace()); + SetLayerColor(layerInfo->GetLayerColor()); + SetMetaData(layerInfo->GetMetaData()); + SetMetaDataSet(layerInfo->GetMetaDataSet()); + SetTunnelHandle(layerInfo->GetTunnelHandle()); + SetTunnelHandleChange(layerInfo->GetTunnelHandleChange()); + SetBuffer(layerInfo->GetBuffer()); + SetPreBuffer(layerInfo->GetPreBuffer()); + SetAcquireFence(layerInfo->GetAcquireFence()); + IsPreMulti(layerInfo->GetIsPreMulti()); + SetSdrNit(layerInfo->GetSdrNit()); + SetDisplayNit(layerInfo->GetDisplayNit()); + SetBrightnessRatio(layerInfo->GetBrightnessRatio()); + SetLayerLinearMatrix(layerInfo->GetLayerLinearMatrix()); + SetLayerSourceTuning(layerInfo->GetLayerSourceTuning()); + SetRotationFixed(layerInfo->GetRotationFixed()); + SetLayerArsr(layerInfo->GetLayerArsr()); + SetLayerCopybit(layerInfo->GetLayerCopybit()); + SetNeedBilinearInterpolation(layerInfo->GetNeedBilinearInterpolation()); + SetTunnelLayerId(layerInfo->GetTunnelLayerId()); + SetTunnelLayerProperty(layerInfo->GetTunnelLayerProperty()); + SetAncoFlags(layerInfo->GetAncoFlags()); +} + +void RSLayerImpl::SetAlpha(const GraphicLayerAlpha &alpha) +{ + if (alpha == layerAlpha_) { + return; + } + layerAlpha_ = alpha; + SetRsLayerCmd(RSLayerCmdType::ALPHA, alpha); +} + +} // namespace Rosen +} // namespace OHOS diff --git a/rosen/modules/composer/composer_client/rs_layer_impl.h b/rosen/modules/composer/composer_client/rs_layer_impl.h new file mode 100644 index 0000000000..b07fe1dbb0 --- /dev/null +++ b/rosen/modules/composer/composer_client/rs_layer_impl.h @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef COMPOSER_CLIENT_RS_LAYER_IMPL_H +#define COMPOSER_CLIENT_RS_LAYER_IMPL_H + +#include +#include "iconsumer_surface.h" +#include +#include +#include "graphic_error.h" +#include "hdi_display_type.h" +#include "common/rs_anco_type.h" + +#include "rslayer.h" +#include "rslayer_property_cmd.h" + +namespace OHOS { +namespace Rosen { +static const std::map TransformTypeStrs = { + {GRAPHIC_ROTATE_NONE, "0 "}, + {GRAPHIC_ROTATE_90, "1 "}, + {GRAPHIC_ROTATE_180, "2 "}, + {GRAPHIC_ROTATE_270, "3 "}, + {GRAPHIC_FLIP_H, "4 "}, + {GRAPHIC_FLIP_V, "5 "}, + {GRAPHIC_FLIP_H_ROT90, "6 "}, + {GRAPHIC_FLIP_V_ROT90, "7 "}, + {GRAPHIC_FLIP_H_ROT180, "8 "}, + {GRAPHIC_FLIP_V_ROT180, "9 "}, + {GRAPHIC_FLIP_H_ROT270, "10 "}, + {GRAPHIC_FLIP_V_ROT270, "11 "}, + {GRAPHIC_ROTATE_BUTT, "12 "}, +}; + +static const std::map CompositionTypeStrs = { + {GRAPHIC_COMPOSITION_CLIENT, "0 "}, + {GRAPHIC_COMPOSITION_DEVICE, "1 "}, + {GRAPHIC_COMPOSITION_CURSOR, "2 "}, + {GRAPHIC_COMPOSITION_VIDEO, "3