2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
20 #include <dali/dali.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
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)
31 bool hittable = false;
35 case Dali::HitTestAlgorithm::CHECK_ACTOR:
37 // Check whether the actor is visible and not fully transparent.
39 && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
46 case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
48 if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
63 } // anonymous namespace
66 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
68 TestApplication application;
69 tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
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 );
81 Actor offscreenActor = Actor::New();
82 offscreenActor.SetSize( stageSize );
83 offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
84 stage.Add( offscreenActor );
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 );
97 application.SendNotification();
100 application.SendNotification();
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 );
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 );
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 );
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 );