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