diff --git a/adapter/ohos/cpp/ace_ability.cpp b/adapter/ohos/cpp/ace_ability.cpp index c3a0edff9981c3cc1b4f407a32d7159cb68cc4ce..dbc36f862d1f37805a605b2b1a7ece4fbbe72f11 100644 --- a/adapter/ohos/cpp/ace_ability.cpp +++ b/adapter/ohos/cpp/ace_ability.cpp @@ -192,6 +192,11 @@ void AceAbility::OnStart(const Want& want) parsedPageUrl = ""; } + auto context = Platform::AceContainer::GetContainer(abilityId_)->GetPipelineContext(); + if(context != nullptr) { + context->SetWindowId(window->GetWindowID()); + } + // run page. Platform::AceContainer::RunPage( abilityId_, Platform::AceContainer::GetContainer(abilityId_)->GeneratePageId(), diff --git a/frameworks/core/components/camera/camera.cpp b/frameworks/core/components/camera/camera.cpp index 5f4e41bc80f4eda1272699e1f415454085af147f..8228c963f8e756c154a3ac45fc67222af9e53897 100644 --- a/frameworks/core/components/camera/camera.cpp +++ b/frameworks/core/components/camera/camera.cpp @@ -356,6 +356,8 @@ void CameraCallback::StartPreview() subWindow_ = OHOS::WindowManager::GetInstance()->CreateSubWindow(context->GetWindowId(), &config); subWindow_->GetSurface()->SetQueueSize(10); + // call context to create hole + context->ClipRootHole(config.pos_x, config.pos_y, config.width, config.height); } previewSurface_ = subWindow_->GetSurface(); @@ -546,9 +548,11 @@ void CameraCallback::onRecord(bool isSucces, std::string info) void CameraCallback::OnCameraSizeChange(int32_t width, int32_t height) { + auto context = context_.Upgrade(); LOGE("CameraCallback:OnCameraSizeChange %{public}d %{public}d %{public}p-", width, height, subWindow_.get()); if (subWindow_) { subWindow_->SetSubWindowSize(width, height); + context->ClipRootHole(windowOffset_.GetX(), windowOffset_.GetY(), static_cast(width), static_cast(height)); } windowSize_.SetWidth(width); windowSize_.SetWidth(height); @@ -556,8 +560,10 @@ void CameraCallback::OnCameraSizeChange(int32_t width, int32_t height) void CameraCallback::OnCameraOffsetChange(int32_t x, int32_t y) { + auto context = context_.Upgrade(); if (subWindow_) { subWindow_->Move(x, y); + context->ClipRootHole(static_cast(x), static_cast(y), windowSize_.Width(), windowSize_.Height()); } windowOffset_.SetX(x); windowOffset_.SetX(y); diff --git a/frameworks/core/components/root/flutter_render_root.cpp b/frameworks/core/components/root/flutter_render_root.cpp index 07fe8b70a4a2da8c58d50963fb15d16bf440eec1..0a0fb5247a5524e64b8316beb674357ed8be80f8 100644 --- a/frameworks/core/components/root/flutter_render_root.cpp +++ b/frameworks/core/components/root/flutter_render_root.cpp @@ -41,11 +41,14 @@ void FlutterRenderRoot::Paint(RenderContext& context, const Offset& offset) } auto skColor = SkColorSetARGB(bgColor_.GetAlpha(), bgColor_.GetRed(), bgColor_.GetGreen(), bgColor_.GetBlue()); auto pipelineContext = GetContext().Upgrade(); + canvas->save(); + canvas->clipRect(transparentHole_.Left(), transparentHole_.Top(), transparentHole_.Left() + transparentHole_.Width(), transparentHole_.Top() + transparentHole_.Height(), SkClipOp::kDifference); if (pipelineContext && pipelineContext->IsJsCard()) { canvas->canvas()->drawColor(skColor); } else { canvas->canvas()->clear(skColor); } + canvas->restore(); RenderNode::Paint(context, offset); } diff --git a/frameworks/core/components/root/render_root.cpp b/frameworks/core/components/root/render_root.cpp index 574fa1e24c2e0e60ef6c86334449e4aa7cf8add9..afedf74b22284c319238afef8fac273a67c5041f 100644 --- a/frameworks/core/components/root/render_root.cpp +++ b/frameworks/core/components/root/render_root.cpp @@ -112,6 +112,15 @@ void RenderRoot::SetDefaultBgColor() MarkNeedRender(); } +void RenderRoot::SetTransparentHole(double left, double top, double width, double height) +{ + transparentHole_.SetLeft(left); + transparentHole_.SetTop(top); + transparentHole_.SetWidth(width); + transparentHole_.SetHeight(height); + MarkNeedRender(); +} + void RenderRoot::SetBgColor(const Color& color) { bgColor_ = color; diff --git a/frameworks/core/components/root/render_root.h b/frameworks/core/components/root/render_root.h index d568bdfc27522104a6fba7c05a1014ae507fcf67..da18d07719e1e8fde5e457cbb79c5d2dfc463d19 100644 --- a/frameworks/core/components/root/render_root.h +++ b/frameworks/core/components/root/render_root.h @@ -63,6 +63,8 @@ public: void SetDefaultBgColor(); + void SetTransparentHole(double left, double top, double width, double height); + void NotifyOnShow() const { for (const auto& child : GetChildren()) { @@ -82,6 +84,7 @@ protected: float scale_ = 1.0f; Color bgColor_; + Rect transparentHole_; bool forceColor_ = false; bool isBgColorInit_ = false; bool isReset_ = false; diff --git a/frameworks/core/pipeline/pipeline_context.cpp b/frameworks/core/pipeline/pipeline_context.cpp index 3ad0de5c4fc9cf144279e76a0579fcc669b1f7d8..709aa65c7e393095601b720b22a6e5880086fb4a 100644 --- a/frameworks/core/pipeline/pipeline_context.cpp +++ b/frameworks/core/pipeline/pipeline_context.cpp @@ -1644,6 +1644,17 @@ void PipelineContext::RefreshRootBgColor() const } } +void PipelineContext::ClipRootHole(double left, double top, double width, double height) const +{ + if (!rootElement_) { + return; + } + const auto& render = AceType::DynamicCast(rootElement_->GetRenderNode()); + if (render) { + render->SetTransparentHole(left, top, width, height); + } +} + void PipelineContext::SetOnPageShow(OnPageShowCallBack&& onPageShowCallBack) { if (!onPageShowCallBack) { diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 1cd950362ab693d112694ca7fddedf22f9de239c..4af9f94b93b8a20e781ff92686522c6e783ddfde 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -552,6 +552,7 @@ public: } void RefreshRootBgColor() const; + void ClipRootHole(double left, double top, double width, double height) const; void AddToHoverList(const RefPtr& node); using UpdateWindowBlurRegionHandler = std::function>&)>;