2 * Copyright (c) 2016 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 UtcDaliBufferImageDownCast(void)
79 TestApplication application;
80 tet_infoline("Testing Dali::BufferImage::DownCast()");
82 BufferImage bitmap = BufferImage::New(1, 1, Dali::Pixel::BGRA8888);
83 Actor actor = CreateRenderableActor( bitmap );
84 application.SendNotification();
85 application.Render(16);
86 application.Render(16);
87 application.SendNotification();
89 Image image = GetTexture( actor );
90 BufferImage bufferImage = BufferImage::DownCast( image );
92 DALI_TEST_CHECK(bufferImage);
96 int UtcDaliBufferImageDownCast2(void)
98 TestApplication application;
99 tet_infoline("Testing Dali::BufferImage::DownCast()");
101 Image image = ResourceImage::New("IncorrectImageName");
102 Actor actor = CreateRenderableActor( image );
103 application.SendNotification();
104 application.Render(16);
105 application.Render(16);
106 application.SendNotification();
108 Image image1 = GetTexture( actor );
110 BufferImage bufferImage = BufferImage::DownCast( image1 );
111 DALI_TEST_CHECK(!bufferImage);
113 Actor unInitialzedActor;
114 bufferImage = BufferImage::DownCast( unInitialzedActor );
115 DALI_TEST_CHECK(!bufferImage);
119 int UtcDaliBufferImageWHITE(void)
121 TestApplication application;
123 tet_infoline("UtcDaliBufferImageWHITE - BufferImage::WHITE()");
125 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
126 application.SendNotification();
127 application.Render(16);
128 application.Render(16);
129 application.SendNotification();
131 PixelBuffer* buffer = image.GetBuffer();
133 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
134 buffer != NULL && // valid buffer
135 *buffer == 0xff); // r component is 255
139 int UtcDaliBufferImageGetBuffer(void)
141 TestApplication application;
143 tet_infoline("UtcDaliBufferImageGetBuffer");
145 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
147 PixelBuffer* buffer = image.GetBuffer();
148 application.SendNotification();
149 application.Render();
150 application.Render();
151 application.SendNotification();
153 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
154 buffer != NULL && // valid buffer
155 *((unsigned int*)buffer) == 0xffffffff); // all component are 255
159 int UtcDaliBufferImageGetBufferSize(void)
161 TestApplication application;
163 tet_infoline("UtcDaliBufferImageGetBufferSize");
165 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
166 application.SendNotification();
167 application.Render();
168 application.Render();
169 application.SendNotification();
171 PixelBuffer* buffer = image.GetBuffer();
172 unsigned int bufferSize = image.GetBufferSize();
173 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
175 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
176 buffer != NULL && // valid buffer
177 bufferSize == pixelSize); // r component is 255
181 int UtcDaliBufferImageGetBufferStride(void)
183 TestApplication application;
185 tet_infoline("UtcDaliBufferImageGetBufferStride");
187 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
188 application.SendNotification();
189 application.Render();
190 application.Render();
191 application.SendNotification();
193 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
194 unsigned int bufferStride = image.GetBufferStride();
195 DALI_TEST_CHECK( bufferStride == pixelSize );
196 DALI_TEST_CHECK( !image.IsDataExternal() );
198 PixelBuffer* buffer = new PixelBuffer[20 * 16];
199 image = BufferImage::New(buffer, 16, 16, Pixel::A8, 20);
200 application.SendNotification();
201 application.Render(16);
202 application.Render(16);
203 application.SendNotification();
205 bufferStride = image.GetBufferStride();
207 DALI_TEST_CHECK( bufferStride == 20);
208 DALI_TEST_CHECK( image.IsDataExternal() );
214 int UtcDaliBufferImageGetPixelFormat(void)
216 TestApplication application;
218 tet_infoline("UtcDaliBufferImageGetPixelFormat");
220 // Set pixel format to a non-default
221 BufferImage image = BufferImage::New( 16, 16, Pixel::A8 );
222 application.SendNotification();
223 application.Render(16);
224 application.Render(16);
225 application.SendNotification();
227 DALI_TEST_CHECK( image.GetPixelFormat() == Pixel::A8 );
232 int UtcDaliBufferImageIsDataExternal(void)
234 TestApplication application;
236 tet_infoline("UtcDaliBufferImageIsDataExternal - BufferImage::IsDataExternal()");
238 PixelBuffer* buffer = new PixelBuffer[16 * 16];
239 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
240 application.SendNotification();
241 application.Render();
242 application.Render();
243 application.SendNotification();
245 DALI_TEST_CHECK( image.IsDataExternal() );
252 static bool SignalReceived;
253 static void ImageUploaded(Image image)
255 tet_infoline("Received image uploaded signal");
256 SignalReceived = true;
260 int UtcDaliBufferImageUpdate01(void)
262 TestApplication application;
264 tet_infoline("UtcDaliBufferImageUpdate01 - single empty rect");
266 PixelBuffer* buffer = new PixelBuffer[16 * 16];
268 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
269 Actor actor = CreateRenderableActor( image );
270 Stage::GetCurrent().Add(actor);
271 actor.SetVisible(true);
273 SignalReceived = false;
274 image.UploadedSignal().Connect( ImageUploaded );
276 std::vector<GLuint> ids;
280 application.GetGlAbstraction().SetNextTextureIds(ids);
282 // Allow actor to be staged and rendered
283 application.SendNotification();
284 application.Render(0);
285 application.Render(16);
286 application.SendNotification();
287 application.Render(16);
288 application.SendNotification();
290 DALI_TEST_CHECK( image.IsDataExternal() );
291 application.GetGlAbstraction().EnableTextureCallTrace(true);
293 image.Update();//(RectArea()); // notify Core that the image has been updated
294 application.SendNotification();
295 application.Render(16);
296 application.Render(16);
297 application.SendNotification();
298 application.Render(16);
299 application.SendNotification();
301 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
303 std::stringstream out;
304 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " << 0u << ", " << 16u <<", "<< 16u;
305 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str() ), true, TEST_LOCATION);
307 DALI_TEST_CHECK( SignalReceived == true );
308 SignalReceived = false;
312 int UtcDaliBufferImageUpdate02(void)
314 TestApplication application;
316 tet_infoline("UtcDaliBufferImageUpdate02 - Multiple rects");
318 PixelBuffer* buffer = new PixelBuffer[16 * 16];
319 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
320 Actor actor = CreateRenderableActor( image );
321 Stage::GetCurrent().Add(actor);
322 actor.SetVisible(true);
324 SignalReceived = false;
325 image.UploadedSignal().Connect( ImageUploaded );
327 application.SendNotification();
328 application.Render(0);
329 application.Render(16);
330 application.SendNotification();
331 application.Render(16);
332 application.SendNotification();
334 DALI_TEST_CHECK( image.IsDataExternal() );
335 application.GetGlAbstraction().EnableTextureCallTrace(true);
337 // Check that multiple updates in a frame will be properly uploaded
338 image.Update(RectArea(9,9,5,5));
339 image.Update(RectArea(2,2,4,4));
340 image.Update(RectArea(3,3,1,6));
342 application.SendNotification();
343 application.Render(16);
344 application.Render(16);
345 application.SendNotification();
346 application.Render(16);
347 application.SendNotification();
349 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
352 std::stringstream out;
353 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 9u << ", " << 9u << ", " << 5u <<", "<< 5u;
354 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
358 std::stringstream out;
359 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 2u << ", " << 2u << ", " << 4u <<", "<< 4u;
360 DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
364 std::stringstream out;
365 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 3u << ", " << 3u << ", " << 1u <<", "<< 6u;
366 DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
369 DALI_TEST_CHECK( SignalReceived == true );
370 SignalReceived = false;
374 int UtcDaliBufferImageUploadedSignal01(void)
376 TestApplication application;
378 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent when image is staged");
380 PixelBuffer* buffer = new PixelBuffer[16 * 16];
381 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
382 SignalReceived = false;
383 image.UploadedSignal().Connect( ImageUploaded );
385 application.SendNotification();
386 application.Render(16);
387 application.Render(16);
388 application.SendNotification();
390 Actor actor = CreateRenderableActor( image );
391 Stage::GetCurrent().Add(actor);
392 application.SendNotification();
393 application.Render(16);
394 application.SendNotification();
395 application.Render(16);
396 application.SendNotification();
397 application.Render(16);
398 application.SendNotification();
400 DALI_TEST_CHECK( SignalReceived == true );
404 int UtcDaliBufferImageUploadedSignal02(void)
406 TestApplication application;
408 tet_infoline("UtcDaliBufferImageUploadedSignal - Test that Uploaded signal is sent after Update");
410 PixelBuffer* buffer = new PixelBuffer[16 * 16];
411 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
412 SignalReceived = false;
413 //ScopedConnection connection =
414 image.UploadedSignal().Connect( ImageUploaded );
416 application.SendNotification();
417 application.Render(16);
418 application.Render(16);
419 application.SendNotification();
421 Actor actor = CreateRenderableActor( image );
422 Stage::GetCurrent().Add(actor);
423 application.SendNotification();
424 application.Render(16);
425 application.SendNotification();
426 application.Render(16);
427 application.SendNotification();
428 application.Render(16);
429 application.SendNotification();
430 DALI_TEST_CHECK( SignalReceived == true );
431 SignalReceived = false;
433 image.Update(RectArea()); // notify Core that the whole image has been updated
434 application.SendNotification();
435 application.Render(16);
436 application.SendNotification();
437 application.Render(16);
438 application.SendNotification();
439 application.Render(16);
440 application.SendNotification();
441 DALI_TEST_CHECK( SignalReceived == true );