2 * Copyright (c) 2016 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/visual-factory/visual-factory.h>
30 #include <dali-toolkit/dali-toolkit.h>
31 #include "dummy-control.h"
34 using namespace Dali::Toolkit;
38 typedef NinePatchImage::StretchRanges StretchRanges;
40 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
41 const char* TEST_NPATCH_FILE_NAME = "gallery_image_01.9.png";
42 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
43 const char* TEST_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube.obj";
44 const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
45 const char* TEST_SIMPLE_OBJ_FILE_NAME = TEST_RESOURCE_DIR "/Cube-Points-Only.obj";
46 const char* TEST_SIMPLE_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal-Simple.mtl";
48 // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
49 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
51 // resolution: 34*34, pixel format: RGBA8888
52 static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
53 // resolution: 600*600, pixel format: RGB888
54 static const char* gImage_600_RGB = TEST_RESOURCE_DIR "/test-image-600.jpg";
56 Property::Map DefaultTransform()
58 Property::Map transformMap;
60 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET, Vector2(0.0f, 0.0f) )
61 .Add( Toolkit::DevelVisual::Transform::Property::SIZE, Vector2(1.0f, 1.0f) )
62 .Add( Toolkit::DevelVisual::Transform::Property::ORIGIN, Toolkit::Align::CENTER )
63 .Add( Toolkit::DevelVisual::Transform::Property::ANCHOR_POINT, Toolkit::Align::CENTER )
64 .Add( Toolkit::DevelVisual::Transform::Property::OFFSET_SIZE_MODE, Vector4::ZERO );
68 Integration::Bitmap* CreateBitmap( unsigned int imageWidth, unsigned int imageHeight, unsigned int initialColor, Pixel::Format pixelFormat )
70 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
71 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
72 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
74 memset( pixbuffer, initialColor, imageHeight * imageWidth * bytesPerPixel );
79 void InitialiseRegionsToZeroAlpha( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, Pixel::Format pixelFormat )
81 PixelBuffer* pixbuffer = image->GetBuffer();
82 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
84 for( unsigned int row = 0; row < imageWidth; ++row )
86 unsigned int pixelOffset = row * bytesPerPixel;
87 pixbuffer[ pixelOffset + 3 ] = 0x00;
88 pixelOffset += ( imageHeight - 1 ) * imageWidth * bytesPerPixel;
89 pixbuffer[ pixelOffset + 3 ] = 0x00;
92 for ( unsigned int column = 0; column < imageHeight; ++column )
94 unsigned int pixelOffset = column * imageWidth * bytesPerPixel;
95 pixbuffer[ pixelOffset + 3 ] = 0x00;
96 pixelOffset += ( imageWidth -1 ) * bytesPerPixel;
97 pixbuffer[ pixelOffset + 3 ] = 0x00;
101 void AddStretchRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const StretchRanges& stretchRangesX, const StretchRanges& stretchRangesY, Pixel::Format pixelFormat )
103 PixelBuffer* pixbuffer = image->GetBuffer();
104 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
106 for(StretchRanges::ConstIterator it = stretchRangesX.Begin(); it != stretchRangesX.End(); ++it)
108 const Uint16Pair& range = *it;
109 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
110 for( unsigned int column = range.GetX() + 1u; column < range.GetY() + 1u; ++column )
112 unsigned int pixelOffset = column * bytesPerPixel;
113 pixbuffer[ pixelOffset ] = 0x00;
114 pixbuffer[ pixelOffset + 1 ] = 0x00;
115 pixbuffer[ pixelOffset + 2 ] = 0x00;
116 pixbuffer[ pixelOffset + 3 ] = 0xFF;
121 for(StretchRanges::ConstIterator it = stretchRangesY.Begin(); it != stretchRangesY.End(); ++it)
123 const Uint16Pair& range = *it;
124 //since the stretch range is in the cropped image space, we need to offset by 1 to get it to the uncropped image space
125 for( unsigned int row = range.GetX() + 1u; row < range.GetY() + 1u; ++row )
127 unsigned int pixelOffset = row * imageWidth * bytesPerPixel;
128 pixbuffer[ pixelOffset ] = 0x00;
129 pixbuffer[ pixelOffset + 1 ] = 0x00;
130 pixbuffer[ pixelOffset + 2 ] = 0x00;
131 pixbuffer[ pixelOffset + 3 ] = 0xFF;
136 void AddChildRegionsToImage( Integration::Bitmap* image, unsigned int imageWidth, unsigned int imageHeight, const Vector4& requiredChildRegion, Pixel::Format pixelFormat )
138 PixelBuffer* pixbuffer = image->GetBuffer();
139 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
141 Integration::Bitmap::PackedPixelsProfile* srcProfile = image->GetPackedPixelsProfile();
142 unsigned int bufferStride = srcProfile->GetBufferStride();
144 // Add bottom child region
145 for( unsigned int column = requiredChildRegion.x; column < imageWidth - requiredChildRegion.z; ++column )
147 unsigned int pixelOffset = column * bytesPerPixel;
148 pixelOffset += ( imageHeight - 1 ) * bufferStride;
149 pixbuffer[ pixelOffset ] = 0x00;
150 pixbuffer[ pixelOffset + 1 ] = 0x00;
151 pixbuffer[ pixelOffset + 2 ] = 0x00;
152 pixbuffer[ pixelOffset + 3 ] = 0xFF;
155 // Add right child region
156 for ( unsigned int row = requiredChildRegion.y; row < imageHeight - requiredChildRegion.w; ++row )
158 unsigned int pixelOffset = row * bufferStride + ( imageWidth - 1 ) * bytesPerPixel;
159 pixbuffer[ pixelOffset ] = 0x00;
160 pixbuffer[ pixelOffset + 1 ] = 0x00;
161 pixbuffer[ pixelOffset + 2 ] = 0x00;
162 pixbuffer[ pixelOffset + 3 ] = 0xFF;
166 Integration::ResourcePointer CustomizeNinePatch( TestApplication& application,
167 unsigned int ninePatchImageWidth,
168 unsigned int ninePatchImageHeight,
169 const StretchRanges& stretchRangesX,
170 const StretchRanges& stretchRangesY,
171 bool addChildRegion = false,
172 Vector4 requiredChildRegion = Vector4::ZERO )
174 TestPlatformAbstraction& platform = application.GetPlatform();
176 Pixel::Format pixelFormat = Pixel::RGBA8888;
178 tet_infoline("Create Bitmap");
179 platform.SetClosestImageSize(Vector2( ninePatchImageWidth, ninePatchImageHeight));
180 Integration::Bitmap* bitmap = CreateBitmap( ninePatchImageWidth, ninePatchImageHeight, 0xFF, pixelFormat );
182 tet_infoline("Clear border regions");
183 InitialiseRegionsToZeroAlpha( bitmap, ninePatchImageWidth, ninePatchImageHeight, pixelFormat );
185 tet_infoline("Add Stretch regions to Bitmap");
186 AddStretchRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY, pixelFormat );
190 tet_infoline("Add Child regions to Bitmap");
191 AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat );
194 tet_infoline("Getting resource");
195 Integration::ResourcePointer resourcePtr(bitmap);
196 //platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
197 platform.SetSynchronouslyLoadedResource( resourcePtr);
202 void TestVisualRender( ToolkitTestApplication& application,
204 Visual::Base& visual,
205 std::size_t expectedSamplers = 0,
206 ImageDimensions imageDimensions = ImageDimensions(),
207 Integration::ResourcePointer resourcePtr = Integration::ResourcePointer())
209 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
210 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
214 // set the image size, for test case, this needs to be set before loading started
215 application.GetPlatform().SetClosestImageSize( Vector2(imageDimensions.GetWidth(), imageDimensions.GetHeight()) );
218 actor.SetSize( 200.f, 200.f );
219 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
221 Stage::GetCurrent().Add( actor );
223 application.SendNotification();
224 application.Render();
228 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
231 application.GetPlatform().SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr );
235 application.Render();
236 application.SendNotification();
240 DALI_TEST_EQUALS( application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc) ||
241 application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceSynchronouslyFunc ), true, TEST_LOCATION);
244 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
251 void dali_visual_factory_startup(void)
253 test_return_value = TET_UNDEF;
256 void dali_visual_factory_cleanup(void)
258 test_return_value = TET_PASS;
261 int UtcDaliVisualFactoryGet(void)
263 ToolkitTestApplication application;
264 tet_infoline( "UtcDaliVisualFactory" );
268 type = TypeRegistry::Get().GetTypeInfo( "VisualFactory" );
269 DALI_TEST_CHECK( type );
270 BaseHandle handle = type.CreateInstance();
271 DALI_TEST_CHECK( handle );
273 VisualFactory factory;
274 factory = VisualFactory::Get();
275 DALI_TEST_CHECK( factory );
277 VisualFactory newFactory = VisualFactory::Get();
278 DALI_TEST_CHECK( newFactory );
280 // Check that visual factory is a singleton
281 DALI_TEST_CHECK(factory == newFactory);
286 int UtcDaliVisualFactoryCopyAndAssignment(void)
288 ToolkitTestApplication application;
289 tet_infoline( "UtcDaliVisualFactoryCopyAndAssignment" );
290 VisualFactory factory = VisualFactory::Get();
292 VisualFactory factoryCopy( factory );
293 DALI_TEST_CHECK(factory == factoryCopy);
295 VisualFactory emptyFactory;
296 VisualFactory emptyFactoryCopy( emptyFactory );
297 DALI_TEST_CHECK(emptyFactory == emptyFactoryCopy);
299 VisualFactory factoryEquals;
300 factoryEquals = factory;
301 DALI_TEST_CHECK(factory == factoryEquals);
303 VisualFactory emptyFactoryEquals;
304 emptyFactoryEquals = emptyFactory;
305 DALI_TEST_CHECK( emptyFactory == emptyFactoryEquals );
309 DALI_TEST_CHECK( factory = factoryCopy );
314 int UtcDaliVisualFactoryGetColorVisual1(void)
316 ToolkitTestApplication application;
317 tet_infoline( "UtcDaliVisualFactoryGetColorVisual1: Request color visual with a Property::Map" );
319 VisualFactory factory = VisualFactory::Get();
320 DALI_TEST_CHECK( factory );
322 Property::Map propertyMap;
323 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
324 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
325 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, testColor);
327 Visual::Base visual = factory.CreateVisual(propertyMap);
328 DALI_TEST_CHECK( visual );
330 DummyControl actor = DummyControl::New();
331 TestVisualRender( application, actor, visual );
333 Vector4 actualValue(Vector4::ZERO);
334 TestGlAbstraction& gl = application.GetGlAbstraction();
335 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
336 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
341 int UtcDaliVisualFactoryGetColorVisual2(void)
343 ToolkitTestApplication application;
344 tet_infoline( "UtcDaliVisualFactoryGetColorVisual2: Request color visual with a Vector4" );
346 VisualFactory factory = VisualFactory::Get();
347 DALI_TEST_CHECK( factory );
349 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
350 Dali::Property::Map map;
351 map[ Visual::Property::TYPE ] = Visual::COLOR;
352 map[ ColorVisual::Property::MIX_COLOR ] = testColor;
353 Visual::Base visual = factory.CreateVisual( map );
354 DALI_TEST_CHECK( visual );
356 DummyControl actor = DummyControl::New();
357 TestVisualRender( application, actor, visual );
359 Vector4 actualValue(Vector4::ZERO);
360 TestGlAbstraction& gl = application.GetGlAbstraction();
361 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "mixColor", actualValue ) );
362 DALI_TEST_EQUALS( actualValue, testColor, TEST_LOCATION );
364 Stage::GetCurrent().Remove(actor);
365 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
370 int UtcDaliVisualFactoryGetBorderVisual1(void)
372 ToolkitTestApplication application;
373 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual1: Request border visual with a Property::Map" );
375 VisualFactory factory = VisualFactory::Get();
376 DALI_TEST_CHECK( factory );
378 Property::Map propertyMap;
379 Vector4 testColor( 1.f, 0.5f, 0.3f, 0.2f );
380 float testSize = 5.f;
381 propertyMap.Insert(Visual::Property::TYPE, Visual::BORDER);
382 propertyMap.Insert(BorderVisual::Property::COLOR, testColor);
383 propertyMap.Insert(BorderVisual::Property::SIZE, testSize);
385 Visual::Base visual = factory.CreateVisual(propertyMap);
386 DALI_TEST_CHECK( visual );
388 DummyControl actor = DummyControl::New();
389 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
390 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
391 actor.SetSize(200.f, 200.f);
392 Stage::GetCurrent().Add( actor );
393 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
395 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
396 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
397 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
399 TestGlAbstraction& gl = application.GetGlAbstraction();
401 application.SendNotification();
402 application.Render(0);
404 Vector4 actualColor(Vector4::ZERO);
405 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
406 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
408 float actualSize = 0.f;
409 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
410 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
413 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
418 int UtcDaliVisualFactoryGetBorderVisual2(void)
420 ToolkitTestApplication application;
421 tet_infoline( "UtcDaliVisualFactoryGetBorderVisual2: Request border visual with a borderSize and a borderColor" );
423 VisualFactory factory = VisualFactory::Get();
424 DALI_TEST_CHECK( factory );
426 Vector4 testColor( 1.f, 0.5f, 0.3f, 1.f );
427 float testSize = 5.f;
429 Dali::Property::Map propertyMap;
430 propertyMap[ Visual::Property::TYPE ] = Visual::BORDER;
431 propertyMap[ BorderVisual::Property::COLOR ] = testColor;
432 propertyMap[ BorderVisual::Property::SIZE ] = testSize;
433 Visual::Base visual = factory.CreateVisual( propertyMap );
434 DALI_TEST_CHECK( visual );
436 DummyControl actor = DummyControl::New();
437 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
438 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
439 actor.SetSize(200.f, 200.f);
440 Stage::GetCurrent().Add( actor );
441 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f));
443 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
445 TestGlAbstraction& gl = application.GetGlAbstraction();
447 application.SendNotification();
448 application.Render(0);
450 int blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
451 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::AUTO, TEST_LOCATION );
453 Vector4 actualColor(Vector4::ZERO);
454 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "borderColor", actualColor ) );
455 DALI_TEST_EQUALS( actualColor, testColor, TEST_LOCATION );
457 float actualSize = 0.f;
458 DALI_TEST_CHECK( gl.GetUniformValue<float>( "borderSize", actualSize ) );
459 DALI_TEST_EQUALS( actualSize, testSize, TEST_LOCATION );
463 // enable the anti-aliasing
464 Dali::Property::Map map;
465 map[ Visual::Property::TYPE ] = Visual::BORDER;
466 map[ BorderVisual::Property::COLOR ] = testColor;
467 map[ BorderVisual::Property::SIZE ] = testSize;
468 map[ BorderVisual::Property::ANTI_ALIASING ] = true;
469 visual = factory.CreateVisual( map );
471 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
472 Stage::GetCurrent().Add( actor );
474 blendMode = actor.GetRendererAt(0u).GetProperty<int>( Renderer::Property::BLEND_MODE );
475 DALI_TEST_EQUALS( static_cast<BlendMode::Type>(blendMode), BlendMode::ON, TEST_LOCATION );
480 int UtcDaliVisualFactoryGetLinearGradientVisual(void)
482 ToolkitTestApplication application;
483 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
485 VisualFactory factory = VisualFactory::Get();
486 DALI_TEST_CHECK( factory );
488 Property::Map propertyMap;
489 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
491 Vector2 start(-1.f, -1.f);
492 Vector2 end(1.f, 1.f);
493 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
494 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
495 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
497 Property::Array stopOffsets;
498 stopOffsets.PushBack( 0.2f );
499 stopOffsets.PushBack( 0.8f );
500 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
502 Property::Array stopColors;
503 stopColors.PushBack( Color::RED );
504 stopColors.PushBack( Color::GREEN );
505 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
507 Visual::Base visual = factory.CreateVisual(propertyMap);
508 DALI_TEST_CHECK( visual );
510 // A lookup texture is generated and pass to shader as sampler
511 DummyControl actor = DummyControl::New();
512 TestVisualRender( application, actor, visual, 1u);
517 int UtcDaliVisualFactoryGetRadialGradientVisual(void)
519 ToolkitTestApplication application;
520 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
522 VisualFactory factory = VisualFactory::Get();
523 DALI_TEST_CHECK( factory );
525 Property::Map propertyMap;
526 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
528 Vector2 center(100.f, 100.f);
529 float radius = 100.f;
530 propertyMap.Insert(GradientVisual::Property::UNITS, GradientVisual::Units::USER_SPACE);
531 propertyMap.Insert(GradientVisual::Property::CENTER, center);
532 propertyMap.Insert(GradientVisual::Property::RADIUS, radius);
534 Property::Array stopOffsets;
535 stopOffsets.PushBack( 0.0f );
536 stopOffsets.PushBack( 1.f );
537 propertyMap.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
539 Property::Array stopColors;
540 stopColors.PushBack( Color::RED );
541 stopColors.PushBack( Color::GREEN );
542 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
544 Visual::Base visual = factory.CreateVisual(propertyMap);
545 DALI_TEST_CHECK( visual );
547 // A lookup texture is generated and pass to shader as sampler
548 DummyControl actor = DummyControl::New();
549 TestVisualRender( application, actor, visual, 1u );
551 Matrix3 alignMatrix( radius, 0.f, 0.f, 0.f, radius, 0.f, center.x, center.y, 1.f );
552 alignMatrix.Invert();
554 Matrix3 actualValue( Matrix3::IDENTITY );
555 TestGlAbstraction& gl = application.GetGlAbstraction();
556 DALI_TEST_CHECK( gl.GetUniformValue<Matrix3>( "uAlignmentMatrix", actualValue ) );
557 DALI_TEST_EQUALS( actualValue, alignMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
562 int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void)
564 ToolkitTestApplication application;
565 tet_infoline("UtcDaliVisualFactoryGetRadialGradientVisual");
567 VisualFactory factory = VisualFactory::Get();
568 DALI_TEST_CHECK( factory );
570 Property::Map propertyMap;
571 propertyMap.Insert(Visual::Property::TYPE, Visual::GRADIENT);
573 Vector2 start(-1.f, -1.f);
574 Vector2 end(1.f, 1.f);
575 propertyMap.Insert(GradientVisual::Property::START_POSITION, start);
576 propertyMap.Insert(GradientVisual::Property::END_POSITION, end);
577 propertyMap.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
579 Property::Array stopColors;
580 stopColors.PushBack( Color::RED );
581 stopColors.PushBack( Color::GREEN );
582 propertyMap.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
584 Visual::Base visual = factory.CreateVisual(propertyMap);
585 DALI_TEST_CHECK( visual );
587 // A lookup texture is generated and pass to shader as sampler
588 DummyControl actor = DummyControl::New();
589 TestVisualRender( application, actor, visual, 1u );
591 Stage::GetCurrent().Remove( actor );
592 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
597 int UtcDaliVisualFactoryGetImageVisual1(void)
599 ToolkitTestApplication application;
600 tet_infoline( "UtcDaliVisualFactoryGetImageVisual1: Request image visual with a Property::Map" );
602 VisualFactory factory = VisualFactory::Get();
603 DALI_TEST_CHECK( factory );
605 Property::Map propertyMap;
606 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
607 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
609 Visual::Base visual = factory.CreateVisual( propertyMap );
610 DALI_TEST_CHECK( visual );
612 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
613 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
616 const int height=513;
617 TestGlAbstraction& gl = application.GetGlAbstraction();
618 TraceCallStack& textureTrace = gl.GetTextureTrace();
619 textureTrace.Enable(true);
621 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
622 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
624 DummyControl actor = DummyControl::New();
625 TestVisualRender( application, actor, visual, 1u,
626 ImageDimensions(width, height),
627 Integration::ResourcePointer( bitmap ) );
629 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
631 Stage::GetCurrent().Remove( actor );
632 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
637 int UtcDaliVisualFactoryGetImageVisual2(void)
639 ToolkitTestApplication application;
640 tet_infoline( "UtcDaliVisualFactoryGetImageVisual2: Request image visual with an image handle" );
642 VisualFactory factory = VisualFactory::Get();
643 DALI_TEST_CHECK( factory );
645 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
646 Visual::Base visual = factory.CreateVisual( image );
648 // For tesing the LoadResourceFunc is called, a big image size should be set, so the atlasing is not applied.
649 // Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
652 const int height=513;
654 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
655 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height,width, height );
657 TestGlAbstraction& gl = application.GetGlAbstraction();
658 TraceCallStack& textureTrace = gl.GetTextureTrace();
659 textureTrace.Enable(true);
661 DummyControl actor = DummyControl::New();
662 TestVisualRender( application, actor, visual, 1u,
663 ImageDimensions(width, height),
664 Integration::ResourcePointer(bitmap) );
666 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
670 int UtcDaliVisualFactoryGetImageVisual3(void)
672 ToolkitTestApplication application;
673 tet_infoline( "UtcDaliVisualFactoryGetImageVisual3: Request image visual with a Property::Map, test custom wrap mode and pixel area with atlasing" );
675 VisualFactory factory = VisualFactory::Get();
676 DALI_TEST_CHECK( factory );
678 // Test wrap mode with atlasing. Image with a size smaller than 512*512 will be uploaded as a part of the atlas.
681 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
683 Property::Map propertyMap;
684 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
685 propertyMap.Insert( ImageVisual::Property::URL, gImage_34_RGBA );
686 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
687 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
688 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
689 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
690 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
691 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
693 Visual::Base visual = factory.CreateVisual( propertyMap );
694 DALI_TEST_CHECK( visual );
696 TestGlAbstraction& gl = application.GetGlAbstraction();
697 TraceCallStack& textureTrace = gl.GetTextureTrace();
698 textureTrace.Enable(true);
699 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
700 texParameterTrace.Enable( true );
702 DummyControl actor = DummyControl::New();
703 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
704 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
705 actor.SetSize(2000, 2000);
706 actor.SetParentOrigin(ParentOrigin::CENTER);
707 Stage::GetCurrent().Add( actor );
710 application.SendNotification();
711 application.Render();
712 application.Render();
713 application.SendNotification();
714 BitmapLoader loader = BitmapLoader::GetLatestCreated();
715 DALI_TEST_CHECK( loader );
716 loader.WaitForLoading();// waiting until the image to be loaded
717 DALI_TEST_CHECK( loader.IsLoaded() );
719 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
721 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
723 // WITH atlasing, the wrapping is handled manually in shader, so the following gl function should not be called
724 std::stringstream out;
725 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
726 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
728 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
729 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
731 // test the uniforms which used to handle the wrap mode
732 Renderer renderer = actor.GetRendererAt( 0u );
733 DALI_TEST_CHECK( renderer );
735 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
736 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
737 Vector4 pixelAreaUniform;
738 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
739 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
741 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
742 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
743 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
744 Vector2 wrapModeUniform;
745 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
746 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
749 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
754 int UtcDaliVisualFactoryGetImageVisual4(void)
756 ToolkitTestApplication application;
757 tet_infoline( "UtcDaliVisualFactoryGetImageVisual4: Request image visual with a Property::Map, test custom wrap mode and pixel area without atlasing" );
759 VisualFactory factory = VisualFactory::Get();
760 DALI_TEST_CHECK( factory );
762 // Test wrap mode without atlasing. Image with a size bigger than 512*512 will NOT be uploaded as a part of the atlas.
764 const int height=600;
765 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
767 Property::Map propertyMap;
768 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
769 propertyMap.Insert( ImageVisual::Property::URL, gImage_600_RGB );
770 propertyMap.Insert( ImageVisual::Property::DESIRED_WIDTH, width );
771 propertyMap.Insert( ImageVisual::Property::DESIRED_HEIGHT, height );
772 propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, true );
773 propertyMap.Insert( ImageVisual::Property::PIXEL_AREA, pixelArea );
774 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT );
775 propertyMap.Insert( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
777 Visual::Base visual = factory.CreateVisual( propertyMap );
778 DALI_TEST_CHECK( visual );
780 TestGlAbstraction& gl = application.GetGlAbstraction();
781 TraceCallStack& textureTrace = gl.GetTextureTrace();
782 textureTrace.Enable(true);
783 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
784 texParameterTrace.Enable( true );
786 DummyControl actor = DummyControl::New();
787 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
788 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
789 actor.SetSize(2000, 2000);
790 actor.SetParentOrigin(ParentOrigin::CENTER);
791 Stage::GetCurrent().Add( actor );
794 application.SendNotification();
795 application.Render();
796 application.Render();
797 application.SendNotification();
798 BitmapLoader loader = BitmapLoader::GetLatestCreated();
799 DALI_TEST_CHECK( loader );
800 loader.WaitForLoading();// waiting until the image to be loaded
801 DALI_TEST_CHECK( loader.IsLoaded() );
803 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
805 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
807 // WITHOUT atlasing, the wrapping is handled by setting gl texture parameters
808 std::stringstream out;
809 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
810 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
812 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
813 DALI_TEST_CHECK( texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
815 // test the uniforms which used to handle the wrap mode
816 Renderer renderer = actor.GetRendererAt( 0u );
817 DALI_TEST_CHECK( renderer );
819 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
820 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
821 Vector4 pixelAreaUniform;
822 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
823 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
825 Property::Index wrapModeIndex = renderer.GetPropertyIndex( "wrapMode" );
826 DALI_TEST_CHECK(wrapModeIndex == Property::INVALID_INDEX);
829 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
834 int UtcDaliVisualFactoryGetNPatchVisual1(void)
836 ToolkitTestApplication application;
837 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual1: Request 9-patch visual with a Property::Map" );
839 VisualFactory factory = VisualFactory::Get();
840 DALI_TEST_CHECK( factory );
842 const unsigned int ninePatchImageHeight = 18;
843 const unsigned int ninePatchImageWidth = 28;
844 StretchRanges stretchRangesX;
845 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
846 StretchRanges stretchRangesY;
847 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
848 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
850 Property::Map propertyMap;
851 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
852 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
854 tet_infoline( "whole grid" );
855 Visual::Base visual = factory.CreateVisual( propertyMap );
856 DALI_TEST_CHECK( visual );
859 TestGlAbstraction& gl = application.GetGlAbstraction();
860 TraceCallStack& textureTrace = gl.GetTextureTrace();
861 textureTrace.Enable(true);
863 DummyControl actor = DummyControl::New();
864 TestVisualRender( application, actor, visual, 1u,
865 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
868 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
871 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
873 tet_infoline( "border only" );
874 Visual::Base visual = factory.CreateVisual( propertyMap );
875 DALI_TEST_CHECK( visual );
877 TestGlAbstraction& gl = application.GetGlAbstraction();
878 TraceCallStack& textureTrace = gl.GetTextureTrace();
879 textureTrace.Enable(true);
881 DummyControl actor = DummyControl::New();
882 TestVisualRender( application, actor, visual, 1u,
883 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
886 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
892 int UtcDaliVisualFactoryGetNPatchVisual2(void)
894 ToolkitTestApplication application;
895 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual2: Request n-patch visual with a Property::Map" );
897 VisualFactory factory = VisualFactory::Get();
898 DALI_TEST_CHECK( factory );
900 const unsigned int ninePatchImageWidth = 18;
901 const unsigned int ninePatchImageHeight = 28;
902 StretchRanges stretchRangesX;
903 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
904 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
905 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
906 StretchRanges stretchRangesY;
907 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
908 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
909 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
910 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
911 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
913 Property::Map propertyMap;
914 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
915 propertyMap.Insert( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
917 Visual::Base visual = factory.CreateVisual( propertyMap );
918 DALI_TEST_CHECK( visual );
920 TestGlAbstraction& gl = application.GetGlAbstraction();
921 TraceCallStack& textureTrace = gl.GetTextureTrace();
922 textureTrace.Enable(true);
924 DummyControl actor = DummyControl::New();
925 TestVisualRender( application, actor, visual, 1u,
926 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
929 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
931 Stage::GetCurrent().Remove( actor );
932 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
935 propertyMap.Insert( ImageVisual::Property::BORDER_ONLY, true );
937 tet_infoline( "border only" );
938 Visual::Base visual = factory.CreateVisual( propertyMap );
939 DALI_TEST_CHECK( visual );
941 TestGlAbstraction& gl = application.GetGlAbstraction();
942 TraceCallStack& textureTrace = gl.GetTextureTrace();
943 textureTrace.Enable(true);
944 DummyControl actor = DummyControl::New();
945 TestVisualRender( application, actor, visual, 1u,
946 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
950 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
952 Stage::GetCurrent().Remove( actor );
953 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
959 int UtcDaliVisualFactoryGetNPatchVisual3(void)
961 ToolkitTestApplication application;
962 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual3: Request 9-patch visual with an image url" );
964 VisualFactory factory = VisualFactory::Get();
965 DALI_TEST_CHECK( factory );
967 const unsigned int ninePatchImageHeight = 18;
968 const unsigned int ninePatchImageWidth = 28;
969 StretchRanges stretchRangesX;
970 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
971 StretchRanges stretchRangesY;
972 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
973 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
975 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
976 DALI_TEST_CHECK( visual );
978 TestGlAbstraction& gl = application.GetGlAbstraction();
979 TraceCallStack& textureTrace = gl.GetTextureTrace();
980 textureTrace.Enable(true);
982 DummyControl actor = DummyControl::New();
983 TestVisualRender( application, actor, visual, 1u,
984 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
987 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
990 ResourceImage image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
991 Visual::Base nPatchVisual = factory.CreateVisual( image );
992 Vector2 controlSize( 20.f, 30.f ), naturalSize(0,0);
993 nPatchVisual.SetTransformAndSize(DefaultTransform(), controlSize );
994 nPatchVisual.GetNaturalSize( naturalSize );
995 DALI_TEST_EQUALS( naturalSize, Vector2( ninePatchImageWidth-2, ninePatchImageHeight-2 ), TEST_LOCATION );
1000 int UtcDaliVisualFactoryGetNPatchVisual4(void)
1002 ToolkitTestApplication application;
1003 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual4: Request n-patch visual with an image url" );
1005 VisualFactory factory = VisualFactory::Get();
1006 DALI_TEST_CHECK( factory );
1008 const unsigned int ninePatchImageHeight = 18;
1009 const unsigned int ninePatchImageWidth = 28;
1010 StretchRanges stretchRangesX;
1011 stretchRangesX.PushBack( Uint16Pair( 2, 3 ) );
1012 stretchRangesX.PushBack( Uint16Pair( 5, 7 ) );
1013 stretchRangesX.PushBack( Uint16Pair( 12, 15 ) );
1014 StretchRanges stretchRangesY;
1015 stretchRangesY.PushBack( Uint16Pair( 4, 5 ) );
1016 stretchRangesY.PushBack( Uint16Pair( 8, 12 ) );
1017 stretchRangesY.PushBack( Uint16Pair( 15, 16 ) );
1018 stretchRangesY.PushBack( Uint16Pair( 25, 27 ) );
1019 Integration::ResourcePointer ninePatchResource = CustomizeNinePatch( application, ninePatchImageWidth, ninePatchImageHeight, stretchRangesX, stretchRangesY );
1021 Visual::Base visual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
1022 DALI_TEST_CHECK( visual );
1024 TestGlAbstraction& gl = application.GetGlAbstraction();
1025 TraceCallStack& textureTrace = gl.GetTextureTrace();
1026 textureTrace.Enable(true);
1028 DummyControl actor = DummyControl::New();
1029 TestVisualRender( application, actor, visual, 1u,
1030 ImageDimensions(ninePatchImageWidth, ninePatchImageHeight),
1031 ninePatchResource );
1033 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1038 int UtcDaliVisualFactoryGetNPatchVisualN1(void)
1040 //This should still load but display an error image
1042 ToolkitTestApplication application;
1043 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid image url" );
1045 VisualFactory factory = VisualFactory::Get();
1046 DALI_TEST_CHECK( factory );
1048 Visual::Base visual = factory.CreateVisual( "ERROR.9.jpg", ImageDimensions() );
1049 DALI_TEST_CHECK( visual );
1051 //The testkit still has to load a bitmap for the broken renderer image
1052 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1053 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1055 TestGlAbstraction& gl = application.GetGlAbstraction();
1056 TraceCallStack& textureTrace = gl.GetTextureTrace();
1057 textureTrace.Enable(true);
1059 DummyControl actor = DummyControl::New();
1060 TestVisualRender( application, actor, visual, 1u,
1062 Integration::ResourcePointer(bitmap) );
1064 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1069 int UtcDaliVisualFactoryGetNPatchVisualN2(void)
1071 //This should still load but display an error image
1073 ToolkitTestApplication application;
1074 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid URL" );
1076 VisualFactory factory = VisualFactory::Get();
1077 DALI_TEST_CHECK( factory );
1079 Property::Map propertyMap;
1080 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1081 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1083 Visual::Base visual = factory.CreateVisual( propertyMap );
1084 DALI_TEST_CHECK( visual );
1086 //The testkit still has to load a bitmap for the broken renderer image
1087 Integration::Bitmap* bitmap = Integration::Bitmap::New(Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD);
1088 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 100, 100, 100, 100 );
1090 TestGlAbstraction& gl = application.GetGlAbstraction();
1091 TraceCallStack& textureTrace = gl.GetTextureTrace();
1092 textureTrace.Enable(true);
1093 TraceCallStack& drawTrace = gl.GetDrawTrace();
1094 drawTrace.Enable(true);
1096 DummyControl actor = DummyControl::New();
1097 TestVisualRender( application, actor, visual, 1u,
1099 Integration::ResourcePointer(bitmap) );
1101 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1106 int UtcDaliVisualFactoryGetNPatchVisualN3(void)
1108 // Passing in an invalid visual type so we should not get a visual
1110 ToolkitTestApplication application;
1111 tet_infoline( "UtcDaliVisualFactoryGetNPatchVisualN: Request n-patch visual with an invalid visual type" );
1113 VisualFactory factory = VisualFactory::Get();
1114 DALI_TEST_CHECK( factory );
1116 Property::Map propertyMap;
1117 propertyMap.Insert( Visual::Property::TYPE, 111 );
1118 propertyMap.Insert( ImageVisual::Property::URL, "ERROR.9.jpg" );
1120 Visual::Base visual = factory.CreateVisual( propertyMap );
1121 DALI_TEST_CHECK( !visual );
1126 int UtcDaliVisualFactoryGetSvgVisual(void)
1128 ToolkitTestApplication application;
1129 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1131 VisualFactory factory = VisualFactory::Get();
1132 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions() );
1133 DALI_TEST_CHECK( visual );
1135 TestGlAbstraction& gl = application.GetGlAbstraction();
1136 TraceCallStack& textureTrace = gl.GetTextureTrace();
1137 textureTrace.Enable(true);
1139 DummyControl actor = DummyControl::New();
1140 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1141 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1142 actor.SetSize( 200.f, 200.f );
1143 Stage::GetCurrent().Add( actor );
1144 visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) );
1146 application.SendNotification();
1147 application.Render();
1149 // renderer is not added to actor until the rasterization is completed.
1150 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1152 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1154 // renderer is added to actor
1155 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1157 // waiting for the resource uploading
1158 application.SendNotification();
1159 application.Render();
1161 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1166 int UtcDaliVisualFactoryGetSvgVisualLarge(void)
1168 ToolkitTestApplication application;
1169 tet_infoline( "UtcDaliVisualFactoryGetSvgVisual: Request svg visual with a svg url" );
1171 VisualFactory factory = VisualFactory::Get();
1172 Visual::Base visual = factory.CreateVisual( TEST_SVG_FILE_NAME, ImageDimensions( 2000, 2000 ) );
1173 DALI_TEST_CHECK( visual );
1175 TestGlAbstraction& gl = application.GetGlAbstraction();
1176 TraceCallStack& textureTrace = gl.GetTextureTrace();
1177 textureTrace.Enable(true);
1179 DummyControl actor = DummyControl::New(true);
1180 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1181 actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size.
1182 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1183 Stage::GetCurrent().Add( actor );
1185 application.SendNotification();
1186 application.Render();
1188 // renderer is not added to actor until the rasterization is completed.
1189 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
1191 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1193 // renderer is added to actor
1194 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
1196 // waiting for the resource uploading
1197 application.SendNotification();
1198 application.Render();
1200 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
1205 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1206 //This is expected to succeed, which will then pass the test.
1207 void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1209 VisualFactory factory = VisualFactory::Get();
1210 DALI_TEST_CHECK( factory );
1212 //Create a mesh visual.
1213 Visual::Base visual = factory.CreateVisual( propertyMap );
1214 DALI_TEST_CHECK( visual );
1216 //Create an actor on stage to house the visual.
1217 DummyControl actor = DummyControl::New();
1218 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1219 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1220 actor.SetSize( 200.f, 200.f );
1221 Stage::GetCurrent().Add( actor );
1222 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1224 //Ensure set on stage.
1225 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1227 //Attempt to render to queue resource load requests.
1228 application.SendNotification();
1229 application.Render( 0 );
1231 //Tell the platform abstraction that the required resources have been loaded.
1232 TestPlatformAbstraction& platform = application.GetPlatform();
1233 platform.SetAllResourceRequestsAsLoaded();
1235 //Render again to upload the now-loaded textures.
1236 application.SendNotification();
1237 application.Render( 0 );
1239 Matrix testScaleMatrix;
1240 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1241 Matrix actualScaleMatrix;
1243 //Test to see if the object has been successfully loaded.
1244 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1245 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1247 //Finish by setting off stage, and ensuring this was successful.
1249 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1252 //Creates a mesh visual from the given propertyMap and tries to load it on stage in the given application.
1253 //This is expected to fail, which will then pass the test.
1254 void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
1256 VisualFactory factory = VisualFactory::Get();
1257 DALI_TEST_CHECK( factory );
1259 //Create a mesh visual.
1260 Visual::Base visual = factory.CreateVisual( propertyMap );
1261 DALI_TEST_CHECK( visual );
1263 //Create an actor on stage to house the visual.
1264 DummyControl actor = DummyControl::New();
1265 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1266 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1267 actor.SetSize( 200.f, 200.f );
1268 Stage::GetCurrent().Add( actor );
1269 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1271 //Ensure set on stage.
1272 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1274 //Attempt to render to queue resource load requests.
1275 application.SendNotification();
1276 application.Render( 0 );
1278 //Tell the platform abstraction that the required resources have been loaded.
1279 TestPlatformAbstraction& platform = application.GetPlatform();
1280 platform.SetAllResourceRequestsAsLoaded();
1282 //Render again to upload the now-loaded textures.
1283 application.SendNotification();
1284 application.Render( 0 );
1286 //Test to see if the object has not been loaded, as expected.
1288 DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
1290 //Finish by setting off stage, and ensuring this was successful.
1292 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1295 //Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
1296 int UtcDaliVisualFactoryGetMeshVisual1(void)
1298 //Set up test application first, so everything else can be handled.
1299 ToolkitTestApplication application;
1301 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual1: Request mesh visual with a valid object file only" );
1304 //Set up visual properties.
1305 Property::Map propertyMap;
1306 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1307 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1309 //Test to see if mesh loads correctly.
1310 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1316 //Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
1317 int UtcDaliVisualFactoryGetMeshVisual2(void)
1319 //Set up test application first, so everything else can be handled.
1320 ToolkitTestApplication application;
1322 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual2: Request mesh visual with blank material file and images directory" );
1324 //Set up visual properties.
1325 Property::Map propertyMap;
1326 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1327 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1328 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "" );
1329 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "" );
1331 //Test to see if mesh loads correctly.
1332 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1337 //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
1338 int UtcDaliVisualFactoryGetMeshVisual3b(void)
1340 //Set up test application first, so everything else can be handled.
1341 ToolkitTestApplication application;
1343 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1345 //Set up visual properties.
1346 Property::Map propertyMap;
1347 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1348 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1349 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1350 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, Color::GREEN ); // Test that wrong property types don't prevent the object load
1351 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, 1.0f );
1352 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, 1.0f );
1353 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1355 //Test to see if mesh loads correctly.
1356 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1361 //Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
1362 int UtcDaliVisualFactoryGetMeshVisual3(void)
1364 //Set up test application first, so everything else can be handled.
1365 ToolkitTestApplication application;
1367 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual3: Request mesh visual with all parameters correct" );
1369 //Set up visual properties.
1370 Property::Map propertyMap;
1371 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1372 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1373 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1374 propertyMap.Insert( MeshVisual::Property::USE_MIPMAPPING, false );
1375 propertyMap.Insert( MeshVisual::Property::USE_SOFT_NORMALS, false );
1376 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3::XAXIS );
1377 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1379 //Test to see if mesh loads correctly.
1380 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1385 //Test if mesh visual can load a correctly supplied mesh without a normal map or gloss map in the material file.
1386 int UtcDaliVisualFactoryGetMeshVisual4(void)
1388 //Set up test application first, so everything else can be handled.
1389 ToolkitTestApplication application;
1391 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual4: Request mesh visual with diffuse texture but not normal or gloss." );
1394 //Set up visual properties.
1395 Property::Map propertyMap;
1396 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1397 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1398 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_SIMPLE_MTL_FILE_NAME );
1399 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1401 //Test to see if mesh loads correctly.
1402 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1407 //Test if mesh visual can load when made to use diffuse textures only.
1408 int UtcDaliVisualFactoryGetMeshVisual5(void)
1410 //Set up test application first, so everything else can be handled.
1411 ToolkitTestApplication application;
1413 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual and make it only use diffuse textures." );
1415 //Set up visual properties.
1416 Property::Map propertyMap;
1417 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1418 propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
1419 propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
1420 propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
1421 propertyMap.Insert( "useMipmapping", false );
1422 propertyMap.Insert( "useSoftNormals", false );
1423 propertyMap.Insert( "lightPosition", Vector3::ZAXIS );
1424 propertyMap.Insert( "shadingMode", MeshVisual::ShadingMode::TEXTURED_WITH_SPECULAR_LIGHTING );
1426 //Test to see if mesh loads correctly.
1427 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1433 //Test if mesh visual can load when made to not use the supplied textures.
1434 int UtcDaliVisualFactoryGetMeshVisual6(void)
1436 //Set up test application first, so everything else can be handled.
1437 ToolkitTestApplication application;
1439 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual6: Request mesh visual and make it not use any textures." );
1441 //Set up visual properties.
1442 Property::Map propertyMap;
1443 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1444 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1445 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1446 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1447 propertyMap.Insert( MeshVisual::Property::SHADING_MODE, MeshVisual::ShadingMode::TEXTURELESS_WITH_DIFFUSE_LIGHTING );
1449 //Test to see if mesh loads correctly.
1450 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1454 //Test if mesh visual loads correctly when light position is manually set.
1455 int UtcDaliVisualFactoryGetMeshVisual7(void)
1457 //Set up test application first, so everything else can be handled.
1458 ToolkitTestApplication application;
1461 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual7: Request mesh visual with custom light position." );
1463 //Set up visual properties.
1464 Property::Map propertyMap;
1465 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1466 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1467 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1468 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1469 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1471 //Test to see if mesh loads correctly.
1472 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1477 //Test if mesh visual loads correctly when supplied an object file without face normals or texture points.
1478 //Note that this notably tests object loader functionality.
1479 int UtcDaliVisualFactoryGetMeshVisual8(void)
1481 //Set up test application first, so everything else can be handled.
1482 ToolkitTestApplication application;
1484 tet_infoline( "UtcDaliVisualFactoryGetMeshVisual5: Request mesh visual with normal-less object file." );
1486 //Set up visual properties.
1487 Property::Map propertyMap;
1488 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1489 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_SIMPLE_OBJ_FILE_NAME );
1490 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1491 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1493 //Test to see if mesh loads correctly.
1494 MeshVisualLoadsCorrectlyTest( propertyMap, application );
1499 //Test if mesh visual handles the case of lacking an object file.
1500 int UtcDaliVisualFactoryGetMeshVisualN1(void)
1502 //Set up test application first, so everything else can be handled.
1503 ToolkitTestApplication application;
1505 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN1: Request mesh visual without object file" );
1507 //Set up visual properties.
1508 Property::Map propertyMap;
1509 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1510 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1511 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1513 //Test to see if mesh doesn't load with these properties, as expected.
1514 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1520 //Test if mesh visual handles the case of being passed invalid material and images urls.
1521 int UtcDaliVisualFactoryGetMeshVisualN2(void)
1523 //Set up test application first, so everything else can be handled.
1524 ToolkitTestApplication application;
1526 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN2: Request mesh visual with invalid material and images urls" );
1528 //Set up visual properties.
1529 Property::Map propertyMap;
1530 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1531 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, TEST_OBJ_FILE_NAME );
1532 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, "invalid" );
1533 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, "also invalid" );
1535 //Test to see if mesh doesn't load with these properties, as expected.
1536 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1542 //Test if mesh visual handles the case of being passed an invalid object url
1543 int UtcDaliVisualFactoryGetMeshVisualN3(void)
1545 //Set up test application first, so everything else can be handled.
1546 ToolkitTestApplication application;
1547 tet_infoline( "UtcDaliVisualFactoryGetMeshVisualN3: Request mesh visual with invalid object url" );
1550 //Set up visual properties.
1551 Property::Map propertyMap;
1552 propertyMap.Insert( Visual::Property::TYPE, Visual::MESH );
1553 propertyMap.Insert( MeshVisual::Property::OBJECT_URL, "invalid" );
1554 propertyMap.Insert( MeshVisual::Property::MATERIAL_URL, TEST_MTL_FILE_NAME );
1555 propertyMap.Insert( MeshVisual::Property::TEXTURES_PATH, TEST_RESOURCE_DIR "/" );
1557 //Test to see if mesh doesn't load with these properties, as expected.
1558 MeshVisualDoesNotLoadCorrectlyTest( propertyMap, application );
1563 //Creates a primitive visual with the given property map and tests to see if it correctly loads in the given application.
1564 void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestApplication& application )
1566 VisualFactory factory = VisualFactory::Get();
1567 DALI_TEST_CHECK( factory );
1569 //Create a primitive visual.
1570 Visual::Base visual = factory.CreateVisual( propertyMap );
1571 DALI_TEST_CHECK( visual );
1573 //Create an actor on stage to house the visual.
1574 DummyControl actor = DummyControl::New();
1575 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1576 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1578 actor.SetSize( 200.f, 200.f );
1579 Stage::GetCurrent().Add( actor );
1580 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) );
1582 //Ensure set on stage.
1583 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
1585 //Tell test application to load the visual.
1586 application.SendNotification();
1587 application.Render(0);
1589 Matrix testScaleMatrix;
1590 testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
1591 Matrix actualScaleMatrix;
1593 //Test to see if the object has been successfully loaded.
1594 DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
1595 DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
1597 //Finish by setting off stage, and ensuring this was successful.
1599 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
1602 //Test if primitive shape loads correctly when supplied with only the bare minimum requirements, the shape to use.
1603 int UtcDaliVisualFactoryGetPrimitiveVisual1(void)
1605 //Set up test application first, so everything else can be handled.
1606 ToolkitTestApplication application;
1608 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual1: Request primitive visual with a shape only" );
1610 //Set up visual properties.
1611 Property::Map propertyMap;
1612 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1613 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1615 //Test to see if shape loads correctly.
1616 TestPrimitiveVisualWithProperties( propertyMap, application );
1621 //Test if primitive shape loads correctly when supplied with all possible parameters
1622 int UtcDaliVisualFactoryGetPrimitiveVisual2(void)
1624 //Set up test application first, so everything else can be handled.
1625 ToolkitTestApplication application;
1627 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual2: Request primitive visual with everything" );
1629 //Set up visual properties.
1630 Property::Map propertyMap;
1631 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1632 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CUBE );
1633 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1634 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1635 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1636 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1637 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1638 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1639 propertyMap.Insert( PrimitiveVisual::Property::SCALE_RADIUS, 60.0f );
1640 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1641 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, 0.8f );
1642 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.9, 1.0, 1.1 ) );
1644 //Test to see if shape loads correctly.
1645 TestPrimitiveVisualWithProperties( propertyMap, application );
1650 //Test if primitive shape loads a sphere correctly.
1651 int UtcDaliVisualFactoryGetPrimitiveVisual3(void)
1653 //Set up test application first, so everything else can be handled.
1654 ToolkitTestApplication application;
1656 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual3: Request primitive visual to display a sphere" );
1658 //Set up visual properties.
1659 Property::Map propertyMap;
1660 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1661 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1662 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1663 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1664 propertyMap.Insert( PrimitiveVisual::Property::STACKS, 20 );
1666 //Test to see if shape loads correctly.
1667 TestPrimitiveVisualWithProperties( propertyMap, application );
1672 //Test if primitive shape loads a conic section correctly.
1673 int UtcDaliVisualFactoryGetPrimitiveVisual4(void)
1675 //Set up test application first, so everything else can be handled.
1676 ToolkitTestApplication application;
1678 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual4: Request primitive visual to display a conic section" );
1680 //Set up visual properties.
1681 Property::Map propertyMap;
1682 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1683 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM );
1684 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1685 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1686 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1687 propertyMap.Insert( PrimitiveVisual::Property::SCALE_BOTTOM_RADIUS, 40.0f );
1688 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1690 //Test to see if shape loads correctly.
1691 TestPrimitiveVisualWithProperties( propertyMap, application );
1696 //Test if primitive shape loads a bevelled cube correctly.
1697 int UtcDaliVisualFactoryGetPrimitiveVisual5(void)
1699 //Set up test application first, so everything else can be handled.
1700 ToolkitTestApplication application;
1702 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual5: Request primitive visual to display a bevelled cube" );
1704 //Set up visual properties.
1705 Property::Map propertyMap;
1706 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1707 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::BEVELLED_CUBE );
1708 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1709 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, 0.7f );
1711 //Test to see if shape loads correctly.
1712 TestPrimitiveVisualWithProperties( propertyMap, application );
1717 //Test if primitive shape loads an octahedron correctly.
1718 int UtcDaliVisualFactoryGetPrimitiveVisual6(void)
1720 //Set up test application first, so everything else can be handled.
1721 ToolkitTestApplication application;
1723 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual6: Request primitive visual to display an octahedron" );
1725 //Set up visual properties.
1726 Property::Map propertyMap;
1727 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1728 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::OCTAHEDRON );
1729 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1731 //Test to see if shape loads correctly.
1732 TestPrimitiveVisualWithProperties( propertyMap, application );
1737 //Test if primitive shape loads a cone correctly.
1738 int UtcDaliVisualFactoryGetPrimitiveVisual7(void)
1740 //Set up test application first, so everything else can be handled.
1741 ToolkitTestApplication application;
1743 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual7: Request primitive visual to display a cone" );
1745 //Set up visual properties.
1746 Property::Map propertyMap;
1747 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1748 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONE );
1749 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1750 propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 );
1751 propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f );
1752 propertyMap.Insert( PrimitiveVisual::Property::SCALE_HEIGHT, 50.0f );
1754 //Test to see if shape loads correctly.
1755 TestPrimitiveVisualWithProperties( propertyMap, application );
1760 //Test if primitive shape loads correctly when light position is manually set.
1761 int UtcDaliVisualFactoryGetPrimitiveVisual8(void)
1763 //Set up test application first, so everything else can be handled.
1764 ToolkitTestApplication application;
1766 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual8: Request primitive visual with set light position" );
1768 //Set up visual properties.
1769 Property::Map propertyMap;
1770 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1771 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1772 propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) );
1773 propertyMap.Insert( MeshVisual::Property::LIGHT_POSITION, Vector3( 0.0, 1.0, 2.0 ) );
1775 //Test to see if shape loads correctly.
1776 TestPrimitiveVisualWithProperties( propertyMap, application );
1781 //Test if primitive shape loads correctly when told to use too many slices.
1782 int UtcDaliVisualFactoryGetPrimitiveVisual9(void)
1784 //Set up test application first, so everything else can be handled.
1785 ToolkitTestApplication application;
1787 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual9: Request primitive visual with above-cap slices." );
1789 //Set up visual properties.
1790 Property::Map propertyMap;
1791 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1792 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1793 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 1000000 ) );
1795 //Test to see if shape loads correctly.
1796 TestPrimitiveVisualWithProperties( propertyMap, application );
1801 //Test if primitive shape loads correctly when told to use too few slices. (2 slices or less.)
1802 int UtcDaliVisualFactoryGetPrimitiveVisual10(void)
1804 //Set up test application first, so everything else can be handled.
1805 ToolkitTestApplication application;
1807 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual10: Request primitive visual with too few slices." );
1809 //Set up visual properties.
1810 Property::Map propertyMap;
1811 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1812 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1813 propertyMap.Insert( PrimitiveVisual::Property::SLICES, Property::Value( 2 ) );
1815 //Test to see if shape loads correctly.
1816 TestPrimitiveVisualWithProperties( propertyMap, application );
1821 //Test if primitive shape loads correctly when told to use too many stacks.
1822 int UtcDaliVisualFactoryGetPrimitiveVisual11(void)
1824 //Set up test application first, so everything else can be handled.
1825 ToolkitTestApplication application;
1827 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual11: Request primitive visual with too many stacks." );
1829 //Set up visual properties.
1830 Property::Map propertyMap;
1831 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1832 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1833 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1000000 ) );
1835 //Test to see if shape loads correctly.
1836 TestPrimitiveVisualWithProperties( propertyMap, application );
1841 //Test if primitive shape loads correctly when told to use too few stacks. (1 stack or less.)
1842 int UtcDaliVisualFactoryGetPrimitiveVisual12(void)
1844 //Set up test application first, so everything else can be handled.
1845 ToolkitTestApplication application;
1847 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual12: Request primitive visual with too few stacks." );
1849 //Set up visual properties.
1850 Property::Map propertyMap;
1851 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1852 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1853 propertyMap.Insert( PrimitiveVisual::Property::STACKS, Property::Value( 1 ) );
1855 //Test to see if shape loads correctly.
1856 TestPrimitiveVisualWithProperties( propertyMap, application );
1861 //Test if primitive shape loads correctly when told to use invalid (zero or negative) dimensions.
1862 int UtcDaliVisualFactoryGetPrimitiveVisual13(void)
1864 //Set up test application first, so everything else can be handled.
1865 ToolkitTestApplication application;
1867 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual13: Request primitive visual with invalid scale dimensions." );
1869 //Set up visual properties.
1870 Property::Map propertyMap;
1871 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1872 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1873 propertyMap.Insert( PrimitiveVisual::Property::SCALE_DIMENSIONS, Vector3::ZERO );
1875 //Test to see if shape loads correctly.
1876 TestPrimitiveVisualWithProperties( propertyMap, application );
1881 //Test if primitive shape loads correctly when told to use too low a bevel percentage.
1882 int UtcDaliVisualFactoryGetPrimitiveVisual14(void)
1884 //Set up test application first, so everything else can be handled.
1885 ToolkitTestApplication application;
1887 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual14: Request primitive visual with too low a bevel percentage." );
1889 //Set up visual properties.
1890 Property::Map propertyMap;
1891 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1892 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1893 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( -1.0f ) );
1895 //Test to see if shape loads correctly.
1896 TestPrimitiveVisualWithProperties( propertyMap, application );
1901 //Test if primitive shape loads correctly when told to use too high a bevel percentage.
1902 int UtcDaliVisualFactoryGetPrimitiveVisual15(void)
1904 //Set up test application first, so everything else can be handled.
1905 ToolkitTestApplication application;
1907 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual15: Request primitive visual with too high a bevel percentage." );
1909 //Set up visual properties.
1910 Property::Map propertyMap;
1911 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1912 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1913 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_PERCENTAGE, Property::Value( 2.0f ) );
1915 //Test to see if shape loads correctly.
1916 TestPrimitiveVisualWithProperties( propertyMap, application );
1921 //Test if primitive shape loads correctly when told to use too low a bevel smoothness.
1922 int UtcDaliVisualFactoryGetPrimitiveVisual16(void)
1924 //Set up test application first, so everything else can be handled.
1925 ToolkitTestApplication application;
1927 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual16: Request primitive visual with too low a bevel smoothness." );
1929 //Set up visual properties.
1930 Property::Map propertyMap;
1931 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1932 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1933 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( -1.0f ) );
1935 //Test to see if shape loads correctly.
1936 TestPrimitiveVisualWithProperties( propertyMap, application );
1941 //Test if primitive shape loads correctly when told to use too high a bevel smoothness.
1942 int UtcDaliVisualFactoryGetPrimitiveVisual17(void)
1944 //Set up test application first, so everything else can be handled.
1945 ToolkitTestApplication application;
1947 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisual17: Request primitive visual with too high a bevel smoothness." );
1949 //Set up visual properties.
1950 Property::Map propertyMap;
1951 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1952 propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::SPHERE );
1953 propertyMap.Insert( PrimitiveVisual::Property::BEVEL_SMOOTHNESS, Property::Value( 2.0f ) );
1955 //Test to see if shape loads correctly.
1956 TestPrimitiveVisualWithProperties( propertyMap, application );
1961 //Test if primitive shape visual handles the case of not being passed a specific shape to use.
1962 int UtcDaliVisualFactoryGetPrimitiveVisualN1(void)
1964 //Set up test application first, so everything else can be handled.
1965 ToolkitTestApplication application;
1967 tet_infoline( "UtcDaliVisualFactoryGetPrimitiveVisualN1: Request primitive visual without shape" );
1969 //Set up visual properties, without supplying shape.
1970 Property::Map propertyMap;
1971 propertyMap.Insert( Visual::Property::TYPE, Visual::PRIMITIVE );
1973 //Test to see if shape loads regardless of missing input.
1974 TestPrimitiveVisualWithProperties( propertyMap, application );
1979 int UtcDaliVisualFactoryGetBatchImageVisual1(void)
1981 ToolkitTestApplication application;
1982 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual1: Request a Batch Image visual with a Property::Map" );
1984 VisualFactory factory = VisualFactory::Get();
1985 DALI_TEST_CHECK( factory );
1987 Property::Map propertyMap;
1988 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
1989 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
1990 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
1992 Visual::Base visual = factory.CreateVisual( propertyMap );
1993 DALI_TEST_CHECK( visual );
1995 DummyControl actor = DummyControl::New();
1996 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
1997 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
1999 actor.SetSize( 200.0f, 200.0f );
2000 Stage::GetCurrent().Add( actor );
2001 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
2003 // Test SetOnStage().
2004 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2006 application.SendNotification();
2007 application.Render();
2009 // Test SetOffStage().
2011 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2016 int UtcDaliVisualFactoryGetBatchImageVisual2(void)
2018 ToolkitTestApplication application;
2019 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual2: Request Batch Image visual from an Image Visual with batchingEnabled set" );
2021 VisualFactory factory = VisualFactory::Get();
2022 DALI_TEST_CHECK( factory );
2024 Property::Map propertyMap;
2025 // Create a normal Image Visual.
2026 propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
2027 // Instruct the factory to change Image Visuals to Batch-Image Visuals.
2028 propertyMap.Insert( ImageVisual::Property::BATCHING_ENABLED, true );
2030 // Properties for the Batch-Image Visual.
2031 propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
2033 Visual::Base visual = factory.CreateVisual( propertyMap );
2034 DALI_TEST_CHECK( visual );
2036 // Check that a Batch-Image visual was created instead of an Image visual.
2037 Property::Map resultMap;
2038 visual.CreatePropertyMap( resultMap );
2040 Property::Value* value = resultMap.Find( Visual::Property::TYPE, Property::INTEGER );
2041 DALI_TEST_CHECK( value );
2042 DALI_TEST_EQUALS( value->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
2044 DummyControl actor = DummyControl::New();
2045 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2046 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2048 actor.SetSize( 200.0f, 200.0f );
2049 Stage::GetCurrent().Add( actor );
2050 visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.0f, 200.0f ) );
2052 // Test SetOnStage().
2053 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2055 application.SendNotification();
2056 application.Render();
2058 // Test SetOffStage().
2060 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2065 int UtcDaliVisualFactoryGetBatchImageVisual3(void)
2067 ToolkitTestApplication application;
2068 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual3: Create an ImageView that uses a batched visual internally" );
2070 VisualFactory factory = VisualFactory::Get();
2071 DALI_TEST_CHECK( factory );
2073 // Create a property-map that enables batching.
2074 Property::Map propertyMap;
2075 propertyMap[ Dali::Toolkit::ImageVisual::Property::URL ] = TEST_IMAGE_FILE_NAME ;
2076 propertyMap[ "desiredHeight" ] = 200;
2077 propertyMap[ "desiredWidth" ] = 200;
2078 propertyMap[ "batchingEnabled" ] = true;
2080 // Create an ImageView, passing the property-map in to instruct it to use batching.
2081 Toolkit::ImageView imageView = Toolkit::ImageView::New();
2082 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2084 imageView.SetSize( 200.0f, 200.0f );
2085 Stage::GetCurrent().Add( imageView );
2090 int UtcDaliVisualFactoryGetBatchImageVisual4N(void)
2092 ToolkitTestApplication application;
2093 tet_infoline( "UtcDaliVisualFactoryGetBatchImageVisual4: Create an ImageView that uses a batched visual, with desired properties of the wrong type" );
2095 VisualFactory factory = VisualFactory::Get();
2096 DALI_TEST_CHECK( factory );
2098 // Create a property-map that enables batching.
2099 Property::Map propertyMap;
2100 propertyMap[ Dali::Toolkit::ImageVisual::Property::URL ] = TEST_IMAGE_FILE_NAME ;
2101 propertyMap[ "desiredHeight" ] = Vector2(100, 100);
2102 propertyMap[ "desiredWidth" ] = Vector3(1, 1, 1);
2103 propertyMap[ "batchingEnabled" ] = true;
2105 // Create an ImageView, passing the property-map in to instruct it to use batching.
2106 Toolkit::ImageView imageView = Toolkit::ImageView::New();
2107 imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
2109 imageView.SetSize( 200.0f, 200.0f );
2110 Stage::GetCurrent().Add( imageView );
2115 int UtcDaliVisualFactoryGetAnimatedImageVisual1(void)
2117 ToolkitTestApplication application;
2118 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual1: Request animated image visual with a gif url" );
2120 VisualFactory factory = VisualFactory::Get();
2121 Visual::Base visual = factory.CreateVisual( TEST_GIF_FILE_NAME, ImageDimensions() );
2122 DALI_TEST_CHECK( visual );
2124 TestGlAbstraction& gl = application.GetGlAbstraction();
2125 TraceCallStack& textureTrace = gl.GetTextureTrace();
2126 textureTrace.Enable(true);
2128 DummyControl actor = DummyControl::New();
2129 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2130 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2131 actor.SetSize( 200.0f, 200.0f );
2132 Stage::GetCurrent().Add( actor );
2134 application.SendNotification();
2135 application.Render();
2137 // renderer is added to actor
2138 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2140 // test the uniforms which used to handle the atlas rect
2141 // the four frames should be located inside atlas as follows: atlas size 100*100
2150 Renderer renderer = actor.GetRendererAt( 0u );
2151 DALI_TEST_CHECK( renderer );
2153 Property::Value atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2154 // take into consideration the half pixel correction
2155 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 0.5f, 49.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2157 // waiting for the resource uploading
2158 application.SendNotification();
2159 application.Render();
2161 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2163 // Force the timer used by the animatedImageVisual to tick,
2164 Dali::Timer timer = Timer::New( 0 );
2165 timer.MockEmitSignal();
2166 application.SendNotification();
2167 application.Render();
2168 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2169 // take into consideration the half pixel correction
2170 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 0.5f, 99.5f, 49.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2172 // Force the timer used by the animatedImageVisual to tick,
2173 timer.MockEmitSignal();
2174 application.SendNotification();
2175 application.Render();
2176 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2177 // take into consideration the half pixel correction
2178 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(0.5f, 50.5f, 49.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2180 // Force the timer used by the animatedImageVisual to tick,
2181 timer.MockEmitSignal();
2182 application.SendNotification();
2183 application.Render();
2184 atlasRectValue = renderer.GetProperty( renderer.GetPropertyIndex( "uAtlasRect" ) );
2185 // take into consideration the half pixel correction
2186 DALI_TEST_EQUALS( atlasRectValue.Get<Vector4>(), Vector4(50.5f, 50.5f, 99.5f, 99.5f)/100.f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2188 // Test SetOffStage().
2190 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
2195 int UtcDaliVisualFactoryGetAnimatedImageVisual2(void)
2197 ToolkitTestApplication application;
2198 tet_infoline( "UtcDaliVisualFactoryGetAnimatedImageVisual2: Request animated image visual with a Property::Map, test custom wrap mode and pixel area" );
2200 const Vector4 pixelArea(-0.5f, -0.5f, 2.f, 2.f);
2201 Property::Map propertyMap;
2202 propertyMap.Add( Visual::Property::TYPE, Visual::IMAGE )
2203 .Add( ImageVisual::Property::URL, TEST_GIF_FILE_NAME )
2204 .Add( ImageVisual::Property::PIXEL_AREA, pixelArea )
2205 .Add( ImageVisual::Property::WRAP_MODE_U, WrapMode::MIRRORED_REPEAT )
2206 .Add( ImageVisual::Property::WRAP_MODE_V, WrapMode::REPEAT );
2208 Visual::Base visual = VisualFactory::Get().CreateVisual( propertyMap );
2209 DALI_TEST_CHECK( visual );
2211 TestGlAbstraction& gl = application.GetGlAbstraction();
2212 TraceCallStack& textureTrace = gl.GetTextureTrace();
2213 textureTrace.Enable(true);
2214 TraceCallStack& texParameterTrace = gl.GetTexParameterTrace();
2215 texParameterTrace.Enable( true );
2217 DummyControl actor = DummyControl::New();
2218 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
2219 dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
2220 actor.SetSize( 200.0f, 200.0f );
2221 Stage::GetCurrent().Add( actor );
2223 application.SendNotification();
2224 application.Render();
2226 DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
2228 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
2230 // For animated image visual, the wrapping is handled manually in shader, so the following gl function should not be called
2231 std::stringstream out;
2232 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_S << ", " << GL_MIRRORED_REPEAT;
2233 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2235 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_WRAP_T << ", " << GL_REPEAT;
2236 DALI_TEST_CHECK( !texParameterTrace.FindMethodAndParams("TexParameteri", out.str()) );
2238 // test the uniforms which used to handle the wrap mode
2239 Renderer renderer = actor.GetRendererAt( 0u );
2240 DALI_TEST_CHECK( renderer );
2242 Property::Value pixelAreaValue = renderer.GetProperty( renderer.GetPropertyIndex( "pixelArea" ) );
2243 DALI_TEST_EQUALS( pixelAreaValue.Get<Vector4>(), pixelArea, TEST_LOCATION );
2244 Vector4 pixelAreaUniform;
2245 DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
2246 DALI_TEST_EQUALS( pixelArea, pixelAreaUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2248 Property::Value wrapModeValue = renderer.GetProperty( renderer.GetPropertyIndex( "wrapMode" ) );
2249 Vector2 wrapMode( WrapMode::MIRRORED_REPEAT-1, WrapMode::REPEAT-1 );
2250 DALI_TEST_EQUALS( wrapModeValue.Get<Vector2>(), wrapMode, TEST_LOCATION );
2251 Vector2 wrapModeUniform;
2252 DALI_TEST_CHECK( gl.GetUniformValue<Vector2>( "wrapMode", wrapModeUniform ) );
2253 DALI_TEST_EQUALS( wrapMode, wrapModeUniform, Math::MACHINE_EPSILON_100, TEST_LOCATION );
2256 DALI_TEST_CHECK( actor.GetRendererCount() == 0u );