Change common test application
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-application.cpp
index 5aa928e..0e640e7 100644 (file)
@@ -1,18 +1,19 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include "test-application.h"
 
@@ -23,12 +24,15 @@ namespace Dali
 TestApplication::TestApplication( size_t surfaceWidth,
                                   size_t surfaceHeight,
                                   float  horizontalDpi,
-                                  float  verticalDpi)
+                                  float  verticalDpi,
+                                  ResourcePolicy::DataRetention policy)
 : mCore( NULL ),
   mSurfaceWidth( surfaceWidth ),
   mSurfaceHeight( surfaceHeight ),
   mFrame( 0u ),
-  mDpi( horizontalDpi, verticalDpi )
+  mDpi( horizontalDpi, verticalDpi ),
+  mLastVSyncTime(0u),
+  mDataRetentionPolicy( policy )
 {
   Initialize();
 }
@@ -37,12 +41,15 @@ TestApplication::TestApplication( bool   initialize,
                                   size_t surfaceWidth,
                                   size_t surfaceHeight,
                                   float  horizontalDpi,
-                                  float  verticalDpi )
+                                  float  verticalDpi,
+                                  ResourcePolicy::DataRetention policy)
 : mCore( NULL ),
   mSurfaceWidth( surfaceWidth ),
   mSurfaceHeight( surfaceHeight ),
   mFrame( 0u ),
-  mDpi( horizontalDpi, verticalDpi )
+  mDpi( horizontalDpi, verticalDpi ),
+  mLastVSyncTime(0u),
+  mDataRetentionPolicy( policy )
 {
   if ( initialize )
   {
@@ -52,12 +59,18 @@ TestApplication::TestApplication( bool   initialize,
 
 void TestApplication::Initialize()
 {
-  mCore = Dali::Integration::Core::New(
-    mRenderController,
-    mPlatformAbstraction,
-    mGlAbstraction,
-    mGlSyncAbstraction,
-    mGestureManager );
+  // We always need the first update!
+  mStatus.keepUpdating = Integration::KeepUpdating::STAGE_KEEP_RENDERING;
+
+  mCore = Dali::Integration::Core::New( mRenderController,
+                                        mPlatformAbstraction,
+                                        mGlAbstraction,
+                                        mGlSyncAbstraction,
+                                        mGestureManager,
+                                        mDataRetentionPolicy,
+                                        Integration::RenderToFrameBuffer::FALSE,
+                                        Integration::DepthBufferAvailable::TRUE,
+                                        Integration::StencilBufferAvailable::TRUE );
 
   mCore->ContextCreated();
   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
@@ -65,6 +78,8 @@ void TestApplication::Initialize()
 
   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
   Dali::Integration::Log::InstallLogFunction(logFunction);
+
+  mCore->SceneCreated();
 }
 
 TestApplication::~TestApplication()
@@ -141,16 +156,34 @@ void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
 }
 
-bool TestApplication::Render( unsigned int intervalMilliseconds  )
+void TestApplication::SetTopMargin( unsigned int margin )
 {
-  // Update Time values
-  mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
-  unsigned int seconds(0u), microseconds(0u);
-  mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
+  mCore->SetTopMargin( margin );
+}
+
+void TestApplication::DoUpdate( unsigned int 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);
+  }
+
+  unsigned int nextVSyncTime = mLastVSyncTime + intervalMilliseconds;
+  float elapsedSeconds = intervalMilliseconds / 1e3f;
+
+  mCore->Update( elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false );
+
+  GetRenderController().Initialize();
+
+  mLastVSyncTime = nextVSyncTime;
+}
 
-  mCore->VSync( mFrame, seconds, microseconds );
-  mCore->Update( mStatus );
-  mCore->Render( mRenderStatus );
+bool TestApplication::Render( unsigned int intervalMilliseconds, const char* location )
+{
+  DoUpdate( intervalMilliseconds, location );
+  mCore->Render( mRenderStatus, false );
 
   mFrame++;
 
@@ -164,21 +197,19 @@ unsigned int TestApplication::GetUpdateStatus()
 
 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
 {
-  // Update Time values
-  mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
-  unsigned int seconds(0u), microseconds(0u);
-  mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
-
-  mCore->VSync( mFrame, seconds, microseconds );
-  mCore->Update( mStatus );
-
+  DoUpdate( intervalMilliseconds );
   return mStatus.KeepUpdating();
 }
 
+bool TestApplication::GetRenderNeedsUpdate()
+{
+  return mRenderStatus.NeedsUpdate();
+}
+
 bool TestApplication::RenderOnly( )
 {
   // Update Time values
-  mCore->Render( mRenderStatus );
+  mCore->Render( mRenderStatus, false );
 
   mFrame++;
 
@@ -187,9 +218,22 @@ bool TestApplication::RenderOnly( )
 
 void TestApplication::ResetContext()
 {
-  mCore->ContextToBeDestroyed();
+  mCore->ContextDestroyed();
+  mGlAbstraction.Initialize();
   mCore->ContextCreated();
 }
 
+unsigned int TestApplication::Wait( unsigned int durationToWait )
+{
+  int time = 0;
+
+  for(unsigned int i = 0; i <= ( durationToWait / RENDER_FRAME_INTERVAL); i++)
+  {
+    SendNotification();
+    Render(RENDER_FRAME_INTERVAL);
+    time += RENDER_FRAME_INTERVAL;
+  }
+  return time;
+}
 
 } // Namespace dali