[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / video-view / video-view-impl.cpp
index 5608105..5fa13de 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 // EXTERNAL INCLUDES
 #include <dali/devel-api/actors/actor-devel.h>
 #include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/devel-api/rendering/texture-devel.h>
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/adaptor-framework/native-image-source.h>
@@ -83,6 +84,8 @@ const char* const CUSTOM_FRAGMENT_SHADER("fragmentShader");
 const char* const DEFAULT_SAMPLER_TYPE_NAME("sampler2D");
 const char* const CUSTOM_SAMPLER_TYPE_NAME("samplerExternalOES");
 
+const char* const IS_VIDEO_VIEW_PROPERTY_NAME = "isVideoView";
+
 } // namespace
 
 VideoView::VideoView(Dali::VideoSyncMode syncMode)
@@ -91,7 +94,8 @@ VideoView::VideoView(Dali::VideoSyncMode syncMode)
   mFrameID(0),
   mIsPlay(false),
   mIsUnderlay(true),
-  mSyncMode(syncMode)
+  mSyncMode(syncMode),
+  mSiblingOrder(0)
 {
 }
 
@@ -111,12 +115,15 @@ Toolkit::VideoView VideoView::New(VideoSyncMode syncMode)
 
 void VideoView::OnInitialize()
 {
+  Actor self = Self();
   mVideoPlayer.FinishedSignal().Connect(this, &VideoView::EmitSignalFinish);
 
-  DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
-    return std::unique_ptr<Dali::Accessibility::Accessible>(
-      new DevelControl::AccessibleImpl(actor, Dali::Accessibility::Role::VIDEO));
-  });
+  // Accessibility
+  self.SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::VIDEO);
+  self.SetProperty(DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, true);
+
+  //update self property
+  self.RegisterProperty(IS_VIDEO_VIEW_PROPERTY_NAME, true, Property::READ_WRITE);
 }
 
 void VideoView::SetUrl(const std::string& url)
@@ -503,12 +510,15 @@ void VideoView::SetDepthIndex(int depthIndex)
 
 void VideoView::OnSceneConnection(int depth)
 {
-  Control::OnSceneConnection(depth);
-
+  Actor self = Self();
   if(mIsUnderlay)
   {
+    mSiblingOrder = self.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER);
+    DevelActor::ChildOrderChangedSignal(self.GetParent()).Connect(this, &VideoView::OnChildOrderChanged);
     SetWindowSurfaceTarget();
   }
+
+  Control::OnSceneConnection(depth);
 }
 
 void VideoView::OnSceneDisconnection()
@@ -526,6 +536,57 @@ void VideoView::OnSizeSet(const Vector3& targetSize)
   Control::OnSizeSet(targetSize);
 }
 
+void VideoView::OnChildOrderChanged(Actor actor)
+{
+  Actor self                = Self();
+  int   currentSiblingOrder = self.GetProperty<int>(Dali::DevelActor::Property::SIBLING_ORDER);
+  if(currentSiblingOrder != mSiblingOrder)
+  {
+    Actor parent = self.GetParent();
+    Actor child;
+    Actor upper;
+    Actor lower;
+
+    int numChildren = static_cast<int>(parent.GetChildCount());
+    for(int i = 0; i < numChildren; i++)
+    {
+      child = parent.GetChildAt(i);
+      if(!IsVideoView(child))
+      {
+        continue;
+      }
+
+      if(child == self)
+      {
+        continue;
+      }
+
+      if(i < currentSiblingOrder)
+      {
+        lower = child;
+      }
+      else if(i > currentSiblingOrder)
+      {
+        upper = child;
+        break;
+      }
+    }
+
+    if(lower)
+    {
+      Toolkit::VideoView lowerView = Toolkit::VideoView::DownCast(lower);
+      mVideoPlayer.RaiseAbove(GetImpl(lowerView).GetVideoPlayer());
+    }
+
+    if(upper)
+    {
+      Toolkit::VideoView upperView = Toolkit::VideoView::DownCast(upper);
+      mVideoPlayer.LowerBelow(GetImpl(upperView).GetVideoPlayer());
+    }
+    mSiblingOrder = currentSiblingOrder;
+  }
+}
+
 Vector3 VideoView::GetNaturalSize()
 {
   Vector3 size;
@@ -543,30 +604,6 @@ Vector3 VideoView::GetNaturalSize()
   }
 }
 
