From 15927b5a282329dfbfc73c1ae6b91f93f0677c4e Mon Sep 17 00:00:00 2001 From: sunbees Date: Tue, 5 Mar 2024 11:13:37 +0800 Subject: [PATCH] add handle surface interface Signed-off-by: sunbees Change-Id: I15a10b91e64a151858c6f484119a2ef42c28ccc8 --- .../jsview/js_xcomponent_controller.cpp | 78 ++++++++++++++- .../jsview/js_xcomponent_controller.h | 6 +- .../xcomponent/inner_xcomponent_controller.h | 12 ++- .../xcomponent/xcomponent_controller_ng.cpp | 63 +++++++++++- .../xcomponent/xcomponent_controller_ng.h | 18 +++- .../xcomponent/xcomponent_paint_method.cpp | 19 ++-- .../xcomponent/xcomponent_paint_method.h | 8 +- .../pattern/xcomponent/xcomponent_pattern.cpp | 95 +++++++++++++++---- .../pattern/xcomponent/xcomponent_pattern.h | 36 ++++++- .../render/adapter/rosen_render_surface.cpp | 11 ++- .../render/adapter/rosen_render_surface.h | 4 +- .../adapter/rosen_render_surface_mingw.cpp | 6 +- .../components_ng/render/render_surface.h | 4 +- 13 files changed, 310 insertions(+), 50 deletions(-) diff --git a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp index 490e408ef73..fb5e9c8d2fb 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -22,6 +22,16 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h" namespace OHOS::Ace::Framework { +namespace { +bool ParseSurfaceRectParam(const JSRef& jsValue, CalcDimension& result) +{ + if (!jsValue->IsNumber()) { + return false; + } + result = CalcDimension(jsValue->ToNumber(), DimensionUnit::PX); + return true; +} +} // namespace void JSXComponentController::JSBind(BindingTarget globalObj) { JSClass::Declare("XComponentController"); @@ -30,6 +40,10 @@ void JSXComponentController::JSBind(BindingTarget globalObj) "getXComponentContext", &JSXComponentController::GetXComponentContext); JSClass::CustomMethod( "setXComponentSurfaceSize", &JSXComponentController::SetSurfaceConfig); + JSClass::CustomMethod( + "getXComponentSurfaceRect", &JSXComponentController::GetXComponentSurfaceRect); + JSClass::CustomMethod( + "setXComponentSurfaceRect", &JSXComponentController::SetXComponentSurfaceRect); JSClass::Bind( globalObj, JSXComponentController::Constructor, JSXComponentController::Destructor); } @@ -89,4 +103,64 @@ void JSXComponentController::SetSurfaceConfig(const JSCallbackInfo& args) xcomponentController_->ConfigSurface(surfaceWidth, surfaceHeight); } } -} // namespace OHOS::Ace::Framework \ No newline at end of file + +void JSXComponentController::GetXComponentSurfaceRect(const JSCallbackInfo& args) +{ + if (!xcomponentController_) { + return; + } + auto retObj = JSRef::New(); + float offsetX = 0.0f; + float offsetY = 0.0f; + float width = 0.0f; + float height = 0.0f; + xcomponentController_->GetLocalLocation(offsetX, offsetY); + xcomponentController_->GetSurfaceSize(width, height); + retObj->SetProperty("offsetX", offsetX); + retObj->SetProperty("offsetY", offsetY); + retObj->SetProperty("surfaceWidth", width); + retObj->SetProperty("surfaceHeight", height); + args.SetReturnValue(retObj); +} + +void JSXComponentController::SetXComponentSurfaceRect(const JSCallbackInfo& args) +{ + if (args.Length() < 1 || !args[0]->IsObject()) { + return; + } + if (!xcomponentController_) { + return; + } + + JSRef obj = JSRef::Cast(args[0]); + auto jsSurfaceWidth = obj->GetProperty("surfaceWidth"); + CalcDimension surfaceWidth; + if (!ParseSurfaceRectParam(jsSurfaceWidth, surfaceWidth) || !surfaceWidth.IsValid()) { + return; + } + auto jsSurfaceHeight = obj->GetProperty("surfaceHeight"); + CalcDimension surfaceHeight; + if (!ParseSurfaceRectParam(jsSurfaceHeight, surfaceHeight) || !surfaceHeight.IsValid()) { + return; + } + xcomponentController_->SetIdealSurfaceWidth(static_cast(surfaceWidth.ConvertToPx())); + xcomponentController_->SetIdealSurfaceHeight(static_cast(surfaceHeight.ConvertToPx())); + + auto jsOffsetX = obj->GetProperty("offsetX"); + CalcDimension offsetX; + if (ParseSurfaceRectParam(jsOffsetX, offsetX)) { + xcomponentController_->SetIdealSurfaceOffsetX(static_cast(offsetX.ConvertToPx())); + } else { + xcomponentController_->ClearIdealSurfaceOffset(true); + } + auto jsOffsetY = obj->GetProperty("offsetY"); + CalcDimension offsetY; + if (ParseSurfaceRectParam(jsOffsetY, offsetY)) { + xcomponentController_->SetIdealSurfaceOffsetY(static_cast(offsetY.ConvertToPx())); + } else { + xcomponentController_->ClearIdealSurfaceOffset(false); + } + + xcomponentController_->UpdateSurfaceBounds(); +} +} // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h index 4003f2f4572..dc65f9a93bd 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_xcomponent_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -43,6 +43,10 @@ public: renderContext_ = renderContext; } + void GetXComponentSurfaceRect(const JSCallbackInfo& args); + + void SetXComponentSurfaceRect(const JSCallbackInfo& args); + std::shared_ptr GetController() const { return xcomponentController_; diff --git a/frameworks/core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h b/frameworks/core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h index 38837179a40..bec05620fb2 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h +++ b/frameworks/core/components_ng/pattern/xcomponent/inner_xcomponent_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -51,6 +51,16 @@ public: configSurfaceImpl_ = std::move(ConfigSurfaceImpl); } + virtual void GetLocalLocation(float& offsetX, float& offsetY) {} + virtual void GetSurfaceSize(float& surfaceWidth, float& surfaceHeight) {} + + virtual void SetIdealSurfaceWidth(float surfaceWidth) {} + virtual void SetIdealSurfaceHeight(float surfaceHeight) {} + virtual void SetIdealSurfaceOffsetX(float offsetX) {} + virtual void SetIdealSurfaceOffsetY(float offsetY) {} + virtual void ClearIdealSurfaceOffset(bool isXAxis) {} + virtual void UpdateSurfaceBounds() {} + private: ConfigSurfaceImpl configSurfaceImpl_; std::string surfaceId_; diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.cpp index 59b09c5aad2..099da79fdd1 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -16,6 +16,7 @@ #include "core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h" #include "base/log/log_wrapper.h" +#include "base/utils/utils.h" #include "core/components/common/layout/constants.h" #include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" @@ -104,4 +105,64 @@ RefPtr XComponentControllerNG::GetPattern() { return pattern_.Upgrade(); } + +void XComponentControllerNG::GetLocalLocation(float& offsetX, float& offsetY) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + auto localPostion = pattern->GetLocalPosition(); + offsetX = localPostion.GetX(); + offsetY = localPostion.GetY(); +} + +void XComponentControllerNG::GetSurfaceSize(float& surfaceWidth, float& surfaceHeight) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + auto surfaceSize = pattern->GetSurfaceSize(); + surfaceWidth = surfaceSize.Width(); + surfaceHeight = surfaceSize.Height(); +} + +void XComponentControllerNG::SetIdealSurfaceWidth(float surfaceWidth) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->SetIdealSurfaceWidth(surfaceWidth); +} + +void XComponentControllerNG::SetIdealSurfaceHeight(float surfaceHeight) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->SetIdealSurfaceHeight(surfaceHeight); +} + +void XComponentControllerNG::SetIdealSurfaceOffsetX(float offsetX) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->SetIdealSurfaceOffsetX(offsetX); +} + +void XComponentControllerNG::SetIdealSurfaceOffsetY(float offsetY) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->SetIdealSurfaceOffsetY(offsetY); +} + +void XComponentControllerNG::ClearIdealSurfaceOffset(bool isXAxis) +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->ClearIdealSurfaceOffset(isXAxis); +} + +void XComponentControllerNG::UpdateSurfaceBounds() +{ + auto pattern = pattern_.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->UpdateSurfaceBounds(true); +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h index ff5ddae60ed..aae1425fc6e 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_controller_ng.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -36,6 +36,22 @@ public: XComponentControllerErrorCode ResetExtController( std::shared_ptr xcomponentController) override; + void SetIdealSurfaceWidth(float surfaceWidth) override; + + void SetIdealSurfaceHeight(float surfaceHeight) override; + + void SetIdealSurfaceOffsetX(float offsetX) override; + + void SetIdealSurfaceOffsetY(float offsetY) override; + + void ClearIdealSurfaceOffset(bool isXAxis) override; + + void UpdateSurfaceBounds() override; + + void GetSurfaceSize(float& surfaceWidth, float& surfaceHeight) override; + + void GetLocalLocation(float& offsetX, float& offsetY) override; + void SetPattern(const RefPtr& pattern); RefPtr GetPattern(); diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp index d92c2134503..ccd8782ddb9 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -14,20 +14,27 @@ */ #include "core/components_ng/pattern/xcomponent/xcomponent_paint_method.h" +#include "core/components_ng/pattern/xcomponent/xcomponent_pattern.h" + namespace OHOS::Ace::NG { CanvasDrawFunction XComponentPaintMethod::GetContentDrawFunction(PaintWrapper* paintWrapper) { auto renderContext = paintWrapper->GetRenderContext(); CHECK_NULL_RETURN(renderContext, nullptr); - auto paintRect = renderContext->GetPaintRectWithTransform(); - auto width = paintRect.Width(); - auto height = paintRect.Height(); - return [weak = WeakClaim(this), width, height](RSCanvas& canvas) { + auto pattern = pattern_.Upgrade(); + CHECK_NULL_RETURN(pattern, nullptr); + auto surfaceSize = pattern->GetSurfaceSize(); + auto localPostion = pattern->GetLocalPosition(); + auto width = surfaceSize.Width(); + auto height = surfaceSize.Height(); + auto offsetX = localPostion.GetX(); + auto offsetY = localPostion.GetY(); + return [weak = WeakClaim(this), width, height, offsetX, offsetY](RSCanvas& canvas) { auto painter = weak.Upgrade(); CHECK_NULL_VOID(painter); auto surface = painter->renderSuface_; if (surface) { - surface->DrawBufferForXComponent(canvas, width, height); + surface->DrawBufferForXComponent(canvas, width, height, offsetX, offsetY); } }; } diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.h index 19057940f53..d42749d773f 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_paint_method.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -20,16 +20,20 @@ #include "core/components_ng/render/render_surface.h" namespace OHOS::Ace::NG { +class XComponentPattern; class ACE_EXPORT XComponentPaintMethod : public NodePaintMethod { DECLARE_ACE_TYPE(XComponentPaintMethod, NodePaintMethod) public: - XComponentPaintMethod(RefPtr surface) : renderSuface_(surface) {} + XComponentPaintMethod(const RefPtr& surface, const RefPtr& pattern) + : renderSuface_(surface), pattern_(pattern) + {} ~XComponentPaintMethod() override = default; CanvasDrawFunction GetContentDrawFunction(PaintWrapper* paintWrapper) override; private: RefPtr renderSuface_; + WeakPtr pattern_; }; } // namespace OHOS::Ace::NG #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_XCOMPONENT_PAINT_METHOD_H diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp index 65800903402..cc81b0196ac 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -165,14 +165,14 @@ void XComponentPattern::Initialize(int32_t instanceId) #endif } handlingSurfaceRenderContext_ = renderContextForSurface_; - auto* controllerNG = static_cast(xcomponentController_.get()); - if (controllerNG) { - controllerNG->SetPattern(AceType::Claim(this)); - } } else if (type_ == XComponentType::TEXTURE) { renderSurface_->SetRenderContext(renderContext); renderSurface_->SetIsTexture(true); } + auto* controllerNG = static_cast(xcomponentController_.get()); + if (controllerNG) { + controllerNG->SetPattern(AceType::Claim(this)); + } renderSurface_->InitSurface(); renderSurface_->UpdateXComponentConfig(); InitEvent(); @@ -340,7 +340,7 @@ bool XComponentPattern::OnDirtyLayoutWrapperSwap(const RefPtr& di auto geometryNode = dirty->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, false); drawSize_ = geometryNode->GetContentSize(); - if (drawSize_.IsNonPositive()) { + if (!drawSize_.IsPositive()) { return false; } @@ -363,28 +363,19 @@ bool XComponentPattern::OnDirtyLayoutWrapperSwap(const RefPtr& di } } } - localposition_ = geometryNode->GetContentOffset(); + localPosition_ = geometryNode->GetContentOffset(); #if !(defined(VIDEO_TEXTURE_SUPPORTED) && defined(XCOMPONENT_SUPPORTED)) if (SystemProperties::GetExtSurfaceEnabled()) { auto host = GetHost(); CHECK_NULL_RETURN(host, false); auto transformRelativeOffset = host->GetTransformRelativeOffset(); renderSurface_->SetExtSurfaceBounds( - static_cast(transformRelativeOffset.GetX() + localposition_.GetX()), - static_cast(transformRelativeOffset.GetY() + localposition_.GetY()), + static_cast(transformRelativeOffset.GetX() + localPosition_.GetX()), + static_cast(transformRelativeOffset.GetY() + localPosition_.GetY()), static_cast(drawSize_.Width()), static_cast(drawSize_.Height())); } #endif - if (handlingSurfaceRenderContext_) { - handlingSurfaceRenderContext_->SetBounds( - localposition_.GetX(), localposition_.GetY(), drawSize_.Width(), drawSize_.Height()); -#ifdef ENABLE_ROSEN_BACKEND - auto* transactionProxy = Rosen::RSTransactionProxy::GetInstance(); - if (transactionProxy != nullptr) { - transactionProxy->FlushImplicitTransaction(); - } -#endif - } + UpdateSurfaceBounds(); // XComponentType::SURFACE has set surface default size in RSSurfaceNode->SetBounds() if (type_ == XComponentType::TEXTURE) { renderSurface_->SetSurfaceDefaultSize( @@ -918,7 +909,7 @@ void XComponentPattern::SetHandlingRenderContextForSurface(const RefPtrClearChildren(); renderContext->AddChild(handlingSurfaceRenderContext_, 0); handlingSurfaceRenderContext_->SetBounds( - localposition_.GetX(), localposition_.GetY(), drawSize_.Width(), drawSize_.Height()); + localPosition_.GetX(), localPosition_.GetY(), drawSize_.Width(), drawSize_.Height()); } OffsetF XComponentPattern::GetOffsetRelativeToWindow() @@ -1093,4 +1084,68 @@ void XComponentPattern::SetExportTextureSurfaceId(const std::string& surfaceId) { exportTextureSurfaceId_ = StringUtils::StringToLongUint(surfaceId); } + +void XComponentPattern::SetIdealSurfaceWidth(float surfaceWidth) +{ + selfIdealSurfaceWidth_ = surfaceWidth; +} + +void XComponentPattern::SetIdealSurfaceHeight(float surfaceHeight) +{ + selfIdealSurfaceHeight_ = surfaceHeight; +} + +void XComponentPattern::SetIdealSurfaceOffsetX(float offsetX) +{ + selfIdealSurfaceOffsetX_ = offsetX; +} + +void XComponentPattern::SetIdealSurfaceOffsetY(float offsetY) +{ + selfIdealSurfaceOffsetY_ = offsetY; +} + +void XComponentPattern::ClearIdealSurfaceOffset(bool isXAxis) +{ + if (isXAxis) { + selfIdealSurfaceOffsetX_.reset(); + } else { + selfIdealSurfaceOffsetY_.reset(); + } +} + +void XComponentPattern::UpdateSurfaceBounds(bool needForceRender) +{ + if (!drawSize_.IsPositive()) { + return; + } + if (selfIdealSurfaceWidth_.has_value() && Positive(selfIdealSurfaceWidth_.value()) && + selfIdealSurfaceHeight_.has_value() && Positive(selfIdealSurfaceHeight_.value())) { + localPosition_.SetX(selfIdealSurfaceOffsetX_.has_value() + ? selfIdealSurfaceOffsetX_.value() + : (drawSize_.Width() - selfIdealSurfaceWidth_.value()) / 2.0f); + + localPosition_.SetY(selfIdealSurfaceOffsetY_.has_value() + ? selfIdealSurfaceOffsetY_.value() + : (drawSize_.Height() - selfIdealSurfaceHeight_.value()) / 2.0f); + surfaceSize_ = { selfIdealSurfaceWidth_.value(), selfIdealSurfaceHeight_.value() }; + } else { + surfaceSize_ = drawSize_; + } + if (handlingSurfaceRenderContext_) { + handlingSurfaceRenderContext_->SetBounds( + localPosition_.GetX(), localPosition_.GetY(), surfaceSize_.Width(), surfaceSize_.Height()); +#ifdef ENABLE_ROSEN_BACKEND + auto* transactionProxy = Rosen::RSTransactionProxy::GetInstance(); + if (transactionProxy != nullptr) { + transactionProxy->FlushImplicitTransaction(); + } +#endif + } + if (needForceRender) { + auto host = GetHost(); + CHECK_NULL_VOID(host); + host->MarkNeedRenderOnly(); + } +} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h index d4cf25e94f8..217c894b010 100644 --- a/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h +++ b/frameworks/core/components_ng/pattern/xcomponent/xcomponent_pattern.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -77,7 +77,7 @@ public: RefPtr CreateNodePaintMethod() override { if (type_ == XComponentType::TEXTURE) { - auto paint = MakeRefPtr(renderSurface_); + auto paint = MakeRefPtr(renderSurface_, AceType::Claim(this)); return paint; } return nullptr; @@ -174,16 +174,26 @@ public: type_ = type; } - SizeF GetDrawSize() + const SizeF& GetDrawSize() const { return drawSize_; } - OffsetF GetGlobalPosition() + const SizeF& GetSurfaceSize() const + { + return surfaceSize_; + } + + const OffsetF& GetGlobalPosition() const { return globalPosition_; } + const OffsetF& GetLocalPosition() const + { + return localPosition_; + } + OffsetF GetOffsetRelativeToWindow(); const RefPtr& GetRenderContextForSurface() @@ -246,6 +256,14 @@ public: void FireExternalEvent(RefPtr context, const std::string& componentId, const uint32_t nodeId, const bool isDestroy); void ConfigSurface(uint32_t surfaceWidth, uint32_t surfaceHeight); + + void SetIdealSurfaceWidth(float surfaceWidth); + void SetIdealSurfaceHeight(float surfaceHeight); + void SetIdealSurfaceOffsetX(float offsetX); + void SetIdealSurfaceOffsetY(float offsetY); + void ClearIdealSurfaceOffset(bool isXAxis); + void UpdateSurfaceBounds(bool needForceRender = false); + private: void OnAttachToFrameNode() override; void OnDetachFromFrameNode(FrameNode* frameNode) override; @@ -314,10 +332,18 @@ private: WeakPtr context_; int32_t instanceId_; SizeF initSize_; - OffsetF localposition_; + OffsetF localPosition_; OffsetF globalPosition_; SizeF drawSize_; + SizeF surfaceSize_; RefPtr displaySync_ = AceType::MakeRefPtr(); + + std::optional selfIdealSurfaceWidth_; + std::optional selfIdealSurfaceHeight_; + std::optional selfIdealSurfaceOffsetX_; + std::optional selfIdealSurfaceOffsetY_; + + // for export texture NodeRenderType renderType_ = NodeRenderType::RENDER_TYPE_DISPLAY; uint64_t exportTextureSurfaceId_ = 0U; #ifdef OHOS_PLATFORM diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp index f73e5a229ba..a0e55b558e6 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -354,7 +354,8 @@ void RosenRenderSurface::ConsumeXComponentBuffer() #endif } -void RosenRenderSurface::DrawBufferForXComponent(RSCanvas& canvas, float width, float height) +void RosenRenderSurface::DrawBufferForXComponent( + RSCanvas& canvas, float width, float height, float offsetX, float offsetY) { #ifdef OHOS_PLATFORM auto renderContext = renderContext_.Upgrade(); @@ -379,13 +380,13 @@ void RosenRenderSurface::DrawBufferForXComponent(RSCanvas& canvas, float width, CHECK_NULL_VOID(skCanvas); auto* recordingCanvas = static_cast(skCanvas); CHECK_NULL_VOID(recordingCanvas); - Rosen::RSSurfaceBufferInfo info { surfaceNode->buffer_, 0, 0, static_cast(width), + Rosen::RSSurfaceBufferInfo info { surfaceNode->buffer_, offsetX, offsetY, static_cast(width), static_cast(height) }; recordingCanvas->DrawSurfaceBuffer(info); #else auto& recordingCanvas = static_cast(canvas); - Rosen::DrawingSurfaceBufferInfo info {surfaceNode->buffer_, 0, 0, static_cast(width), - static_cast(height)}; + Rosen::DrawingSurfaceBufferInfo info { surfaceNode->buffer_, offsetX, offsetY, static_cast(width), + static_cast(height) }; recordingCanvas.DrawSurfaceBuffer(info); #endif #endif diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface.h b/frameworks/core/components_ng/render/adapter/rosen_render_surface.h index 7704f23ed94..fdac3925111 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface.h +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -98,7 +98,7 @@ public: void DrawBuffer(); - void DrawBufferForXComponent(RSCanvas& canvas, float width, float height) override; + void DrawBufferForXComponent(RSCanvas& canvas, float width, float height, float offsetX, float offsetY) override; #ifdef OHOS_PLATFORM OHOS::sptr GetSurface() const diff --git a/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp b/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp index 074aa20fb8c..ccd01f1eac7 100644 --- a/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp +++ b/frameworks/core/components_ng/render/adapter/rosen_render_surface_mingw.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 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 @@ -81,6 +81,8 @@ void DrawBuffer() {} void ConsumeXComponentBuffer() {} -void RosenRenderSurface::DrawBufferForXComponent(RSCanvas& canvas, float width, float height) {} +void RosenRenderSurface::DrawBufferForXComponent( + RSCanvas& canvas, float width, float height, float offsetX, float offsetY) +{} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/render/render_surface.h b/frameworks/core/components_ng/render/render_surface.h index e2cf893334a..6426762fe4e 100644 --- a/frameworks/core/components_ng/render/render_surface.h +++ b/frameworks/core/components_ng/render/render_surface.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -98,7 +98,7 @@ public: virtual void SetSurfaceQueueSize(int32_t queueSize) {} - virtual void DrawBufferForXComponent(RSCanvas& canvas, float width, float height) {}; + virtual void DrawBufferForXComponent(RSCanvas& canvas, float width, float height, float offsetX, float offsetY) {}; protected: ACE_DISALLOW_COPY_AND_MOVE(RenderSurface); -- Gitee