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 Actor actor = CreateRenderableActor( 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 Actor actor = CreateRenderableActor( 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 Actor actor = CreateRenderableActor( bitmap );
169 application.SendNotification();
170 application.Render(16);
171 application.Render(16);
172 application.SendNotification();
174 Image image = GetTexture( actor );
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 Actor actor = CreateRenderableActor( image );
188 application.SendNotification();
189 application.Render(16);
190 application.Render(16);
191 application.SendNotification();
193 Image image1 = GetTexture( actor );
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 Actor actor = CreateRenderableActor( 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();
388 std::stringstream out;
389 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 16u;
390 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str() ), true, TEST_LOCATION);
392 DALI_TEST_CHECK( SignalReceived == true );
393 SignalReceived = false;
397 int UtcDaliBufferImageUpdate02(void)
399 TestApplication application;
401 tet_infoline("UtcDaliBufferImageUpdate02 - Multiple rects");
403 PixelBuffer* buffer = new PixelBuffer[16 * 16];
404 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
405 Actor actor = CreateRenderableActor( image );
406 Stage::GetCurrent().Add(actor);
407 actor.SetVisible(true);
409 SignalReceived = false;
410 image.UploadedSignal().Connect( ImageUploaded );
412 application.SendNotification();
413 application.Render(0);
414 application.Render(16);
415 application.SendNotification();
416 application.Render(16);
417 application.SendNotification();
419 DALI_TEST_CHECK( image.IsDataExternal() );
420 application.GetGlAbstraction().EnableTextureCallTrace(true);
422 // Check that multiple updates in a frame will be properly uploaded
423 image.Update(RectArea(9,9,5,5));
424 image.Update(RectArea(2,2,4,4));
425 image.Update(RectArea(3,3,1,6));
427 application.SendNotification();
428 application.Render(16);
429 application.Render(16);
430 application.SendNotification();
431 application.Render(16);
432 application.SendNotification();
434 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
437 std::stringstream out;
438 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 9u << ", " << 9u << ", " << 5u <<", "<< 5u;
439 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
443 std::stringstream out;
444 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 2u << ", " << 2u << ", " << 4u <<", "<< 4u;
445 DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
449 std::stringstream out;
450 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 3u << ", " << 3u << ", " << 1u <<", "<< 6u;
451 DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
454 DALI_TEST_CHECK( SignalReceived == true );
455 SignalReceived = false;
459 int UtcDaliBufferImageUploadedSignal01(void)
461 TestApplication application;
463 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent when image is staged");
465 PixelBuffer* buffer = new PixelBuffer[16 * 16];
466 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
467 SignalReceived = false;
468 image.UploadedSignal().Connect( ImageUploaded );
470 application.SendNotification();
471 application.Render(16);
472 application.Render(16);
473 application.SendNotification();
475 Actor actor = CreateRenderableActor( image );
476 Stage::GetCurrent().Add(actor);
477 application.SendNotification();
478 application.Render(16);
479 application.SendNotification();
480 application.Render(16);
481 application.SendNotification();
482 application.Render(16);
483 application.SendNotification();
485 DALI_TEST_CHECK( SignalReceived == true );
489 int UtcDaliBufferImageUploadedSignal02(void)
491 TestApplication application;
493 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent after Update");
495 PixelBuffer* buffer = new PixelBuffer[16 * 16];
496 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
497 SignalReceived = false;
498 //ScopedConnection connection =
499 image.UploadedSignal().Connect( ImageUploaded );
501 application.SendNotification();
502 application.Render(16);
503 application.Render(16);
504 application.SendNotification();
506 Actor actor = CreateRenderableActor( image );
507 Stage::GetCurrent().Add(actor);
508 application.SendNotification();
509 application.Render(16);
510 application.SendNotification();
511 application.Render(16);
512 application.SendNotification();
513 application.Render(16);
514 application.SendNotification();
515 DALI_TEST_CHECK( SignalReceived == true );
516 SignalReceived = false;
518 image.Update(RectArea()); // notify Core that the whole image has been updated
519 application.SendNotification();
520 application.Render(16);
521 application.SendNotification();
522 application.Render(16);
523 application.SendNotification();
524 application.Render(16);
525 application.SendNotification();
526 DALI_TEST_CHECK( SignalReceived == true );