2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <toolkit-timer.h>
21 #include <toolkit-bitmap-loader.h>
22 #include <toolkit-event-thread-callback.h>
23 #include <dali/public-api/rendering/renderer.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/shader.h>
26 #include <dali/devel-api/images/nine-patch-image.h>
27 #include <dali-toolkit/devel-api/align-enums.h>
28 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
29 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <dali-toolkit/dali-toolkit.h>
32 #include "dummy-control.h"
35 using namespace Dali::Toolkit;
39 typedef NinePatchImage::StretchRanges StretchRanges;
41 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
42 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
43 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
44 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
45 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
46 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
47 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
49 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
50 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
52 // resolution: 34*34, pixel format: RGBA8888
53 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
54 // resolution: 600*600, pixel format: RGB888
55 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
57 Property::Map DefaultTransform()
59 Property::Map transformMap;
61 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
62 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
63 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
64 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
65 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) )
66 .Add( Toolkit::DevelVisual::Transform::Property::SIZE_POLICY, Vector2( Toolkit::DevelVisual::Transform::Policy::RELATIVE, Toolkit::DevelVisual::Transform::Policy::RELATIVE ) );
70 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
72 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
73 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
74 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
76 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
81 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
83 PixelBuffer* pixbuffer = image->GetBuffer();
84 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
86 for( unsigned int row = 0; row < imageWidth; ++row )
88 unsigned int pixelOffset = row * bytesPerPixel;
89 pixbuffer[ pixelOffset + 3 ] = 0x00;
90 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
91 pixbuffer[ pixelOffset + 3 ] = 0x00;
94 for ( unsigned int column = 0; column < imageHeight; ++column )
96 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
97 pixbuffer[ pixelOffset + 3 ] = 0x00;
98 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
99 pixbuffer[ pixelOffset + 3 ] = 0x00;
103 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
105 PixelBuffer* pixbuffer = image->GetBuffer();
106 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
108 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
110 const Uint16Pair& range = *it;
111 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
112 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
114 unsigned int pixelOffset = column * bytesPerPixel;
115 pixbuffer[ pixelOffset ] = 0x00;
116 pixbuffer[ pixelOffset + 1 ] = 0x00;
117 pixbuffer[ pixelOffset + 2 ] = 0x00;
118 pixbuffer[ pixelOffset + 3 ] = 0xFF;
123 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
125 const Uint16Pair& range = *it;
126 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
127 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
129 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
130 pixbuffer[ pixelOffset ] = 0x00;
131 pixbuffer[ pixelOffset + 1 ] = 0x00;
132 pixbuffer[ pixelOffset + 2 ] = 0x00;
133 pixbuffer[ pixelOffset + 3 ] = 0xFF;
138 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
140 PixelBuffer* pixbuffer = image->GetBuffer();
141 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
143 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
144 unsigned int bufferStride = srcProfile->GetBufferStride();
146 // Add bottom child region
147 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
149 unsigned int pixelOffset = column * bytesPerPixel;
150 pixelOffset += ( imageHeight - 1 ) * bufferStride;
151 pixbuffer[ pixelOffset ] = 0x00;
152 pixbuffer[ pixelOffset + 1 ] = 0x00;
153 pixbuffer[ pixelOffset + 2 ] = 0x00;
154 pixbuffer[ pixelOffset + 3 ] = 0xFF;
157 // Add right child region
158 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
160 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
161 pixbuffer[ pixelOffset ] = 0x00;
162 pixbuffer[ pixelOffset + 1 ] = 0x00;
163 pixbuffer[ pixelOffset + 2 ] = 0x00;
164 pixbuffer[ pixelOffset + 3 ] = 0xFF;
168 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
169 unsigned int ninePatchImageWidth,
170 unsigned int ninePatchImageHeight,
171 const StretchRanges& stretchRangesX,
172 const StretchRanges& stretchRangesY,
173 bool addChildRegion = false,
174 Vector4 requiredChildRegion = Vector4::ZERO )
176 TestPlatformAbstraction& platform = application.GetPlatform();
178 Pixel::Format pixelFormat = Pixel::RGBA8888;
180 tet_infoline("Create Bitmap");
181 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
182 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
184 tet_infoline("Clear border regions");
185 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
187 tet_infoline("Add Stretch regions to Bitmap");
188 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
192 tet_infoline("Add Child regions to Bitmap");
193 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
196 tet_infoline("Getting resource");
197 Integration::ResourcePointer resourcePtr(bitmap);
198 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
199 platform.SetSynchronouslyLoadedResource( resourcePtr);
204 void TestVisualRender( ToolkitTestApplication& application,
206 Visual::Base& visual,
207 std::size_t expectedSamplers = 0,
208 ImageDimensions imageDimensions = ImageDimensions(),
209 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
211 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
212 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
216 // set the image size, for test case, this needs to be set before loading started
217 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
220 actor.SetSize( 200.f, 200.f );
221 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
223 Stage::GetCurrent().Add( actor );
225 application.SendNotification();
226 application.Render();
228 application.Render();
229 application.SendNotification();
233 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
236 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
243 void dali_visual_factory_startup(void)
245 test_return_value = TET_UNDEF;
248 void dali_visual_factory_cleanup(void)
250 test_return_value = TET_PASS;
253 int UtcDaliVisualFactoryGet(void)
255 ToolkitTestApplication application;
256 tet_infoline( "UtcDaliVisualFactory" );
260 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
261 DALI_TEST_CHECK( type );
262 BaseHandle handle = type.CreateInstance();
263 DALI_TEST_CHECK( handle );
265 VisualFactory factory;
266 factory = VisualFactory::Get();
267 DALI_TEST_CHECK( factory );
269 VisualFactory newFactory = VisualFactory::Get();
270 DALI_TEST_CHECK( newFactory );
272 // Check that visual factory is a singleton
273 DALI_TEST_CHECK(factory == newFactory);
278 int UtcDaliVisualFactoryCopyAndAssignment(void)
280 ToolkitTestApplication application;
281 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
282 VisualFactory factory = VisualFactory::Get();
284 VisualFactory factoryCopy( factory );
285 DALI_TEST_CHECK(factory == factoryCopy);
287 VisualFactory emptyFactory;
288 VisualFactory emptyFactoryCopy( emptyFactory );
289 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
291 VisualFactory factoryEquals;
292 factoryEquals = factory;
293 DALI_TEST_CHECK(factory == factoryEquals);
295 VisualFactory emptyFactoryEquals;
296 emptyFactoryEquals = emptyFactory;
297 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
301 DALI_TEST_CHECK( factory = factoryCopy );
306 int UtcDaliVisualFactoryGetColorVisual1(void)
308 ToolkitTestApplication application;
309 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
311 VisualFactory factory = VisualFactory::Get();
312 DALI_TEST_CHECK( factory );
314 Property::Map propertyMap;
315 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
316 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
317 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
319 Visual::Base visual = factory.CreateVisual(propertyMap);
320 DALI_TEST_CHECK( visual );
322 DummyControl actor = DummyControl::New();
323 TestVisualRender( application, actor, visual );
325 Vector3 actualValue(Vector4::ZERO);
327 TestGlAbstraction& gl = application.GetGlAbstraction();
328 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
329 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
330 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
331 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
336 int UtcDaliVisualFactoryGetColorVisual2(void)
338 ToolkitTestApplication application;
339 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
341 VisualFactory factory = VisualFactory::Get();
342 DALI_TEST_CHECK( factory );
344 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
345 Dali::Property::Map map;
346 map[ Visual::Property::TYPE ] = Visual::COLOR;
347 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
348 Visual::Base visual = factory.CreateVisual( map );
349 DALI_TEST_CHECK( visual );
351 DummyControl actor = DummyControl::New();
352 TestVisualRender( application, actor, visual );
356 TestGlAbstraction& gl = application.GetGlAbstraction();
357 DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "mixColor", actualValue ) );
358 DALI_TEST_CHECK( gl.GetUniformValue<float>( "opacity", opacity ) );
359 DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION );
360 DALI_TEST_EQUALS( opacity, testColor.a, TEST_LOCATION );
362 Stage::GetCurrent().Remove(actor);
363 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
368 int UtcDaliVisualFactoryGetBorderVisual1(void)
370 ToolkitTestApplication application;
371 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
373 VisualFactory factory = VisualFactory::Get();
374 DALI_TEST_CHECK( factory );
376 Property::Map propertyMap;
377 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
378 float testSize = 5.f;
379 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
380 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
381 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
383 Visual::Base visual = factory.CreateVisual(propertyMap);
384 DALI_TEST_CHECK( visual );
386 DummyControl actor = DummyControl::New();
387 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
388 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
389 actor.SetSize(200.f, 200.f);
390 Stage::GetCurrent().Add( actor );
391 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
393 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
394 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
395 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
397 TestGlAbstraction& gl = application.GetGlAbstraction();
399 application.SendNotification();
400 application.Render(0);
402 Vector4 actualColor(Vector4::ZERO);
403 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
404 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
406 float actualSize = 0.f;
407 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
408 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
411 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
416 int UtcDaliVisualFactoryGetBorderVisual2(void)
418 ToolkitTestApplication application;
419 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
421 VisualFactory factory = VisualFactory::Get();
422 DALI_TEST_CHECK( factory );
424 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
425 float testSize = 5.f;
427 Dali::Property::Map propertyMap;
428 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
429 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
430 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
431 Visual::Base visual = factory.CreateVisual( propertyMap );
432 DALI_TEST_CHECK( visual );
434 DummyControl actor = DummyControl::New();
435 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
436 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
437 actor.SetSize(200.f, 200.f);
438 Stage::GetCurrent().Add( actor );
439 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
441 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
443 TestGlAbstraction& gl = application.GetGlAbstraction();
445 application.SendNotification();
446 application.Render(0);
448 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
449 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
451 Vector4 actualColor(Vector4::ZERO);
452 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
453 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
455 float actualSize = 0.f;
456 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
457 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
461 // enable the anti-aliasing
462 Dali::Property::Map map;
463 map[ Visual::Property::TYPE ] = Visual::BORDER;
464 map[ BorderVisual::Property::COLOR ] = testColor;
465 map[ BorderVisual::Property::SIZE ] = testSize;
466 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
467 visual = factory.CreateVisual( map );
469 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
470 Stage::GetCurrent().Add( actor );
472 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
473 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
478 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
480 ToolkitTestApplication application;
481 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
483 VisualFactory factory = VisualFactory::Get();
484 DALI_TEST_CHECK( factory );
486 Property::Map propertyMap;
487 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
489 Vector2 start(-1.f, -1.f);
490 Vector2 end(1.f, 1.f);
491 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
492 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
493 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
495 Property::Array stopOffsets;
496 stopOffsets.PushBack( 0.2f );
497 stopOffsets.PushBack( 0.8f );
498 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
500 Property::Array stopColors;
501 stopColors.PushBack( Color::RED );
502 stopColors.PushBack( Color::GREEN );
503 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
505 Visual::Base visual = factory.CreateVisual(propertyMap);
506 DALI_TEST_CHECK( visual );
508 // A lookup texture is generated and pass to shader as sampler
509 DummyControl actor = DummyControl::New();
510 TestVisualRender( application, actor, visual, 1u);
515 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
517 ToolkitTestApplication application;
518 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
520 VisualFactory factory = VisualFactory::Get();
521 DALI_TEST_CHECK( factory );
523 Property::Map propertyMap;
524 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
526 Vector2 center(100.f, 100.f);
527 float radius = 100.f;
528 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
529 propertyMap.Insert(GradientVisual::Property::CENTER, center);
530 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
532 Property::Array stopOffsets;
533 stopOffsets.PushBack( 0.0f );
534 stopOffsets.PushBack( 1.f );
535 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
537 Property::Array stopColors;
538 stopColors.PushBack( Color::RED );
539 stopColors.PushBack( Color::GREEN );
540 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
542 Visual::Base visual = factory.CreateVisual(propertyMap);
543 DALI_TEST_CHECK( visual );
545 // A lookup texture is generated and pass to shader as sampler
546 DummyControl actor = DummyControl::New();
547 TestVisualRender( application, actor, visual, 1u );
549 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
550 alignMatrix.Invert();
552 Matrix3 actualValue( Matrix3::IDENTITY );
553 TestGlAbstraction& gl = application.GetGlAbstraction();
554 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
555 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
560 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
562 ToolkitTestApplication application;
563 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
565 VisualFactory factory = VisualFactory::Get();
566 DALI_TEST_CHECK( factory );
568 Property::Map propertyMap;
569 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
571 Vector2 start(-1.f, -1.f);
572 Vector2 end(1.f, 1.f);
573 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
574 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
575 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
577 Property::Array stopColors;
578 stopColors.PushBack( Color::RED );
579 stopColors.PushBack( Color::GREEN );
580 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
582 Visual::Base visual = factory.CreateVisual(propertyMap);
583 DALI_TEST_CHECK( visual );
585 // A lookup texture is generated and pass to shader as sampler
586 DummyControl actor = DummyControl::New();
587 TestVisualRender( application, actor, visual, 1u );
589 Stage::GetCurrent().Remove( actor );
590 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
595 int UtcDaliVisualFactoryGetImageVisual1(void)
597 ToolkitTestApplication application;
598 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
600 VisualFactory factory = VisualFactory::Get();
601 DALI_TEST_CHECK( factory );
603 Property::Map propertyMap;
604 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
605 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
607 Visual::Base visual = factory.CreateVisual( propertyMap );
608 DALI_TEST_CHECK( visual );
610 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
611 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
614 const int height=513;
615 TestGlAbstraction& gl = application.GetGlAbstraction();
616 TraceCallStack& textureTrace = gl.GetTextureTrace();
617 textureTrace.Enable(true);
619 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
620 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
622 DummyControl actor = DummyControl::New();
623 TestVisualRender( application, actor, visual, 1u,
624 ImageDimensions(width, height),
625 Integration::ResourcePointer( bitmap ) );
627 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
629 Stage::GetCurrent().Remove( actor );
630 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
635 int UtcDaliVisualFactoryGetImageVisual2(void)
637 ToolkitTestApplication application;
638 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
640 VisualFactory factory = VisualFactory::Get();
641 DALI_TEST_CHECK( factory );
643 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
644 Visual::Base visual = factory.CreateVisual( image );
646 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
647 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
650 const int height=513;
652 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
653 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
655 TestGlAbstraction& gl = application.GetGlAbstraction();
656 TraceCallStack& textureTrace = gl.GetTextureTrace();
657 textureTrace.Enable(true);
659 DummyControl actor = DummyControl::New();
660 TestVisualRender( application, actor, visual, 1u,
661 ImageDimensions(width, height),
662 Integration::ResourcePointer(bitmap) );
664 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
668 int UtcDaliVisualFactoryGetImageVisual3(void)
670 ToolkitTestApplication application;
671 tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
673 VisualFactory factory = VisualFactory::Get();
674 DALI_TEST_CHECK( factory );
676 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
679 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
681 Property::Map propertyMap;
682 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
683 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
684 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
685 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
686 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
687 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
688 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
689 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
691 Visual::Base visual = factory.CreateVisual( propertyMap );
692 DALI_TEST_CHECK( visual );
694 TestGlAbstraction& gl = application.GetGlAbstraction();
695 TraceCallStack& textureTrace = gl.GetTextureTrace();
696 textureTrace.Enable(true);
697 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
698 texParameterTrace.Enable( true );
700 DummyControl actor = DummyControl::New();
701 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
702 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
703 actor.SetSize(2000, 2000);
704 actor.SetParentOrigin(ParentOrigin::CENTER);
705 Stage::GetCurrent().Add( actor );
708 application.SendNotification();
709 application.Render();
710 application.Render();
711 application.SendNotification();
712 BitmapLoader loader = BitmapLoader::GetLatestCreated();
713 DALI_TEST_CHECK( loader );
714 loader.WaitForLoading();// waiting until the image to be loaded
715 DALI_TEST_CHECK( loader.IsLoaded() );
717 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
719 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
721 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
722 std::stringstream out;
723 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
724 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
726 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
727 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
729 // test the uniforms which used to handle the wrap mode
730 Renderer renderer = actor.GetRendererAt( 0u );
731 DALI_TEST_CHECK( renderer );
733 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
734 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
735 Vector4 pixelAreaUniform;
736 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
737 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
739 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
740 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
741 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
742 Vector2 wrapModeUniform;
743 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
744 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
747 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
752 int UtcDaliVisualFactoryGetImageVisual4(void)
754 ToolkitTestApplication application;
755 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
757 VisualFactory factory = VisualFactory::Get();
758 DALI_TEST_CHECK( factory );
760 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
762 const int height=600;
763 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
765 Property::Map propertyMap;
766 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
767 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
768 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
769 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
770 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
771 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
772 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
773 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
775 Visual::Base visual = factory.CreateVisual( propertyMap );
776 DALI_TEST_CHECK( visual );
778 TestGlAbstraction& gl = application.GetGlAbstraction();
779 TraceCallStack& textureTrace = gl.GetTextureTrace();
780 textureTrace.Enable(true);
781 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
782 texParameterTrace.Enable( true );
784 DummyControl actor = DummyControl::New();
785 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
786 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
787 actor.SetSize(2000, 2000);
788 actor.SetParentOrigin(ParentOrigin::CENTER);
789 Stage::GetCurrent().Add( actor );
792 application.SendNotification();
793 application.Render();
794 application.Render();
795 application.SendNotification();
796 BitmapLoader loader = BitmapLoader::GetLatestCreated();
797 DALI_TEST_CHECK( loader );
798 loader.WaitForLoading();// waiting until the image to be loaded
799 DALI_TEST_CHECK( loader.IsLoaded() );
801 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
803 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
805 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
806 std::stringstream out;
807 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
808 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
810 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
811 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
813 // test the uniforms which used to handle the wrap mode
814 Renderer renderer = actor.GetRendererAt( 0u );
815 DALI_TEST_CHECK( renderer );
817 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
818 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
819 Vector4 pixelAreaUniform;
820 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
821 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
823 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
824 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
827 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
832 int UtcDaliVisualFactoryGetNPatchVisual1(void)
834 ToolkitTestApplication application;
835 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
837 VisualFactory factory = VisualFactory::Get();
838 DALI_TEST_CHECK( factory );
840 const unsigned int ninePatchImageHeight = 18;
841 const unsigned int ninePatchImageWidth = 28;
842 StretchRanges stretchRangesX;
843 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
844 StretchRanges stretchRangesY;
845 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
846 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
848 Property::Map propertyMap;
849 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
850 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
852 tet_infoline( "whole grid" );
853 Visual::Base visual = factory.CreateVisual( propertyMap );
854 DALI_TEST_CHECK( visual );
857 TestGlAbstraction& gl = application.GetGlAbstraction();
858 TraceCallStack& textureTrace = gl.GetTextureTrace();
859 textureTrace.Enable(true);
861 DummyControl actor = DummyControl::New();
862 TestVisualRender( application, actor, visual, 1u,
863 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
866 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
869 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
871 tet_infoline( "border only" );
872 Visual::Base visual = factory.CreateVisual( propertyMap );
873 DALI_TEST_CHECK( visual );
875 TestGlAbstraction& gl = application.GetGlAbstraction();
876 TraceCallStack& textureTrace = gl.GetTextureTrace();
877 textureTrace.Enable(true);
879 DummyControl actor = DummyControl::New();
880 TestVisualRender( application, actor, visual, 1u,
881 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
884 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
890 int UtcDaliVisualFactoryGetNPatchVisual2(void)
892 ToolkitTestApplication application;
893 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
895 VisualFactory factory = VisualFactory::Get();
896 DALI_TEST_CHECK( factory );
898 Property::Map propertyMap;
899 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
900 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
901 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
903 tet_infoline( "whole grid" );
904 Visual::Base visual = factory.CreateVisual( propertyMap );
905 DALI_TEST_CHECK( visual );
907 TestGlAbstraction& gl = application.GetGlAbstraction();
908 TraceCallStack& textureTrace = gl.GetTextureTrace();
909 textureTrace.Enable(true);
911 DummyControl actor = DummyControl::New();
912 TestVisualRender( application, actor, visual, 1u );
914 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
917 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
919 tet_infoline( "border only" );
920 Visual::Base visual = factory.CreateVisual( propertyMap );
921 DALI_TEST_CHECK( visual );
923 TestGlAbstraction& gl = application.GetGlAbstraction();
924 TraceCallStack& textureTrace = gl.GetTextureTrace();
925 textureTrace.Enable(true);
927 DummyControl actor = DummyControl::New();
928 TestVisualRender( application, actor, visual, 1u );
930 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
936 int UtcDaliVisualFactoryGetNPatchVisual3(void)
938 ToolkitTestApplication application;
939 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
941 VisualFactory factory = VisualFactory::Get();
942 DALI_TEST_CHECK( factory );
944 const unsigned int ninePatchImageWidth = 18;
945 const unsigned int ninePatchImageHeight = 28;
946 StretchRanges stretchRangesX;
947 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
948 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
949 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
950 StretchRanges stretchRangesY;
951 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
952 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
953 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
954 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
955 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
957 Property::Map propertyMap;
958 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
959 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
961 Visual::Base visual = factory.CreateVisual( propertyMap );
962 DALI_TEST_CHECK( visual );
964 TestGlAbstraction& gl = application.GetGlAbstraction();
965 TraceCallStack& textureTrace = gl.GetTextureTrace();
966 textureTrace.Enable(true);
968 DummyControl actor = DummyControl::New();
969 TestVisualRender( application, actor, visual, 1u,
970 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
973 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
975 Stage::GetCurrent().Remove( actor );
976 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
979 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
981 tet_infoline( "border only" );
982 Visual::Base visual = factory.CreateVisual( propertyMap );
983 DALI_TEST_CHECK( visual );
985 TestGlAbstraction& gl = application.GetGlAbstraction();
986 TraceCallStack& textureTrace = gl.GetTextureTrace();
987 textureTrace.Enable(true);
988 DummyControl actor = DummyControl::New();
989 TestVisualRender( application, actor, visual, 1u,
990 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
994 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
996 Stage::GetCurrent().Remove( actor );
997 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1003 int UtcDaliVisualFactoryGetNPatchVisual4(void)
1005 ToolkitTestApplication application;
1006 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
1008 VisualFactory factory = VisualFactory::Get();
1009 DALI_TEST_CHECK( factory );
1011 const unsigned int ninePatchImageHeight = 18;
1012 const unsigned int ninePatchImageWidth = 28;
1013 StretchRanges stretchRangesX;
1014 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1015 StretchRanges stretchRangesY;
1016 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1017 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1019 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1020 DALI_TEST_CHECK( visual );
1022 TestGlAbstraction& gl = application.GetGlAbstraction();
1023 TraceCallStack& textureTrace = gl.GetTextureTrace();
1024 textureTrace.Enable(true);
1026 DummyControl actor = DummyControl::New();
1027 TestVisualRender( application, actor, visual, 1u,
1028 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1029 ninePatchResource );
1031 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1034 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
1035 Visual::Base nPatchVisual = factory.CreateVisual( image );
1036 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
1037 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
1038 nPatchVisual.GetNaturalSize( naturalSize );
1039 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
1044 int UtcDaliVisualFactoryGetNPatchVisual5(void)
1046 ToolkitTestApplication application;
1047 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
1049 VisualFactory factory = VisualFactory::Get();
1050 DALI_TEST_CHECK( factory );
1052 const unsigned int ninePatchImageHeight = 18;
1053 const unsigned int ninePatchImageWidth = 28;
1054 StretchRanges stretchRangesX;
1055 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1056 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
1057 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
1058 StretchRanges stretchRangesY;
1059 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1060 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1061 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1062 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1063 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1065 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1066 DALI_TEST_CHECK( visual );
1068 TestGlAbstraction& gl = application.GetGlAbstraction();
1069 TraceCallStack& textureTrace = gl.GetTextureTrace();
1070 textureTrace.Enable(true);
1072 DummyControl actor = DummyControl::New();
1073 TestVisualRender( application, actor, visual, 1u,
1074 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1075 ninePatchResource );
1077 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1082 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1084 //This should still load but display an error image
1086 ToolkitTestApplication application;
1087 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1089 VisualFactory factory = VisualFactory::Get();
1090 DALI_TEST_CHECK( factory );
1092 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1093 DALI_TEST_CHECK( visual );
1095 //The testkit still has to load a bitmap for the broken renderer image
1096 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1097 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1099 TestGlAbstraction& gl = application.GetGlAbstraction();
1100 TraceCallStack& textureTrace = gl.GetTextureTrace();
1101 textureTrace.Enable(true);
1103 DummyControl actor = DummyControl::New();
1104 TestVisualRender( application, actor, visual, 1u,
1106 Integration::ResourcePointer(bitmap) );
1108 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1113 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1115 //This should still load but display an error image
1117 ToolkitTestApplication application;
1118 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1120 VisualFactory factory = VisualFactory::Get();
1121 DALI_TEST_CHECK( factory );
1123 Property::Map propertyMap;
1124 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
1125 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1127 Visual::Base visual = factory.CreateVisual( propertyMap );
1128 DALI_TEST_CHECK( visual );
1130 //The testkit still has to load a bitmap for the broken renderer image
1131 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1132 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1134 TestGlAbstraction& gl = application.GetGlAbstraction();
1135 TraceCallStack& textureTrace = gl.GetTextureTrace();
1136 textureTrace.Enable(true);
1137 TraceCallStack& drawTrace = gl.GetDrawTrace();
1138 drawTrace.Enable(true);
1140 DummyControl actor = DummyControl::New();
1141 TestVisualRender( application, actor, visual, 1u,
1143 Integration::ResourcePointer(bitmap) );
1145 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1150 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1152 // Passing in an invalid visual type so we should not get a visual
1154 ToolkitTestApplication application;
1155 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1157 VisualFactory factory = VisualFactory::Get();
1158 DALI_TEST_CHECK( factory );
1160 Property::Map propertyMap;
1161 propertyMap.Insert( Visual::Property::TYPE, 111 );
1162 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1164 Visual::Base visual = factory.CreateVisual( propertyMap );
1165 DALI_TEST_CHECK( !visual );
1170 int UtcDaliVisualFactoryGetSvgVisual(void)
1172 ToolkitTestApplication application;
1173 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1175 VisualFactory factory = VisualFactory::Get();
1176 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1177 DALI_TEST_CHECK( visual );
1179 TestGlAbstraction& gl = application.GetGlAbstraction();
1180 TraceCallStack& textureTrace = gl.GetTextureTrace();
1181 textureTrace.Enable(true);
1183 DummyControl actor = DummyControl::New();
1184 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1185 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1186 actor.SetSize( 200.f, 200.f );
1187 Stage::GetCurrent().Add( actor );
1188 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
1190 application.SendNotification();
1191 application.Render();
1193 // renderer is not added to actor until the rasterization is completed.
1194 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1196 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1198 // renderer is added to actor
1199 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1201 // waiting for the resource uploading
1202 application.SendNotification();
1203 application.Render();
1205 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1210 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1212 ToolkitTestApplication application;
1213 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1215 VisualFactory factory = VisualFactory::Get();
1216 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1217 DALI_TEST_CHECK( visual );
1219 TestGlAbstraction& gl = application.GetGlAbstraction();
1220 TraceCallStack& textureTrace = gl.GetTextureTrace();
1221 textureTrace.Enable(true);
1223 DummyControl actor = DummyControl::New(true);
1224 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1225 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1226 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1227 Stage::GetCurrent().Add( actor );
1229 application.SendNotification();
1230 application.Render();
1232 // renderer is not added to actor until the rasterization is completed.
1233 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1235 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1237 // renderer is added to actor
1238 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1240 // waiting for the resource uploading
1241 application.SendNotification();
1242 application.Render();
1244 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1249 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1250 //This is expected to succeed, which will then pass the test.
1251 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1253 VisualFactory factory = VisualFactory::Get();
1254 DALI_TEST_CHECK( factory );
1256 //Create a mesh visual.
1257 Visual::Base visual = factory.CreateVisual( propertyMap );
1258 DALI_TEST_CHECK( visual );
1260 //Create an actor on stage to house the visual.
1261 DummyControl actor = DummyControl::New();
1262 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1263 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1264 actor.SetSize( 200.f, 200.f );
1265 Stage::GetCurrent().Add( actor );
1266 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1268 //Ensure set on stage.
1269 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1271 //Attempt to render to queue resource load requests.
1272 application.SendNotification();
1273 application.Render( 0 );
1275 //Render again to upload the now-loaded textures.
1276 application.SendNotification();
1277 application.Render( 0 );
1279 Matrix testScaleMatrix;
1280 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1281 Matrix actualScaleMatrix;
1283 //Test to see if the object has been successfully loaded.
1284 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1285 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1287 //Finish by setting off stage, and ensuring this was successful.
1289 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1292 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1293 //This is expected to fail, which will then pass the test.
1294 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1296 VisualFactory factory = VisualFactory::Get();
1297 DALI_TEST_CHECK( factory );
1299 //Create a mesh visual.
1300 Visual::Base visual = factory.CreateVisual( propertyMap );
1301 DALI_TEST_CHECK( visual );
1303 //Create an actor on stage to house the visual.
1304 DummyControl actor = DummyControl::New();
1305 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1306 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1307 actor.SetSize( 200.f, 200.f );
1308 Stage::GetCurrent().Add( actor );
1309 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1311 //Ensure set on stage.
1312 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1314 //Attempt to render to queue resource load requests.
1315 application.SendNotification();
1316 application.Render( 0 );
1318 //Render again to upload the now-loaded textures.
1319 application.SendNotification();
1320 application.Render( 0 );
1322 //Test to see if the object has not been loaded, as expected.
1324 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1326 //Finish by setting off stage, and ensuring this was successful.
1328 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1331 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1332 int UtcDaliVisualFactoryGetMeshVisual1(void)
1334 //Set up test application first, so everything else can be handled.
1335 ToolkitTestApplication application;
1337 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1340 //Set up visual properties.
1341 Property::Map propertyMap;
1342 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1343 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1345 //Test to see if mesh loads correctly.
1346 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1352 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1353 int UtcDaliVisualFactoryGetMeshVisual2(void)
1355 //Set up test application first, so everything else can be handled.
1356 ToolkitTestApplication application;
1358 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1360 //Set up visual properties.
1361 Property::Map propertyMap;
1362 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1363 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1364 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1365 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1367 //Test to see if mesh loads correctly.
1368 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1373 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location, but duff optional parameters
1374 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1376 //Set up test application first, so everything else can be handled.
1377 ToolkitTestApplication application;
1379 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1381 //Set up visual properties.
1382 Property::Map propertyMap;
1383 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1384 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1385 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1386 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1387 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1388 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1389 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1391 //Test to see if mesh loads correctly.
1392 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1397 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1398 int UtcDaliVisualFactoryGetMeshVisual3(void)
1400 //Set up test application first, so everything else can be handled.
1401 ToolkitTestApplication application;
1403 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1405 //Set up visual properties.
1406 Property::Map propertyMap;
1407 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1408 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1409 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1410 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1411 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1412 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1413 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1415 //Test to see if mesh loads correctly.
1416 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1421 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1422 int UtcDaliVisualFactoryGetMeshVisual4(void)
1424 //Set up test application first, so everything else can be handled.
1425 ToolkitTestApplication application;
1427 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1430 //Set up visual properties.
1431 Property::Map propertyMap;
1432 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1433 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1434 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1435 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1437 //Test to see if mesh loads correctly.
1438 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1443 //Test if mesh visual can load when made to use diffuse textures only.
1444 int UtcDaliVisualFactoryGetMeshVisual5(void)
1446 //Set up test application first, so everything else can be handled.
1447 ToolkitTestApplication application;
1449 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1451 //Set up visual properties.
1452 Property::Map propertyMap;
1453 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1454 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1455 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1456 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1457 propertyMap.Insert( "useMipmapping", false );
1458 propertyMap.Insert( "useSoftNormals", false );
1459 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1460 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1462 //Test to see if mesh loads correctly.
1463 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1469 //Test if mesh visual can load when made to not use the supplied textures.
1470 int UtcDaliVisualFactoryGetMeshVisual6(void)
1472 //Set up test application first, so everything else can be handled.
1473 ToolkitTestApplication application;
1475 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1477 //Set up visual properties.
1478 Property::Map propertyMap;
1479 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1480 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1481 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1482 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1483 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1485 //Test to see if mesh loads correctly.
1486 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1490 //Test if mesh visual loads correctly when light position is manually set.
1491 int UtcDaliVisualFactoryGetMeshVisual7(void)
1493 //Set up test application first, so everything else can be handled.
1494 ToolkitTestApplication application;
1497 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1499 //Set up visual properties.
1500 Property::Map propertyMap;
1501 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1502 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1503 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1504 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1505 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1507 //Test to see if mesh loads correctly.
1508 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1513 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1514 //Note that this notably tests object loader functionality.
1515 int UtcDaliVisualFactoryGetMeshVisual8(void)
1517 //Set up test application first, so everything else can be handled.
1518 ToolkitTestApplication application;
1520 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1522 //Set up visual properties.
1523 Property::Map propertyMap;
1524 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1525 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1526 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1527 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1529 //Test to see if mesh loads correctly.
1530 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1535 //Test if mesh visual handles the case of lacking an object file.
1536 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1538 //Set up test application first, so everything else can be handled.
1539 ToolkitTestApplication application;
1541 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1543 //Set up visual properties.
1544 Property::Map propertyMap;
1545 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1546 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1547 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1549 //Test to see if mesh doesn't load with these properties, as expected.
1550 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1556 //Test if mesh visual handles the case of being passed invalid material and images urls.
1557 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1559 //Set up test application first, so everything else can be handled.
1560 ToolkitTestApplication application;
1562 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1564 //Set up visual properties.
1565 Property::Map propertyMap;
1566 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1567 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1568 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1569 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1571 //Test to see if mesh doesn't load with these properties, as expected.
1572 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1578 //Test if mesh visual handles the case of being passed an invalid object url
1579 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1581 //Set up test application first, so everything else can be handled.
1582 ToolkitTestApplication application;
1583 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1586 //Set up visual properties.
1587 Property::Map propertyMap;
1588 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1589 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1590 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1591 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1593 //Test to see if mesh doesn't load with these properties, as expected.
1594 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1599 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1600 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1602 VisualFactory factory = VisualFactory::Get();
1603 DALI_TEST_CHECK( factory );
1605 //Create a primitive visual.
1606 Visual::Base visual = factory.CreateVisual( propertyMap );
1607 DALI_TEST_CHECK( visual );
1609 //Create an actor on stage to house the visual.
1610 DummyControl actor = DummyControl::New();
1611 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1612 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1614 actor.SetSize( 200.f, 200.f );
1615 Stage::GetCurrent().Add( actor );
1616 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1618 //Ensure set on stage.
1619 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1621 //Tell test application to load the visual.
1622 application.SendNotification();
1623 application.Render(0);
1625 Matrix testScaleMatrix;
1626 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1627 Matrix actualScaleMatrix;
1629 //Test to see if the object has been successfully loaded.
1630 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1631 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1633 //Finish by setting off stage, and ensuring this was successful.
1635 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1638 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1639 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1641 //Set up test application first, so everything else can be handled.
1642 ToolkitTestApplication application;
1644 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1646 //Set up visual properties.
1647 Property::Map propertyMap;
1648 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1649 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1651 //Test to see if shape loads correctly.
1652 TestPrimitiveVisualWithProperties( propertyMap, application );
1657 //Test if primitive shape loads correctly when supplied with all possible parameters
1658 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1660 //Set up test application first, so everything else can be handled.
1661 ToolkitTestApplication application;
1663 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1665 //Set up visual properties.
1666 Property::Map propertyMap;
1667 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1668 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1669 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1670 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1671 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1672 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1673 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1674 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1675 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1676 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1677 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1678 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1680 //Test to see if shape loads correctly.
1681 TestPrimitiveVisualWithProperties( propertyMap, application );
1686 //Test if primitive shape loads a sphere correctly.
1687 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1689 //Set up test application first, so everything else can be handled.
1690 ToolkitTestApplication application;
1692 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1694 //Set up visual properties.
1695 Property::Map propertyMap;
1696 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1697 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1698 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1699 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1700 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1702 //Test to see if shape loads correctly.
1703 TestPrimitiveVisualWithProperties( propertyMap, application );
1708 //Test if primitive shape loads a conic section correctly.
1709 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1711 //Set up test application first, so everything else can be handled.
1712 ToolkitTestApplication application;
1714 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1716 //Set up visual properties.
1717 Property::Map propertyMap;
1718 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1719 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1720 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1721 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1722 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1723 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1724 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1726 //Test to see if shape loads correctly.
1727 TestPrimitiveVisualWithProperties( propertyMap, application );
1732 //Test if primitive shape loads a bevelled cube correctly.
1733 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1735 //Set up test application first, so everything else can be handled.
1736 ToolkitTestApplication application;
1738 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1740 //Set up visual properties.
1741 Property::Map propertyMap;
1742 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1743 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1744 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1745 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1747 //Test to see if shape loads correctly.
1748 TestPrimitiveVisualWithProperties( propertyMap, application );
1753 //Test if primitive shape loads an octahedron correctly.
1754 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1756 //Set up test application first, so everything else can be handled.
1757 ToolkitTestApplication application;
1759 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1761 //Set up visual properties.
1762 Property::Map propertyMap;
1763 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1764 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1765 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1767 //Test to see if shape loads correctly.
1768 TestPrimitiveVisualWithProperties( propertyMap, application );
1773 //Test if primitive shape loads a cone correctly.
1774 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1776 //Set up test application first, so everything else can be handled.
1777 ToolkitTestApplication application;
1779 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1781 //Set up visual properties.
1782 Property::Map propertyMap;
1783 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1784 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1785 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1786 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1787 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1788 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1790 //Test to see if shape loads correctly.
1791 TestPrimitiveVisualWithProperties( propertyMap, application );
1796 //Test if primitive shape loads correctly when light position is manually set.
1797 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1799 //Set up test application first, so everything else can be handled.
1800 ToolkitTestApplication application;
1802 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1804 //Set up visual properties.
1805 Property::Map propertyMap;
1806 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1807 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1808 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1809 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1811 //Test to see if shape loads correctly.
1812 TestPrimitiveVisualWithProperties( propertyMap, application );
1817 //Test if primitive shape loads correctly when told to use too many slices.
1818 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1820 //Set up test application first, so everything else can be handled.
1821 ToolkitTestApplication application;
1823 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1825 //Set up visual properties.
1826 Property::Map propertyMap;
1827 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1828 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1829 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1831 //Test to see if shape loads correctly.
1832 TestPrimitiveVisualWithProperties( propertyMap, application );
1837 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1838 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1840 //Set up test application first, so everything else can be handled.
1841 ToolkitTestApplication application;
1843 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1845 //Set up visual properties.
1846 Property::Map propertyMap;
1847 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1848 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1849 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1851 //Test to see if shape loads correctly.
1852 TestPrimitiveVisualWithProperties( propertyMap, application );
1857 //Test if primitive shape loads correctly when told to use too many stacks.
1858 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1860 //Set up test application first, so everything else can be handled.
1861 ToolkitTestApplication application;
1863 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1865 //Set up visual properties.
1866 Property::Map propertyMap;
1867 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1868 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1869 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1871 //Test to see if shape loads correctly.
1872 TestPrimitiveVisualWithProperties( propertyMap, application );
1877 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1878 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1880 //Set up test application first, so everything else can be handled.
1881 ToolkitTestApplication application;
1883 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1885 //Set up visual properties.
1886 Property::Map propertyMap;
1887 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1888 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1889 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1891 //Test to see if shape loads correctly.
1892 TestPrimitiveVisualWithProperties( propertyMap, application );
1897 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1898 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1900 //Set up test application first, so everything else can be handled.
1901 ToolkitTestApplication application;
1903 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1905 //Set up visual properties.
1906 Property::Map propertyMap;
1907 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1908 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1909 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1911 //Test to see if shape loads correctly.
1912 TestPrimitiveVisualWithProperties( propertyMap, application );
1917 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1918 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1920 //Set up test application first, so everything else can be handled.
1921 ToolkitTestApplication application;
1923 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1925 //Set up visual properties.
1926 Property::Map propertyMap;
1927 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1928 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1929 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1931 //Test to see if shape loads correctly.
1932 TestPrimitiveVisualWithProperties( propertyMap, application );
1937 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1938 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1940 //Set up test application first, so everything else can be handled.
1941 ToolkitTestApplication application;
1943 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1945 //Set up visual properties.
1946 Property::Map propertyMap;
1947 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1948 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1949 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1951 //Test to see if shape loads correctly.
1952 TestPrimitiveVisualWithProperties( propertyMap, application );
1957 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1958 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1960 //Set up test application first, so everything else can be handled.
1961 ToolkitTestApplication application;
1963 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1965 //Set up visual properties.
1966 Property::Map propertyMap;
1967 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1968 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1969 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1971 //Test to see if shape loads correctly.
1972 TestPrimitiveVisualWithProperties( propertyMap, application );
1977 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1978 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1980 //Set up test application first, so everything else can be handled.
1981 ToolkitTestApplication application;
1983 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1985 //Set up visual properties.
1986 Property::Map propertyMap;
1987 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1988 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1989 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1991 //Test to see if shape loads correctly.
1992 TestPrimitiveVisualWithProperties( propertyMap, application );
1997 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1998 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
2000 //Set up test application first, so everything else can be handled.
2001 ToolkitTestApplication application;
2003 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
2005 //Set up visual properties, without supplying shape.
2006 Property::Map propertyMap;
2007 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
2009 //Test to see if shape loads regardless of missing input.
2010 TestPrimitiveVisualWithProperties( propertyMap, application );
2015 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
2017 ToolkitTestApplication application;
2018 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
2020 VisualFactory factory = VisualFactory::Get();
2021 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
2022 DALI_TEST_CHECK( visual );
2024 TestGlAbstraction& gl = application.GetGlAbstraction();
2025 TraceCallStack& textureTrace = gl.GetTextureTrace();
2026 textureTrace.Enable(true);
2028 DummyControl actor = DummyControl::New();
2029 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2030 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2031 actor.SetSize( 200.0f, 200.0f );
2032 Stage::GetCurrent().Add( actor );
2034 application.SendNotification();
2035 application.Render();
2037 // renderer is added to actor
2038 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2040 // test the uniforms which used to handle the atlas rect
2041 // the four frames should be located inside atlas as follows: atlas size 100*100
2050 Renderer renderer = actor.GetRendererAt( 0u );
2051 DALI_TEST_CHECK( renderer );
2053 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2054 // take into consideration the half pixel correction
2055 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2057 // waiting for the resource uploading
2058 application.SendNotification();
2059 application.Render();
2061 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2063 // Force the timer used by the animatedImageVisual to tick,
2064 Dali::Timer timer = Timer::New( 0 );
2065 timer.MockEmitSignal();
2066 application.SendNotification();
2067 application.Render();
2068 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2069 // take into consideration the half pixel correction
2070 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2072 // Force the timer used by the animatedImageVisual to tick,
2073 timer.MockEmitSignal();
2074 application.SendNotification();
2075 application.Render();
2076 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2077 // take into consideration the half pixel correction
2078 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2080 // Force the timer used by the animatedImageVisual to tick,
2081 timer.MockEmitSignal();
2082 application.SendNotification();
2083 application.Render();
2084 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2085 // take into consideration the half pixel correction
2086 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2088 // Test SetOffStage().
2090 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2095 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
2097 ToolkitTestApplication application;
2098 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
2100 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
2101 Property::Map propertyMap;
2102 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
2103 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
2104 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
2105 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
2106 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
2108 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
2109 DALI_TEST_CHECK( visual );
2111 TestGlAbstraction& gl = application.GetGlAbstraction();
2112 TraceCallStack& textureTrace = gl.GetTextureTrace();
2113 textureTrace.Enable(true);
2114 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
2115 texParameterTrace.Enable( true );
2117 DummyControl actor = DummyControl::New();
2118 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2119 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2120 actor.SetSize( 200.0f, 200.0f );
2121 Stage::GetCurrent().Add( actor );
2123 application.SendNotification();
2124 application.Render();
2126 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2128 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2130 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
2131 std::stringstream out;
2132 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
2133 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2135 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
2136 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2138 // test the uniforms which used to handle the wrap mode
2139 Renderer renderer = actor.GetRendererAt( 0u );
2140 DALI_TEST_CHECK( renderer );
2142 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
2143 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
2144 Vector4 pixelAreaUniform;
2145 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
2146 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2148 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
2149 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
2150 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
2151 Vector2 wrapModeUniform;
2152 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
2153 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2156 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );