Add AutoRotation, LetterBox 01/317901/11
authorjoogab.yun <joogab.yun@samsung.com>
Thu, 9 Jan 2025 07:42:43 +0000 (16:42 +0900)
committerjoogab.yun <joogab.yun@samsung.com>
Mon, 13 Jan 2025 08:17:09 +0000 (17:17 +0900)
Change-Id: I6972611ce1b22e2544c56813a3ab8857ba0eeafd

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp
automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp
dali-toolkit/devel-api/controls/video-view/video-view-devel.cpp
dali-toolkit/devel-api/controls/video-view/video-view-devel.h
dali-toolkit/internal/controls/camera-view/camera-view-impl.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.cpp
dali-toolkit/internal/controls/video-view/video-view-impl.h
dali-toolkit/internal/graphics/shaders/video-view-texture.vert

index 899c098126778eef653cfe68dc5200cc5f5baa23..b1cf96a060561de086300302eea43135fa0acdcc 100755 (executable)
@@ -139,6 +139,27 @@ public:
 
   }
 
+  void SetAutoRotationEnabled(bool enable)
+  {
+
+  }
+
+  bool IsAutoRotationEnabled() const
+  {
+    return false;
+  }
+
+  void SetLetterBoxEnabled(bool enable)
+  {
+
+  }
+
+  bool IsLetterBoxEnabled() const
+  {
+    return false;
+  }
+
+
 public:
 
   std::string mUrl;
@@ -385,5 +406,26 @@ void VideoPlayer::SceneDisconnection()
   Internal::Adaptor::GetImplementation( *this ).SceneDisconnection();
 }
 
+void VideoPlayer::SetAutoRotationEnabled(bool enable)
+{
+  Internal::Adaptor::GetImplementation( *this ).SetAutoRotationEnabled(enable);
+}
+
+bool VideoPlayer::IsAutoRotationEnabled() const
+{
+  return Internal::Adaptor::GetImplementation( *this ).IsAutoRotationEnabled();
+}
+
+void VideoPlayer::SetLetterBoxEnabled(bool enable)
+{
+  Internal::Adaptor::GetImplementation( *this ).SetLetterBoxEnabled(enable);
+}
+
+bool VideoPlayer::IsLetterBoxEnabled() const
+{
+  return Internal::Adaptor::GetImplementation( *this ).IsLetterBoxEnabled();
+}
+
+
 } // namespace Dali;
 
index 4dbea796f42a768d0f0b707ccdb99598def946fa..8704a65e19d705084ba38c2681b6ab58a53b313c 100644 (file)
@@ -900,3 +900,22 @@ int UtcDaliVideoViewSynchronizationForWindowRotation(void)
 
   END_TEST;
 }
+
+// For coverage
+int UtcDaliVideoViewDisplayModeForCoverage(void)
+{
+  ToolkitTestApplication application;
+
+  VideoView videoView = VideoView::New();
+  DALI_TEST_CHECK(videoView);
+
+  Toolkit::DevelVideoView::SetAutoRotationEnabled(videoView, true);
+  // A false return is correct because there is no plugin.
+  DALI_TEST_EQUALS(false, Toolkit::DevelVideoView::IsAutoRotationEnabled(videoView), TEST_LOCATION);
+
+  Toolkit::DevelVideoView::SetLetterBoxEnabled(videoView, true);
+  // A false return is correct because there is no plugin.
+  DALI_TEST_EQUALS(false, Toolkit::DevelVideoView::IsLetterBoxEnabled(videoView), TEST_LOCATION);
+
+  END_TEST;
+}
index f58501349ec8cfa798e764e6f38e80054e870c07..f5191978e1e7b4c7d5ddc3002f20b15bab71149b 100644 (file)
@@ -41,6 +41,26 @@ void PlayAnimation(VideoView videoView, Animation animation)
   Dali::Toolkit::GetImpl(videoView).PlayAnimation(animation);\r
 }\r
 \r
