2 * Copyright (c) 2015 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("hopefullyThisImageFileDoesNotExist");
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 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
156 Vector4 border(0.1,0.2,0.3,0.4);
157 actor.SetNinePatchBorder(border);
159 DALI_TEST_EQUALS( 0.1f, actor.GetNinePatchBorder().x, TEST_LOCATION );
160 DALI_TEST_EQUALS( 0.2f, actor.GetNinePatchBorder().y, TEST_LOCATION );
161 DALI_TEST_EQUALS( 0.3f, actor.GetNinePatchBorder().z, TEST_LOCATION );
162 DALI_TEST_EQUALS( 0.4f, actor.GetNinePatchBorder().w, TEST_LOCATION );
166 int UtcDaliImageActorPixelArea(void)
168 TestApplication application;
169 tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
171 BufferImage img = BufferImage::New( 10, 10 );
172 ImageActor actor = ImageActor::New( img );
174 ImageActor::PixelArea area( 1, 2, 3, 4 );
175 actor.SetPixelArea( area );
177 DALI_TEST_EQUALS( 1, actor.GetPixelArea().x, TEST_LOCATION );
178 DALI_TEST_EQUALS( 2, actor.GetPixelArea().y, TEST_LOCATION );
179 DALI_TEST_EQUALS( 3, actor.GetPixelArea().width, TEST_LOCATION );
180 DALI_TEST_EQUALS( 4, actor.GetPixelArea().height, TEST_LOCATION );
182 ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
184 DALI_TEST_EQUALS( 5, actor2.GetPixelArea().x, TEST_LOCATION );
185 DALI_TEST_EQUALS( 6, actor2.GetPixelArea().y, TEST_LOCATION );
186 DALI_TEST_EQUALS( 7, actor2.GetPixelArea().width, TEST_LOCATION );
187 DALI_TEST_EQUALS( 8, actor2.GetPixelArea().height, TEST_LOCATION );
191 // Set a size that is too large on an Image with a shader that requires grid
192 int UtcDaliImageActorSetSize01(void)
194 TestApplication application;
196 BufferImage img = BufferImage::New( 1,1 );
197 ImageActor actor = ImageActor::New( img );
199 ShaderEffect effect = ShaderEffect::New( " ", " ", ShaderEffect::HINT_GRID );
200 actor.SetShaderEffect( effect );
202 const float INVALID_SIZE = float(1u<<31);
203 Vector3 vector( INVALID_SIZE, INVALID_SIZE, 0.0f );
205 DALI_TEST_CHECK(vector != actor.GetCurrentSize());
207 actor.SetSize(vector);
208 Stage::GetCurrent().Add(actor);
210 // flush the queue and render once
211 application.SendNotification();
212 application.Render();
214 DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
218 int UtcDaliImageActorGetCurrentSize01(void)
220 TestApplication application;
221 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
223 Vector2 initialImageSize(100, 50);
224 BufferImage image = BufferImage::New( initialImageSize.width, initialImageSize.height );
225 ImageActor actor = ImageActor::New( image );
226 Stage::GetCurrent().Add(actor);
228 application.SendNotification();
229 application.Render();
231 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
233 Vector2 size(200.0f, 200.0f);
236 // flush the queue and render once
237 application.SendNotification();
238 application.Render();
239 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
244 application.Render(8);
246 // Test when a pixel area is set
247 ImageActor::PixelArea area(0, 0, 10, 10);
248 actor.SetPixelArea(area);
249 application.Render(9);
250 // natural size is not used as setsize is called
251 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
257 int UtcDaliImageActorGetCurrentSize02(void)
259 TestApplication application;
260 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");
262 Vector2 initialImageSize(100, 50);
264 application.GetPlatform().SetClosestImageSize(initialImageSize);
266 Image image = ResourceImage::New("image.jpg");
267 ImageActor actor = ImageActor::New( image );
268 Stage::GetCurrent().Add(actor);
270 application.SendNotification(); // Flush update messages
271 application.Render(); // Process resource request
272 application.SendNotification(); // Flush update messages
273 application.Render(); // Process resource request
275 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
277 // Now complete the image load
278 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
279 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
280 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
282 Integration::ResourcePointer resourcePtr(bitmap); // reference it
283 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
284 application.Render(); // Process LoadComplete
285 application.SendNotification(); // Process event messages
286 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
287 application.GetPlatform().ClearReadyResources(); //
289 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
291 Vector2 size(200.0f, 200.0f);
294 // flush the queue and render once
295 application.SendNotification();
296 application.Render();
297 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
303 int UtcDaliImageActorGetCurrentSize03(void)
305 TestApplication application;
306 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");
308 const Vector2 closestImageSize( 80, 45);
309 application.GetPlatform().SetClosestImageSize(closestImageSize);
311 Vector2 requestedSize( 40, 30 );
312 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
313 ImageActor actor = ImageActor::New( image );
314 Stage::GetCurrent().Add(actor);
316 application.SendNotification(); // Flush update messages
317 application.Render(); // Process resource request
318 application.SendNotification(); // Flush update messages
319 application.Render(); // Process resource request
321 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
323 // Now complete the image load
324 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
325 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
326 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
328 Integration::ResourcePointer resourcePtr(bitmap); // reference it
329 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
330 application.Render(); // Process LoadComplete
331 application.SendNotification(); // Process event messages
332 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
333 application.GetPlatform().ClearReadyResources(); //
335 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
341 int UtcDaliImageActorGetCurrentSize04(void)
343 TestApplication application;
344 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
346 const Vector2 closestImageSize( 80, 45);
347 application.GetPlatform().SetClosestImageSize(closestImageSize);
349 Vector2 requestedSize( 40, 30 );
350 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
351 ImageActor actor = ImageActor::New( image );
352 Stage::GetCurrent().Add(actor);
354 application.SendNotification(); // Flush update messages
355 application.Render(); // Process resource request
357 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
359 // Now complete the image load
360 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
361 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
362 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
364 Integration::ResourcePointer resourcePtr(bitmap); // reference it
365 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
366 application.Render(); // Process LoadComplete
367 application.SendNotification(); // Process event messages
368 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
369 application.GetPlatform().ClearReadyResources(); //
371 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
373 Vector2 size(200.0f, 200.0f);
376 // flush the queue and render once
377 application.SendNotification();
378 application.Render();
379 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
381 // Load a different image
383 Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
384 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
386 const Vector2 request2Size( 100, 100 );
387 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( request2Size.x, request2Size.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
388 actor.SetImage(image2);
390 application.SendNotification(); // Flush update messages
391 application.Render(); // Process resource request
392 application.SendNotification(); // Flush update messages
393 application.Render(); // Process resource request
395 // Ensure the actor size is kept
396 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
398 // Now complete the image load
399 req = application.GetPlatform().GetRequest();
400 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
401 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
403 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
404 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
405 application.Render(); // Process LoadComplete
406 application.SendNotification(); // Process event messages
407 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
408 application.GetPlatform().ClearReadyResources(); //
410 // Ensure the actor size is kept
411 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), size, TEST_LOCATION );
417 int UtcDaliImageActorGetCurrentSize05(void)
419 TestApplication application;
420 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
422 Vector2 closestImageSize( 80, 45);
423 application.GetPlatform().SetClosestImageSize(closestImageSize);
425 Vector2 requestedSize( 40, 30 );
426 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
427 ImageActor actor = ImageActor::New( image );
428 Stage::GetCurrent().Add(actor);
430 application.SendNotification(); // Flush update messages
431 application.Render(); // Process resource request
433 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
435 // Now complete the image load
436 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
437 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
438 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
440 Integration::ResourcePointer resourcePtr(bitmap); // reference it
441 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
442 application.Render(); // Process LoadComplete
443 application.SendNotification(); // Process event messages
444 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
445 application.GetPlatform().ClearReadyResources(); //
447 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
449 // Load a different image
451 Vector2 image2ClosestSize = Vector2(240, 150);
452 application.GetPlatform().SetClosestImageSize(image2ClosestSize);
454 const Vector2 requestedSize2( 100, 100 );
455 Image image2 = ResourceImage::New("image.jpg", ImageDimensions( requestedSize2.x, requestedSize2.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
456 actor.SetImage(image2);
458 application.SendNotification(); // Flush update messages
459 application.Render(); // Process resource request
460 application.SendNotification(); // Flush update messages
461 application.Render(); // Process resource request
463 // Ensure the actor size is kept
464 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
466 // Now complete the image load
467 req = application.GetPlatform().GetRequest();
468 Integration::Bitmap* bitmap2 = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
469 bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
471 Integration::ResourcePointer resourcePtr2(bitmap2); // reference it
472 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr2);
473 application.Render(); // Process LoadComplete
474 application.SendNotification(); // Process event messages
475 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
476 application.GetPlatform().ClearReadyResources(); //
478 application.SendNotification(); // Process event messages
479 application.Render(); // Process LoadComplete
481 // Ensure the actor size gets the new image's natural size
482 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
486 int UtcDaliImageActorNaturalPixelAreaSize01(void)
488 TestApplication application;
489 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
491 //If an image is loaded without setting size, then the actor gets the natural size of the image
492 //Setting the pixel area will change the actor size to match the pixel area
493 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
495 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
498 Vector2 closestImageSize( 80, 45);
499 application.GetPlatform().SetClosestImageSize(closestImageSize);
501 Vector2 requestedSize( 40, 30 );
502 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
503 ImageActor actor = ImageActor::New( image );
504 Stage::GetCurrent().Add(actor);
506 application.SendNotification(); // Flush update messages
507 application.Render(); // Process resource request
509 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
511 // Now complete the image load
512 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
513 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
514 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
516 Integration::ResourcePointer resourcePtr(bitmap); // reference it
517 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
518 application.Render(); // Process LoadComplete
519 application.SendNotification(); // Process event messages
520 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
521 application.GetPlatform().ClearReadyResources(); //
523 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
525 // Set a pixel area on a naturally sized actor - expect the actor to take the
526 // pixel area as size
527 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
528 application.SendNotification(); // Process event messages
529 application.Render(); // Process LoadComplete
530 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
532 // Set a size. Expect the partial image to stretch to fill the new size
533 actor.SetSize(100, 100);
534 application.SendNotification(); // Process event messages
535 application.Render(); // Process LoadComplete
536 application.Render(); // Process LoadComplete
537 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
539 // Clear the pixel area. Expect the whole image to be shown, filling the set size.
540 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
541 application.SendNotification(); // Process event messages
542 application.Render(); // Process LoadComplete
543 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
547 int UtcDaliImageActorNaturalPixelAreaSize02(void)
549 TestApplication application;
550 tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
552 //If an image is loaded without setting size, then the actor gets the natural size of the image
553 //Setting the pixel area will change the actor size to match the pixel area
554 //Setting the actor size will not change pixel area, and will cause the partial image to stretch
556 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
559 Vector2 closestImageSize( 80, 45);
560 application.GetPlatform().SetClosestImageSize(closestImageSize);
562 Vector2 requestedSize( 40, 30 );
563 Image image = ResourceImage::New("image.jpg", ImageDimensions( requestedSize.x, requestedSize.y ), FittingMode::DEFAULT, SamplingMode::DEFAULT );
564 ImageActor actor = ImageActor::New( image );
565 Stage::GetCurrent().Add(actor);
567 application.SendNotification(); // Flush update messages
568 application.Render(); // Process resource request
570 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
572 // Now complete the image load
573 Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
574 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
575 bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
577 Integration::ResourcePointer resourcePtr(bitmap); // reference it
578 application.GetPlatform().SetResourceLoaded(req->GetId(), req->GetType()->id, resourcePtr);
579 application.Render(); // Process LoadComplete
580 application.SendNotification(); // Process event messages
581 application.GetPlatform().DiscardRequest(); // Ensure load request is discarded
582 application.GetPlatform().ClearReadyResources(); //
584 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
586 // Set a pixel area on a naturally sized actor - expect the actor to take the
587 // pixel area as size
588 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 30, 30));
589 application.SendNotification(); // Process event messages
590 application.Render(); // Process LoadComplete
591 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(30, 30), TEST_LOCATION );
593 // Clear the pixel area. Expect the whole image to be shown, changing actor size
594 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
595 application.SendNotification(); // Process event messages
596 application.Render(); // Process LoadComplete
597 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
599 // Set a size. Expect the partial image to stretch to fill the new size
600 actor.SetSize(100, 100);
601 application.SendNotification(); // Process event messages
602 application.Render(); // Process LoadComplete
603 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
605 // Set a pixel area, don't expect size to change
606 actor.SetPixelArea(ImageActor::PixelArea(0, 0, 40, 40));
607 application.SendNotification(); // Process event messages
608 application.Render(); // Process LoadComplete
609 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), Vector2(100, 100), TEST_LOCATION );
611 // Clearing pixel area should change actor size to image size
612 actor.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
613 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, image.GetWidth(), image.GetHeight()) );
614 application.SendNotification(); // Process event messages
615 application.Render(); // Process LoadComplete
616 DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
622 int UtcDaliImageActorDefaultProperties(void)
624 TestApplication application;
625 tet_infoline("Testing Dali::ImageActor DefaultProperties");
627 BufferImage img = BufferImage::New( 10, 10 );
628 ImageActor actor = ImageActor::New( img );
630 std::vector<Property::Index> indices;
631 indices.push_back(ImageActor::Property::PIXEL_AREA );
632 indices.push_back(ImageActor::Property::STYLE );
633 indices.push_back(ImageActor::Property::BORDER );
634 indices.push_back(ImageActor::Property::IMAGE );
636 DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
638 for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
640 DALI_TEST_CHECK( *iter == actor.GetPropertyIndex(actor.GetPropertyName(*iter)) );
641 DALI_TEST_CHECK( actor.IsPropertyWritable(*iter) );
642 DALI_TEST_CHECK( !actor.IsPropertyAnimatable(*iter) );
643 DALI_TEST_CHECK( actor.GetPropertyType(*iter) == actor.GetPropertyType(*iter) ); // just checking call succeeds
646 // set/get one of them
647 actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
649 ImageActor::PixelArea area( 1, 2, 3, 4 );
650 actor.SetProperty(ImageActor::Property::PIXEL_AREA, Property::Value(Rect<int>(area)));
652 DALI_TEST_CHECK(Property::RECTANGLE == actor.GetPropertyType(ImageActor::Property::PIXEL_AREA));
654 Property::Value v = actor.GetProperty(ImageActor::Property::PIXEL_AREA);
656 DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
661 int UtcDaliImageActorUseImageAlpha01(void)
663 TestApplication application;
665 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
667 BufferImage image = BufferImage::New( 100, 50 );
668 ImageActor actor = ImageActor::New( image );
669 actor.SetBlendMode( BlendingMode::ON );
670 actor.SetSize(100, 50);
671 application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
672 Stage::GetCurrent().Add(actor);
674 application.SendNotification();
675 application.Render();
677 const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace();
678 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
679 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
683 int UtcDaliImageActorUseImageAlpha02(void)
685 TestApplication application;
687 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
689 BufferImage image = BufferImage::New( 100, 50 );
690 ImageActor actor = ImageActor::New( image );
691 actor.SetBlendMode( BlendingMode::OFF );
692 actor.SetSize(100, 50);
693 application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
694 Stage::GetCurrent().Add(actor);
696 application.SendNotification();
697 application.Render();
699 const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace();
700 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
701 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
705 int UtcDaliImageActorUseImageAlpha03(void)
707 TestApplication application;
709 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
711 BufferImage image = BufferImage::New( 100, 50 );
712 ImageActor actor = ImageActor::New( image );
713 actor.SetBlendMode( BlendingMode::AUTO );
714 actor.SetColor(Vector4(1.0, 1.0, 1.0, 0.5));
715 actor.SetSize(100, 50);
716 application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
717 Stage::GetCurrent().Add(actor);
719 application.SendNotification();
720 application.Render();
722 const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace();
723 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
724 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
728 int UtcDaliImageActorUseImageAlpha04(void)
730 TestApplication application;
732 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
734 FrameBufferImage image = FrameBufferImage::New( 100, 50, Pixel::RGBA8888 );
735 RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
736 RenderTask task = taskList.GetTask( 0u );
737 task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
738 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
739 application.SendNotification();
740 application.Render(0);
742 ImageActor actor = ImageActor::New( image );
743 application.SendNotification();
744 application.Render(0);
746 actor.SetBlendMode( BlendingMode::ON );
747 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
748 actor.SetSize(100, 50);
749 application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
750 Stage::GetCurrent().Add(actor);
752 application.SendNotification();
753 application.Render();
755 const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace();
756 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
757 DALI_TEST_EQUALS( BlendEnabled( callTrace), true, TEST_LOCATION );
761 int UtcDaliImageActorUseImageAlpha05(void)
763 TestApplication application;
765 tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
767 BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
768 ImageActor actor = ImageActor::New( image );
769 actor.SetBlendMode( BlendingMode::AUTO );
770 actor.SetColor(Vector4(1.0, 1.0, 1.0, 1.0));
771 actor.SetSize(100, 50);
772 application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
773 Stage::GetCurrent().Add(actor);
775 application.SendNotification();
776 application.Render();
778 const TraceCallStack& callTrace = application.GetGlAbstraction().GetEnableDisableTrace();
779 DALI_TEST_EQUALS( BlendDisabled( callTrace ), false, TEST_LOCATION );
780 DALI_TEST_EQUALS( BlendEnabled( callTrace), false, TEST_LOCATION );
784 int UtcDaliImageActorGetStyle(void)
786 TestApplication application;
788 Image image = ResourceImage::New(TestImageFilename);
789 ImageActor actor = ImageActor::New(image);
791 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
793 // flush the queue and render once
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
801 int UtcDaliImageActorSetNinePatchBorder(void)
803 TestApplication application;
805 Image image = ResourceImage::New(TestImageFilename);
806 ImageActor actor = ImageActor::New(image);
808 actor.SetStyle(ImageActor::STYLE_NINE_PATCH);
809 DALI_TEST_EQUALS( ImageActor::STYLE_NINE_PATCH, actor.GetStyle(), TEST_LOCATION );
811 actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
813 DALI_TEST_EQUALS( 1.0f, actor.GetNinePatchBorder().x, TEST_LOCATION );
814 DALI_TEST_EQUALS( 2.0f, actor.GetNinePatchBorder().y, TEST_LOCATION );
815 DALI_TEST_EQUALS( 3.0f, actor.GetNinePatchBorder().z, TEST_LOCATION );
816 DALI_TEST_EQUALS( 4.0f, actor.GetNinePatchBorder().w, TEST_LOCATION );
820 int UtcDaliImageActorNewNull(void)
822 TestApplication application;
824 ImageActor actor = ImageActor::New(Image());
826 DALI_TEST_CHECK(actor);
830 int UtcDaliImageActorNewNullWithArea(void)
832 TestApplication application;
834 ImageActor::PixelArea area( 1, 2, 3, 4 );
836 ImageActor actor = ImageActor::New(Image(), area);
838 DALI_TEST_CHECK(actor);
842 int UtcDaliImageActorSetImage(void)
844 TestApplication application;
846 ImageActor actor = ImageActor::New(Image());
848 DALI_TEST_CHECK(actor);
850 actor.SetImage( Image() );
852 DALI_TEST_CHECK(!actor.GetImage());
856 int UtcDaliImageActorPropertyIndices(void)
858 TestApplication application;
859 Actor basicActor = Actor::New();
860 ImageActor imageActor = ImageActor::New();
862 Property::IndexContainer indices;
863 imageActor.GetPropertyIndices( indices );
864 DALI_TEST_CHECK( indices.Size() > basicActor.GetPropertyCount() );
865 DALI_TEST_EQUALS( indices.Size(), imageActor.GetPropertyCount(), TEST_LOCATION );
869 int UtcDaliImageActorImageProperty(void)
871 TestApplication application;
872 Image image = ResourceImage::New( "MY_PATH" );
873 ImageActor imageActor = ImageActor::New( image );
875 Stage::GetCurrent().Add( imageActor );
876 application.SendNotification();
877 application.Render();
879 Property::Value imageProperty = imageActor.GetProperty( ImageActor::Property::IMAGE );
880 Property::Map* imageMap = imageProperty.GetMap();
881 DALI_TEST_CHECK( imageMap != NULL );
882 DALI_TEST_CHECK( NULL != imageMap->Find( "filename" ) );
883 DALI_TEST_EQUALS( (*imageMap)[ "filename" ].Get< std::string >(), "MY_PATH", TEST_LOCATION );
887 int UtcDaliImageActorNinePatch01(void)
889 TestApplication application;
890 TestPlatformAbstraction& platform = application.GetPlatform();
891 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
892 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
893 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
895 tet_infoline("Test the successful loading of a nine-patch image\n");
897 platform.SetClosestImageSize(Vector2(4, 4));
898 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
899 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
900 memset( pixels, 0, 64 );
902 Integration::ResourcePointer resourcePtr(bitmap); // reference it
903 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
905 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
906 DALI_TEST_CHECK( ninePatchImage );
908 ImageActor imageActor = ImageActor::New( ninePatchImage );
909 DALI_TEST_CHECK( imageActor );
910 Stage::GetCurrent().Add( imageActor );
913 textureTrace.Reset();
914 drawTrace.Enable(true);
915 textureTrace.Enable(true);
916 glAbstraction.ClearBoundTextures();
917 std::vector<GLuint> ids;
919 glAbstraction.SetNextTextureIds( ids );
921 application.SendNotification();
922 application.Render();
924 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
925 typedef std::vector<GLuint> TexVec;
926 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
927 DALI_TEST_CHECK( textures.size() > 0 );
928 if( textures.size() > 0 )
930 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
937 int UtcDaliImageActorNinePatch02(void)
939 TestApplication application;
940 TestPlatformAbstraction& platform = application.GetPlatform();
941 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
942 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
943 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
945 tet_infoline("Test the failed loading of a nine-patch image\n");
947 platform.SetClosestImageSize(Vector2(0, 0));
948 Integration::ResourcePointer resourcePtr;
949 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
951 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
952 DALI_TEST_CHECK( ninePatchImage );
954 ImageActor imageActor = ImageActor::New( ninePatchImage );
955 DALI_TEST_CHECK( imageActor );
956 Stage::GetCurrent().Add( imageActor );
959 textureTrace.Reset();
960 drawTrace.Enable(true);
961 textureTrace.Enable(true);
962 glAbstraction.ClearBoundTextures();
963 std::vector<GLuint> ids;
965 glAbstraction.SetNextTextureIds( ids );
967 application.SendNotification();
968 application.Render();
970 // Check that nothing was drawn.
971 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawElements" ) );
972 typedef std::vector<GLuint> TexVec;
973 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
974 DALI_TEST_CHECK( textures.size() == 0u );
980 int UtcDaliImageActorNinePatch03(void)
982 TestApplication application;
983 TestPlatformAbstraction& platform = application.GetPlatform();
984 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
985 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
986 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
988 tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
990 platform.SetClosestImageSize(Vector2(4, 4));
991 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_RETAIN );
992 Integration::PixelBuffer* pixels = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, 4,4,4,4 );
993 memset( pixels, 0, 64 );
995 Integration::ResourcePointer resourcePtr(bitmap); // reference it
996 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
998 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
999 DALI_TEST_CHECK( ninePatchImage );
1001 ImageActor imageActor = ImageActor::New();
1002 DALI_TEST_CHECK( imageActor );
1003 Stage::GetCurrent().Add( imageActor );
1005 imageActor.SetImage( ninePatchImage );
1008 textureTrace.Reset();
1009 drawTrace.Enable(true);
1010 textureTrace.Enable(true);
1011 glAbstraction.ClearBoundTextures();
1012 std::vector<GLuint> ids;
1013 ids.push_back( 23 );
1014 glAbstraction.SetNextTextureIds( ids );
1016 application.SendNotification();
1017 application.Render();
1019 DALI_TEST_CHECK( drawTrace.FindMethod( "DrawElements" ) );
1020 typedef std::vector<GLuint> TexVec;
1021 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1022 DALI_TEST_CHECK( textures.size() > 0 );
1023 if( textures.size() > 0 )
1025 DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1032 int UtcDaliImageActorNinePatch04(void)
1034 TestApplication application;
1035 TestPlatformAbstraction& platform = application.GetPlatform();
1036 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1037 TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1038 TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1040 tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1042 platform.SetClosestImageSize(Vector2(0, 0));
1043 Integration::ResourcePointer resourcePtr;
1044 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1046 Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1047 DALI_TEST_CHECK( ninePatchImage );
1049 ImageActor imageActor = ImageActor::New();
1050 DALI_TEST_CHECK( imageActor );
1051 Stage::GetCurrent().Add( imageActor );
1053 imageActor.SetImage( ninePatchImage );
1056 textureTrace.Reset();
1057 drawTrace.Enable(true);
1058 textureTrace.Enable(true);
1059 glAbstraction.ClearBoundTextures();
1060 std::vector<GLuint> ids;
1061 ids.push_back( 23 );
1062 glAbstraction.SetNextTextureIds( ids );
1064 application.SendNotification();
1065 application.Render();
1067 // Check that nothing was drawn.
1068 DALI_TEST_CHECK( ! drawTrace.FindMethod( "DrawElements" ) );
1069 typedef std::vector<GLuint> TexVec;
1070 const TexVec& textures = glAbstraction.GetBoundTextures(GL_TEXTURE0);
1071 DALI_TEST_CHECK( textures.size() == 0u );
1076 int UtcDaliImageActorGetNaturalSize(void)
1078 TestApplication application;
1081 BufferImage img = BufferImage::New( 10, 10 );
1082 ImageActor actor = ImageActor::New( img );
1084 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1087 ImageActor::PixelArea area( 1, 2, 3, 4 );
1088 actor.SetPixelArea( area );
1090 DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );
1095 int UtcDaliImageActorGetSortModifier(void)
1097 TestApplication application;
1099 tet_infoline("Testing Dali::ImageActor::GetSortModifier()");
1101 ImageActor actor = ImageActor::New();
1102 Stage::GetCurrent().Add(actor);
1104 DALI_TEST_EQUALS(actor.GetSortModifier(), 0.0f, TEST_LOCATION);
1106 Stage::GetCurrent().Remove(actor);
1110 int UtcDaliImageActorSetGetBlendMode(void)
1112 TestApplication application;
1114 tet_infoline("Testing Dali::ImageActor::SetBlendMode() / Dali::ImageActor::GetBlendMode()");
1116 ImageActor actor = ImageActor::New();
1118 actor.SetBlendMode( BlendingMode::OFF );
1119 DALI_TEST_CHECK( BlendingMode::OFF == actor.GetBlendMode() );
1121 actor.SetBlendMode( BlendingMode::AUTO );
1122 DALI_TEST_CHECK( BlendingMode::AUTO == actor.GetBlendMode() );
1124 actor.SetBlendMode( BlendingMode::ON );
1125 DALI_TEST_CHECK( BlendingMode::ON == actor.GetBlendMode() );
1129 int UtcDaliImageActorSetGetBlendFunc(void)
1131 TestApplication application;
1132 TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1134 tet_infoline("Testing Dali::ImageActor::UtcDaliImageActorSetGetBlendFunc()");
1136 BufferImage img = BufferImage::New( 1,1 );
1137 ImageActor actor = ImageActor::New( img );
1138 Stage::GetCurrent().Add( actor );
1139 application.SendNotification();
1140 application.Render();
1142 // Test the defaults as documented int blending.h
1144 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1145 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1146 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1147 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1148 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1149 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA, srcFactorRgb, TEST_LOCATION );
1150 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorRgb, TEST_LOCATION );
1151 DALI_TEST_EQUALS( BlendingFactor::ONE, srcFactorAlpha, TEST_LOCATION );
1152 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_ALPHA, destFactorAlpha, TEST_LOCATION );
1155 // Set to non-default values
1156 actor.SetBlendFunc( BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE, BlendingFactor::ONE_MINUS_SRC_COLOR, BlendingFactor::SRC_ALPHA_SATURATE );
1158 // Test that Set was successful
1160 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1161 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1162 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1163 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1164 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1165 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorRgb, TEST_LOCATION );
1166 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorRgb, TEST_LOCATION );
1167 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_SRC_COLOR, srcFactorAlpha, TEST_LOCATION );
1168 DALI_TEST_EQUALS( BlendingFactor::SRC_ALPHA_SATURATE, destFactorAlpha, TEST_LOCATION );
1171 // Render & check GL commands
1172 application.SendNotification();
1173 application.Render();
1174 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
1175 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
1176 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_SRC_COLOR, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1177 DALI_TEST_EQUALS( (GLenum)GL_SRC_ALPHA_SATURATE, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1179 // Set using separate alpha settings
1180 actor.SetBlendFunc( BlendingFactor::CONSTANT_COLOR, BlendingFactor::ONE_MINUS_CONSTANT_COLOR,
1181 BlendingFactor::CONSTANT_ALPHA, BlendingFactor::ONE_MINUS_CONSTANT_ALPHA );
1183 // Test that Set was successful
1185 BlendingFactor::Type srcFactorRgb( BlendingFactor::ZERO );
1186 BlendingFactor::Type destFactorRgb( BlendingFactor::ZERO );
1187 BlendingFactor::Type srcFactorAlpha( BlendingFactor::ZERO );
1188 BlendingFactor::Type destFactorAlpha( BlendingFactor::ZERO );
1189 actor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha );
1190 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_COLOR, srcFactorRgb, TEST_LOCATION );
1191 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_COLOR, destFactorRgb, TEST_LOCATION );
1192 DALI_TEST_EQUALS( BlendingFactor::CONSTANT_ALPHA, srcFactorAlpha, TEST_LOCATION );
1193 DALI_TEST_EQUALS( BlendingFactor::ONE_MINUS_CONSTANT_ALPHA, destFactorAlpha, TEST_LOCATION );
1196 // Render & check GL commands
1197 application.SendNotification();
1198 application.Render();
1199 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncSrcRgb(), TEST_LOCATION );
1200 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_COLOR, glAbstraction.GetLastBlendFuncDstRgb(), TEST_LOCATION );
1201 DALI_TEST_EQUALS( (GLenum)GL_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncSrcAlpha(), TEST_LOCATION );
1202 DALI_TEST_EQUALS( (GLenum)GL_ONE_MINUS_CONSTANT_ALPHA, glAbstraction.GetLastBlendFuncDstAlpha(), TEST_LOCATION );
1206 int UtcDaliImageActorSetGetAlpha(void)
1208 TestApplication application;
1210 tet_infoline("Testing Dali::ImageActor::SetGetAlpha()");
1212 BufferImage img = BufferImage::New( 1,1 );
1213 ImageActor actor = ImageActor::New( img );
1214 Stage::GetCurrent().Add( actor );
1215 application.SendNotification();
1216 application.Render();
1218 // use the image alpha on actor
1219 actor.SetBlendMode(BlendingMode::ON);
1221 // Test that Set was successful
1222 DALI_TEST_EQUALS( BlendingMode::ON, actor.GetBlendMode(), TEST_LOCATION );
1224 // Now test that it can be set to false
1225 actor.SetBlendMode(BlendingMode::OFF);
1226 DALI_TEST_EQUALS(BlendingMode::OFF, actor.GetBlendMode(), TEST_LOCATION );
1230 int UtcDaliImageActorSetGetFilterModes(void)
1232 TestApplication application;
1234 tet_infoline("Testing Dali::ImageActor::SetFilterMode() / Dali::ImageActor::GetFilterMode()");
1236 ImageActor actor = ImageActor::New();
1238 FilterMode::Type minifyFilter = FilterMode::NEAREST;
1239 FilterMode::Type magnifyFilter = FilterMode::NEAREST;
1242 actor.GetFilterMode( minifyFilter, magnifyFilter );
1243 DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1244 DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1247 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1248 actor.GetFilterMode( minifyFilter, magnifyFilter );
1249 DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1250 DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1253 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1254 actor.GetFilterMode( minifyFilter, magnifyFilter );
1255 DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1256 DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1259 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1260 actor.GetFilterMode( minifyFilter, magnifyFilter );
1261 DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1262 DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1265 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1266 actor.GetFilterMode( minifyFilter, magnifyFilter );
1267 DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1268 DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1271 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::NEAREST );
1272 actor.GetFilterMode( minifyFilter, magnifyFilter );
1273 DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1274 DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1279 int UtcDaliImageActorSetFilterMode(void)
1281 TestApplication application;
1283 tet_infoline("Testing Dali::ImageActor::SetFilterMode()");
1285 BufferImage img = BufferImage::New( 1,1 );
1286 ImageActor actor = ImageActor::New( img );
1288 actor.SetSize(100.0f, 100.0f);
1289 actor.SetParentOrigin(ParentOrigin::CENTER);
1290 actor.SetAnchorPoint(AnchorPoint::CENTER);
1292 Stage::GetCurrent().Add(actor);
1294 /**************************************************************/
1297 TraceCallStack& texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1298 texParameterTrace.Reset();
1299 texParameterTrace.Enable( true );
1301 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1303 // Flush the queue and render once
1304 application.SendNotification();
1305 application.Render();
1307 texParameterTrace.Enable( false );
1309 std::stringstream out;
1311 // Verify actor gl state
1313 // There are two calls to TexParameteri when the texture is first created
1314 // Texture mag filter is not called as the first time set it uses the system default
1315 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 3, TEST_LOCATION);
1318 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1319 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
1321 /**************************************************************/
1324 texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1325 texParameterTrace.Reset();
1326 texParameterTrace.Enable( true );
1328 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1330 // Flush the queue and render once
1331 application.SendNotification();
1332 application.Render();
1334 texParameterTrace.Enable( false );
1336 // Verify actor gl state
1338 // Should not make any calls when settings are the same
1339 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
1341 /**************************************************************/
1344 texParameterTrace.Reset();
1345 texParameterTrace.Enable( true );
1347 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::NEAREST );
1349 // Flush the queue and render once
1350 application.SendNotification();
1351 application.Render();
1353 texParameterTrace.Enable( false );
1355 // Verify actor gl state
1356 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1359 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1360 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1363 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
1364 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1366 /**************************************************************/
1369 texParameterTrace.Reset();
1370 texParameterTrace.Enable( true );
1372 actor.SetFilterMode( FilterMode::LINEAR, FilterMode::LINEAR );
1374 // Flush the queue and render once
1375 application.SendNotification();
1376 application.Render();
1378 texParameterTrace.Enable( false );
1380 // Verify actor gl state
1381 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1384 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1385 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1388 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
1389 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1392 /**************************************************************/
1395 texParameterTrace.Reset();
1396 texParameterTrace.Enable( true );
1398 actor.SetFilterMode( FilterMode::NEAREST, FilterMode::LINEAR );
1400 // Flush the queue and render once
1401 application.SendNotification();
1402 application.Render();
1404 texParameterTrace.Enable( false );
1406 // Verify actor gl state
1407 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1410 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1411 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1413 /**************************************************************/
1416 texParameterTrace.Reset();
1417 texParameterTrace.Enable( true );
1419 actor.SetFilterMode( FilterMode::DEFAULT, FilterMode::DEFAULT );
1421 // Flush the queue and render once
1422 application.SendNotification();
1423 application.Render();
1425 texParameterTrace.Enable( false );
1427 // Verify actor gl state
1428 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1431 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1432 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1434 /**************************************************************/
1437 texParameterTrace.Reset();
1438 texParameterTrace.Enable( true );
1440 actor.SetFilterMode( FilterMode::NONE, FilterMode::NONE );
1442 // Flush the queue and render once
1443 application.SendNotification();
1444 application.Render();
1446 texParameterTrace.Enable( false );
1448 // Verify actor gl state
1449 DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1452 out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST_MIPMAP_LINEAR;
1453 DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1455 /**************************************************************/
1457 Stage::GetCurrent().Remove(actor);
1462 int UtcDaliImageActorSetShaderEffect(void)
1464 TestApplication application;
1465 BufferImage img = BufferImage::New( 1,1 );
1466 ImageActor actor = ImageActor::New( img );
1467 Stage::GetCurrent().Add( actor );
1469 // flush the queue and render once
1470 application.SendNotification();
1471 application.Render();
1472 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1474 application.GetGlAbstraction().EnableShaderCallTrace( true );
1476 const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1477 const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1478 ShaderEffect effect = ShaderEffect::New(vertexShader, fragmentShader );
1479 DALI_TEST_CHECK( effect != actor.GetShaderEffect() );
1481 actor.SetShaderEffect( effect );
1482 DALI_TEST_CHECK( effect == actor.GetShaderEffect() );
1484 // flush the queue and render once
1485 application.SendNotification();
1486 application.Render();
1488 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1489 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1491 std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1492 DALI_TEST_EQUALS( vertexShader,
1493 actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1494 std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1495 DALI_TEST_EQUALS( fragmentShader,
1496 actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1501 int UtcDaliImageActorGetShaderEffect(void)
1503 TestApplication application;
1504 ImageActor actor = ImageActor::New();
1506 ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorGetShaderEffect-VertexSource", "UtcDaliImageActorGetShaderEffect-FragmentSource" );
1507 actor.SetShaderEffect(effect);
1509 DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1513 int UtcDaliImageActorRemoveShaderEffect01(void)
1515 TestApplication application;
1516 ImageActor actor = ImageActor::New();
1518 ShaderEffect defaultEffect = actor.GetShaderEffect();
1520 ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorRemoveShaderEffect-VertexSource", "UtcDaliImageActorRemoveShaderEffect-FragmentSource" );
1521 actor.SetShaderEffect(effect);
1523 DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1525 actor.RemoveShaderEffect();
1527 DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1531 int UtcDaliImageActorRemoveShaderEffect02(void)
1533 TestApplication application;
1534 ImageActor actor = ImageActor::New();
1536 ShaderEffect defaultEffect = actor.GetShaderEffect();
1538 actor.RemoveShaderEffect();
1540 DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1544 int UtcDaliSetShaderEffectRecursively(void)
1546 TestApplication application;
1551 * actor3 imageactor1
1554 BufferImage img = BufferImage::New( 1,1 );
1555 ImageActor actor1 = ImageActor::New( img );
1556 Actor actor2 = Actor::New();
1557 actor1.Add( actor2 );
1558 Actor actor3 = Actor::New();
1559 actor2.Add( actor3 );
1560 ImageActor imageactor1 = ImageActor::New( img );
1561 actor2.Add( imageactor1 );
1562 ImageActor imageactor2 = ImageActor::New( img );
1563 actor3.Add( imageactor2 );
1564 Actor actor4 = Actor::New();
1565 actor1.Add( actor4 );
1566 Stage::GetCurrent().Add( actor1 );
1568 // flush the queue and render once
1569 application.SendNotification();
1570 application.Render();
1571 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1573 application.GetGlAbstraction().EnableShaderCallTrace( true );
1575 const std::string vertexShader = "UtcDaliImageActorSetShaderEffect-VertexSource";
1576 const std::string fragmentShader = "UtcDaliImageActorSetShaderEffect-FragmentSource";
1577 // test with empty effect
1578 ShaderEffect effect;
1579 SetShaderEffectRecursively( actor1, effect );
1581 effect = ShaderEffect::New(vertexShader, fragmentShader );
1583 DALI_TEST_CHECK( effect != actor1.GetShaderEffect() );
1584 DALI_TEST_CHECK( effect != imageactor1.GetShaderEffect() );
1585 DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1587 SetShaderEffectRecursively( actor1, effect );
1588 DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1589 DALI_TEST_CHECK( effect == imageactor2.GetShaderEffect() );
1591 // flush the queue and render once
1592 application.SendNotification();
1593 application.Render();
1595 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1596 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1598 std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
1599 DALI_TEST_EQUALS( vertexShader,
1600 actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
1601 std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
1602 DALI_TEST_EQUALS( fragmentShader,
1603 actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
1605 // remove from one that does not have shader
1606 RemoveShaderEffectRecursively( actor4 );
1609 RemoveShaderEffectRecursively( actor3 );
1610 DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1611 DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1613 // test with empty actor just to check it does not crash
1615 SetShaderEffectRecursively( empty, effect );
1616 RemoveShaderEffectRecursively( empty );
1618 // test with actor with no children just to check it does not crash
1619 Actor loner = Actor::New();
1620 Stage::GetCurrent().Add( loner );
1621 SetShaderEffectRecursively( loner, effect );
1622 RemoveShaderEffectRecursively( loner );
1627 int UtcDaliImageActorTestClearCache(void)
1629 // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
1630 TestApplication application;
1632 tet_infoline("Testing Dali::ImageActor::ClearCache()");
1634 BufferImage img = BufferImage::New( 1,1 );
1635 ImageActor actor = ImageActor::New( img );
1637 actor.SetParentOrigin(ParentOrigin::CENTER);
1638 actor.SetAnchorPoint(AnchorPoint::CENTER);
1640 Stage::GetCurrent().Add(actor);
1642 /**************************************************************/
1643 // Flush the queue and render once
1644 application.SendNotification();
1645 application.Render();
1647 // There should be a single call to Clear
1648 DALI_TEST_EQUALS( application.GetGlAbstraction().GetClearCountCalled(), 1u, TEST_LOCATION );
1650 // the last set clear mask should be COLOR, DEPTH & STENCIL which occurs at the start of each frame
1651 GLbitfield mask = application.GetGlAbstraction().GetLastClearMask();
1652 DALI_TEST_CHECK( mask & GL_DEPTH_BUFFER_BIT );
1653 DALI_TEST_CHECK( mask & GL_STENCIL_BUFFER_BIT );
1654 DALI_TEST_CHECK( mask & GL_COLOR_BUFFER_BIT );