Sync test-application
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-application.cpp
index 6636676..440270a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
 
 namespace Dali
 {
-
-
-TestApplication::TestApplication( size_t surfaceWidth,
-                                  size_t surfaceHeight,
-                                  float  horizontalDpi,
-                                  float  verticalDpi,
-                                  ResourcePolicy::DataRetention policy)
-: mCore( NULL ),
-  mSurfaceWidth( surfaceWidth ),
-  mSurfaceHeight( surfaceHeight ),
-  mFrame( 0u ),
-  mDpi( horizontalDpi, verticalDpi ),
-  mLastVSyncTime(0u),
-  mDataRetentionPolicy( policy )
-{
-  Initialize();
-}
-
-TestApplication::TestApplication( bool   initialize,
-                                  size_t surfaceWidth,
-                                  size_t surfaceHeight,
-                                  float  horizontalDpi,
-                                  float  verticalDpi,
-                                  ResourcePolicy::DataRetention policy)
-: mCore( NULL ),
-  mSurfaceWidth( surfaceWidth ),
-  mSurfaceHeight( surfaceHeight ),
-  mFrame( 0u ),
-  mDpi( horizontalDpi, verticalDpi ),
+const Rect<int> TestApplication::DEFAULT_SURFACE_RECT = Rect<int>(0, 0, TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT);
+
+bool TestApplication::mLoggingEnabled = true;
+
+TestApplication::TestApplication(uint32_t surfaceWidth,
+                                 uint32_t surfaceHeight,
+                                 uint32_t horizontalDpi,
+                                 uint32_t verticalDpi,
+                                 bool     initialize,
+                                 bool     enablePartialUpdate)
+: mCore(NULL),
+  mSurfaceWidth(surfaceWidth),
+  mSurfaceHeight(surfaceHeight),
+  mFrame(0u),
+  mDpi{horizontalDpi, verticalDpi},
   mLastVSyncTime(0u),
-  mDataRetentionPolicy( policy )
+  mPartialUpdateEnabled(enablePartialUpdate)
 {
-  if ( initialize )
+  if(initialize)
   {
     Initialize();
   }
@@ -59,25 +45,51 @@ TestApplication::TestApplication( bool   initialize,
 
 void TestApplication::Initialize()
 {
+  CreateCore();
+  CreateScene();
+  InitializeCore();
+}
+
+void TestApplication::CreateCore()
+{
   // We always need the first update!
   mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
 
-  mCore = Dali::Integration::Core::New(
-    mRenderController,
-    mPlatformAbstraction,
-    mGlAbstraction,
-    mGlSyncAbstraction,
-    mGestureManager,
-    mDataRetentionPolicy);
+  mCore = Dali::Integration::Core::New(mRenderController,
+                                       mPlatformAbstraction,
+                                       mGraphicsController,
+                                       Integration::RenderToFrameBuffer::FALSE,
+                                       Integration::DepthBufferAvailable::TRUE,
+                                       Integration::StencilBufferAvailable::TRUE,
+                                       mPartialUpdateEnabled ? Integration::PartialUpdateAvailable::TRUE : Integration::PartialUpdateAvailable::FALSE);
 
   mCore->ContextCreated();
-  mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
-  mCore->SetDpi( mDpi.x, mDpi.y );
 
   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
   Dali::Integration::Log::InstallLogFunction(logFunction);
 
+  Dali::Integration::Trace::LogContextFunction logContextFunction(&TestApplication::LogContext);
+  Dali::Integration::Trace::InstallLogContextFunction(logContextFunction);
+
+  Dali::Integration::Trace::LogContext(true, "Test");
+}
+
+void TestApplication::CreateScene()
+{
+  mScene = Dali::Integration::Scene::New(Size(static_cast<float>(mSurfaceWidth), static_cast<float>(mSurfaceHeight)));
+  mScene.SetDpi(Vector2(static_cast<float>(mDpi.x), static_cast<float>(mDpi.y)));
+
+  // Create render target for the scene
+  Graphics::RenderTargetCreateInfo rtInfo{};
+  rtInfo.SetExtent({mSurfaceWidth, mSurfaceHeight});
+  mRenderTarget = mGraphicsController.CreateRenderTarget(rtInfo, nullptr);
+  mScene.SetSurfaceRenderTarget(mRenderTarget.get());
+}
+
+void TestApplication::InitializeCore()
+{
   mCore->SceneCreated();
+  mCore->Initialize();
 }
 
 TestApplication::~TestApplication()
@@ -86,22 +98,37 @@ TestApplication::~TestApplication()
   delete mCore;
 }
 
+void TestApplication::LogContext(bool start, const char* tag)
+{
+  if(start)
+  {
+    fprintf(stderr, "INFO: Trace Start: %s\n", tag);
+  }
+  else
+  {
+    fprintf(stderr, "INFO: Trace End: %s\n", tag);
+  }
+}
+
 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
 {
-  switch(level)
+  if(mLoggingEnabled)
   {
-    case Dali::Integration::Log::DebugInfo:
-      fprintf(stderr, "INFO: %s", message.c_str());
-      break;
-    case Dali::Integration::Log::DebugWarning:
-      fprintf(stderr, "WARN: %s", message.c_str());
-      break;
-    case Dali::Integration::Log::DebugError:
-      fprintf(stderr, "ERROR: %s", message.c_str());
-      break;
-    default:
-      fprintf(stderr, "DEFAULT: %s", message.c_str());
-      break;
+    switch(level)
+    {
+      case Dali::Integration::Log::DebugInfo:
+        fprintf(stderr, "INFO: %s", message.c_str());
+        break;
+      case Dali::Integration::Log::DebugWarning:
+        fprintf(stderr, "WARN: %s", message.c_str());
+        break;
+      case Dali::Integration::Log::DebugError:
+        fprintf(stderr, "ERROR: %s", message.c_str());
+        break;
+      default:
+        fprintf(stderr, "DEFAULT: %s", message.c_str());
+        break;
+    }
   }
 }
 
@@ -120,19 +147,24 @@ TestRenderController& TestApplication::GetRenderController()
   return mRenderController;
 }
 
+TestGraphicsController& TestApplication::GetGraphicsController()
+{
+  return mGraphicsController;
+}
+
 TestGlAbstraction& TestApplication::GetGlAbstraction()
 {
-  return mGlAbstraction;
+  return static_cast<TestGlAbstraction&>(mGraphicsController.GetGlAbstraction());
 }
 
-TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
+TestGlContextHelperAbstraction& TestApplication::GetGlContextHelperAbstraction()
 {
-  return mGlSyncAbstraction;
+  return static_cast<TestGlContextHelperAbstraction&>(mGraphicsController.GetGlContextHelperAbstraction());
 }
 
-TestGestureManager& TestApplication::GetGestureManager()
+TestGraphicsSyncImplementation& TestApplication::GetGraphicsSyncImpl()
 {
-  return mGestureManager;
+  return static_cast<TestGraphicsSyncImplementation&>(mGraphicsController.GetGraphicsSyncImpl());
 }
 
 void TestApplication::ProcessEvent(const Integration::Event& event)
@@ -146,56 +178,72 @@ void TestApplication::SendNotification()
   mCore->ProcessEvents();
 }
 
