Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-demo.git] / examples / homescreen-benchmark / homescreen-benchmark.cpp
index e5925b8..c32aaf7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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.
@@ -22,8 +22,6 @@
 #include <iostream>
 
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
-#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
-#include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 
 using namespace Dali;
 using Dali::Toolkit::TextLabel;
@@ -49,7 +47,6 @@ const float DEFAULT_OPT_ROW_COUNT           ( 5 );
 const float DEFAULT_OPT_COL_COUNT           ( 4 );
 const float DEFAULT_OPT_PAGE_COUNT          ( 10 );
 const bool  DEFAULT_OPT_USE_TABLEVIEW       ( true );
-const bool  DEFAULT_OPT_BATCHING_ENABLED    ( true );
 const bool  DEFAULT_OPT_ICON_LABELS         ( true );
 const IconType  DEFAULT_OPT_ICON_TYPE       ( IMAGEVIEW );
 const bool  DEFAULT_OPT_USE_TEXT_LABEL      ( false );
@@ -116,7 +113,6 @@ public:
       mCols( DEFAULT_OPT_COL_COUNT ),
       mPageCount( DEFAULT_OPT_PAGE_COUNT ),
       mTableViewEnabled( DEFAULT_OPT_USE_TABLEVIEW ),
-      mBatchingEnabled( DEFAULT_OPT_BATCHING_ENABLED ),
       mIconLabelsEnabled( DEFAULT_OPT_ICON_LABELS ),
       mIconType( DEFAULT_OPT_ICON_TYPE ),
       mUseTextLabel( DEFAULT_OPT_USE_TEXT_LABEL )
@@ -127,7 +123,6 @@ public:
     int  mCols;
     int  mPageCount;
     bool mTableViewEnabled;
-    bool mBatchingEnabled;
     bool mIconLabelsEnabled;
     IconType mIconType;
     bool mUseTextLabel;
@@ -189,6 +184,9 @@ public:
 
     // Respond to a click anywhere on the stage.
     stage.GetRootLayer().TouchSignal().Connect( this, &HomescreenBenchmark::OnTouch );
+
+    // Respond to key events
+    stage.KeyEventSignal().Connect( this, &HomescreenBenchmark::OnKeyEvent );
   }
 
   bool OnTouch( Actor actor, const TouchData& touch )
@@ -201,22 +199,18 @@ public:
   Actor AddPage()
   {
     // Create root page actor.
-    Actor pageActor;
+    Toolkit::Control pageActor;
 
     if( mConfig.mTableViewEnabled )
     {
-      Toolkit::TableView tableView = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols );
-
-      // Create geometry batcher for table view.
-      tableView.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
-      pageActor = tableView;
+      pageActor = Toolkit::TableView::New( mConfig.mRows, mConfig.mCols );
     }
     else
     {
       pageActor = Toolkit::Control::New();
-      pageActor.SetProperty( Toolkit::Control::Property::BACKGROUND_COLOR, Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
     }
 
+    pageActor.SetBackgroundColor( Vector4( 0.0f, 0.0f, 0.0f, 0.5f ) );
     pageActor.SetParentOrigin( ParentOrigin::CENTER );
     pageActor.SetAnchorPoint( AnchorPoint::CENTER );
     pageActor.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
@@ -235,9 +229,6 @@ public:
     imagePath << IMAGE_PATH_PREFIX << currentIconIndex << IMAGE_PATH_POSTFIX;
     map[ Dali::Toolkit::ImageVisual::Property::URL ] = imagePath.str();
 
-    // Enable/disable batching
-    map[ Toolkit::ImageVisual::Property::BATCHING_ENABLED ] = mConfig.mBatchingEnabled;
-
     imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
     imageView.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::ALL_DIMENSIONS );
     imageView.SetSizeScalePolicy( SizeScalePolicy::FIT_WITH_ASPECT_RATIO );
