b170b6a7d3b653d8c168da263897c96bc7edd9ac
[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/public-api/dali-core.h>
19 #include <dali/devel-api/images/pixel-data-devel.h>
20 #include <dali-test-suite-utils.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
230   END_TEST;
231 }
232
233 int UtcDaliTextureUpload02(void)
234 {
235   TestApplication application;
236
237   //Create the texture
238   unsigned int width(64);
239   unsigned int height(64);
240   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
241
242   application.GetGlAbstraction().EnableTextureCallTrace(true);
243
244   application.SendNotification();
245   application.Render();
246
247   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
248
249   //TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map
250   for( unsigned int i(0); i<6; ++i )
251   {
252     std::stringstream out;
253     out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i <<", "<< 0u << ", " << width <<", "<< height;
254     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
255   }
256
257   unsigned int bufferSize( width * height * 4 );
258   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
259   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
260
261   //Upload data to the POSITIVE_X face of the texture
262   {
263     callStack.Reset();
264
265     texture.Upload( pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height );
266     application.SendNotification();
267     application.Render();
268
269     //TexImage2D should be called to upload the data to the POSITIVE_X face
270     {
271       std::stringstream out;
272       out << GL_TEXTURE_CUBE_MAP_POSITIVE_X <<", "<< 0u << ", " << width <<", "<< height;
273       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
274     }
275   }
276
277   //Upload data to the NEGATIVE_X face of the texture
278   {
279     callStack.Reset();
280
281     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
282     application.SendNotification();
283     application.Render();
284
285     //TexImage2D should be called to upload the data to the NEGATIVE_X face
286     {
287       std::stringstream out;
288       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
289       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
290     }
291   }
292
293   //Upload data to the POSITIVE_Y face of the texture
294   {
295     callStack.Reset();
296     texture.Upload( pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height );
297     application.SendNotification();
298     application.Render();
299
300     //TexImage2D should be called to upload the data to the POSITIVE_Y face
301     {
302       std::stringstream out;
303       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
304       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
305     }
306   }
307
308   //Upload data to the NEGATIVE_Y face of the texture
309   {
310     callStack.Reset();
311     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height );
312     application.SendNotification();
313     application.Render();
314
315     //TexImage2D should be called to upload the data to the NEGATIVE_Y face
316     {
317       std::stringstream out;
318       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y <<", "<< 0u << ", " << width <<", "<< height;
319       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
320     }
321   }
322
323   //Upload data to the POSITIVE_Z face of the texture
324   {
325     callStack.Reset();
326     texture.Upload( pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height );
327     application.SendNotification();
328     application.Render();
329
330     //TexImage2D should be called to upload the data to the POSITIVE_Z face
331     {
332       std::stringstream out;
333       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
334       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
335     }
336   }
337
338   //Upload data to the NEGATIVE_Z face of the texture
339   {
340     callStack.Reset();
341     texture.Upload( pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height );
342     application.SendNotification();
343     application.Render();
344
345     //TexImage2D should be called to upload the data to the NEGATIVE_Z face
346     {
347       std::stringstream out;
348       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z <<", "<< 0u << ", " << width <<", "<< height;
349       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
350     }
351   }
352
353   END_TEST;
354 }
355
356 int UtcDaliTextureUpload03(void)
357 {
358   TestApplication application;
359
360   //Create the texture
361   unsigned int width(64);
362   unsigned int height(64);
363   unsigned int widthMipmap1(32);
364   unsigned int heightMipmap1(32);
365
366   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
367
368   application.GetGlAbstraction().EnableTextureCallTrace(true);
369
370   application.SendNotification();
371   application.Render();
372
373   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
374
375   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
376   {
377     std::stringstream out;
378     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
379     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
380   }
381
382   //Upload data to the texture mipmap 0 and mipmap 1
383   callStack.Reset();
384
385   unsigned int bufferSize( width * height * 4 );
386   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc(  bufferSize ) );
387   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
388   texture.Upload( pixelData, 0u, 0u, 0u, 0u, width, height );
389
390   bufferSize = widthMipmap1 * heightMipmap1 * 4;
391   buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
392   PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
393   texture.Upload( pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
394   application.SendNotification();
395   application.Render();
396
397   //TexImage2D should be called to upload the data to mipmaps 0 and 1
398   {
399     std::stringstream out;
400     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
401     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
402   }
403   {
404     std::stringstream out;
405     out << GL_TEXTURE_2D <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
406     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
407   }
408
409   END_TEST;
410 }
411
412 int UtcDaliTextureUpload04(void)
413 {
414   TestApplication application;
415
416   //Create the texture
417   unsigned int width(64);
418   unsigned int height(64);
419   unsigned int widthMipmap1(32);
420   unsigned int heightMipmap1(32);
421
422   Texture texture = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
423
424   application.GetGlAbstraction().EnableTextureCallTrace(true);
425   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
426
427   //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
428   unsigned int bufferSize( width * height * 4 );
429   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
430   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
431   texture.Upload( pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height );
432
433   bufferSize = widthMipmap1 * heightMipmap1 * 4;
434   buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
435   PixelData pixelDataMipmap1 = PixelData::New( buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE );
436   texture.Upload( pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1 );
437   application.SendNotification();
438   application.Render();
439
440   //TexImage2D should be called to upload the data to mipmaps 0 and 1
441   {
442     std::stringstream out;
443     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 0u << ", " << width <<", "<< height;
444     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
445   }
446   {
447     std::stringstream out;
448     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X <<", "<< 1u << ", " << widthMipmap1 <<", "<< heightMipmap1;
449     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
450   }
451
452   END_TEST;
453 }
454
455 int UtcDaliTextureUpload05(void)
456 {
457   Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
458   {
459     Pixel::COMPRESSED_R11_EAC,
460     Pixel::COMPRESSED_SIGNED_R11_EAC,
461     Pixel::COMPRESSED_RG11_EAC,
462     Pixel::COMPRESSED_SIGNED_RG11_EAC,
463     Pixel::COMPRESSED_RGB8_ETC2,
464     Pixel::COMPRESSED_SRGB8_ETC2,
465     Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
466     Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
467     Pixel::COMPRESSED_RGBA8_ETC2_EAC,
468     Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
469     Pixel::COMPRESSED_RGB8_ETC1,
470     Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
471     Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
472     Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
473     Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
474     Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
475     Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
476     Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
477     Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
478     Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
479     Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
480     Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
481     Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
482     Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
483     Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
484     Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
485     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
486     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
487     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
488     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
489     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
490     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
491     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
492     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
493     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
494     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
495     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
496     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
497     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
498     Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
499   };
500   const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
501
502   for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
503   {
504     TestApplication application;
505
506     //Create a texture with a compressed format
507     unsigned int width(64);
508     unsigned int height(64);
509     Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
510
511     application.GetGlAbstraction().EnableTextureCallTrace(true);
512
513     application.SendNotification();
514     application.Render();
515
516     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
517
518     //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
519     {
520       std::stringstream out;
521       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
522       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
523     }
524
525     //Upload data to the texture
526     callStack.Reset();
527
528     unsigned int bufferSize( width * height * 4 );
529     unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
530     PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
531     texture.Upload( pixelData );
532     application.SendNotification();
533     application.Render();
534
535     //CompressedTexImage2D should be called to upload the data
536     {
537       std::stringstream out;
538       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
539       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
540     }
541
542     //Upload part of the texture
543     callStack.Reset();
544     bufferSize =  width * height * 2;
545     buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
546     PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
547     texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
548     application.SendNotification();
549     application.Render();
550
551     //CompressedTexSubImage2D should be called to upload the data
552     {
553       std::stringstream out;
554       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
555       DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
556     }
557
558     application.GetGlAbstraction().ResetTextureCallStack();
559   }
560
561   END_TEST;
562 }
563
564 int UtcDaliTextureUpload06(void)
565 {
566   TestApplication application;
567
568   //Create the texture
569   unsigned int width(64);
570   unsigned int height(64);
571   tet_infoline( "Creating a Texure with an alpha channel" );
572   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
573
574   application.GetGlAbstraction().EnableTextureCallTrace(true);
575
576   application.SendNotification();
577   application.Render();
578
579   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
580
581   tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
582   {
583     std::stringstream out;
584     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
585     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
586   }
587
588   tet_infoline( "Upload data to the texture" );
589   callStack.Reset();
590
591   tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
592   unsigned int bufferSize( width * height * 3 );
593   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
594   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
595   texture.Upload( pixelData );
596   application.SendNotification();
597   application.Render();
598
599   tet_infoline( "TexImage2D should be called to upload the data" );
600   {
601     std::stringstream out;
602     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
603     DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
604   }
605
606   END_TEST;
607 }
608
609 int UtcDaliTextureUpload07(void)
610 {
611   Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
612   {
613     Pixel::RGB16F,
614     Pixel::RGB32F,
615   };
616   const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
617
618   for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
619   {
620     TestApplication application;
621
622     //Create the texture
623     unsigned int width(64);
624     unsigned int height(64);
625     tet_infoline( "Creating a floating point texture" );
626     Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
627
628     application.GetGlAbstraction().EnableTextureCallTrace(true);
629
630     application.SendNotification();
631     application.Render();
632
633     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
634
635     tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
636     {
637       std::stringstream out;
638       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
639       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
640     }
641
642     tet_infoline( "Upload data to the texture" );
643     callStack.Reset();
644
645     tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
646     unsigned int bufferSize( width * height * 3 );
647     unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
648     PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
649     texture.Upload( pixelData );
650     application.SendNotification();
651     application.Render();
652
653     tet_infoline( "TexImage2D should be called to upload the data" );
654     {
655       std::stringstream out;
656       out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
657       DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
658     }
659   }
660
661   END_TEST;
662 }
663
664 int UtcDaliTextureUploadSmallerThanSize(void)
665 {
666   TestApplication application;
667
668   //Create the texture
669   unsigned int width(64);
670   unsigned int height(64);
671   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
672
673   application.GetGlAbstraction().EnableTextureCallTrace(true);
674
675   application.SendNotification();
676   application.Render();
677
678   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
679
680   //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
681   {
682     std::stringstream out;
683     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
684     std::string params;
685     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
686     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
687   }
688
689   //Upload data to the texture
690   callStack.Reset();
691
692   unsigned int bufferSize( width * height * 4 );
693   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
694   PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
695   texture.Upload( pixelData );
696   application.SendNotification();
697   application.Render();
698
699   //TexImage2D should be called to upload the data
700   {
701     std::stringstream out;
702     out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " <<  0u << ", " << width/2 << ", " <<  height/2;
703     std::string params;
704     DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
705     DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
706   }
707
708   END_TEST;
709 }
710
711 int UtcDaliTextureGenerateMipmaps(void)
712 {
713   TestApplication application;
714   unsigned int width(64);
715   unsigned int height(64);
716
717   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
718   texture.GenerateMipmaps();
719
720   Texture textureCubemap = Texture::New( TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height );
721   textureCubemap.GenerateMipmaps();
722
723   application.GetGlAbstraction().EnableTextureCallTrace(true);
724   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
725   application.SendNotification();
726   application.Render();
727
728   {
729     std::stringstream out;
730     out << GL_TEXTURE_2D;
731     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
732   }
733   {
734     std::stringstream out;
735     out << GL_TEXTURE_CUBE_MAP;
736     DALI_TEST_CHECK( callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str() ) );
737   }
738
739   END_TEST;
740 }
741
742 int UtcDaliTextureGetWidth(void)
743 {
744   TestApplication application;
745   unsigned int width(64);
746   unsigned int height(64);
747
748   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
749   DALI_TEST_EQUALS( texture.GetWidth(), width, TEST_LOCATION );
750   END_TEST;
751 }
752
753 int UtcDaliTextureGetHeight(void)
754 {
755   TestApplication application;
756   unsigned int width(64);
757   unsigned int height(64);
758
759   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
760   DALI_TEST_EQUALS( texture.GetHeight(), height, TEST_LOCATION );
761
762   END_TEST;
763 }
764
765 int UtcDaliTextureContextLoss(void)
766 {
767   tet_infoline("UtcDaliTextureContextLoss\n");
768   TestApplication application;
769
770   //Create the texture
771   unsigned int width(64);
772   unsigned int height(64);
773   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
774   DALI_TEST_CHECK( texture );
775
776   application.SendNotification();
777   application.Render(16);
778
779   // Lose & regain context (in render 'thread')
780   application.ResetContext();
781   DALI_TEST_CHECK( texture );
782
783   END_TEST;
784 }
785
786 int UtcDaliNativeImageTexture01(void)
787 {
788   TestApplication application;
789   tet_infoline( "UtcDaliNativeImageTexture01" );
790
791   TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
792   {
793     Texture texture = Texture::New( *(imageInterface.Get()) );
794     Actor actor = CreateRenderableActor(texture, "", "");
795     application.GetScene().Add(actor);
796
797     DALI_TEST_CHECK( texture );
798
799     application.SendNotification();
800     application.Render(16);
801
802     DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
803     DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION );
804     DALI_TEST_EQUALS( actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16,16,0)), TEST_LOCATION);
805
806     UnparentAndReset(actor);
807
808     application.SendNotification();
809     application.Render(16);
810   }
811   application.SendNotification();
812   application.Render(16);
813
814   DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
815   DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION );
816
817   END_TEST;
818 }
819
820
821 int UtcDaliNativeImageTexture02(void)
822 {
823   TestApplication application;
824   tet_infoline( "UtcDaliNativeImageTexture02 - test error on TargetTexture" );
825
826   TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
827   imageInterface->mTargetTextureError = 1u;
828   {
829     Texture texture = Texture::New( *(imageInterface.Get()) );
830     Actor actor = CreateRenderableActor(texture, "", "");
831     application.GetScene().Add(actor);
832
833     DALI_TEST_CHECK( texture );
834
835     application.SendNotification();
836     application.Render(16);
837
838     // Expect 2 attempts to create the texture - once when adding the texture
839     // to the scene-graph, and again since that failed, during the Bind.
840     DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
841     DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
842
843     UnparentAndReset(actor);
844
845     application.SendNotification();
846     application.Render(16);
847   }
848   application.SendNotification();
849   application.Render(16);
850
851   // Expect that there are no further calls to create/destroy resource
852   DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
853   DALI_TEST_EQUALS( imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION );
854
855   END_TEST;
856 }
857
858 int UtcDaliTextureGenerateMipmapsNegative(void)
859 {
860   TestApplication application;
861   Dali::Texture instance;
862   try
863   {
864     instance.GenerateMipmaps();
865     DALI_TEST_CHECK(false); // Should not get here
866   }
867   catch(...)
868   {
869     DALI_TEST_CHECK(true); // We expect an assert
870   }
871   END_TEST;
872 }
873
874 int UtcDaliTextureUploadNegative01(void)
875 {
876   TestApplication application;
877   Dali::Texture instance;
878   try
879   {
880     Dali::PixelData arg1;
881     instance.Upload(arg1);
882     DALI_TEST_CHECK(false); // Should not get here
883   }
884   catch(...)
885   {
886     DALI_TEST_CHECK(true); // We expect an assert
887   }
888   END_TEST;
889 }
890
891 int UtcDaliTextureUploadNegative02(void)
892 {
893   TestApplication application;
894   Dali::Texture instance;
895   try
896   {
897     Dali::PixelData arg1;
898     unsigned int arg2(0u);
899     unsigned int arg3(0u);
900     unsigned int arg4(0u);
901     unsigned int arg5(0u);
902     unsigned int arg6(0u);
903     unsigned int arg7(0u);
904     instance.Upload(arg1,arg2,arg3,arg4,arg5,arg6,arg7);
905     DALI_TEST_CHECK(false); // Should not get here
906   }
907   catch(...)
908   {
909     DALI_TEST_CHECK(true); // We expect an assert
910   }
911   END_TEST;
912 }
913
914 int UtcDaliTextureGetWidthNegative(void)
915 {
916   TestApplication application;
917   Dali::Texture instance;
918   try
919   {
920     instance.GetWidth();
921     DALI_TEST_CHECK(false); // Should not get here
922   }
923   catch(...)
924   {
925     DALI_TEST_CHECK(true); // We expect an assert
926   }
927   END_TEST;
928 }
929
930 int UtcDaliTextureGetHeightNegative(void)
931 {
932   TestApplication application;
933   Dali::Texture instance;
934   try
935   {
936     instance.GetHeight();
937     DALI_TEST_CHECK(false); // Should not get here
938   }
939   catch(...)
940   {
941     DALI_TEST_CHECK(true); // We expect an assert
942   }
943   END_TEST;
944 }