-void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
+void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location)
 {
-  mSurfaceWidth = width;
-  mSurfaceHeight = height;
+  if(GetUpdateStatus() == 0 &&
+     mRenderStatus.NeedsUpdate() == false &&
+     !GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc))
+  {
+    fprintf(stderr, "WARNING - Update not required :%s\n", location == NULL ? "NULL" : location);
+  }
 
-  mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
-}
+  uint32_t nextVSyncTime  = mLastVSyncTime + intervalMilliseconds;
+  float    elapsedSeconds = static_cast<float>(intervalMilliseconds) * 0.001f;
 
-void TestApplication::SetTopMargin( unsigned int margin )
-{
-  mCore->SetTopMargin( margin );
+  mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false);
+
+  GetRenderController().Initialize();
+
+  mLastVSyncTime = nextVSyncTime;
 }
 
-void TestApplication::DoUpdate( unsigned int intervalMilliseconds, const char* location )
+bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location)
 {
-  if( GetUpdateStatus() == 0 &&
-      mRenderStatus.NeedsUpdate() == false &&
-      ! GetRenderController().WasCalled(TestRenderController::RequestUpdateFunc) )
-  {
-    fprintf(stderr, "WARNING - Update not required :%s\n", location==NULL?"NULL":location);
-  }
+  DoUpdate(intervalMilliseconds, location);
 
-  unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
-  float elapsedSeconds = intervalMilliseconds / 1e3f;
+  // Reset the status
+  mRenderStatus.SetNeedsUpdate(false);
+  mRenderStatus.SetNeedsPostRender(false);
 
-  mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus );
+  mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
+  mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
+  mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
+  mCore->PostRender(false /*do not skip rendering*/);
 
