Updated ImageVisual to handle CPU Image Masking
[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   DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 2, TEST_LOCATION );
349
350   tet_infoline("Test that removing 1 actor deletes it's texture\n");
351
352   Stage::GetCurrent().Remove( actor );
353   application.SendNotification();
354   application.Render();
355
356   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
357   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
358
359   tet_infoline("Test that removing last actor deletes it's texture\n");
360
361   Stage::GetCurrent().Remove( actor2 );
362   application.SendNotification();
363   application.Render();
364
365   DALI_TEST_CHECK( actor2.GetRendererCount() == 0u );
366   DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 2, TEST_LOCATION );
367
368   END_TEST;
369 }
370
371
372 int UtcDaliImageVisualImageHandle(void)
373 {
374   ToolkitTestApplication application;
375   tet_infoline( "Request image visual with an image handle" );
376
377   VisualFactory factory = VisualFactory::Get();
378   DALI_TEST_CHECK( factory );
379
380   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
381   Visual::Base visual = factory.CreateVisual( image );
382
383   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
384   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
385
386   const int width=512;
387   const int height=513;
388
389   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
390   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
391
392   TestGlAbstraction& gl = application.GetGlAbstraction();
393   TraceCallStack& textureTrace = gl.GetTextureTrace();
394   textureTrace.Enable(true);
395
396   DummyControl actor = DummyControl::New();
397   TestVisualRender( application, actor, visual, 1u,
398                     ImageDimensions(width, height),
399                     Integration::ResourcePointer(bitmap) );
400
401   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
402   END_TEST;
403 }
404
405 int UtcDaliImageVisualCustomWrapModePixelArea(void)
406 {
407   ToolkitTestApplication application;
408   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
409
410   VisualFactory factory = VisualFactory::Get();
411   DALI_TEST_CHECK( factory );
412
413   // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
414   const int width=34;
415   const int height=34;
416   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
417
418   Property::Map propertyMap;
419   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
420   propertyMap.Insert( ImageVisual::Property::URL, TEST_SMALL_IMAGE_FILE_NAME );
421   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
422   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
423   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
424   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
425   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
426   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
427   propertyMap.Insert( DevelImageVisual::Property::ATLASING, true );
428
429   Visual::Base visual = factory.CreateVisual( propertyMap );
430   DALI_TEST_CHECK( visual );
431
432   TestGlAbstraction& gl = application.GetGlAbstraction();
433   TraceCallStack& textureTrace = gl.GetTextureTrace();
434   textureTrace.Enable(true);
435   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
436   texParameterTrace.Enable( true );
437
438   DummyControl actor = DummyControl::New();
439   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
440   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
441   actor.SetSize(2000, 2000);
442   actor.SetParentOrigin(ParentOrigin::CENTER);
443   Stage::GetCurrent().Add( actor );
444
445   // loading started
446   application.SendNotification();
447   application.Render();
448
449   BitmapLoader loader = BitmapLoader::GetLatestCreated();
450   DALI_TEST_CHECK( loader );
451   loader.WaitForLoading();// waiting until the image to be loaded
452   DALI_TEST_CHECK( loader.IsLoaded() );
453
454   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
455
456   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
457
458   // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
459   std::stringstream out;
460   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
461   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
462   out.str("");
463   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
464   DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
465
466   // test the uniforms which used to handle the wrap mode
467   Renderer renderer = actor.GetRendererAt( 0u );
468   DALI_TEST_CHECK( renderer );
469
470   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
471   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
472   Vector4 pixelAreaUniform;
473   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
474   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
475
476   Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
477   Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
478   DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
479   Vector2 wrapModeUniform;
480   DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
481   DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
482
483   actor.Unparent( );
484   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
485
486   END_TEST;
487 }
488
489 int UtcDaliImageVisualCustomWrapModeNoAtlas(void)
490 {
491   ToolkitTestApplication application;
492   tet_infoline( "Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
493
494   VisualFactory factory = VisualFactory::Get();
495   DALI_TEST_CHECK( factory );
496
497   // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
498   const int width=600;
499   const int height=600;
500   const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
501
502   Property::Map propertyMap;
503   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
504   propertyMap.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
505   propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
506   propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
507   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
508   propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
509   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
510   propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
511
512   Visual::Base visual = factory.CreateVisual( propertyMap );
513   DALI_TEST_CHECK( visual );
514
515   TestGlAbstraction& gl = application.GetGlAbstraction();
516   TraceCallStack& textureTrace = gl.GetTextureTrace();
517   textureTrace.Enable(true);
518   TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
519   texParameterTrace.Enable( true );
520
521   DummyControl actor = DummyControl::New();
522   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
523   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
524   actor.SetSize(2000, 2000);
525   actor.SetParentOrigin(ParentOrigin::CENTER);
526   Stage::GetCurrent().Add( actor );
527
528   // loading started
529   application.SendNotification();
530   application.Render();
531
532   BitmapLoader loader = BitmapLoader::GetLatestCreated();
533   DALI_TEST_CHECK( loader );
534   loader.WaitForLoading();// waiting until the image to be loaded
535   DALI_TEST_CHECK( loader.IsLoaded() );
536
537   DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
538
539   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
540
541   // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
542   std::stringstream out;
543   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
544   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
545   out.str("");
546   out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
547   DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
548
549   // test the uniforms which used to handle the wrap mode
550   Renderer renderer = actor.GetRendererAt( 0u );
551   DALI_TEST_CHECK( renderer );
552
553   Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
554   DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
555   Vector4 pixelAreaUniform;
556   DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
557   DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
558
559   Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
560   DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
561
562   actor.Unparent();
563   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
564
565   END_TEST;
566 }
567
568 int UtcDaliImageVisualAnimateMixColor(void)
569 {
570   ToolkitTestApplication application;
571   tet_infoline( "Animate mix color" );
572
573   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
574
575   VisualFactory factory = VisualFactory::Get();
576   Property::Map propertyMap;
577   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
578   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
579   propertyMap.Insert("mixColor", Color::BLUE);
580   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
581   Visual::Base visual = factory.CreateVisual( propertyMap );
582
583   DummyControl actor = DummyControl::New(true);
584   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
585   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
586
587   actor.SetSize(2000, 2000);
588   actor.SetParentOrigin(ParentOrigin::CENTER);
589   actor.SetColor(Color::BLACK);
590   Stage::GetCurrent().Add(actor);
591
592   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
593
594   Renderer renderer = actor.GetRendererAt(0);
595   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
596   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
597   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
598
599   tet_infoline("Test that the renderer has the mixColor property");
600   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
601
602   const Vector4 TARGET_MIX_COLOR( 1.0f, 0.0f, 0.0f, 0.5f );
603
604   Property::Map map;
605   map["target"] = "testVisual";
606   map["property"] = "mixColor";
607   map["initialValue"] = Color::MAGENTA;
608   map["targetValue"] = TARGET_MIX_COLOR;
609   map["animator"] = Property::Map()
610     .Add("alphaFunction", "LINEAR")
611     .Add("timePeriod", Property::Map()
612          .Add("delay", 0.0f)
613          .Add("duration", 4.0f));
614
615   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
616
617   Animation animation = dummyImpl.CreateTransition( transition );
618
619   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
620   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
621
622   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
623   animation.Play();
624
625   application.SendNotification();
626   application.Render(0); // Ensure animation starts
627   application.Render(2000u); // Halfway point
628   Vector4 testColor(1.0f, 0.0f, 0.5f, 0.75f );
629
630   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Vector4(0.5f, 0.5f, 0.5f, 1.0f )), true, TEST_LOCATION );
631   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(testColor)), true, TEST_LOCATION );
632   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", testColor.a), true, TEST_LOCATION );
633
634   application.Render(2000u); // Halfway point between blue and white
635
636   DALI_TEST_EQUALS( actor.GetCurrentColor(), Color::WHITE, TEST_LOCATION );
637   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("uColor", Color::WHITE ), true, TEST_LOCATION );
638   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector3>("mixColor", Vector3(TARGET_MIX_COLOR)), true, TEST_LOCATION );
639   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", TARGET_MIX_COLOR.a), true, TEST_LOCATION );
640
641   TestMixColor( visual, DevelVisual::Property::MIX_COLOR, TARGET_MIX_COLOR );
642
643   blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
644   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
645
646   END_TEST;
647 }
648
649 int UtcDaliImageVisualAnimateOpacity(void)
650 {
651   ToolkitTestApplication application;
652   tet_infoline( "Animate image visual opacity" );
653
654   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
655
656   VisualFactory factory = VisualFactory::Get();
657   Property::Map propertyMap;
658   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
659   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
660   propertyMap.Insert("opacity", 0.5f);
661   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
662   Visual::Base visual = factory.CreateVisual( propertyMap );
663
664   DummyControl actor = DummyControl::New(true);
665   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
666   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
667
668   actor.SetSize(2000, 2000);
669   actor.SetParentOrigin(ParentOrigin::CENTER);
670   actor.SetColor(Color::BLACK);
671   Stage::GetCurrent().Add(actor);
672
673   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
674
675   Renderer renderer = actor.GetRendererAt(0);
676   tet_infoline("Test that the renderer has the opacity property");
677   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::OPACITY );
678   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
679
680
681   Property::Value blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
682   DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
683
684   {
685     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." );
686
687     Property::Map map;
688     map["target"] = "testVisual";
689     map["property"] = "opacity";
690     map["targetValue"] = 1.0f;
691     map["animator"] = Property::Map()
692       .Add("alphaFunction", "LINEAR")
693       .Add("timePeriod", Property::Map()
694            .Add("delay", 0.0f)
695            .Add("duration", 4.0f));
696
697     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
698     Animation animation = dummyImpl.CreateTransition( transition );
699     animation.Play();
700
701     application.SendNotification();
702     application.Render(0);     // Ensure animation starts
703     application.Render(2000u); // Halfway point through animation
704     application.SendNotification(); // Handle any signals
705
706     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.75f), true, TEST_LOCATION );
707
708     application.Render(2001u); // end
709     application.SendNotification(); // ensure animation finished signal is sent
710
711     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 1.0f), true, TEST_LOCATION );
712
713     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
714     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::AUTO, TEST_LOCATION );
715   }
716
717
718   {
719     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." );
720
721     Property::Map map;
722     map["target"] = "testVisual";
723     map["property"] = DevelVisual::Property::OPACITY;
724     map["targetValue"] = 0.1f;
725     map["animator"] = Property::Map()
726       .Add("alphaFunction", "LINEAR")
727       .Add("timePeriod", Property::Map()
728            .Add("delay", 0.0f)
729            .Add("duration", 4.0f));
730
731     Dali::Toolkit::TransitionData transition = TransitionData::New( map );
732     Animation animation = dummyImpl.CreateTransition( transition );
733     animation.Play();
734
735     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
736     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
737
738     application.SendNotification();
739     application.Render(0);     // Ensure animation starts
740     application.Render(2000u); // Halfway point
741     application.SendNotification();
742
743     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.55f), true, TEST_LOCATION );
744
745     application.Render(2016u); // end
746     application.SendNotification();
747
748     DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<float>("opacity", 0.1f), true, TEST_LOCATION );
749
750     blendModeValue = renderer.GetProperty( Renderer::Property::BLEND_MODE );
751     DALI_TEST_EQUALS( blendModeValue.Get<int>(), (int)BlendMode::ON, TEST_LOCATION );
752   }
753
754
755   END_TEST;
756 }
757
758 int UtcDaliImageVisualAnimatePixelArea(void)
759 {
760   ToolkitTestApplication application;
761   tet_infoline( "ImageVisual animate pixel area" );
762
763   application.GetPlatform().SetClosestImageSize( Vector2(100, 100) );
764
765   VisualFactory factory = VisualFactory::Get();
766   Property::Map propertyMap;
767   propertyMap.Insert(Visual::Property::TYPE,  Visual::IMAGE);
768   propertyMap.Insert(ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
769   propertyMap.Insert("mixColor", Color::BLUE);
770   propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
771   Visual::Base visual = factory.CreateVisual( propertyMap );
772
773   DummyControl actor = DummyControl::New(true);
774   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(actor.GetImplementation());
775   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual );
776
777   actor.SetSize(2000, 2000);
778   actor.SetParentOrigin(ParentOrigin::CENTER);
779   actor.SetColor(Color::BLACK);
780   Stage::GetCurrent().Add(actor);
781
782   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION);
783
784   Renderer renderer = actor.GetRendererAt(0);
785   Property::Index index = DevelHandle::GetPropertyIndex( renderer, DevelVisual::Property::MIX_COLOR );
786
787   tet_infoline("Test that the renderer has the mixColor property");
788   DALI_TEST_CHECK( index != Property::INVALID_INDEX );
789
790   // TransitionData only takes string keys
791   Property::Map map;
792   map["target"] = "testVisual";
793   map["property"] = "pixelArea";
794   map["initialValue"] = Vector4( 0,0,0,1 );
795   map["targetValue"] = Vector4( 0,0,1,1 ); // Animate width from zero to full
796   map["animator"] = Property::Map()
797     .Add("alphaFunction", "LINEAR")
798     .Add("timePeriod", Property::Map()
799          .Add("delay", 0.0f)
800          .Add("duration", 4.0f));
801
802   Dali::Toolkit::TransitionData transition = TransitionData::New( map );
803
804   Animation animation = dummyImpl.CreateTransition( transition );
805   animation.AnimateTo( Property(actor, Actor::Property::COLOR), Color::WHITE );
806   animation.Play();
807
808   application.SendNotification();
809   application.Render(0);     // Ensure animation starts
810   application.Render(2000u); // Halfway point
811
812   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4(0.0f, 0.0f, 0.5f, 1.0f )), true, TEST_LOCATION );
813
814   application.Render(2000u); // End of animation
815
816   DALI_TEST_EQUALS( application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", Vector4( 0.0f, 0.0f, 1.0f, 1.0f )), true, TEST_LOCATION );
817
818   END_TEST;
819 }
820
821 int UtcDaliImageVisualTextureCancelRemoteLoad(void)
822 {
823   ToolkitTestApplication application;
824   tet_infoline( "Request remote image visual, then destroy visual to cancel load" );
825
826   Property::Map propertyMap;
827   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
828   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_IMAGE_FILE_NAME );
829
830   TestGlAbstraction& gl = application.GetGlAbstraction();
831   TraceCallStack& textureTrace = gl.GetTextureTrace();
832   textureTrace.Enable(true);
833   TraceCallStack& drawTrace = gl.GetDrawTrace();
834   drawTrace.Enable(true);
835
836   Actor actor = CreateActorWithImageVisual( propertyMap );
837   Stage::GetCurrent().Add( actor );
838   application.SendNotification();
839
840   Stage::GetCurrent().Remove( actor );
841   application.SendNotification();
842
843   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
844   DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
845   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
846   DALI_TEST_EQUALS( drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
847
848   END_TEST;
849 }
850
851 int UtcDaliImageVisualSetInvalidAsyncImage(void)
852 {
853   ToolkitTestApplication application;
854   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
855
856   VisualFactory factory = VisualFactory::Get();
857   DALI_TEST_CHECK( factory );
858
859   Property::Map propertyMap;
860   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
861   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
862
863   Visual::Base visual = factory.CreateVisual( propertyMap );
864   DALI_TEST_CHECK( visual );
865
866   TestGlAbstraction& gl = application.GetGlAbstraction();
867   TraceCallStack& textureTrace = gl.GetTextureTrace();
868   textureTrace.Enable(true);
869
870   DummyControl actor = DummyControl::New();
871   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
872   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
873
874   actor.SetSize( 200.f, 200.f );
875   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
876
877   Stage::GetCurrent().Add( actor );
878
879   application.SendNotification();
880   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
881
882   application.SendNotification();
883   application.Render();
884
885   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
886   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
887
888   Stage::GetCurrent().Remove( actor );
889   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
890
891   END_TEST;
892 }
893
894 int UtcDaliImageVisualSetInvalidSyncImage(void)
895 {
896   ToolkitTestApplication application;
897   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
898
899   VisualFactory factory = VisualFactory::Get();
900   DALI_TEST_CHECK( factory );
901
902   Property::Map propertyMap;
903   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
904   propertyMap.Insert( ImageVisual::Property::URL, TEST_INVALID_FILE_NAME );
905   propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
906
907   Visual::Base visual = factory.CreateVisual( propertyMap );
908   DALI_TEST_CHECK( visual );
909
910   TestGlAbstraction& gl = application.GetGlAbstraction();
911   TraceCallStack& textureTrace = gl.GetTextureTrace();
912   textureTrace.Enable(true);
913
914   DummyControl actor = DummyControl::New();
915   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
916   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
917
918   actor.SetSize( 200.f, 200.f );
919   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
920
921   Stage::GetCurrent().Add( actor );
922
923   application.SendNotification();
924   application.Render();
925
926   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
927   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
928
929   Stage::GetCurrent().Remove( actor );
930   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
931
932   END_TEST;
933 }
934
935 int UtcDaliImageVisualSetInvalidRemoteImage(void)
936 {
937   ToolkitTestApplication application;
938   tet_infoline( "Request image visual with invalid images - should draw broken.png" );
939
940   VisualFactory factory = VisualFactory::Get();
941   DALI_TEST_CHECK( factory );
942
943   // Local invalid file, asynchronous loading
944   Property::Map propertyMap;
945   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
946   propertyMap.Insert( ImageVisual::Property::URL, TEST_REMOTE_INVALID_FILE_NAME );
947
948   Visual::Base visual = factory.CreateVisual( propertyMap );
949   DALI_TEST_CHECK( visual );
950
951   TestGlAbstraction& gl = application.GetGlAbstraction();
952   TraceCallStack& textureTrace = gl.GetTextureTrace();
953   textureTrace.Enable(true);
954
955   DummyControl actor = DummyControl::New();
956   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
957   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
958
959   actor.SetSize( 200.f, 200.f );
960   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
961
962   Stage::GetCurrent().Add( actor );
963
964   application.SendNotification();
965   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
966
967   application.SendNotification();
968   application.Render();
969
970   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
971   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
972
973   Stage::GetCurrent().Remove( actor );
974   DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
975
976   END_TEST;
977 }
978
979 int UtcDaliImageVisualAlphaMask(void)
980 {
981   ToolkitTestApplication application;
982   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
983
984   VisualFactory factory = VisualFactory::Get();
985   DALI_TEST_CHECK( factory );
986
987   Property::Map propertyMap;
988   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
989   propertyMap.Insert( ImageVisual::Property::URL,  TEST_LARGE_IMAGE_FILE_NAME );
990   propertyMap.Insert( DevelImageVisual::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME );
991
992   Visual::Base visual = factory.CreateVisual( propertyMap );
993   DALI_TEST_CHECK( visual );
994
995   Property::Map testMap;
996   visual.CreatePropertyMap(testMap);
997   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::ALPHA_MASK_URL),Property::Value(TEST_MASK_IMAGE_FILE_NAME), TEST_LOCATION );
998
999   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1000   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1001
1002   TestGlAbstraction& gl = application.GetGlAbstraction();
1003   TraceCallStack& textureTrace = gl.GetTextureTrace();
1004   textureTrace.Enable(true);
1005
1006   DummyControl actor = DummyControl::New();
1007   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1008   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1009
1010   actor.SetSize( 200.f, 200.f );
1011   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1012   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), false, TEST_LOCATION );
1013
1014   Stage::GetCurrent().Add( actor );
1015   application.SendNotification();
1016   application.Render();
1017
1018   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1019
1020   application.SendNotification();
1021   application.Render();
1022
1023   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1024   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1025   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), true, TEST_LOCATION );
1026
1027   END_TEST;
1028 }
1029
1030 int UtcDaliImageVisualRemoteAlphaMask(void)
1031 {
1032   ToolkitTestApplication application;
1033   tet_infoline( "Request image visual with a Property::Map containing an Alpha mask" );
1034
1035   VisualFactory factory = VisualFactory::Get();
1036   DALI_TEST_CHECK( factory );
1037
1038   const std::string MASK_IMAGE = TEST_REMOTE_IMAGE_FILE_NAME;
1039
1040   Property::Map propertyMap;
1041   propertyMap.Insert( Visual::Property::TYPE,  Visual::IMAGE );
1042   propertyMap.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
1043   propertyMap.Insert( "alphaMaskUrl", MASK_IMAGE );
1044
1045   Visual::Base visual = factory.CreateVisual( propertyMap );
1046   DALI_TEST_CHECK( visual );
1047
1048   Property::Map testMap;
1049   visual.CreatePropertyMap(testMap);
1050   DALI_TEST_EQUALS(*testMap.Find(DevelImageVisual::Property::ALPHA_MASK_URL),Property::Value(MASK_IMAGE), TEST_LOCATION );
1051
1052   // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
1053   // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
1054
1055   TestGlAbstraction& gl = application.GetGlAbstraction();
1056   TraceCallStack& textureTrace = gl.GetTextureTrace();
1057   textureTrace.Enable(true);
1058
1059   DummyControl actor = DummyControl::New();
1060   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1061   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1062   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), false, TEST_LOCATION );
1063
1064   actor.SetSize( 200.f, 200.f );
1065   DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1066
1067   Stage::GetCurrent().Add( actor );
1068   application.SendNotification();
1069   application.Render();
1070
1071   DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION );
1072
1073   application.SendNotification();
1074   application.Render();
1075
1076   DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1077   DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1078   DALI_TEST_EQUALS( DevelControl::IsResourceReady( actor ), true, TEST_LOCATION );
1079
1080   END_TEST;
1081 }