Fixed test case build & some test cases
[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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/dali.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27 namespace
28 {
29 // The functor to be used in the hit-test algorithm to check whether the actor is hittable.
30 bool IsActorHittableFunction(Actor actor, Dali::HitTestAlgorithm::TraverseType type)
31 {
32   bool hittable = false;
33
34   switch (type)
35   {
36     case Dali::HitTestAlgorithm::CHECK_ACTOR:
37     {
38       // Check whether the actor is visible and not fully transparent.
39       if( actor.IsVisible()
40        && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
41       {
42
43           hittable = true;
44       }
45       break;
46     }
47     case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
48     {
49       if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
50       {
51         hittable = true;
52       }
53       break;
54     }
55     default:
56     {
57       break;
58     }
59   }
60
61   return hittable;
62 };
63
64 } // anonymous namespace
65
66
67 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
68 {
69   TestApplication application;
70   tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
71
72   Stage stage = Stage::GetCurrent();
73   Size stageSize = stage.GetSize();
74   Actor mappingActor = Actor::New();
75   Vector2 scale( 0.6f, 0.75f);
76   Vector2 offset( stageSize.x*0.1f, stageSize.y*0.15f);
77   mappingActor.SetSize( stageSize * scale );
78   mappingActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
79   mappingActor.SetPosition( offset.x, offset.y );
80   stage.Add( mappingActor );
81
82   Actor offscreenActor = Actor::New();
83   offscreenActor.SetSize( stageSize );
84   offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
85   stage.Add( offscreenActor );
86
87   RenderTaskList taskList = stage.GetRenderTaskList();
88   RenderTask renderTask = taskList.CreateTask();
89   FrameBufferImage frameBufferImage =  FrameBufferImage::New(stageSize.width*scale.x, stageSize.height*scale.y, Pixel::A8, Image::Never);
90   renderTask.SetSourceActor( offscreenActor );
91   renderTask.SetExclusive( true );
92   renderTask.SetInputEnabled( true );
93   renderTask.SetTargetFrameBuffer( frameBufferImage );
94   renderTask.SetRefreshRate( RenderTask::REFRESH_ONCE );
95   renderTask.SetScreenToFrameBufferMappingActor( mappingActor );
96   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
97
98   // Render and notify
99   application.SendNotification();
100   application.Render();
101   application.Render();
102   application.SendNotification();
103
104   Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
105   Dali::HitTestAlgorithm::Results results;
106   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
107   DALI_TEST_CHECK( !results.actor);
108   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
109
110   screenCoordinates.x = stageSize.x * 0.265f;
111   screenCoordinates.y = stageSize.y * 0.33f;
112   results.actor = Actor();
113   results.actorCoordinates = Vector2::ZERO;
114   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
115   DALI_TEST_CHECK( results.actor  == offscreenActor);
116   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
117
118   screenCoordinates.x = stageSize.x * 0.435f;
119   screenCoordinates.y = stageSize.y * 0.52f;
120   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
121   DALI_TEST_CHECK( results.actor  == offscreenActor);
122   DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
123
124   screenCoordinates.x = stageSize.x * 0.65f;
125   screenCoordinates.y = stageSize.y * 0.95f;
126   Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction );
127   DALI_TEST_CHECK( !results.actor);
128   DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
129   END_TEST;
130 }