Merge "Create Texture by ResourceId + Set Texture size and format internally." into...
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
1 /*
2  * Copyright (c) 2023 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/rendering/texture-devel.h>
20 #include <dali/integration-api/texture-integ.h>
21 #include <dali/public-api/dali-core.h>
22 #include <test-native-image.h>
23
24 using namespace Dali;
25
26 #include <mesh-builder.h>
27
28 void texture_set_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void texture_set_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 int UtcDaliTextureNew01(void)
39 {
40   TestApplication application;
41
42   unsigned int width(64);
43   unsigned int height(64);
44   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
45
46   DALI_TEST_CHECK(texture);
47   END_TEST;
48 }
49
50 int UtcDaliTextureNew02(void)
51 {
52   TestApplication application;
53   Texture         texture;
54   DALI_TEST_CHECK(!texture);
55   END_TEST;
56 }
57
58 int UtcDaliTextureNew03(void)
59 {
60   TestApplication application;
61
62   // Create a native image source.
63   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
64
65   // Create a texture from the native image source.
66   Texture nativeTexture = Texture::New(*testNativeImage);
67
68   // Check the texture was created OK.
69   DALI_TEST_CHECK(nativeTexture);
70
71   END_TEST;
72 }
73
74 int UtcDaliTextureNew04(void)
75 {
76   TestApplication application;
77
78   Texture texture = Texture::New(TextureType::TEXTURE_2D);
79
80   DALI_TEST_CHECK(texture);
81   END_TEST;
82 }
83
84 int UtcDaliTextureNew05(void)
85 {
86   TestApplication application;
87
88   uint32_t expectResourceId = 11u;
89
90   Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
91
92   DALI_TEST_CHECK(texture);
93
94   uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
95
96   DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
97
98   END_TEST;
99 }
100
101 int UtcDaliTextureCopyConstructor(void)
102 {
103   TestApplication application;
104
105   unsigned int width(64);
106   unsigned int height(64);
107   Texture      texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
108
109   Texture textureCopy(texture);
110
111   DALI_TEST_CHECK(textureCopy);
112
113   END_TEST;
114 }
115
116 int UtcDaliTextureAssignmentOperator(void)
117 {
118   TestApplication application;
119   unsigned int    width(64);
120   unsigned int    height(64);
121   Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
122
123   Texture texture2;
124   DALI_TEST_CHECK(!texture2);
125
126   texture2 = texture;
127   DALI_TEST_CHECK(texture2);
128
129   END_TEST;
130 }
131
132 int UtcDaliTextureMoveConstructor(void)
133 {
134   TestApplication application;
135
136   uint32_t width   = 64;
137   uint32_t height  = 64;
138   Texture  texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
139   DALI_TEST_CHECK(texture);
140   DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
141   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
142   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
143
144   Texture move = std::move(texture);
145   DALI_TEST_CHECK(move);
146   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
147   DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
148   DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
149   DALI_TEST_CHECK(!texture);
150
151   END_TEST;
152 }
153
154 int UtcDaliTextureMoveAssignment(void)
155 {
156   TestApplication application;
157
158   uint32_t width   = 64;
159   uint32_t height  = 64;
160   Texture  texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
161   DALI_TEST_CHECK(texture);
162   DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
163   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
164   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
165
166   Texture move;
167   move = std::move(texture);
168   DALI_TEST_CHECK(move);
169   DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
170   DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
171   DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
172   DALI_TEST_CHECK(!texture);
173
174   END_TEST;
175 }
176
177 int UtcDaliTextureDownCast01(void)
178 {
179   TestApplication application;
180   unsigned int    width(64);
181   unsigned int    height(64);
182   Texture         texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
183
184   BaseHandle handle(texture);
185   Texture    texture2 = Texture::DownCast(handle);
186   DALI_TEST_CHECK(texture2);
187
188   END_TEST;
189 }
190
191 int UtcDaliTextureDownCast02(void)
192 {
193   TestApplication application;
194
195   Handle  handle  = Handle::New(); // Create a custom object
196   Texture texture = Texture::DownCast(handle);
197   DALI_TEST_CHECK(!texture);
198   END_TEST;
199 }
200
201 int UtcDaliTextureUpload01(void)
202 {
203   TestApplication application;
204
205   //Create the texture
206   unsigned int width(64);
207   unsigned int height(64);
208   Texture      texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
209
210   application.GetGlAbstraction().EnableTextureCallTrace(true);
211
212   application.SendNotification();
213   application.Render();
214
215   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
216
217   //Upload data to the texture
218   callStack.Reset();
219
220   unsigned int   bufferSize(width * height * 4);
221   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
222   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
223   texture.Upload(pixelData);
224   application.SendNotification();
225   application.Render();
226
227   //TexImage2D should be called to upload the data
228   {
229     std::stringstream out;
230     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
231     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
232   }
233
234   //Upload part of the texture
235   callStack.Reset();
236   bufferSize                  = width * height;
237   buffer                      = reinterpret_cast<unsigned char*>(malloc(bufferSize));
238   PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
239   texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
240   application.SendNotification();
241   application.Render();
242
243   //TexSubImage2D should be called to upload the data
244   {
245     std::stringstream out;
246     out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
247     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
248   }
249
250   END_TEST;
251 }
252
253 int UtcDaliTextureUpload02(void)
254 {
255   TestApplication application;
256
257   //Create the texture
258   unsigned int width(64);
259   unsigned int height(64);
260   Texture      texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
261
262   application.GetGlAbstraction().EnableTextureCallTrace(true);
263
264   application.SendNotification();
265   application.Render();
266
267   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
268
269   tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
270   for(unsigned int i(0); i < 6; ++i)
271   {
272     std::stringstream out;
273     out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
274     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
275   }
276
277   unsigned int   bufferSize(width * height * 4);
278   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
279   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
280
281   //Upload data to the POSITIVE_X face of the texture
282   {
283     callStack.Reset();
284
285     texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
286     application.SendNotification();
287     application.Render();
288
289     //TexImage2D should be called to upload the data to the POSITIVE_X face
290     {
291       std::stringstream out;
292       out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
293       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
294     }
295   }
296
297   //Upload data to the NEGATIVE_X face of the texture
298   {
299     callStack.Reset();
300
301     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
302     application.SendNotification();
303     application.Render();
304
305     //TexImage2D should be called to upload the data to the NEGATIVE_X face
306     {
307       std::stringstream out;
308       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
309       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
310     }
311   }
312
313   //Upload data to the POSITIVE_Y face of the texture
314   {
315     callStack.Reset();
316     texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
317     application.SendNotification();
318     application.Render();
319
320     //TexImage2D should be called to upload the data to the POSITIVE_Y face
321     {
322       std::stringstream out;
323       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
324       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
325     }
326   }
327
328   //Upload data to the NEGATIVE_Y face of the texture
329   {
330     callStack.Reset();
331     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
332     application.SendNotification();
333     application.Render();
334
335     //TexImage2D should be called to upload the data to the NEGATIVE_Y face
336     {
337       std::stringstream out;
338       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
339       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
340     }
341   }
342
343   //Upload data to the POSITIVE_Z face of the texture
344   {
345     callStack.Reset();
346     texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
347     application.SendNotification();
348     application.Render();
349
350     //TexImage2D should be called to upload the data to the POSITIVE_Z face
351     {
352       std::stringstream out;
353       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
354       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
355     }
356   }
357
358   //Upload data to the NEGATIVE_Z face of the texture
359   {
360     callStack.Reset();
361     texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
362     application.SendNotification();
363     application.Render();
364
365     //TexImage2D should be called to upload the data to the NEGATIVE_Z face
366     {
367       std::stringstream out;
368       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
369       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
370     }
371   }
372
373   END_TEST;
374 }
375
376 int UtcDaliTextureUpload03(void)
377 {
378   TestApplication application;
379
380   //Create the texture
381   unsigned int width(64);
382   unsigned int height(64);
383   unsigned int widthMipmap1(32);
384   unsigned int heightMipmap1(32);
385
386   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
387
388   application.GetGlAbstraction().EnableTextureCallTrace(true);
389
390   application.SendNotification();
391   application.Render();
392
393   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
394
395   tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
396   {
397     std::stringstream out;
398     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
399     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
400   }
401
402   //Upload data to the texture mipmap 0 and mipmap 1
403   callStack.Reset();
404
405   unsigned int   bufferSize(width * height * 4);
406   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
407   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
408   texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
409
410   bufferSize                 = widthMipmap1 * heightMipmap1 * 4;
411   buffer                     = reinterpret_cast<unsigned char*>(malloc(bufferSize));
412   PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
413   texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
414   application.SendNotification();
415   application.Render();
416
417   //TexImage2D should be called to upload the data to mipmaps 0 and 1
418   {
419     std::stringstream out;
420     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
421     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
422   }
423   {
424     std::stringstream out;
425     out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
426     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
427   }
428
429   END_TEST;
430 }
431
432 int UtcDaliTextureUpload04(void)
433 {
434   TestApplication application;
435
436   //Create the texture
437   unsigned int width(64);
438   unsigned int height(64);
439   unsigned int widthMipmap1(32);
440   unsigned int heightMipmap1(32);
441
442   Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
443
444   application.GetGlAbstraction().EnableTextureCallTrace(true);
445   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
446
447   //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
448   unsigned int   bufferSize(width * height * 4);
449   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
450   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
451   texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
452
453   bufferSize                 = widthMipmap1 * heightMipmap1 * 4;
454   buffer                     = reinterpret_cast<unsigned char*>(malloc(bufferSize));
455   PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
456   texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
457   application.SendNotification();
458   application.Render();
459
460   //TexImage2D should be called to upload the data to mipmaps 0 and 1
461   {
462     std::stringstream out;
463     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
464     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
465   }
466   {
467     std::stringstream out;
468     out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
469     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
470   }
471
472   END_TEST;
473 }
474
475 int UtcDaliTextureUpload05(void)
476 {
477   Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
478     {
479       Pixel::COMPRESSED_R11_EAC,
480       Pixel::COMPRESSED_SIGNED_R11_EAC,
481       Pixel::COMPRESSED_RG11_EAC,
482       Pixel::COMPRESSED_SIGNED_RG11_EAC,
483       Pixel::COMPRESSED_RGB8_ETC2,
484       Pixel::COMPRESSED_SRGB8_ETC2,
485       Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
486       Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
487       Pixel::COMPRESSED_RGBA8_ETC2_EAC,
488       Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
489       Pixel::COMPRESSED_RGB8_ETC1,
490       Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
491       Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
492       Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
493       Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
494       Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
495       Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
496       Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
497       Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
498       Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
499       Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
500       Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
501       Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
502       Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
503       Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
504       Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
505       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
506       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
507       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
508       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
509       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
510       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
511       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
512       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
513       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
514       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
515       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
516       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
517       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
518       Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
519     };
520   const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
521
522   for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
523   {
524     TestApplication application;
525
526     //Create a texture with a compressed format
527     unsigned int width(64);
528     unsigned int height(64);
529     Texture      texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
530
531     application.GetGlAbstraction().EnableTextureCallTrace(true);
532
533     application.SendNotification();
534     application.Render();
535
536     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
537
538     tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
539     {
540       std::stringstream out;
541       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
542       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
543     }
544
545     //Upload data to the texture
546     callStack.Reset();
547
548     unsigned int   bufferSize(width * height * 4);
549     unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
550     PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
551     texture.Upload(pixelData);
552     application.SendNotification();
553     application.Render();
554
555     //CompressedTexImage2D should be called to upload the data
556     {
557       std::stringstream out;
558       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
559       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
560     }
561
562     //Upload part of the texture
563     callStack.Reset();
564     bufferSize                  = width * height;
565     buffer                      = reinterpret_cast<unsigned char*>(malloc(bufferSize));
566     PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
567     texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
568     application.SendNotification();
569     application.Render();
570
571     //CompressedTexSubImage2D should be called to upload the data
572     {
573       std::stringstream out;
574       out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
575       DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
576     }
577
578     application.GetGlAbstraction().ResetTextureCallStack();
579   }
580
581   END_TEST;
582 }
583
584 int UtcDaliTextureUpload06(void)
585 {
586   TestApplication application;
587
588   //Create the texture
589   unsigned int width(64);
590   unsigned int height(64);
591   tet_infoline("Creating a Texure with an alpha channel");
592   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
593
594   application.GetGlAbstraction().EnableTextureCallTrace(true);
595
596   application.SendNotification();
597   application.Render();
598
599   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
600
601   tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
602   {
603     std::stringstream out;
604     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
605     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
606   }
607
608   tet_infoline("Upload data to the texture");
609   callStack.Reset();
610
611   tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
612   unsigned int   bufferSize(width * height * 3);
613   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
614   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
615   texture.Upload(pixelData);
616   application.SendNotification();
617   application.Render();
618
619   tet_infoline("TexImage2D should be called to upload the data");
620   {
621     std::stringstream out;
622     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
623     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
624   }
625
626   END_TEST;
627 }
628
629 int UtcDaliTextureUpload07(void)
630 {
631   Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
632     {
633       Pixel::RGB16F,
634       Pixel::RGB32F,
635     };
636   const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
637
638   for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
639   {
640     TestApplication application;
641
642     //Create the texture
643     unsigned int width(64);
644     unsigned int height(64);
645     tet_infoline("Creating a floating point texture");
646     Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
647
648     application.GetGlAbstraction().EnableTextureCallTrace(true);
649
650     application.SendNotification();
651     application.Render();
652
653     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
654
655     tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
656     {
657       std::stringstream out;
658       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
659       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
660     }
661
662     tet_infoline("Upload data to the texture");
663     callStack.Reset();
664
665     tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
666     unsigned int   bufferSize(width * height * 3);
667     unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
668     PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
669     texture.Upload(pixelData);
670     application.SendNotification();
671     application.Render();
672
673     tet_infoline("TexImage2D should be called to upload the data");
674     {
675       std::stringstream out;
676       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
677       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
678     }
679   }
680
681   END_TEST;
682 }
683
684 int UtcDaliTextureUpload08(void)
685 {
686   TestApplication application;
687
688   //Create the texture without pixel information
689   tet_infoline("Creating a Texure without any size/format information");
690   Texture texture = Texture::New(TextureType::TEXTURE_2D);
691
692   application.GetGlAbstraction().EnableTextureCallTrace(true);
693
694   application.SendNotification();
695   application.Render();
696
697   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
698
699   tet_infoline("TexImage2D should not be called with a null pointer to reserve storage for the texture in the gpu");
700   DALI_TEST_CHECK(!callStack.FindMethod("GenTextures"));
701   DALI_TEST_CHECK(!callStack.FindMethod("TexImage2D"));
702
703   tet_infoline("Upload data to the texture");
704   unsigned int width(64);
705   unsigned int height(64);
706   callStack.Reset();
707
708   tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
709   unsigned int   bufferSize(width * height * 3);
710   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
711   PixelData      pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
712   texture.Upload(pixelData);
713   application.SendNotification();
714   application.Render();
715
716   tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
717   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
718   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
719   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
720
721   tet_infoline("TexImage2D should be called to upload the data");
722   DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
723   {
724     std::stringstream out;
725     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
726     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
727   }
728
729   tet_infoline("Upload another data to the texture");
730   width  = 40;
731   height = 73;
732   callStack.Reset();
733
734   tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
735   bufferSize = width * height * 4;
736   buffer     = reinterpret_cast<unsigned char*>(malloc(bufferSize));
737   pixelData  = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
738   texture.Upload(pixelData);
739   application.SendNotification();
740   application.Render();
741
742   tet_infoline("TexImage2D should be generate new graphics, and be called to upload the data");
743   DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
744   {
745     std::stringstream out;
746     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
747     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
748   }
749
750   tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
751   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
752   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
753   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
754
755   END_TEST;
756 }
757
758 int UtcDaliTextureUploadSubPixelData01(void)
759 {
760   TestApplication application;
761
762   //Create the texture
763   unsigned int width(64);
764   unsigned int height(64);
765   Texture      texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
766
767   application.GetGlAbstraction().EnableTextureCallTrace(true);
768
769   application.SendNotification();
770   application.Render();
771
772   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
773
774   //Upload data to the texture
775   callStack.Reset();
776
777   uint32_t bufferWidth   = width * 2;
778   uint32_t bufferHeight  = height * 2;
779   uint32_t bufferXOffset = width;
780   uint32_t bufferYOffset = height;
781
782   unsigned int   bufferSize(bufferWidth * bufferHeight * 4);
783   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
784   PixelData      pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
785   DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
786   application.SendNotification();
787   application.Render();
788
789   //TexImage2D should be called to upload the data
790   {
791     std::stringstream out;
792     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
793     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
794   }
795
796   //Upload part of the texture
797   callStack.Reset();
798   DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
799   application.SendNotification();
800   application.Render();
801
802   //TexSubImage2D should be called to upload the data
803   {
804     std::stringstream out;
805     out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
806     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
807   }
808
809   END_TEST;
810 }
811
812 int UtcDaliTextureUploadSubPixelData02(void)
813 {
814   TestApplication application;
815
816   //Create the texture
817   unsigned int width(64);
818   unsigned int height(64);
819   Texture      texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
820
821   application.GetGlAbstraction().EnableTextureCallTrace(true);
822
823   application.SendNotification();
824   application.Render();
825
826   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
827
828   tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
829   for(unsigned int i(0); i < 6; ++i)
830   {
831     std::stringstream out;
832     out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
833     DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
834   }
835
836   uint32_t bufferWidth   = width * 2;
837   uint32_t bufferHeight  = height * 2;
838   uint32_t bufferXOffset = width;
839   uint32_t bufferYOffset = height;
840
841   unsigned int   bufferSize(bufferWidth * bufferHeight * 4);
842   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
843   PixelData      pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
844
845   //Upload data to the POSITIVE_X face of the texture
846   {
847     callStack.Reset();
848
849     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
850     application.SendNotification();
851     application.Render();
852
853     //TexImage2D should be called to upload the data to the POSITIVE_X face
854     {
855       std::stringstream out;
856       out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
857       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
858     }
859   }
860
861   //Upload data to the NEGATIVE_X face of the texture
862   {
863     callStack.Reset();
864
865     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
866     application.SendNotification();
867     application.Render();
868
869     //TexImage2D should be called to upload the data to the NEGATIVE_X face
870     {
871       std::stringstream out;
872       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
873       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
874     }
875   }
876
877   //Upload data to the POSITIVE_Y face of the texture
878   {
879     callStack.Reset();
880     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
881     application.SendNotification();
882     application.Render();
883
884     //TexImage2D should be called to upload the data to the POSITIVE_Y face
885     {
886       std::stringstream out;
887       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
888       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
889     }
890   }
891
892   //Upload data to the NEGATIVE_Y face of the texture
893   {
894     callStack.Reset();
895     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
896     application.SendNotification();
897     application.Render();
898
899     //TexImage2D should be called to upload the data to the NEGATIVE_Y face
900     {
901       std::stringstream out;
902       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
903       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
904     }
905   }
906
907   //Upload data to the POSITIVE_Z face of the texture
908   {
909     callStack.Reset();
910     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
911     application.SendNotification();
912     application.Render();
913
914     //TexImage2D should be called to upload the data to the POSITIVE_Z face
915     {
916       std::stringstream out;
917       out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
918       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
919     }
920   }
921
922   //Upload data to the NEGATIVE_Z face of the texture
923   {
924     callStack.Reset();
925     DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
926     application.SendNotification();
927     application.Render();
928
929     //TexImage2D should be called to upload the data to the NEGATIVE_Z face
930     {
931       std::stringstream out;
932       out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
933       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
934     }
935   }
936
937   END_TEST;
938 }
939
940 int UtcDaliTextureUploadPixelFormats(void)
941 {
942   TestApplication application;
943   application.GetGlAbstraction().EnableTextureCallTrace(true);
944
945   //Create the texture
946   unsigned int width(64);
947   unsigned int height(64);
948
949   std::vector<Pixel::Format> formats =
950     {
951       Pixel::A8,
952       Pixel::L8,
953       Pixel::LA88,
954       Pixel::RGB565,
955       Pixel::BGR565,
956       Pixel::RGBA4444,
957       Pixel::BGRA4444,
958       Pixel::RGBA5551,
959       Pixel::BGRA5551,
960       Pixel::RGB888,
961       Pixel::RGB8888,
962       Pixel::BGR8888,
963       Pixel::RGBA8888,
964       Pixel::BGRA8888,
965       Pixel::DEPTH_UNSIGNED_INT,
966       Pixel::DEPTH_FLOAT,
967       Pixel::DEPTH_STENCIL,
968       Pixel::RGB16F,
969       Pixel::RGB32F,
970       Pixel::R11G11B10F,
971       Pixel::CHROMINANCE_U,
972       Pixel::CHROMINANCE_V};
973
974   for(auto format : formats)
975   {
976     tet_infoline("Creating a Texure with a new or recent format");
977     Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
978
979     application.SendNotification();
980     application.Render();
981
982     TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
983
984     tet_infoline("TexImage2D should be called twice per texture");
985     DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
986     {
987       std::stringstream out;
988       out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
989       DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
990     }
991     callStack.Reset();
992   }
993
994   END_TEST;
995 }
996
997 int UtcDaliTextureUploadSmallerThanSize(void)
998 {
999   TestApplication application;
1000
1001   //Create the texture
1002   unsigned int width(64);
1003   unsigned int height(64);
1004   Texture      texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1005
1006   application.GetGlAbstraction().EnableTextureCallTrace(true);
1007
1008   application.SendNotification();
1009   application.Render();
1010
1011   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1012   callStack.EnableLogging(true);
1013   TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
1014   texParamCallStack.EnableLogging(true);
1015
1016   tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
1017   {
1018     std::stringstream out;
1019     out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1020     std::string params;
1021     DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
1022     DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1023   }
1024
1025   //Upload data to the texture
1026   callStack.Reset();
1027
1028   unsigned int   bufferSize(width * height * 4);
1029   unsigned char* buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1030   PixelData      pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
1031   texture.Upload(pixelData);
1032   application.SendNotification();
1033   application.Render();
1034
1035   //TexSubImage2D should be called to upload the data
1036   {
1037     std::stringstream out;
1038     out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
1039     std::string params;
1040     DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
1041     DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1042   }
1043   END_TEST;
1044 }
1045
1046 int UtcDaliTextureGenerateMipmaps(void)
1047 {
1048   TestApplication application;
1049   unsigned int    width(64);
1050   unsigned int    height(64);
1051
1052   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1053   texture.GenerateMipmaps();
1054
1055   Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1056   textureCubemap.GenerateMipmaps();
1057
1058   application.GetGlAbstraction().EnableTextureCallTrace(true);
1059   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1060   application.SendNotification();
1061   application.Render();
1062
1063   {
1064     std::stringstream out;
1065     out << GL_TEXTURE_2D;
1066     DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1067   }
1068   {
1069     std::stringstream out;
1070     out << GL_TEXTURE_CUBE_MAP;
1071     DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1072   }
1073
1074   END_TEST;
1075 }
1076
1077 int UtcDaliTextureGetWidth(void)
1078 {
1079   TestApplication application;
1080   unsigned int    width(64);
1081   unsigned int    height(64);
1082
1083   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1084   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1085   END_TEST;
1086 }
1087
1088 int UtcDaliTextureGetHeight(void)
1089 {
1090   TestApplication application;
1091   unsigned int    width(64);
1092   unsigned int    height(64);
1093
1094   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1095   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1096
1097   END_TEST;
1098 }
1099
1100 int UtcDaliTextureGetTextureType(void)
1101 {
1102   TestApplication application;
1103   unsigned int    width(64);
1104   unsigned int    height(64);
1105
1106   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1107   DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
1108
1109   texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1110   DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
1111
1112   END_TEST;
1113 }
1114
1115 int UtcDaliTextureSetSize(void)
1116 {
1117   TestApplication application;
1118   unsigned int    width(64);
1119   unsigned int    height(64);
1120
1121   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1122   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1123   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1124   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1125
1126   width += 11u;
1127   height += 22u;
1128
1129   Integration::SetTextureSize(texture, ImageDimensions(width, height));
1130   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1131   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1132   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1133
1134   application.SendNotification();
1135   application.Render();
1136
1137   END_TEST;
1138 }
1139
1140 int UtcDaliTextureSetPixelFormat(void)
1141 {
1142   TestApplication application;
1143   unsigned int    width(64);
1144   unsigned int    height(64);
1145
1146   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1147   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1148   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1149   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1150
1151   Integration::SetTexturePixelFormat(texture, Pixel::BGRA5551);
1152   DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1153   DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1154   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::BGRA5551, TEST_LOCATION);
1155
1156   application.SendNotification();
1157   application.Render();
1158
1159   END_TEST;
1160 }
1161
1162 int UtcDaliTextureContextLoss(void)
1163 {
1164   tet_infoline("UtcDaliTextureContextLoss\n");
1165   TestApplication application;
1166
1167   //Create the texture
1168   unsigned int width(64);
1169   unsigned int height(64);
1170   Texture      texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1171   DALI_TEST_CHECK(texture);
1172
1173   application.SendNotification();
1174   application.Render(16);
1175
1176   // Lose & regain context (in render 'thread')
1177   application.ResetContext();
1178   DALI_TEST_CHECK(texture);
1179
1180   END_TEST;
1181 }
1182
1183 int UtcDaliNativeImageTexture01(void)
1184 {
1185   TestApplication application;
1186   tet_infoline("UtcDaliNativeImageTexture01");
1187
1188   TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1189   {
1190     Texture texture = Texture::New(*(imageInterface.Get()));
1191     Actor   actor   = CreateRenderableActor(texture, "", "");
1192     application.GetScene().Add(actor);
1193
1194     DALI_TEST_CHECK(texture);
1195
1196     application.SendNotification();
1197     application.Render(16);
1198
1199     DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1200     DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1201     DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1202
1203     UnparentAndReset(actor);
1204
1205     application.SendNotification();
1206     application.Render(16);
1207   }
1208   application.SendNotification();
1209   application.Render(16);
1210
1211   DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1212   DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1213
1214   END_TEST;
1215 }
1216
1217 int UtcDaliNativeImageTexture02(void)
1218 {
1219   TestApplication application;
1220   tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1221
1222   TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1223   imageInterface->mTargetTextureError   = 1u;
1224   {
1225     Texture texture = Texture::New(*(imageInterface.Get()));
1226     Actor   actor   = CreateRenderableActor(texture, "", "");
1227     application.GetScene().Add(actor);
1228
1229     DALI_TEST_CHECK(texture);
1230
1231     application.SendNotification();
1232     application.Render(16);
1233
1234     // Expect 2 attempts to create the texture - once when adding the texture
1235     // to the scene-graph, and again since that failed, during the Bind.
1236     // The second one succeeds (TargetTexture only errors once)
1237     DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1238     DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1239
1240     UnparentAndReset(actor);
1241
1242     application.SendNotification();
1243     application.Render(16);
1244   }
1245   application.SendNotification();
1246   application.Render(16);
1247
1248   // Expect that there are no further calls to create/destroy resource
1249   DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1250   DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1251
1252   END_TEST;
1253 }
1254
1255 int UtcDaliTextureGenerateMipmapsNegative(void)
1256 {
1257   TestApplication application;
1258   Dali::Texture   instance;
1259   try
1260   {
1261     instance.GenerateMipmaps();
1262     DALI_TEST_CHECK(false); // Should not get here
1263   }
1264   catch(...)
1265   {
1266     DALI_TEST_CHECK(true); // We expect an assert
1267   }
1268   END_TEST;
1269 }
1270
1271 int UtcDaliTextureUploadNegative01(void)
1272 {
1273   TestApplication application;
1274   Dali::Texture   instance;
1275   try
1276   {
1277     Dali::PixelData arg1;
1278     instance.Upload(arg1);
1279     DALI_TEST_CHECK(false); // Should not get here
1280   }
1281   catch(...)
1282   {
1283     DALI_TEST_CHECK(true); // We expect an assert
1284   }
1285   END_TEST;
1286 }
1287
1288 int UtcDaliTextureUploadNegative02(void)
1289 {
1290   TestApplication application;
1291   Dali::Texture   instance;
1292   try
1293   {
1294     Dali::PixelData arg1;
1295     unsigned int    arg2(0u);
1296     unsigned int    arg3(0u);
1297     unsigned int    arg4(0u);
1298     unsigned int    arg5(0u);
1299     unsigned int    arg6(0u);
1300     unsigned int    arg7(0u);
1301     instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1302     DALI_TEST_CHECK(false); // Should not get here
1303   }
1304   catch(...)
1305   {
1306     DALI_TEST_CHECK(true); // We expect an assert
1307   }
1308   END_TEST;
1309 }
1310
1311 int UtcDaliTextureGetWidthNegative(void)
1312 {
1313   TestApplication application;
1314   Dali::Texture   instance;
1315   try
1316   {
1317     instance.GetWidth();
1318     DALI_TEST_CHECK(false); // Should not get here
1319   }
1320   catch(...)
1321   {
1322     DALI_TEST_CHECK(true); // We expect an assert
1323   }
1324   END_TEST;
1325 }
1326
1327 int UtcDaliTextureGetHeightNegative(void)
1328 {
1329   TestApplication application;
1330   Dali::Texture   instance;
1331   try
1332   {
1333     instance.GetHeight();
1334     DALI_TEST_CHECK(false); // Should not get here
1335   }
1336   catch(...)
1337   {
1338     DALI_TEST_CHECK(true); // We expect an assert
1339   }
1340   END_TEST;
1341 }
1342
1343 int UtcDaliTextureCheckNativeP(void)
1344 {
1345   TestApplication        application;
1346   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1347   Texture                nativeTexture   = Texture::New(*testNativeImage);
1348
1349   DALI_TEST_CHECK(nativeTexture);
1350   DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1351   END_TEST;
1352 }
1353
1354 int UtcDaliTextureCheckNativeN1(void)
1355 {
1356   TestApplication application;
1357   unsigned int    width(64);
1358   unsigned int    height(64);
1359   Texture         texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1360
1361   DALI_TEST_CHECK(texture);
1362   DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1363   END_TEST;
1364 }
1365
1366 int UtcDaliTextureCheckNativeN2(void)
1367 {
1368   TestApplication application;
1369   Texture         texture;
1370   try
1371   {
1372     bool native = DevelTexture::IsNative(texture);
1373     DALI_TEST_CHECK(native != native);
1374   }
1375   catch(...)
1376   {
1377     DALI_TEST_CHECK(true);
1378   }
1379   END_TEST;
1380 }
1381
1382 int UtcDaliTextureApplyFragShaderP1(void)
1383 {
1384   TestApplication        application;
1385   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1386   Texture                nativeTexture   = Texture::New(*testNativeImage);
1387   DALI_TEST_CHECK(nativeTexture);
1388
1389   const std::string baseFragShader =
1390     "varying mediump vec4 uColor;\n"
1391     "void main(){\n"
1392     "  gl_FragColor=uColor;\n"
1393     "}\n";
1394   std::string fragShader = baseFragShader;
1395   bool        applied    = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1396
1397   std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1398
1399   DALI_TEST_CHECK(applied);
1400   DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1401   DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1402   DALI_TEST_CHECK(!fragShader.empty());
1403   END_TEST;
1404 }
1405
1406 int UtcDaliTextureApplyFragShaderP2(void)
1407 {
1408   TestApplication        application;
1409   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1410   Texture                nativeTexture   = Texture::New(*testNativeImage);
1411   DALI_TEST_CHECK(nativeTexture);
1412
1413   const std::string baseFragShader =
1414     "varying mediump vec4 uColor;\n"
1415     "varying vec2 vTexCoord;\n"
1416     "uniform sampler2D uNative;\n"
1417     "void main(){\n"
1418     "  gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1419     "}\n";
1420   std::string fragShader = baseFragShader;
1421   bool        applied    = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1422
1423   DALI_TEST_CHECK(applied);
1424   DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1425   DALI_TEST_CHECK(!fragShader.empty());
1426   DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1427   END_TEST;
1428 }
1429
1430 int UtcDaliTextureApplyFragShaderN1(void)
1431 {
1432   TestApplication        application;
1433   TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1434   Texture                nativeTexture   = Texture::New(*testNativeImage);
1435   DALI_TEST_CHECK(nativeTexture);
1436
1437   std::string fragShader;
1438   bool        applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1439
1440   DALI_TEST_CHECK(!applied);
1441   DALI_TEST_CHECK(fragShader.empty());
1442   END_TEST;
1443 }
1444
1445 int UtcDaliTextureApplyFragShaderN2(void)
1446 {
1447   TestApplication application;
1448   unsigned int    width(64);
1449   unsigned int    height(64);
1450   Texture         texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1451
1452   const std::string baseFragShader =
1453     "varying mediump vec4 uColor;\n"
1454     "void main(){\n"
1455     "  gl_FragColor=uColor;\n"
1456     "}\n";
1457   std::string fragShader = baseFragShader;
1458   bool        applied    = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1459
1460   DALI_TEST_CHECK(!applied);
1461   DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1462   END_TEST;
1463 }
1464
1465 int UtcDaliTextureGetPixelFormat(void)
1466 {
1467   TestApplication application;
1468   uint32_t        width(64);
1469   uint32_t        height(64);
1470
1471   Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1472   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1473
1474   texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1475   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1476
1477   texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1478   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1479
1480   texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1481   DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1482
1483   END_TEST;
1484 }
1485
1486 int utcDaliTexturePartialUpdate01(void)
1487 {
1488   TestApplication application(
1489     TestApplication::DEFAULT_SURFACE_WIDTH,
1490     TestApplication::DEFAULT_SURFACE_HEIGHT,
1491     TestApplication::DEFAULT_HORIZONTAL_DPI,
1492     TestApplication::DEFAULT_VERTICAL_DPI,
1493     true,
1494     true);
1495
1496   tet_infoline("Check the damaged rect with partial update and texture change");
1497
1498   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1499
1500   std::vector<Rect<int32_t>> damagedRects;
1501   Rect<int32_t>              clippingRect;
1502
1503   Geometry geometry = CreateQuadGeometry();
1504   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1505   Renderer renderer = Renderer::New(geometry, shader);
1506
1507   uint32_t   width(4);
1508   uint32_t   height(4);
1509   Texture    texture    = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1510   TextureSet textureSet = TextureSet::New();
1511   textureSet.SetTexture(0u, texture);
1512   renderer.SetTextures(textureSet);
1513
1514   Actor actor = Actor::New();
1515   actor.AddRenderer(renderer);
1516
1517   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1518   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1519   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1520   application.GetScene().Add(actor);
1521
1522   damagedRects.clear();
1523   application.SendNotification();
1524   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1525   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1526
1527   // Aligned by 16
1528   clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1529   DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1530   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1531   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1532   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1533   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1534   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1535
1536   damagedRects.clear();
1537   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1538   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1539
1540   // Ensure the damaged rect is empty
1541   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1542
1543   // Upload texture
1544   uint32_t  bufferSize(width * height * 4);
1545   uint8_t*  buffer    = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1546   PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1547   texture.Upload(pixelData);
1548
1549   damagedRects.clear();
1550   application.SendNotification();
1551   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1552   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1553
1554   // Aligned by 16
1555   clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1556   DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1557   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1558   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1559   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1560   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1561   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1562
1563   damagedRects.clear();
1564   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1565   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1566
1567   // Ensure the damaged rect is empty
1568   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1569
1570   END_TEST;
1571 }
1572
1573 int utcDaliTexturePartialUpdate02(void)
1574 {
1575   TestApplication application(
1576     TestApplication::DEFAULT_SURFACE_WIDTH,
1577     TestApplication::DEFAULT_SURFACE_HEIGHT,
1578     TestApplication::DEFAULT_HORIZONTAL_DPI,
1579     TestApplication::DEFAULT_VERTICAL_DPI,
1580     true,
1581     true);
1582
1583   tet_infoline("Check the damaged rect with partial update and texture change");
1584
1585   const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1586
1587   std::vector<Rect<int32_t>> damagedRects;
1588   Rect<int32_t>              clippingRect;
1589
1590   Geometry geometry = CreateQuadGeometry();
1591   Shader   shader   = Shader::New("vertexSrc", "fragmentSrc");
1592   Renderer renderer = Renderer::New(geometry, shader);
1593
1594   uint32_t   width(4);
1595   uint32_t   height(4);
1596   Texture    texture1   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1597   Texture    texture2   = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1598   TextureSet textureSet = TextureSet::New();
1599   textureSet.SetTexture(0u, texture1);
1600   renderer.SetTextures(textureSet);
1601
1602   Actor actor = Actor::New();
1603   actor.AddRenderer(renderer);
1604
1605   actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1606   actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1607   actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1608   application.GetScene().Add(actor);
1609
1610   damagedRects.clear();
1611   application.SendNotification();
1612   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1613   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1614
1615   // Aligned by 16
1616   clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1617   DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1618   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1619   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1620   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1621   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1622   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1623
1624   damagedRects.clear();
1625   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1626   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1627
1628   // Ensure the damaged rect is empty
1629   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1630
1631   // Set another texture
1632   textureSet.SetTexture(0u, texture2);
1633
1634   damagedRects.clear();
1635   application.SendNotification();
1636   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1637   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1638
1639   // Aligned by 16
1640   clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1641   DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1642   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1643   DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1644   DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1645   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1646   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1647
1648   damagedRects.clear();
1649   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1650   application.RenderWithPartialUpdate(damagedRects, clippingRect);
1651
1652   // Ensure the damaged rect is empty
1653   DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1654
1655   END_TEST;
1656 }