2 * Copyright (c) 2017 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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/shader.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali/devel-api/object/handle-devel.h>
28 #include <dali-toolkit/devel-api/align-enums.h>
29 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
32 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
33 #include <dali-toolkit/dali-toolkit.h>
34 #include "dummy-control.h"
37 using namespace Dali::Toolkit;
39 void dali_image_visual_startup(void)
41 test_return_value = TET_UNDEF;
44 void dali_image_visual_cleanup(void)
46 test_return_value = TET_PASS;
51 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery_small-1.jpg";
52 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
53 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
54 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
58 Actor CreateActorWithImageVisual(const Property::Map& map)
60 VisualFactory factory = VisualFactory::Get();
61 DummyControl actor = DummyControl::New();
62 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
63 Visual::Base visual = factory.CreateVisual( map );
64 DALI_TEST_CHECK( visual );
65 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
66 actor.SetSize( 200.f, 200.f );
67 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
71 void TestVisualRender( ToolkitTestApplication& application,
74 std::size_t expectedSamplers = 0,
75 ImageDimensions imageDimensions = ImageDimensions(),
76 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
78 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
79 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
83 // set the image size, for test case, this needs to be set before loading started
84 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
87 actor.SetSize( 200.f, 200.f );
88 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
90 Stage::GetCurrent().Add( actor );
92 application.SendNotification(); // Send messages to update
93 application.Render(); // process update and render
94 application.SendNotification(); // process any signals to event
98 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
101 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
104 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
107 visual.CreatePropertyMap(map);
108 Property::Value* value = map.Find( mixColorIndex );
109 DALI_TEST_CHECK( value );
111 DALI_TEST_CHECK( value->Get( mixColor1 ) );
112 DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
114 value = map.Find( DevelVisual::Property::MIX_COLOR );
115 DALI_TEST_CHECK( value );
117 DALI_TEST_CHECK( value->Get( mixColor2 ) );
118 DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
120 value = map.Find( DevelVisual::Property::OPACITY );
121 DALI_TEST_CHECK( value );
123 DALI_TEST_CHECK( value->Get( opacity ) );
124 DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
129 int UtcDaliImageVisualPropertyMap(void)
131 ToolkitTestApplication application;
132 tet_infoline( "Request image visual with a Property::Map" );
134 VisualFactory factory = VisualFactory::Get();
135 DALI_TEST_CHECK( factory );
137 Property::Map propertyMap;
138 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
139 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
141 Visual::Base visual = factory.CreateVisual( propertyMap );
142 DALI_TEST_CHECK( visual );
144 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
145 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
147 TestGlAbstraction& gl = application.GetGlAbstraction();
148 TraceCallStack& textureTrace = gl.GetTextureTrace();
149 textureTrace.Enable(true);
151 DummyControl actor = DummyControl::New();
152 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
153 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
155 actor.SetSize( 200.f, 200.f );
156 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
158 Stage::GetCurrent().Add( actor );
159 application.SendNotification();
160 application.Render();
162 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
164 application.SendNotification();
165 application.Render();
167 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
169 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
171 Stage::GetCurrent().Remove( actor );
172 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
178 int UtcDaliImageVisualRemoteImageLoad(void)
180 ToolkitTestApplication application;
181 tet_infoline( "Request remote image visual with a Property::Map" );
183 VisualFactory factory = VisualFactory::Get();
184 DALI_TEST_CHECK( factory );
186 Property::Map propertyMap;
187 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
188 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
190 Visual::Base visual = factory.CreateVisual( propertyMap );
191 DALI_TEST_CHECK( visual );
193 TestGlAbstraction& gl = application.GetGlAbstraction();
194 TraceCallStack& textureTrace = gl.GetTextureTrace();
195 textureTrace.Enable(true);
197 DummyControl actor = DummyControl::New();
198 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
199 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
201 actor.SetSize( 200.f, 200.f );
202 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
204 Stage::GetCurrent().Add( actor );
205 application.SendNotification();
207 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
209 application.SendNotification();
210 application.Render();
212 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
213 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
215 Stage::GetCurrent().Remove( actor );
216 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
221 int UtcDaliImageVisualTextureReuse1(void)
223 ToolkitTestApplication application;
224 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
226 Property::Map propertyMap;
227 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
228 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
230 TestGlAbstraction& gl = application.GetGlAbstraction();
231 TraceCallStack& textureTrace = gl.GetTextureTrace();
232 textureTrace.Enable(true);
233 TraceCallStack& drawTrace = gl.GetDrawTrace();
234 drawTrace.Enable(true);
236 Actor actor = CreateActorWithImageVisual( propertyMap );
237 Stage::GetCurrent().Add( actor );
238 application.SendNotification();
240 // Wait for image to load
241 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
243 application.SendNotification();
244 application.Render();
246 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
247 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
248 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
249 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
250 textureTrace.Reset();
253 Actor actor2 = CreateActorWithImageVisual( propertyMap );
254 Stage::GetCurrent().Add(actor2);
256 application.SendNotification(); // Send messages to update
257 application.Render(); // process update and render
258 application.SendNotification(); // process any signals to event
260 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
262 tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
263 "draw calls use the same texture as the previous draw call\n" );
265 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
266 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
267 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
269 tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
271 Stage::GetCurrent().Remove( actor );
272 application.SendNotification();
273 application.Render();
275 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
276 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
278 tet_infoline("Test that removing last actor does delete the texture\n");
280 Stage::GetCurrent().Remove( actor2 );
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
285 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
291 int UtcDaliImageVisualTextureReuse2(void)
293 ToolkitTestApplication application;
294 tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same url but different property map - should create new texture" );
296 Property::Map propertyMap;
297 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
298 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
300 TestGlAbstraction& gl = application.GetGlAbstraction();
301 TraceCallStack& textureTrace = gl.GetTextureTrace();
302 textureTrace.Enable(true);
303 TraceCallStack& drawTrace = gl.GetDrawTrace();
304 drawTrace.Enable(true);
306 Actor actor = CreateActorWithImageVisual( propertyMap );
307 Stage::GetCurrent().Add( actor );
308 application.SendNotification();
310 // Wait for image to load
311 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
313 application.SendNotification();
314 application.Render();
316 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
317 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
318 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
319 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
320 textureTrace.Reset();
323 propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
324 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
325 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
326 Actor actor2 = CreateActorWithImageVisual( propertyMap );
327 Stage::GetCurrent().Add(actor2);
329 application.SendNotification();
331 // Wait for image to load
332 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
334 application.SendNotification();
335 application.Render();
337 DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
339 tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
340 "renderers are using different textures\n" );
342 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
343 DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
344 DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 2, TEST_LOCATION );
346 tet_infoline("Test that removing 1 actor deletes it's texture\n");
348 Stage::GetCurrent().Remove( actor );
349 application.SendNotification();
350 application.Render();
352 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
353 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
355 tet_infoline("Test that removing last actor deletes it's texture\n");
357 Stage::GetCurrent().Remove( actor2 );
358 application.SendNotification();
359 application.Render();
361 DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
362 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
368 int UtcDaliImageVisualImageHandle(void)
370 ToolkitTestApplication application;
371 tet_infoline( "Request image visual with an image handle" );
373 VisualFactory factory = VisualFactory::Get();
374 DALI_TEST_CHECK( factory );
376 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
377 Visual::Base visual = factory.CreateVisual( image );
379 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
380 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
383 const int height=513;
385 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
386 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
388 TestGlAbstraction& gl = application.GetGlAbstraction();
389 TraceCallStack& textureTrace = gl.GetTextureTrace();
390 textureTrace.Enable(true);
392 DummyControl actor = DummyControl::New();
393 TestVisualRender( application, actor, visual, 1u,
394 ImageDimensions(width, height),
395 Integration::ResourcePointer(bitmap) );
397 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
401 int UtcDaliImageVisualCustomWrapModePixelArea(void)
403 ToolkitTestApplication application;
404 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
406 VisualFactory factory = VisualFactory::Get();
407 DALI_TEST_CHECK( factory );
409 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
412 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
414 Property::Map propertyMap;
415 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
416 propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
417 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
418 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
419 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
420 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
421 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
422 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
423 propertyMap.Insert( DevelImageVisual::Property::ATLASING, true );
425 Visual::Base visual = factory.CreateVisual( propertyMap );
426 DALI_TEST_CHECK( visual );
428 TestGlAbstraction& gl = application.GetGlAbstraction();
429 TraceCallStack& textureTrace = gl.GetTextureTrace();
430 textureTrace.Enable(true);
431 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
432 texParameterTrace.Enable( true );
434 DummyControl actor = DummyControl::New();
435 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
436 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
437 actor.SetSize(2000, 2000);
438 actor.SetParentOrigin(ParentOrigin::CENTER);
439 Stage::GetCurrent().Add( actor );
442 application.SendNotification();
443 application.Render();
445 BitmapLoader loader = BitmapLoader::GetLatestCreated();
446 DALI_TEST_CHECK( loader );
447 loader.WaitForLoading();// waiting until the image to be loaded
448 DALI_TEST_CHECK( loader.IsLoaded() );
450 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
452 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
454 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
455 std::stringstream out;
456 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
457 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
459 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
460 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
462 // test the uniforms which used to handle the wrap mode
463 Renderer renderer = actor.GetRendererAt( 0u );
464 DALI_TEST_CHECK( renderer );
466 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
467 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
468 Vector4 pixelAreaUniform;
469 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
470 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
472 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
473 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
474 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
475 Vector2 wrapModeUniform;
476 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
477 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
480 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
485 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
487 ToolkitTestApplication application;
488 tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
490 VisualFactory factory = VisualFactory::Get();
491 DALI_TEST_CHECK( factory );
493 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
495 const int height=600;
496 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
498 Property::Map propertyMap;
499 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
500 propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
501 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
502 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
503 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
504 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
505 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
506 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
508 Visual::Base visual = factory.CreateVisual( propertyMap );
509 DALI_TEST_CHECK( visual );
511 TestGlAbstraction& gl = application.GetGlAbstraction();
512 TraceCallStack& textureTrace = gl.GetTextureTrace();
513 textureTrace.Enable(true);
514 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
515 texParameterTrace.Enable( true );
517 DummyControl actor = DummyControl::New();
518 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
519 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
520 actor.SetSize(2000, 2000);
521 actor.SetParentOrigin(ParentOrigin::CENTER);
522 Stage::GetCurrent().Add( actor );
525 application.SendNotification();
526 application.Render();
528 BitmapLoader loader = BitmapLoader::GetLatestCreated();
529 DALI_TEST_CHECK( loader );
530 loader.WaitForLoading();// waiting until the image to be loaded
531 DALI_TEST_CHECK( loader.IsLoaded() );
533 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
535 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
537 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
538 std::stringstream out;
539 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
540 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
542 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
543 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
545 // test the uniforms which used to handle the wrap mode
546 Renderer renderer = actor.GetRendererAt( 0u );
547 DALI_TEST_CHECK( renderer );
549 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
550 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
551 Vector4 pixelAreaUniform;
552 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
553 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
555 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
556 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
559 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
564 int UtcDaliImageVisualAnimateMixColor(void)
566 ToolkitTestApplication application;
567 tet_infoline( "Animate mix color" );
569 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
571 VisualFactory factory = VisualFactory::Get();
572 Property::Map propertyMap;
573 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
574 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
575 propertyMap.Insert("mixColor", Color::BLUE);
576 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
577 Visual::Base visual = factory.CreateVisual( propertyMap );
579 DummyControl actor = DummyControl::New(true);
580 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
581 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
583 actor.SetSize(2000, 2000);
584 actor.SetParentOrigin(ParentOrigin::CENTER);
585 actor.SetColor(Color::BLACK);
586 Stage::GetCurrent().Add(actor);
588 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
590 Renderer renderer = actor.GetRendererAt(0);
591 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
592 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
593 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
595 tet_infoline("Test that the renderer has the mixColor property");
596 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
598 const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
601 map["target"] = "testVisual";
602 map["property"] = "mixColor";
603 map["initialValue"] = Color::MAGENTA;
604 map["targetValue"] = TARGET_MIX_COLOR;
605 map["animator"] = Property::Map()
606 .Add("alphaFunction", "LINEAR")
607 .Add("timePeriod", Property::Map()
609 .Add("duration", 4.0f));
611 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
613 Animation animation = dummyImpl.CreateTransition( transition );
615 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
616 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
618 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
621 application.SendNotification();
622 application.Render(0); // Ensure animation starts
623 application.Render(2000u); // Halfway point
624 Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
626 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
627 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
628 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
630 application.Render(2000u); // Halfway point between blue and white
632 DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
633 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
634 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
635 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
637 TestMixColor( visual, DevelVisual::Property::MIX_COLOR, TARGET_MIX_COLOR );
639 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
640 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
645 int UtcDaliImageVisualAnimateOpacity(void)
647 ToolkitTestApplication application;
648 tet_infoline( "Animate image visual opacity" );
650 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
652 VisualFactory factory = VisualFactory::Get();
653 Property::Map propertyMap;
654 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
655 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
656 propertyMap.Insert("opacity", 0.5f);
657 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
658 Visual::Base visual = factory.CreateVisual( propertyMap );
660 DummyControl actor = DummyControl::New(true);
661 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
662 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
664 actor.SetSize(2000, 2000);
665 actor.SetParentOrigin(ParentOrigin::CENTER);
666 actor.SetColor(Color::BLACK);
667 Stage::GetCurrent().Add(actor);
669 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
671 Renderer renderer = actor.GetRendererAt(0);
672 tet_infoline("Test that the renderer has the opacity property");
673 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
674 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
677 Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
678 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
681 tet_infoline( "Test that the opacity can be increased to full via animation, and that the blend mode is set appropriately at the start and end of the animation." );
684 map["target"] = "testVisual";
685 map["property"] = "opacity";
686 map["targetValue"] = 1.0f;
687 map["animator"] = Property::Map()
688 .Add("alphaFunction", "LINEAR")
689 .Add("timePeriod", Property::Map()
691 .Add("duration", 4.0f));
693 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
694 Animation animation = dummyImpl.CreateTransition( transition );
697 application.SendNotification();
698 application.Render(0); // Ensure animation starts
699 application.Render(2000u); // Halfway point through animation
700 application.SendNotification(); // Handle any signals
702 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
704 application.Render(2001u); // end
705 application.SendNotification(); // ensure animation finished signal is sent
707 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
709 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
710 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
715 tet_infoline( "Test that the opacity can be reduced via animation, and that the blend mode is set appropriately at the start and end of the animation." );
718 map["target"] = "testVisual";
719 map["property"] = DevelVisual::Property::OPACITY;
720 map["targetValue"] = 0.1f;
721 map["animator"] = Property::Map()
722 .Add("alphaFunction", "LINEAR")
723 .Add("timePeriod", Property::Map()
725 .Add("duration", 4.0f));
727 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
728 Animation animation = dummyImpl.CreateTransition( transition );
731 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
732 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
734 application.SendNotification();
735 application.Render(0); // Ensure animation starts
736 application.Render(2000u); // Halfway point
737 application.SendNotification();
739 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
741 application.Render(2016u); // end
742 application.SendNotification();
744 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
746 blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
747 DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
754 int UtcDaliImageVisualAnimatePixelArea(void)
756 ToolkitTestApplication application;
757 tet_infoline( "ImageVisual animate pixel area" );
759 application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
761 VisualFactory factory = VisualFactory::Get();
762 Property::Map propertyMap;
763 propertyMap.Insert(Visual::Property::TYPE, Visual::IMAGE);
764 propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
765 propertyMap.Insert("mixColor", Color::BLUE);
766 propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
767 Visual::Base visual = factory.CreateVisual( propertyMap );
769 DummyControl actor = DummyControl::New(true);
770 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
771 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
773 actor.SetSize(2000, 2000);
774 actor.SetParentOrigin(ParentOrigin::CENTER);
775 actor.SetColor(Color::BLACK);
776 Stage::GetCurrent().Add(actor);
778 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
780 Renderer renderer = actor.GetRendererAt(0);
781 Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
783 tet_infoline("Test that the renderer has the mixColor property");
784 DALI_TEST_CHECK( index != Property::INVALID_INDEX );
786 // TransitionData only takes string keys
788 map["target"] = "testVisual";
789 map["property"] = "pixelArea";
790 map["initialValue"] = Vector4( 0,0,0,1 );
791 map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
792 map["animator"] = Property::Map()
793 .Add("alphaFunction", "LINEAR")
794 .Add("timePeriod", Property::Map()
796 .Add("duration", 4.0f));
798 Dali::Toolkit::TransitionData transition = TransitionData::New( map );
800 Animation animation = dummyImpl.CreateTransition( transition );
801 animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
804 application.SendNotification();
805 application.Render(0); // Ensure animation starts
806 application.Render(2000u); // Halfway point
808 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
810 application.Render(2000u); // End of animation
812 DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
817 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
819 ToolkitTestApplication application;
820 tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
822 Property::Map propertyMap;
823 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
824 propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
826 TestGlAbstraction& gl = application.GetGlAbstraction();
827 TraceCallStack& textureTrace = gl.GetTextureTrace();
828 textureTrace.Enable(true);
829 TraceCallStack& drawTrace = gl.GetDrawTrace();
830 drawTrace.Enable(true);
832 Actor actor = CreateActorWithImageVisual( propertyMap );
833 Stage::GetCurrent().Add( actor );
834 application.SendNotification();
836 Stage::GetCurrent().Remove( actor );
837 application.SendNotification();
839 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
840 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
841 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
842 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );