2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
27 #include <mesh-builder.h>
29 void texture_set_startup(void)
31 test_return_value = TET_UNDEF;
34 void texture_set_cleanup(void)
36 test_return_value = TET_PASS;
39 int UtcDaliTextureNew01(void)
41 TestApplication application;
43 unsigned int width(64);
44 unsigned int height(64);
45 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
47 DALI_TEST_CHECK(texture);
51 int UtcDaliTextureNew02(void)
53 TestApplication application;
55 DALI_TEST_CHECK(!texture);
59 int UtcDaliTextureNew03(void)
61 TestApplication application;
63 // Create a native image source.
64 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
66 // Create a texture from the native image source.
67 Texture nativeTexture = Texture::New(*testNativeImage);
69 // Check the texture was created OK.
70 DALI_TEST_CHECK(nativeTexture);
75 int UtcDaliTextureNew04(void)
77 TestApplication application;
79 Texture texture = Texture::New(TextureType::TEXTURE_2D);
81 DALI_TEST_CHECK(texture);
85 int UtcDaliTextureNew05(void)
87 TestApplication application;
89 uint32_t expectResourceId = 11u;
91 Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
93 DALI_TEST_CHECK(texture);
95 uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
97 DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
102 int UtcDaliTextureCopyConstructor(void)
104 TestApplication application;
106 unsigned int width(64);
107 unsigned int height(64);
108 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
110 Texture textureCopy(texture);
112 DALI_TEST_CHECK(textureCopy);
117 int UtcDaliTextureAssignmentOperator(void)
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);
125 DALI_TEST_CHECK(!texture2);
128 DALI_TEST_CHECK(texture2);
133 int UtcDaliTextureMoveConstructor(void)
135 TestApplication application;
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);
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);
155 int UtcDaliTextureMoveAssignment(void)
157 TestApplication application;
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);
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);
178 int UtcDaliTextureDownCast01(void)
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);
185 BaseHandle handle(texture);
186 Texture texture2 = Texture::DownCast(handle);
187 DALI_TEST_CHECK(texture2);
192 int UtcDaliTextureDownCast02(void)
194 TestApplication application;
196 Handle handle = Handle::New(); // Create a custom object
197 Texture texture = Texture::DownCast(handle);
198 DALI_TEST_CHECK(!texture);
202 int UtcDaliTextureUpload01(void)
204 TestApplication application;
207 unsigned int width(64);
208 unsigned int height(64);
209 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
211 application.GetGlAbstraction().EnableTextureCallTrace(true);
213 application.SendNotification();
214 application.Render();
216 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
218 //Upload data to the texture
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();
228 //TexImage2D should be called to upload the data
230 std::stringstream out;
231 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
232 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
235 //Upload part of the texture
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();
244 //TexSubImage2D should be called to upload the data
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()));
254 int UtcDaliTextureUpload02(void)
256 TestApplication application;
259 unsigned int width(64);
260 unsigned int height(64);
261 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
263 application.GetGlAbstraction().EnableTextureCallTrace(true);
265 application.SendNotification();
266 application.Render();
268 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
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)
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()));
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);
282 //Upload data to the POSITIVE_X face of the texture
286 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
287 application.SendNotification();
288 application.Render();
290 //TexImage2D should be called to upload the data to the POSITIVE_X face
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()));
298 //Upload data to the NEGATIVE_X face of the texture
302 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
303 application.SendNotification();
304 application.Render();
306 //TexImage2D should be called to upload the data to the NEGATIVE_X face
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()));
314 //Upload data to the POSITIVE_Y face of the texture
317 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
318 application.SendNotification();
319 application.Render();
321 //TexImage2D should be called to upload the data to the POSITIVE_Y face
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()));
329 //Upload data to the NEGATIVE_Y face of the texture
332 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
333 application.SendNotification();
334 application.Render();
336 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
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()));
344 //Upload data to the POSITIVE_Z face of the texture
347 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
348 application.SendNotification();
349 application.Render();
351 //TexImage2D should be called to upload the data to the POSITIVE_Z face
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()));
359 //Upload data to the NEGATIVE_Z face of the texture
362 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
363 application.SendNotification();
364 application.Render();
366 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
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()));
377 int UtcDaliTextureUpload03(void)
379 TestApplication application;
382 unsigned int width(64);
383 unsigned int height(64);
384 unsigned int widthMipmap1(32);
385 unsigned int heightMipmap1(32);
387 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
389 application.GetGlAbstraction().EnableTextureCallTrace(true);
391 application.SendNotification();
392 application.Render();
394 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
396 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
398 std::stringstream out;
399 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
400 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
403 //Upload data to the texture mipmap 0 and mipmap 1
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);
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();
418 //TexImage2D should be called to upload the data to mipmaps 0 and 1
420 std::stringstream out;
421 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
422 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
425 std::stringstream out;
426 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
427 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
433 int UtcDaliTextureUpload04(void)
435 TestApplication application;
438 unsigned int width(64);
439 unsigned int height(64);
440 unsigned int widthMipmap1(32);
441 unsigned int heightMipmap1(32);
443 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
445 application.GetGlAbstraction().EnableTextureCallTrace(true);
446 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
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);
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();
461 //TexImage2D should be called to upload the data to mipmaps 0 and 1
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()));
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()));
476 int UtcDaliTextureUpload05(void)
478 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
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,
521 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
523 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
525 TestApplication application;
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);
532 application.GetGlAbstraction().EnableTextureCallTrace(true);
534 application.SendNotification();
535 application.Render();
537 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
539 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
541 std::stringstream out;
542 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
543 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
546 //Upload data to the texture
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();
556 //CompressedTexImage2D should be called to upload the data
558 std::stringstream out;
559 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
560 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
563 //Upload part of the texture
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();
572 //CompressedTexSubImage2D should be called to upload the data
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()));
579 application.GetGlAbstraction().ResetTextureCallStack();
585 int UtcDaliTextureUpload06(void)
587 TestApplication application;
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);
595 application.GetGlAbstraction().EnableTextureCallTrace(true);
597 application.SendNotification();
598 application.Render();
600 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
602 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
604 std::stringstream out;
605 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
606 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
609 tet_infoline("Upload data to the texture");
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();
620 tet_infoline("TexImage2D should be called to upload the data");
622 std::stringstream out;
623 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
624 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
630 int UtcDaliTextureUpload07(void)
632 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
637 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
639 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
641 TestApplication application;
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);
649 application.GetGlAbstraction().EnableTextureCallTrace(true);
651 application.SendNotification();
652 application.Render();
654 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
656 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
658 std::stringstream out;
659 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
660 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
663 tet_infoline("Upload data to the texture");
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();
674 tet_infoline("TexImage2D should be called to upload the data");
676 std::stringstream out;
677 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
678 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
685 int UtcDaliTextureUpload08(void)
687 TestApplication application;
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);
693 application.GetGlAbstraction().EnableTextureCallTrace(true);
695 application.SendNotification();
696 application.Render();
698 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
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"));
704 tet_infoline("Upload data to the texture");
705 unsigned int width(64);
706 unsigned int height(64);
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();
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);
722 tet_infoline("TexImage2D should be called to upload the data");
723 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
725 std::stringstream out;
726 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
727 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
730 tet_infoline("Upload another data to the texture");
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();
743 tet_infoline("TexImage2D should be generate new graphics, and be called to upload the data");
744 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
746 std::stringstream out;
747 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
748 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
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);
759 int UtcDaliTextureUpload09(void)
761 TestApplication application;
765 uint32_t height(64u);
766 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
768 application.GetGlAbstraction().EnableTextureCallTrace(true);
770 application.SendNotification();
771 application.Render();
773 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
775 //Upload data to the texture
778 uint32_t bufferSize(width * height * 4u);
779 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
782 PixelData pixelData = Dali::Integration::NewPixelDataWithReleaseAfterUpload(buffer, bufferSize, width, height, 0u, Pixel::RGBA8888, PixelData::FREE);
783 DALI_TEST_CHECK(pixelData);
785 Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
787 DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
788 DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
790 texture.Upload(pixelData);
792 application.SendNotification();
793 application.Render();
795 //TexImage2D should be called to upload the data
797 std::stringstream out;
798 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
799 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
802 // Check whether the buffer become nullptr after texture uploaded.
803 pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
805 DALI_TEST_CHECK(pixelDataBuffer.buffer == nullptr);
810 int UtcDaliTextureUploadSubPixelData01(void)
812 TestApplication application;
815 unsigned int width(64);
816 unsigned int height(64);
817 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
819 application.GetGlAbstraction().EnableTextureCallTrace(true);
821 application.SendNotification();
822 application.Render();
824 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
826 //Upload data to the texture
829 uint32_t bufferWidth = width * 2;
830 uint32_t bufferHeight = height * 2;
831 uint32_t bufferXOffset = width;
832 uint32_t bufferYOffset = height;
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();
841 //TexImage2D should be called to upload the data
843 std::stringstream out;
844 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
845 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
848 //Upload part of the texture
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();
854 //TexSubImage2D should be called to upload the data
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()));
864 int UtcDaliTextureUploadSubPixelData02(void)
866 TestApplication application;
869 unsigned int width(64);
870 unsigned int height(64);
871 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
873 application.GetGlAbstraction().EnableTextureCallTrace(true);
875 application.SendNotification();
876 application.Render();
878 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
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)
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()));
888 uint32_t bufferWidth = width * 2;
889 uint32_t bufferHeight = height * 2;
890 uint32_t bufferXOffset = width;
891 uint32_t bufferYOffset = height;
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);
897 //Upload data to the POSITIVE_X face of the texture
901 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
902 application.SendNotification();
903 application.Render();
905 //TexImage2D should be called to upload the data to the POSITIVE_X face
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()));
913 //Upload data to the NEGATIVE_X face of the texture
917 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
918 application.SendNotification();
919 application.Render();
921 //TexImage2D should be called to upload the data to the NEGATIVE_X face
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()));
929 //Upload data to the POSITIVE_Y face of the texture
932 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
933 application.SendNotification();
934 application.Render();
936 //TexImage2D should be called to upload the data to the POSITIVE_Y face
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()));
944 //Upload data to the NEGATIVE_Y face of the texture
947 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
948 application.SendNotification();
949 application.Render();
951 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
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()));
959 //Upload data to the POSITIVE_Z face of the texture
962 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
963 application.SendNotification();
964 application.Render();
966 //TexImage2D should be called to upload the data to the POSITIVE_Z face
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()));
974 //Upload data to the NEGATIVE_Z face of the texture
977 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
978 application.SendNotification();
979 application.Render();
981 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
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()));
992 int UtcDaliTextureUploadPixelFormats(void)
994 TestApplication application;
995 application.GetGlAbstraction().EnableTextureCallTrace(true);
998 unsigned int width(64);
999 unsigned int height(64);
1001 std::vector<Pixel::Format> formats =
1017 Pixel::DEPTH_UNSIGNED_INT,
1019 Pixel::DEPTH_STENCIL,
1023 Pixel::CHROMINANCE_U,
1024 Pixel::CHROMINANCE_V};
1026 for(auto format : formats)
1028 tet_infoline("Creating a Texure with a new or recent format");
1029 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
1031 application.SendNotification();
1032 application.Render();
1034 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1036 tet_infoline("TexImage2D should be called twice per texture");
1037 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
1039 std::stringstream out;
1040 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1041 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
1049 int UtcDaliTextureUploadSmallerThanSize(void)
1051 TestApplication application;
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);
1058 application.GetGlAbstraction().EnableTextureCallTrace(true);
1060 application.SendNotification();
1061 application.Render();
1063 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1064 callStack.EnableLogging(true);
1065 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
1066 texParamCallStack.EnableLogging(true);
1068 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
1070 std::stringstream out;
1071 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1073 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
1074 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1077 //Upload data to the texture
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();
1087 //TexSubImage2D should be called to upload the data
1089 std::stringstream out;
1090 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
1092 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
1093 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1098 int UtcDaliTextureGenerateMipmaps(void)
1100 TestApplication application;
1101 unsigned int width(64);
1102 unsigned int height(64);
1104 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1105 texture.GenerateMipmaps();
1107 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1108 textureCubemap.GenerateMipmaps();
1110 application.GetGlAbstraction().EnableTextureCallTrace(true);
1111 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1112 application.SendNotification();
1113 application.Render();
1116 std::stringstream out;
1117 out << GL_TEXTURE_2D;
1118 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1121 std::stringstream out;
1122 out << GL_TEXTURE_CUBE_MAP;
1123 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1129 int UtcDaliTextureGenerateMipmapsCompressedFormat(void)
1131 TestApplication application;
1132 unsigned int width(64);
1133 unsigned int height(64);
1135 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA8_ETC2_EAC, width, height);
1136 texture.GenerateMipmaps();
1138 application.GetGlAbstraction().EnableTextureCallTrace(true);
1139 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1140 application.SendNotification();
1141 application.Render();
1143 // Check generate mipmap didn't called when we use compressed pixel format.
1144 DALI_TEST_CHECK(!callStack.FindMethod("GenerateMipmap"));
1149 int UtcDaliTextureGetWidth(void)
1151 TestApplication application;
1152 unsigned int width(64);
1153 unsigned int height(64);
1155 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1156 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1160 int UtcDaliTextureGetHeight(void)
1162 TestApplication application;
1163 unsigned int width(64);
1164 unsigned int height(64);
1166 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1167 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1172 int UtcDaliTextureGetTextureType(void)
1174 TestApplication application;
1175 unsigned int width(64);
1176 unsigned int height(64);
1178 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1179 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
1181 texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1182 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
1187 int UtcDaliTextureSetSize(void)
1189 TestApplication application;
1190 unsigned int width(64);
1191 unsigned int height(64);
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);
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);
1206 application.SendNotification();
1207 application.Render();
1212 int UtcDaliTextureSetPixelFormat(void)
1214 TestApplication application;
1215 unsigned int width(64);
1216 unsigned int height(64);
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);
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);
1228 application.SendNotification();
1229 application.Render();
1234 int UtcDaliTextureContextLoss(void)
1236 tet_infoline("UtcDaliTextureContextLoss\n");
1237 TestApplication application;
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);
1245 application.SendNotification();
1246 application.Render(16);
1248 // Lose & regain context (in render 'thread')
1249 application.ResetContext();
1250 DALI_TEST_CHECK(texture);
1255 int UtcDaliNativeImageTexture01(void)
1257 TestApplication application;
1258 tet_infoline("UtcDaliNativeImageTexture01");
1260 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1262 Texture texture = Texture::New(*(imageInterface.Get()));
1263 Actor actor = CreateRenderableActor(texture, "", "");
1264 application.GetScene().Add(actor);
1266 DALI_TEST_CHECK(texture);
1268 application.SendNotification();
1269 application.Render(16);
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);
1275 UnparentAndReset(actor);
1277 application.SendNotification();
1278 application.Render(16);
1280 application.SendNotification();
1281 application.Render(16);
1283 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1284 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1289 int UtcDaliNativeImageTexture02(void)
1291 TestApplication application;
1292 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1294 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1295 imageInterface->mTargetTextureError = 1u;
1297 Texture texture = Texture::New(*(imageInterface.Get()));
1298 Actor actor = CreateRenderableActor(texture, "", "");
1299 application.GetScene().Add(actor);
1301 DALI_TEST_CHECK(texture);
1303 application.SendNotification();
1304 application.Render(16);
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);
1312 UnparentAndReset(actor);
1314 application.SendNotification();
1315 application.Render(16);
1317 application.SendNotification();
1318 application.Render(16);
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);
1327 int UtcDaliTextureGenerateMipmapsNegative(void)
1329 TestApplication application;
1330 Dali::Texture instance;
1333 instance.GenerateMipmaps();
1334 DALI_TEST_CHECK(false); // Should not get here
1338 DALI_TEST_CHECK(true); // We expect an assert
1343 int UtcDaliTextureUploadNegative01(void)
1345 TestApplication application;
1346 Dali::Texture instance;
1349 Dali::PixelData arg1;
1350 instance.Upload(arg1);
1351 DALI_TEST_CHECK(false); // Should not get here
1355 DALI_TEST_CHECK(true); // We expect an assert
1360 int UtcDaliTextureUploadNegative02(void)
1362 TestApplication application;
1363 Dali::Texture instance;
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
1378 DALI_TEST_CHECK(true); // We expect an assert
1383 int UtcDaliTextureGetWidthNegative(void)
1385 TestApplication application;
1386 Dali::Texture instance;
1389 instance.GetWidth();
1390 DALI_TEST_CHECK(false); // Should not get here
1394 DALI_TEST_CHECK(true); // We expect an assert
1399 int UtcDaliTextureGetHeightNegative(void)
1401 TestApplication application;
1402 Dali::Texture instance;
1405 instance.GetHeight();
1406 DALI_TEST_CHECK(false); // Should not get here
1410 DALI_TEST_CHECK(true); // We expect an assert
1415 int UtcDaliTextureCheckNativeP(void)
1417 TestApplication application;
1418 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1419 Texture nativeTexture = Texture::New(*testNativeImage);
1421 DALI_TEST_CHECK(nativeTexture);
1422 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1426 int UtcDaliTextureCheckNativeN1(void)
1428 TestApplication application;
1429 unsigned int width(64);
1430 unsigned int height(64);
1431 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1433 DALI_TEST_CHECK(texture);
1434 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1438 int UtcDaliTextureCheckNativeN2(void)
1440 TestApplication application;
1444 bool native = DevelTexture::IsNative(texture);
1445 DALI_TEST_CHECK(native != native);
1449 DALI_TEST_CHECK(true);
1454 int UtcDaliTextureApplyFragShaderP1(void)
1456 TestApplication application;
1457 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1458 Texture nativeTexture = Texture::New(*testNativeImage);
1459 DALI_TEST_CHECK(nativeTexture);
1461 const std::string baseFragShader =
1462 "varying mediump vec4 uColor;\n"
1464 " gl_FragColor=uColor;\n"
1466 std::string fragShader = baseFragShader;
1467 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1469 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
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());
1478 int UtcDaliTextureApplyFragShaderP2(void)
1480 TestApplication application;
1481 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1482 Texture nativeTexture = Texture::New(*testNativeImage);
1483 DALI_TEST_CHECK(nativeTexture);
1485 const std::string baseFragShader =
1486 "varying mediump vec4 uColor;\n"
1487 "varying vec2 vTexCoord;\n"
1488 "uniform sampler2D uNative;\n"
1490 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1492 std::string fragShader = baseFragShader;
1493 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
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());
1502 int UtcDaliTextureApplyFragShaderN1(void)
1504 TestApplication application;
1505 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1506 Texture nativeTexture = Texture::New(*testNativeImage);
1507 DALI_TEST_CHECK(nativeTexture);
1509 std::string fragShader;
1510 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1512 DALI_TEST_CHECK(!applied);
1513 DALI_TEST_CHECK(fragShader.empty());
1517 int UtcDaliTextureApplyFragShaderN2(void)
1519 TestApplication application;
1520 unsigned int width(64);
1521 unsigned int height(64);
1522 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1524 const std::string baseFragShader =
1525 "varying mediump vec4 uColor;\n"
1527 " gl_FragColor=uColor;\n"
1529 std::string fragShader = baseFragShader;
1530 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1532 DALI_TEST_CHECK(!applied);
1533 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1537 int UtcDaliTextureGetPixelFormat(void)
1539 TestApplication application;
1541 uint32_t height(64);
1543 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1544 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1546 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1547 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1549 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1550 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1552 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1553 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1558 int utcDaliTexturePartialUpdate01(void)
1560 TestApplication application(
1561 TestApplication::DEFAULT_SURFACE_WIDTH,
1562 TestApplication::DEFAULT_SURFACE_HEIGHT,
1563 TestApplication::DEFAULT_HORIZONTAL_DPI,
1564 TestApplication::DEFAULT_VERTICAL_DPI,
1568 tet_infoline("Check the damaged rect with partial update and texture change");
1570 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1572 std::vector<Rect<int32_t>> damagedRects;
1573 Rect<int32_t> clippingRect;
1575 Geometry geometry = CreateQuadGeometry();
1576 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1577 Renderer renderer = Renderer::New(geometry, shader);
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);
1586 Actor actor = Actor::New();
1587 actor.AddRenderer(renderer);
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);
1594 damagedRects.clear();
1595 application.SendNotification();
1596 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1597 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
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);
1608 damagedRects.clear();
1609 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1610 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1612 // Ensure the damaged rect is empty
1613 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
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);
1621 damagedRects.clear();
1622 application.SendNotification();
1623 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1624 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
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);
1635 damagedRects.clear();
1636 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1637 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1639 // Ensure the damaged rect is empty
1640 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1645 int utcDaliTexturePartialUpdate02(void)
1647 TestApplication application(
1648 TestApplication::DEFAULT_SURFACE_WIDTH,
1649 TestApplication::DEFAULT_SURFACE_HEIGHT,
1650 TestApplication::DEFAULT_HORIZONTAL_DPI,
1651 TestApplication::DEFAULT_VERTICAL_DPI,
1655 tet_infoline("Check the damaged rect with partial update and texture change");
1657 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1659 std::vector<Rect<int32_t>> damagedRects;
1660 Rect<int32_t> clippingRect;
1662 Geometry geometry = CreateQuadGeometry();
1663 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1664 Renderer renderer = Renderer::New(geometry, shader);
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);
1674 Actor actor = Actor::New();
1675 actor.AddRenderer(renderer);
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);
1682 damagedRects.clear();
1683 application.SendNotification();
1684 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1685 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
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);
1696 damagedRects.clear();
1697 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1698 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1700 // Ensure the damaged rect is empty
1701 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1703 // Set another texture
1704 textureSet.SetTexture(0u, texture2);
1706 damagedRects.clear();
1707 application.SendNotification();
1708 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1709 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
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);
1720 damagedRects.clear();
1721 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1722 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1724 // Ensure the damaged rect is empty
1725 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);