Optimize HitTestWithinLayer (20% faster HitTest).
authorArtem Dergachev <dergachev.a@samsung.com>
Thu, 17 Apr 2014 14:29:41 +0000 (18:29 +0400)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 15 May 2014 11:38:49 +0000 (12:38 +0100)
Whenever a temporary HitActor structure instance is created, constructor and destructor functions
are called for its .actor field.

In certain scenarios this results in creating and instantly deleting around 1000 dummy Actor
objects during a single call of HitTest().

HitTestWithinLayer is an important bottleneck in such scenarios, second only to
UpdateNodesAndAttachments (depending on the touchevent:framerate ratio).

This change makes the test around 20% faster and additionally reduces power consumption.

Change-Id: Iad9f59f39f6229516f036cc49025c2e0ef72ad3d

dali/internal/event/events/hit-test-algorithm-impl.cpp

index 5077f70..7ebf256 100644 (file)
@@ -48,7 +48,8 @@ namespace
 struct HitActor
 {
   HitActor()
-  : x( 0 ),
+  : actor( NULL ),
+    x( 0 ),
     y( 0 ),
     distance( std::numeric_limits<float>::max() ),
     overlay( false )
@@ -56,7 +57,7 @@ struct HitActor
 
   }
 
-  Dali::Actor actor;                    ///< the actor hit. (if actor hit, then initialised)
+  Actor *actor;                         ///< the actor hit. (if actor hit, then initialised)
   float x;                              ///< x position of hit (only valid if actor valid)
   float y;                              ///< y position of hit (only valid if actor valid)
   float distance;                       ///< distance from ray origin to hit actor
@@ -159,7 +160,7 @@ HitActor HitTestWithinLayer( Actor& actor,
           }
           else
           {
-            hit.actor = Dali::Actor(&actor);
+            hit.actor = &actor;
             hit.x = hitPointLocal.x;
             hit.y = hitPointLocal.y;
             hit.distance = distance;
@@ -370,7 +371,7 @@ bool HitTestRenderTask( LayerList& layers,
         if ( hit.actor )
         {
           results.renderTask = Dali::RenderTask(&renderTask);
-          results.actor = hit.actor;
+          results.actor = Dali::Actor(hit.actor);
           results.actorCoordinates.x = hit.x;
           results.actorCoordinates.y = hit.y;
           return true; // Success