From: Paul Wisbey Date: Fri, 26 Jul 2019 14:26:41 +0000 (+0100) Subject: Fixed viewport issue when changing window size X-Git-Tag: dali_1.4.31~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F87%2F210987%2F6;p=platform%2Fcore%2Fuifw%2Fdali-core.git Fixed viewport issue when changing window size Note - this is necessary when using toolkit controls that create render-tasks: blur views, page-turn-view etc. Change-Id: Ia4d5f54b722d154a59620c38d6f7eae9fbf460eb --- diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h index 6572dbc..3fae461 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h @@ -1436,6 +1436,10 @@ public: inline void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) { + std::string commaString(", "); + std::string params( std::to_string(x) + commaString + std::to_string(y) + commaString + std::to_string(width) + commaString + std::to_string(height) ); + + mViewportTrace.PushCall("Viewport", params); } /* OpenGL ES 3.0 */ @@ -1974,6 +1978,11 @@ public: // TEST FUNCTIONS inline void ResetSetUniformCallStack() { mSetUniformTrace.Reset(); } inline TraceCallStack& GetSetUniformTrace() { return mSetUniformTrace; } + //Methods for Viewport verification + inline void EnableViewportCallTrace(bool enable) { mViewportTrace.Enable(enable); } + inline void ResetViewportCallStack() { mViewportTrace.Reset(); } + inline TraceCallStack& GetViewportTrace() { return mViewportTrace; } + template inline bool GetUniformValue( const char* name, T& value ) const { @@ -2209,6 +2218,7 @@ private: TraceCallStack mStencilFunctionTrace; TraceCallStack mScissorTrace; TraceCallStack mSetUniformTrace; + TraceCallStack mViewportTrace; // Shaders & Uniforms GLuint mLastShaderIdUsed; diff --git a/automated-tests/src/dali/utc-Dali-Scene.cpp b/automated-tests/src/dali/utc-Dali-Scene.cpp index 6e44ca7..b914478 100644 --- a/automated-tests/src/dali/utc-Dali-Scene.cpp +++ b/automated-tests/src/dali/utc-Dali-Scene.cpp @@ -25,6 +25,7 @@ #include #include +#include // Internal headers are allowed here @@ -945,6 +946,138 @@ int UtcDaliSceneSurfaceResizedDefaultScene(void) END_TEST; } +int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void) +{ + tet_infoline( "Ensure resizing of the surface & viewport is handled properly" ); + + TestApplication application; + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& callStack = glAbstraction.GetViewportTrace(); + glAbstraction.EnableViewportCallTrace( true ); + + // Initial scene setup + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.AddRenderer(renderer); + actor.SetSize(400, 400); + Stage::GetCurrent().Add(actor); + + // Render before resizing surface + application.SendNotification(); + application.Render(0); + glAbstraction.ResetViewportCallStack(); + + auto defaultScene = application.GetScene(); + Integration::RenderSurface* defaultSurface = defaultScene.GetSurface(); + DALI_TEST_CHECK( defaultSurface ); + + // Ensure stage size matches the surface size + auto stage = Stage::GetCurrent(); + DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION ); + + // Resize the surface and inform the scene accordingly + Vector2 newSize( 1000.0f, 2000.0f ); + std::string viewportParams( "0, 0, 1000, 2000" ); // to match newSize + DALI_TEST_CHECK( stage.GetSize() != newSize ); + defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) ); + defaultScene.SurfaceResized(); + + DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION ); + DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION ); + + // Render after resizing surface + application.SendNotification(); + application.Render(0); + + // Check that the viewport is handled properly + DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) ); + + END_TEST; +} + +int UtcDaliSceneSurfaceResizedMultipleRenderTasks(void) +{ + tet_infoline( "Ensure resizing of the surface & viewport is handled properly" ); + + TestApplication application; + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& callStack = glAbstraction.GetViewportTrace(); + glAbstraction.EnableViewportCallTrace( true ); + + // Initial scene setup + auto stage = Stage::GetCurrent(); + + Geometry geometry = CreateQuadGeometry(); + Shader shader = CreateShader(); + Renderer renderer = Renderer::New( geometry, shader ); + + Actor actor = Actor::New(); + actor.AddRenderer(renderer); + int testWidth = 400; + int testHeight = 400; + actor.SetSize(testWidth, testHeight); + stage.Add(actor); + + CameraActor offscreenCameraActor = CameraActor::New( Size( testWidth, testHeight ) ); + Stage::GetCurrent().Add( offscreenCameraActor ); + + FrameBuffer newFrameBuffer = FrameBuffer::New( testWidth, testHeight, FrameBuffer::Attachment::NONE ); + + RenderTask newTask = stage.GetRenderTaskList().CreateTask(); + newTask.SetCameraActor( offscreenCameraActor ); + newTask.SetSourceActor( actor ); + newTask.SetFrameBuffer( newFrameBuffer ); + newTask.SetViewportPosition( Vector2(0, 0) ); + newTask.SetViewportSize( Vector2(testWidth, testHeight) ); + + // Render before resizing surface + application.SendNotification(); + application.Render(0); + glAbstraction.ResetViewportCallStack(); + + Rect initialViewport = newTask.GetViewport(); + int initialWidth = initialViewport.width; + int initialHeight = initialViewport.height; + DALI_TEST_EQUALS( initialWidth, testWidth, TEST_LOCATION ); + DALI_TEST_EQUALS( initialHeight, testHeight, TEST_LOCATION ); + + auto defaultScene = application.GetScene(); + Integration::RenderSurface* defaultSurface = defaultScene.GetSurface(); + DALI_TEST_CHECK( defaultSurface ); + + // Ensure stage size matches the surface size + DALI_TEST_EQUALS( stage.GetSize(), Vector2( defaultSurface->GetPositionSize().width, defaultSurface->GetPositionSize().height ), TEST_LOCATION ); + + // Resize the surface and inform the scene accordingly + Vector2 newSize( 800.0f, 480.0f ); + std::string viewportParams( "0, 0, 800, 480" ); // to match newSize + DALI_TEST_CHECK( stage.GetSize() != newSize ); + defaultSurface->MoveResize( PositionSize( 0, 0, newSize.width, newSize.height ) ); + defaultScene.SurfaceResized(); + + DALI_TEST_EQUALS( stage.GetSize(), newSize, TEST_LOCATION ); + DALI_TEST_EQUALS( defaultScene.GetSize(), newSize, TEST_LOCATION ); + + // Render after resizing surface + application.SendNotification(); + application.Render(0); + + // Check that the viewport is handled properly + DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("Viewport", viewportParams ) ); + + // Second render-task should not be affected + Rect viewport = newTask.GetViewport(); + int width = viewport.width; + int height = viewport.height; + DALI_TEST_EQUALS( width, testWidth, TEST_LOCATION ); + DALI_TEST_EQUALS( height, testHeight, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliSceneSurfaceResizedAdditionalScene(void) { tet_infoline( "Ensure resizing of the surface is handled properly on additional scenes" ); diff --git a/dali/internal/event/common/scene-impl.cpp b/dali/internal/event/common/scene-impl.cpp index 6055dc6..a4c65c5 100644 --- a/dali/internal/event/common/scene-impl.cpp +++ b/dali/internal/event/common/scene-impl.cpp @@ -225,7 +225,7 @@ void Scene::SurfaceResized() if( ( fabsf( mSize.width - fWidth ) > Math::MACHINE_EPSILON_1 ) || ( fabsf( mSize.height - fHeight ) > Math::MACHINE_EPSILON_1 ) ) { - Rect< int32_t > newSize( 0, 0, static_cast< int32_t >( surfacePositionSize.width ), static_cast< int32_t >( surfacePositionSize.height ) ); + Rect< int32_t > newSize( 0, 0, static_cast< int32_t >( surfacePositionSize.width ), static_cast< int32_t >( surfacePositionSize.height ) ); // truncated mSize.width = fWidth; mSize.height = fHeight; @@ -237,19 +237,11 @@ void Scene::SurfaceResized() ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal(); SceneGraph::UpdateManager& updateManager = tls->GetUpdateManager(); - SetDefaultSurfaceRectMessage( updateManager, newSize ); // truncated + SetDefaultSurfaceRectMessage( updateManager, newSize ); + // set default render-task viewport parameters RenderTaskPtr defaultRenderTask = mRenderTaskList->GetTask( 0u ); - - // if single render task to screen then set its viewport parameters - if( 1 == mRenderTaskList->GetTaskCount() ) - { - if( !defaultRenderTask->GetTargetFrameBuffer() ) - { - defaultRenderTask->SetViewport( newSize ); // truncated - } - } - + defaultRenderTask->SetViewport( newSize ); defaultRenderTask->GetFrameBuffer()->SetSize( static_cast( newSize.width ), static_cast( newSize.height ) ); } }