Merge "Clean up the code to build successfully on macOS" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / events / hit-test-algorithm-impl.cpp
index f685837..25d6a42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -28,7 +28,7 @@
 #include <dali/internal/event/actors/layer-impl.h>
 #include <dali/internal/event/actors/layer-list.h>
 #include <dali/internal/event/common/projection.h>
-#include <dali/internal/event/images/frame-buffer-image-impl.h>
+#include <dali/internal/event/events/ray-test.h>
 #include <dali/internal/event/render-tasks/render-task-impl.h>
 #include <dali/internal/event/render-tasks/render-task-list-impl.h>
 
@@ -47,7 +47,7 @@ namespace
 struct HitActor
 {
   HitActor()
-  : actor( NULL ),
+  : actor( nullptr ),
     distance( std::numeric_limits<float>::max() ),
     depth( std::numeric_limits<int>::min() )
   {
@@ -74,17 +74,17 @@ struct HitTestFunctionWrapper : public HitTestInterface
   {
   }
 
-  virtual bool IsActorHittable( Actor* actor )
+  bool IsActorHittable( Actor* actor ) override
   {
     return mFunc( Dali::Actor( actor ), Dali::HitTestAlgorithm::CHECK_ACTOR );
   }
 
-  virtual bool DescendActorHierarchy( Actor* actor )
+  bool DescendActorHierarchy( Actor* actor ) override
   {
     return mFunc( Dali::Actor( actor ), Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE );
   }
 
-  virtual bool DoesLayerConsumeHit( Layer* layer )
+  bool DoesLayerConsumeHit( Layer* layer ) override
   {
     // Layer::IsTouchConsumed() focuses on touch only. Here we are a wrapper for the public-api
     // where the caller may want to check for something completely different.
@@ -101,19 +101,19 @@ struct HitTestFunctionWrapper : public HitTestInterface
  */
 struct ActorTouchableCheck : public HitTestInterface
 {
-  virtual bool IsActorHittable( Actor* actor )
+  bool IsActorHittable( Actor* actor ) override
   {
     return actor->GetTouchRequired() && // Does the Application or derived actor type require a touch event?
            actor->IsHittable();         // Is actor sensitive, visible and on the scene?
   }
 
-  virtual bool DescendActorHierarchy( Actor* actor )
+  bool DescendActorHierarchy( Actor* actor ) override
   {
     return actor->IsVisible() && // Actor is visible, if not visible then none of its children are visible.
            actor->IsSensitive(); // Actor is sensitive, if insensitive none of its children should be hittable either.
   }
 
-  virtual bool DoesLayerConsumeHit( Layer* layer )
+  bool DoesLayerConsumeHit( Layer* layer ) override
   {
     return layer->IsTouchConsumed();
   }
@@ -160,7 +160,8 @@ HitActor HitTestWithinLayer( Actor& actor,
                              bool& overlayHit,
                              bool layerIs3d,
                              uint32_t clippingDepth,
-                             uint32_t clippingBitPlaneMask )
+                             uint32_t clippingBitPlaneMask,
+                             const RayTest& rayTest )
 {
   HitActor hit;
 
@@ -187,13 +188,13 @@ HitActor HitTestWithinLayer( Actor& actor,
 
     // Ensure the actor has a valid size.
     // If so, perform a quick ray sphere test to see if our ray is close to the actor.
-    if( size.x > 0.0f && size.y > 0.0f && actor.RaySphereTest( rayOrigin, rayDir ) )
+    if( size.x > 0.0f && size.y > 0.0f && rayTest.SphereTest( actor, rayOrigin, rayDir ) )
     {
       Vector2 hitPointLocal;
       float distance;
 
       // Finally, perform a more accurate ray test to see if our ray actually hits the actor.
-      if( actor.RayActorTest( rayOrigin, rayDir, hitPointLocal, distance ) )
+      if( rayTest.ActorTest( actor, rayOrigin, rayDir, hitPointLocal, distance ) )
       {
         if( distance >= nearClippingPlane && distance <= farClippingPlane )
         {
@@ -297,7 +298,8 @@ HitActor HitTestWithinLayer( Actor& actor,
                                                  overlayHit,
                                                  layerIs3d,
                                                  newClippingDepth,
-                                                 clippingBitPlaneMask ) );
+                                                 clippingBitPlaneMask,
+                                                 rayTest ) );
 
         bool updateChildHit = false;
         if( currentHit.distance >= 0.0f )
@@ -407,7 +409,8 @@ bool HitTestRenderTask( const RenderTaskList::ExclusivesContainer& exclusives,
                         RenderTask& renderTask,
                         Vector2 screenCoordinates,
                         Results& results,
-                        HitTestInterface& hitCheck )
+                        HitTestInterface& hitCheck,
+                        const RayTest& rayTest )
 {
   if ( renderTask.IsHittable( screenCoordinates ) )
   {
@@ -432,7 +435,7 @@ bool HitTestRenderTask( const RenderTaskList::ExclusivesContainer& exclusives,
       Dali::Layer layer( sourceActor->GetLayer() );
       if( layer )
       {
-        const uint32_t sourceActorDepth( layer.GetDepth() );
+        const uint32_t sourceActorDepth( layer.GetProperty< bool >( Dali::Layer::Property::DEPTH ) );
 
         CameraActor* cameraActor = renderTask.GetCameraActor();
         bool pickingPossible = cameraActor->BuildPickingRay(
@@ -473,7 +476,8 @@ bool HitTestRenderTask( const RenderTaskList::ExclusivesContainer& exclusives,
                                         overlayHit,
                                         layer->GetBehavior() == Dali::Layer::LAYER_3D,
                                         0u,
-                                        0u );
+                                        0u,
+                                        rayTest );
             }
             else if( IsWithinSourceActors( *sourceActor, *layer ) )
             {
@@ -489,7 +493,8 @@ bool HitTestRenderTask( const RenderTaskList::ExclusivesContainer& exclusives,
                                         overlayHit,
                                         layer->GetBehavior() == Dali::Layer::LAYER_3D,
                                         0u,
-                                        0u );
+                                        0u,
+                                        rayTest );
             }
 
             // If this layer is set to consume the hit, then do not check any layers behind it
@@ -542,18 +547,19 @@ bool HitTestRenderTaskList( const Vector2& sceneSize,
   RenderTaskList::RenderTaskContainer& tasks = taskList.GetTasks();
   RenderTaskList::RenderTaskContainer::reverse_iterator endIter = tasks.rend();
   const auto& exclusives = taskList.GetExclusivesList();
+  RayTest rayTest;
 
   for( RenderTaskList::RenderTaskContainer::reverse_iterator iter = tasks.rbegin(); endIter != iter; ++iter )
   {
     RenderTask& renderTask = *iter->Get();
-    bool isOffscreenRenderTask = ( renderTask.GetTargetFrameBuffer() || renderTask.GetFrameBuffer() );
+    const bool isOffscreenRenderTask = renderTask.GetFrameBuffer();
     if( (onScreen && isOffscreenRenderTask) || (!onScreen && !isOffscreenRenderTask) )
     {
       // Skip to next task
       continue;
     }
 
-    if( HitTestRenderTask( exclusives, sceneSize, layers, renderTask, screenCoordinates, results, hitCheck ) )
+    if( HitTestRenderTask( exclusives, sceneSize, layers, renderTask, screenCoordinates, results, hitCheck, rayTest ) )
     {
       // Return true when an actor is hit (or layer in our render-task consumes the hit)
       return true; // don't bother checking off screen tasks
@@ -597,9 +603,7 @@ bool HitTestForEachRenderTask( const Vector2& sceneSize,
 
 } // unnamed namespace
 
-HitTestInterface::~HitTestInterface()
-{
-}
+HitTestInterface::~HitTestInterface() = default;
 
 bool HitTest( const Vector2& sceneSize, RenderTaskList& taskList, LayerList& layerList, const Vector2& screenCoordinates, Dali::HitTestAlgorithm::Results& results, Dali::HitTestAlgorithm::HitTestFunction func )
 {