Added resourceReadySignal to image-scaling-irregular demo 04/132804/3
authorNick Holland <nick.holland@partner.samsung.com>
Wed, 7 Jun 2017 15:06:04 +0000 (16:06 +0100)
committerNick Holland <nick.holland@partner.samsung.com>
Fri, 16 Jun 2017 09:22:47 +0000 (09:22 +0000)
Demo now waits for first 10 Images to load before loading any
further images to speed up start up time.

Un-earths a bug in TextureObserver which causes a seg fault

Change-Id: Ia389bd3ca322be2dfb37170a5ea40af65dfc23f2

examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp

index 7edeec6..69f5931 100644 (file)
@@ -47,6 +47,7 @@
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <iostream>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
 
 // INTERNAL INCLUDES
 #include "grid-flags.h"
@@ -166,7 +167,7 @@ const char* IMAGE_PATHS[] = {
   NULL
 };
 const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u;
-
+const unsigned int INITIAL_IMAGES_TO_LOAD = 10;
 
 
 /**
@@ -260,7 +261,8 @@ public:
 
   ImageScalingIrregularGridController( Application& application )
   : mApplication( application ),
-    mScrolling( false )
+    mScrolling( false ),
+    mImagesLoaded( 0 )
   {
     std::cout << "ImageScalingIrregularGridController::ImageScalingIrregularGridController" << std::endl;
 
@@ -274,6 +276,21 @@ public:
   }
 
   /**
+   * Called everytime an ImageView has loaded it's image
+   */
+  void ResourceReadySignal( Toolkit::Control control )
+  {
+    mImagesLoaded++;
+    // To allow fast startup, we only place a small number of ImageViews on stage first
+    if ( mImagesLoaded == INITIAL_IMAGES_TO_LOAD )
+    {
+      // Adding the ImageViews to the stage will trigger loading of the Images
+      mGridActor.Add( mOffStageImageViews );
+    }
+  }
+
+
+  /**
    * One-time setup in response to Application InitSignal.
    */
   void Create( Application& application )
@@ -306,6 +323,11 @@ public:
 
     SetTitle( APPLICATION_TITLE );
 
+    mOffStageImageViews = Actor::New();
+    mOffStageImageViews.SetAnchorPoint( AnchorPoint::CENTER );
+    mOffStageImageViews.SetParentOrigin(ParentOrigin::CENTER);
+    mOffStageImageViews.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+
     // Build the main content of the widow:
     PopulateContentLayer( DEFAULT_SCALING_MODE );
   }
@@ -442,8 +464,9 @@ public:
     outFieldHeight = actualGridHeight * cellHeight;
     const Vector2 gridOrigin = Vector2( -fieldWidth * 0.5f, -outFieldHeight * 0.5 );
 
+     unsigned int count = 0;
     // Build the image actors in their right locations in their parent's frame:
-    for( std::vector<PositionedImage>::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i )
+    for( std::vector<PositionedImage>::const_iterator i = placedImages.begin(), end = placedImages.end(); i != end; ++i, ++count )
     {
       const PositionedImage& imageSource = *i;
       const Vector2 imageSize = imageSource.imageGridDims * cellSize - Vector2( GRID_CELL_PADDING * 2, GRID_CELL_PADDING * 2 );
@@ -454,11 +477,20 @@ public:
       image.SetPosition( Vector3( imagePosition.x, imagePosition.y, 0 ) );
       image.SetSize( imageSize );
       image.TouchSignal().Connect( this, &ImageScalingIrregularGridController::OnTouchImage );
+      Toolkit::DevelControl::ResourceReadySignal( image).Connect( this, &ImageScalingIrregularGridController::ResourceReadySignal);
       mFittingModes[image.GetId()] = fittingMode;
       mResourceUrls[image.GetId()] = imageSource.configuration.path;
       mSizes[image.GetId()] = imageSize;
-
-      gridActor.Add( image );
+      if ( count < INITIAL_IMAGES_TO_LOAD )
+      {
+        gridActor.Add( image );
+      }
+      else
+      {
+        // Store the ImageView in an offstage actor until the inital batch of ImageViews have finished loading their images
+        // Required
+        mOffStageImageViews.Add( image );
+      }
     }
 
     return gridActor;
@@ -601,6 +633,7 @@ private:
   Toolkit::ToolBar mToolBar;          ///< The View's Toolbar.
   TextLabel mTitleActor;               ///< The Toolbar's Title.
   Actor mGridActor;                   ///< The container for the grid of images
+  Actor mOffStageImageViews;          ///< ImageViews held off stage until the inital batch have loaded their images
   ScrollView mScrollView;             ///< ScrollView UI Component
   ScrollBar mScrollBarVertical;
   ScrollBar mScrollBarHorizontal;
@@ -608,6 +641,7 @@ private:
   std::map<unsigned, Dali::FittingMode::Type> mFittingModes; ///< Stores the current scaling mode of each image, keyed by image actor id.
   std::map<unsigned, std::string> mResourceUrls; ///< Stores the url of each image, keyed by image actor id.
   std::map<unsigned, Vector2> mSizes; ///< Stores the current size of each image, keyed by image actor id.
+  unsigned int mImagesLoaded;         ///< How many images have been loaded
 };
 
 void RunTest( Application& application )