Dali 3D User Interface Engine
utc-Dali-ImageActor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 #include <stdlib.h>
22 #include "dali-test-suite-utils/dali-test-suite-utils.h"
23 
24 using namespace Dali;
25 
26 static const char* TestImageFilename = "icon_wrt.png";
27 
29 {
31 }
32 
34 {
36 }
37 
38 
40 {
41  TestApplication application;
42  tet_infoline("Testing Dali::ImageActor::ImageActor()");
43 
44  ImageActor actor;
45 
46  DALI_TEST_CHECK(!actor);
47  END_TEST;
48 }
49 
51 {
52  TestApplication application;
53 
54  ImageActor* actor = new ImageActor();
55  delete actor;
56 
57  DALI_TEST_CHECK( true );
58  END_TEST;
59 }
60 
62 {
63  TestApplication application;
64  tet_infoline("Positive test for Dali::ImageActor::New()");
65 
67  ImageActor actor = ImageActor::New(image);
68  Stage::GetCurrent().Add(actor);
69 
70  application.SendNotification();
71  application.Render();
72  application.Render();
73  application.SendNotification();
74 
76 
77  DALI_TEST_CHECK(actor);
78  END_TEST;
79 }
80 
82 {
83  TestApplication application;
84  tet_infoline("Negative test for Dali::ImageActor::New()");
85 
86  Image image = ResourceImage::New("hopefullyThisImageFileDoesNotExist");
87  ImageActor actor = ImageActor::New(image);
88 
89  DALI_TEST_CHECK(actor);
90  END_TEST;
91 }
92 
94 {
95  TestApplication application;
96  tet_infoline("Testing Dali::ImageActor::DownCast()");
97 
98  Image image = ResourceImage::New("IncorrectImageName");
99  ImageActor actor1 = ImageActor::New(image);
100  Actor anActor = Actor::New();
101  anActor.Add(actor1);
102 
103  Actor child = anActor.GetChildAt(0);
104  ImageActor imageActor = DownCast< ImageActor >(child);
105 
106  DALI_TEST_CHECK(imageActor);
107  END_TEST;
108 }
109 
111 {
112  TestApplication application;
113  tet_infoline("Testing Dali::ImageActor::DownCast()");
114 
115  Actor actor1 = Actor::New();
116  Actor anActor = Actor::New();
117  anActor.Add(actor1);
118 
119  Actor child = anActor.GetChildAt(0);
120  ImageActor imageActor = ImageActor::DownCast(child);
121  DALI_TEST_CHECK(!imageActor);
122 
123  Actor unInitialzedActor;
124  imageActor = ImageActor::DownCast( unInitialzedActor );
125  DALI_TEST_CHECK(!imageActor);
126  END_TEST;
127 }
128 
130 {
131  TestApplication application;
132  tet_infoline("Testing Dali::ImageActor::ImageActor(const ImageActor& )");
133 
134  Image image = ResourceImage::New("IncorrectImageName");
135  ImageActor actor1 = ImageActor::New(image);
136 
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 );
141 
142  END_TEST;
143 }
144 
146 {
147  TestApplication application;
148  tet_infoline("Positive test for Dali::ImageActor:: 9 patch api");
149 
151  ImageActor actor = ImageActor::New(image);
152 
155 
156  Vector4 border(0.1,0.2,0.3,0.4);
157  actor.SetNinePatchBorder(border);
158 
163  END_TEST;
164 }
165 
167 {
168  TestApplication application;
169  tet_infoline("Positive test for Dali::ImageActor::UtcDaliImageActorPixelArea");
170 
171  BufferImage img = BufferImage::New( 10, 10 );
172  ImageActor actor = ImageActor::New( img );
173 
174  ImageActor::PixelArea area( 1, 2, 3, 4 );
175  actor.SetPixelArea( area );
176 
181 
182  ImageActor actor2 = ImageActor::New( img, ImageActor::PixelArea( 5, 6, 7, 8 ) );
183 
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 );
188  END_TEST;
189 }
190 
191 // Set a size that is too large on an Image with a shader that requires grid
193 {
194  TestApplication application;
195 
196  BufferImage img = BufferImage::New( 1,1 );
197  ImageActor actor = ImageActor::New( img );
198 
200  actor.SetShaderEffect( effect );
201 
202  const float INVALID_SIZE = float(1u<<31);
203  Vector3 vector( INVALID_SIZE, INVALID_SIZE, 0.0f );
204 
205  DALI_TEST_CHECK(vector != actor.GetCurrentSize());
206 
207  actor.SetSize(vector);
208  Stage::GetCurrent().Add(actor);
209 
210  // flush the queue and render once
211  application.SendNotification();
212  application.Render();
213 
214  DALI_TEST_EQUALS(vector, actor.GetCurrentSize(), TEST_LOCATION );
215  END_TEST;
216 }
217 
219 {
220  TestApplication application;
221  tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize");
222 
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);
227 
228  application.SendNotification();
229  application.Render();
230 
231  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
232 
233  Vector2 size(200.0f, 200.0f);
234  actor.SetSize(size);
235 
236  // flush the queue and render once
237  application.SendNotification();
238  application.Render();
240 
241  size.x = 200.0f;
242  size.y = 200.0f;
243  actor.SetSize(size);
244  application.Render(8);
245 
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
252 
253  END_TEST;
254 }
255 
256 
258 {
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");
261 
262  Vector2 initialImageSize(100, 50);
263 
264  application.GetPlatform().SetClosestImageSize(initialImageSize);
265 
266  Image image = ResourceImage::New("image.jpg");
267  ImageActor actor = ImageActor::New( image );
268  Stage::GetCurrent().Add(actor);
269 
270  application.SendNotification(); // Flush update messages
271  application.Render(); // Process resource request
272  application.SendNotification(); // Flush update messages
273  application.Render(); // Process resource request
274 
275  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
276 
277  // Now complete the image load
278  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
280  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, initialImageSize.width,initialImageSize.height, initialImageSize.width,initialImageSize.height );
281 
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(); //
288 
289  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), initialImageSize, TEST_LOCATION );
290 
291  Vector2 size(200.0f, 200.0f);
292  actor.SetSize(size);
293 
294  // flush the queue and render once
295  application.SendNotification();
296  application.Render();
298 
299  END_TEST;
300 }
301 
302 
304 {
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");
307 
308  const Vector2 closestImageSize( 80, 45);
309  application.GetPlatform().SetClosestImageSize(closestImageSize);
310 
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);
315 
316  application.SendNotification(); // Flush update messages
317  application.Render(); // Process resource request
318  application.SendNotification(); // Flush update messages
319  application.Render(); // Process resource request
320 
321  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
322 
323  // Now complete the image load
324  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
326  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
327 
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(); //
334 
335  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
336 
337  END_TEST;
338 }
339 
340 
342 {
343  TestApplication application;
344  tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doesn't change a set actor size");
345 
346  const Vector2 closestImageSize( 80, 45);
347  application.GetPlatform().SetClosestImageSize(closestImageSize);
348 
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);
353 
354  application.SendNotification(); // Flush update messages
355  application.Render(); // Process resource request
356 
357  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
358 
359  // Now complete the image load
360  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
362  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
363 
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(); //
370 
371  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
372 
373  Vector2 size(200.0f, 200.0f);
374  actor.SetSize(size);
375 
376  // flush the queue and render once
377  application.SendNotification();
378  application.Render();
380 
381  // Load a different image
382 
383  Vector2 image2ClosestSize = Vector2(240, 150); // The actual size image loader will return for the request below
384  application.GetPlatform().SetClosestImageSize(image2ClosestSize);
385 
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);
389 
390  application.SendNotification(); // Flush update messages
391  application.Render(); // Process resource request
392  application.SendNotification(); // Flush update messages
393  application.Render(); // Process resource request
394 
395  // Ensure the actor size is kept
397 
398  // Now complete the image load
399  req = application.GetPlatform().GetRequest();
401  bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
402 
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(); //
409 
410  // Ensure the actor size is kept
412 
413  END_TEST;
414 }
415 
416 
418 {
419  TestApplication application;
420  tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
421 
422  Vector2 closestImageSize( 80, 45);
423  application.GetPlatform().SetClosestImageSize(closestImageSize);
424 
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);
429 
430  application.SendNotification(); // Flush update messages
431  application.Render(); // Process resource request
432 
433  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
434 
435  // Now complete the image load
436  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
438  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
439 
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(); //
446 
447  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
448 
449  // Load a different image
450 
451  Vector2 image2ClosestSize = Vector2(240, 150);
452  application.GetPlatform().SetClosestImageSize(image2ClosestSize);
453 
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);
457 
458  application.SendNotification(); // Flush update messages
459  application.Render(); // Process resource request
460  application.SendNotification(); // Flush update messages
461  application.Render(); // Process resource request
462 
463  // Ensure the actor size is kept
464  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
465 
466  // Now complete the image load
467  req = application.GetPlatform().GetRequest();
469  bitmap2->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, image2ClosestSize.width, image2ClosestSize.height, image2ClosestSize.width, image2ClosestSize.height );
470 
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(); //
477 
478  application.SendNotification(); // Process event messages
479  application.Render(); // Process LoadComplete
480 
481  // Ensure the actor size gets the new image's natural size
482  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize2, TEST_LOCATION );
483  END_TEST;
484 }
485 
487 {
488  TestApplication application;
489  tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
490 
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
494 //to the new size.
495 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
496 
497 
498  Vector2 closestImageSize( 80, 45);
499  application.GetPlatform().SetClosestImageSize(closestImageSize);
500 
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);
505 
506  application.SendNotification(); // Flush update messages
507  application.Render(); // Process resource request
508 
509  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
510 
511  // Now complete the image load
512  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
514  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
515 
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(); //
522 
523  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
524 
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
531 
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
538 
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
544  END_TEST;
545 }
546 
548 {
549  TestApplication application;
550  tet_infoline("Positive test for Dali::ImageActor::GetCurrentSize - check a new image doens't change actor size until load complete");
551 
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
555 //to the new size.
556 //Clearing the pixel area will not change actor size, and the actor will show the whole image.
557 
558 
559  Vector2 closestImageSize( 80, 45);
560  application.GetPlatform().SetClosestImageSize(closestImageSize);
561 
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);
566 
567  application.SendNotification(); // Flush update messages
568  application.Render(); // Process resource request
569 
570  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
571 
572  // Now complete the image load
573  Integration::ResourceRequest* req = application.GetPlatform().GetRequest();
575  bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, closestImageSize.width, closestImageSize.height, closestImageSize.width, closestImageSize.height );
576 
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(); //
583 
584  DALI_TEST_EQUALS( Vector2(actor.GetCurrentSize()), requestedSize, TEST_LOCATION );
585 
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
592 
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 );
598 
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
604 
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
610 
611  // Clearing pixel area should change actor size to image size
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 );
617  END_TEST;
618 }
619 
620 
621 
623 {
624  TestApplication application;
625  tet_infoline("Testing Dali::ImageActor DefaultProperties");
626 
627  BufferImage img = BufferImage::New( 10, 10 );
628  ImageActor actor = ImageActor::New( img );
629 
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 );
635 
636  DALI_TEST_CHECK(actor.GetPropertyCount() == ( Actor::New().GetPropertyCount() + indices.size() ) );
637 
638  for(std::vector<Property::Index>::iterator iter = indices.begin(); iter != indices.end(); ++iter)
639  {
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
644  }
645 
646  // set/get one of them
647  actor.SetPixelArea(ImageActor::PixelArea( 0, 0, 0, 0 ));
648 
649  ImageActor::PixelArea area( 1, 2, 3, 4 );
651 
653 
655 
656  DALI_TEST_CHECK(v.Get<Rect<int> >() == area);
657 
658  END_TEST;
659 }
660 
662 {
663  TestApplication application;
664 
665  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
666 
667  BufferImage image = BufferImage::New( 100, 50 );
668  ImageActor actor = ImageActor::New( image );
670  actor.SetSize(100, 50);
671  application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
672  Stage::GetCurrent().Add(actor);
673 
674  application.SendNotification();
675  application.Render();
676 
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 );
680  END_TEST;
681 }
682 
684 {
685  TestApplication application;
686 
687  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
688 
689  BufferImage image = BufferImage::New( 100, 50 );
690  ImageActor actor = ImageActor::New( image );
692  actor.SetSize(100, 50);
693  application.GetGlAbstraction().EnableEnableDisableCallTrace(true); // For Enable(GL_BLEND)
694  Stage::GetCurrent().Add(actor);
695 
696  application.SendNotification();
697  application.Render();
698 
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 );
702  END_TEST;
703 }
704 
706 {
707  TestApplication application;
708 
709  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
710 
711  BufferImage image = BufferImage::New( 100, 50 );
712  ImageActor actor = ImageActor::New( image );
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);
718 
719  application.SendNotification();
720  application.Render();
721 
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 );
725  END_TEST;
726 }
727 
729 {
730  TestApplication application;
731 
732  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
733 
736  RenderTask task = taskList.GetTask( 0u );
737  task.SetTargetFrameBuffer( image ); // To ensure frame buffer is connected
739  application.SendNotification();
740  application.Render(0);
741 
742  ImageActor actor = ImageActor::New( image );
743  application.SendNotification();
744  application.Render(0);
745 
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);
751 
752  application.SendNotification();
753  application.Render();
754 
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 );
758  END_TEST;
759 }
760 
762 {
763  TestApplication application;
764 
765  tet_infoline("Testing Dali::RenderableActor::SetUseImageAlpha()");
766 
767  BufferImage image = BufferImage::New( 100, 50, Pixel::RGB888 );
768  ImageActor actor = ImageActor::New( image );
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);
774 
775  application.SendNotification();
776  application.Render();
777 
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 );
781  END_TEST;
782 }
783 
785 {
786  TestApplication application;
787 
789  ImageActor actor = ImageActor::New(image);
790 
792 
793  // flush the queue and render once
794  application.SendNotification();
795  application.Render();
796 
798  END_TEST;
799 }
800 
802 {
803  TestApplication application;
804 
806  ImageActor actor = ImageActor::New(image);
807 
810 
811  actor.SetNinePatchBorder(Vector4( 1.0f, 2.0f, 3.0f, 4.0f));
812 
817  END_TEST;
818 }
819 
821 {
822  TestApplication application;
823 
824  ImageActor actor = ImageActor::New(Image());
825 
826  DALI_TEST_CHECK(actor);
827  END_TEST;
828 }
829 
831 {
832  TestApplication application;
833 
834  ImageActor::PixelArea area( 1, 2, 3, 4 );
835 
836  ImageActor actor = ImageActor::New(Image(), area);
837 
838  DALI_TEST_CHECK(actor);
839  END_TEST;
840 }
841 
843 {
844  TestApplication application;
845 
846  ImageActor actor = ImageActor::New(Image());
847 
848  DALI_TEST_CHECK(actor);
849 
850  actor.SetImage( Image() );
851 
852  DALI_TEST_CHECK(!actor.GetImage());
853  END_TEST;
854 }
855 
857 {
858  TestApplication application;
859  Actor basicActor = Actor::New();
860  ImageActor imageActor = ImageActor::New();
861 
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 );
866  END_TEST;
867 }
868 
870 {
871  TestApplication application;
872  Image image = ResourceImage::New( "MY_PATH" );
873  ImageActor imageActor = ImageActor::New( image );
874 
875  Stage::GetCurrent().Add( imageActor );
876  application.SendNotification();
877  application.Render();
878 
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 );
884  END_TEST;
885 }
886 
888 {
889  TestApplication application;
890  TestPlatformAbstraction& platform = application.GetPlatform();
891  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
892  TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
893  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
894 
895  tet_infoline("Test the successful loading of a nine-patch image\n");
896 
897  platform.SetClosestImageSize(Vector2(4, 4));
900  memset( pixels, 0, 64 );
901 
902  Integration::ResourcePointer resourcePtr(bitmap); // reference it
903  platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
904 
905  Image ninePatchImage = ResourceImage::New( "blah.#.png" );
906  DALI_TEST_CHECK( ninePatchImage );
907 
908  ImageActor imageActor = ImageActor::New( ninePatchImage );
909  DALI_TEST_CHECK( imageActor );
910  Stage::GetCurrent().Add( imageActor );
911 
912  drawTrace.Reset();
913  textureTrace.Reset();
914  drawTrace.Enable(true);
915  textureTrace.Enable(true);
916  glAbstraction.ClearBoundTextures();
917  std::vector<GLuint> ids;
918  ids.push_back( 23 );
919  glAbstraction.SetNextTextureIds( ids );
920 
921  application.SendNotification();
922  application.Render();
923 
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 )
929  {
930  DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
931  }
932 
933  END_TEST;
934 }
935 
936 
938 {
939  TestApplication application;
940  TestPlatformAbstraction& platform = application.GetPlatform();
941  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
942  TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
943  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
944 
945  tet_infoline("Test the failed loading of a nine-patch image\n");
946 
947  platform.SetClosestImageSize(Vector2(0, 0));
948  Integration::ResourcePointer resourcePtr;
949  platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
950 
951  Image ninePatchImage = ResourceImage::New( "blah.#.png" );
952  DALI_TEST_CHECK( ninePatchImage );
953 
954  ImageActor imageActor = ImageActor::New( ninePatchImage );
955  DALI_TEST_CHECK( imageActor );
956  Stage::GetCurrent().Add( imageActor );
957 
958  drawTrace.Reset();
959  textureTrace.Reset();
960  drawTrace.Enable(true);
961  textureTrace.Enable(true);
962  glAbstraction.ClearBoundTextures();
963  std::vector<GLuint> ids;
964  ids.push_back( 23 );
965  glAbstraction.SetNextTextureIds( ids );
966 
967  application.SendNotification();
968  application.Render();
969 
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 );
975 
976  END_TEST;
977 }
978 
979 
981 {
982  TestApplication application;
983  TestPlatformAbstraction& platform = application.GetPlatform();
984  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
985  TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
986  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
987 
988  tet_infoline("Test the successful loading of a nine-patch image added using ImageActor::SetImage()\n");
989 
990  platform.SetClosestImageSize(Vector2(4, 4));
993  memset( pixels, 0, 64 );
994 
995  Integration::ResourcePointer resourcePtr(bitmap); // reference it
996  platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
997 
998  Image ninePatchImage = ResourceImage::New( "blah.#.png" );
999  DALI_TEST_CHECK( ninePatchImage );
1000 
1001  ImageActor imageActor = ImageActor::New();
1002  DALI_TEST_CHECK( imageActor );
1003  Stage::GetCurrent().Add( imageActor );
1004 
1005  imageActor.SetImage( ninePatchImage );
1006 
1007  drawTrace.Reset();
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 );
1015 
1016  application.SendNotification();
1017  application.Render();
1018 
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 )
1024  {
1025  DALI_TEST_EQUALS( textures[0], 23u, TEST_LOCATION );
1026  }
1027 
1028  END_TEST;
1029 }
1030 
1031 
1033 {
1034  TestApplication application;
1035  TestPlatformAbstraction& platform = application.GetPlatform();
1036  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1037  TraceCallStack& textureTrace = glAbstraction.GetTextureTrace();
1038  TraceCallStack& drawTrace = glAbstraction.GetDrawTrace();
1039 
1040  tet_infoline("Test the failed loading of a nine-patch image using ImageActor::SetImage()\n");
1041 
1042  platform.SetClosestImageSize(Vector2(0, 0));
1043  Integration::ResourcePointer resourcePtr;
1044  platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
1045 
1046  Image ninePatchImage = ResourceImage::New( "blah.#.png" );
1047  DALI_TEST_CHECK( ninePatchImage );
1048 
1049  ImageActor imageActor = ImageActor::New();
1050  DALI_TEST_CHECK( imageActor );
1051  Stage::GetCurrent().Add( imageActor );
1052 
1053  imageActor.SetImage( ninePatchImage );
1054 
1055  drawTrace.Reset();
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 );
1063 
1064  application.SendNotification();
1065  application.Render();
1066 
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 );
1072 
1073  END_TEST;
1074 }
1075 
1077 {
1078  TestApplication application;
1079 
1080  // Standard image
1081  BufferImage img = BufferImage::New( 10, 10 );
1082  ImageActor actor = ImageActor::New( img );
1083 
1084  DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 10, 10 ) );
1085 
1086  // Pixel area set
1087  ImageActor::PixelArea area( 1, 2, 3, 4 );
1088  actor.SetPixelArea( area );
1089 
1090  DALI_TEST_CHECK( actor.GetNaturalSize().GetVectorXY() == Vector2( 3, 4 ) );
1091 
1092  END_TEST;
1093 }
1094 
1096 {
1097  TestApplication application;
1098 
1099  tet_infoline("Testing Dali::ImageActor::GetSortModifier()");
1100 
1101  ImageActor actor = ImageActor::New();
1102  Stage::GetCurrent().Add(actor);
1103 
1105 
1106  Stage::GetCurrent().Remove(actor);
1107  END_TEST;
1108 }
1109 
1111 {
1112  TestApplication application;
1113 
1114  tet_infoline("Testing Dali::ImageActor::SetBlendMode() / Dali::ImageActor::GetBlendMode()");
1115 
1116  ImageActor actor = ImageActor::New();
1117 
1120 
1123 
1124  actor.SetBlendMode( BlendingMode::ON );
1126  END_TEST;
1127 }
1128 
1130 {
1131  TestApplication application;
1132  TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
1133 
1134  tet_infoline("Testing Dali::ImageActor::UtcDaliImageActorSetGetBlendFunc()");
1135 
1136  BufferImage img = BufferImage::New( 1,1 );
1137  ImageActor actor = ImageActor::New( img );
1138  Stage::GetCurrent().Add( actor );
1139  application.SendNotification();
1140  application.Render();
1141 
1142  // Test the defaults as documented int blending.h
1143  {
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 );
1153  }
1154 
1155  // Set to non-default values
1157 
1158  // Test that Set was successful
1159  {
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 );
1169  }
1170 
1171  // Render & check GL commands
1172  application.SendNotification();
1173  application.Render();
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 );
1178 
1179  // Set using separate alpha settings
1182 
1183  // Test that Set was successful
1184  {
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 );
1194  }
1195 
1196  // Render & check GL commands
1197  application.SendNotification();
1198  application.Render();
1203  END_TEST;
1204 }
1205 
1207 {
1208  TestApplication application;
1209 
1210  tet_infoline("Testing Dali::ImageActor::SetGetAlpha()");
1211 
1212  BufferImage img = BufferImage::New( 1,1 );
1213  ImageActor actor = ImageActor::New( img );
1214  Stage::GetCurrent().Add( actor );
1215  application.SendNotification();
1216  application.Render();
1217 
1218  // use the image alpha on actor
1220 
1221  // Test that Set was successful
1223 
1224  // Now test that it can be set to false
1227  END_TEST;
1228 }
1229 
1231 {
1232  TestApplication application;
1233 
1234  tet_infoline("Testing Dali::ImageActor::SetFilterMode() / Dali::ImageActor::GetFilterMode()");
1235 
1236  ImageActor actor = ImageActor::New();
1237 
1238  FilterMode::Type minifyFilter = FilterMode::NEAREST;
1239  FilterMode::Type magnifyFilter = FilterMode::NEAREST;
1240 
1241  // Default test
1242  actor.GetFilterMode( minifyFilter, magnifyFilter );
1243  DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1244  DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1245 
1246  // Default/Default
1248  actor.GetFilterMode( minifyFilter, magnifyFilter );
1249  DALI_TEST_CHECK( FilterMode::DEFAULT == minifyFilter );
1250  DALI_TEST_CHECK( FilterMode::DEFAULT == magnifyFilter );
1251 
1252  // Nearest/Nearest
1254  actor.GetFilterMode( minifyFilter, magnifyFilter );
1255  DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1256  DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1257 
1258  // Linear/Linear
1260  actor.GetFilterMode( minifyFilter, magnifyFilter );
1261  DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1262  DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1263 
1264  // Nearest/Linear
1266  actor.GetFilterMode( minifyFilter, magnifyFilter );
1267  DALI_TEST_CHECK( FilterMode::NEAREST == minifyFilter );
1268  DALI_TEST_CHECK( FilterMode::LINEAR == magnifyFilter );
1269 
1270  // Linear/Nearest
1272  actor.GetFilterMode( minifyFilter, magnifyFilter );
1273  DALI_TEST_CHECK( FilterMode::LINEAR == minifyFilter );
1274  DALI_TEST_CHECK( FilterMode::NEAREST == magnifyFilter );
1275 
1276  END_TEST;
1277 }
1278 
1280 {
1281  TestApplication application;
1282 
1283  tet_infoline("Testing Dali::ImageActor::SetFilterMode()");
1284 
1285  BufferImage img = BufferImage::New( 1,1 );
1286  ImageActor actor = ImageActor::New( img );
1287 
1288  actor.SetSize(100.0f, 100.0f);
1291 
1292  Stage::GetCurrent().Add(actor);
1293 
1294  /**************************************************************/
1295 
1296  // Default/Default
1297  TraceCallStack& texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1298  texParameterTrace.Reset();
1299  texParameterTrace.Enable( true );
1300 
1302 
1303  // Flush the queue and render once
1304  application.SendNotification();
1305  application.Render();
1306 
1307  texParameterTrace.Enable( false );
1308 
1309  std::stringstream out;
1310 
1311  // Verify actor gl state
1312 
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);
1316 
1317  out.str("");
1318  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1319  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(2, "TexParameteri", out.str()), true, TEST_LOCATION);
1320 
1321  /**************************************************************/
1322 
1323  // Default/Default
1324  texParameterTrace = application.GetGlAbstraction().GetTexParameterTrace();
1325  texParameterTrace.Reset();
1326  texParameterTrace.Enable( true );
1327 
1329 
1330  // Flush the queue and render once
1331  application.SendNotification();
1332  application.Render();
1333 
1334  texParameterTrace.Enable( false );
1335 
1336  // Verify actor gl state
1337 
1338  // Should not make any calls when settings are the same
1339  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 0, TEST_LOCATION);
1340 
1341  /**************************************************************/
1342 
1343  // Nearest/Nearest
1344  texParameterTrace.Reset();
1345  texParameterTrace.Enable( true );
1346 
1348 
1349  // Flush the queue and render once
1350  application.SendNotification();
1351  application.Render();
1352 
1353  texParameterTrace.Enable( false );
1354 
1355  // Verify actor gl state
1356  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1357 
1358  out.str("");
1359  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1360  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1361 
1362  out.str("");
1363  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_NEAREST;
1364  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1365 
1366  /**************************************************************/
1367 
1368  // Linear/Linear
1369  texParameterTrace.Reset();
1370  texParameterTrace.Enable( true );
1371 
1373 
1374  // Flush the queue and render once
1375  application.SendNotification();
1376  application.Render();
1377 
1378  texParameterTrace.Enable( false );
1379 
1380  // Verify actor gl state
1381  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 2, TEST_LOCATION);
1382 
1383  out.str("");
1384  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1385  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1386 
1387  out.str("");
1388  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MAG_FILTER << ", " << GL_LINEAR;
1389  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(1, "TexParameteri", out.str()), true, TEST_LOCATION);
1390 
1391 
1392  /**************************************************************/
1393 
1394  // Nearest/Linear
1395  texParameterTrace.Reset();
1396  texParameterTrace.Enable( true );
1397 
1399 
1400  // Flush the queue and render once
1401  application.SendNotification();
1402  application.Render();
1403 
1404  texParameterTrace.Enable( false );
1405 
1406  // Verify actor gl state
1407  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1408 
1409  out.str("");
1410  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_NEAREST;
1411  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1412 
1413  /**************************************************************/
1414 
1415  // Default/Default
1416  texParameterTrace.Reset();
1417  texParameterTrace.Enable( true );
1418 
1420 
1421  // Flush the queue and render once
1422  application.SendNotification();
1423  application.Render();
1424 
1425  texParameterTrace.Enable( false );
1426 
1427  // Verify actor gl state
1428  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1429 
1430  out.str("");
1431  out << GL_TEXTURE_2D << ", " << GL_TEXTURE_MIN_FILTER << ", " << GL_LINEAR;
1432  DALI_TEST_EQUALS( texParameterTrace.TestMethodAndParams(0, "TexParameteri", out.str()), true, TEST_LOCATION);
1433 
1434  /**************************************************************/
1435 
1436  // None/None
1437  texParameterTrace.Reset();
1438  texParameterTrace.Enable( true );
1439 
1441 
1442  // Flush the queue and render once
1443  application.SendNotification();
1444  application.Render();
1445 
1446  texParameterTrace.Enable( false );
1447 
1448  // Verify actor gl state
1449  DALI_TEST_EQUALS( texParameterTrace.CountMethod( "TexParameteri" ), 1, TEST_LOCATION);
1450 
1451  out.str("");
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);
1454 
1455  /**************************************************************/
1456 
1457  Stage::GetCurrent().Remove(actor);
1458 
1459  END_TEST;
1460 }
1461 
1463 {
1464  TestApplication application;
1465  BufferImage img = BufferImage::New( 1,1 );
1466  ImageActor actor = ImageActor::New( img );
1467  Stage::GetCurrent().Add( actor );
1468 
1469  // flush the queue and render once
1470  application.SendNotification();
1471  application.Render();
1472  GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1473 
1474  application.GetGlAbstraction().EnableShaderCallTrace( true );
1475 
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() );
1480 
1481  actor.SetShaderEffect( effect );
1482  DALI_TEST_CHECK( effect == actor.GetShaderEffect() );
1483 
1484  // flush the queue and render once
1485  application.SendNotification();
1486  application.Render();
1487 
1488  GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1489  DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1490 
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 );
1497 
1498  END_TEST;
1499 }
1500 
1502 {
1503  TestApplication application;
1504  ImageActor actor = ImageActor::New();
1505 
1506  ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorGetShaderEffect-VertexSource", "UtcDaliImageActorGetShaderEffect-FragmentSource" );
1507  actor.SetShaderEffect(effect);
1508 
1509  DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1510  END_TEST;
1511 }
1512 
1514 {
1515  TestApplication application;
1516  ImageActor actor = ImageActor::New();
1517 
1518  ShaderEffect defaultEffect = actor.GetShaderEffect();
1519 
1520  ShaderEffect effect = ShaderEffect::New("UtcDaliImageActorRemoveShaderEffect-VertexSource", "UtcDaliImageActorRemoveShaderEffect-FragmentSource" );
1521  actor.SetShaderEffect(effect);
1522 
1523  DALI_TEST_CHECK(effect == actor.GetShaderEffect());
1524 
1525  actor.RemoveShaderEffect();
1526 
1527  DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1528  END_TEST;
1529 }
1530 
1532 {
1533  TestApplication application;
1534  ImageActor actor = ImageActor::New();
1535 
1536  ShaderEffect defaultEffect = actor.GetShaderEffect();
1537 
1538  actor.RemoveShaderEffect();
1539 
1540  DALI_TEST_CHECK(defaultEffect == actor.GetShaderEffect());
1541  END_TEST;
1542 }
1543 
1545 {
1546  TestApplication application;
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 );
1567 
1568  // flush the queue and render once
1569  application.SendNotification();
1570  application.Render();
1571  GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1572 
1573  application.GetGlAbstraction().EnableShaderCallTrace( true );
1574 
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 );
1580 
1581  effect = ShaderEffect::New(vertexShader, fragmentShader );
1582 
1583  DALI_TEST_CHECK( effect != actor1.GetShaderEffect() );
1584  DALI_TEST_CHECK( effect != imageactor1.GetShaderEffect() );
1585  DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1586 
1587  SetShaderEffectRecursively( actor1, effect );
1588  DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1589  DALI_TEST_CHECK( effect == imageactor2.GetShaderEffect() );
1590 
1591  // flush the queue and render once
1592  application.SendNotification();
1593  application.Render();
1594 
1595  GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1596  DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1597 
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 );
1604 
1605  // remove from one that does not have shader
1607 
1608  // remove partially
1610  DALI_TEST_CHECK( effect == imageactor1.GetShaderEffect() );
1611  DALI_TEST_CHECK( effect != imageactor2.GetShaderEffect() );
1612 
1613  // test with empty actor just to check it does not crash
1614  Actor empty;
1615  SetShaderEffectRecursively( empty, effect );
1617 
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 );
1623 
1624  END_TEST;
1625 }
1626 
1628 {
1629  // Testing the framebuffer state caching in frame-buffer-state-caching.cpp
1630  TestApplication application;
1631 
1632  tet_infoline("Testing Dali::ImageActor::ClearCache()");
1633 
1634  BufferImage img = BufferImage::New( 1,1 );
1635  ImageActor actor = ImageActor::New( img );
1636 
1639 
1640  Stage::GetCurrent().Add(actor);
1641 
1642  /**************************************************************/
1643  // Flush the queue and render once
1644  application.SendNotification();
1645  application.Render();
1646 
1647  // There should be a single call to Clear
1649 
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();
1655 
1656  END_TEST;
1657 }
Dali Docs Home
Read more about Dali