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 Image image = BufferImage::New(1, 1, Dali::Pixel::BGRA8888);
83 BufferImage bufferImage = BufferImage::DownCast( image );
85 DALI_TEST_CHECK(bufferImage);
89 int UtcDaliBufferImageDownCast2(void)
91 TestApplication application;
92 tet_infoline("Testing Dali::BufferImage::DownCast()");
94 Image image = ResourceImage::New("IncorrectImageName");
95 Actor actor = CreateRenderableActor( image );
96 application.SendNotification();
97 application.Render(16);
98 application.Render(16);
99 application.SendNotification();
101 BufferImage bufferImage = BufferImage::DownCast( image );
102 DALI_TEST_CHECK(!bufferImage);
104 Actor unInitialzedActor;
105 bufferImage = BufferImage::DownCast( unInitialzedActor );
106 DALI_TEST_CHECK(!bufferImage);
110 int UtcDaliBufferImageWHITE(void)
112 TestApplication application;
114 tet_infoline("UtcDaliBufferImageWHITE - BufferImage::WHITE()");
116 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
117 application.SendNotification();
118 application.Render(16);
119 application.Render(16);
120 application.SendNotification();
122 PixelBuffer* buffer = image.GetBuffer();
124 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
125 buffer != NULL && // valid buffer
126 *buffer == 0xff); // r component is 255
130 int UtcDaliBufferImageGetBuffer(void)
132 TestApplication application;
134 tet_infoline("UtcDaliBufferImageGetBuffer");
136 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
138 PixelBuffer* buffer = image.GetBuffer();
139 application.SendNotification();
140 application.Render();
141 application.Render();
142 application.SendNotification();
144 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
145 buffer != NULL && // valid buffer
146 *((unsigned int*)buffer) == 0xffffffff); // all component are 255
150 int UtcDaliBufferImageGetBufferSize(void)
152 TestApplication application;
154 tet_infoline("UtcDaliBufferImageGetBufferSize");
156 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
157 application.SendNotification();
158 application.Render();
159 application.Render();
160 application.SendNotification();
162 PixelBuffer* buffer = image.GetBuffer();
163 unsigned int bufferSize = image.GetBufferSize();
164 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
166 DALI_TEST_CHECK( image.GetWidth() == 1 && // 1 pixel wide
167 buffer != NULL && // valid buffer
168 bufferSize == pixelSize); // r component is 255
172 int UtcDaliBufferImageGetBufferStride(void)
174 TestApplication application;
176 tet_infoline("UtcDaliBufferImageGetBufferStride");
178 BufferImage image = BufferImage::WHITE(); // creates a 1x1 RGBA white pixel
179 application.SendNotification();
180 application.Render();
181 application.Render();
182 application.SendNotification();
184 unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
185 unsigned int bufferStride = image.GetBufferStride();
186 DALI_TEST_CHECK( bufferStride == pixelSize );
187 DALI_TEST_CHECK( !image.IsDataExternal() );
189 PixelBuffer* buffer = new PixelBuffer[20 * 16];
190 image = BufferImage::New(buffer, 16, 16, Pixel::A8, 20);
191 application.SendNotification();
192 application.Render(16);
193 application.Render(16);
194 application.SendNotification();
196 bufferStride = image.GetBufferStride();
198 DALI_TEST_CHECK( bufferStride == 20);
199 DALI_TEST_CHECK( image.IsDataExternal() );
205 int UtcDaliBufferImageGetPixelFormat(void)
207 TestApplication application;
209 tet_infoline("UtcDaliBufferImageGetPixelFormat");
211 // Set pixel format to a non-default
212 BufferImage image = BufferImage::New( 16, 16, Pixel::A8 );
213 application.SendNotification();
214 application.Render(16);
215 application.Render(16);
216 application.SendNotification();
218 DALI_TEST_CHECK( image.GetPixelFormat() == Pixel::A8 );
223 int UtcDaliBufferImageIsDataExternal(void)
225 TestApplication application;
227 tet_infoline("UtcDaliBufferImageIsDataExternal - BufferImage::IsDataExternal()");
229 PixelBuffer* buffer = new PixelBuffer[16 * 16];
230 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
231 application.SendNotification();
232 application.Render();
233 application.Render();
234 application.SendNotification();
236 DALI_TEST_CHECK( image.IsDataExternal() );
240 int UtcDaliBufferImageUpdate01(void)
242 TestApplication application;
244 tet_infoline("UtcDaliBufferImageUpdate01 - single empty rect");
246 PixelBuffer* buffer = new PixelBuffer[16 * 16];
248 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
249 Actor actor = CreateRenderableActor( image );
250 Stage::GetCurrent().Add(actor);
251 actor.SetVisible(true);
253 std::vector<GLuint> ids;
257 application.GetGlAbstraction().SetNextTextureIds(ids);
259 // Allow actor to be staged and rendered
260 application.SendNotification();
261 application.Render(0);
262 application.Render(16);
263 application.SendNotification();
264 application.Render(16);
265 application.SendNotification();
267 DALI_TEST_CHECK( image.IsDataExternal() );
268 application.GetGlAbstraction().EnableTextureCallTrace(true);
270 image.Update();//(RectArea()); // notify Core that the image has been updated
271 application.SendNotification();
272 application.Render(16);
273 application.Render(16);
274 application.SendNotification();
275 application.Render(16);
276 application.SendNotification();
278 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
280 std::stringstream out;
281 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 16u <<", "<< 16u;
282 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexImage2D", out.str().c_str() ), true, TEST_LOCATION);
286 int UtcDaliBufferImageUpdate02(void)
288 TestApplication application;
290 tet_infoline("UtcDaliBufferImageUpdate02 - Multiple rects");
292 PixelBuffer* buffer = new PixelBuffer[16 * 16];
293 BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
294 Actor actor = CreateRenderableActor( image );
295 Stage::GetCurrent().Add(actor);
296 actor.SetVisible(true);
298 application.SendNotification();
299 application.Render(0);
300 application.Render(16);
301 application.SendNotification();
302 application.Render(16);
303 application.SendNotification();
305 DALI_TEST_CHECK( image.IsDataExternal() );
306 application.GetGlAbstraction().EnableTextureCallTrace(true);
308 // Check that multiple updates in a frame will be properly uploaded
309 image.Update(RectArea(9,9,5,5));
310 image.Update(RectArea(2,2,4,4));
311 image.Update(RectArea(3,3,1,6));
313 application.SendNotification();
314 application.Render(16);
315 application.Render(16);
316 application.SendNotification();
317 application.Render(16);
318 application.SendNotification();
320 const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
323 std::stringstream out;
324 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 9u << ", " << 9u << ", " << 5u <<", "<< 5u;
325 DALI_TEST_EQUALS( callStack.TestMethodAndParams(0, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
329 std::stringstream out;
330 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 2u << ", " << 2u << ", " << 4u <<", "<< 4u;
331 DALI_TEST_EQUALS( callStack.TestMethodAndParams(1, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);
335 std::stringstream out;
336 out << GL_TEXTURE_2D <<", "<< 0u << ", " << 3u << ", " << 3u << ", " << 1u <<", "<< 6u;
337 DALI_TEST_EQUALS( callStack.TestMethodAndParams(2, "TexSubImage2D", out.str().c_str()), true, TEST_LOCATION);