Fixed viewport issue when changing window size 87/210987/6
authorPaul Wisbey <p.wisbey@samsung.com>
Fri, 26 Jul 2019 14:26:41 +0000 (15:26 +0100)
committerPaul Wisbey <p.wisbey@samsung.com>
Tue, 30 Jul 2019 09:08:13 +0000 (10:08 +0100)
Note - this is necessary when using toolkit controls
that create render-tasks: blur views, page-turn-view etc.

Change-Id: Ia4d5f54b722d154a59620c38d6f7eae9fbf460eb

automated-tests/src/dali/dali-test-suite-utils/test-gl-abstraction.h
automated-tests/src/dali/utc-Dali-Scene.cpp
dali/internal/event/common/scene-impl.cpp

index 6572dbc..3fae461 100644 (file)
@@ -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 <typename T>
   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;
index 6e44ca7..b914478 100644 (file)
@@ -25,6 +25,7 @@
 #include <dali/integration-api/events/wheel-event-integ.h>
 
 #include <dali-test-suite-utils.h>
+#include <mesh-builder.h>
 
 // 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<int32_t> 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<int32_t> 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" );
index 6055dc6..a4c65c5 100644 (file)
@@ -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<uint32_t>( newSize.width ), static_cast<uint32_t>( newSize.height ) );
     }
   }