2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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 );
95 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
98 application.SendNotification();
100 application.Render();
101 application.SendNotification();
103 Vector2 screenCoordinates( stageSize.x * 0.05f, stageSize.y * 0.05f );
104 Dali::HitTestAlgorithm::Results results;
105 DALI_TEST_CHECK( !results.actor );
106 DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
107 // miss expected, results not changed
108 DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
109 DALI_TEST_CHECK( !results.actor );
110 DALI_TEST_EQUALS( Vector2::ZERO, results.actorCoordinates, 0.1f, TEST_LOCATION );
112 screenCoordinates.x = stageSize.x * 0.265f;
113 screenCoordinates.y = stageSize.y * 0.33f;
114 results.actor = Actor();
115 results.actorCoordinates = Vector2::ZERO;
116 // hit expected, results changed
117 DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
118 DALI_TEST_CHECK( results.actor == offscreenActor );
119 DALI_TEST_EQUALS( (screenCoordinates-offset)/scale , results.actorCoordinates, 0.1f, TEST_LOCATION );
121 screenCoordinates.x = stageSize.x * 0.435f;
122 screenCoordinates.y = stageSize.y * 0.52f;
123 // hit expected, results changed
124 DALI_TEST_CHECK( true == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
125 DALI_TEST_CHECK( results.actor == offscreenActor );
126 const Vector2 expectedCoordinates = (screenCoordinates-offset)/scale;
127 DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );
129 screenCoordinates.x = stageSize.x * 0.65f;
130 screenCoordinates.y = stageSize.y * 0.95f;
131 // miss expected, results not changed
132 DALI_TEST_CHECK( false == Dali::HitTestAlgorithm::HitTest( renderTask, screenCoordinates, results, IsActorHittableFunction ) );
133 DALI_TEST_CHECK( results.actor == offscreenActor );
134 DALI_TEST_EQUALS( expectedCoordinates , results.actorCoordinates, 0.1f, TEST_LOCATION );