+void SetAutoRotationEnabled(VideoView videoView, bool enable)\r
+{\r
+  Dali::Toolkit::GetImpl(videoView).SetAutoRotationEnabled(enable);\r
+}\r
+\r
+bool IsAutoRotationEnabled(VideoView videoView)\r
+{\r
+return Dali::Toolkit::GetImpl(videoView).IsAutoRotationEnabled();\r
+}\r
+\r
+void SetLetterBoxEnabled(VideoView videoView, bool enable)\r
+{\r
+  Dali::Toolkit::GetImpl(videoView).SetLetterBoxEnabled(enable);\r
+}\r
+\r
+bool IsLetterBoxEnabled(VideoView videoView)\r
+{\r
+  return Dali::Toolkit::GetImpl(videoView).IsLetterBoxEnabled();\r
+}\r
+\r
 } // namespace DevelVideoView\r
 \r
 } // namespace Toolkit\r
index 73d7826f2392f4c8d8ed85260a5c30bee062faa8..c3543c80fade60f3ecde994442dc35cf694ab574 100644 (file)
@@ -60,6 +60,38 @@ DALI_TOOLKIT_API VideoView New(VideoSyncMode syncMode);
  */\r
 DALI_TOOLKIT_API void PlayAnimation(VideoView videoView, Animation animation);\r
 \r
+/**\r
+ * @brief Sets auto rotation feature. If enabled, video will rotate automatically according to the video orientation.\r
+ *\r
+ * @param[in] videoView The current VideoView\r
+ * @param[in] enable true if auto rotation should be enabled, false otherwise. Default value is false.\r
+ */\r
+DALI_TOOLKIT_API void SetAutoRotationEnabled(VideoView videoView, bool enable);\r
+\r
+/**\r
+ * @brief Checks whether auto rotation feature is enabled.\r
+ *\r
+ * @param[in] videoView The current VideoView\r
+ * @return true if auto rotation is enabled, false otherwise. Default value is false.\r
+ */\r
+DALI_TOOLKIT_API bool IsAutoRotationEnabled(VideoView videoView);\r
+\r
+/**\r
+ * @brief Sets letter box feature. If enabled, the video will play in the video player's aspect ratio.\r
+ *\r
+ * @param[in] videoView The current VideoView\r
+ * @param[in] enable true if letter box should be enabled, false otherwise. Default value is false.\r
+ */\r
+DALI_TOOLKIT_API void SetLetterBoxEnabled(VideoView videoView, bool enable);\r
+\r
+/**\r
+ * @brief Checks whether letter box feature is enabled.\r
+ *\r
+ * @param[in] videoView The current VideoView\r
+ * @return true if letter box is enabled, false otherwise. Default value is false.\r
+ */\r
+DALI_TOOLKIT_API bool IsLetterBoxEnabled(VideoView videoView);\r
+\r
 } // namespace DevelVideoView\r
 \r
 } // namespace Toolkit\r
index 1cc292d16e5de0766ba41fc7f27e72d907e66ec9..104b0ff0b9bc6a65d6050100a1b90e5f088e715d 100644 (file)
@@ -188,7 +188,12 @@ Dali::Shader CameraView::CreateShader(Dali::NativeImageSourcePtr nativeImageSour
 
   nativeImageSourcePtr->ApplyNativeFragmentShader(fragmentShader);
 
-  return Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "CAMERA_VIEW");
+  Dali::Shader shader = Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "CAMERA_VIEW");
+  // Initialize shader properties
+  shader.RegisterProperty("uRotationMatrix", Property::Value(Vector4(1.0f, 0.0f, 0.0f, 1.0f)));
+  shader.RegisterProperty("uSizeRatio", Property::Value(Vector2(0.0f, 0.0f)));
+
+  return shader;
 }
 
 } // namespace Internal
index 8524950acf3e834667d8b31c09cda8db5aab1ceb..068f67c29291b03e74d03b6c24e4263d7ec91202 100644 (file)
@@ -719,6 +719,7 @@ void VideoView::SetNativeImageTarget()
     textureSet.SetTexture(0u, mNativeTexture);
   }
   Self().AddRenderer(mTextureRenderer);
+  mTextureRenderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
 
   // Note VideoPlayer::SetRenderingTarget resets all the options. (e.g. url, mute, looping)
   mVideoPlayer.SetRenderingTarget(nativeImageSourcePtr);
