2 * Copyright (c) 2014 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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali/integration-api/bitmap.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
26 static const char* TestImageFilename = "icon_wrt.png";
28 void image_actor_test_startup(void)
30 test_return_value = TET_UNDEF;
33 void image_actor_test_cleanup(void)
35 test_return_value = TET_PASS;
39 int UtcDaliImageActorConstructorVoid(void)
41 TestApplication application;
42 tet_infoline("Testing Dali::ImageActor::ImageActor()");
46 DALI_TEST_CHECK(!actor);
50 int UtcDaliImageActorDestructor(void)
52 TestApplication application;
54 ImageActor* actor = new ImageActor();
57 DALI_TEST_CHECK( true );
61 int UtcDaliImageActorNew01(void)
63 TestApplication application;
64 tet_infoline("Positive test for Dali::ImageActor::New()");
66 Image image = ResourceImage::New(TestImageFilename);
67 ImageActor actor = ImageActor::New(image);
68 Stage::GetCurrent().Add(actor);
70 application.SendNotification();
73 application.SendNotification();
75 DALI_TEST_CHECK(application.GetPlatform().WasCalled(TestPlatformAbstraction::LoadResourceFunc));
77 DALI_TEST_CHECK(actor);
81 int UtcDaliImageActorNew02(void)
83 TestApplication application;
84 tet_infoline("Negative test for Dali::ImageActor::New()");
86 Image image = ResourceImage::New("hopefully-this-image-file-does-not-exist");
87 ImageActor actor = ImageActor::New(image);
89 DALI_TEST_CHECK(actor);
93 int UtcDaliImageActorDownCast(void)
95 TestApplication application;
96 tet_infoline("Testing Dali::ImageActor::DownCast()");
98 Image image = ResourceImage::New("IncorrectImageName");
99 ImageActor actor1 = ImageActor::New(image);
100 Actor anActor = Actor::New();
103 Actor child = anActor.GetChildAt(0);
104 ImageActor imageActor = DownCast< ImageActor >(child);
106 DALI_TEST_CHECK(imageActor);
110 int UtcDaliImageActorDownCast2(void)
112 TestApplication application;
113 tet_infoline("Testing Dali::ImageActor::DownCast()");
115 Actor actor1 = Actor::New();
116 Actor anActor = Actor::New();
119 Actor child = anActor.GetChildAt(0);
120 ImageActor imageActor = ImageActor::DownCast(child);
121 DALI_TEST_CHECK(!imageActor);
123 Actor unInitialzedActor;
124 imageActor = ImageActor::DownCast( unInitialzedActor );
125 DALI_TEST_CHECK(!imageActor);
129 int UtcDaliImageActorCopyConstructor(void)
131 TestApplication application;
132 tet_infoline("Testing Dali::ImageActor::ImageActor(const ImageActor& )");
134 Image image = ResourceImage::New("IncorrectImageName");
135 ImageActor actor1 = ImageActor::New(image);
137 ImageActor actor2(actor1);
138 DALI_TEST_CHECK(actor2);
139 DALI_TEST_EQUALS( actor2, actor1, TEST_LOCATION );
140 DALI_TEST_EQUALS( actor2.GetImage(), image, TEST_LOCATION );
145 int UtcDaliImageActor9Patch(void)
147 TestApplication application;
148 tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
150 Image image = ResourceImage::New(TestImageFilename);
151 ImageActor actor = ImageActor::New(image);
153 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
154 Vector4 border(0.1,0.2,0.3,0.4);
155 actor.SetNinePatchBorder(border);
157 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
158 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
159 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
160 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
164 int UtcDaliImageActorPixelArea(void)
166 TestApplication application;
167 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
169 BufferImage img = BufferImage::New( 10, 10 );
170 ImageActor actor = ImageActor::New( img );
172 ImageActor::PixelArea area( 1, 2, 3, 4 );
173 actor.SetPixelArea( area );
175 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
176 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
177 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
178 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
180 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
182 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
183 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
184 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
185 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
189 // Set a size that is too large on an Image with a shader that requires grid
190 int UtcDaliImageActorSetSize01(void)
192 TestApplication application;
194 BufferImage img = BufferImage::New( 1,1 );
195 ImageActor actor = ImageActor::New( img );
197 ShaderEffect effect = ShaderEffect::New( " ", " ", ShaderEffect::HINT_GRID );
198 actor.SetShaderEffect( effect );
200 const float INVALID_SIZE = float(1u<<31);
201 Vector3 vector( INVALID_SIZE, INVALID_SIZE, INVALID_SIZE );
203 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
205 actor.SetSize(vector);
206 Stage::GetCurrent().Add(actor);
208 // flush the queue and render once
209 application.SendNotification();
210 application.Render();
212 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
216 int UtcDaliImageActorGetCurrentSize01(void)
218 TestApplication application;
219 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
221 Vector2 initialImageSize(100, 50);
222 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
223 ImageActor actor = ImageActor::New( image );
224 Stage::GetCurrent().Add(actor);
226 application.SendNotification();
227 application.Render();
229 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
231 Vector2 size(200.0f, 200.0f);
234 // flush the queue and render once
235 application.SendNotification();
236 application.Render();
237 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
242 application.Render(8);
244 // Test when a pixel area is set
245 ImageActor::PixelArea area(0, 0, 10, 10);
246 actor.SetPixelArea(area);
247 application.Render(9);
248 // natural size is not used as setsize is called
249 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
255 int UtcDaliImageActorGetCurrentSize02(void)
257 TestApplication application;
258 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource sets the actor size with it's natural size immediately rather than on load");
260 Vector2 initialImageSize(100, 50);
262 application.GetPlatform().SetClosestImageSize(initialImageSize);
264 Image image = ResourceImage::New("image.jpg");
265 ImageActor actor = ImageActor::New( image );
266 Stage::GetCurrent().Add(actor);
268 application.SendNotification(); // Flush update messages
269 application.Render(); // Process resource request
270 application.SendNotification(); // Flush update messages
271 application.Render(); // Process resource request
273 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
275 // Now complete the image load
276 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
277 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
278 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
280 Integration::ResourcePointer resourcePtr(bitmap); // reference it
281 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
282 application.Render(); // Process LoadComplete
283 application.SendNotification(); // Process event messages
284 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
285 application.GetPlatform().ClearReadyResources(); //
287 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
289 Vector2 size(200.0f, 200.0f);
292 // flush the queue and render once
293 application.SendNotification();
294 application.Render();
295 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
301 int UtcDaliImageActorGetCurrentSize03(void)
303 TestApplication application;
304 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - Test that using an image resource with a requested size sets the actor size with it's nearest size immediately rather than on load");
306 const Vector2 closestImageSize( 80, 45);
307 application.GetPlatform().SetClosestImageSize(closestImageSize);
309 Vector2 requestedSize( 40, 30 );
310 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
311 ImageActor actor = ImageActor::New( image );
312 Stage::GetCurrent().Add(actor);
314 application.SendNotification(); // Flush update messages
315 application.Render(); // Process resource request
316 application.SendNotification(); // Flush update messages
317 application.Render(); // Process resource request
319 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
321 // Now complete the image load
322 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
323 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
324 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
326 Integration::ResourcePointer resourcePtr(bitmap); // reference it
327 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
328 application.Render(); // Process LoadComplete
329 application.SendNotification(); // Process event messages
330 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
331 application.GetPlatform().ClearReadyResources(); //
333 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
339 int UtcDaliImageActorGetCurrentSize04(void)
341 TestApplication application;
342 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
344 const Vector2 closestImageSize( 80, 45);
345 application.GetPlatform().SetClosestImageSize(closestImageSize);
347 Vector2 requestedSize( 40, 30 );
348 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
349 ImageActor actor = ImageActor::New( image );
350 Stage::GetCurrent().Add(actor);
352 application.SendNotification(); // Flush update messages
353 application.Render(); // Process resource request
355 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
357 // Now complete the image load
358 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
359 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
360 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
362 Integration::ResourcePointer resourcePtr(bitmap); // reference it
363 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
364 application.Render(); // Process LoadComplete
365 application.SendNotification(); // Process event messages
366 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
367 application.GetPlatform().ClearReadyResources(); //
369 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
371 Vector2 size(200.0f, 200.0f);
374 // flush the queue and render once
375 application.SendNotification();
376 application.Render();
377 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
379 // Load a different image
381 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
382 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
384 const Vector2 request2Size( 100, 100 );
385 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
386 actor.SetImage(image2);
388 application.SendNotification(); // Flush update messages
389 application.Render(); // Process resource request
390 application.SendNotification(); // Flush update messages
391 application.Render(); // Process resource request
393 // Ensure the actor size is kept
394 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
396 // Now complete the image load
397 req = application.GetPlatform().GetRequest();
398 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
399 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
401 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
402 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
403 application.Render(); // Process LoadComplete
404 application.SendNotification(); // Process event messages
405 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
406 application.GetPlatform().ClearReadyResources(); //
408 // Ensure the actor size is kept
409 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
415 int UtcDaliImageActorGetCurrentSize05(void)
417 TestApplication application;
418 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
420 Vector2 closestImageSize( 80, 45);
421 application.GetPlatform().SetClosestImageSize(closestImageSize);
423 Vector2 requestedSize( 40, 30 );
424 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
425 ImageActor actor = ImageActor::New( image );
426 Stage::GetCurrent().Add(actor);
428 application.SendNotification(); // Flush update messages
429 application.Render(); // Process resource request
431 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
433 // Now complete the image load
434 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
435 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
436 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
438 Integration::ResourcePointer resourcePtr(bitmap); // reference it
439 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
440 application.Render(); // Process LoadComplete
441 application.SendNotification(); // Process event messages
442 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
443 application.GetPlatform().ClearReadyResources(); //
445 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
447 // Load a different image
449 Vector2 image2ClosestSize = Vector2(240, 150);
450 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
452 const Vector2 requestedSize2( 100, 100 );
453 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
454 actor.SetImage(image2);
456 application.SendNotification(); // Flush update messages
457 application.Render(); // Process resource request
458 application.SendNotification(); // Flush update messages
459 application.Render(); // Process resource request
461 // Ensure the actor size is kept
462 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
464 // Now complete the image load
465 req = application.GetPlatform().GetRequest();
466 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
467 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
469 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
470 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
471 application.Render(); // Process LoadComplete
472 application.SendNotification(); // Process event messages
473 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
474 application.GetPlatform().ClearReadyResources(); //
476 application.SendNotification(); // Process event messages
477 application.Render(); // Process LoadComplete
479 // Ensure the actor size gets the new image's natural size
480 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
484 int UtcDaliImageActorNaturalPixelAreaSize01(void)
486 TestApplication application;
487 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
489 //If an image is loaded without setting size, then the actor gets the natural size of the image
490 //Setting the pixel area will change the actor size to match the pixel area
491 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
493 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
496 Vector2 closestImageSize( 80, 45);
497 application.GetPlatform().SetClosestImageSize(closestImageSize);
499 Vector2 requestedSize( 40, 30 );
500 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
501 ImageActor actor = ImageActor::New( image );
502 Stage::GetCurrent().Add(actor);
504 application.SendNotification(); // Flush update messages
505 application.Render(); // Process resource request
507 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
509 // Now complete the image load
510 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
511 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
512 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
514 Integration::ResourcePointer resourcePtr(bitmap); // reference it
515 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
516 application.Render(); // Process LoadComplete
517 application.SendNotification(); // Process event messages
518 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
519 application.GetPlatform().ClearReadyResources(); //
521 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
523 // Set a pixel area on a naturally sized actor - expect the actor to take the
524 // pixel area as size
525 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
526 application.SendNotification(); // Process event messages
527 application.Render(); // Process LoadComplete
528 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
530 // Set a size. Expect the partial image to stretch to fill the new size
531 actor.SetSize(100, 100);
532 application.SendNotification(); // Process event messages
533 application.Render(); // Process LoadComplete
534 application.Render(); // Process LoadComplete
535 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
537 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
538 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
539 application.SendNotification(); // Process event messages
540 application.Render(); // Process LoadComplete
541 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
545 int UtcDaliImageActorNaturalPixelAreaSize02(void)
547 TestApplication application;
548 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
550 //If an image is loaded without setting size, then the actor gets the natural size of the image
551 //Setting the pixel area will change the actor size to match the pixel area
552 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
554 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
557 Vector2 closestImageSize( 80, 45);
558 application.GetPlatform().SetClosestImageSize(closestImageSize);
560 Vector2 requestedSize( 40, 30 );
561 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
562 ImageActor actor = ImageActor::New( image );
563 Stage::GetCurrent().Add(actor);
565 application.SendNotification(); // Flush update messages
566 application.Render(); // Process resource request
568 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
570 // Now complete the image load
571 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
572 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
573 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
575 Integration::ResourcePointer resourcePtr(bitmap); // reference it
576 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
577 application.Render(); // Process LoadComplete
578 application.SendNotification(); // Process event messages
579 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
580 application.GetPlatform().ClearReadyResources(); //
582 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
584 // Set a pixel area on a naturally sized actor - expect the actor to take the
585 // pixel area as size
586 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
587 application.SendNotification(); // Process event messages
588 application.Render(); // Process LoadComplete
589 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
591 // Clear the pixel area. Expect the whole image to be shown, changing actor size
592 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
593 application.SendNotification(); // Process event messages
594 application.Render(); // Process LoadComplete
595 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
597 // Set a size. Expect the partial image to stretch to fill the new size
598 actor.SetSize(100, 100);
599 application.SendNotification(); // Process event messages
600 application.Render(); // Process LoadComplete
601 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
603 // Set a pixel area, don't expect size to change
604 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
605 application.SendNotification(); // Process event messages
606 application.Render(); // Process LoadComplete
607 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
609 // Clearing pixel area should change actor size to image size
610 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
611 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
612 application.SendNotification(); // Process event messages
613 application.Render(); // Process LoadComplete
614 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
620 int UtcDaliImageActorDefaultProperties(void)
622 TestApplication application;
623 tet_infoline("Testing Dali::ImageActor DefaultProperties");
625 BufferImage img = BufferImage::New( 10, 10 );
626 ImageActor actor = ImageActor::New( img );
628 std::vector<Property::Index> indices;
629 indices.push_back(ImageActor::Property::PIXEL_AREA );
630 indices.push_back(ImageActor::Property::STYLE );
631 indices.push_back(ImageActor::Property::BORDER );
632 indices.push_back(ImageActor::Property::IMAGE );
634 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
636 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
638 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
639 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
640 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
641 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
644 // set/get one of them
645 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
647 ImageActor::PixelArea area( 1, 2, 3, 4 );
648 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
650 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
652 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
654 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
659 int UtcDaliImageActorUseImageAlpha01(void)
661 TestApplication application;
663 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
665 BufferImage image = BufferImage::New( 100, 50 );
666 ImageActor actor = ImageActor::New( image );
667 actor.SetBlendMode( BlendingMode::ON );
668 actor.SetSize(100, 50);
669 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
670 Stage::GetCurrent().Add(actor);
672 application.SendNotification();
673 application.Render();
675 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
676 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
677 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
681 int UtcDaliImageActorUseImageAlpha02(void)
683 TestApplication application;
685 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
687 BufferImage image = BufferImage::New( 100, 50 );
688 ImageActor actor = ImageActor::New( image );
689 actor.SetBlendMode( BlendingMode::OFF );
690 actor.SetSize(100, 50);
691 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
692 Stage::GetCurrent().Add(actor);
694 application.SendNotification();
695 application.Render();
697 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
698 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
699 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
703 int UtcDaliImageActorUseImageAlpha03(void)
705 TestApplication application;
707 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
709 BufferImage image = BufferImage::New( 100, 50 );
710 ImageActor actor = ImageActor::New( image );
711 actor.SetBlendMode( BlendingMode::AUTO );
712 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
713 actor.SetSize(100, 50);
714 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
715 Stage::GetCurrent().Add(actor);
717 application.SendNotification();
718 application.Render();
720 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
721 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
722 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
726 int UtcDaliImageActorUseImageAlpha04(void)
728 TestApplication application;
730 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
732 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
733 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
734 RenderTask task = taskList.GetTask( 0u );
735 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
736 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
737 application.SendNotification();
738 application.Render(0);
740 ImageActor actor = ImageActor::New( image );
741 application.SendNotification();
742 application.Render(0);
744 actor.SetBlendMode( BlendingMode::ON );
745 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
746 actor.SetSize(100, 50);
747 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
748 Stage::GetCurrent().Add(actor);
750 application.SendNotification();
751 application.Render();
753 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
754 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
755 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
759 int UtcDaliImageActorUseImageAlpha05(void)
761 TestApplication application;
763 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
765 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
766 ImageActor actor = ImageActor::New( image );
767 actor.SetBlendMode( BlendingMode::AUTO );
768 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
769 actor.SetSize(100, 50);
770 application.GetGlAbstraction().EnableCullFaceCallTrace(true); // For Enable(GL_BLEND)
771 Stage::GetCurrent().Add(actor);
773 application.SendNotification();
774 application.Render();
776 const TraceCallStack& callTrace = application.GetGlAbstraction().GetCullFaceTrace();
777 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
778 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
782 int UtcDaliImageGetStyle(void)
784 TestApplication application;
786 Image image = ResourceImage::New(TestImageFilename);
787 ImageActor actor = ImageActor::New(image);
789 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
791 // flush the queue and render once
792 application.SendNotification();
793 application.Render();
795 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
799 int UtcDaliImageSetNinePatchBorder(void)
801 TestApplication application;
803 Image image = ResourceImage::New(TestImageFilename);
804 ImageActor actor = ImageActor::New(image);
806 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
807 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
809 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
810 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
811 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
812 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
816 int UtcDaliImageActorNewNull(void)
818 TestApplication application;
820 ImageActor actor = ImageActor::New(Image());
822 DALI_TEST_CHECK(actor);
826 int UtcDaliImageActorNewNullWithArea(void)
828 TestApplication application;
830 ImageActor::PixelArea area( 1, 2, 3, 4 );
832 ImageActor actor = ImageActor::New(Image(), area);
834 DALI_TEST_CHECK(actor);
838 int UtcDaliImageActorSetImage(void)
840 TestApplication application;
842 ImageActor actor = ImageActor::New(Image());
844 DALI_TEST_CHECK(actor);
846 actor.SetImage( Image() );
848 DALI_TEST_CHECK(!actor.GetImage());
852 int UtcDaliImageActorPropertyIndices(void)
854 TestApplication application;
855 Actor basicActor = Actor::New();
856 ImageActor imageActor = ImageActor::New();
858 Property::IndexContainer indices;
859 imageActor.GetPropertyIndices( indices );
860 DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
861 DALI_TEST_EQUALS( indices.Size(), imageActor.GetPropertyCount(), TEST_LOCATION );
865 int UtcDaliImageActorImageProperty(void)
867 TestApplication application;
868 Image image = ResourceImage::New( "MY_PATH" );
869 ImageActor imageActor = ImageActor::New( image );
871 Stage::GetCurrent().Add( imageActor );
872 application.SendNotification();
873 application.Render();
875 Property::Value imageProperty = imageActor.GetProperty( ImageActor::Property::IMAGE );
876 Property::Map* imageMap = imageProperty.GetMap();
877 DALI_TEST_CHECK( imageMap != NULL );
878 DALI_TEST_CHECK( NULL != imageMap->Find( "filename" ) );
879 DALI_TEST_EQUALS( (*imageMap)[ "filename" ].Get< std::string >(), "MY_PATH", TEST_LOCATION );
883 int UtcDaliImageActorNinePatch01(void)
885 TestApplication application;
886 TestPlatformAbstraction& platform = application.GetPlatform();
887 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
888 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
889 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
891 tet_infoline("Test the successful loading of a nine-patch image\n");
893 platform.SetClosestImageSize(Vector2(4, 4));
894 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
895 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
896 memset( pixels, 0, 64 );
898 Integration::ResourcePointer resourcePtr(bitmap); // reference it
899 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
901 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
902 DALI_TEST_CHECK( ninePatchImage );
904 ImageActor imageActor = ImageActor::New( ninePatchImage );
905 DALI_TEST_CHECK( imageActor );
906 Stage::GetCurrent().Add( imageActor );
909 textureTrace.Reset();
910 drawTrace.Enable(true);
911 textureTrace.Enable(true);
912 glAbstraction.ClearBoundTextures();
913 std::vector<GLuint> ids;
915 glAbstraction.SetNextTextureIds( ids );
917 application.SendNotification();
918 application.Render();
920 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
921 typedef std::vector<GLuint> TexVec;
922 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
923 DALI_TEST_CHECK( textures.size() > 0 );
924 if( textures.size() > 0 )
926 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
933 int UtcDaliImageActorNinePatch02(void)
935 TestApplication application;
936 TestPlatformAbstraction& platform = application.GetPlatform();
937 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
938 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
939 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
941 tet_infoline("Test the failed loading of a nine-patch image\n");
943 platform.SetClosestImageSize(Vector2(0, 0));
944 Integration::ResourcePointer resourcePtr;
945 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
947 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
948 DALI_TEST_CHECK( ninePatchImage );
950 ImageActor imageActor = ImageActor::New( ninePatchImage );
951 DALI_TEST_CHECK( imageActor );
952 Stage::GetCurrent().Add( imageActor );
955 textureTrace.Reset();
956 drawTrace.Enable(true);
957 textureTrace.Enable(true);
958 glAbstraction.ClearBoundTextures();
959 std::vector<GLuint> ids;
961 glAbstraction.SetNextTextureIds( ids );
963 application.SendNotification();
964 application.Render();
966 // Check that nothing was drawn.
967 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
968 typedef std::vector<GLuint> TexVec;
969 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
970 DALI_TEST_CHECK( textures.size() == 0u );
976 int UtcDaliImageActorNinePatch03(void)
978 TestApplication application;
979 TestPlatformAbstraction& platform = application.GetPlatform();
980 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
981 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
982 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
984 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
986 platform.SetClosestImageSize(Vector2(4, 4));
987 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
988 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
989 memset( pixels, 0, 64 );
991 Integration::ResourcePointer resourcePtr(bitmap); // reference it
992 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
994 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
995 DALI_TEST_CHECK( ninePatchImage );
997 ImageActor imageActor = ImageActor::New();
998 DALI_TEST_CHECK( imageActor );
999 Stage::GetCurrent().Add( imageActor );
1001 imageActor.SetImage( ninePatchImage );
1004 textureTrace.Reset();
1005 drawTrace.Enable(true);
1006 textureTrace.Enable(true);
1007 glAbstraction.ClearBoundTextures();
1008 std::vector<GLuint> ids;
1009 ids.push_back( 23 );
1010 glAbstraction.SetNextTextureIds( ids );
1012 application.SendNotification();
1013 application.Render();
1015 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawArrays" ) );
1016 typedef std::vector<GLuint> TexVec;
1017 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1018 DALI_TEST_CHECK( textures.size() > 0 );
1019 if( textures.size() > 0 )
1021 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1028 int UtcDaliImageActorNinePatch04(void)
1030 TestApplication application;
1031 TestPlatformAbstraction& platform = application.GetPlatform();
1032 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1033 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1034 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1036 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1038 platform.SetClosestImageSize(Vector2(0, 0));
1039 Integration::ResourcePointer resourcePtr;
1040 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1042 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1043 DALI_TEST_CHECK( ninePatchImage );
1045 ImageActor imageActor = ImageActor::New();
1046 DALI_TEST_CHECK( imageActor );
1047 Stage::GetCurrent().Add( imageActor );
1049 imageActor.SetImage( ninePatchImage );
1052 textureTrace.Reset();
1053 drawTrace.Enable(true);
1054 textureTrace.Enable(true);
1055 glAbstraction.ClearBoundTextures();
1056 std::vector<GLuint> ids;
1057 ids.push_back( 23 );
1058 glAbstraction.SetNextTextureIds( ids );
1060 application.SendNotification();
1061 application.Render();
1063 // Check that nothing was drawn.
1064 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawArrays" ) );
1065 typedef std::vector<GLuint> TexVec;
1066 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1067 DALI_TEST_CHECK( textures.size() == 0u );
1072 int UtcDaliImageActorGetNaturalSize(void)
1074 TestApplication application;
1077 BufferImage img = BufferImage::New( 10, 10 );
1078 ImageActor actor = ImageActor::New( img );
1080 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1083 ImageActor::PixelArea area( 1, 2, 3, 4 );
1084 actor.SetPixelArea( area );
1086 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );
1091 int UtcDaliImageActorGetSortModifier(void)
1093 TestApplication application;
1095 tet_infoline("Testing Dali::ImageActor::GetSortModifier()");
1097 ImageActor actor = ImageActor::New();
1098 Stage::GetCurrent().Add(actor);
1100 DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION);
1102 Stage::GetCurrent().Remove(actor);
1106 int UtcDaliImageActorSetGetBlendMode(void)
1108 TestApplication application;
1110 tet_infoline("Testing Dali::ImageActor::SetBlendMode() / Dali::ImageActor::GetBlendMode()");
1112 ImageActor actor = ImageActor::New();
1114 actor.SetBlendMode( BlendingMode::OFF );
1115 DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() );
1117 actor.SetBlendMode( BlendingMode::AUTO );
1118 DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() );
1120 actor.SetBlendMode( BlendingMode::ON );
1121 DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() );
1125 int UtcDaliImageActorSetGetBlendFunc(void)
1127 TestApplication application;
1128 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1130 tet_infoline("Testing Dali::ImageActor::UtcDaliImageActorSetGetBlendFunc()");
1132 BufferImage img = BufferImage::New( 1,1 );
1133 ImageActor actor = ImageActor::New( img );
1134 Stage::GetCurrent().Add( actor );
1135 application.SendNotification();
1136 application.Render();
1138 // Test the defaults as documented int blending.h
1140 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1141 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1142 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1143 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1144 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1145 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1146 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1147 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1148 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1151 // Set to non-default values
1152 actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE, BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
1154 // Test that Set was successful
1156 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1157 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1158 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1159 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1160 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1161 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
1162 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
1163 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
1164 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
1167 // Render & check GL commands
1168 application.SendNotification();
1169 application.Render();
1170 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
1171 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
1172 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1173 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1175 // Set using separate alpha settings
1176 actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
1177 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
1179 // Test that Set was successful
1181 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1182 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1183 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1184 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1185 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1186 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
1187 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
1188 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
1189 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
1192 // Render & check GL commands
1193 application.SendNotification();
1194 application.Render();
1195 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
1196 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
1197 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1198 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1202 int UtcDaliImageActorSetGetAlpha(void)
1204 TestApplication application;
1206 tet_infoline("Testing Dali::ImageActor::SetGetAlpha()");
1208 BufferImage img = BufferImage::New( 1,1 );
1209 ImageActor actor = ImageActor::New( img );
1210 Stage::GetCurrent().Add( actor );
1211 application.SendNotification();
1212 application.Render();
1214 // use the image alpha on actor
1215 actor.SetBlendMode(BlendingMode::ON);
1217 // Test that Set was successful
1218 DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION );
1220 // Now test that it can be set to false
1221 actor.SetBlendMode(BlendingMode::OFF);
1222 DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION );
1226 int UtcDaliImageActorSetGetFilterModes(void)
1228 TestApplication application;
1230 tet_infoline("Testing Dali::ImageActor::SetFilterMode() / Dali::ImageActor::GetFilterMode()");
1232 ImageActor actor = ImageActor::New();
1234 FilterMode::Type minifyFilter = FilterMode::NEAREST;
1235 FilterMode::Type magnifyFilter = FilterMode::NEAREST;
1238 actor.GetFilterMode( minifyFilter, magnifyFilter );
1239 DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1240 DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1243 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1244 actor.GetFilterMode( minifyFilter, magnifyFilter );
1245 DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1246 DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1249 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1250 actor.GetFilterMode( minifyFilter, magnifyFilter );
1251 DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1252 DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1255 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1256 actor.GetFilterMode( minifyFilter, magnifyFilter );
1257 DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1258 DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1261 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1262 actor.GetFilterMode( minifyFilter, magnifyFilter );
1263 DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1264 DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1267 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::NEAREST );
1268 actor.GetFilterMode( minifyFilter, magnifyFilter );
1269 DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1270 DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1275 int UtcDaliImageActorSetFilterMode(void)
1277 TestApplication application;
1279 tet_infoline("Testing Dali::ImageActor::SetFilterMode()");
1281 BufferImage img = BufferImage::New( 1,1 );
1282 ImageActor actor = ImageActor::New( img );
1284 actor.SetSize(100.0f, 100.0f);
1285 actor.SetParentOrigin(ParentOrigin::CENTER);
1286 actor.SetAnchorPoint(AnchorPoint::CENTER);
1288 Stage::GetCurrent().Add(actor);
1290 /**************************************************************/
1293 TraceCallStack& texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1294 texParameterTrace.Reset();
1295 texParameterTrace.Enable( true );
1297 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1299 // Flush the queue and render once
1300 application.SendNotification();
1301 application.Render();
1303 texParameterTrace.Enable( false );
1305 std::stringstream out;
1307 // Verify actor gl state
1309 // There are two calls to TexParameteri when the texture is first created
1310 // Texture mag filter is not called as the first time set it uses the system default
1311 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1314 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1315 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
1317 /**************************************************************/
1320 texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1321 texParameterTrace.Reset();
1322 texParameterTrace.Enable( true );
1324 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1326 // Flush the queue and render once
1327 application.SendNotification();
1328 application.Render();
1330 texParameterTrace.Enable( false );
1332 // Verify actor gl state
1334 // Should not make any calls when settings are the same
1335 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
1337 /**************************************************************/
1340 texParameterTrace.Reset();
1341 texParameterTrace.Enable( true );
1343 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1345 // Flush the queue and render once
1346 application.SendNotification();
1347 application.Render();
1349 texParameterTrace.Enable( false );
1351 // Verify actor gl state
1352 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1355 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1356 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1359 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
1360 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1362 /**************************************************************/
1365 texParameterTrace.Reset();
1366 texParameterTrace.Enable( true );
1368 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1370 // Flush the queue and render once
1371 application.SendNotification();
1372 application.Render();
1374 texParameterTrace.Enable( false );
1376 // Verify actor gl state
1377 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1380 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1381 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1384 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
1385 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1388 /**************************************************************/
1391 texParameterTrace.Reset();
1392 texParameterTrace.Enable( true );
1394 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1396 // Flush the queue and render once
1397 application.SendNotification();
1398 application.Render();
1400 texParameterTrace.Enable( false );
1402 // Verify actor gl state
1403 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1406 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1407 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1409 /**************************************************************/
1412 texParameterTrace.Reset();
1413 texParameterTrace.Enable( true );
1415 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1417 // Flush the queue and render once
1418 application.SendNotification();
1419 application.Render();
1421 texParameterTrace.Enable( false );
1423 // Verify actor gl state
1424 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1427 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1428 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1430 /**************************************************************/
1433 texParameterTrace.Reset();
1434 texParameterTrace.Enable( true );
1436 actor.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
1438 // Flush the queue and render once
1439 application.SendNotification();
1440 application.Render();
1442 texParameterTrace.Enable( false );
1444 // Verify actor gl state
1445 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1448 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
1449 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1451 /**************************************************************/
1453 Stage::GetCurrent().Remove(actor);
1458 int UtcDaliImageActorSetShaderEffect(void)
1460 TestApplication application;
1461 BufferImage img = BufferImage::New( 1,1 );
1462 ImageActor actor = ImageActor::New( img );
1463 Stage::GetCurrent().Add( actor );
1465 // flush the queue and render once
1466 application.SendNotification();
1467 application.Render();
1468 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1470 application.GetGlAbstraction().EnableShaderCallTrace( true );
1472 const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1473 const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1474 ShaderEffect effect = ShaderEffect::New(vertexShader, fragmentShader );
1475 DALI_TEST_CHECK( effect != actor.GetShaderEffect() );
1477 actor.SetShaderEffect( effect );
1478 DALI_TEST_CHECK( effect == actor.GetShaderEffect() );
1480 // flush the queue and render once
1481 application.SendNotification();
1482 application.Render();
1484 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1485 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1487 std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1488 DALI_TEST_EQUALS( vertexShader,
1489 actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1490 std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1491 DALI_TEST_EQUALS( fragmentShader,
1492 actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1497 int UtcDaliImageActorGetShaderEffect(void)
1499 TestApplication application;
1500 ImageActor actor = ImageActor::New();
1502 ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorGetShaderEffect-VertexSource", "UtcDaliImageActorGetShaderEffect-FragmentSource" );
1503 actor.SetShaderEffect(effect);
1505 DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1509 int UtcDaliImageActorRemoveShaderEffect01(void)
1511 TestApplication application;
1512 ImageActor actor = ImageActor::New();
1514 ShaderEffect defaultEffect = actor.GetShaderEffect();
1516 ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorRemoveShaderEffect-VertexSource", "UtcDaliImageActorRemoveShaderEffect-FragmentSource" );
1517 actor.SetShaderEffect(effect);
1519 DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1521 actor.RemoveShaderEffect();
1523 DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1527 int UtcDaliImageActorRemoveShaderEffect02(void)
1529 TestApplication application;
1530 ImageActor actor = ImageActor::New();
1532 ShaderEffect defaultEffect = actor.GetShaderEffect();
1534 actor.RemoveShaderEffect();
1536 DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1540 int UtcDaliSetShaderEffectRecursively(void)
1542 TestApplication application;
1547 * actor3 imageactor1
1550 BufferImage img = BufferImage::New( 1,1 );
1551 ImageActor actor1 = ImageActor::New( img );
1552 Actor actor2 = Actor::New();
1553 actor1.Add( actor2 );
1554 Actor actor3 = Actor::New();
1555 actor2.Add( actor3 );
1556 ImageActor imageactor1 = ImageActor::New( img );
1557 actor2.Add( imageactor1 );
1558 ImageActor imageactor2 = ImageActor::New( img );
1559 actor3.Add( imageactor2 );
1560 Actor actor4 = Actor::New();
1561 actor1.Add( actor4 );
1562 Stage::GetCurrent().Add( actor1 );
1564 // flush the queue and render once
1565 application.SendNotification();
1566 application.Render();
1567 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1569 application.GetGlAbstraction().EnableShaderCallTrace( true );
1571 const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1572 const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1573 // test with empty effect
1574 ShaderEffect effect;
1575 SetShaderEffectRecursively( actor1, effect );
1577 effect = ShaderEffect::New(vertexShader, fragmentShader );
1579 DALI_TEST_CHECK( effect != actor1.GetShaderEffect() );
1580 DALI_TEST_CHECK( effect != imageactor1.GetShaderEffect() );
1581 DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1583 SetShaderEffectRecursively( actor1, effect );
1584 DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1585 DALI_TEST_CHECK( effect == imageactor2.GetShaderEffect() );
1587 // flush the queue and render once
1588 application.SendNotification();
1589 application.Render();
1591 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1592 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1594 std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1595 DALI_TEST_EQUALS( vertexShader,
1596 actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1597 std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1598 DALI_TEST_EQUALS( fragmentShader,
1599 actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1601 // remove from one that does not have shader
1602 RemoveShaderEffectRecursively( actor4 );
1605 RemoveShaderEffectRecursively( actor3 );
1606 DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1607 DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1609 // test with empty actor just to check it does not crash
1611 SetShaderEffectRecursively( empty, effect );
1612 RemoveShaderEffectRecursively( empty );
1614 // test with actor with no children just to check it does not crash
1615 Actor loner = Actor::New();
1616 Stage::GetCurrent().Add( loner );
1617 SetShaderEffectRecursively( loner, effect );
1618 RemoveShaderEffectRecursively( loner );
1623 int UtcDaliImageActorTestClearCache(void)
1625 // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
1626 TestApplication application;
1628 tet_infoline("Testing Dali::ImageActor::ClearCache()");
1630 BufferImage img = BufferImage::New( 1,1 );
1631 ImageActor actor = ImageActor::New( img );
1633 actor.SetParentOrigin(ParentOrigin::CENTER);
1634 actor.SetAnchorPoint(AnchorPoint::CENTER);
1636 Stage::GetCurrent().Add(actor);
1638 /**************************************************************/
1639 // Flush the queue and render once
1640 application.SendNotification();
1641 application.Render();
1643 // There should be a single call to Clear
1644 DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled() , 1u, TEST_LOCATION );
1646 // the last set clear mask should be COLOR, DEPTH & STENCIL which occurs at the start of each frame
1647 GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
1648 DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT );
1649 DALI_TEST_CHECK( mask & GL_STENCIL_BUFFER_BIT );
1650 DALI_TEST_CHECK( mask & GL_COLOR_BUFFER_BIT );