mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
fix window change problem for video
Signed-off-by: w00584494 <wangqiangqiang10@huawei.com> Change-Id: Ia3518fe2b7ce160f68aa65ceb35fec8682b4dccf
This commit is contained in:
parent
224dfd1d01
commit
e9e59f67a2
@ -89,7 +89,8 @@ void ImageAnalyzerManager::CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMa
|
||||
analyzerUIConfig_.onAnalyzed = std::nullopt;
|
||||
}
|
||||
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap)
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap,
|
||||
const NG::OffsetF& offset)
|
||||
{
|
||||
if (!isAnalyzerOverlayBuild_) {
|
||||
return;
|
||||
@ -106,6 +107,12 @@ void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMa
|
||||
}
|
||||
|
||||
CHECK_NULL_VOID(pixelMap);
|
||||
if (holder_ == ImageAnalyzerHolder::VIDEO_CUSTOM) {
|
||||
analyzerUIConfig_.pixelMapWidth = pixelMap->GetWidth();
|
||||
analyzerUIConfig_.pixelMapHeight = pixelMap->GetHeight();
|
||||
analyzerUIConfig_.overlayOffset = offset;
|
||||
}
|
||||
|
||||
if (holder_ != ImageAnalyzerHolder::IMAGE) {
|
||||
analyzerUIConfig_.contentWidth = pixelMap->GetWidth();
|
||||
analyzerUIConfig_.contentHeight = pixelMap->GetHeight();
|
||||
|
@ -29,7 +29,8 @@ void ImageAnalyzerManager::CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMa
|
||||
{
|
||||
}
|
||||
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap)
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap,
|
||||
const NG::OffsetF& offset)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
|
||||
bool IsSupportImageAnalyzerFeature();
|
||||
void CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
|
||||
void UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap);
|
||||
void UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
|
||||
void UpdateAnalyzerOverlayLayout();
|
||||
void UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode, const PixelMapInfo& info = {});
|
||||
void DestroyAnalyzerOverlay();
|
||||
|
@ -71,6 +71,7 @@ constexpr uint32_t DURATION_POS = 3;
|
||||
constexpr uint32_t FULL_SCREEN_POS = 4;
|
||||
constexpr int32_t AVERAGE_VALUE = 2;
|
||||
constexpr int32_t ANALYZER_DELAY_TIME = 100;
|
||||
constexpr int32_t ANALYZER_CAPTURE_DELAY_TIME = 1000;
|
||||
const Dimension LIFT_HEIGHT = 28.0_vp;
|
||||
const std::string PNG_FILE_EXTENSION = "png";
|
||||
|
||||
@ -1041,17 +1042,22 @@ bool VideoPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty,
|
||||
videoFrameSize.Height());
|
||||
}
|
||||
|
||||
auto padding = layoutProperty->CreatePaddingAndBorder();
|
||||
auto imageFit = layoutProperty->GetObjectFitValue(ImageFit::COVER);
|
||||
if (imageFit == ImageFit::COVER) {
|
||||
contentRect_ = Rect(padding.left.value_or(0), padding.top.value_or(0),
|
||||
videoNodeSize.Width(), videoNodeSize.Height());
|
||||
} else {
|
||||
contentRect_ = Rect((videoNodeSize.Width() - videoFrameSize.Width()) / AVERAGE_VALUE + padding.left.value_or(0),
|
||||
(videoNodeSize.Height() - videoFrameSize.Height()) / AVERAGE_VALUE + padding.top.value_or(0),
|
||||
videoFrameSize.Width(), videoFrameSize.Height());
|
||||
}
|
||||
if (IsSupportImageAnalyzer()) {
|
||||
Rect tmpRect;
|
||||
auto padding = layoutProperty->CreatePaddingAndBorder();
|
||||
auto imageFit = layoutProperty->GetObjectFitValue(ImageFit::COVER);
|
||||
if (imageFit == ImageFit::COVER || imageFit == ImageFit::NONE) {
|
||||
tmpRect = Rect(padding.left.value_or(0), padding.top.value_or(0),
|
||||
videoNodeSize.Width(), videoNodeSize.Height());
|
||||
} else {
|
||||
tmpRect = Rect((videoNodeSize.Width() - videoFrameSize.Width()) / AVERAGE_VALUE + padding.left.value_or(0),
|
||||
(videoNodeSize.Height() - videoFrameSize.Height()) / AVERAGE_VALUE + padding.top.value_or(0),
|
||||
videoFrameSize.Width(), videoFrameSize.Height());
|
||||
}
|
||||
if (contentRect_ != tmpRect && ShouldUpdateImageAnalyzer()) {
|
||||
StartUpdateImageAnalyzer();
|
||||
}
|
||||
contentRect_ = tmpRect;
|
||||
UpdateAnalyzerUIConfig(geometryNode);
|
||||
}
|
||||
|
||||
@ -1782,6 +1788,24 @@ bool VideoPattern::IsSupportImageAnalyzer()
|
||||
return isEnableAnalyzer_ && !needControlBar && imageAnalyzerManager_->IsSupportImageAnalyzerFeature();
|
||||
}
|
||||
|
||||
bool VideoPattern::ShouldUpdateImageAnalyzer() {
|
||||
auto layoutProperty = GetLayoutProperty<VideoLayoutProperty>();
|
||||
CHECK_NULL_RETURN(layoutProperty, false);
|
||||
const auto& constraint = layoutProperty->GetCalcLayoutConstraint();
|
||||
if (!constraint || !constraint->selfIdealSize.has_value() || !constraint->selfIdealSize->IsValid()) {
|
||||
return false;
|
||||
}
|
||||
auto selfIdealSize = constraint->selfIdealSize;
|
||||
if (!selfIdealSize->PercentWidth() && !selfIdealSize->PercentHeight()) {
|
||||
return false;
|
||||
}
|
||||
auto imageFit = layoutProperty->GetObjectFit().value_or(ImageFit::COVER);
|
||||
if (imageFit != ImageFit::COVER && imageFit != ImageFit::NONE) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void VideoPattern::StartImageAnalyzer()
|
||||
{
|
||||
if (!IsSupportImageAnalyzer() || !imageAnalyzerManager_) {
|
||||
@ -1825,6 +1849,53 @@ void VideoPattern::CreateAnalyzerOverlay()
|
||||
imageAnalyzerManager_->CreateAnalyzerOverlay(pixelMap, contentOffset);
|
||||
}
|
||||
|
||||
void VideoPattern::StartUpdateImageAnalyzer()
|
||||
{
|
||||
CHECK_NULL_VOID(imageAnalyzerManager_);
|
||||
if (!imageAnalyzerManager_->IsOverlayCreated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateOverlayVisibility(VisibleType::GONE);
|
||||
ContainerScope scope(instanceId_);
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto context = host->GetContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto uiTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
|
||||
uiTaskExecutor.PostDelayedTask([weak = WeakClaim(this)] {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
if (!pattern->isContentSizeChanged_) {
|
||||
return;
|
||||
}
|
||||
pattern->UpdateAnalyzerOverlay();
|
||||
pattern->isContentSizeChanged_ = false;
|
||||
}, ANALYZER_CAPTURE_DELAY_TIME, "ArkUIVideoUpdateAnalyzerOverlay");
|
||||
isContentSizeChanged_ = true;
|
||||
}
|
||||
|
||||
void VideoPattern::UpdateAnalyzerOverlay()
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto context = host->GetRenderContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto nailPixelMap = context->GetThumbnailPixelMap();
|
||||
CHECK_NULL_VOID(nailPixelMap);
|
||||
auto pixelMap = nailPixelMap->GetCropPixelMap(contentRect_);
|
||||
CHECK_NULL_VOID(pixelMap);
|
||||
UpdateOverlayVisibility(VisibleType::VISIBLE);
|
||||
|
||||
auto layoutProperty = GetLayoutProperty<VideoLayoutProperty>();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
auto padding = layoutProperty->CreatePaddingAndBorder();
|
||||
OffsetF contentOffset = { contentRect_.Left() - padding.left.value_or(0),
|
||||
contentRect_.Top() - padding.top.value_or(0) };
|
||||
CHECK_NULL_VOID(imageAnalyzerManager_);
|
||||
imageAnalyzerManager_->UpdateAnalyzerOverlay(pixelMap, contentOffset);
|
||||
}
|
||||
|
||||
void VideoPattern::UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode)
|
||||
{
|
||||
if (IsSupportImageAnalyzer()) {
|
||||
@ -1851,6 +1922,17 @@ bool VideoPattern::GetAnalyzerState()
|
||||
return imageAnalyzerManager_->IsOverlayCreated();
|
||||
}
|
||||
|
||||
void VideoPattern::UpdateOverlayVisibility(VisibleType type)
|
||||
{
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto overlayNode = host->GetOverlayNode();
|
||||
CHECK_NULL_VOID(overlayNode);
|
||||
auto prop = overlayNode->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(prop);
|
||||
prop->UpdateVisibility(type);
|
||||
}
|
||||
|
||||
void VideoPattern::OnWindowHide()
|
||||
{
|
||||
#if defined(OHOS_PLATFORM)
|
||||
|
@ -337,11 +337,14 @@ private:
|
||||
void ChangePlayerStatus(bool isPlaying, const PlaybackStatus& status);
|
||||
|
||||
bool IsSupportImageAnalyzer();
|
||||
bool ShouldUpdateImageAnalyzer();
|
||||
void StartImageAnalyzer();
|
||||
void StartUpdateImageAnalyzer();
|
||||
void CreateAnalyzerOverlay();
|
||||
void DestroyAnalyzerOverlay();
|
||||
void UpdateAnalyzerOverlay();
|
||||
void UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode);
|
||||
void UpdateOverlayVisibility(VisibleType type);
|
||||
|
||||
RefPtr<VideoControllerV2> videoControllerV2_;
|
||||
RefPtr<FrameNode> controlBar_;
|
||||
@ -368,6 +371,7 @@ private:
|
||||
bool isEnableAnalyzer_ = false;
|
||||
bool isAnalyzerCreated_ = false;
|
||||
bool isPaused_ = false;
|
||||
bool isContentSizeChanged_ = false;
|
||||
|
||||
uint32_t currentPos_ = 0;
|
||||
uint32_t duration_ = 0;
|
||||
|
@ -28,7 +28,7 @@ void ImageAnalyzerManager::CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMa
|
||||
{
|
||||
}
|
||||
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap)
|
||||
void ImageAnalyzerManager::UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ class MockImageAnalyzerManager : public ImageAnalyzerManager {
|
||||
public:
|
||||
bool IsSupportImageAnalyzerFeature();
|
||||
void CreateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
|
||||
void UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap);
|
||||
void UpdateAnalyzerOverlay(const RefPtr<OHOS::Ace::PixelMap>& pixelMap, const NG::OffsetF& offset = { 0.0f, 0.0f });
|
||||
void UpdateAnalyzerOverlayLayout();
|
||||
void UpdateAnalyzerUIConfig(const RefPtr<NG::GeometryNode>& geometryNode, const PixelMapInfo& info = {});
|
||||
void DestroyAnalyzerOverlay();
|
||||
|
Loading…
Reference in New Issue
Block a user