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/dali.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
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)
32 bool hittable = false;
36 case Dali::HitTestAlgorithm::CHECK_ACTOR:
38 // Check whether the actor is visible and not fully transparent.
40 && actor.GetCurrentWorldColor().a > 0.01f) // not FULLY_TRANSPARENT
47 case Dali::HitTestAlgorithm::DESCEND_ACTOR_TREE:
49 if( actor.IsVisible() ) // Actor is visible, if not visible then none of its children are visible.
64 } // anonymous namespace
67 int UtcDaliRenderTaskSetScreenToFrameBufferMappingActor(void)
69 TestApplication application;
70 tet_infoline("Testing RenderTask::SetScreenToFrameBufferMappingActor ");
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 );
82 Actor offscreenActor = Actor::New();
83 offscreenActor.SetSize( stageSize );
84 offscreenActor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
85 stage.Add( offscreenActor );
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 );
99 application.SendNotification();
100 application.Render();
101 application.Render();
102 application.SendNotification();
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 );
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 );
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 );
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 );