From 2686e339e74c6004dcb76b1be6f6d97ea7675df3 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Sun, 25 Jun 2023 06:47:40 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!13861?= =?UTF-8?q?=20:=20=E4=BF=AE=E5=A4=8D=E6=97=A0=E6=B3=95=E5=A4=9A=E6=AC=A1?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=85=A8=E5=B1=8F'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/components_ng/pattern/BUILD.gn | 2 - .../pattern/video/video_full_screen_node.cpp | 62 ----- .../pattern/video/video_full_screen_node.h | 43 ---- .../video/video_full_screen_pattern.cpp | 122 --------- .../pattern/video/video_full_screen_pattern.h | 66 ----- .../pattern/video/video_pattern.cpp | 234 ++++++------------ .../pattern/video/video_pattern.h | 115 ++------- test/unittest/core/pattern/video/BUILD.gn | 2 - .../core/pattern/video/video_test_ng.cpp | 37 ++- 9 files changed, 109 insertions(+), 574 deletions(-) delete mode 100644 frameworks/core/components_ng/pattern/video/video_full_screen_node.cpp delete mode 100644 frameworks/core/components_ng/pattern/video/video_full_screen_node.h delete mode 100644 frameworks/core/components_ng/pattern/video/video_full_screen_pattern.cpp delete mode 100644 frameworks/core/components_ng/pattern/video/video_full_screen_pattern.h diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index 0e35cf8c43d..5f3d8be556d 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -442,8 +442,6 @@ build_component_ng("pattern_ng") { "toggle/switch_pattern.cpp", "toggle/toggle_model_ng.cpp", "video/video_accessibility_property.cpp", - "video/video_full_screen_node.cpp", - "video/video_full_screen_pattern.cpp", "video/video_layout_algorithm.cpp", "video/video_model_ng.cpp", "video/video_node.cpp", diff --git a/frameworks/core/components_ng/pattern/video/video_full_screen_node.cpp b/frameworks/core/components_ng/pattern/video/video_full_screen_node.cpp deleted file mode 100644 index 89e4f034ca1..00000000000 --- a/frameworks/core/components_ng/pattern/video/video_full_screen_node.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2023 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 "core/components_ng/pattern/video/video_full_screen_node.h" -#include "core/components_ng/pattern/image/image_pattern.h" -#include "core/components_ng/pattern/video/video_full_screen_pattern.h" - -namespace OHOS::Ace::NG { -void VideoFullScreenNode::InitVideoFullScreenNode(const RefPtr& video) -{ - if (video->HasPreviewImageNode()) { - int32_t imageId = ElementRegister::GetInstance()->MakeUniqueId(); - auto previewNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, imageId, - []() { return AceType::MakeRefPtr(); }); - CHECK_NULL_VOID(previewNode); - AddChild(previewNode); - } - if (video->HasControllerRowNode()) { - int32_t controlRowId = GetControllerRowId(); - auto fullScreenPattern = AceType::DynamicCast(GetPattern()); - auto controlRowNode = fullScreenPattern->CreateControlBar(controlRowId); - CHECK_NULL_VOID(controlRowNode); - AddChild(controlRowNode); - } - InitVideoParam(video); -} - -RefPtr VideoFullScreenNode::CreateFullScreenNode(const std::string& tag, - int32_t nodeId, const RefPtr& pattern) -{ - auto fullScreenNode = AceType::MakeRefPtr(tag, nodeId, pattern, false); - ElementRegister::GetInstance()->AddUINode(fullScreenNode); - fullScreenNode->InitializePatternAndContext(); - return fullScreenNode; -} - -void VideoFullScreenNode::InitVideoParam(const RefPtr& video) -{ - // init preview param - auto layoutProperty = video->GetLayoutProperty(); - CHECK_NULL_VOID(layoutProperty); - auto fullScreenLayout = GetLayoutProperty(); - CHECK_NULL_VOID(fullScreenLayout); - - fullScreenLayout->UpdatePosterImageInfo(layoutProperty->GetPosterImageInfo().value()); - fullScreenLayout->UpdateObjectFit(layoutProperty->GetObjectFitValue(ImageFit::COVER)); - fullScreenLayout->UpdateVideoSource(layoutProperty->GetVideoSource().value()); - fullScreenLayout->UpdateControls(layoutProperty->GetControls().value()); -} -} \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/video/video_full_screen_node.h b/frameworks/core/components_ng/pattern/video/video_full_screen_node.h deleted file mode 100644 index 6ecdffd31f3..00000000000 --- a/frameworks/core/components_ng/pattern/video/video_full_screen_node.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_FULL_SCREEN_NODE_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_FULL_SCREEN_NODE_H - -#include - -#include "core/components_ng/base/frame_node.h" -#include "core/components_ng/pattern/video/video_node.h" - -namespace OHOS::Ace::NG { -class ACE_EXPORT VideoFullScreenNode : public VideoNode { - DECLARE_ACE_TYPE(VideoFullScreenNode, VideoNode); - -public: - VideoFullScreenNode(const std::string& tag, int32_t nodeId, const RefPtr& pattern, bool isRoot = false) - :VideoNode(tag, nodeId, pattern, isRoot) {} - - ~VideoFullScreenNode() override = default; - - void InitVideoFullScreenNode(const RefPtr& videoNode); - - static RefPtr CreateFullScreenNode(const std::string& tag, int32_t nodeId, - const RefPtr& pattern); - -private: - void InitVideoParam(const RefPtr& video); -}; -} -#endif \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.cpp b/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.cpp deleted file mode 100644 index 092984cbfe3..00000000000 --- a/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2023 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 "core/components_ng/pattern/video/video_full_screen_pattern.h" - -#include "core/components_ng/pattern/video/video_full_screen_node.h" -#include "core/components_ng/pattern/image/image_pattern.h" - -namespace OHOS::Ace::NG { -void VideoFullScreenPattern::InitFullScreenParam(const RefPtr& videoPattern, - const RefPtr& renderSurface, - const RefPtr& mediaPlayer, - const RefPtr& context) -{ - UpdateMediaParam(mediaPlayer, renderSurface, context); - videoPattern->ResetMediaParam(); - videoPattern_ = AceType::WeakClaim(AceType::RawPtr(videoPattern)); - RecoverState(videoPattern); - auto video = videoPattern->GetHost(); - CHECK_NULL_VOID(video); - SetEventHub(video->GetEventHub()); -} - -void VideoFullScreenPattern::RequestFullScreen(const RefPtr& videoNode) -{ - auto fullScreenNode = AceType::DynamicCast(GetHost()); - CHECK_NULL_VOID(fullScreenNode); - fullScreenNode->InitVideoFullScreenNode(videoNode); - // add node to root - int32_t rootId = videoNode->GetRootId(); - auto rootNode = FrameNode::GetFrameNode(V2::ROOT_ETS_TAG, rootId); - - fullScreenNode->MountToParent(rootNode); - // set video size all window - LayoutConstraintF parentConstraint; - float rootWidth = PipelineContext::GetCurrentRootWidth(); - float rootHeight = PipelineContext::GetCurrentRootHeight(); - parentConstraint.maxSize.SetWidth(rootWidth); - parentConstraint.maxSize.SetHeight(rootHeight); - auto geometryNode = fullScreenNode->GetGeometryNode(); - geometryNode->SetParentLayoutConstraint(parentConstraint); - geometryNode->SetMarginFrameOffset(OffsetF {0.0f, 0.0f}); - fullScreenNode->MarkModifyDone(); - fullScreenNode->RebuildRenderContextTree(); - fullScreenNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD); - rootNode->RebuildRenderContextTree(); - rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); -} - -void VideoFullScreenPattern::ExitFullScreen() -{ - auto videoPattern = videoPattern_.Upgrade(); - CHECK_NULL_VOID(videoPattern); - videoPattern->UpdateMediaParam(mediaPlayer_, renderSurface_, renderContextForMediaPlayer_); - ResetMediaParam(); - // remove full screen node - auto fullScreenNode = GetHost(); - CHECK_NULL_VOID(fullScreenNode); - auto rootNode = fullScreenNode->GetParent(); - CHECK_NULL_VOID(rootNode); - rootNode->RemoveChild(fullScreenNode); - rootNode->RebuildRenderContextTree(); - - auto videoNode = AceType::DynamicCast(videoPattern->GetHost()); - CHECK_NULL_VOID(videoNode); - // change value about time and playing status - videoPattern->RecoverState(AceType::Claim(this)); - // change full screen button - videoPattern->OnFullScreenChange(false); - videoNode->MarkModifyDone(); -} - -void VideoFullScreenPattern::UpdateState() -{ - auto videoPattern = videoPattern_.Upgrade(); - CHECK_NULL_VOID(videoPattern); - UpdateLoop(videoPattern->GetLoop()); - UpdateMuted(videoPattern->GetMuted()); - UpdateAutoPlay(videoPattern->GetAutoPlay()); - UpdateProgressRate(videoPattern->GetProgressRate()); - - // update full screen layout - auto fullScreenNode = GetHost(); - CHECK_NULL_VOID(fullScreenNode); - auto fullScreenLayout = fullScreenNode->GetLayoutProperty(); - auto videoNode = videoPattern->GetHost(); - CHECK_NULL_VOID(videoNode); - auto videoLayout = videoNode->GetLayoutProperty(); - bool isChanged = false; - if (fullScreenLayout->GetObjectFit() != videoLayout->GetObjectFit()) { - fullScreenLayout->UpdateObjectFit(videoLayout->GetObjectFit().value()); - } - if (fullScreenLayout->GetVideoSource() != videoLayout->GetVideoSource()) { - isChanged = true; - fullScreenLayout->UpdateVideoSource(videoLayout->GetVideoSource().value()); - } - if (fullScreenLayout->GetPosterImageInfo() != videoLayout->GetPosterImageInfo()) { - isChanged = true; - fullScreenLayout->UpdatePosterImageInfo(videoLayout->GetPosterImageInfo().value()); - } - if (fullScreenLayout->GetControls() != videoLayout->GetControls()) { - isChanged = true; - fullScreenLayout->UpdateControls(videoLayout->GetControls().value()); - } - if (isChanged) { - fullScreenNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD); - } - fullScreenNode->MarkModifyDone(); -} -} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.h b/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.h deleted file mode 100644 index c7d8681975e..00000000000 --- a/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2023 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_FULL_SCREEN_PATTERN_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_VIDEO_VIDEO_FULL_SCREEN_PATTERN_H - -#include "core/components_ng/pattern/video/video_pattern.h" -#include "core/components/video/video_controller_v2.h" -#include "core/components_ng/pattern/video/video_node.h" - -namespace OHOS::Ace::NG { -class VideoFullScreenPattern : public VideoPattern { - DECLARE_ACE_TYPE(VideoFullScreenPattern, VideoPattern); -public: - VideoFullScreenPattern() = default; - explicit VideoFullScreenPattern(const RefPtr& videoController): VideoPattern(videoController) {} - ~VideoFullScreenPattern() override = default; - void InitFullScreenParam(const RefPtr& video, - const RefPtr& renderSurface, - const RefPtr& mediaPlayer, - const RefPtr& context); - void RequestFullScreen(const RefPtr& videoNode); - - void ExitFullScreen(); - - bool OnBackPressed() override - { - ExitFullScreen(); - return true; - } - - const RefPtr GetOriginVideoPattern() - { - return videoPattern_.Upgrade(); - } - - RefPtr CreateEventHub() override - { - return eventHub_; - } - - void SetEventHub(const RefPtr& eventHub) - { - eventHub_ = eventHub; - } - - void UpdateState(); - -private: - WeakPtr videoPattern_; - RefPtr eventHub_; -}; -} -#endif \ No newline at end of file diff --git a/frameworks/core/components_ng/pattern/video/video_pattern.cpp b/frameworks/core/components_ng/pattern/video/video_pattern.cpp index 11f30d06e43..1c4c14362a6 100644 --- a/frameworks/core/components_ng/pattern/video/video_pattern.cpp +++ b/frameworks/core/components_ng/pattern/video/video_pattern.cpp @@ -14,7 +14,6 @@ */ #include "core/components_ng/pattern/video/video_pattern.h" -#include "video_node.h" #include "base/geometry/dimension.h" #include "base/geometry/ng/size_t.h" @@ -48,9 +47,6 @@ #include "core/components_ng/property/property.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/pipeline_ng/pipeline_context.h" -#include "core/components_ng/pattern/video/video_full_screen_pattern.h" -#include "core/components_ng/pattern/video/video_full_screen_node.h" - #ifdef ENABLE_DRAG_FRAMEWORK #include "core/common/udmf/udmf_client.h" @@ -249,10 +245,6 @@ bool VideoPattern::SetSourceForMediaPlayer() auto videoSrc = videoLayoutProperty->GetVideoSource().value(); src_ = videoSrc; LOGI("Video Set src for media, it is : %{public}s", videoSrc.c_str()); - if (mediaPlayer_ == nullptr) { - LOGE("mediaPlayer is nullptr"); - return false; - } return mediaPlayer_->SetSource(videoSrc); } @@ -644,10 +636,7 @@ void VideoPattern::PrepareSurface() void VideoPattern::OnAttachToFrameNode() { - // full screen node is not supposed to register js controller event - if (!InstanceOf(this)) { - SetMethodCall(); - } + SetMethodCall(); auto host = GetHost(); CHECK_NULL_VOID(host); auto renderContext = host->GetRenderContext(); @@ -666,29 +655,16 @@ void VideoPattern::OnModifyDone() SetHiddenChangeEvent([weak = WeakClaim(this)](bool hidden) { auto videoPattern = weak.Upgrade(); CHECK_NULL_VOID_NOLOG(videoPattern); - auto fullScreenNode = videoPattern->GetFullScreenNode(); - if (fullScreenNode) { - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->HiddenChange(hidden); - return; - } videoPattern->HiddenChange(hidden); }); } - // update full screen pattern state - UpdateFsState(); - // Update the control bar and preview image. UpdatePreviewImage(); UpdateControllerBar(); - // Update the media player when video node is not in full screen or current node is full screen node - if (!fullScreenNodeId_.has_value() || InstanceOf(this)) { - LOGI("trigger modify media player"); - UpdateMediaPlayer(); - } + // Update the media player. + UpdateMediaPlayer(); if (SystemProperties::GetExtSurfaceEnabled()) { auto pipelineContext = PipelineContext::GetCurrentContext(); @@ -795,7 +771,7 @@ void VideoPattern::UpdateVideoProperty() void VideoPattern::OnRebuildFrame() { - if (!renderSurface_ || !renderSurface_->IsSurfaceValid()) { + if (!renderSurface_->IsSurfaceValid()) { LOGE("surface not valid"); return; } @@ -812,6 +788,7 @@ bool VideoPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, LOGD("Video skill measure."); return false; } + auto geometryNode = dirty->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, false); auto videoNodeSize = geometryNode->GetContentSize(); @@ -822,17 +799,15 @@ bool VideoPattern::OnDirtyLayoutWrapperSwap(const RefPtr& dirty, videoNodeSize.ToString().c_str()); auto videoFrameSize = MeasureVideoContentLayout(videoNodeSize, layoutProperty); // Change the surface layout for drawing video frames - if (renderContextForMediaPlayer_) { - renderContextForMediaPlayer_->SetBounds( - videoNodeOffset.GetX() + (videoNodeSize.Width() - videoFrameSize.Width()) / AVERAGE_VALUE, - videoNodeOffset.GetY() + (videoNodeSize.Height() - videoFrameSize.Height()) / AVERAGE_VALUE, - videoFrameSize.Width(), videoFrameSize.Height()); + renderContextForMediaPlayer_->SetBounds( + videoNodeOffset.GetX() + (videoNodeSize.Width() - videoFrameSize.Width()) / AVERAGE_VALUE, + videoNodeOffset.GetY() + (videoNodeSize.Height() - videoFrameSize.Height()) / AVERAGE_VALUE, + videoFrameSize.Width(), videoFrameSize.Height()); LOGD("Video renderContext for mediaPlayer position x is %{public}lf,y is %{public}lf,width is %{public}lf,height " "is %{public}lf.", videoNodeOffset.GetX() + (videoNodeSize.Width() - videoFrameSize.Width()) / AVERAGE_VALUE, videoNodeOffset.GetY() + (videoNodeSize.Height() - videoFrameSize.Height()) / AVERAGE_VALUE, videoFrameSize.Width(), videoFrameSize.Height()); - } auto host = GetHost(); CHECK_NULL_RETURN(host, false); host->MarkNeedSyncRenderTree(); @@ -895,7 +870,7 @@ RefPtr VideoPattern::CreateControlBar(int32_t nodeId) auto fullScreenButton = CreateSVG(); CHECK_NULL_RETURN(fullScreenButton, nullptr); SetFullScreenButtonCallBack(fullScreenButton); - ChangeFullScreenButtonTag(InstanceOf(this), fullScreenButton); + ChangeFullScreenButtonTag(isFullScreen_, fullScreenButton); controlBar->AddChild(fullScreenButton); auto renderContext = controlBar->GetRenderContext(); @@ -1011,102 +986,61 @@ void VideoPattern::SetMethodCall() uiTaskExecutor.PostTask([weak]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = AceType::DynamicCast(pattern->GetFullScreenNode()); - // if current is full screen state, send start event to full screen node - if (!fullScreenNode) { - pattern->Start(); - return; - } - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->Start(); + pattern->Start(); }); }); videoController->SetPausetImpl([weak = WeakClaim(this), uiTaskExecutor]() { uiTaskExecutor.PostTask([weak]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = pattern->GetFullScreenNode(); - if (!fullScreenNode) { - pattern->Pause(); - return; - } - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->Pause(); + pattern->Pause(); }); }); videoController->SetStopImpl([weak = WeakClaim(this), uiTaskExecutor]() { uiTaskExecutor.PostTask([weak]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = pattern->GetFullScreenNode(); - if (!fullScreenNode) { - pattern->Stop(); - return; - } - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->Stop(); + pattern->Stop(); }); }); videoController->SetSeekToImpl([weak = WeakClaim(this), uiTaskExecutor](float pos, SeekMode seekMode) { uiTaskExecutor.PostTask([weak, pos, seekMode]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = pattern->GetFullScreenNode(); - if (!fullScreenNode) { - pattern->SetCurrentTime(pos, seekMode); - return; - } - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->SetCurrentTime(pos, seekMode); + pattern->SetCurrentTime(pos, seekMode); }); }); videoController->SetRequestFullscreenImpl([weak = WeakClaim(this), uiTaskExecutor](bool isFullScreen) { uiTaskExecutor.PostTask([weak, isFullScreen]() { - auto videoPattern = weak.Upgrade(); - CHECK_NULL_VOID(videoPattern); + auto pattern = weak.Upgrade(); + CHECK_NULL_VOID(pattern); if (isFullScreen) { - videoPattern->FullScreen(); + pattern->FullScreen(); } else { - auto fullScreenNode = videoPattern->GetFullScreenNode(); - CHECK_NULL_VOID(fullScreenNode); - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->ExitFullScreen(); + pattern->ExitFullScreen(); } - }); }); videoController->SetExitFullscreenImpl([weak = WeakClaim(this), uiTaskExecutor](bool isSync) { if (isSync) { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = pattern->GetFullScreenNode(); - CHECK_NULL_VOID(fullScreenNode); - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->ExitFullScreen(); + pattern->ExitFullScreen(); return; } uiTaskExecutor.PostTask([weak]() { auto pattern = weak.Upgrade(); CHECK_NULL_VOID(pattern); - auto fullScreenNode = pattern->GetFullScreenNode(); - CHECK_NULL_VOID(fullScreenNode); - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->ExitFullScreen(); + pattern->ExitFullScreen(); }); }); + CHECK_NULL_VOID_NOLOG(videoControllerV2_); videoControllerV2_->AddVideoController(videoController); } void VideoPattern::Start() { - LOGI("Video start to play"); + LOGI("Video start to play."); if (!mediaPlayer_->IsMediaPlayerValid()) { LOGE("media player is invalid."); return; @@ -1139,7 +1073,6 @@ void VideoPattern::Start() platformTask.PostTask([weak = WeakClaim(RawPtr(mediaPlayer_))] { auto mediaPlayer = weak.Upgrade(); CHECK_NULL_VOID(mediaPlayer); - LOGI("trigger mediaPlayer play"); mediaPlayer->Play(); }); } @@ -1229,13 +1162,11 @@ void VideoPattern::ChangePlayButtonTag(RefPtr& playBtn) void VideoPattern::SetFullScreenButtonCallBack(RefPtr& fullScreenBtn) { CHECK_NULL_VOID(fullScreenBtn); - auto fsClickCallback = [weak = WeakClaim(this)](GestureEvent& /* info */) { + auto fsClickCallback = [weak = WeakClaim(this), &isFullScreen = isFullScreen_](GestureEvent& /* info */) { auto videoPattern = weak.Upgrade(); CHECK_NULL_VOID(videoPattern); - if (InstanceOf(videoPattern)) { - auto pattern = AceType::DynamicCast(videoPattern); - CHECK_NULL_VOID(pattern); - pattern->ExitFullScreen(); + if (isFullScreen) { + videoPattern->ExitFullScreen(); } else { videoPattern->FullScreen(); } @@ -1304,34 +1235,60 @@ void VideoPattern::OnFullScreenChange(bool isFullScreen) break; } } - if (fullScreenNodeId_.has_value()) { - auto fullScreenNode = FrameNode::GetFrameNode(V2::VIDEO_ETS_TAG, fullScreenNodeId_.value()); - CHECK_NULL_VOID(fullScreenNode); - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - CHECK_NULL_VOID(fullScreenPattern); - fullScreenPattern->SetMediaFullScreen(isFullScreen); - return; + mediaPlayer_->FullScreenChange(isFullScreen); + if (SystemProperties::GetExtSurfaceEnabled()) { + renderSurface_->SetIsFullScreen(isFullScreen); } - SetMediaFullScreen(isFullScreen); } void VideoPattern::FullScreen() { + if (isFullScreen_) { + LOGE("The video is already full screen when FullScreen"); + return; + } + + auto context = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(context); auto host = GetHost(); CHECK_NULL_VOID(host); - auto videoNode = AceType::DynamicCast(host); - CHECK_NULL_VOID(videoNode); - auto fullScreenPattern = AceType::MakeRefPtr(videoControllerV2_); - fullScreenPattern->InitFullScreenParam(AceType::Claim(this), - renderSurface_, mediaPlayer_, renderContextForMediaPlayer_); - fullScreenNodeId_ = ElementRegister::GetInstance()->MakeUniqueId(); - auto fullScreenNode = VideoFullScreenNode::CreateFullScreenNode(V2::VIDEO_ETS_TAG, - fullScreenNodeId_.value(), fullScreenPattern); - CHECK_NULL_VOID(fullScreenNode); - fullScreenPattern->RequestFullScreen(videoNode); + auto fullScreenManager = context->GetFullScreenManager(); + CHECK_NULL_VOID(fullScreenManager); + fullScreenManager->RequestFullScreen(host); + isFullScreen_ = true; OnFullScreenChange(true); } +void VideoPattern::ExitFullScreen() +{ + if (!isFullScreen_) { + LOGE("The video is not full screen when ExitFullScreen"); + return; + } + + auto context = PipelineContext::GetCurrentContext(); + CHECK_NULL_VOID(context); + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto fullScreenManager = context->GetFullScreenManager(); + CHECK_NULL_VOID(fullScreenManager); + fullScreenManager->ExitFullScreen(host); + isFullScreen_ = false; + OnFullScreenChange(false); +} + +bool VideoPattern::OnBackPressed() +{ + if (!isFullScreen_) { + LOGE("The video is not full screen when OnBackPressed"); + return false; + } + + LOGI("Exit full screen when OnBackPressed"); + ExitFullScreen(); + return true; +} + void VideoPattern::EnableDrag() { auto host = GetHost(); @@ -1417,57 +1374,4 @@ void VideoPattern::EnableDrag() CHECK_NULL_VOID(eventHub); eventHub->SetOnDrop(std::move(dragEnd)); } - -VideoPattern::~VideoPattern() -{ - if (!fullScreenNodeId_.has_value()) { - return; - } - auto fullScreenNode = FrameNode::GetFrameNode(V2::VIDEO_ETS_TAG, fullScreenNodeId_.value()); - CHECK_NULL_VOID(fullScreenNode); - auto parent = fullScreenNode->GetParent(); - CHECK_NULL_VOID(parent); - parent->RemoveChild(fullScreenNode); - parent->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF); -} - -void VideoPattern::RecoverState(const RefPtr& videoPattern) -{ - CHECK_NULL_VOID(videoPattern); - currentPos_ = videoPattern->GetCurrentPos(); - if (mediaPlayer_->IsPlaying() != isPlaying_) { - isPlaying_ = mediaPlayer_->IsPlaying(); - ChangePlayButtonTag(); - } - isPlaying_ = mediaPlayer_->IsPlaying(); - isInitialState_ = videoPattern->GetInitialState(); - auto layoutProperty = videoPattern->GetLayoutProperty(); - src_ = layoutProperty->GetVideoSource().value(); - isStop_ = videoPattern->GetIsStop(); - muted_ = videoPattern->GetMuted(); - autoPlay_ = videoPattern->GetAutoPlay(); - loop_ = videoPattern->GetLoop(); - duration_ = videoPattern->GetDuration(); - progressRate_ = videoPattern->GetProgressRate(); - fullScreenNodeId_.reset(); - RegisterMediaPlayerEvent(); -} - -void VideoPattern::UpdateFsState() -{ - if (!fullScreenNodeId_.has_value()) { - return; - } - auto videoNode = FrameNode::GetFrameNode(V2::VIDEO_ETS_TAG, fullScreenNodeId_.value()); - CHECK_NULL_VOID(videoNode); - auto videoPattern = AceType::DynamicCast(videoNode->GetPattern()); - CHECK_NULL_VOID(videoPattern); - // update full screen state - videoPattern->UpdateState(); -} - -bool VideoPattern::IsFullScreen() const -{ - return InstanceOf(this); -} } // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/video/video_pattern.h b/frameworks/core/components_ng/pattern/video/video_pattern.h index b0981e526d9..c1cd382b604 100644 --- a/frameworks/core/components_ng/pattern/video/video_pattern.h +++ b/frameworks/core/components_ng/pattern/video/video_pattern.h @@ -42,7 +42,7 @@ public: VideoPattern() = default; explicit VideoPattern(const RefPtr& videoController); - ~VideoPattern() override; + ~VideoPattern() override = default; RefPtr CreateEventHub() override { @@ -99,7 +99,10 @@ public: return loop_; } - bool IsFullScreen() const; + bool IsFullScreen() const + { + return isFullScreen_; + } void UpdateProgressRate(double progressRate) { @@ -134,15 +137,7 @@ public: return duration_; } - bool GetInitialState() const - { - return isInitialState_; - } - - virtual bool OnBackPressed() - { - return false; - } + bool OnBackPressed(); void OnVisibleChange(bool isVisible) override; @@ -157,69 +152,11 @@ public: isStop_ = isStop; } - bool GetIsStop() const - { - return isStop_; - } - void SetIsDrag(bool isDrag) { isDrag_ = isDrag; } - bool isInitialState() const - { - return isInitialState_; - } - - void UpdateMediaParam(const RefPtr& mediaPlayer, const RefPtr& renderSurface, - const RefPtr& renderContext) - { - mediaPlayer_ = AceType::Claim(AceType::RawPtr(mediaPlayer)); - renderSurface_ = AceType::Claim(AceType::RawPtr(renderSurface)); - renderContextForMediaPlayer_ = AceType::Claim(AceType::RawPtr(renderContext)); - } - - void ResetMediaParam() - { - mediaPlayer_.Reset(); - renderSurface_.Reset(); - renderContextForMediaPlayer_.Reset(); - } - - void OnFullScreenChange(bool isFullScreen); - - void RecoverState(const RefPtr& videoPattern); - - RefPtr GetFullScreenNode() const - { - if (!fullScreenNodeId_.has_value()) { - return nullptr; - } - return FrameNode::GetFrameNode(V2::VIDEO_ETS_TAG, fullScreenNodeId_.value()); - } - - void OnPlayerStatus(PlaybackStatus status); - - void OnCurrentTimeChange(uint32_t currentPos); - - void OnError(const std::string& errorId); - - void OnResolutionChange() const; - -protected: - void OnUpdateTime(uint32_t time, int pos) const; - void RegisterMediaPlayerEvent(); - - // Video src. - std::string src_; - bool isInitialState_ = true; // Initial state is true. Play or seek will set it to false. - bool isPlaying_ = false; - - RefPtr mediaPlayer_ = MediaPlayer::Create(); - RefPtr renderSurface_ = RenderSurface::Create(); - RefPtr renderContextForMediaPlayer_ = RenderContext::Create(); - private: void OnAttachToFrameNode() override; void OnModifyDone() override; @@ -228,13 +165,13 @@ private: // Set properties for media player. void PrepareMediaPlayer(); + void PrepareSurface(); + void RegisterMediaPlayerEvent(); void SetMethodCall(); - bool SetSourceForMediaPlayer(); void UpdateLooping(); void UpdateSpeed(); void UpdateMuted(); - void PrepareSurface(); bool HasPlayer() const; @@ -243,13 +180,18 @@ private: void Pause(); void Stop(); void FullScreen(); - + void ExitFullScreen(); void SetCurrentTime(float currentPos, SeekMode seekMode = SeekMode::SEEK_PREVIOUS_SYNC); - void SetFullScreenButtonCallBack(RefPtr& fullScreenBtn); + void OnCurrentTimeChange(uint32_t currentPos); + void OnPlayerStatus(PlaybackStatus status); + void OnError(const std::string& errorId); + void OnResolutionChange() const; void OnPrepared(double width, double height, uint32_t duration, uint32_t currentPos, bool needFireEvent); void OnCompletion(); void OnSliderChange(float posTime, int32_t mode); + void OnUpdateTime(uint32_t time, int pos) const; + void OnFullScreenChange(bool isFullScreen); void UpdatePreviewImage(); void UpdateControllerBar(); @@ -260,26 +202,19 @@ private: RefPtr CreateSlider(); void ChangePlayButtonTag(); void ChangePlayButtonTag(RefPtr& playBtn); - + void SetFullScreenButtonCallBack(RefPtr& fullScreenBtn); void ChangeFullScreenButtonTag(bool isFullScreen, RefPtr& fullScreenBtn); void ResetStatus(); void HiddenChange(bool hidden); void PrintPlayerStatus(PlaybackStatus status); - void UpdateFsState(); - // Fire error manually, eg. src is not existed. It must run on ui. void FireError(); - void SetMediaFullScreen(bool isFullScreen) - { - mediaPlayer_->FullScreenChange(isFullScreen); - if (SystemProperties::GetExtSurfaceEnabled()) { - renderSurface_->SetIsFullScreen(isFullScreen); - } - } - RefPtr videoControllerV2_; + RefPtr renderSurface_ = RenderSurface::Create(); + RefPtr mediaPlayer_ = MediaPlayer::Create(); + RefPtr renderContextForMediaPlayer_ = RenderContext::Create(); GestureEventFunc playBtnCallBack_; GestureEventFunc pauseBtnCallBack_; @@ -291,20 +226,22 @@ private: bool muted_ = false; bool autoPlay_ = false; bool loop_ = false; - + bool isFullScreen_ = false; + bool isInitialState_ = true; // Initial state is true. Play or seek will set it to false. + bool isPlaying_ = false; bool pastPlayingStatus_ = false; - uint32_t currentPos_ = 0; + // Video duration. uint32_t duration_ = 0; - - // full screen node id - std::optional fullScreenNodeId_; + uint32_t currentPos_ = 0; // Video playback speed. double progressRate_ = 1.0; Rect lastBoundsRect_; + // Video src. + std::string src_; ACE_DISALLOW_COPY_AND_MOVE(VideoPattern); }; } // namespace OHOS::Ace::NG diff --git a/test/unittest/core/pattern/video/BUILD.gn b/test/unittest/core/pattern/video/BUILD.gn index 0c0c8b4e8e0..68dee2eab3f 100644 --- a/test/unittest/core/pattern/video/BUILD.gn +++ b/test/unittest/core/pattern/video/BUILD.gn @@ -45,8 +45,6 @@ ace_unittest("video_test_ng") { "$ace_root/frameworks/core/components_ng/pattern/text/text_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/text/text_styles.cpp", "$ace_root/frameworks/core/components_ng/pattern/video/video_accessibility_property.cpp", - "$ace_root/frameworks/core/components_ng/pattern/video/video_full_screen_node.cpp", - "$ace_root/frameworks/core/components_ng/pattern/video/video_full_screen_pattern.cpp", "$ace_root/frameworks/core/components_ng/pattern/video/video_layout_algorithm.cpp", "$ace_root/frameworks/core/components_ng/pattern/video/video_model_ng.cpp", "$ace_root/frameworks/core/components_ng/pattern/video/video_node.cpp", diff --git a/test/unittest/core/pattern/video/video_test_ng.cpp b/test/unittest/core/pattern/video/video_test_ng.cpp index 2a6f4f515bd..1a7f287d06f 100644 --- a/test/unittest/core/pattern/video/video_test_ng.cpp +++ b/test/unittest/core/pattern/video/video_test_ng.cpp @@ -35,7 +35,6 @@ #include "core/components_ng/event/drag_event.h" #include "core/components_ng/layout/layout_algorithm.h" #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" -#include "core/components_ng/pattern/video/video_full_screen_pattern.h" #include "core/components_ng/pattern/video/video_layout_algorithm.h" #include "core/components_ng/pattern/video/video_layout_property.h" #include "core/components_ng/pattern/video/video_model_ng.h" @@ -1021,12 +1020,12 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1) json->Put("fullscreen", true); auto fullScreenTrue = json->ToString(); pattern->FullScreen(); // will called onFullScreenChange(true) - EXPECT_TRUE(pattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(pattern->isFullScreen_); EXPECT_EQ(fullScreenCheck, fullScreenTrue); fullScreenCheck.clear(); pattern->FullScreen(); // call again, nothing will happen - EXPECT_TRUE(pattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(pattern->isFullScreen_); EXPECT_TRUE(fullScreenCheck.empty()); // get the full screen svg node & get its gestureEventHub @@ -1046,20 +1045,16 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1) json = JsonUtil::Create(true); json->Put("fullscreen", false); auto fullScreenFalse = json->ToString(); - EXPECT_FALSE(pattern->GetFullScreenNode() != nullptr); + EXPECT_FALSE(pattern->isFullScreen_); EXPECT_EQ(fullScreenCheck, fullScreenFalse); fullScreenCheck.clear(); - auto fullScreenNode = pattern->GetFullScreenNode(); - EXPECT_FALSE(fullScreenNode == nullptr); - auto fullScreenPattern = AceType::DynamicCast(fullScreenNode->GetPattern()); - EXPECT_FALSE(fullScreenPattern == nullptr); - fullScreenPattern->ExitFullScreen(); // call again, nothing will happen - EXPECT_FALSE(pattern->GetFullScreenNode() != nullptr); + pattern->ExitFullScreen(); // call again, nothing will happen + EXPECT_FALSE(pattern->isFullScreen_); EXPECT_TRUE(fullScreenCheck.empty()); fsEvent->ActClick(); // this will call FullScreen() - EXPECT_TRUE(pattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(pattern->isFullScreen_); /** * @tc.steps: step4. call OnBackPressed @@ -1072,7 +1067,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1) auto flag = fullScreenManager->OnBackPressed(); // will on videoPattern->OnBackPressed() EXPECT_TRUE(flag); - EXPECT_FALSE(pattern->GetFullScreenNode() != nullptr); + EXPECT_FALSE(pattern->isFullScreen_); EXPECT_EQ(fullScreenCheck, fullScreenFalse); root->AddChild(tempFrameNode); @@ -1080,7 +1075,7 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1) EXPECT_FALSE(flag); pattern->OnBackPressed(); // nothing will happen - EXPECT_FALSE(pattern->GetFullScreenNode() != nullptr); + EXPECT_FALSE(pattern->isFullScreen_); /** * @tc.steps: step5. call FullScreen & ExitFullScreen in videoController @@ -1088,12 +1083,12 @@ HWTEST_F(VideoTestNg, VideoPatternTest013, TestSize.Level1) * @tc.expected: step5. onFullScreenChange(true / false) will be called */ pattern->FullScreen(); - EXPECT_TRUE(pattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(pattern->isFullScreen_); EXPECT_EQ(fullScreenCheck, fullScreenTrue); videoController->ExitFullscreen(false); // nothing will happen for it's async - EXPECT_TRUE(pattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(pattern->isFullScreen_); videoController->ExitFullscreen(true); - EXPECT_FALSE(pattern->GetFullScreenNode() != nullptr); + EXPECT_FALSE(pattern->isFullScreen_); EXPECT_EQ(fullScreenCheck, fullScreenFalse); } @@ -1168,7 +1163,7 @@ HWTEST_F(VideoTestNg, VideoFullScreenTest015, TestSize.Level1) layoutWrapper.SetLayoutAlgorithm(AceType::MakeRefPtr(videoLayoutAlgorithm)); videoPattern->FullScreen(); // will called onFullScreenChange(true) - EXPECT_TRUE(videoPattern->GetFullScreenNode() != nullptr); + EXPECT_TRUE(videoPattern->isFullScreen_); // Test MeasureContent when it is fullScreen. /** @@ -1203,12 +1198,8 @@ HWTEST_F(VideoTestNg, VideoFullScreenTest015, TestSize.Level1) * @tc.steps: step3. change from full screen to normal size, check size. * @tc.expected: step2. Video size is same to origional size. */ - auto videoFullScreenNode = videoPattern->GetFullScreenNode(); - EXPECT_FALSE(videoFullScreenNode == nullptr); - auto fullScreenPattern = AceType::DynamicCast(videoFullScreenNode->GetPattern()); - EXPECT_FALSE(fullScreenPattern == nullptr); - fullScreenPattern->ExitFullScreen(); // will called onFullScreenChange(true) - EXPECT_FALSE(videoPattern->GetFullScreenNode() != nullptr); + videoPattern->ExitFullScreen(); // will called onFullScreenChange(true) + EXPECT_FALSE(videoPattern->isFullScreen_); videoSize = videoLayoutAlgorithm->MeasureContent(layoutConstraint, &layoutWrapper).value_or(SizeF(0.0f, 0.0f)); EXPECT_EQ(videoSize, SizeF(VIDEO_WIDTH, VIDEO_HEIGHT)); -- Gitee