@@ -329,7 +320,7 @@ public:
           else
           {
             Property::Map map;
-            map.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT ).
+            map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT ).
               Add( Toolkit::TextVisual::Property::TEXT, DEMO_APPS_NAMES[currentIconIndex] ).
               Add( Toolkit::TextVisual::Property::TEXT_COLOR, Color::WHITE ).
               Add( Toolkit::TextVisual::Property::POINT_SIZE, ( ( static_cast<float>( ROW_HEIGHT * LABEL_AREA ) * 72.0f )  / dpi.y ) * 0.25f ).
@@ -396,11 +387,6 @@ public:
       page.SetAnchorPoint( AnchorPoint::CENTER );
       page.SetPosition( Vector3( stageSize.x * i, 0.0f, 0.0f ) );
       mScrollParent.Add( page );
-
-      if( mConfig.mTableViewEnabled && mConfig.mBatchingEnabled )
-      {
-        page.SetProperty( DevelActor::Property::BATCH_PARENT, true );
-      }
     }
 
     mScrollParent.SetOpacity( 1.0f );
@@ -455,6 +441,17 @@ public:
     }
   }
 
+  void OnKeyEvent( const KeyEvent& event )
+  {
+    if( event.state == KeyEvent::Down )
+    {
+      if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
 
   Application&                mApplication;
@@ -467,27 +464,6 @@ private:
   int                         mCurrentPage;
 };
 
-void RunTest( Application& application, const HomescreenBenchmark::Config& config, bool printHelpAndExit )
-{
-  HomescreenBenchmark test( application, config );
-
-  if( printHelpAndExit )
-  {
-    PrintHelp( "c<num>",               " Number of columns" );
-    PrintHelp( "r<num>",               " Number of rows" );
-    PrintHelp( "p<num>",               " Number of pages ( must be greater than 1 )" );
-    PrintHelp( "-disable-tableview",   " Disables the use of TableView for layouting (must be enabled for batching)" );
-    PrintHelp( "-disable-batching",    " Disables geometry batching" );
-    PrintHelp( "-disable-icon-labels", " Disables labels for each icon" );
-    PrintHelp( "-use-checkbox",        " Uses checkboxes for icons" );
-    PrintHelp( "-use-text-label",      " Uses TextLabel instead of a TextVisual" );
-    return;
-  }
-
-  application.MainLoop();
-}
-
-// Entry point for Linux & Tizen applications.
 int DALI_EXPORT_API main( int argc, char **argv )
 {
   // Default settings.
@@ -514,10 +490,6 @@ int DALI_EXPORT_API main( int argc, char **argv )
     {
       config.mTableViewEnabled = false;
     }
-    else if( arg.compare( "--disable-batching" ) == 0 )
-    {
-      config.mBatchingEnabled = false;
-    }
     else if( arg.compare( "--disable-icon-labels" ) == 0 )
     {
       config.mIconLabelsEnabled = false;
@@ -537,8 +509,21 @@ int DALI_EXPORT_API main( int argc, char **argv )
   }
 
   Application application = Application::New( &argc, &argv );
+  HomescreenBenchmark test( application, config );
 
-  RunTest( application, config, printHelpAndExit );
+  if( printHelpAndExit )
+  {
+    PrintHelp( "c<num>",               " Number of columns" );
+    PrintHelp( "r<num>",               " Number of rows" );
+    PrintHelp( "p<num>",               " Number of pages ( must be greater than 1 )" );
+    PrintHelp( "-disable-tableview",   " Disables the use of TableView for layouting" );
+    PrintHelp( "-disable-icon-labels", " Disables labels for each icon" );
+    PrintHelp( "-use-checkbox",        " Uses checkboxes for icons" );
+    PrintHelp( "-use-text-label",      " Uses TextLabel instead of a TextVisual" );
+    return 0;
+  }
+
+  application.MainLoop();
 
   return 0;
 }