[Tizen] Add Integration API to Create public event type
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
1 /*
2  * Copyright (c) 2020 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 <dali-test-suite-utils.h>
19 #include <dali/devel-api/images/pixel-data-devel.h>
20 #include <dali/public-api/dali-core.h>
21 #include <test-native-image.h>
22
23 using namespace Dali;
24
25 #include <mesh-builder.h>
26
27 void texture_set_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void texture_set_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 int UtcDaliTextureNew01(void)
38 {
39   TestApplication application;
40
41   unsigned int width(64);
42   unsigned int height(64);
43   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
44
45   DALI_TEST_CHECK(texture);
46   END_TEST;
47 }
48
49 int UtcDaliTextureNew02(void)
50 {
51   TestApplication application;
52   Texture         texture;
53   DALI_TEST_CHECK(!texture);
54   END_TEST;
55 }
56
57 int UtcDaliTextureNew03(void)
58 {
59   TestApplication application;
60
61   // Create a native image source.
62   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
63
64   // Create a texture from the native image source.
65   Texture nativeTexture = Texture::New(*testNativeImage);
66
67   // Check the texture was created OK.
68   DALI_TEST_CHECK(nativeTexture);
69
70   END_TEST;
71 }
72
73 int UtcDaliTextureCopyConstructor(void)
74 {
75   TestApplication application;
76
77   unsigned int width(64);
78   unsigned int height(64);
79   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
80
81   Texture textureCopy(texture);
82
83   DALI_TEST_CHECK(textureCopy);
84
85   END_TEST;
86 }
87
88 int UtcDaliTextureAssignmentOperator(void)
89 {
90   TestApplication application;
91   unsigned int    width(64);
92   unsigned int    height(64);
93   Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
94
95   Texture texture2;
96   DALI_TEST_CHECK(!texture2);
97
98   texture2 = texture;
99   DALI_TEST_CHECK(texture2);
100
101   END_TEST;
102 }
103
104 int UtcDaliTextureMoveConstructor(void)
105 {
106   TestApplication application;
107
108   uint32_t width   = 64;
109   uint32_t height  = 64;
110   Texture  texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
111   DALI_TEST_CHECK(texture);
112   DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
113   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
114   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
115
116   Texture move = std::move(texture);
117   DALI_TEST_CHECK(move);
118   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
119   DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
120   DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
121   DALI_TEST_CHECK(!texture);
122
123   END_TEST;
124 }
125
126 int UtcDaliTextureMoveAssignment(void)
127 {
128   TestApplication application;
129
130   uint32_t width   = 64;
131   uint32_t height  = 64;
132   Texture  texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
133   DALI_TEST_CHECK(texture);
134   DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
135   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
136   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
137
138   Texture move;
139   move = std::move(texture);
140   DALI_TEST_CHECK(move);
141   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142   DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
143   DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
144   DALI_TEST_CHECK(!texture);
145
146   END_TEST;
147 }
148
149 int UtcDaliTextureDownCast01(void)
150 {
151   TestApplication application;
152   unsigned int    width(64);
153   unsigned int    height(64);
154   Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
155
156   BaseHandle handle(texture);
157   Texture    texture2 = Texture::DownCast(handle);
158   DALI_TEST_CHECK(texture2);
159
160   END_TEST;
161 }
162
163 int UtcDaliTextureDownCast02(void)
164 {
165   TestApplication application;
166
167   Handle  handle  = Handle::New(); // Create a custom object
168   Texture texture = Texture::DownCast(handle);
169   DALI_TEST_CHECK(!texture);
170   END_TEST;
171 }
172
173 int UtcDaliTextureUpload01(void)
174 {
175   TestApplication application;
176
177   //Create the texture
178   unsigned int width(64);
179   unsigned int height(64);
180   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
181
182   application.GetGlAbstraction().EnableTextureCallTrace(true);
183
184   application.SendNotification();
185   application.Render();
186
187   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
188
189   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
190   {
191     std::stringstream out;
192     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
193     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
194   }
195
196   //Upload data to the texture
197   callStack.Reset();
198
199   unsigned int   bufferSize(width * height * 4);
200   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
201   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
202   texture.Upload(pixelData);
203   application.SendNotification();
204   application.Render();
205
206   //TexImage2D should be called to upload the data
207   {
208     std::stringstream out;
209     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
210     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
211   }
212
213   //Upload part of the texture
214   callStack.Reset();
215   bufferSize                  = width * height * 2;
216   buffer                      = reinterpret_cast<unsigned char*>(malloc(bufferSize));
217   PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
218   texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
219   application.SendNotification();
220   application.Render();
221
222   //TexSubImage2D should be called to upload the data
223   {
224     std::stringstream out;
225     out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
226     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
227   }
228
229   END_TEST;
230 }
231
232 int UtcDaliTextureUpload02(void)
233 {
234   TestApplication application;
235
236   //Create the texture
237   unsigned int width(64);
238   unsigned int height(64);
239   Texture      texture = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
240
241   application.GetGlAbstraction().EnableTextureCallTrace(true);
242
243   application.SendNotification();
244   application.Render();
245
246   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
247
248   //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
249   for(unsigned int i(0); i < 6; ++i)
250   {
251     std::stringstream out;
252     out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
253     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
254   }
255
256   unsigned int   bufferSize(width * height * 4);
257   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
258   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
259
260   //Upload data to the POSITIVE_X face of the texture
261   {
262     callStack.Reset();
263
264     texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
265     application.SendNotification();
266     application.Render();
267
268     //TexImage2D should be called to upload the data to the POSITIVE_X face
269     {
270       std::stringstream out;
271       out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
272       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
273     }
274   }
275
276   //Upload data to the NEGATIVE_X face of the texture
277   {
278     callStack.Reset();
279
280     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
281     application.SendNotification();
282     application.Render();
283
284     //TexImage2D should be called to upload the data to the NEGATIVE_X face
285     {
286       std::stringstream out;
287       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
288       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
289     }
290   }
291
292   //Upload data to the POSITIVE_Y face of the texture
293   {
294     callStack.Reset();
295     texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
296     application.SendNotification();
297     application.Render();
298
299     //TexImage2D should be called to upload the data to the POSITIVE_Y face
300     {
301       std::stringstream out;
302       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
303       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
304     }
305   }
306
307   //Upload data to the NEGATIVE_Y face of the texture
308   {
309     callStack.Reset();
310     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
311     application.SendNotification();
312     application.Render();
313
314     //TexImage2D should be called to upload the data to the NEGATIVE_Y face
315     {
316       std::stringstream out;
317       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
318       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
319     }
320   }
321
322   //Upload data to the POSITIVE_Z face of the texture
323   {
324     callStack.Reset();
325     texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
326     application.SendNotification();
327     application.Render();
328
329     //TexImage2D should be called to upload the data to the POSITIVE_Z face
330     {
331       std::stringstream out;
332       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
333       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
334     }
335   }
336
337   //Upload data to the NEGATIVE_Z face of the texture
338   {
339     callStack.Reset();
340     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
341     application.SendNotification();
342     application.Render();
343
344     //TexImage2D should be called to upload the data to the NEGATIVE_Z face
345     {
346       std::stringstream out;
347       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
348       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
349     }
350   }
351
352   END_TEST;
353 }
354
355 int UtcDaliTextureUpload03(void)
356 {
357   TestApplication application;
358
359   //Create the texture
360   unsigned int width(64);
361   unsigned int height(64);
362   unsigned int widthMipmap1(32);
363   unsigned int heightMipmap1(32);
364
365   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
366
367   application.GetGlAbstraction().EnableTextureCallTrace(true);
368
369   application.SendNotification();
370   application.Render();
371
372   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
373
374   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
375   {
376     std::stringstream out;
377     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
378     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
379   }
380
381   //Upload data to the texture mipmap 0 and mipmap 1
382   callStack.Reset();
383
384   unsigned int   bufferSize(width * height * 4);
385   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
386   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
387   texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
388
389   bufferSize                 = widthMipmap1 * heightMipmap1 * 4;
390   buffer                     = reinterpret_cast<unsigned char*>(malloc(bufferSize));
391   PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
392   texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
393   application.SendNotification();
394   application.Render();
395
396   //TexImage2D should be called to upload the data to mipmaps 0 and 1
397   {
398     std::stringstream out;
399     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
400     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
401   }
402   {
403     std::stringstream out;
404     out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
405     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
406   }
407
408   END_TEST;
409 }
410
411 int UtcDaliTextureUpload04(void)
412 {
413   TestApplication application;
414
415   //Create the texture
416   unsigned int width(64);
417   unsigned int height(64);
418   unsigned int widthMipmap1(32);
419   unsigned int heightMipmap1(32);
420
421   Texture texture = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
422
423   application.GetGlAbstraction().EnableTextureCallTrace(true);
424   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
425
426   //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
427   unsigned int   bufferSize(width * height * 4);
428   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
429   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
430   texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
431
432   bufferSize                 = widthMipmap1 * heightMipmap1 * 4;
433   buffer                     = reinterpret_cast<unsigned char*>(malloc(bufferSize));
434   PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
435   texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
436   application.SendNotification();
437   application.Render();
438
439   //TexImage2D should be called to upload the data to mipmaps 0 and 1
440   {
441     std::stringstream out;
442     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
443     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
444   }
445   {
446     std::stringstream out;
447     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
448     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
449   }
450
451   END_TEST;
452 }
453
454 int UtcDaliTextureUpload05(void)
455 {
456   Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
457     {
458       Pixel::COMPRESSED_R11_EAC,
459       Pixel::COMPRESSED_SIGNED_R11_EAC,
460       Pixel::COMPRESSED_RG11_EAC,
461       Pixel::COMPRESSED_SIGNED_RG11_EAC,
462       Pixel::COMPRESSED_RGB8_ETC2,
463       Pixel::COMPRESSED_SRGB8_ETC2,
464       Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
465       Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
466       Pixel::COMPRESSED_RGBA8_ETC2_EAC,
467       Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
468       Pixel::COMPRESSED_RGB8_ETC1,
469       Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
470       Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
471       Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
472       Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
473       Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
474       Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
475       Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
476       Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
477       Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
478       Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
479       Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
480       Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
481       Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
482       Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
483       Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
484       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
485       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
486       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
487       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
488       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
489       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
490       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
491       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
492       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
493       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
494       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
495       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
496       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
497       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
498     };
499   const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
500
501   for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
502   {
503     TestApplication application;
504
505     //Create a texture with a compressed format
506     unsigned int width(64);
507     unsigned int height(64);
508     Texture      texture = Texture::New(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
509
510     application.GetGlAbstraction().EnableTextureCallTrace(true);
511
512     application.SendNotification();
513     application.Render();
514
515     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
516
517     //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
518     {
519       std::stringstream out;
520       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
521       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
522     }
523
524     //Upload data to the texture
525     callStack.Reset();
526
527     unsigned int   bufferSize(width * height * 4);
528     unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
529     PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
530     texture.Upload(pixelData);
531     application.SendNotification();
532     application.Render();
533
534     //CompressedTexImage2D should be called to upload the data
535     {
536       std::stringstream out;
537       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
538       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
539     }
540
541     //Upload part of the texture
542     callStack.Reset();
543     bufferSize                  = width * height * 2;
544     buffer                      = reinterpret_cast<unsigned char*>(malloc(bufferSize));
545     PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
546     texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
547     application.SendNotification();
548     application.Render();
549
550     //CompressedTexSubImage2D should be called to upload the data
551     {
552       std::stringstream out;
553       out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
554       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
555     }
556
557     application.GetGlAbstraction().ResetTextureCallStack();
558   }
559
560   END_TEST;
561 }
562
563 int UtcDaliTextureUpload06(void)
564 {
565   TestApplication application;
566
567   //Create the texture
568   unsigned int width(64);
569   unsigned int height(64);
570   tet_infoline("Creating a Texure with an alpha channel");
571   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
572
573   application.GetGlAbstraction().EnableTextureCallTrace(true);
574
575   application.SendNotification();
576   application.Render();
577
578   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
579
580   tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
581   {
582     std::stringstream out;
583     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
584     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
585   }
586
587   tet_infoline("Upload data to the texture");
588   callStack.Reset();
589
590   tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
591   unsigned int   bufferSize(width * height * 3);
592   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
593   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
594   texture.Upload(pixelData);
595   application.SendNotification();
596   application.Render();
597
598   tet_infoline("TexImage2D should be called to upload the data");
599   {
600     std::stringstream out;
601     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
602     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
603   }
604
605   END_TEST;
606 }
607
608 int UtcDaliTextureUpload07(void)
609 {
610   Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
611     {
612       Pixel::RGB16F,
613       Pixel::RGB32F,
614     };
615   const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
616
617   for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
618   {
619     TestApplication application;
620
621     //Create the texture
622     unsigned int width(64);
623     unsigned int height(64);
624     tet_infoline("Creating a floating point texture");
625     Texture texture = Texture::New(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
626
627     application.GetGlAbstraction().EnableTextureCallTrace(true);
628
629     application.SendNotification();
630     application.Render();
631
632     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
633
634     tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
635     {
636       std::stringstream out;
637       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
638       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
639     }
640
641     tet_infoline("Upload data to the texture");
642     callStack.Reset();
643
644     tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
645     unsigned int   bufferSize(width * height * 3);
646     unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
647     PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
648     texture.Upload(pixelData);
649     application.SendNotification();
650     application.Render();
651
652     tet_infoline("TexImage2D should be called to upload the data");
653     {
654       std::stringstream out;
655       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
656       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
657     }
658   }
659
660   END_TEST;
661 }
662
663 int UtcDaliTextureUploadSmallerThanSize(void)
664 {
665   TestApplication application;
666
667   //Create the texture
668   unsigned int width(64);
669   unsigned int height(64);
670   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
671
672   application.GetGlAbstraction().EnableTextureCallTrace(true);
673
674   application.SendNotification();
675   application.Render();
676
677   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
678
679   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
680   {
681     std::stringstream out;
682     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
683     std::string params;
684     DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
685     DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
686   }
687
688   //Upload data to the texture
689   callStack.Reset();
690
691   unsigned int   bufferSize(width * height * 4);
692   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
693   PixelData      pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
694   texture.Upload(pixelData);
695   application.SendNotification();
696   application.Render();
697
698   //TexImage2D should be called to upload the data
699   {
700     std::stringstream out;
701     out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
702     std::string params;
703     DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
704     DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
705   }
706
707   END_TEST;
708 }
709
710 int UtcDaliTextureGenerateMipmaps(void)
711 {
712   TestApplication application;
713   unsigned int    width(64);
714   unsigned int    height(64);
715
716   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
717   texture.GenerateMipmaps();
718
719   Texture textureCubemap = Texture::New(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
720   textureCubemap.GenerateMipmaps();
721
722   application.GetGlAbstraction().EnableTextureCallTrace(true);
723   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
724   application.SendNotification();
725   application.Render();
726
727   {
728     std::stringstream out;
729     out << GL_TEXTURE_2D;
730     DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
731   }
732   {
733     std::stringstream out;
734     out << GL_TEXTURE_CUBE_MAP;
735     DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
736   }
737
738   END_TEST;
739 }
740
741 int UtcDaliTextureGetWidth(void)
742 {
743   TestApplication application;
744   unsigned int    width(64);
745   unsigned int    height(64);
746
747   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
748   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
749   END_TEST;
750 }
751
752 int UtcDaliTextureGetHeight(void)
753 {
754   TestApplication application;
755   unsigned int    width(64);
756   unsigned int    height(64);
757
758   Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
759   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
760
761   END_TEST;
762 }
763
764 int UtcDaliTextureContextLoss(void)
765 {
766   tet_infoline("UtcDaliTextureContextLoss\n");
767   TestApplication application;
768
769   //Create the texture
770   unsigned int width(64);
771   unsigned int height(64);
772   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
773   DALI_TEST_CHECK(texture);
774
775   application.SendNotification();
776   application.Render(16);
777
778   // Lose & regain context (in render 'thread')
779   application.ResetContext();
780   DALI_TEST_CHECK(texture);
781
782   END_TEST;
783 }
784
785 int UtcDaliNativeImageTexture01(void)
786 {
787   TestApplication application;
788   tet_infoline("UtcDaliNativeImageTexture01");
789
790   TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
791   {
792     Texture texture = Texture::New(*(imageInterface.Get()));
793     Actor   actor   = CreateRenderableActor(texture, "", "");
794     application.GetScene().Add(actor);
795
796     DALI_TEST_CHECK(texture);
797
798     application.SendNotification();
799     application.Render(16);
800
801     DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
802     DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
803     DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
804
805     UnparentAndReset(actor);
806
807     application.SendNotification();
808     application.Render(16);
809   }
810   application.SendNotification();
811   application.Render(16);
812
813   DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
814   DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
815
816   END_TEST;
817 }
818
819 int UtcDaliNativeImageTexture02(void)
820 {
821   TestApplication application;
822   tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
823
824   TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
825   imageInterface->mTargetTextureError   = 1u;
826   {
827     Texture texture = Texture::New(*(imageInterface.Get()));
828     Actor   actor   = CreateRenderableActor(texture, "", "");
829     application.GetScene().Add(actor);
830
831     DALI_TEST_CHECK(texture);
832
833     application.SendNotification();
834     application.Render(16);
835
836     // Expect 2 attempts to create the texture - once when adding the texture
837     // to the scene-graph, and again since that failed, during the Bind.
838     DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
839     DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
840
841     UnparentAndReset(actor);
842
843     application.SendNotification();
844     application.Render(16);
845   }
846   application.SendNotification();
847   application.Render(16);
848
849   // Expect that there are no further calls to create/destroy resource
850   DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
851   DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
852
853   END_TEST;
854 }
855
856 int UtcDaliTextureGenerateMipmapsNegative(void)
857 {
858   TestApplication application;
859   Dali::Texture   instance;
860   try
861   {
862     instance.GenerateMipmaps();
863     DALI_TEST_CHECK(false); // Should not get here
864   }
865   catch(...)
866   {
867     DALI_TEST_CHECK(true); // We expect an assert
868   }
869   END_TEST;
870 }
871
872 int UtcDaliTextureUploadNegative01(void)
873 {
874   TestApplication application;
875   Dali::Texture   instance;
876   try
877   {
878     Dali::PixelData arg1;
879     instance.Upload(arg1);
880     DALI_TEST_CHECK(false); // Should not get here
881   }
882   catch(...)
883   {
884     DALI_TEST_CHECK(true); // We expect an assert
885   }
886   END_TEST;
887 }
888
889 int UtcDaliTextureUploadNegative02(void)
890 {
891   TestApplication application;
892   Dali::Texture   instance;
893   try
894   {
895     Dali::PixelData arg1;
896     unsigned int    arg2(0u);
897     unsigned int    arg3(0u);
898     unsigned int    arg4(0u);
899     unsigned int    arg5(0u);
900     unsigned int    arg6(0u);
901     unsigned int    arg7(0u);
902     instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
903     DALI_TEST_CHECK(false); // Should not get here
904   }
905   catch(...)
906   {
907     DALI_TEST_CHECK(true); // We expect an assert
908   }
909   END_TEST;
910 }
911
912 int UtcDaliTextureGetWidthNegative(void)
913 {
914   TestApplication application;
915   Dali::Texture   instance;
916   try
917   {
918     instance.GetWidth();
919     DALI_TEST_CHECK(false); // Should not get here
920   }
921   catch(...)
922   {
923     DALI_TEST_CHECK(true); // We expect an assert
924   }
925   END_TEST;
926 }
927
928 int UtcDaliTextureGetHeightNegative(void)
929 {
930   TestApplication application;
931   Dali::Texture   instance;
932   try
933   {
934     instance.GetHeight();
935     DALI_TEST_CHECK(false); // Should not get here
936   }
937   catch(...)
938   {
939     DALI_TEST_CHECK(true); // We expect an assert
940   }
941   END_TEST;
942 }