2 * Copyright (c) 2019 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.
18 // Need to override adaptor classes for toolkit test harness, so include
19 // test harness headers before dali headers.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <toolkit-event-thread-callback.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/scripting/scripting.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
27 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
28 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <test-native-image.h>
37 #include "dummy-control.h"
40 using namespace Toolkit;
42 void utc_dali_toolkit_image_view_startup(void)
44 test_return_value = TET_UNDEF;
47 void utc_dali_toolkit_image_view_cleanup(void)
49 test_return_value = TET_PASS;
55 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
56 attribute mediump vec2 aPosition;\n
57 varying mediump vec2 vTexCoord;\n
58 uniform mediump mat4 uMvpMatrix;\n
59 uniform mediump vec3 uSize;\n
63 mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
64 vertexPosition.xyz *= uSize;\n
65 vertexPosition = uMvpMatrix * vertexPosition;\n
67 vTexCoord = aPosition + vec2(0.5);\n
68 gl_Position = vertexPosition;\n
72 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
73 varying mediump vec2 vTexCoord;\n
74 uniform sampler2D sTexture;\n
75 uniform lowp vec4 uColor;\n
79 gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n
83 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
84 const char* TEST_IMAGE_FILE_NAME2 = "gallery_image_02.jpg";
86 const char* TEST_IMAGE_1 = TEST_RESOURCE_DIR "/TB-gloss.png";
87 const char* TEST_IMAGE_2 = TEST_RESOURCE_DIR "/tb-norm.png";
89 // resolution: 34*34, pixel format: RGBA8888
90 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
91 // resolution: 600*600, pixel format: RGB888
92 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
94 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
95 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
97 void TestImage( ImageView imageView, BufferImage image )
99 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
102 DALI_TEST_CHECK( value.Get( map ) );
104 DALI_TEST_CHECK( map.Find( "width" ) );
105 DALI_TEST_CHECK( map.Find( "height" ) );
106 DALI_TEST_CHECK( map.Find( "type" ) );
109 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
110 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
113 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
114 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
117 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
118 DALI_TEST_EQUALS( type, "BufferImage", TEST_LOCATION );
121 void TestImage( ImageView imageView, ResourceImage image )
123 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
126 DALI_TEST_CHECK( value.Get( map ) );
128 if( map.Find( "width" ) )
131 DALI_TEST_CHECK( map[ "width" ].Get( width ) );
132 DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
135 if( map.Find( "height" ) )
138 DALI_TEST_CHECK( map[ "height" ].Get( height ) );
139 DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
142 DALI_TEST_CHECK( map.Find( "type" ) );
145 DALI_TEST_CHECK( map[ "type" ].Get( type ) );
146 DALI_TEST_EQUALS( type, "ResourceImage", TEST_LOCATION );
148 std::string filename;
149 DALI_TEST_CHECK( map[ "filename" ].Get( filename ) );
150 DALI_TEST_EQUALS( filename, image.GetUrl(), TEST_LOCATION );
153 void TestUrl( ImageView imageView, const std::string url )
155 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
157 std::string urlActual;
158 DALI_TEST_CHECK( value.Get( urlActual ) );
159 DALI_TEST_EQUALS( urlActual, url, TEST_LOCATION );
164 int UtcDaliImageViewNewP(void)
166 TestApplication application;
168 ImageView imageView = ImageView::New();
170 DALI_TEST_CHECK( imageView );
175 int UtcDaliImageViewNewImageP(void)
177 TestApplication application;
179 BufferImage image = CreateBufferImage( 100, 200, Vector4( 1.f, 1.f, 1.f, 1.f ) );
180 ImageView imageView = ImageView::New( image );
182 DALI_TEST_CHECK( imageView );
183 TestImage( imageView, image );
188 int UtcDaliImageViewNewUrlP(void)
190 TestApplication application;
192 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
193 DALI_TEST_CHECK( imageView );
195 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
200 int UtcDaliImageViewConstructorP(void)
202 TestApplication application;
206 DALI_TEST_CHECK( !imageView );
211 int UtcDaliImageViewCopyConstructorP(void)
213 TestApplication application;
215 // Initialize an object, ref count == 1
216 ImageView imageView = ImageView::New();
218 ImageView copy( imageView );
219 DALI_TEST_CHECK( copy );
224 int UtcDaliImageViewAssignmentOperatorP(void)
226 TestApplication application;
228 ImageView imageView = ImageView::New();
230 ImageView copy( imageView );
231 DALI_TEST_CHECK( copy );
232 DALI_TEST_EQUALS( imageView, copy, TEST_LOCATION );
237 int UtcDaliImageViewDownCastP(void)
239 TestApplication application;
241 ImageView imageView = ImageView::New();
243 BaseHandle object(imageView);
245 ImageView imageView2 = ImageView::DownCast( object );
246 DALI_TEST_CHECK(imageView2);
248 ImageView imageView3 = DownCast< ImageView >( object );
249 DALI_TEST_CHECK(imageView3);
254 int UtcDaliImageViewDownCastN(void)
256 TestApplication application;
258 BaseHandle unInitializedObject;
260 ImageView imageView1 = ImageView::DownCast( unInitializedObject );
261 DALI_TEST_CHECK( !imageView1 );
263 ImageView imageView2 = DownCast< ImageView >( unInitializedObject );
264 DALI_TEST_CHECK( !imageView2 );
269 int UtcDaliImageViewTypeRegistry(void)
271 ToolkitTestApplication application;
273 TypeRegistry typeRegistry = TypeRegistry::Get();
274 DALI_TEST_CHECK( typeRegistry );
276 TypeInfo typeInfo = typeRegistry.GetTypeInfo( "ImageView" );
277 DALI_TEST_CHECK( typeInfo );
279 BaseHandle handle = typeInfo.CreateInstance();
280 DALI_TEST_CHECK( handle );
282 ImageView imageView = ImageView::DownCast( handle );
283 DALI_TEST_CHECK( imageView );
288 int UtcDaliImageViewSetGetProperty01(void)
290 ToolkitTestApplication application;
292 ImageView imageView = ImageView::New();
294 Property::Index idx = imageView.GetPropertyIndex( "image" );
295 DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
297 imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
298 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
303 int UtcDaliImageViewSetGetProperty02(void)
305 ToolkitTestApplication application;
307 Image image = CreateBufferImage( 10, 10, Color::WHITE );
308 ImageView imageView = ImageView::New(image);
309 Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
311 Stage::GetCurrent().Add( imageView );
313 application.SendNotification();
314 application.Render();
315 TestGlAbstraction& gl = application.GetGlAbstraction();
317 Vector4 pixelAreaUniform;
318 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
319 DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
321 Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
322 Vector4 pixelAreaValue;
323 DALI_TEST_CHECK( value.Get(pixelAreaValue) );
324 DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
326 Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
327 imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
329 application.SendNotification();
330 application.Render();
332 value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
333 value.Get(pixelAreaValue);
334 DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
336 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
337 DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
342 int UtcDaliImageViewSetGetProperty03(void)
344 ToolkitTestApplication application;
346 Image image = CreateBufferImage( 10, 10, Color::WHITE );
347 ImageView imageView = ImageView::New(image);
348 Stage::GetCurrent().Add( imageView );
349 application.SendNotification();
350 application.Render();
352 // conventional alpha blending
353 Renderer renderer = imageView.GetRendererAt( 0 );
354 Property::Value value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
356 DALI_TEST_CHECK( value.Get( enable ) );
357 DALI_TEST_CHECK( enable );
359 // pre-multiplied alpha blending
360 imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
361 application.SendNotification();
362 application.Render();
364 int srcFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
365 int destFactorRgb = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
366 int srcFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
367 int destFactorAlpha = renderer.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
368 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
369 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
370 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
371 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
373 value = renderer.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
374 DALI_TEST_CHECK( value.Get( enable ) );
375 DALI_TEST_CHECK( enable );
380 int UtcDaliImageViewPreMultipliedAlphaPng(void)
382 ToolkitTestApplication application;
384 // Set up trace debug
385 TestGlAbstraction& gl = application.GetGlAbstraction();
386 TraceCallStack& textureTrace = gl.GetTextureTrace();
387 textureTrace.Enable( true );
389 Property::Map imageMap;
390 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
391 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
393 ImageView imageView1 = ImageView::New();
394 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
396 Stage::GetCurrent().Add( imageView1 );
398 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
400 DALI_TEST_CHECK( value.Get( enable ) );
401 DALI_TEST_CHECK( enable ); // Default value is true
403 // loading started, this waits for the loader thread for max 30 seconds
404 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
406 application.SendNotification();
407 application.Render();
409 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
410 DALI_TEST_CHECK( value.Get( enable ) );
411 DALI_TEST_CHECK( enable ); // Keep true
413 // conventional alpha blending
414 Renderer renderer1 = imageView1.GetRendererAt( 0 );
415 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
416 DALI_TEST_CHECK( value.Get( enable ) );
417 DALI_TEST_CHECK( enable );
419 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
420 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
421 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
422 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
423 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
424 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
425 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
426 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
428 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
429 textureTrace.Reset();
431 // Disable pre-multiplied alpha blending
432 imageView1.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
435 Property::Map attributes;
436 DevelControl::DoAction( imageView1, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes );
438 // loading started, this waits for the loader thread for max 30 seconds
439 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
441 application.SendNotification();
442 application.Render();
444 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
445 DALI_TEST_CHECK( value.Get( enable ) );
446 DALI_TEST_CHECK( !enable );
448 // conventional alpha blending
449 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
450 DALI_TEST_CHECK( value.Get( enable ) );
451 DALI_TEST_CHECK( !enable );
453 srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
454 destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
455 srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
456 destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
457 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
458 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
459 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
460 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
462 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
463 textureTrace.Reset();
465 // Make a new ImageView using the same image
466 ImageView imageView2 = ImageView::New();
467 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
469 Stage::GetCurrent().Add( imageView2 );
471 application.SendNotification();
472 application.Render();
474 Renderer renderer2 = imageView2.GetRendererAt( 0 );
475 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
476 DALI_TEST_CHECK( value.Get( enable ) );
477 DALI_TEST_CHECK( enable );
479 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
480 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
481 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
482 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
483 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::ONE );
484 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
485 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
486 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
488 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
493 int UtcDaliImageViewPreMultipliedAlphaJpg(void)
495 ToolkitTestApplication application;
497 // Set up trace debug
498 TestGlAbstraction& gl = application.GetGlAbstraction();
499 TraceCallStack& textureTrace = gl.GetTextureTrace();
500 textureTrace.Enable( true );
502 Property::Map imageMap;
503 imageMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
504 imageMap[ ImageVisual::Property::RELEASE_POLICY] = ImageVisual::ReleasePolicy::NEVER; // To keep the texture cache
506 ImageView imageView1 = ImageView::New();
507 imageView1.SetProperty( ImageView::Property::IMAGE, imageMap );
509 Stage::GetCurrent().Add( imageView1 );
511 Property::Value value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
513 DALI_TEST_CHECK( value.Get( enable ) );
514 DALI_TEST_CHECK( enable ); // Default value is true
516 // loading started, this waits for the loader thread for max 30 seconds
517 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
519 application.SendNotification();
520 application.Render();
522 value = imageView1.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
523 DALI_TEST_CHECK( value.Get( enable ) );
524 DALI_TEST_CHECK( !enable ); // Should be false after loading
526 // conventional alpha blending
527 Renderer renderer1 = imageView1.GetRendererAt( 0 );
528 value = renderer1.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
529 DALI_TEST_CHECK( value.Get( enable ) );
530 DALI_TEST_CHECK( !enable );
532 int srcFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
533 int destFactorRgb = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
534 int srcFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
535 int destFactorAlpha = renderer1.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
536 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
537 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
538 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
539 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
541 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); // A new texture should be generated.
542 textureTrace.Reset();
544 ImageView imageView2 = ImageView::New();
545 imageView2.SetProperty( ImageView::Property::IMAGE, imageMap );
547 // Disable pre-multiplied alpha blending
548 imageView2.SetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA, false );
550 Stage::GetCurrent().Add( imageView2 );
552 application.SendNotification();
553 application.Render();
555 value = imageView2.GetProperty( ImageView::Property::PRE_MULTIPLIED_ALPHA );
556 DALI_TEST_CHECK( value.Get( enable ) );
557 DALI_TEST_CHECK( !enable );
559 // conventional alpha blending
560 Renderer renderer2 = imageView2.GetRendererAt( 0 );
561 value = renderer2.GetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA );
562 DALI_TEST_CHECK( value.Get( enable ) );
563 DALI_TEST_CHECK( !enable );
565 srcFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_RGB );
566 destFactorRgb = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_RGB );
567 srcFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_SRC_ALPHA );
568 destFactorAlpha = renderer2.GetProperty<int>( Renderer::Property::BLEND_FACTOR_DEST_ALPHA );
569 DALI_TEST_CHECK( srcFactorRgb == BlendFactor::SRC_ALPHA );
570 DALI_TEST_CHECK( destFactorRgb == BlendFactor::ONE_MINUS_SRC_ALPHA );
571 DALI_TEST_CHECK( srcFactorAlpha == BlendFactor::ONE );
572 DALI_TEST_CHECK( destFactorAlpha == BlendFactor::ONE_MINUS_SRC_ALPHA );
574 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION ); // The cached texture should be used.
579 int UtcDaliImageViewPixelArea(void)
581 // Test pixel area property
582 ToolkitTestApplication application;
584 // Gif image, use AnimatedImageVisual internally
585 // Atlasing is applied to pack multiple frames, use custom wrap mode
586 ImageView gifView = ImageView::New();
587 const Vector4 pixelAreaVisual( 0.f, 0.f, 2.f, 2.f );
588 gifView.SetProperty( ImageView::Property::IMAGE,
589 Property::Map().Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
590 .Add( ImageVisual::Property::PIXEL_AREA, pixelAreaVisual ) );
593 Stage stage = Stage::GetCurrent();
594 stage.Add( gifView );
597 application.SendNotification();
598 application.Render(16);
599 DALI_TEST_CHECK( gifView.GetRendererCount() == 1u );
601 const Vector4 fullTextureRect( 0.f, 0.f, 1.f, 1.f );
602 // test that the pixel area value defined in the visual property map is registered on renderer
603 Renderer renderer = gifView.GetRendererAt(0);
604 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
605 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaVisual, TEST_LOCATION );
607 // test that the shader has the default pixel area value registered.
608 Shader shader = renderer.GetShader();
609 pixelAreaValue = shader.GetProperty( shader.GetPropertyIndex( "pixelArea" ) );
610 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), fullTextureRect, TEST_LOCATION );
612 // test that the uniform uses the pixelArea property on the renderer.
613 TestGlAbstraction& gl = application.GetGlAbstraction();
614 Vector4 pixelAreaUniform;
615 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
616 DALI_TEST_EQUALS( pixelAreaVisual, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
618 // set the pixelArea property on the control
619 const Vector4 pixelAreaControl( -1.f, -1.f, 3.f, 3.f );
620 gifView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaControl );
621 application.SendNotification();
622 application.Render(16);
624 // check the pixelArea property on the control
625 pixelAreaValue = gifView.GetProperty( gifView.GetPropertyIndex( "pixelArea" ) );
626 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelAreaControl, TEST_LOCATION );
627 // test that the uniform uses the pixelArea property on the control.
628 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
629 DALI_TEST_EQUALS( pixelAreaControl, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
635 int UtcDaliImageViewAsyncLoadingWithoutAltasing(void)
637 ToolkitTestApplication application;
638 TestGlAbstraction& gl = application.GetGlAbstraction();
639 const std::vector<GLuint>& textures = gl.GetBoundTextures();
640 size_t numTextures = textures.size();
642 // Async loading, no atlasing for big size image
643 ImageView imageView = ImageView::New( gImage_600_RGB );
645 // By default, Aysnc loading is used
646 Stage::GetCurrent().Add( imageView );
647 imageView.SetSize(100, 100);
648 imageView.SetParentOrigin( ParentOrigin::CENTER );
650 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
652 application.SendNotification();
653 application.Render(16);
654 application.SendNotification();
656 const std::vector<GLuint>& textures2 = gl.GetBoundTextures();
657 DALI_TEST_GREATER( textures2.size(), numTextures, TEST_LOCATION );
664 int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
666 ToolkitTestApplication application;
668 //Async loading, automatic atlasing for small size image
669 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
671 callStack.Enable(true);
673 Property::Map imageMap;
675 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
676 imageMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
677 imageMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
678 imageMap[ ImageVisual::Property::ATLASING] = true;
680 ImageView imageView = ImageView::New();
681 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
682 imageView.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10u, 10u, 10u, 10u ) );
684 // By default, Aysnc loading is used
685 // loading is not started if the actor is offStage
687 Stage::GetCurrent().Add( imageView );
688 application.SendNotification();
689 application.Render(16);
690 application.Render(16);
691 application.SendNotification();
693 imageView.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT );
694 application.SendNotification();
695 application.Render(16);
696 application.Render(16);
697 application.SendNotification();
699 // loading started, this waits for the loader thread for max 30 seconds
700 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
702 application.SendNotification();
703 application.Render(16);
705 callStack.Enable(false);
707 TraceCallStack::NamedParams params;
708 params["width"] = ToString(34);
709 params["height"] = ToString(34);
710 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
715 int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
717 ToolkitTestApplication application;
719 //Async loading, automatic atlasing for small size image
720 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
722 callStack.Enable(true);
724 Property::Map asyncLoadingMap;
725 asyncLoadingMap[ "url" ] = gImage_34_RGBA;
726 asyncLoadingMap[ "desiredHeight" ] = 34;
727 asyncLoadingMap[ "desiredWidth" ] = 34;
728 asyncLoadingMap[ "synchronousLoading" ] = false;
729 asyncLoadingMap[ "atlasing" ] = true;
731 ImageView imageView = ImageView::New();
732 imageView.SetProperty( ImageView::Property::IMAGE, asyncLoadingMap );
734 Stage::GetCurrent().Add( imageView );
735 application.SendNotification();
736 application.Render(16);
737 application.Render(16);
738 application.SendNotification();
740 // loading started, this waits for the loader thread for max 30 seconds
741 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
743 application.SendNotification();
744 application.Render(16);
746 callStack.Enable(false);
748 TraceCallStack::NamedParams params;
749 params["width"] = ToString(34);
750 params["height"] = ToString(34);
751 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ), true, TEST_LOCATION );
756 int UtcDaliImageViewSyncLoading(void)
758 ToolkitTestApplication application;
760 tet_infoline("ImageView Testing sync loading and size using index key property map");
762 Property::Map syncLoadingMap;
763 syncLoadingMap[ ImageVisual::Property::SYNCHRONOUS_LOADING ] = true;
764 syncLoadingMap[ ImageVisual::Property::ATLASING ] = true;
766 // Sync loading, no atlasing for big size image
768 ImageView imageView = ImageView::New();
770 // Sync loading is used
771 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_600_RGB;
772 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
775 // Sync loading, automatic atlasing for small size image
777 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
779 callStack.Enable(true);
781 ImageView imageView = ImageView::New( );
783 // Sync loading is used
784 syncLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
785 syncLoadingMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 34;
786 syncLoadingMap[ ImageVisual::Property::DESIRED_WIDTH ] = 34;
787 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
789 Stage::GetCurrent().Add( imageView );
790 application.SendNotification();
791 application.Render(16);
793 TraceCallStack::NamedParams params;
794 params["width"] = ToString(34);
795 params["height"] = ToString(34);
796 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
797 true, TEST_LOCATION );
802 int UtcDaliImageViewSyncLoading02(void)
804 ToolkitTestApplication application;
806 tet_infoline("ImageView Testing sync loading and size using string key property map");
808 // Sync loading, automatic atlasing for small size image
810 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
812 callStack.Enable(true);
814 ImageView imageView = ImageView::New( );
816 // Sync loading is used
817 Property::Map syncLoadingMap;
818 syncLoadingMap[ "url" ] = gImage_34_RGBA;
819 syncLoadingMap[ "desiredHeight" ] = 34;
820 syncLoadingMap[ "desiredWidth" ] = 34;
821 syncLoadingMap[ "synchronousLoading" ] = true;
822 syncLoadingMap[ "atlasing" ] = true;
823 imageView.SetProperty( ImageView::Property::IMAGE, syncLoadingMap );
825 Stage::GetCurrent().Add( imageView );
826 application.SendNotification();
827 application.Render(16);
829 TraceCallStack::NamedParams params;
830 params["width"] = ToString(34);
831 params["height"] = ToString(34);
832 DALI_TEST_EQUALS( callStack.FindMethodAndParams( "TexSubImage2D", params ),
833 true, TEST_LOCATION );
838 int UtcDaliImageViewAddedTexture(void)
840 ToolkitTestApplication application;
842 tet_infoline("ImageView Testing image view with texture provided manager url");
844 ImageView imageView = ImageView::New();
846 // empty texture is ok, though pointless from app point of view
848 std::string url = TextureManager::AddTexture(empty);
849 DALI_TEST_CHECK(url.size() > 0u);
851 Property::Map propertyMap;
852 propertyMap[ImageVisual::Property::URL] = url;
853 imageView.SetProperty(ImageView::Property::IMAGE, propertyMap);
855 Stage::GetCurrent().Add( imageView );
856 application.SendNotification();
857 application.Render();
862 int UtcDaliImageViewSizeWithBackground(void)
864 ToolkitTestApplication application;
868 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
869 ImageView imageView = ImageView::New();
870 imageView.SetBackgroundImage( image );
872 Stage::GetCurrent().Add( imageView );
873 application.SendNotification();
874 application.Render();
876 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
877 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
882 int UtcDaliImageViewSizeWithBackgroundAndImage(void)
884 ToolkitTestApplication application;
886 int widthBackground = 100;
887 int heightBackground = 200;
890 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
891 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
893 ImageView imageView = ImageView::New();
894 imageView.SetBackgroundImage( imageBackground );
895 imageView.SetImage( image );
897 Stage::GetCurrent().Add( imageView );
898 application.SendNotification();
899 application.Render();
901 DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
902 DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
907 int UtcDaliImageViewHeightForWidthBackground(void)
909 ToolkitTestApplication application;
911 int widthBackground = 100;
912 int heightBackground = 200;
913 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
915 ImageView imageView = ImageView::New();
916 imageView.SetBackgroundImage( imageBackground );
918 Stage::GetCurrent().Add( imageView );
919 application.SendNotification();
920 application.Render();
922 Control control = Control::DownCast( imageView );
923 DALI_TEST_CHECK( control );
924 DALI_TEST_EQUALS( imageView.GetHeightForWidth( 123.f ), control.GetHeightForWidth( 123.f ), TEST_LOCATION );
925 DALI_TEST_EQUALS( imageView.GetWidthForHeight( 321.f ), control.GetWidthForHeight( 321.f ), TEST_LOCATION );
930 int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
932 ToolkitTestApplication application;
934 int widthBackground = 100;
935 int heightBackground = 200;
938 Image imageBackground = CreateBufferImage( widthBackground, heightBackground, Vector4(1.f, 1.f, 1.f, 1.f) );
939 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
941 ImageView imageView = ImageView::New();
942 imageView.SetBackgroundImage( imageBackground );
943 imageView.SetImage( image );
945 Stage::GetCurrent().Add( imageView );
946 application.SendNotification();
947 application.Render();
949 DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
950 DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
955 int UtcDaliImageViewSetBufferImage(void)
957 ToolkitTestApplication application;
961 BufferImage image1 = CreateBufferImage( width1, height1, Vector4( 1.f, 1.f, 1.f, 1.f ) );
962 ImageView imageView = ImageView::New();
963 imageView.SetImage( image1 );
965 TestImage( imageView, image1 );
969 BufferImage image2 = CreateBufferImage( width2, height2, Vector4( 1.f, 1.f, 1.f, 1.f ) );
970 imageView.SetImage( image2 );
972 TestImage( imageView, image2 );
977 int UtcDaliImageViewSetImageUrl(void)
979 ToolkitTestApplication application;
981 ImageView imageView = ImageView::New();
982 imageView.SetImage( TEST_IMAGE_FILE_NAME );
983 TestUrl( imageView, TEST_IMAGE_FILE_NAME );
986 imageView.SetImage( TEST_IMAGE_FILE_NAME2 );
987 TestUrl( imageView, TEST_IMAGE_FILE_NAME2 );
992 int UtcDaliImageViewSetImageOnstageP(void)
994 ToolkitTestApplication application;
996 ImageView imageView = ImageView::New();
998 Stage::GetCurrent().Add( imageView );
999 application.SendNotification();
1000 application.Render();
1002 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1003 imageView.SetImage( image1 );
1004 TestImage( imageView, image1 );
1008 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1009 imageView.SetImage( image2 );
1010 TestImage( imageView, image2 );
1015 int UtcDaliImageViewSetImageOnstageN(void)
1017 ToolkitTestApplication application;
1019 ImageView imageView = ImageView::New();
1021 Stage::GetCurrent().Add( imageView );
1022 application.SendNotification();
1023 application.Render();
1025 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1026 imageView.SetImage( image1 );
1027 TestImage( imageView, image1 );
1030 imageView.SetImage( image2 );
1032 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1034 //the value should be empty
1036 DALI_TEST_CHECK( !value.Get( url ) );
1040 DALI_TEST_CHECK( map.Empty() );
1045 int UtcDaliImageViewSetImageOffstageP(void)
1047 ToolkitTestApplication application;
1049 ImageView imageView = ImageView::New();
1051 Stage::GetCurrent().Add( imageView );
1052 application.SendNotification();
1053 application.Render();
1054 Stage::GetCurrent().Remove( imageView );
1056 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1057 imageView.SetImage( image1 );
1058 TestImage( imageView, image1 );
1062 BufferImage image2 = CreateBufferImage( width, height, Vector4( 1.f, 1.f, 1.f, 1.f ) );
1063 imageView.SetImage( image2 );
1064 TestImage( imageView, image2 );
1069 bool gResourceReadySignalFired = false;
1070 Vector3 gNaturalSize;
1072 void ResourceReadySignal( Control control )
1074 gResourceReadySignalFired = true;
1077 int UtcDaliImageViewCheckResourceReady(void)
1079 ToolkitTestApplication application;
1081 gResourceReadySignalFired = false;
1086 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1088 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1089 ImageView imageView = ImageView::New( TEST_GIF_FILE_NAME );
1091 imageView.SetBackgroundImage( image );
1093 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1095 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1097 Stage::GetCurrent().Add( imageView );
1099 application.SendNotification();
1100 application.Render(16);
1103 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1105 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1110 int UtcDaliImageViewSetImageOffstageN(void)
1112 ToolkitTestApplication application;
1114 ImageView imageView = ImageView::New();
1116 Stage::GetCurrent().Add( imageView );
1117 application.SendNotification();
1118 application.Render();
1119 Stage::GetCurrent().Remove( imageView );
1121 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1122 imageView.SetImage( image1 );
1123 TestImage( imageView, image1 );
1126 imageView.SetImage( image2 );
1128 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1130 //the value should be empty
1132 DALI_TEST_CHECK( !value.Get( url ) );
1136 DALI_TEST_CHECK( map.Empty() );
1141 int UtcDaliImageViewSetImageN(void)
1143 ToolkitTestApplication application;
1146 ImageView imageView = ImageView::New();
1147 imageView.SetImage( image1 );
1149 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1151 //the value should be empty
1153 DALI_TEST_CHECK( !value.Get( url ) );
1157 DALI_TEST_CHECK( map.Empty() );
1159 std::string resource_url;
1160 Property::Value val = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1161 DALI_TEST_CHECK( !val.Get( resource_url ) );
1166 int UtcDaliImageViewSetImageTypeChangesP(void)
1168 ToolkitTestApplication application;
1170 ImageView imageView = ImageView::New();
1171 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1173 Stage::GetCurrent().Add( imageView );
1177 Toolkit::Visual::Base visual;
1179 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1180 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1182 application.SendNotification();
1183 application.Render( 16 );
1185 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1187 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1188 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1191 imageView.SetImage( "TEST_URL" );
1193 application.SendNotification();
1194 application.Render( 16 );
1196 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1197 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1199 DALI_TEST_CHECK( value.Get( url ) ); // Value should NOT be empty
1200 DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
1201 DALI_TEST_CHECK( visual ); // Visual should be valid
1203 // Set an empty Image
1204 imageView.SetImage( Image() );
1206 application.SendNotification();
1207 application.Render( 16 );
1209 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1210 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1212 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1214 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1215 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1218 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
1219 imageView.SetImage( image1 );
1221 application.SendNotification();
1222 application.Render( 16 );
1224 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1225 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1227 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1228 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1229 DALI_TEST_CHECK( visual ); // Visual should be valid
1232 imageView.SetImage( "" );
1234 application.SendNotification();
1235 application.Render( 16 );
1237 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1238 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1240 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1242 DALI_TEST_CHECK( map.Empty() ); // Value should be empty
1243 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1245 // Set a URL in property map
1246 Property::Map propertyMap;
1247 propertyMap[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
1248 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1250 application.SendNotification();
1251 application.Render( 16 );
1253 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1254 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1256 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1257 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1258 DALI_TEST_CHECK( visual ); // Visual should be valid
1260 // Set a URL in property map again
1261 propertyMap[ImageVisual::Property::URL] = gImage_34_RGBA;
1262 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1264 application.SendNotification();
1265 application.Render( 16 );
1267 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1268 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1270 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1271 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1272 DALI_TEST_CHECK( visual ); // Visual should be valid
1274 // Set an empty URL in property map
1275 propertyMap[ImageVisual::Property::URL] = std::string();
1276 imageView.SetProperty( ImageView::Property::IMAGE, propertyMap );
1278 application.SendNotification();
1279 application.Render( 16 );
1281 value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1282 visual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1284 DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
1285 DALI_TEST_CHECK( value.Get( map ) ); // Value should NOT be empty
1286 DALI_TEST_CHECK( ! visual ); // Visual should be invalid
1291 int UtcDaliImageViewResourceUrlP(void)
1293 ToolkitTestApplication application;
1295 ImageView imageView = ImageView::New();
1296 DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
1298 imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
1299 DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
1304 // Scenarios 1: ImageView from regular image
1305 int UtcDaliImageViewSetImageBufferImage(void)
1307 ToolkitTestApplication application;
1309 ImageView imageView = ImageView::New();
1310 Stage::GetCurrent().Add( imageView );
1312 TestGlAbstraction& gl = application.GetGlAbstraction();
1313 gl.EnableTextureCallTrace( true );
1315 std::vector< GLuint > ids;
1316 ids.push_back( 23 );
1317 application.GetGlAbstraction().SetNextTextureIds( ids );
1321 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1323 imageView.SetImage( image );
1325 application.SendNotification();
1326 application.Render();
1328 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1330 std::stringstream params;
1331 params << GL_TEXTURE_2D << ", " << 23;
1332 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1337 // Scenarios 2: ImageView from Native image
1338 int UtcDaliImageViewSetImageNativeImage(void)
1340 ToolkitTestApplication application;
1342 ImageView imageView = ImageView::New();
1343 Stage::GetCurrent().Add( imageView );
1345 TestGlAbstraction& gl = application.GetGlAbstraction();
1346 gl.EnableTextureCallTrace( true );
1348 std::vector< GLuint > ids;
1349 ids.push_back( 23 );
1350 application.GetGlAbstraction().SetNextTextureIds( ids );
1354 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1355 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1357 imageView.SetImage( nativeImage );
1358 application.SendNotification();
1359 application.Render();
1361 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1363 std::stringstream params;
1364 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1365 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1370 // Scenarios 3: ImageView initially from regular image but then SetImage called with Native image
1371 int UtcDaliImageViewSetImageBufferImageToNativeImage(void)
1373 ToolkitTestApplication application;
1377 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1379 ImageView imageView = ImageView::New( image );
1380 Stage::GetCurrent().Add( imageView );
1382 TestGlAbstraction& gl = application.GetGlAbstraction();
1383 gl.EnableTextureCallTrace( true );
1385 std::vector< GLuint > ids;
1386 ids.push_back( 23 );
1387 application.GetGlAbstraction().SetNextTextureIds( ids );
1389 application.SendNotification();
1390 application.Render();
1392 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1394 std::stringstream params;
1395 params << GL_TEXTURE_2D << ", " << 23;
1396 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1400 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1401 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1402 imageView.SetImage( nativeImage );
1405 ids.push_back( 24 );
1406 application.GetGlAbstraction().SetNextTextureIds( ids );
1408 application.SendNotification();
1409 application.Render();
1411 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1413 std::stringstream nextTextureParams;
1414 nextTextureParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1415 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1420 // Scenarios 4: ImageView initially from Native image but then SetImage called with regular image
1421 int UtcDaliImageViewSetImageNativeImageToBufferImage(void)
1423 ToolkitTestApplication application;
1427 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1428 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1430 ImageView imageView = ImageView::New( nativeImage );
1431 Stage::GetCurrent().Add( imageView );
1433 TestGlAbstraction& gl = application.GetGlAbstraction();
1434 gl.EnableTextureCallTrace( true );
1436 std::vector< GLuint > ids;
1437 ids.push_back( 23 );
1438 application.GetGlAbstraction().SetNextTextureIds( ids );
1440 application.SendNotification();
1441 application.Render();
1443 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1445 std::stringstream params;
1446 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1447 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1451 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1452 imageView.SetImage( image );
1455 ids.push_back( 24 );
1456 application.GetGlAbstraction().SetNextTextureIds( ids );
1458 application.SendNotification();
1459 application.Render();
1461 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1463 std::stringstream nextTextureParams;
1464 nextTextureParams << GL_TEXTURE_2D << ", " << 24;
1465 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nextTextureParams.str()) );
1470 // Scenarios 5: ImageView from Native image with custom shader
1471 int UtcDaliImageViewSetImageNativeImageWithCustomShader(void)
1473 ToolkitTestApplication application;
1478 Property::Map customShader;
1479 customShader.Insert( "vertexShader", VERTEX_SHADER );
1480 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1482 Property::Array shaderHints;
1483 shaderHints.PushBack( "requiresSelfDepthTest" );
1484 shaderHints.PushBack( "outputIsTransparent" );
1485 shaderHints.PushBack( "outputIsOpaque" );
1486 shaderHints.PushBack( "modifiesGeometry" );
1488 customShader.Insert( "hints", shaderHints );
1491 map.Insert( "shader", customShader );
1493 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1494 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1496 ImageView imageView = ImageView::New( nativeImage );
1497 imageView.SetProperty( ImageView::Property::IMAGE, map );
1498 Stage::GetCurrent().Add( imageView );
1500 TestGlAbstraction& gl = application.GetGlAbstraction();
1501 gl.EnableTextureCallTrace( true );
1503 std::vector< GLuint > ids;
1504 ids.push_back( 23 );
1505 application.GetGlAbstraction().SetNextTextureIds( ids );
1507 application.SendNotification();
1508 application.Render();
1510 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1512 std::stringstream params;
1513 params << GL_TEXTURE_EXTERNAL_OES << ", " << 23;
1514 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1519 // Scenarios 6: ImageView initially from regular image with custom shader but then SetImage called with Native
1520 int UtcDaliImageViewSetImageBufferImageWithCustomShaderToNativeImage(void)
1522 ToolkitTestApplication application;
1527 Property::Map customShader;
1528 customShader.Insert( "vertexShader", VERTEX_SHADER );
1529 customShader.Insert( "fragmentShader", FRAGMENT_SHADER );
1531 Property::Array shaderHints;
1532 shaderHints.PushBack( "requiresSelfDepthTest" );
1533 shaderHints.PushBack( "outputIsTransparent" );
1534 shaderHints.PushBack( "outputIsOpaque" );
1535 shaderHints.PushBack( "modifiesGeometry" );
1537 customShader.Insert( "hints", shaderHints );
1540 map.Insert( "shader", customShader );
1542 BufferImage image = CreateBufferImage( width, height, Color::WHITE );
1544 ImageView imageView = ImageView::New( image );
1545 imageView.SetProperty( ImageView::Property::IMAGE, map );
1546 Stage::GetCurrent().Add( imageView );
1548 TestGlAbstraction& gl = application.GetGlAbstraction();
1549 gl.EnableTextureCallTrace( true );
1551 std::vector< GLuint > ids;
1552 ids.push_back( 23 );
1553 application.GetGlAbstraction().SetNextTextureIds( ids );
1555 application.SendNotification();
1556 application.Render();
1558 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1560 std::stringstream params;
1561 params << GL_TEXTURE_2D << ", " << 23;
1562 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", params.str()) );
1564 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( width, height );
1565 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
1566 imageView.SetImage( nativeImage );
1569 ids.push_back( 24 );
1570 application.GetGlAbstraction().SetNextTextureIds( ids );
1572 application.SendNotification();
1573 application.Render();
1575 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethod("BindTexture") );
1577 std::stringstream nativeImageParams;
1578 nativeImageParams << GL_TEXTURE_EXTERNAL_OES << ", " << 24;
1579 DALI_TEST_CHECK( gl.GetTextureTrace().FindMethodAndParams("BindTexture", nativeImageParams.str()) );
1585 int UtcDaliImageViewGetImageP1(void)
1587 ToolkitTestApplication application;
1589 ImageView imageView = ImageView::New();
1590 DALI_TEST_CHECK( ! imageView.GetImage() );
1592 Image image = CreateBufferImage();
1593 imageView.SetImage( image );
1594 DALI_TEST_CHECK( imageView.GetImage() == image );
1599 int UtcDaliImageViewGetImageP2(void)
1601 ToolkitTestApplication application;
1603 BufferImage image = CreateBufferImage();
1604 ImageView imageView = ImageView::New( image );
1605 DALI_TEST_CHECK( imageView.GetImage() == image );
1610 int UtcDaliImageViewGetImageN(void)
1612 ToolkitTestApplication application;
1614 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
1615 DALI_TEST_CHECK( ! imageView.GetImage() );
1617 Image image = CreateBufferImage();
1618 imageView.SetImage( image );
1619 DALI_TEST_CHECK( imageView.GetImage() == image );
1621 imageView.SetImage( TEST_IMAGE_FILE_NAME );
1622 DALI_TEST_CHECK( ! imageView.GetImage() );
1628 int UtcDaliImageViewReplaceImage(void)
1630 ToolkitTestApplication application;
1632 gResourceReadySignalFired = false;
1636 Image image = CreateBufferImage( width, height, Vector4(1.f, 1.f, 1.f, 1.f) );
1638 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1639 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1641 DALI_TEST_EQUALS( imageView.IsResourceReady(), false, TEST_LOCATION );
1643 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1645 Stage::GetCurrent().Add( imageView );
1647 application.SendNotification();
1648 application.Render(16);
1650 // loading started, this waits for the loader thread for max 30 seconds
1651 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1653 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1655 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1657 gResourceReadySignalFired = false;
1659 imageView.SetImage(TEST_IMAGE_2);
1661 application.SendNotification();
1662 application.Render(16);
1664 // loading started, this waits for the loader thread for max 30 seconds
1665 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1667 DALI_TEST_EQUALS( imageView.GetRendererCount(), 1u, TEST_LOCATION );
1669 DALI_TEST_EQUALS( imageView.IsResourceReady(), true, TEST_LOCATION );
1671 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1676 void OnRelayoutOverride( Size size )
1678 gNaturalSize = size; // Size Relayout is using
1681 int UtcDaliImageViewReplaceImageAndGetNaturalSize(void)
1683 ToolkitTestApplication application;
1685 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1686 ImageView imageView = ImageView::New( TEST_IMAGE_1 );
1687 imageView.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1689 DummyControl dummyControl = DummyControl::New( true );
1690 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1691 dummyControl.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::ALL_DIMENSIONS );
1693 dummyControl.Add( imageView );
1694 dummyImpl.SetRelayoutCallback( &OnRelayoutOverride );
1695 Stage::GetCurrent().Add( dummyControl );
1697 application.SendNotification();
1698 application.Render();
1700 // loading started, this waits for the loader thread for max 30 seconds
1701 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1703 DALI_TEST_EQUALS( gNaturalSize.width, 1024.0f, TEST_LOCATION );
1704 DALI_TEST_EQUALS( gNaturalSize.height, 1024.0f, TEST_LOCATION );
1706 gNaturalSize = Vector3::ZERO;
1708 imageView.SetImage(gImage_600_RGB);
1710 // Waiting for resourceReady so SendNotifcation not called here.
1712 // loading started, this waits for the loader thread for max 30 seconds
1713 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1715 // Trigger a potential relayout
1716 application.SendNotification();
1717 application.Render();
1719 DALI_TEST_EQUALS( gNaturalSize.width, 600.0f, TEST_LOCATION );
1720 DALI_TEST_EQUALS( gNaturalSize.height, 600.0f, TEST_LOCATION );
1725 int UtcDaliImageViewResourceReadySignalWithImmediateLoad(void)
1727 tet_infoline("Test Setting Image with IMMEDIATE load and receving ResourceReadySignal before staged.");
1729 ToolkitTestApplication application;
1731 gResourceReadySignalFired = false;
1733 Property::Map imageMap;
1735 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1736 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1738 tet_infoline("Creating ImageView without URL so image does not start loading");
1739 ImageView imageView = ImageView::New();
1740 tet_infoline("Connect to image loaded signal before setting image");
1741 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1742 tet_infoline("Setting Image with IMMEDIATE load, signal already connected so will be triggered.");
1743 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1745 // loading started, this waits for the loader thread
1746 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1748 application.SendNotification();
1749 application.Render(16);
1751 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1756 int UtcDaliImageViewResourceReadySignalWithReusedImage(void)
1758 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal.");
1760 ToolkitTestApplication application;
1762 gResourceReadySignalFired = false;
1764 Property::Map imageMap;
1766 imageMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1767 imageMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1769 ImageView imageView = ImageView::New();
1770 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1771 imageView.SetProperty( ImageView::Property::IMAGE, imageMap );
1773 // loading started, this waits for the loader thread
1774 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1776 application.SendNotification();
1777 application.Render(16);
1779 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1780 gResourceReadySignalFired = false;
1782 ImageView imageViewWithExistingImage = ImageView::New();
1783 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1784 imageViewWithExistingImage.SetProperty( ImageView::Property::IMAGE, imageMap );
1786 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1791 int UtcDaliImageViewResourceReadySignalWithReusedImage02(void)
1793 tet_infoline("Test Setting Image that was already loaded by another ImageView and still getting ResourceReadySignal when staged.");
1795 ToolkitTestApplication application;
1797 gResourceReadySignalFired = false;
1799 Property::Map imageImmediateLoadingMap;
1800 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = gImage_34_RGBA;
1801 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
1803 tet_infoline("Immediate load an image");
1804 ImageView imageView = ImageView::New();
1805 imageView.ResourceReadySignal().Connect( &ResourceReadySignal);
1806 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
1808 // loading started, this waits for the loader thread
1809 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1811 application.SendNotification();
1812 application.Render(16);
1814 tet_infoline("Check image loaded");
1815 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1816 gResourceReadySignalFired = false;
1818 tet_infoline("Create another ImageView with the same URL");
1819 ImageView imageViewWithExistingImage = ImageView::New( gImage_34_RGBA );
1820 tet_infoline("Connect to ResourceReady signal for second ImageView, it should still fire as resource is ready");
1821 imageViewWithExistingImage.ResourceReadySignal().Connect( &ResourceReadySignal);
1823 Stage::GetCurrent().Add( imageViewWithExistingImage );
1825 DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
1830 int UtcDaliImageViewPaddingProperty(void)
1832 ToolkitTestApplication application;
1834 ImageView imageView = ImageView::New();
1835 Property::Map imagePropertyMap;
1836 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1837 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/gallery-small-1.jpg" ;
1838 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1839 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1840 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1841 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1842 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1843 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1844 Stage::GetCurrent().Add( imageView );
1846 application.SendNotification();
1847 application.Render();
1849 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1851 ImageView childImage = ImageView::New();
1852 childImage.SetBackgroundColor( Color::BLACK );
1853 childImage.SetSize( 10.f, 10.f );
1854 imageView.Add( childImage );
1856 application.SendNotification();
1857 application.Render();
1859 // Child ImageView should be positioned dependinig on Parent ImageView's Padding value
1860 DALI_TEST_EQUALS( childImage.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1862 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1863 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1864 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1865 Property::Map resultMap;
1866 imageVisual.CreatePropertyMap( resultMap );
1868 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1869 DALI_TEST_CHECK( transformValue );
1870 Property::Map* retMap = transformValue->GetMap();
1871 DALI_TEST_CHECK( retMap );
1873 // Image Visual should be positioned depending on ImageView's padding
1874 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1879 int UtcDaliImageViewPaddingProperty02(void)
1881 ToolkitTestApplication application;
1883 ImageView imageView = ImageView::New();
1884 Property::Map imagePropertyMap;
1885 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1886 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = TEST_RESOURCE_DIR "/Kid1.svg" ;
1887 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = 128;
1888 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = 128;
1889 imagePropertyMap[ DevelVisual::Property::VISUAL_FITTING_MODE ] = Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO;
1890 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
1891 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1892 imageView.SetParentOrigin( ParentOrigin::TOP_LEFT );
1893 imageView.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1894 Stage::GetCurrent().Add( imageView );
1896 application.SendNotification();
1897 application.Render();
1899 DALI_TEST_EQUALS( imageView.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1901 // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
1902 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( imageView );
1903 Toolkit::Visual::Base imageVisual = DevelControl::GetVisual( controlImpl, ImageView::Property::IMAGE );
1904 Property::Map resultMap;
1905 imageVisual.CreatePropertyMap( resultMap );
1907 Property::Value* transformValue = resultMap.Find( Visual::Property::TRANSFORM );
1908 DALI_TEST_CHECK( transformValue );
1909 Property::Map* retMap = transformValue->GetMap();
1910 DALI_TEST_CHECK( retMap );
1912 // Image Visual should be positioned depending on ImageView's padding
1913 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 15, 5 ), TEST_LOCATION );
1918 int UtcDaliImageViewUsingAtlasAndGetNaturalSize(void)
1920 ToolkitTestApplication application;
1922 // Check ImageView with background and main image, to ensure both visuals are marked as loaded
1923 ImageView imageView = ImageView::New();
1924 Property::Map imageMap;
1925 imageMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
1926 imageMap[ Toolkit::ImageVisual::Property::URL ] = gImage_34_RGBA;
1927 imageMap[ Toolkit::ImageVisual::Property::ATLASING ] = true;
1928 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1929 Stage::GetCurrent().Add( imageView );
1931 // Trigger a potential relayout
1932 application.SendNotification();
1933 application.Render();
1935 Vector3 naturalSize = imageView.GetNaturalSize();
1937 DALI_TEST_EQUALS( naturalSize.width, 34.0f, TEST_LOCATION );
1938 DALI_TEST_EQUALS( naturalSize.height, 34.0f, TEST_LOCATION );
1943 int UtcDaliImageViewFillMode(void)
1945 ToolkitTestApplication application;
1947 tet_infoline( "Create an ImageVisual without padding and set the fill-mode to fill" );
1948 tet_infoline( " There should be no need to change the transform, our size-policy should be relative and size shoudl be [1,1]");
1950 ImageView imageView = ImageView::New();
1951 Property::Map imageMap;
1952 imageMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
1953 imageMap.Add( Toolkit::ImageVisual::Property::URL, gImage_600_RGB );
1954 imageMap.Add( DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FittingMode::FILL );
1956 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, imageMap );
1958 Stage::GetCurrent().Add( imageView );
1960 // Trigger a potential relayout
1961 application.SendNotification();
1962 application.Render();
1964 Toolkit::Visual::Base visual = DevelControl::GetVisual( Toolkit::Internal::GetImplementation( imageView ), Toolkit::ImageView::Property::IMAGE );
1965 Property::Map returnedMap;
1966 visual.CreatePropertyMap( returnedMap );
1968 Property::Value* value = returnedMap.Find( Toolkit::Visual::Property::TRANSFORM );
1969 DALI_TEST_CHECK( value );
1970 Property::Map* map = value->GetMap();
1971 DALI_TEST_CHECK( map );
1974 value = map->Find( Toolkit::Visual::Transform::Property::SIZE );
1975 DALI_TEST_CHECK( value );
1976 DALI_TEST_EQUALS( value->Get< Vector2 >(), Vector2::ONE, TEST_LOCATION ); // Relative size so will take up 100%
1978 value = map->Find( Toolkit::Visual::Transform::Property::SIZE_POLICY );
1979 DALI_TEST_CHECK( value );
1980 DALI_TEST_CHECK( value->Get< int >() == Toolkit::Visual::Transform::Policy::RELATIVE );
1985 int UtcDaliImageViewCustomShader(void)
1987 ToolkitTestApplication application;
1989 // Set a custom shader with an image url
1991 Property::Map properties;
1992 Property::Map shader;
1993 const std::string vertexShader = "Foobar";
1994 const std::string fragmentShader = "Foobar";
1995 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
1996 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
1998 properties[Visual::Property::TYPE] = Visual::IMAGE;
1999 properties[Visual::Property::SHADER] = shader;
2000 properties[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2002 ImageView imageView = ImageView::New();
2003 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2005 Stage::GetCurrent().Add( imageView );
2007 application.SendNotification();
2008 application.Render();
2010 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2012 Renderer renderer = imageView.GetRendererAt( 0 );
2013 Shader shader2 = renderer.GetShader();
2014 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2015 Property::Map* map = value.GetMap();
2016 DALI_TEST_CHECK( map );
2018 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2019 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2021 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2022 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2025 // Set a custom shader after setting an image url
2027 Property::Map properties;
2028 Property::Map shader;
2029 const std::string vertexShader = "Foobar";
2030 const std::string fragmentShader = "Foobar";
2031 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2032 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2034 properties[Visual::Property::SHADER] = shader;
2036 ImageView imageView = ImageView::New( TEST_IMAGE_FILE_NAME );
2037 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2039 Stage::GetCurrent().Add( imageView );
2041 application.SendNotification();
2042 application.Render();
2044 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2046 Renderer renderer = imageView.GetRendererAt( 0 );
2047 Shader shader2 = renderer.GetShader();
2048 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2049 Property::Map* map = value.GetMap();
2050 DALI_TEST_CHECK( map );
2052 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2053 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2055 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2056 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2059 // Set a custom shader before setting an image url
2061 Property::Map properties;
2062 Property::Map shader;
2063 const std::string vertexShader = "Foobar";
2064 const std::string fragmentShader = "Foobar";
2065 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2066 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2068 properties[Visual::Property::SHADER] = shader;
2070 ImageView imageView = ImageView::New();
2071 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2072 imageView.SetProperty( ImageView::Property::IMAGE, TEST_IMAGE_FILE_NAME );
2074 Stage::GetCurrent().Add( imageView );
2076 application.SendNotification();
2077 application.Render();
2078 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2080 Renderer renderer = imageView.GetRendererAt( 0 );
2081 Shader shader2 = renderer.GetShader();
2082 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2083 Property::Map* map = value.GetMap();
2084 DALI_TEST_CHECK( map );
2086 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2087 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2089 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2090 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2093 // Set a custom shader after setting a property map
2095 Property::Map properties;
2096 Property::Map shader;
2097 const std::string vertexShader = "Foobar";
2098 const std::string fragmentShader = "Foobar";
2099 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2100 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2102 properties[Visual::Property::SHADER] = shader;
2104 Property::Map properties1;
2105 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2106 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2108 ImageView imageView = ImageView::New();
2109 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2110 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2112 Stage::GetCurrent().Add( imageView );
2114 application.SendNotification();
2115 application.Render();
2116 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2118 Renderer renderer = imageView.GetRendererAt( 0 );
2119 Shader shader2 = renderer.GetShader();
2120 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2121 Property::Map* map = value.GetMap();
2122 DALI_TEST_CHECK( map );
2124 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2125 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2127 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2128 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2131 // Set a custom shader before setting a property map
2133 Property::Map properties;
2134 Property::Map shader;
2135 const std::string vertexShader = "Foobar";
2136 const std::string fragmentShader = "Foobar";
2137 shader[Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
2138 shader[Visual::Shader::Property::VERTEX_SHADER] = vertexShader;
2140 properties[Visual::Property::SHADER] = shader;
2142 Property::Map properties1;
2143 properties1[Visual::Property::TYPE] = Visual::IMAGE;
2144 properties1[ImageVisual::Property::URL] = TEST_IMAGE_FILE_NAME;
2146 ImageView imageView = ImageView::New();
2147 imageView.SetProperty( ImageView::Property::IMAGE, properties );
2148 imageView.SetProperty( ImageView::Property::IMAGE, properties1 );
2150 Stage::GetCurrent().Add( imageView );
2152 application.SendNotification();
2153 application.Render();
2154 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2156 Renderer renderer = imageView.GetRendererAt( 0 );
2157 Shader shader2 = renderer.GetShader();
2158 Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
2159 Property::Map* map = value.GetMap();
2160 DALI_TEST_CHECK( map );
2162 Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
2163 DALI_TEST_EQUALS( fragmentShader, fragment->Get< std::string >(), TEST_LOCATION );
2165 Property::Value* vertex = map->Find( "vertex" ); // vertex key name from shader-impl.cpp
2166 DALI_TEST_EQUALS( vertexShader, vertex->Get< std::string >(), TEST_LOCATION );
2175 static int gFailCounter = 0;
2176 const int MAX_RETRIES(3);
2178 void ReloadImage(ImageView imageView)
2180 Property::Map imageImmediateLoadingMap;
2181 imageImmediateLoadingMap[ ImageVisual::Property::URL ] = "Non-existant-image.jpg";
2182 imageImmediateLoadingMap[ ImageVisual::Property::LOAD_POLICY ] = ImageVisual::LoadPolicy::IMMEDIATE;
2184 tet_infoline("Immediate load an image");
2185 imageView.SetProperty( ImageView::Property::IMAGE, imageImmediateLoadingMap );
2188 void ResourceFailedReload( Control control )
2191 if( gFailCounter < MAX_RETRIES )
2193 ReloadImage(ImageView::DownCast(control));
2198 int UtcDaliImageViewReloadFailedOnResourceReadySignal(void)
2200 tet_infoline("Test reloading failed image from within signal handler.");
2202 ToolkitTestApplication application;
2206 ImageView imageView = ImageView::New();
2207 imageView.ResourceReadySignal().Connect( &ResourceFailedReload );
2208 DALI_TEST_EQUALS( gFailCounter, 0, TEST_LOCATION );
2209 ReloadImage(imageView);
2211 // loading started, this waits for the loader thread to complete
2212 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2213 application.SendNotification();
2215 DALI_TEST_EQUALS( gFailCounter, 1, TEST_LOCATION );
2217 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2218 application.SendNotification();
2220 DALI_TEST_EQUALS( gFailCounter, 2, TEST_LOCATION );
2222 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
2223 application.SendNotification();
2224 DALI_TEST_EQUALS( gFailCounter, 3, TEST_LOCATION );