Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-RenderTask.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <iostream>
18
19 #include <stdlib.h>
20 #include <dali/dali.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 namespace
27 {
28 // The functor to be used in the hit-test algorithm to check whether the actor is hittable.
29 bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
30 {
31   bool hittable = false;
32
33   switch (type)
34   {
35     case Dali::HitTestAlgorithm::CHECK_ACTOR:
36     {
37       // Check whether the actor is visible and not fully transparent.
38       if( actor.IsVisible()
39        && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
40       {
41
42           hittable = true;
43       }
44       break;
45     }
46     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
47     {
48       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
49       {
50         hittable = true;
51       }
52       break;
53     }
54     default:
55     {
56       break;
57     }
58   }
59
60   return hittable;
61 };
62
63 } // anonymous namespace
64
65
66 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
67 {
68   TestApplication application;
69   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
70
71   Stage stage = Stage::GetCurrent();
72   Size stageSize = stage.GetSize();
73   Actor mappingActor = Actor::New();
74   Vector2 scale( 0.6f, 0.75f);
75   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
76   mappingActor.SetSize( stageSize * scale );
77   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
78   mappingActor.SetPosition( offset.x, offset.y );
79   stage.Add( mappingActor );
80
81   Actor offscreenActor = Actor::New();
82   offscreenActor.SetSize( stageSize );
83   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
84   stage.Add( offscreenActor );
85
86   RenderTaskList taskList = stage.GetRenderTaskList();
87   RenderTask renderTask = taskList.CreateTask();
88   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::Never);
89   renderTask.SetSourceActor( offscreenActor );
90   renderTask.SetExclusive( true );
91   renderTask.SetInputEnabled( true );
92   renderTask.SetTargetFrameBuffer( frameBufferImage );
93   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
94   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
95
96   // Render and notify
97   application.SendNotification();
98   application.Render();
99   application.Render();
100   application.SendNotification();
101
102   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
103   Dali::HitTestAlgorithm::Results results;
104   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
105   DALI_TEST_CHECK( !results.actor);
106   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
107
108   screenCoordinates.x = stageSize.x * 0.265f;
109   screenCoordinates.y = stageSize.y * 0.33f;
110   results.actor = Actor();
111   results.actorCoordinates = Vector2::ZERO;
112   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
113   DALI_TEST_CHECK( results.actor  == offscreenActor);
114   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
115
116   screenCoordinates.x = stageSize.x * 0.435f;
117   screenCoordinates.y = stageSize.y * 0.52f;
118   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
119   DALI_TEST_CHECK( results.actor  == offscreenActor);
120   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
121
122   screenCoordinates.x = stageSize.x * 0.65f;
123   screenCoordinates.y = stageSize.y * 0.95f;
124   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
125   DALI_TEST_CHECK( !results.actor);
126   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
127   END_TEST;
128 }