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