diff --git a/frameworks/bridge/declarative_frontend/jsview/js_video.cpp b/frameworks/bridge/declarative_frontend/jsview/js_video.cpp index 9585d13761e3e4eef4be0895ca1642d8929aa293..77b847b125cd018bedd85308fb75d62b67acdfc7 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_video.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_video.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,6 +16,7 @@ #include "frameworks/bridge/declarative_frontend/jsview/js_video.h" #include "base/log/ace_scoring_log.h" +#include "bridge/declarative_frontend/jsview/js_utils.h" #include "bridge/declarative_frontend/jsview/js_video_controller.h" #include "bridge/declarative_frontend/jsview/models/video_model_impl.h" #include "core/components_ng/pattern/video/video_model_ng.h" @@ -95,7 +96,12 @@ void JSVideo::Create(const JSCallbackInfo& info) VideoModel::GetInstance()->SetPosterSourceInfo(previewUri); } else { // Src is a pixelmap. +#if defined(PIXEL_MAP_SUPPORTED) + RefPtr pixMap = CreatePixelMapFromNapiValue(previewUriValue); + VideoModel::GetInstance()->SetPosterSourceByPixelMap(pixMap); +#else LOGE("can not support pixel map"); +#endif } } diff --git a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp index 29d6036cebeed79c621b09282551ae37b3f5447e..acd2abc29d7922d73ffe96156fb671301b6ac9b5 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -61,6 +61,11 @@ void VideoModelImpl::SetPosterSourceInfo(const std::string& posterUrl) videoComponent->SetPoster(posterUrl); } +void VideoModelImpl::SetPosterSourceByPixelMap(RefPtr& pixMap) +{ + LOGW("Pixelmap is not supported."); +} + void VideoModelImpl::SetMuted(bool muted) { auto videoComponent = AceType::DynamicCast(ViewStackProcessor::GetInstance()->GetMainComponent()); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h index 659e972a8b622553742274ea840ce302dc9be812..25a80b46a144849d51559a97525eb40bd2ca24a8 100644 --- a/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h +++ b/frameworks/bridge/declarative_frontend/jsview/models/video_model_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -26,6 +26,7 @@ public: void SetSrc(const std::string& src) override; void SetProgressRate(double progressRate) override; void SetPosterSourceInfo(const std::string& posterUrl) override; + void SetPosterSourceByPixelMap(RefPtr& pixMap) override; void SetMuted(bool muted) override; void SetAutoPlay(bool autoPlay) override; void SetControls(bool controls) override; diff --git a/frameworks/core/components_ng/pattern/video/video_model.h b/frameworks/core/components_ng/pattern/video/video_model.h index fe47b83f9d9e7878593033e09301b7984b7f1307..0641a15f2a0457ad84548fcb143b9bf110afe921 100644 --- a/frameworks/core/components_ng/pattern/video/video_model.h +++ b/frameworks/core/components_ng/pattern/video/video_model.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_VIDEO_VIDEO_MODEL_H #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_VIDEO_VIDEO_MODEL_H +#include "base/image/pixel_map.h" #include "core/components/common/layout/constants.h" #include "core/components/video/video_controller_v2.h" @@ -30,6 +31,7 @@ public: virtual void SetSrc(const std::string& src) = 0; virtual void SetProgressRate(double progressRate) = 0; virtual void SetPosterSourceInfo(const std::string& posterUrl) = 0; + virtual void SetPosterSourceByPixelMap(RefPtr& pixMap) = 0; virtual void SetMuted(bool muted) = 0; virtual void SetAutoPlay(bool autoPlay) = 0; virtual void SetControls(bool controls) = 0; diff --git a/frameworks/core/components_ng/pattern/video/video_model_ng.cpp b/frameworks/core/components_ng/pattern/video/video_model_ng.cpp index 0506b7dada2ac09c02756017f2607a4b42a28a29..a1abbb8ab0675a6cc3671eabca84f7f5fa048157 100644 --- a/frameworks/core/components_ng/pattern/video/video_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/video/video_model_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -51,6 +51,12 @@ void VideoModelNG::SetPosterSourceInfo(const std::string& posterUrl) ACE_UPDATE_LAYOUT_PROPERTY(VideoLayoutProperty, PosterImageInfo, posterSourceInfo); } +void VideoModelNG::SetPosterSourceByPixelMap(RefPtr& pixMap) +{ + ImageSourceInfo posterSourceInfo(pixMap); + ACE_UPDATE_LAYOUT_PROPERTY(VideoLayoutProperty, PosterImageInfo, posterSourceInfo); +} + void VideoModelNG::SetMuted(bool muted) { auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); @@ -165,4 +171,4 @@ void VideoModelNG::SetOnFullScreenChange(VideoEventFunc&& onFullScreenChange) CHECK_NULL_VOID(eventHub); eventHub->SetOnFullScreenChange(std::move(onFullScreenChange)); } -} // namespace OHOS::Ace::NG \ No newline at end of file +} // namespace OHOS::Ace::NG diff --git a/frameworks/core/components_ng/pattern/video/video_model_ng.h b/frameworks/core/components_ng/pattern/video/video_model_ng.h index b1e225e8a635e93c6ac2a503d4a5b00724a48113..2f946ace1a872a9ea9bab76b8893abf64a310541 100644 --- a/frameworks/core/components_ng/pattern/video/video_model_ng.h +++ b/frameworks/core/components_ng/pattern/video/video_model_ng.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -26,6 +26,7 @@ public: void SetSrc(const std::string& src) override; void SetProgressRate(double progressRate) override; void SetPosterSourceInfo(const std::string& posterUrl) override; + void SetPosterSourceByPixelMap(RefPtr& pixMap) override; void SetMuted(bool muted) override; void SetAutoPlay(bool autoPlay) override; void SetControls(bool controls) override; diff --git a/frameworks/core/components_ng/test/pattern/video/BUILD.gn b/frameworks/core/components_ng/test/pattern/video/BUILD.gn index c969ce7406095c553e54ec907de5a56a88f7a433..91bfb6b7a5ec80fac1498e135bedaed748264019 100644 --- a/frameworks/core/components_ng/test/pattern/video/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/video/BUILD.gn @@ -163,6 +163,7 @@ ohos_unittest("video_pattern_test_ng") { # mock "$ace_root/frameworks/base/test/mock/mock_drag_window.cpp", + "$ace_root/frameworks/base/test/mock/mock_pixel_map.cpp", "$ace_root/frameworks/base/test/mock/mock_system_properties.cpp", "$ace_root/frameworks/core/common/test/mock/mock_ace_application_info.cpp", "$ace_root/frameworks/core/components_ng/test/mock/animation/mock_geometry_transition.cpp", diff --git a/frameworks/core/components_ng/test/pattern/video/video_pattern_test_ng.cpp b/frameworks/core/components_ng/test/pattern/video/video_pattern_test_ng.cpp index e98e5b00b67b01561f58ef788434b6be7fb6854c..9d74aeb74b22754903772b2afeb4052a5b243af0 100644 --- a/frameworks/core/components_ng/test/pattern/video/video_pattern_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/video/video_pattern_test_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -1151,11 +1151,11 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest013, TestSize.Level1) } /** - * @tc.name: VideoPatternTest015 + * @tc.name: VideoPatternTest014 * @tc.desc: Test OnResolutionChange & OnHiddenChange * @tc.type: FUNC */ -HWTEST_F(VideoPropertyTestNg, VideoPatternTest015, TestSize.Level1) +HWTEST_F(VideoPropertyTestNg, VideoPatternTest014, TestSize.Level1) { /** * @tc.steps: step1. Create Video @@ -1219,11 +1219,11 @@ HWTEST_F(VideoPropertyTestNg, VideoPatternTest015, TestSize.Level1) } /** - * @tc.name: VideoFullScreenTest016 + * @tc.name: VideoFullScreenTest015 * @tc.desc: Create Video, and invoke its MeasureContent function to calculate the content size when it is fullscreen. * @tc.type: FUNC */ -HWTEST_F(VideoPropertyTestNg, VideoFullScreenTest016, TestSize.Level1) +HWTEST_F(VideoPropertyTestNg, VideoFullScreenTest015, TestSize.Level1) { /** * @tc.steps: step1. Create Video @@ -1298,4 +1298,67 @@ HWTEST_F(VideoPropertyTestNg, VideoFullScreenTest016, TestSize.Level1) videoSize = videoLayoutAlgorithm->MeasureContent(layoutConstraint, &layoutWrapper).value_or(SizeF(0.0f, 0.0f)); EXPECT_EQ(videoSize, SizeF(VIDEO_WIDTH, VIDEO_HEIGHT)); } + +/** + * @tc.name: VideoPropertyTest016 + * @tc.desc: Create Vdeo, and check the pixelmap. + * @tc.type: FUNC + */ +HWTEST_F(VideoPropertyTestNg, VideoPropertyTest016, TestSize.Level1) +{ + VideoModelNG video; + auto videoController = AceType::MakeRefPtr(); + video.Create(videoController); + + /** + * @tc.steps: step1. Create a video. + * @tc.expected: step1. Create successfully. + */ + auto frameNodeTemp = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + CHECK_NULL_VOID(frameNodeTemp); + auto videoPatternTemp = AceType::DynamicCast(frameNodeTemp->GetPattern()); + CHECK_NULL_VOID(videoPatternTemp); + EXPECT_CALL(*(AceType::DynamicCast(videoPatternTemp->mediaPlayer_)), IsMediaPlayerValid()) + .WillRepeatedly(Return(false)); + + /** + * @tc.steps: step3. Set the preview by pixelmap. + * @tc.expected: step2. Set the pixelmap successfully. + */ + void* voidPtr = static_cast(new char[0]); + void* secondVoidPtr = static_cast(new char[0]); + RefPtr pixelMap = PixelMap::CreatePixelMap(voidPtr); + RefPtr secondPixelMap = PixelMap::CreatePixelMap(secondVoidPtr); + + // Default image and pixelmap image and url image. + ImageSourceInfo defaultImage = ImageSourceInfo(""); + ImageSourceInfo pixelMapImage = ImageSourceInfo(pixelMap); + ImageSourceInfo secondPixelMapImage = ImageSourceInfo(secondPixelMap); + ImageSourceInfo urlImage = ImageSourceInfo(VIDEO_POSTER_URL); + + video.SetSrc(VIDEO_SRC); + video.SetProgressRate(VIDEO_PROGRESS_RATE); + video.SetPosterSourceByPixelMap(pixelMap); + + auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode(); + EXPECT_TRUE(frameNode != nullptr && frameNode->GetTag() == V2::VIDEO_ETS_TAG); + auto videoLayoutProperty = frameNode->GetLayoutProperty(); + EXPECT_FALSE(videoLayoutProperty == nullptr); + + EXPECT_EQ(videoLayoutProperty->GetVideoSource().value_or(""), VIDEO_SRC); + EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(defaultImage), pixelMapImage); + + /** + * @tc.steps: step3. Reset preview by another pixelmap. + * @tc.expected: step2. Reset the pixelmap successfully. + */ + video.SetPosterSourceByPixelMap(secondPixelMap); + EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(defaultImage), secondPixelMapImage); + + video.SetPosterSourceInfo(VIDEO_POSTER_URL); + EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(defaultImage), urlImage); + + video.SetPosterSourceByPixelMap(pixelMap); + EXPECT_EQ(videoLayoutProperty->GetPosterImageInfoValue(defaultImage), pixelMapImage); +} } // namespace OHOS::Ace::NG