[Tizen] Add screen and client rotation itself function
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-BufferImage.cpp
1 /*
2  * Copyright (c) 2016 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 <algorithm>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24
25 using std::max;
26 using namespace Dali;
27
28 void utc_dali_buffer_image_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_buffer_image_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 int UtcDaliBufferImageNew01(void)
39 {
40   TestApplication application;
41
42   tet_infoline("UtcDaliBufferImageNew01 - BufferImage::New(unsigned int, unsigned int, Pixel::Format)");
43
44   // invoke default handle constructor
45   BufferImage image;
46
47   // initialise handle
48   image = BufferImage::New(16, 16);
49   application.SendNotification();
50   application.Render(16);
51   application.Render(16);
52   application.SendNotification();
53
54   DALI_TEST_CHECK( image.GetWidth() == 16);
55   END_TEST;
56 }
57
58 int UtcDaliBufferImageNew02(void)
59 {
60   TestApplication application;
61
62   tet_infoline("UtcDaliBufferImageNew02 - BufferImage::New(PixelBuffer*, unsigned int, unsigned int, Pixel::Format, unsigned int)");
63
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();
70
71   DALI_TEST_CHECK( image.GetWidth() == 16);
72
73   delete [] buffer;
74   END_TEST;
75 }
76
77 int UtcDaliBufferImageDownCast(void)
78 {
79   TestApplication application;
80   tet_infoline("Testing Dali::BufferImage::DownCast()");
81
82   Image image = BufferImage::New(1, 1, Dali::Pixel::BGRA8888);
83   BufferImage bufferImage = BufferImage::DownCast( image );
84
85   DALI_TEST_CHECK(bufferImage);
86   END_TEST;
87 }
88
89 int UtcDaliBufferImageDownCast2(void)
90 {
91   TestApplication application;
92   tet_infoline("Testing Dali::BufferImage::DownCast()");
93
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();
100
101   BufferImage bufferImage = BufferImage::DownCast( image );
102   DALI_TEST_CHECK(!bufferImage);
103
104   Actor unInitialzedActor;
105   bufferImage = BufferImage::DownCast( unInitialzedActor );
106   DALI_TEST_CHECK(!bufferImage);
107   END_TEST;
108 }
109
110 int UtcDaliBufferImageWHITE(void)
111 {
112   TestApplication application;
113
114   tet_infoline("UtcDaliBufferImageWHITE - BufferImage::WHITE()");
115
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();
121
122   PixelBuffer* buffer = image.GetBuffer();
123
124   DALI_TEST_CHECK( image.GetWidth() == 1 &&               // 1 pixel wide
125                    buffer != NULL &&                      // valid buffer
126                    *buffer == 0xff);                       // r component is 255
127   END_TEST;
128 }
129
130 int UtcDaliBufferImageGetBuffer(void)
131 {
132   TestApplication application;
133
134   tet_infoline("UtcDaliBufferImageGetBuffer");
135
136   BufferImage image = BufferImage::WHITE();               // creates a 1x1 RGBA white pixel
137
138   PixelBuffer* buffer = image.GetBuffer();
139   application.SendNotification();
140   application.Render();
141   application.Render();
142   application.SendNotification();
143
144   DALI_TEST_CHECK( image.GetWidth() == 1 &&               // 1 pixel wide
145                    buffer != NULL &&                      // valid buffer
146                    *((unsigned int*)buffer) == 0xffffffff); // all component are 255
147   END_TEST;
148 }
149
150 int UtcDaliBufferImageGetBufferSize(void)
151 {
152   TestApplication application;
153
154   tet_infoline("UtcDaliBufferImageGetBufferSize");
155
156   BufferImage image = BufferImage::WHITE();               // creates a 1x1 RGBA white pixel
157   application.SendNotification();
158   application.Render();
159   application.Render();
160   application.SendNotification();
161
162   PixelBuffer* buffer = image.GetBuffer();
163   unsigned int bufferSize = image.GetBufferSize();
164   unsigned int pixelSize = Pixel::GetBytesPerPixel(image.GetPixelFormat());
165
166   DALI_TEST_CHECK( image.GetWidth() == 1 &&               // 1 pixel wide
167                    buffer != NULL &&                      // valid buffer
168                    bufferSize == pixelSize);              // r component is 255
169   END_TEST;
170 }
171
172 int UtcDaliBufferImageGetBufferStride(void)
173 {
174   TestApplication application;
175
176   tet_infoline("UtcDaliBufferImageGetBufferStride");
177
178   BufferImage image = BufferImage::WHITE();               // creates a 1x1 RGBA white pixel
179   application.SendNotification();
180   application.Render();
181   application.Render();
182   application.SendNotification();
183
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() );
188
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();
195
196   bufferStride = image.GetBufferStride();
197
198   DALI_TEST_CHECK( bufferStride == 20);
199   DALI_TEST_CHECK( image.IsDataExternal() );
200
201   delete [] buffer;
202   END_TEST;
203 }
204
205 int UtcDaliBufferImageGetPixelFormat(void)
206 {
207   TestApplication application;
208
209   tet_infoline("UtcDaliBufferImageGetPixelFormat");
210
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();
217
218   DALI_TEST_CHECK( image.GetPixelFormat() == Pixel::A8 );
219   END_TEST;
220 }
221
222
223 int UtcDaliBufferImageIsDataExternal(void)
224 {
225   TestApplication application;
226
227   tet_infoline("UtcDaliBufferImageIsDataExternal - BufferImage::IsDataExternal()");
228
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();
235
236   DALI_TEST_CHECK( image.IsDataExternal() );
237   END_TEST;
238 }
239
240 int UtcDaliBufferImageUpdate01(void)
241 {
242   TestApplication application;
243
244   tet_infoline("UtcDaliBufferImageUpdate01 - single empty rect");
245
246   PixelBuffer* buffer = new PixelBuffer[16 * 16];
247
248   BufferImage image = BufferImage::New(buffer, 16, 16, Pixel::A8);
249   Actor actor = CreateRenderableActor( image );
250   Stage::GetCurrent().Add(actor);
251   actor.SetVisible(true);
252
253   std::vector<GLuint> ids;
254   ids.push_back(200);
255   ids.push_back(201);
256   ids.push_back(202);
257   application.GetGlAbstraction().SetNextTextureIds(ids);
258
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();
266
267   DALI_TEST_CHECK( image.IsDataExternal() );
268   application.GetGlAbstraction().EnableTextureCallTrace(true);
269
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();
277
278   const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
279
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);
283   END_TEST;
284 }
285
286 int UtcDaliBufferImageUpdate02(void)
287 {
288   TestApplication application;
289
290   tet_infoline("UtcDaliBufferImageUpdate02 - Multiple rects");
291
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);
297
298   application.SendNotification();
299   application.Render(0);
300   application.Render(16);
301   application.SendNotification();
302   application.Render(16);
303   application.SendNotification();
304
305   DALI_TEST_CHECK( image.IsDataExternal() );
306   application.GetGlAbstraction().EnableTextureCallTrace(true);
307
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));
312
313   application.SendNotification();
314   application.Render(16);
315   application.Render(16);
316   application.SendNotification();
317   application.Render(16);
318   application.SendNotification();
319
320   const TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
321
322   {
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);
326   }
327
328   {
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);
332   }
333
334   {
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);
338   }
339
340   END_TEST;
341 }
342