From 5a561921702352971379838bacfe91e3422c46f4 Mon Sep 17 00:00:00 2001 From: "joogab.yun" Date: Thu, 9 Jan 2025 16:42:43 +0900 Subject: [PATCH] Add AutoRotation, LetterBox Change-Id: I6972611ce1b22e2544c56813a3ab8857ba0eeafd --- .../toolkit-video-player.cpp | 42 +++++++++++++++++++ .../src/dali-toolkit/utc-Dali-VideoView.cpp | 19 +++++++++ .../controls/video-view/video-view-devel.cpp | 20 +++++++++ .../controls/video-view/video-view-devel.h | 32 ++++++++++++++ .../controls/camera-view/camera-view-impl.cpp | 7 +++- .../controls/video-view/video-view-impl.cpp | 28 ++++++++++++- .../controls/video-view/video-view-impl.h | 24 +++++++++++ .../graphics/shaders/video-view-texture.vert | 19 ++++++++- 8 files changed, 187 insertions(+), 4 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp index 899c098126..b1cf96a060 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-video-player.cpp @@ -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; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp index 4dbea796f4..8704a65e19 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VideoView.cpp @@ -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; +} diff --git a/dali-toolkit/devel-api/controls/video-view/video-view-devel.cpp b/dali-toolkit/devel-api/controls/video-view/video-view-devel.cpp index f58501349e..f5191978e1 100644 --- a/dali-toolkit/devel-api/controls/video-view/video-view-devel.cpp +++ b/dali-toolkit/devel-api/controls/video-view/video-view-devel.cpp @@ -41,6 +41,26 @@ void PlayAnimation(VideoView videoView, Animation animation) Dali::Toolkit::GetImpl(videoView).PlayAnimation(animation); } +void SetAutoRotationEnabled(VideoView videoView, bool enable) +{ + Dali::Toolkit::GetImpl(videoView).SetAutoRotationEnabled(enable); +} + +bool IsAutoRotationEnabled(VideoView videoView) +{ +return Dali::Toolkit::GetImpl(videoView).IsAutoRotationEnabled(); +} + +void SetLetterBoxEnabled(VideoView videoView, bool enable) +{ + Dali::Toolkit::GetImpl(videoView).SetLetterBoxEnabled(enable); +} + +bool IsLetterBoxEnabled(VideoView videoView) +{ + return Dali::Toolkit::GetImpl(videoView).IsLetterBoxEnabled(); +} + } // namespace DevelVideoView } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/video-view/video-view-devel.h b/dali-toolkit/devel-api/controls/video-view/video-view-devel.h index 73d7826f23..c3543c80fa 100644 --- a/dali-toolkit/devel-api/controls/video-view/video-view-devel.h +++ b/dali-toolkit/devel-api/controls/video-view/video-view-devel.h @@ -60,6 +60,38 @@ DALI_TOOLKIT_API VideoView New(VideoSyncMode syncMode); */ DALI_TOOLKIT_API void PlayAnimation(VideoView videoView, Animation animation); +/** + * @brief Sets auto rotation feature. If enabled, video will rotate automatically according to the video orientation. + * + * @param[in] videoView The current VideoView + * @param[in] enable true if auto rotation should be enabled, false otherwise. Default value is false. + */ +DALI_TOOLKIT_API void SetAutoRotationEnabled(VideoView videoView, bool enable); + +/** + * @brief Checks whether auto rotation feature is enabled. + * + * @param[in] videoView The current VideoView + * @return true if auto rotation is enabled, false otherwise. Default value is false. + */ +DALI_TOOLKIT_API bool IsAutoRotationEnabled(VideoView videoView); + +/** + * @brief Sets letter box feature. If enabled, the video will play in the video player's aspect ratio. + * + * @param[in] videoView The current VideoView + * @param[in] enable true if letter box should be enabled, false otherwise. Default value is false. + */ +DALI_TOOLKIT_API void SetLetterBoxEnabled(VideoView videoView, bool enable); + +/** + * @brief Checks whether letter box feature is enabled. + * + * @param[in] videoView The current VideoView + * @return true if letter box is enabled, false otherwise. Default value is false. + */ +DALI_TOOLKIT_API bool IsLetterBoxEnabled(VideoView videoView); + } // namespace DevelVideoView } // namespace Toolkit diff --git a/dali-toolkit/internal/controls/camera-view/camera-view-impl.cpp b/dali-toolkit/internal/controls/camera-view/camera-view-impl.cpp index 1cc292d16e..104b0ff0b9 100644 --- a/dali-toolkit/internal/controls/camera-view/camera-view-impl.cpp +++ b/dali-toolkit/internal/controls/camera-view/camera-view-impl.cpp @@ -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 diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp index 8524950acf..068f67c292 100644 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.cpp +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.cpp @@ -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 diff --git a/dali-toolkit/internal/controls/video-view/video-view-impl.h b/dali-toolkit/internal/controls/video-view/video-view-impl.h index c8b2a83ff2..707a6cbd90 100644 --- a/dali-toolkit/internal/controls/video-view/video-view-impl.h +++ b/dali-toolkit/internal/controls/video-view/video-view-impl.h @@ -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() diff --git a/dali-toolkit/internal/graphics/shaders/video-view-texture.vert b/dali-toolkit/internal/graphics/shaders/video-view-texture.vert index 5493474794..5d10ec27dd 100644 --- a/dali-toolkit/internal/graphics/shaders/video-view-texture.vert +++ b/dali-toolkit/internal/graphics/shaders/video-view-texture.vert @@ -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); } -- 2.34.1