2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
28 void utc_dali_buffer_image_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_buffer_image_cleanup(void)
35 test_return_value = TET_PASS;
38 int UtcDaliBufferImageNew01(void)
40 TestApplication application;
42 tet_infoline("UtcDaliBufferImageNew01 - BufferImage::New(unsigned int, unsigned int, Pixel::Format)");
44 // invoke default handle constructor
48 image = BufferImage::New(16, 16);
49 application.SendNotification();
50 application.Render(16);
51 application.Render(16);
52 application.SendNotification();
54 DALI_TEST_CHECK( image.GetWidth() == 16);
58 int UtcDaliBufferImageNew02(void)
60 TestApplication application;
62 tet_infoline("UtcDaliBufferImageNew02 - BufferImage::New(PixelBuffer*, unsigned int, unsigned int, Pixel::Format, unsigned int)");
64 PixelBuffer* buffer = new PixelBuffer[16 * 16];
65 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
66 application.SendNotification();
67 application.Render(16);
68 application.Render(16);
69 application.SendNotification();
71 DALI_TEST_CHECK( image.GetWidth() == 16);
77 int UtcDaliBufferImageNewWithPolicy01(void)
79 TestApplication application;
81 tet_infoline("UtcDaliBufferImageNewWithPolicy01 - BufferImage::New(unsigned int, unsigned int, Pixel::Format, LoadPolicy, ReleasePolicy)");
84 std::vector<GLuint> ids;
86 application.GetGlAbstraction().SetNextTextureIds( ids );
88 // invoke default handle constructor
92 image = BufferImage::New(16, 16, Pixel::A8, Image::UNUSED);
93 application.SendNotification();
94 application.Render(16);
95 application.Render(16);
96 application.SendNotification();
98 DALI_TEST_CHECK( image.GetWidth() == 16);
99 ImageActor actor = ImageActor::New(image);
100 Stage::GetCurrent().Add(actor);
102 application.SendNotification();
103 application.Render(16);
104 // testing ReleasePolicy::Unused
105 // fake loading image
106 application.Render(16);
107 application.SendNotification();
109 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
111 // discard texture when actor comes off stage
112 Stage::GetCurrent().Remove(actor);
113 application.Render(16);
114 application.SendNotification();
115 application.Render(16);
116 application.SendNotification();
117 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
121 int UtcDaliBufferImageNewWithPolicy02(void)
123 TestApplication application;
125 tet_infoline("UtcDaliBufferImageNewWithPolicy02 - BufferImage::New(PixelBuffer*, unsigned int, unsigned int, Pixel::Format, unsigned int, ReleasePolicy)");
127 // Force texture id's
128 std::vector<GLuint> ids;
130 application.GetGlAbstraction().SetNextTextureIds( ids );
132 PixelBuffer* buffer = new PixelBuffer[16 * 16];
133 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8, 16, Image::UNUSED);
134 application.SendNotification();
135 application.Render(16);
136 application.Render(16);
137 application.SendNotification();
139 DALI_TEST_CHECK( image.GetWidth() == 16);
140 ImageActor actor = ImageActor::New(image);
141 Stage::GetCurrent().Add(actor);
143 application.SendNotification();
144 application.Render(16);
145 // testing ReleasePolicy::Unused
146 // fake loading image
147 application.Render(16);
148 application.SendNotification();
150 DALI_TEST_CHECK ( !application.GetGlAbstraction().CheckTextureDeleted(23) );
152 // discard texture when actor comes off stage
153 Stage::GetCurrent().Remove(actor);
154 application.Render(16);
155 application.SendNotification();
156 application.Render(16);
157 application.SendNotification();
158 DALI_TEST_CHECK ( application.GetGlAbstraction().CheckTextureDeleted(23) );
162 int UtcDaliBufferImageDownCast(void)
164 TestApplication application;
165 tet_infoline("Testing Dali::BufferImage::DownCast()");
167 BufferImage bitmap = BufferImage::New(1, 1, Dali::Pixel::BGRA8888);
168 ImageActor imageActor = ImageActor::New(bitmap);
169 application.SendNotification();
170 application.Render(16);
171 application.Render(16);
172 application.SendNotification();
174 Image image = imageActor.GetImage();
175 BufferImage bufferImage = BufferImage::DownCast( image );
177 DALI_TEST_CHECK(bufferImage);
181 int UtcDaliBufferImageDownCast2(void)
183 TestApplication application;
184 tet_infoline("Testing Dali::BufferImage::DownCast()");
186 Image image = ResourceImage::New("IncorrectImageName");
187 ImageActor imageActor = ImageActor::New(image);
188 application.SendNotification();
189 application.Render(16);
190 application.Render(16);
191 application.SendNotification();
193 Image image1 = imageActor.GetImage();
195 BufferImage bufferImage = BufferImage::DownCast( image1 );
196 DALI_TEST_CHECK(!bufferImage);
198 Actor unInitialzedActor;
199 bufferImage = BufferImage::DownCast( unInitialzedActor );
200 DALI_TEST_CHECK(!bufferImage);
204 int UtcDaliBufferImageWHITE(void)
206 TestApplication application;
208 tet_infoline("UtcDaliBufferImageWHITE - BufferImage::WHITE()");
210 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
211 application.SendNotification();
212 application.Render(16);
213 application.Render(16);
214 application.SendNotification();
216 PixelBuffer* buffer = image.GetBuffer();
218 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
219 buffer != NULL && // valid buffer
220 *buffer == 0xff); // r component is 255
224 int UtcDaliBufferImageGetBuffer(void)
226 TestApplication application;
228 tet_infoline("UtcDaliBufferImageGetBuffer");
230 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
232 PixelBuffer* buffer = image.GetBuffer();
233 application.SendNotification();
234 application.Render();
235 application.Render();
236 application.SendNotification();
238 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
239 buffer != NULL && // valid buffer
240 *((unsigned int*)buffer) == 0xffffffff); // all component are 255
244 int UtcDaliBufferImageGetBufferSize(void)
246 TestApplication application;
248 tet_infoline("UtcDaliBufferImageGetBufferSize");
250 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
251 application.SendNotification();
252 application.Render();
253 application.Render();
254 application.SendNotification();
256 PixelBuffer* buffer = image.GetBuffer();
257 unsigned int bufferSize = image.GetBufferSize();
258 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
260 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
261 buffer != NULL && // valid buffer
262 bufferSize == pixelSize); // r component is 255
266 int UtcDaliBufferImageGetBufferStride(void)
268 TestApplication application;
270 tet_infoline("UtcDaliBufferImageGetBufferStride");
272 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
273 application.SendNotification();
274 application.Render();
275 application.Render();
276 application.SendNotification();
278 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
279 unsigned int bufferStride = image.GetBufferStride();
280 DALI_TEST_CHECK( bufferStride == pixelSize );
281 DALI_TEST_CHECK( !image.IsDataExternal() );
283 PixelBuffer* buffer = new PixelBuffer[20 * 16];
284 image = BufferImage::New(buffer, 16, 16, Pixel::A8, 20);
285 application.SendNotification();
286 application.Render(16);
287 application.Render(16);
288 application.SendNotification();
290 bufferStride = image.GetBufferStride();
292 DALI_TEST_CHECK( bufferStride == 20);
293 DALI_TEST_CHECK( image.IsDataExternal() );
299 int UtcDaliBufferImageGetPixelFormat(void)
301 TestApplication application;
303 tet_infoline("UtcDaliBufferImageGetPixelFormat");
305 // Set pixel format to a non-default
306 BufferImage image = BufferImage::New( 16, 16, Pixel::A8 );
307 application.SendNotification();
308 application.Render(16);
309 application.Render(16);
310 application.SendNotification();
312 DALI_TEST_CHECK( image.GetPixelFormat() == Pixel::A8 );
317 int UtcDaliBufferImageIsDataExternal(void)
319 TestApplication application;
321 tet_infoline("UtcDaliBufferImageIsDataExternal - BufferImage::IsDataExternal()");
323 PixelBuffer* buffer = new PixelBuffer[16 * 16];
324 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
325 application.SendNotification();
326 application.Render();
327 application.Render();
328 application.SendNotification();
330 DALI_TEST_CHECK( image.IsDataExternal() );
337 static bool SignalReceived;
338 static void ImageUploaded(Image image)
340 tet_infoline("Received image uploaded signal");
341 SignalReceived = true;
345 int UtcDaliBufferImageUpdate01(void)
347 TestApplication application;
349 tet_infoline("UtcDaliBufferImageUpdate01 - single empty rect");
351 PixelBuffer* buffer = new PixelBuffer[16 * 16];
353 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
354 ImageActor actor = ImageActor::New(image);
355 Stage::GetCurrent().Add(actor);
356 actor.SetVisible(true);
358 SignalReceived = false;
359 image.UploadedSignal().Connect( ImageUploaded );
361 std::vector<GLuint> ids;
365 application.GetGlAbstraction().SetNextTextureIds(ids);
367 // Allow actor to be staged and rendered
368 application.SendNotification();
369 application.Render(0);
370 application.Render(16);
371 application.SendNotification();
372 application.Render(16);
373 application.SendNotification();
375 DALI_TEST_CHECK( image.IsDataExternal() );
376 application.GetGlAbstraction().EnableTextureCallTrace(true);
378 image.Update();//(RectArea()); // notify Core that the image has been updated
379 application.SendNotification();
380 application.Render(16);
381 application.Render(16);
382 application.SendNotification();
383 application.Render(16);
384 application.SendNotification();
386 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
387 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "0, 0, 16, 16"), true, TEST_LOCATION);
389 DALI_TEST_CHECK( SignalReceived == true );
390 SignalReceived = false;
394 int UtcDaliBufferImageUpdate02(void)
396 TestApplication application;
398 tet_infoline("UtcDaliBufferImageUpdate02 - Multiple rects");
400 PixelBuffer* buffer = new PixelBuffer[16 * 16];
401 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
402 ImageActor actor = ImageActor::New(image);
403 Stage::GetCurrent().Add(actor);
404 actor.SetVisible(true);
406 SignalReceived = false;
407 image.UploadedSignal().Connect( ImageUploaded );
409 application.SendNotification();
410 application.Render(0);
411 application.Render(16);
412 application.SendNotification();
413 application.Render(16);
414 application.SendNotification();
416 DALI_TEST_CHECK( image.IsDataExternal() );
417 application.GetGlAbstraction().EnableTextureCallTrace(true);
419 // Check that multiple updates in a frame will be properly uploaded
420 image.Update(RectArea(9,9,5,5));
421 image.Update(RectArea(2,2,4,4));
422 image.Update(RectArea(3,3,1,6));
424 application.SendNotification();
425 application.Render(16);
426 application.Render(16);
427 application.SendNotification();
428 application.Render(16);
429 application.SendNotification();
431 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
432 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", "9, 9, 5, 5"), true, TEST_LOCATION);
433 DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", "2, 2, 4, 4"), true, TEST_LOCATION);
434 DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", "3, 3, 1, 6"), true, TEST_LOCATION);
436 DALI_TEST_CHECK( SignalReceived == true );
437 SignalReceived = false;
441 int UtcDaliBufferImageUploadedSignal01(void)
443 TestApplication application;
445 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent when image is staged");
447 PixelBuffer* buffer = new PixelBuffer[16 * 16];
448 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
449 SignalReceived = false;
450 image.UploadedSignal().Connect( ImageUploaded );
452 application.SendNotification();
453 application.Render(16);
454 application.Render(16);
455 application.SendNotification();
457 Dali::ImageActor imageActor = ImageActor::New(image);
458 Stage::GetCurrent().Add(imageActor);
459 application.SendNotification();
460 application.Render(16);
461 application.SendNotification();
462 application.Render(16);
463 application.SendNotification();
464 application.Render(16);
465 application.SendNotification();
467 DALI_TEST_CHECK( SignalReceived == true );
471 int UtcDaliBufferImageUploadedSignal02(void)
473 TestApplication application;
475 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent after Update");
477 PixelBuffer* buffer = new PixelBuffer[16 * 16];
478 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
479 SignalReceived = false;
480 //ScopedConnection connection =
481 image.UploadedSignal().Connect( ImageUploaded );
483 application.SendNotification();
484 application.Render(16);
485 application.Render(16);
486 application.SendNotification();
488 Dali::ImageActor imageActor = ImageActor::New(image);
489 Stage::GetCurrent().Add(imageActor);
490 application.SendNotification();
491 application.Render(16);
492 application.SendNotification();
493 application.Render(16);
494 application.SendNotification();
495 application.Render(16);
496 application.SendNotification();
497 DALI_TEST_CHECK( SignalReceived == true );
498 SignalReceived = false;
500 image.Update(RectArea()); // notify Core that the whole image has been updated
501 application.SendNotification();
502 application.Render(16);
503 application.SendNotification();
504 application.Render(16);
505 application.SendNotification();
506 application.Render(16);
507 application.SendNotification();
508 DALI_TEST_CHECK( SignalReceived == true );