Fixups following changes to actor traversal
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageVisual.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <iostream>
18 #include <stdlib.h>
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/devel-api/controls/control-devel.h>
34 #include <dali-toolkit/dali-toolkit.h>
35 #include "dummy-control.h"
36
37 using namespace Dali;
38 using namespace Dali::Toolkit;
39
40 void dali_image_visual_startup(void)
41 {
42   test_return_value = TET_UNDEF;
43 }
44
45 void dali_image_visual_cleanup(void)
46 {
47   test_return_value = TET_PASS;
48 }
49
50 namespace
51 {
52 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR  "/gallery-small-1.jpg";
53 const char* TEST_LARGE_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/tbcol.png";
54 const char* TEST_SMALL_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/icon-edit.png";
55 const char* TEST_REMOTE_IMAGE_FILE_NAME = "https://www.tizen.org/sites/all/themes/tizen_theme/logo.png";
56 const char* TEST_INVALID_FILE_NAME =  TEST_RESOURCE_DIR  "/invalid.jpg";
57 const char* TEST_REMOTE_INVALID_FILE_NAME = "https://www.tizen.org/invalid.png";
58 const char* TEST_MASK_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/mask.png";
59 }
60
61
62 Actor CreateActorWithImageVisual(const Property::Map& map)
63 {
64   VisualFactory factory = VisualFactory::Get();
65   DummyControl actor = DummyControl::New();
66   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
67   Visual::Base visual = factory.CreateVisual( map );
68   DALI_TEST_CHECK( visual );
69   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
70   actor.SetSize( 200.f, 200.f );
71   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
72   return actor;
73 }
74
75 void TestVisualRender( ToolkitTestApplication& application,
76                        DummyControl& actor,
77                        Visual::Base& visual,
78                        std::size_t expectedSamplers = 0,
79                        ImageDimensions imageDimensions = ImageDimensions(),
80                        Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
81 {
82   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
83   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
84
85   if( resourcePtr )
86   {
87     // set the image size, for test case, this needs to be set before loading started
88     application.GetPlatform().SetClosestImageSize(  Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
89   }
90
91   actor.SetSize( 200.f, 200.f );
92   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
93
94   Stage::GetCurrent().Add( actor );
95
96   application.SendNotification(); // Send messages to update
97   application.Render();           // process update and render
98   application.SendNotification(); // process any signals to event
99
100   if( resourcePtr )
101   {
102     DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
103   }
104
105   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
106 }
107
108 static void TestMixColor( Visual::Base visual, Property::Index mixColorIndex, const Vector4& testColor )
109 {
110   Property::Map map;
111   visual.CreatePropertyMap(map);
112   Property::Value* value = map.Find( mixColorIndex );
113   DALI_TEST_CHECK( value );
114   Vector3 mixColor1;
115   DALI_TEST_CHECK( value->Get( mixColor1 ) );
116   DALI_TEST_EQUALS( mixColor1, Vector3(testColor), 0.001, TEST_LOCATION );
117
118   value = map.Find( DevelVisual::Property::MIX_COLOR );
119   DALI_TEST_CHECK( value );
120   Vector4 mixColor2;
121   DALI_TEST_CHECK( value->Get( mixColor2 ) );
122   DALI_TEST_EQUALS( mixColor2, testColor, 0.001, TEST_LOCATION );
123
124   value = map.Find( DevelVisual::Property::OPACITY );
125   DALI_TEST_CHECK( value );
126   float opacity;
127   DALI_TEST_CHECK( value->Get( opacity ) );
128   DALI_TEST_EQUALS( opacity, testColor.a, 0.001, TEST_LOCATION );
129 }
130
131
132
133 int UtcDaliImageVisualPropertyMap(void)
134 {
135   ToolkitTestApplication application;
136   tet_infoline( "Request image visual with a Property::Map" );
137
138   VisualFactory factory = VisualFactory::Get();
139   DALI_TEST_CHECK( factory );
140
141   Property::Map propertyMap;
142   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
143   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
144
145   Visual::Base visual = factory.CreateVisual( propertyMap );
146   DALI_TEST_CHECK( visual );
147
148   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
149   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
150
151   TestGlAbstraction& gl = application.GetGlAbstraction();
152   TraceCallStack& textureTrace = gl.GetTextureTrace();
153   textureTrace.Enable(true);
154
155   DummyControl actor = DummyControl::New();
156   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
157   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
158
159   actor.SetSize( 200.f, 200.f );
160   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
161
162   Stage::GetCurrent().Add( actor );
163   application.SendNotification();
164   application.Render();
165
166   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
167
168   application.SendNotification();
169   application.Render();
170
171   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
172
173   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
174
175   Stage::GetCurrent().Remove( actor );
176   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
177
178   END_TEST;
179 }
180
181
182 int UtcDaliImageVisualRemoteImageLoad(void)
183 {
184   ToolkitTestApplication application;
185   tet_infoline( "Request remote image visual with a Property::Map" );
186
187   VisualFactory factory = VisualFactory::Get();
188   DALI_TEST_CHECK( factory );
189
190   Property::Map propertyMap;
191   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
192   propertyMap.Insert( ImageVisual::Property::URL,  TEST_REMOTE_IMAGE_FILE_NAME );
193
194   Visual::Base visual = factory.CreateVisual( propertyMap );
195   DALI_TEST_CHECK( visual );
196
197   TestGlAbstraction& gl = application.GetGlAbstraction();
198   TraceCallStack& textureTrace = gl.GetTextureTrace();
199   textureTrace.Enable(true);
200
201   DummyControl actor = DummyControl::New();
202   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
203   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
204
205   actor.SetSize( 200.f, 200.f );
206   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
207
208   Stage::GetCurrent().Add( actor );
209   application.SendNotification();
210
211   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
212
213   application.SendNotification();
214   application.Render();
215
216   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
217   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
218
219   Stage::GetCurrent().Remove( actor );
220   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
221
222   END_TEST;
223 }
224
225 int UtcDaliImageVisualTextureReuse1(void)
226 {
227   ToolkitTestApplication application;
228   tet_infoline( "Request remote image visual with a Property::Map; request a second visual with the same property map - should reuse texture" );
229
230   Property::Map propertyMap;
231   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
232   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
233
234   TestGlAbstraction& gl = application.GetGlAbstraction();
235   TraceCallStack& textureTrace = gl.GetTextureTrace();
236   textureTrace.Enable(true);
237   TraceCallStack& drawTrace = gl.GetDrawTrace();
238   drawTrace.Enable(true);
239
240   Actor actor = CreateActorWithImageVisual( propertyMap );
241   Stage::GetCurrent().Add( actor );
242   application.SendNotification();
243
244   // Wait for image to load
245   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
246
247   application.SendNotification();
248   application.Render();
249
250   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
251   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
252   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
253   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
254   textureTrace.Reset();
255   drawTrace.Reset();
256
257   Actor actor2 = CreateActorWithImageVisual( propertyMap );
258   Stage::GetCurrent().Add(actor2);
259
260   application.SendNotification(); // Send messages to update
261   application.Render();           // process update and render
262   application.SendNotification(); // process any signals to event
263
264   DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
265
266   tet_infoline("Test that 2 draw calls occur with no new texture gens/binds, i.e. both\n"
267                "draw calls use the same texture as the previous draw call\n" );
268
269   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
270   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
271   DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION );
272
273   tet_infoline("Test that removing 1 actor doesn't delete the texture\n");
274
275   Stage::GetCurrent().Remove( actor );
276   application.SendNotification();
277   application.Render();
278
279   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
280   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
281
282   tet_infoline("Test that removing last actor does delete the texture\n");
283
284   Stage::GetCurrent().Remove( actor2 );
285   application.SendNotification();
286   application.Render();
287
288   DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
289   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
290
291   END_TEST;
292 }
293
294
295 int UtcDaliImageVisualTextureReuse2(void)
296 {
297   ToolkitTestApplication application;
298   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" );
299
300   Property::Map propertyMap;
301   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
302   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
303
304   TestGlAbstraction& gl = application.GetGlAbstraction();
305   TraceCallStack& textureTrace = gl.GetTextureTrace();
306   textureTrace.Enable(true);
307   TraceCallStack& drawTrace = gl.GetDrawTrace();
308   drawTrace.Enable(true);
309
310   Actor actor = CreateActorWithImageVisual( propertyMap );
311   Stage::GetCurrent().Add( actor );
312   application.SendNotification();
313
314   // Wait for image to load
315   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
316
317   application.SendNotification();
318   application.Render();
319
320   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
321   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
322   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
323   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
324   textureTrace.Reset();
325   drawTrace.Reset();
326
327   propertyMap.Insert( ImageVisual::Property::SAMPLING_MODE, Dali::SamplingMode::NEAREST );
328   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, 100 );
329   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, 100 );
330   Actor actor2 = CreateActorWithImageVisual( propertyMap );
331   Stage::GetCurrent().Add(actor2);
332
333   application.SendNotification();
334
335   // Wait for image to load
336   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
337
338   application.SendNotification();
339   application.Render();
340
341   DALI_TEST_EQUALS( actor2.GetRendererCount(), 1u, TEST_LOCATION );
342
343   tet_infoline("Test that 2 draw calls occur with 1 new texture gen/bind, i.e. both "
344                "renderers are using different textures\n" );
345
346   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
347   DALI_TEST_EQUALS( drawTrace.CountMethod("DrawArrays"), 2, TEST_LOCATION );
348   TraceCallStack::NamedParams tex1;
349   tex1["texture"] = "1";
350   TraceCallStack::NamedParams tex2;
351   tex1["texture"] = "2";
352   DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex1), true, TEST_LOCATION );
353   DALI_TEST_EQUALS( textureTrace.FindMethodAndParams("BindTexture", tex2), true, TEST_LOCATION );
354
355   tet_infoline("Test that removing 1 actor deletes it's texture\n");
356
357   Stage::GetCurrent().Remove( actor );
358   application.SendNotification();
359   application.Render();
360
361   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
362   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
363
364   tet_infoline("Test that removing last actor deletes it's texture\n");
365
366   Stage::GetCurrent().Remove( actor2 );
367   application.SendNotification();
368   application.Render();
369
370   DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
371   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
372
373   END_TEST;
374 }
375
376
377 int UtcDaliImageVisualImageHandle(void)
378 {
379   ToolkitTestApplication application;
380   tet_infoline( "Request image visual with an image handle" );
381
382   VisualFactory factory = VisualFactory::Get();
383   DALI_TEST_CHECK( factory );
384
385   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
386   Visual::Base visual = factory.CreateVisual( image );
387
388   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
389   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
390
391   const int width=512;
392   const int height=513;
393
394   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
395   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
396
397   TestGlAbstraction& gl = application.GetGlAbstraction();
398   TraceCallStack& textureTrace = gl.GetTextureTrace();
399   textureTrace.Enable(true);
400
401   DummyControl actor = DummyControl::New();
402   TestVisualRender( application, actor, visual, 1u,
403                     ImageDimensions(width, height),
404                     Integration::ResourcePointer(bitmap) );
405
406   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
407   END_TEST;
408 }
409
410 int UtcDaliImageVisualCustomWrapModePixelArea(void)
411 {
412   ToolkitTestApplication application;
413   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
414
415   VisualFactory factory = VisualFactory::Get();
416   DALI_TEST_CHECK( factory );
417
418   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
419   const int width=34;
420   const int height=34;
421   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
422
423   Property::Map propertyMap;
424   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
425   propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
426   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
427   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
428   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
429   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
430   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
431   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
432   propertyMap.Insert( DevelImageVisual::Property::ATLASING, true );
433
434   Visual::Base visual = factory.CreateVisual( propertyMap );
435   DALI_TEST_CHECK( visual );
436
437   TestGlAbstraction& gl = application.GetGlAbstraction();
438   TraceCallStack& textureTrace = gl.GetTextureTrace();
439   textureTrace.Enable(true);
440   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
441   texParameterTrace.Enable( true );
442
443   DummyControl actor = DummyControl::New();
444   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
445   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
446   actor.SetSize(2000, 2000);
447   actor.SetParentOrigin(ParentOrigin::CENTER);
448   Stage::GetCurrent().Add( actor );
449
450   // loading started
451   application.SendNotification();
452   application.Render();
453
454   BitmapLoader loader = BitmapLoader::GetLatestCreated();
455   DALI_TEST_CHECK( loader );
456   loader.WaitForLoading();// waiting until the image to be loaded
457   DALI_TEST_CHECK( loader.IsLoaded() );
458
459   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
460
461   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
462
463   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
464   std::stringstream out;
465   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
466   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
467   out.str("");
468   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
469   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
470
471   // test the uniforms which used to handle the wrap mode
472   Renderer renderer = actor.GetRendererAt( 0u );
473   DALI_TEST_CHECK( renderer );
474
475   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
476   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
477   Vector4 pixelAreaUniform;
478   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
479   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
480
481   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
482   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
483   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
484   Vector2 wrapModeUniform;
485   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
486   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
487
488   actor.Unparent( );
489   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
490
491   END_TEST;
492 }
493
494 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
495 {
496   ToolkitTestApplication application;
497   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
498
499   VisualFactory factory = VisualFactory::Get();
500   DALI_TEST_CHECK( factory );
501
502   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
503   const int width=600;
504   const int height=600;
505   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
506
507   Property::Map propertyMap;
508   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
509   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
510   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
511   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
512   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
513   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
514   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
515   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
516
517   Visual::Base visual = factory.CreateVisual( propertyMap );
518   DALI_TEST_CHECK( visual );
519
520   TestGlAbstraction& gl = application.GetGlAbstraction();
521   TraceCallStack& textureTrace = gl.GetTextureTrace();
522   textureTrace.Enable(true);
523   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
524   texParameterTrace.Enable( true );
525
526   DummyControl actor = DummyControl::New();
527   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
528   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
529   actor.SetSize(2000, 2000);
530   actor.SetParentOrigin(ParentOrigin::CENTER);
531   Stage::GetCurrent().Add( actor );
532
533   // loading started
534   application.SendNotification();
535   application.Render();
536
537   BitmapLoader loader = BitmapLoader::GetLatestCreated();
538   DALI_TEST_CHECK( loader );
539   loader.WaitForLoading();// waiting until the image to be loaded
540   DALI_TEST_CHECK( loader.IsLoaded() );
541
542   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
543
544   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
545
546   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
547   std::stringstream out;
548   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
549   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
550   out.str("");
551   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
552   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
553
554   // test the uniforms which used to handle the wrap mode
555   Renderer renderer = actor.GetRendererAt( 0u );
556   DALI_TEST_CHECK( renderer );
557
558   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
559   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
560   Vector4 pixelAreaUniform;
561   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
562   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
563
564   Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
565   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
566
567   actor.Unparent();
568   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
569
570   END_TEST;
571 }
572
573 int UtcDaliImageVisualAnimateMixColor(void)
574 {
575   ToolkitTestApplication application;
576   tet_infoline( "Animate mix color" );
577
578   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
579
580   VisualFactory factory = VisualFactory::Get();
581   Property::Map propertyMap;
582   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
583   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
584   propertyMap.Insert("mixColor", Color::BLUE);
585   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
586   Visual::Base visual = factory.CreateVisual( propertyMap );
587
588   DummyControl actor = DummyControl::New(true);
589   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
590   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
591
592   actor.SetSize(2000, 2000);
593   actor.SetParentOrigin(ParentOrigin::CENTER);
594   actor.SetColor(Color::BLACK);
595   Stage::GetCurrent().Add(actor);
596
597   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
598
599   Renderer renderer = actor.GetRendererAt(0);
600   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
601   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
602   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
603
604   tet_infoline("Test that the renderer has the mixColor property");
605   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
606
607   const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
608
609   Property::Map map;
610   map["target"] = "testVisual";
611   map["property"] = "mixColor";
612   map["initialValue"] = Color::MAGENTA;
613   map["targetValue"] = TARGET_MIX_COLOR;
614   map["animator"] = Property::Map()
615     .Add("alphaFunction", "LINEAR")
616     .Add("timePeriod", Property::Map()
617          .Add("delay", 0.0f)
618          .Add("duration", 4.0f));
619
620   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
621
622   Animation animation = dummyImpl.CreateTransition( transition );
623
624   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
625   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
626
627   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
628   animation.Play();
629
630   application.SendNotification();
631   application.Render(0); // Ensure animation starts
632   application.Render(2000u); // Halfway point
633   Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
634
635   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
636   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
637   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
638
639   application.Render(2000u); // Halfway point between blue and white
640
641   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
642   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
643   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
644   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
645
646   TestMixColor( visual, DevelVisual::Property::MIX_COLOR, TARGET_MIX_COLOR );
647
648   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
649   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
650
651   END_TEST;
652 }
653
654 int UtcDaliImageVisualAnimateOpacity(void)
655 {
656   ToolkitTestApplication application;
657   tet_infoline( "Animate image visual opacity" );
658
659   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
660
661   VisualFactory factory = VisualFactory::Get();
662   Property::Map propertyMap;
663   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
664   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
665   propertyMap.Insert("opacity", 0.5f);
666   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
667   Visual::Base visual = factory.CreateVisual( propertyMap );
668
669   DummyControl actor = DummyControl::New(true);
670   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
671   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
672
673   actor.SetSize(2000, 2000);
674   actor.SetParentOrigin(ParentOrigin::CENTER);
675   actor.SetColor(Color::BLACK);
676   Stage::GetCurrent().Add(actor);
677
678   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
679
680   Renderer renderer = actor.GetRendererAt(0);
681   tet_infoline("Test that the renderer has the opacity property");
682   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
683   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
684
685
686   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
687   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
688
689   {
690     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." );
691
692     Property::Map map;
693     map["target"] = "testVisual";
694     map["property"] = "opacity";
695     map["targetValue"] = 1.0f;
696     map["animator"] = Property::Map()
697       .Add("alphaFunction", "LINEAR")
698       .Add("timePeriod", Property::Map()
699            .Add("delay", 0.0f)
700            .Add("duration", 4.0f));
701
702     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
703     Animation animation = dummyImpl.CreateTransition( transition );
704     animation.Play();
705
706     application.SendNotification();
707     application.Render(0);     // Ensure animation starts
708     application.Render(2000u); // Halfway point through animation
709     application.SendNotification(); // Handle any signals
710
711     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
712
713     application.Render(2001u); // end
714     application.SendNotification(); // ensure animation finished signal is sent
715
716     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
717
718     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
719     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
720   }
721
722
723   {
724     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." );
725
726     Property::Map map;
727     map["target"] = "testVisual";
728     map["property"] = DevelVisual::Property::OPACITY;
729     map["targetValue"] = 0.1f;
730     map["animator"] = Property::Map()
731       .Add("alphaFunction", "LINEAR")
732       .Add("timePeriod", Property::Map()
733            .Add("delay", 0.0f)
734            .Add("duration", 4.0f));
735
736     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
737     Animation animation = dummyImpl.CreateTransition( transition );
738     animation.Play();
739
740     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
741     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
742
743     application.SendNotification();
744     application.Render(0);     // Ensure animation starts
745     application.Render(2000u); // Halfway point
746     application.SendNotification();
747
748     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
749
750     application.Render(2016u); // end
751     application.SendNotification();
752
753     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
754
755     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
756     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
757   }
758
759
760   END_TEST;
761 }
762
763 int UtcDaliImageVisualAnimatePixelArea(void)
764 {
765   ToolkitTestApplication application;
766   tet_infoline( "ImageVisual animate pixel area" );
767
768   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
769
770   VisualFactory factory = VisualFactory::Get();
771   Property::Map propertyMap;
772   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
773   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
774   propertyMap.Insert("mixColor", Color::BLUE);
775   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
776   Visual::Base visual = factory.CreateVisual( propertyMap );
777
778   DummyControl actor = DummyControl::New(true);
779   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
780   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
781
782   actor.SetSize(2000, 2000);
783   actor.SetParentOrigin(ParentOrigin::CENTER);
784   actor.SetColor(Color::BLACK);
785   Stage::GetCurrent().Add(actor);
786
787   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
788
789   Renderer renderer = actor.GetRendererAt(0);
790   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
791
792   tet_infoline("Test that the renderer has the mixColor property");
793   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
794
795   // TransitionData only takes string keys
796   Property::Map map;
797   map["target"] = "testVisual";
798   map["property"] = "pixelArea";
799   map["initialValue"] = Vector4( 0,0,0,1 );
800   map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
801   map["animator"] = Property::Map()
802     .Add("alphaFunction", "LINEAR")
803     .Add("timePeriod", Property::Map()
804          .Add("delay", 0.0f)
805          .Add("duration", 4.0f));
806
807   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
808
809   Animation animation = dummyImpl.CreateTransition( transition );
810   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
811   animation.Play();
812
813   application.SendNotification();
814   application.Render(0);     // Ensure animation starts
815   application.Render(2000u); // Halfway point
816
817   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
818
819   application.Render(2000u); // End of animation
820
821   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
822
823   END_TEST;
824 }
825
826 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
827 {
828   ToolkitTestApplication application;
829   tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
830
831   Property::Map propertyMap;
832   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
833   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
834
835   TestGlAbstraction& gl = application.GetGlAbstraction();
836   TraceCallStack& textureTrace = gl.GetTextureTrace();
837   textureTrace.Enable(true);
838   TraceCallStack& drawTrace = gl.GetDrawTrace();
839   drawTrace.Enable(true);
840
841   Actor actor = CreateActorWithImageVisual( propertyMap );
842   Stage::GetCurrent().Add( actor );
843   application.SendNotification();
844
845   Stage::GetCurrent().Remove( actor );
846   application.SendNotification();
847
848   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
849   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
850   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
851   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
852
853   END_TEST;
854 }
855
856 int UtcDaliImageVisualSetInvalidAsyncImage(void)
857 {
858   ToolkitTestApplication application;
859   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
860
861   VisualFactory factory = VisualFactory::Get();
862   DALI_TEST_CHECK( factory );
863
864   Property::Map propertyMap;
865   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
866   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
867
868   Visual::Base visual = factory.CreateVisual( propertyMap );
869   DALI_TEST_CHECK( visual );
870
871   TestGlAbstraction& gl = application.GetGlAbstraction();
872   TraceCallStack& textureTrace = gl.GetTextureTrace();
873   textureTrace.Enable(true);
874
875   DummyControl actor = DummyControl::New();
876   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
877   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
878
879   actor.SetSize( 200.f, 200.f );
880   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
881
882   Stage::GetCurrent().Add( actor );
883
884   application.SendNotification();
885   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
886
887   application.SendNotification();
888   application.Render();
889
890   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
891   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
892
893   Stage::GetCurrent().Remove( actor );
894   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
895
896   END_TEST;
897 }
898
899 int UtcDaliImageVisualSetInvalidSyncImage(void)
900 {
901   ToolkitTestApplication application;
902   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
903
904   VisualFactory factory = VisualFactory::Get();
905   DALI_TEST_CHECK( factory );
906
907   Property::Map propertyMap;
908   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
909   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
910   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
911
912   Visual::Base visual = factory.CreateVisual( propertyMap );
913   DALI_TEST_CHECK( visual );
914
915   TestGlAbstraction& gl = application.GetGlAbstraction();
916   TraceCallStack& textureTrace = gl.GetTextureTrace();
917   textureTrace.Enable(true);
918
919   DummyControl actor = DummyControl::New();
920   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
921   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
922
923   actor.SetSize( 200.f, 200.f );
924   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
925
926   Stage::GetCurrent().Add( actor );
927
928   application.SendNotification();
929   application.Render();
930
931   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
932   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
933
934   Stage::GetCurrent().Remove( actor );
935   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
936
937   END_TEST;
938 }
939
940 int UtcDaliImageVisualSetInvalidRemoteImage(void)
941 {
942   ToolkitTestApplication application;
943   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
944
945   VisualFactory factory = VisualFactory::Get();
946   DALI_TEST_CHECK( factory );
947
948   // Local invalid file, asynchronous loading
949   Property::Map propertyMap;
950   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
951   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
952
953   Visual::Base visual = factory.CreateVisual( propertyMap );
954   DALI_TEST_CHECK( visual );
955
956   TestGlAbstraction& gl = application.GetGlAbstraction();
957   TraceCallStack& textureTrace = gl.GetTextureTrace();
958   textureTrace.Enable(true);
959
960   DummyControl actor = DummyControl::New();
961   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
962   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
963
964   actor.SetSize( 200.f, 200.f );
965   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
966
967   Stage::GetCurrent().Add( actor );
968
969   application.SendNotification();
970   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
971
972   application.SendNotification();
973   application.Render();
974
975   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
976   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
977
978   Stage::GetCurrent().Remove( actor );
979   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
980
981   END_TEST;
982 }
983
984 int UtcDaliImageVisualAlphaMask(void)
985 {
986   ToolkitTestApplication application;
987   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
988
989   VisualFactory factory = VisualFactory::Get();
990   DALI_TEST_CHECK( factory );
991
992   Property::Map propertyMap;
993   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
994   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
995   propertyMap.Insert( DevelImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
996
997   Visual::Base visual = factory.CreateVisual( propertyMap );
998   DALI_TEST_CHECK( visual );
999
1000   Property::Map testMap;
1001   visual.CreatePropertyMap(testMap);
1002   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
1003
1004   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1005   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1006
1007   TestGlAbstraction& gl = application.GetGlAbstraction();
1008   TraceCallStack& textureTrace = gl.GetTextureTrace();
1009   textureTrace.Enable(true);
1010
1011   DummyControl actor = DummyControl::New();
1012   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1013   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1014
1015   actor.SetSize( 200.f, 200.f );
1016   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1017   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), false, TEST_LOCATION );
1018
1019   Stage::GetCurrent().Add( actor );
1020   application.SendNotification();
1021   application.Render();
1022
1023   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1024
1025   application.SendNotification();
1026   application.Render();
1027
1028   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1029   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1030   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), true, TEST_LOCATION );
1031
1032   END_TEST;
1033 }
1034
1035 int UtcDaliImageVisualRemoteAlphaMask(void)
1036 {
1037   ToolkitTestApplication application;
1038   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1039
1040   VisualFactory factory = VisualFactory::Get();
1041   DALI_TEST_CHECK( factory );
1042
1043   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1044
1045   Property::Map propertyMap;
1046   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1047   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1048   propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1049
1050   Visual::Base visual = factory.CreateVisual( propertyMap );
1051   DALI_TEST_CHECK( visual );
1052
1053   Property::Map testMap;
1054   visual.CreatePropertyMap(testMap);
1055   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1056
1057   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1058   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1059
1060   TestGlAbstraction& gl = application.GetGlAbstraction();
1061   TraceCallStack& textureTrace = gl.GetTextureTrace();
1062   textureTrace.Enable(true);
1063
1064   DummyControl actor = DummyControl::New();
1065   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1066   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1067   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), false, TEST_LOCATION );
1068
1069   actor.SetSize( 200.f, 200.f );
1070   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1071
1072   Stage::GetCurrent().Add( actor );
1073   application.SendNotification();
1074   application.Render();
1075
1076   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1077
1078   application.SendNotification();
1079   application.Render();
1080
1081   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1082   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1083   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), true, TEST_LOCATION );
1084
1085   END_TEST;
1086 }