-  GetRenderController().Initialize();
+  mFrame++;
 
-  mLastVSyncTime = nextVSyncTime;
+  return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
 }
 
-bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
+bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector<Rect<int>>& damagedRects)
 {
-  DoUpdate( intervalMilliseconds, location );
-  mCore->Render( mRenderStatus );
+  DoUpdate(intervalMilliseconds, location);
+
+  mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
+  mCore->PreRender(mScene, damagedRects);
+
+  return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
+}
+
+bool TestApplication::RenderWithPartialUpdate(std::vector<Rect<int>>& damagedRects, Rect<int>& clippingRect)
+{
+  mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
+  mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect);
+  mCore->PostRender(false /*do not skip rendering*/);
 
   mFrame++;
 
   return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
 }
 
-unsigned int TestApplication::GetUpdateStatus()
+uint32_t TestApplication::GetUpdateStatus()
 {
   return mStatus.KeepUpdating();
 }
 
-bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
+bool TestApplication::UpdateOnly(uint32_t intervalMilliseconds)
 {
-  DoUpdate( intervalMilliseconds );
+  DoUpdate(intervalMilliseconds);
   return mStatus.KeepUpdating();
 }
 
@@ -204,10 +252,18 @@ bool TestApplication::GetRenderNeedsUpdate()
   return mRenderStatus.NeedsUpdate();
 }
 
-bool TestApplication::RenderOnly( )
+bool TestApplication::GetRenderNeedsPostRender()
+{
+  return mRenderStatus.NeedsPostRender();
+}
+
+bool TestApplication::RenderOnly()
 {
   // Update Time values
-  mCore->Render( mRenderStatus );
+  mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/);
+  mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/);
+  mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/);
+  mCore->PostRender(false /*do not skip rendering*/);
 
   mFrame++;
 
@@ -217,15 +273,15 @@ bool TestApplication::RenderOnly( )
 void TestApplication::ResetContext()
 {
   mCore->ContextDestroyed();
-  mGlAbstraction.Initialize();
+  mGraphicsController.Initialize();
   mCore->ContextCreated();
 }
 
-unsigned int TestApplication::Wait( unsigned int durationToWait )
+uint32_t TestApplication::Wait(uint32_t durationToWait)
 {
   int time = 0;
 
-  for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
+  for(uint32_t i = 0; i <= (durationToWait / RENDER_FRAME_INTERVAL); i++)
   {
     SendNotification();
     Render(RENDER_FRAME_INTERVAL);
@@ -234,4 +290,4 @@ unsigned int TestApplication::Wait( unsigned int durationToWait )
   return time;
 }
 
-} // Namespace dali
+} // namespace Dali