@@ -903,7 +904,11 @@ Dali::Shader VideoView::CreateShader()
     DevelTexture::ApplyNativeFragmentShader(mNativeTexture, fragmentShader);
   }
 
-  return Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "VIDEO_VIEW");
+  Dali::Shader shader = Dali::Shader::New(vertexShader, fragmentShader, Shader::Hint::NONE, "VIDEO_VIEW");
+    // Initialize shader properties
+  shader.RegisterProperty("uRotationMatrix", Property::Value(Vector4(1.0f, 0.0f, 0.0f, 1.0f)));
+  shader.RegisterProperty("uSizeRatio", Property::Value(Vector2(0.0f, 0.0f)));
+  return shader;
 }
 
 bool VideoView::GetStringFromProperty(const Dali::Property::Value& value, std::string& output)
@@ -970,6 +975,27 @@ VideoPlayer VideoView::GetVideoPlayer()
   return mVideoPlayer;
 }
 
+void VideoView::SetAutoRotationEnabled(bool enable)
+{
+  mVideoPlayer.SetAutoRotationEnabled(enable);
+}
+
+bool VideoView::IsAutoRotationEnabled() const
+{
+  return mVideoPlayer.IsAutoRotationEnabled();
+}
+
+void VideoView::SetLetterBoxEnabled(bool enable)
+{
+  mVideoPlayer.SetLetterBoxEnabled(enable);
+}
+
+bool VideoView::IsLetterBoxEnabled() const
+{
+  return mVideoPlayer.IsLetterBoxEnabled();
+}
+
+
 } // namespace Internal
 
 } // namespace Toolkit
index c8b2a83ff22f55b16ef85cfb375ebaeb41aea355..707a6cbd907d59fc988c572d6d6e03f2b31d62a8 100644 (file)
@@ -278,6 +278,30 @@ public:
    */
   VideoPlayer GetVideoPlayer();
 
+  /**
+   * @brief Sets auto rotation feature. If enabled, video will rotate automatically according to the video orientation.
+   * @param[in] enable Whether to enable auto rotation feature. Default is false.
+   */
+  void SetAutoRotationEnabled(bool enable);
+
+  /**
+   * @brief Checks whether auto rotation feature is enabled.
+   * @return True if auto rotation feature is enabled. Default is false.
+   */
+  bool IsAutoRotationEnabled() const;
+
+  /**
+   * @brief Sets letter box feature. If enabled, the video will play in the video player's aspect ratio.
+   * @param[in] enable Whether to enable letter box feature. Default is false.
+   */
+  void SetLetterBoxEnabled(bool enable);
+
+  /**
+   * @brief Checks whether letter box feature is enabled.
+   * @return True if letter box feature is enabled. Default is false.
+   */
+  bool IsLetterBoxEnabled() const;
+
 private: // From Control
   /**
    * @copydoc Toolkit::Control::OnInitialize()
index 54934747949aaace766be1b55f23de7364359514..5d10ec27dde3cdd8492ec9e2fce8ce7fe1a494d4 100644 (file)
@@ -8,11 +8,26 @@ UNIFORM_BLOCK VertBlock
 {
   UNIFORM highp mat4 uMvpMatrix;
   UNIFORM highp vec3 uSize;
+  UNIFORM highp vec2 uSizeRatio;
+  UNIFORM highp mat2 uRotationMatrix;
 };
 OUTPUT mediump vec2 sTexCoordRect;
 
+highp vec2 getSize(highp vec2 size)
+{
+  if (size.x < 0.5 || size.y < 0.5)
+  {
+    return uSize.xy;
+  }
+  else
+  {
+    highp float ratio = min(uSize.x / size.x, uSize.y / size.y);
+    return vec2(size.xy * ratio);
+  }
+}
+
 void main()
 {
-  gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);
-  vTexCoord = aPosition + vec2(0.5);
+  gl_Position = uMvpMatrix * vec4(aPosition * getSize(uSizeRatio), 0.0, 1.0);
+  vTexCoord = aPosition * uRotationMatrix + vec2(0.5);
 }