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 );
690 propertyMap.Insert( DevelImageVisual::Property::ATLASING, true );
692 Visual::Base visual = factory.CreateVisual( propertyMap );
693 DALI_TEST_CHECK( visual );
695 TestGlAbstraction& gl = application.GetGlAbstraction();
696 TraceCallStack& textureTrace = gl.GetTextureTrace();
697 textureTrace.Enable(true);
698 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
699 texParameterTrace.Enable( true );
701 DummyControl actor = DummyControl::New();
702 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
703 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
704 actor.SetSize(2000, 2000);
705 actor.SetParentOrigin(ParentOrigin::CENTER);
706 Stage::GetCurrent().Add( actor );
709 application.SendNotification();
710 application.Render();
711 application.Render();
712 application.SendNotification();
713 BitmapLoader loader = BitmapLoader::GetLatestCreated();
714 DALI_TEST_CHECK( loader );
715 loader.WaitForLoading();// waiting until the image to be loaded
716 DALI_TEST_CHECK( loader.IsLoaded() );
718 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
720 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
722 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
723 std::stringstream out;
724 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
725 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
727 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
728 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
730 // test the uniforms which used to handle the wrap mode
731 Renderer renderer = actor.GetRendererAt( 0u );
732 DALI_TEST_CHECK( renderer );
734 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
735 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
736 Vector4 pixelAreaUniform;
737 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
738 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
740 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
741 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
742 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
743 Vector2 wrapModeUniform;
744 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
745 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
748 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
753 int UtcDaliVisualFactoryGetImageVisual4(void)
755 ToolkitTestApplication application;
756 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
758 VisualFactory factory = VisualFactory::Get();
759 DALI_TEST_CHECK( factory );
761 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
763 const int height=600;
764 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
766 Property::Map propertyMap;
767 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
768 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
769 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
770 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
771 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
772 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
773 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
774 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
776 Visual::Base visual = factory.CreateVisual( propertyMap );
777 DALI_TEST_CHECK( visual );
779 TestGlAbstraction& gl = application.GetGlAbstraction();
780 TraceCallStack& textureTrace = gl.GetTextureTrace();
781 textureTrace.Enable(true);
782 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
783 texParameterTrace.Enable( true );
785 DummyControl actor = DummyControl::New();
786 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
787 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
788 actor.SetSize(2000, 2000);
789 actor.SetParentOrigin(ParentOrigin::CENTER);
790 Stage::GetCurrent().Add( actor );
793 application.SendNotification();
794 application.Render();
795 application.Render();
796 application.SendNotification();
797 BitmapLoader loader = BitmapLoader::GetLatestCreated();
798 DALI_TEST_CHECK( loader );
799 loader.WaitForLoading();// waiting until the image to be loaded
800 DALI_TEST_CHECK( loader.IsLoaded() );
802 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
804 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
806 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
807 std::stringstream out;
808 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
809 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
811 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
812 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
814 // test the uniforms which used to handle the wrap mode
815 Renderer renderer = actor.GetRendererAt( 0u );
816 DALI_TEST_CHECK( renderer );
818 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
819 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
820 Vector4 pixelAreaUniform;
821 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
822 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
824 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
825 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
828 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
833 int UtcDaliVisualFactoryGetNPatchVisual1(void)
835 ToolkitTestApplication application;
836 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
838 VisualFactory factory = VisualFactory::Get();
839 DALI_TEST_CHECK( factory );
841 const unsigned int ninePatchImageHeight = 18;
842 const unsigned int ninePatchImageWidth = 28;
843 StretchRanges stretchRangesX;
844 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
845 StretchRanges stretchRangesY;
846 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
847 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
849 Property::Map propertyMap;
850 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
851 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
853 tet_infoline( "whole grid" );
854 Visual::Base visual = factory.CreateVisual( propertyMap );
855 DALI_TEST_CHECK( visual );
858 TestGlAbstraction& gl = application.GetGlAbstraction();
859 TraceCallStack& textureTrace = gl.GetTextureTrace();
860 textureTrace.Enable(true);
862 DummyControl actor = DummyControl::New();
863 TestVisualRender( application, actor, visual, 1u,
864 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
867 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
870 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
872 tet_infoline( "border only" );
873 Visual::Base visual = factory.CreateVisual( propertyMap );
874 DALI_TEST_CHECK( visual );
876 TestGlAbstraction& gl = application.GetGlAbstraction();
877 TraceCallStack& textureTrace = gl.GetTextureTrace();
878 textureTrace.Enable(true);
880 DummyControl actor = DummyControl::New();
881 TestVisualRender( application, actor, visual, 1u,
882 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
885 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
891 int UtcDaliVisualFactoryGetNPatchVisual2(void)
893 ToolkitTestApplication application;
894 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map including border" );
896 VisualFactory factory = VisualFactory::Get();
897 DALI_TEST_CHECK( factory );
899 Property::Map propertyMap;
900 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
901 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
902 propertyMap.Insert( DevelImageVisual::Property::BORDER, Rect< int >( 2, 2, 2, 2 ) );
904 tet_infoline( "whole grid" );
905 Visual::Base visual = factory.CreateVisual( propertyMap );
906 DALI_TEST_CHECK( visual );
908 TestGlAbstraction& gl = application.GetGlAbstraction();
909 TraceCallStack& textureTrace = gl.GetTextureTrace();
910 textureTrace.Enable(true);
912 DummyControl actor = DummyControl::New();
913 TestVisualRender( application, actor, visual, 1u );
915 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
918 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
920 tet_infoline( "border only" );
921 Visual::Base visual = factory.CreateVisual( propertyMap );
922 DALI_TEST_CHECK( visual );
924 TestGlAbstraction& gl = application.GetGlAbstraction();
925 TraceCallStack& textureTrace = gl.GetTextureTrace();
926 textureTrace.Enable(true);
928 DummyControl actor = DummyControl::New();
929 TestVisualRender( application, actor, visual, 1u );
931 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
937 int UtcDaliVisualFactoryGetNPatchVisual3(void)
939 ToolkitTestApplication application;
940 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
942 VisualFactory factory = VisualFactory::Get();
943 DALI_TEST_CHECK( factory );
945 const unsigned int ninePatchImageWidth = 18;
946 const unsigned int ninePatchImageHeight = 28;
947 StretchRanges stretchRangesX;
948 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
949 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
950 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
951 StretchRanges stretchRangesY;
952 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
953 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
954 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
955 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
956 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
958 Property::Map propertyMap;
959 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
960 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
962 Visual::Base visual = factory.CreateVisual( propertyMap );
963 DALI_TEST_CHECK( visual );
965 TestGlAbstraction& gl = application.GetGlAbstraction();
966 TraceCallStack& textureTrace = gl.GetTextureTrace();
967 textureTrace.Enable(true);
969 DummyControl actor = DummyControl::New();
970 TestVisualRender( application, actor, visual, 1u,
971 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
974 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
976 Stage::GetCurrent().Remove( actor );
977 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
980 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
982 tet_infoline( "border only" );
983 Visual::Base visual = factory.CreateVisual( propertyMap );
984 DALI_TEST_CHECK( visual );
986 TestGlAbstraction& gl = application.GetGlAbstraction();
987 TraceCallStack& textureTrace = gl.GetTextureTrace();
988 textureTrace.Enable(true);
989 DummyControl actor = DummyControl::New();
990 TestVisualRender( application, actor, visual, 1u,
991 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
995 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
997 Stage::GetCurrent().Remove( actor );
998 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1004 int UtcDaliVisualFactoryGetNPatchVisual4(void)
1006 ToolkitTestApplication application;
1007 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
1009 VisualFactory factory = VisualFactory::Get();
1010 DALI_TEST_CHECK( factory );
1012 const unsigned int ninePatchImageHeight = 18;
1013 const unsigned int ninePatchImageWidth = 28;
1014 StretchRanges stretchRangesX;
1015 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1016 StretchRanges stretchRangesY;
1017 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1018 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1020 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1021 DALI_TEST_CHECK( visual );
1023 TestGlAbstraction& gl = application.GetGlAbstraction();
1024 TraceCallStack& textureTrace = gl.GetTextureTrace();
1025 textureTrace.Enable(true);
1027 DummyControl actor = DummyControl::New();
1028 TestVisualRender( application, actor, visual, 1u,
1029 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1030 ninePatchResource );
1032 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1035 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
1036 Visual::Base nPatchVisual = factory.CreateVisual( image );
1037 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
1038 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
1039 nPatchVisual.GetNaturalSize( naturalSize );
1040 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
1045 int UtcDaliVisualFactoryGetNPatchVisual5(void)
1047 ToolkitTestApplication application;
1048 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
1050 VisualFactory factory = VisualFactory::Get();
1051 DALI_TEST_CHECK( factory );
1053 const unsigned int ninePatchImageHeight = 18;
1054 const unsigned int ninePatchImageWidth = 28;
1055 StretchRanges stretchRangesX;
1056 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1057 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
1058 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
1059 StretchRanges stretchRangesY;
1060 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1061 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1062 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1063 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1064 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1066 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1067 DALI_TEST_CHECK( visual );
1069 TestGlAbstraction& gl = application.GetGlAbstraction();
1070 TraceCallStack& textureTrace = gl.GetTextureTrace();
1071 textureTrace.Enable(true);
1073 DummyControl actor = DummyControl::New();
1074 TestVisualRender( application, actor, visual, 1u,
1075 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1076 ninePatchResource );
1078 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1083 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1085 //This should still load but display an error image
1087 ToolkitTestApplication application;
1088 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1090 VisualFactory factory = VisualFactory::Get();
1091 DALI_TEST_CHECK( factory );
1093 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1094 DALI_TEST_CHECK( visual );
1096 //The testkit still has to load a bitmap for the broken renderer image
1097 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1098 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1100 TestGlAbstraction& gl = application.GetGlAbstraction();
1101 TraceCallStack& textureTrace = gl.GetTextureTrace();
1102 textureTrace.Enable(true);
1104 DummyControl actor = DummyControl::New();
1105 TestVisualRender( application, actor, visual, 1u,
1107 Integration::ResourcePointer(bitmap) );
1109 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1114 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1116 //This should still load but display an error image
1118 ToolkitTestApplication application;
1119 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1121 VisualFactory factory = VisualFactory::Get();
1122 DALI_TEST_CHECK( factory );
1124 Property::Map propertyMap;
1125 propertyMap.Insert( Visual::Property::TYPE, DevelVisual::N_PATCH );
1126 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1128 Visual::Base visual = factory.CreateVisual( propertyMap );
1129 DALI_TEST_CHECK( visual );
1131 //The testkit still has to load a bitmap for the broken renderer image
1132 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1133 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1135 TestGlAbstraction& gl = application.GetGlAbstraction();
1136 TraceCallStack& textureTrace = gl.GetTextureTrace();
1137 textureTrace.Enable(true);
1138 TraceCallStack& drawTrace = gl.GetDrawTrace();
1139 drawTrace.Enable(true);
1141 DummyControl actor = DummyControl::New();
1142 TestVisualRender( application, actor, visual, 1u,
1144 Integration::ResourcePointer(bitmap) );
1146 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1151 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1153 // Passing in an invalid visual type so we should not get a visual
1155 ToolkitTestApplication application;
1156 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1158 VisualFactory factory = VisualFactory::Get();
1159 DALI_TEST_CHECK( factory );
1161 Property::Map propertyMap;
1162 propertyMap.Insert( Visual::Property::TYPE, 111 );
1163 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1165 Visual::Base visual = factory.CreateVisual( propertyMap );
1166 DALI_TEST_CHECK( !visual );
1171 int UtcDaliVisualFactoryGetSvgVisual(void)
1173 ToolkitTestApplication application;
1174 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1176 VisualFactory factory = VisualFactory::Get();
1177 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1178 DALI_TEST_CHECK( visual );
1180 TestGlAbstraction& gl = application.GetGlAbstraction();
1181 TraceCallStack& textureTrace = gl.GetTextureTrace();
1182 textureTrace.Enable(true);
1184 DummyControl actor = DummyControl::New();
1185 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1186 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1187 actor.SetSize( 200.f, 200.f );
1188 Stage::GetCurrent().Add( actor );
1189 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
1191 application.SendNotification();
1192 application.Render();
1194 // renderer is not added to actor until the rasterization is completed.
1195 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1197 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1199 // renderer is added to actor
1200 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1202 // waiting for the resource uploading
1203 application.SendNotification();
1204 application.Render();
1206 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1211 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1213 ToolkitTestApplication application;
1214 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1216 VisualFactory factory = VisualFactory::Get();
1217 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1218 DALI_TEST_CHECK( visual );
1220 TestGlAbstraction& gl = application.GetGlAbstraction();
1221 TraceCallStack& textureTrace = gl.GetTextureTrace();
1222 textureTrace.Enable(true);
1224 DummyControl actor = DummyControl::New(true);
1225 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1226 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1227 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1228 Stage::GetCurrent().Add( actor );
1230 application.SendNotification();
1231 application.Render();
1233 // renderer is not added to actor until the rasterization is completed.
1234 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1236 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1238 // renderer is added to actor
1239 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1241 // waiting for the resource uploading
1242 application.SendNotification();
1243 application.Render();
1245 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1250 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1251 //This is expected to succeed, which will then pass the test.
1252 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1254 VisualFactory factory = VisualFactory::Get();
1255 DALI_TEST_CHECK( factory );
1257 //Create a mesh visual.
1258 Visual::Base visual = factory.CreateVisual( propertyMap );
1259 DALI_TEST_CHECK( visual );
1261 //Create an actor on stage to house the visual.
1262 DummyControl actor = DummyControl::New();
1263 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1264 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1265 actor.SetSize( 200.f, 200.f );
1266 Stage::GetCurrent().Add( actor );
1267 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1269 //Ensure set on stage.
1270 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1272 //Attempt to render to queue resource load requests.
1273 application.SendNotification();
1274 application.Render( 0 );
1276 //Render again to upload the now-loaded textures.
1277 application.SendNotification();
1278 application.Render( 0 );
1280 Matrix testScaleMatrix;
1281 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1282 Matrix actualScaleMatrix;
1284 //Test to see if the object has been successfully loaded.
1285 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1286 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1288 //Finish by setting off stage, and ensuring this was successful.
1290 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1293 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1294 //This is expected to fail, which will then pass the test.
1295 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1297 VisualFactory factory = VisualFactory::Get();
1298 DALI_TEST_CHECK( factory );
1300 //Create a mesh visual.
1301 Visual::Base visual = factory.CreateVisual( propertyMap );
1302 DALI_TEST_CHECK( visual );
1304 //Create an actor on stage to house the visual.
1305 DummyControl actor = DummyControl::New();
1306 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1307 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1308 actor.SetSize( 200.f, 200.f );
1309 Stage::GetCurrent().Add( actor );
1310 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1312 //Ensure set on stage.
1313 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1315 //Attempt to render to queue resource load requests.
1316 application.SendNotification();
1317 application.Render( 0 );
1319 //Render again to upload the now-loaded textures.
1320 application.SendNotification();
1321 application.Render( 0 );
1323 //Test to see if the object has not been loaded, as expected.
1325 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1327 //Finish by setting off stage, and ensuring this was successful.
1329 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1332 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1333 int UtcDaliVisualFactoryGetMeshVisual1(void)
1335 //Set up test application first, so everything else can be handled.
1336 ToolkitTestApplication application;
1338 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1341 //Set up visual properties.
1342 Property::Map propertyMap;
1343 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1344 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1346 //Test to see if mesh loads correctly.
1347 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1353 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1354 int UtcDaliVisualFactoryGetMeshVisual2(void)
1356 //Set up test application first, so everything else can be handled.
1357 ToolkitTestApplication application;
1359 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1361 //Set up visual properties.
1362 Property::Map propertyMap;
1363 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1364 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1365 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1366 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1368 //Test to see if mesh loads correctly.
1369 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1374 //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
1375 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1377 //Set up test application first, so everything else can be handled.
1378 ToolkitTestApplication application;
1380 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1382 //Set up visual properties.
1383 Property::Map propertyMap;
1384 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1385 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1386 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1387 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1388 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1389 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1390 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1392 //Test to see if mesh loads correctly.
1393 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1398 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1399 int UtcDaliVisualFactoryGetMeshVisual3(void)
1401 //Set up test application first, so everything else can be handled.
1402 ToolkitTestApplication application;
1404 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1406 //Set up visual properties.
1407 Property::Map propertyMap;
1408 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1409 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1410 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1411 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1412 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1413 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1414 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1416 //Test to see if mesh loads correctly.
1417 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1422 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1423 int UtcDaliVisualFactoryGetMeshVisual4(void)
1425 //Set up test application first, so everything else can be handled.
1426 ToolkitTestApplication application;
1428 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1431 //Set up visual properties.
1432 Property::Map propertyMap;
1433 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1434 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1435 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1436 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1438 //Test to see if mesh loads correctly.
1439 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1444 //Test if mesh visual can load when made to use diffuse textures only.
1445 int UtcDaliVisualFactoryGetMeshVisual5(void)
1447 //Set up test application first, so everything else can be handled.
1448 ToolkitTestApplication application;
1450 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1452 //Set up visual properties.
1453 Property::Map propertyMap;
1454 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1455 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1456 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1457 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1458 propertyMap.Insert( "useMipmapping", false );
1459 propertyMap.Insert( "useSoftNormals", false );
1460 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1461 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1463 //Test to see if mesh loads correctly.
1464 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1470 //Test if mesh visual can load when made to not use the supplied textures.
1471 int UtcDaliVisualFactoryGetMeshVisual6(void)
1473 //Set up test application first, so everything else can be handled.
1474 ToolkitTestApplication application;
1476 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1478 //Set up visual properties.
1479 Property::Map propertyMap;
1480 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1481 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1482 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1483 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1484 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1486 //Test to see if mesh loads correctly.
1487 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1491 //Test if mesh visual loads correctly when light position is manually set.
1492 int UtcDaliVisualFactoryGetMeshVisual7(void)
1494 //Set up test application first, so everything else can be handled.
1495 ToolkitTestApplication application;
1498 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1500 //Set up visual properties.
1501 Property::Map propertyMap;
1502 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1503 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1504 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1505 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1506 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1508 //Test to see if mesh loads correctly.
1509 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1514 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1515 //Note that this notably tests object loader functionality.
1516 int UtcDaliVisualFactoryGetMeshVisual8(void)
1518 //Set up test application first, so everything else can be handled.
1519 ToolkitTestApplication application;
1521 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1523 //Set up visual properties.
1524 Property::Map propertyMap;
1525 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1526 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1527 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1528 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1530 //Test to see if mesh loads correctly.
1531 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1536 //Test if mesh visual handles the case of lacking an object file.
1537 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1539 //Set up test application first, so everything else can be handled.
1540 ToolkitTestApplication application;
1542 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1544 //Set up visual properties.
1545 Property::Map propertyMap;
1546 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1547 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1548 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1550 //Test to see if mesh doesn't load with these properties, as expected.
1551 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1557 //Test if mesh visual handles the case of being passed invalid material and images urls.
1558 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1560 //Set up test application first, so everything else can be handled.
1561 ToolkitTestApplication application;
1563 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1565 //Set up visual properties.
1566 Property::Map propertyMap;
1567 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1568 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1569 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1570 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1572 //Test to see if mesh doesn't load with these properties, as expected.
1573 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1579 //Test if mesh visual handles the case of being passed an invalid object url
1580 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1582 //Set up test application first, so everything else can be handled.
1583 ToolkitTestApplication application;
1584 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1587 //Set up visual properties.
1588 Property::Map propertyMap;
1589 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1590 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1591 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1592 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1594 //Test to see if mesh doesn't load with these properties, as expected.
1595 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1600 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1601 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1603 VisualFactory factory = VisualFactory::Get();
1604 DALI_TEST_CHECK( factory );
1606 //Create a primitive visual.
1607 Visual::Base visual = factory.CreateVisual( propertyMap );
1608 DALI_TEST_CHECK( visual );
1610 //Create an actor on stage to house the visual.
1611 DummyControl actor = DummyControl::New();
1612 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1613 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1615 actor.SetSize( 200.f, 200.f );
1616 Stage::GetCurrent().Add( actor );
1617 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1619 //Ensure set on stage.
1620 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1622 //Tell test application to load the visual.
1623 application.SendNotification();
1624 application.Render(0);
1626 Matrix testScaleMatrix;
1627 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1628 Matrix actualScaleMatrix;
1630 //Test to see if the object has been successfully loaded.
1631 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1632 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1634 //Finish by setting off stage, and ensuring this was successful.
1636 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1639 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1640 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1642 //Set up test application first, so everything else can be handled.
1643 ToolkitTestApplication application;
1645 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1647 //Set up visual properties.
1648 Property::Map propertyMap;
1649 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1650 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1652 //Test to see if shape loads correctly.
1653 TestPrimitiveVisualWithProperties( propertyMap, application );
1658 //Test if primitive shape loads correctly when supplied with all possible parameters
1659 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1661 //Set up test application first, so everything else can be handled.
1662 ToolkitTestApplication application;
1664 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1666 //Set up visual properties.
1667 Property::Map propertyMap;
1668 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1669 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1670 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1671 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1672 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1673 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1674 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1675 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1676 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1677 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1678 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1679 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1681 //Test to see if shape loads correctly.
1682 TestPrimitiveVisualWithProperties( propertyMap, application );
1687 //Test if primitive shape loads a sphere correctly.
1688 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1690 //Set up test application first, so everything else can be handled.
1691 ToolkitTestApplication application;
1693 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1695 //Set up visual properties.
1696 Property::Map propertyMap;
1697 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1698 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1699 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1700 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1701 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1703 //Test to see if shape loads correctly.
1704 TestPrimitiveVisualWithProperties( propertyMap, application );
1709 //Test if primitive shape loads a conic section correctly.
1710 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1712 //Set up test application first, so everything else can be handled.
1713 ToolkitTestApplication application;
1715 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1717 //Set up visual properties.
1718 Property::Map propertyMap;
1719 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1720 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1721 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1722 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1723 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1724 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1725 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1727 //Test to see if shape loads correctly.
1728 TestPrimitiveVisualWithProperties( propertyMap, application );
1733 //Test if primitive shape loads a bevelled cube correctly.
1734 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1736 //Set up test application first, so everything else can be handled.
1737 ToolkitTestApplication application;
1739 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1741 //Set up visual properties.
1742 Property::Map propertyMap;
1743 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1744 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1745 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1746 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1748 //Test to see if shape loads correctly.
1749 TestPrimitiveVisualWithProperties( propertyMap, application );
1754 //Test if primitive shape loads an octahedron correctly.
1755 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1757 //Set up test application first, so everything else can be handled.
1758 ToolkitTestApplication application;
1760 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1762 //Set up visual properties.
1763 Property::Map propertyMap;
1764 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1765 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1766 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1768 //Test to see if shape loads correctly.
1769 TestPrimitiveVisualWithProperties( propertyMap, application );
1774 //Test if primitive shape loads a cone correctly.
1775 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1777 //Set up test application first, so everything else can be handled.
1778 ToolkitTestApplication application;
1780 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1782 //Set up visual properties.
1783 Property::Map propertyMap;
1784 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1785 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1786 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1787 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1788 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1789 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1791 //Test to see if shape loads correctly.
1792 TestPrimitiveVisualWithProperties( propertyMap, application );
1797 //Test if primitive shape loads correctly when light position is manually set.
1798 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1800 //Set up test application first, so everything else can be handled.
1801 ToolkitTestApplication application;
1803 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1805 //Set up visual properties.
1806 Property::Map propertyMap;
1807 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1808 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1809 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1810 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1812 //Test to see if shape loads correctly.
1813 TestPrimitiveVisualWithProperties( propertyMap, application );
1818 //Test if primitive shape loads correctly when told to use too many slices.
1819 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1821 //Set up test application first, so everything else can be handled.
1822 ToolkitTestApplication application;
1824 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1826 //Set up visual properties.
1827 Property::Map propertyMap;
1828 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1829 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1830 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1832 //Test to see if shape loads correctly.
1833 TestPrimitiveVisualWithProperties( propertyMap, application );
1838 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1839 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1841 //Set up test application first, so everything else can be handled.
1842 ToolkitTestApplication application;
1844 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1846 //Set up visual properties.
1847 Property::Map propertyMap;
1848 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1849 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1850 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1852 //Test to see if shape loads correctly.
1853 TestPrimitiveVisualWithProperties( propertyMap, application );
1858 //Test if primitive shape loads correctly when told to use too many stacks.
1859 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1861 //Set up test application first, so everything else can be handled.
1862 ToolkitTestApplication application;
1864 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1866 //Set up visual properties.
1867 Property::Map propertyMap;
1868 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1869 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1870 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1872 //Test to see if shape loads correctly.
1873 TestPrimitiveVisualWithProperties( propertyMap, application );
1878 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1879 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1881 //Set up test application first, so everything else can be handled.
1882 ToolkitTestApplication application;
1884 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1886 //Set up visual properties.
1887 Property::Map propertyMap;
1888 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1889 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1890 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1892 //Test to see if shape loads correctly.
1893 TestPrimitiveVisualWithProperties( propertyMap, application );
1898 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1899 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1901 //Set up test application first, so everything else can be handled.
1902 ToolkitTestApplication application;
1904 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1906 //Set up visual properties.
1907 Property::Map propertyMap;
1908 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1909 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1910 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1912 //Test to see if shape loads correctly.
1913 TestPrimitiveVisualWithProperties( propertyMap, application );
1918 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1919 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1921 //Set up test application first, so everything else can be handled.
1922 ToolkitTestApplication application;
1924 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1926 //Set up visual properties.
1927 Property::Map propertyMap;
1928 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1929 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1930 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1932 //Test to see if shape loads correctly.
1933 TestPrimitiveVisualWithProperties( propertyMap, application );
1938 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1939 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1941 //Set up test application first, so everything else can be handled.
1942 ToolkitTestApplication application;
1944 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1946 //Set up visual properties.
1947 Property::Map propertyMap;
1948 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1949 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1950 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1952 //Test to see if shape loads correctly.
1953 TestPrimitiveVisualWithProperties( propertyMap, application );
1958 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1959 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1961 //Set up test application first, so everything else can be handled.
1962 ToolkitTestApplication application;
1964 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1966 //Set up visual properties.
1967 Property::Map propertyMap;
1968 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1969 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1970 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1972 //Test to see if shape loads correctly.
1973 TestPrimitiveVisualWithProperties( propertyMap, application );
1978 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1979 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1981 //Set up test application first, so everything else can be handled.
1982 ToolkitTestApplication application;
1984 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1986 //Set up visual properties.
1987 Property::Map propertyMap;
1988 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1989 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1990 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1992 //Test to see if shape loads correctly.
1993 TestPrimitiveVisualWithProperties( propertyMap, application );
1998 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1999 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
2001 //Set up test application first, so everything else can be handled.
2002 ToolkitTestApplication application;
2004 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
2006 //Set up visual properties, without supplying shape.
2007 Property::Map propertyMap;
2008 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
2010 //Test to see if shape loads regardless of missing input.
2011 TestPrimitiveVisualWithProperties( propertyMap, application );
2016 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
2018 ToolkitTestApplication application;
2019 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
2021 VisualFactory factory = VisualFactory::Get();
2022 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
2023 DALI_TEST_CHECK( visual );
2025 TestGlAbstraction& gl = application.GetGlAbstraction();
2026 TraceCallStack& textureTrace = gl.GetTextureTrace();
2027 textureTrace.Enable(true);
2029 DummyControl actor = DummyControl::New();
2030 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2031 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2032 actor.SetSize( 200.0f, 200.0f );
2033 Stage::GetCurrent().Add( actor );
2035 application.SendNotification();
2036 application.Render();
2038 // renderer is added to actor
2039 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2041 // test the uniforms which used to handle the atlas rect
2042 // the four frames should be located inside atlas as follows: atlas size 100*100
2051 Renderer renderer = actor.GetRendererAt( 0u );
2052 DALI_TEST_CHECK( renderer );
2054 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2055 // take into consideration the half pixel correction
2056 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2058 // waiting for the resource uploading
2059 application.SendNotification();
2060 application.Render();
2062 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2064 // Force the timer used by the animatedImageVisual to tick,
2065 Dali::Timer timer = Timer::New( 0 );
2066 timer.MockEmitSignal();
2067 application.SendNotification();
2068 application.Render();
2069 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2070 // take into consideration the half pixel correction
2071 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2073 // Force the timer used by the animatedImageVisual to tick,
2074 timer.MockEmitSignal();
2075 application.SendNotification();
2076 application.Render();
2077 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2078 // take into consideration the half pixel correction
2079 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2081 // Force the timer used by the animatedImageVisual to tick,
2082 timer.MockEmitSignal();
2083 application.SendNotification();
2084 application.Render();
2085 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2086 // take into consideration the half pixel correction
2087 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2089 // Test SetOffStage().
2091 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2096 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
2098 ToolkitTestApplication application;
2099 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
2101 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
2102 Property::Map propertyMap;
2103 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
2104 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
2105 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
2106 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
2107 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
2109 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
2110 DALI_TEST_CHECK( visual );
2112 TestGlAbstraction& gl = application.GetGlAbstraction();
2113 TraceCallStack& textureTrace = gl.GetTextureTrace();
2114 textureTrace.Enable(true);
2115 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
2116 texParameterTrace.Enable( true );
2118 DummyControl actor = DummyControl::New();
2119 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2120 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2121 actor.SetSize( 200.0f, 200.0f );
2122 Stage::GetCurrent().Add( actor );
2124 application.SendNotification();
2125 application.Render();
2127 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2129 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2131 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
2132 std::stringstream out;
2133 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
2134 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2136 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
2137 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2139 // test the uniforms which used to handle the wrap mode
2140 Renderer renderer = actor.GetRendererAt( 0u );
2141 DALI_TEST_CHECK( renderer );
2143 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
2144 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
2145 Vector4 pixelAreaUniform;
2146 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
2147 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2149 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
2150 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
2151 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
2152 Vector2 wrapModeUniform;
2153 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
2154 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2157 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );