From 346c9cf5555f8df4da3a0e3785c5047f82e92398 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 17 Sep 2024 19:55:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E5=B1=82=E6=B8=B2=E6=9F=93=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9B=B4=E6=96=B0=E8=93=9D=E9=BB=84=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- blink/public/platform/web_native_client.h | 2 +- .../renderer/core/html/html_plugin_element.cc | 13 +- .../renderer/core/html/html_plugin_element.h | 4 - blink/renderer/core/layout/layout_native.cc | 116 +----------------- blink/renderer/core/layout/layout_native.h | 15 +-- blink/renderer/core/loader/native_loader.cc | 50 +++----- blink/renderer/core/loader/native_loader.h | 10 +- blink/renderer/core/paint/native_painter.cc | 8 +- .../platform/web_native_bridge_impl.cc | 2 +- 9 files changed, 42 insertions(+), 178 deletions(-) diff --git a/blink/public/platform/web_native_client.h b/blink/public/platform/web_native_client.h index 734d504dcb..aea4cbc9f9 100644 --- a/blink/public/platform/web_native_client.h +++ b/blink/public/platform/web_native_client.h @@ -31,7 +31,7 @@ class BLINK_PLATFORM_EXPORT WebNativeClient { virtual void Repaint() = 0; virtual void SetCcLayer(cc::Layer*) = 0; - using RectChangeCB = base::RepeatingCallback; + using RectChangeCB = base::RepeatingCallback; virtual void OnCreateNativeSurface(int native_embed_id, RectChangeCB rect_changed_cb) = 0; virtual void OnLayerRectChange(const gfx::Rect& rect) = 0; diff --git a/blink/renderer/core/html/html_plugin_element.cc b/blink/renderer/core/html/html_plugin_element.cc index fc64416ce2..344862c773 100755 --- a/blink/renderer/core/html/html_plugin_element.cc +++ b/blink/renderer/core/html/html_plugin_element.cc @@ -296,9 +296,6 @@ void HTMLPlugInElement::RemovedFrom(ContainerNode& insertion_point) { // Plugins can persist only through reattachment during a lifecycle // update. This method shouldn't be called in that lifecycle phase. DCHECK(!persisted_plugin_); - LOG(INFO)<<"HTMLPlugInElement::RemovedFrom"; - if (native_loader_) - native_loader_->OnDestroyNativeSurface(); HTMLFrameOwnerElement::RemovedFrom(insertion_point); } @@ -362,6 +359,12 @@ void HTMLPlugInElement::DetachLayoutTree(bool performing_reattach) { RemovePluginFromFrameView(plugin); ResetInstance(); +#if BUILDFLAG(IS_OHOS) + if(GetLayoutObject() && GetLayoutObject()->IsLayoutNative() && + native_loader_ && !performing_reattach) { + native_loader_->Dispose(); + } +#endif HTMLFrameOwnerElement::DetachLayoutTree(performing_reattach); } @@ -867,6 +870,10 @@ HTMLPlugInElement::CustomStyleForLayoutObject( #if BUILDFLAG(IS_OHOS) bool HTMLPlugInElement::CheckNativeType(const char* key) const { + if (GetObjectContentType() != ObjectContentType::kNone) { + return false; + } + auto settings = GetDocument().GetSettings(); if (!settings || !settings->GetNativeEmbedModeEnabled()) { return false; diff --git a/blink/renderer/core/html/html_plugin_element.h b/blink/renderer/core/html/html_plugin_element.h index 0f3ffa6a3c..7c2453ff69 100644 --- a/blink/renderer/core/html/html_plugin_element.h +++ b/blink/renderer/core/html/html_plugin_element.h @@ -110,10 +110,6 @@ class CORE_EXPORT HTMLPlugInElement bool CheckNativeType(const char* key) const; - bool ShouldLoadForNative() const { - return IsNativeType() && GetObjectContentType() == ObjectContentType::kNone; - } - HTMLNativeLoader* NativeLoader() const { return native_loader_.Get(); } #endif diff --git a/blink/renderer/core/layout/layout_native.cc b/blink/renderer/core/layout/layout_native.cc index 37202402c4..fbb4a780b0 100755 --- a/blink/renderer/core/layout/layout_native.cc +++ b/blink/renderer/core/layout/layout_native.cc @@ -23,15 +23,8 @@ namespace blink { -namespace { - -const float kInitEffectZoom = 1.0f; - -} // namespace - LayoutNative::LayoutNative(Element* native) : LayoutImage(native) { SetImageResource(MakeGarbageCollected()); - SetIntrinsicSize(CalculateIntrinsicSize(kInitEffectZoom)); } LayoutNative::~LayoutNative() = default; @@ -40,120 +33,17 @@ void LayoutNative::Trace(Visitor* visitor) const { LayoutImage::Trace(visitor); } -LayoutSize LayoutNative::DefaultSize() { - return LayoutSize(kDefaultWidth, kDefaultHeight); -} - -void LayoutNative::UpdateIntrinsicSize(bool is_in_layout) { - NOT_DESTROYED(); - LayoutSize size = CalculateIntrinsicSize(StyleRef().EffectiveZoom()); - // Never set the element size to zero when in a media document. - if (size.IsEmpty() && GetNode()->ownerDocument() && - GetNode()->ownerDocument()->IsMediaDocument()) { - return; - } - - if (auto* layout_view = View()) { - size = LayoutSize(layout_view->GetLayoutSize()); - } - - if (size == IntrinsicSize()) { - return; - } - - SetIntrinsicSize(size); - SetIntrinsicLogicalWidthsDirty(); - if (!is_in_layout) { - SetNeedsLayoutAndFullPaintInvalidation( - layout_invalidation_reason::kSizeChanged); - } - - if (!NativeElement() || !NativeElement()->NativeLoader()) { - return; - } - NativeElement()->NativeLoader()->UpdateSize(gfx::Size(size.Width().ToInt(), - size.Height().ToInt())); -} - -LayoutSize LayoutNative::CalculateIntrinsicSize(float scale) { - NOT_DESTROYED(); - - LayoutSize size = DefaultSize(); - size.Scale(scale); - - if (!NativeElement() || !NativeElement()->NativeLoader()) { - return size; - } - - if (const auto* content = - NativeElement()->NativeLoader()->GetWebNativeBridge()) { - gfx::Size nature_size = content->NaturalSize(); - if (!nature_size.IsEmpty()) { - LayoutSize layout_size = LayoutSize(nature_size); - layout_size.Scale(scale); - return layout_size; - } - } - - return size; -} - -void LayoutNative::ImageChanged(WrappedImagePtr new_image, - CanDeferInvalidation defer) { - NOT_DESTROYED(); - LayoutImage::ImageChanged(new_image, defer); - - // The intrinsic size is now that of the image, but in case we already had the - // intrinsic size of the video we call this here to restore the video size. - UpdateIntrinsicSize(/* is_in_layout */ false); -} - void LayoutNative::PaintReplaced(const PaintInfo& paint_info, const PhysicalOffset& paint_offset) const { NOT_DESTROYED(); NativePainter(*this).PaintReplaced(paint_info, paint_offset); } -void LayoutNative::UpdateLayout() { - NOT_DESTROYED(); - UpdateNativeContent(/* is_in_layout */ true); - - LayoutImage::UpdateLayout(); -} - -HTMLPlugInElement* LayoutNative::NativeElement() const { +HTMLPlugInElement* LayoutNative::PluginElement() const { NOT_DESTROYED(); return To(GetNode()); } -void LayoutNative::UpdateFromElement() { - NOT_DESTROYED(); - LayoutImage::UpdateFromElement(); - UpdateNativeContent(/* is_in_layout */ false); - - SetShouldDoFullPaintInvalidation(); -} - -void LayoutNative::UpdateNativeContent(bool is_in_layout) { - NOT_DESTROYED(); - UpdateIntrinsicSize(is_in_layout); - - if (!NativeElement() || !NativeElement()->NativeLoader()) { - return; - } - - auto* native_bridge = NativeElement()->NativeLoader()->GetWebNativeBridge(); - if (!native_bridge) { - return; - } - - if (!NativeElement()->InActiveDocument()) { - return; - } - - NativeElement()->SetNeedsCompositingUpdate(); -} - PhysicalRect LayoutNative::ReplacedContentRectFrom( const LayoutSize size, const NGPhysicalBoxStrut& border_padding) const { @@ -165,10 +55,10 @@ PhysicalRect LayoutNative::ReplacedContentRectFrom( bool LayoutNative::SupportsAcceleratedRendering() const { NOT_DESTROYED(); - if (!NativeElement() || !NativeElement()->NativeLoader()) { + if (!PluginElement() || !PluginElement()->NativeLoader()) { return false; } - return !!NativeElement()->NativeLoader()->CcLayer(); + return !!PluginElement()->NativeLoader()->CcLayer(); } CompositingReasons LayoutNative::AdditionalCompositingReasons() const { diff --git a/blink/renderer/core/layout/layout_native.h b/blink/renderer/core/layout/layout_native.h index af8b839efc..15b386486c 100755 --- a/blink/renderer/core/layout/layout_native.h +++ b/blink/renderer/core/layout/layout_native.h @@ -36,7 +36,7 @@ class LayoutNative final : public LayoutImage { bool SupportsAcceleratedRendering() const; - HTMLPlugInElement* NativeElement() const; + HTMLPlugInElement* PluginElement() const; const char* GetName() const override { NOT_DESTROYED(); @@ -49,11 +49,6 @@ class LayoutNative final : public LayoutImage { } private: - void UpdateFromElement() override; - - LayoutSize CalculateIntrinsicSize(float scale); - void UpdateIntrinsicSize(bool is_in_layout); - bool IsChildAllowed(LayoutObject*, const ComputedStyle&) const final { NOT_DESTROYED(); return false; @@ -64,8 +59,6 @@ class LayoutNative final : public LayoutImage { return false; } - void ImageChanged(WrappedImagePtr, CanDeferInvalidation) override; - bool IsOfType(LayoutObjectType type) const override { NOT_DESTROYED(); return type == kLayoutObjectNative || LayoutImage::IsOfType(type); @@ -74,21 +67,17 @@ class LayoutNative final : public LayoutImage { void PaintReplaced(const PaintInfo&, const PhysicalOffset& paint_offset) const override; - void UpdateLayout() override; - bool CanHaveAdditionalCompositingReasons() const override { NOT_DESTROYED(); return true; } CompositingReasons AdditionalCompositingReasons() const override; - - void UpdateNativeContent(bool is_in_layout); }; template <> struct DowncastTraits { static bool AllowFrom(const LayoutObject& object) { - return object.IsLayoutImage(); + return object.IsLayoutNative(); } }; diff --git a/blink/renderer/core/loader/native_loader.cc b/blink/renderer/core/loader/native_loader.cc index d7c5d8d386..67d5db0104 100644 --- a/blink/renderer/core/loader/native_loader.cc +++ b/blink/renderer/core/loader/native_loader.cc @@ -144,14 +144,6 @@ void NativeLoader::LoadResource(LocalFrame* frame) { web_native_bridge_->StartPipeline(); } -gfx::Rect NativeLoader::PluginBoundingRect() { - if (bounding_rect_.IsEmpty()) { - bounding_rect_ = plugin_element_->PixelSnappedBoundingBox(); - } - - return bounding_rect_; -} - void NativeLoader::OnCreateNativeSurface(int native_embed_id, RectChangeCB rect_changed_cb) { LOG(INFO) << "[NativeEmbed] NativeLoader::OnCreateNativeSurface"; @@ -159,11 +151,17 @@ void NativeLoader::OnCreateNativeSurface(int native_embed_id, return; } - if (PluginBoundingRect().IsEmpty()) { + if (bounding_rect_.IsEmpty()) { plugin_element_->GetDocument().UpdateStyleAndLayoutForNode( plugin_element_, DocumentUpdateReason::kPlugin); + bounding_rect_ = plugin_element_->PixelSnappedBoundingBox(); + if (bounding_rect_.IsEmpty()) { + first_update_rect_ = false; + } } + LOG(INFO) << "NativeEmbed NativeLoader::OnCreateNativeSurface:" + << bounding_rect_.ToString(); native_embed_id_ = native_embed_id; bounding_rect_changed_cb_ = rect_changed_cb; cc_layer_->SetNativeEmbedId(native_embed_id_); @@ -172,12 +170,12 @@ void NativeLoader::OnCreateNativeSurface(int native_embed_id, auto* frame = CurrentFrame(); if (frame && frame->View()) { auto bounds_to_viewport = - frame->View()->FrameToViewport(PluginBoundingRect()); + frame->View()->FrameToViewport(bounding_rect_); // We will use the position relative to visual viewport. bounding_rect_.set_origin(bounds_to_viewport.origin()); embed_info->rect = bounds_to_viewport; if (!bounding_rect_changed_cb_.is_null()) { - bounding_rect_changed_cb_.Run(bounds_to_viewport, false); + bounding_rect_changed_cb_.Run(bounds_to_viewport); } } @@ -211,41 +209,28 @@ void NativeLoader::OnLayerRectVisibilityChange(bool visibility) { } } -void NativeLoader::UpdateSize(gfx::Size size) { - String native_type = GetTypeAttribute(); - LOG(INFO) << "NativeEmbed size:" << size.ToString() << ",native_type:" << native_type; - if (native_type == "native/video") { - return; - } - if (PluginBoundingRect().size() != size) { - if (!bounding_rect_changed_cb_.is_null()) { - bounding_rect_changed_cb_.Run(gfx::ScaleToEnclosingRect( - bounding_rect_, PageConstraintInitalScale(plugin_element_->GetDocument())), true); - } - } -} - void NativeLoader::OnLayerRectChange(const gfx::Rect& rect) { - if (PluginBoundingRect().ApproximatelyEqual(rect, 1) || - !native_bridge_observer_remote_set_) { + if (first_update_rect_) { + first_update_rect_ = false; return; } - if (first_update_rect_) { - first_update_rect_ = false; + if (bounding_rect_.ApproximatelyEqual(rect, 1) || + !native_bridge_observer_remote_set_) { return; } - if (PluginBoundingRect().size() != rect.size()) { + if (bounding_rect_.size() != rect.size()) { bounding_rect_ = rect; if (!bounding_rect_changed_cb_.is_null()) { bounding_rect_changed_cb_.Run(gfx::ScaleToEnclosingRect( - bounding_rect_, PageConstraintInitalScale(plugin_element_->GetDocument())), true); + bounding_rect_, PageConstraintInitalScale(plugin_element_->GetDocument()))); } } else { bounding_rect_.set_origin(rect.origin()); } - + LOG(INFO) << "NativeEmbed NativeLoader::OnLayerRectChange:" + << bounding_rect_.ToString(); for (auto& observer : native_bridge_observer_remote_set_->Value()) { observer->OnEmbedRectChange(gfx::Rect( bounding_rect_.origin(), @@ -290,7 +275,6 @@ void NativeLoader::SetCcLayer(cc::Layer* cc_layer) { << GetTypeAttribute(); cc_layer_->SetMayContainNative(true); cc_layer_->SetNeedsPushProperties(); - cc_layer_->SetIsNativeVideo(GetTypeAttribute() == "native/video"); } } diff --git a/blink/renderer/core/loader/native_loader.h b/blink/renderer/core/loader/native_loader.h index 4d5cbb32c1..417b0b18fd 100644 --- a/blink/renderer/core/loader/native_loader.h +++ b/blink/renderer/core/loader/native_loader.h @@ -73,6 +73,8 @@ class CORE_EXPORT NativeLoader HTMLPlugInElement* current_plugin_element() { return plugin_element_.Get(); } + void Dispose(); + // WebNativeClient implementation. void OnCreateNativeSurface(int native_embed_id, RectChangeCB rect_changed_cb) final; @@ -81,15 +83,12 @@ class CORE_EXPORT NativeLoader void OnDestroyNativeSurface() final; void Repaint() final; void SetCcLayer(cc::Layer*) final; - void UpdateSize(gfx::Size size); virtual String DebugName() const = 0; protected: // Assert the correct order of the children in shadow dom when DCHECK is on. static void AssertShadowRootChildren(ShadowRoot&); - void Dispose(); - // Returns a constant reference to the HeapMojoAssociatedRemoteSet holding all // the bound remotes for the media::mojom::blink::MediaPlayerObserver // interface. Needed to allow sending messages directly from @@ -121,7 +120,6 @@ class CORE_EXPORT NativeLoader String GetIdAttribute() const; String GetTagName() const; ParamMap GetParamList() const; - gfx::Rect PluginBoundingRect(); // Adds a new NativeBridgeObserver remote that will be notified about native // bridge events and returns a receiver that an observer implementation can @@ -142,8 +140,8 @@ class CORE_EXPORT NativeLoader void AttachToNewFrame(); std::unique_ptr web_native_bridge_; - int native_embed_id_; - bool first_update_rect_ = false; + int native_embed_id_ = -1; + bool first_update_rect_ = true; bool visibility_ = false; bool first_update_visibility = false; diff --git a/blink/renderer/core/paint/native_painter.cc b/blink/renderer/core/paint/native_painter.cc index 1df95ba61e..21d4b5aa6e 100644 --- a/blink/renderer/core/paint/native_painter.cc +++ b/blink/renderer/core/paint/native_painter.cc @@ -38,9 +38,9 @@ void NativePainter::PaintReplaced(const PaintInfo& paint_info, return; } - if (!layout_native_.NativeElement() || - !layout_native_.NativeElement()->NativeLoader() || - !layout_native_.NativeElement()->NativeLoader()->GetWebNativeBridge()) { + if (!layout_native_.PluginElement() || + !layout_native_.PluginElement()->NativeLoader() || + !layout_native_.PluginElement()->NativeLoader()->GetWebNativeBridge()) { return; } @@ -82,7 +82,7 @@ void NativePainter::PaintReplaced(const PaintInfo& paint_info, !force_software_video_paint; if (paint_with_foreign_layer) { if (cc::Layer* layer = - layout_native_.NativeElement()->NativeLoader()->CcLayer()) { + layout_native_.PluginElement()->NativeLoader()->CcLayer()) { gfx::RectF rect(-replaced_rect.X().ToFloat(), -replaced_rect.Y().ToFloat(), layout_native_.Size().Width().ToFloat(), diff --git a/blink/renderer/platform/web_native_bridge_impl.cc b/blink/renderer/platform/web_native_bridge_impl.cc index 73f1b421a7..68c16e950c 100755 --- a/blink/renderer/platform/web_native_bridge_impl.cc +++ b/blink/renderer/platform/web_native_bridge_impl.cc @@ -210,7 +210,7 @@ void WebNativeBridgeImpl::OnSetLayer() { DVLOG(1) << __func__; DCHECK(main_task_runner_->BelongsToCurrentThread()); DCHECK(!video_layer_); - media::WebRectChangedCB rect_change_cb = base::BindRepeating( + media::RectChangedCB rect_change_cb = base::BindRepeating( &WebNativeBridgeImpl::OnLayerRectChange, base::Unretained(this)); media::RectVisibilityChangedCB rect_visibility_change_cb = base::BindRepeating( &WebNativeBridgeImpl::OnLayerRectVisibilityChange, base::Unretained(this)); -- Gitee