-float VideoView::GetHeightForWidth(float width)
-{
-  if(mVideoSize.GetWidth() > 0 && mVideoSize.GetHeight() > 0)
-  {
-    return GetHeightForWidthBase(width);
-  }
-  else
-  {
-    return Control::GetHeightForWidthBase(width);
-  }
-}
-
-float VideoView::GetWidthForHeight(float height)
-{
-  if(mVideoSize.GetWidth() > 0 && mVideoSize.GetHeight() > 0)
-  {
-    return GetWidthForHeightBase(height);
-  }
-  else
-  {
-    return Control::GetWidthForHeightBase(height);
-  }
-}
-
 void VideoView::SetWindowSurfaceTarget()
 {
   Actor self = Self();
@@ -577,6 +614,9 @@ void VideoView::SetWindowSurfaceTarget()
     return;
   }
 
+  Dali::Window window = DevelWindow::Get(self);
+  window.ResizeSignal().Connect(this, &VideoView::OnWindowResized);
+
   int curPos = mVideoPlayer.GetPlayPosition();
 
   if(mIsPlay)
@@ -605,7 +645,7 @@ void VideoView::SetWindowSurfaceTarget()
   {
     // For underlay rendering mode, video display area have to be transparent.
     Geometry geometry = VisualFactoryCache::CreateQuadGeometry();
-    Shader   shader   = Shader::New(SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG);
+    Shader   shader   = Shader::New(SHADER_VIDEO_VIEW_VERT, SHADER_VIDEO_VIEW_FRAG, Shader::Hint::NONE, "VIDEO_VIEW_OVERLAY");
     mOverlayRenderer  = Renderer::New(geometry, shader);
     mOverlayRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::OFF);
   }
@@ -782,6 +822,17 @@ void VideoView::OnAnimationFinished(Animation& animation)
   SetFrameRenderCallback();
 }
 
+void VideoView::OnWindowResized(Dali::Window winHandle, Dali::Window::WindowSize size)
+{
+  Dali::VideoPlayerPlugin::DisplayRotation videoAngle  = mVideoPlayer.GetDisplayRotation();
+  int                                      windowAngle = (DevelWindow::GetPhysicalOrientation(winHandle) / 90);
+
+  if(windowAngle != videoAngle)
+  {
+    mVideoPlayer.SetDisplayRotation(static_cast<Dali::VideoPlayerPlugin::DisplayRotation>(windowAngle));
+  }
+}
+
 void VideoView::PlayAnimation(Dali::Animation animation)
 {
   if(mIsUnderlay && mSyncMode == Dali::VideoSyncMode::ENABLED)
@@ -794,7 +845,7 @@ void VideoView::PlayAnimation(Dali::Animation animation)
 
 Dali::Shader VideoView::CreateShader()
 {
-  std::string fragmentShader = "#extension GL_OES_EGL_image_external:require\n";
+  std::string fragmentShader;
   std::string vertexShader;
   std::string customFragmentShader;
   bool        checkShader = false;
@@ -825,16 +876,18 @@ Dali::Shader VideoView::CreateShader()
 
     if(!fragmentShaderValue || !checkShader)
     {
-      fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
+      fragmentShader = SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
+      DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShader);
     }
   }
   else
   {
-    vertexShader = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
-    fragmentShader += SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
+    vertexShader   = SHADER_VIDEO_VIEW_TEXTURE_VERT.data();
+    fragmentShader = SHADER_VIDEO_VIEW_TEXTURE_FRAG.data();
+    DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShader);
   }
 
-  return Dali::Shader::New(vertexShader, fragmentShader);
+  return Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "VIDEO_VIEW");
 }
 
 bool VideoView::GetStringFromProperty(const Dali::Property::Value& value, std::string& output)
@@ -879,6 +932,28 @@ void VideoView::SetFrameRenderCallback()
                                         mFrameID);
 }
 
+bool VideoView::IsVideoView(Actor actor) const
+{
+  // Check whether the actor is a VideoView
+  bool isVideoView = false;
+
+  if(actor)
+  {
+    Property::Index propertyIsVideoView = actor.GetPropertyIndex(IS_VIDEO_VIEW_PROPERTY_NAME);
+    if(propertyIsVideoView != Property::INVALID_INDEX)
+    {
+      isVideoView = actor.GetProperty<bool>(propertyIsVideoView);
+    }
+  }
+
+  return isVideoView;
+}
+
+VideoPlayer VideoView::GetVideoPlayer()
+{
+  return mVideoPlayer;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit