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/devel-api/threading/thread.h>
21 #include <dali/integration-api/pixel-data-integ.h>
22 #include <dali/integration-api/texture-integ.h>
23 #include <dali/public-api/dali-core.h>
24 #include <test-native-image.h>
28 #include <mesh-builder.h>
30 void texture_set_startup(void)
32 test_return_value = TET_UNDEF;
35 void texture_set_cleanup(void)
37 test_return_value = TET_PASS;
40 int UtcDaliTextureNew01(void)
42 TestApplication application;
44 unsigned int width(64);
45 unsigned int height(64);
46 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
48 DALI_TEST_CHECK(texture);
52 int UtcDaliTextureNew02(void)
54 TestApplication application;
56 DALI_TEST_CHECK(!texture);
60 int UtcDaliTextureNew03(void)
62 TestApplication application;
64 // Create a native image source.
65 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
67 // Create a texture from the native image source.
68 Texture nativeTexture = Texture::New(*testNativeImage);
70 // Check the texture was created OK.
71 DALI_TEST_CHECK(nativeTexture);
76 int UtcDaliTextureNew04(void)
78 TestApplication application;
80 Texture texture = Texture::New(TextureType::TEXTURE_2D);
82 DALI_TEST_CHECK(texture);
86 int UtcDaliTextureNew05(void)
88 TestApplication application;
90 uint32_t expectResourceId = 11u;
92 Texture texture = Integration::NewTextureWithResourceId(TextureType::TEXTURE_2D, expectResourceId);
94 DALI_TEST_CHECK(texture);
96 uint32_t currentResourceId = Integration::GetTextureResourceId(texture);
98 DALI_TEST_EQUALS(currentResourceId, expectResourceId, TEST_LOCATION);
103 int UtcDaliTextureCopyConstructor(void)
105 TestApplication application;
107 unsigned int width(64);
108 unsigned int height(64);
109 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
111 Texture textureCopy(texture);
113 DALI_TEST_CHECK(textureCopy);
118 int UtcDaliTextureAssignmentOperator(void)
120 TestApplication application;
121 unsigned int width(64);
122 unsigned int height(64);
123 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
126 DALI_TEST_CHECK(!texture2);
129 DALI_TEST_CHECK(texture2);
134 int UtcDaliTextureMoveConstructor(void)
136 TestApplication application;
139 uint32_t height = 64;
140 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
141 DALI_TEST_CHECK(texture);
142 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
143 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
144 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
146 Texture move = std::move(texture);
147 DALI_TEST_CHECK(move);
148 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
149 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
150 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
151 DALI_TEST_CHECK(!texture);
156 int UtcDaliTextureMoveAssignment(void)
158 TestApplication application;
161 uint32_t height = 64;
162 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
163 DALI_TEST_CHECK(texture);
164 DALI_TEST_EQUALS(1, texture.GetBaseObject().ReferenceCount(), TEST_LOCATION);
165 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
166 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
169 move = std::move(texture);
170 DALI_TEST_CHECK(move);
171 DALI_TEST_EQUALS(1, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
172 DALI_TEST_EQUALS(move.GetWidth(), width, TEST_LOCATION);
173 DALI_TEST_EQUALS(move.GetHeight(), height, TEST_LOCATION);
174 DALI_TEST_CHECK(!texture);
179 int UtcDaliTextureDownCast01(void)
181 TestApplication application;
182 unsigned int width(64);
183 unsigned int height(64);
184 Texture texture = Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
186 BaseHandle handle(texture);
187 Texture texture2 = Texture::DownCast(handle);
188 DALI_TEST_CHECK(texture2);
193 int UtcDaliTextureDownCast02(void)
195 TestApplication application;
197 Handle handle = Handle::New(); // Create a custom object
198 Texture texture = Texture::DownCast(handle);
199 DALI_TEST_CHECK(!texture);
203 int UtcDaliTextureUpload01(void)
205 TestApplication application;
208 unsigned int width(64);
209 unsigned int height(64);
210 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
212 application.GetGlAbstraction().EnableTextureCallTrace(true);
214 application.SendNotification();
215 application.Render();
217 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
219 //Upload data to the texture
222 unsigned int bufferSize(width * height * 4);
223 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
224 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
225 texture.Upload(pixelData);
226 application.SendNotification();
227 application.Render();
229 //TexImage2D should be called to upload the data
231 std::stringstream out;
232 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
233 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
236 //Upload part of the texture
238 bufferSize = width * height;
239 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
240 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
241 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
242 application.SendNotification();
243 application.Render();
245 //TexSubImage2D should be called to upload the data
247 std::stringstream out;
248 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
249 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
255 int UtcDaliTextureUpload02(void)
257 TestApplication application;
260 unsigned int width(64);
261 unsigned int height(64);
262 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
264 application.GetGlAbstraction().EnableTextureCallTrace(true);
266 application.SendNotification();
267 application.Render();
269 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
271 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
272 for(unsigned int i(0); i < 6; ++i)
274 std::stringstream out;
275 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
276 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
279 unsigned int bufferSize(width * height * 4);
280 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
281 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
283 //Upload data to the POSITIVE_X face of the texture
287 texture.Upload(pixelData, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
288 application.SendNotification();
289 application.Render();
291 //TexImage2D should be called to upload the data to the POSITIVE_X face
293 std::stringstream out;
294 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
295 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
299 //Upload data to the NEGATIVE_X face of the texture
303 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
304 application.SendNotification();
305 application.Render();
307 //TexImage2D should be called to upload the data to the NEGATIVE_X face
309 std::stringstream out;
310 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
311 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
315 //Upload data to the POSITIVE_Y face of the texture
318 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
319 application.SendNotification();
320 application.Render();
322 //TexImage2D should be called to upload the data to the POSITIVE_Y face
324 std::stringstream out;
325 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
326 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
330 //Upload data to the NEGATIVE_Y face of the texture
333 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
334 application.SendNotification();
335 application.Render();
337 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
339 std::stringstream out;
340 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
341 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
345 //Upload data to the POSITIVE_Z face of the texture
348 texture.Upload(pixelData, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
349 application.SendNotification();
350 application.Render();
352 //TexImage2D should be called to upload the data to the POSITIVE_Z face
354 std::stringstream out;
355 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
356 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
360 //Upload data to the NEGATIVE_Z face of the texture
363 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
364 application.SendNotification();
365 application.Render();
367 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
369 std::stringstream out;
370 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
371 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
378 int UtcDaliTextureUpload03(void)
380 TestApplication application;
383 unsigned int width(64);
384 unsigned int height(64);
385 unsigned int widthMipmap1(32);
386 unsigned int heightMipmap1(32);
388 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
390 application.GetGlAbstraction().EnableTextureCallTrace(true);
392 application.SendNotification();
393 application.Render();
395 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
397 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
399 std::stringstream out;
400 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
401 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
404 //Upload data to the texture mipmap 0 and mipmap 1
407 unsigned int bufferSize(width * height * 4);
408 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
409 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
410 texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
412 bufferSize = widthMipmap1 * heightMipmap1 * 4;
413 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
414 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
415 texture.Upload(pixelDataMipmap1, 0u, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
416 application.SendNotification();
417 application.Render();
419 //TexImage2D should be called to upload the data to mipmaps 0 and 1
421 std::stringstream out;
422 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
423 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
426 std::stringstream out;
427 out << GL_TEXTURE_2D << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
428 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
434 int UtcDaliTextureUpload04(void)
436 TestApplication application;
439 unsigned int width(64);
440 unsigned int height(64);
441 unsigned int widthMipmap1(32);
442 unsigned int heightMipmap1(32);
444 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
446 application.GetGlAbstraction().EnableTextureCallTrace(true);
447 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
449 //Upload data to the NEGATIVE_X face mipmap 0 and mipmap 1
450 unsigned int bufferSize(width * height * 4);
451 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
452 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
453 texture.Upload(pixelData, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
455 bufferSize = widthMipmap1 * heightMipmap1 * 4;
456 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
457 PixelData pixelDataMipmap1 = PixelData::New(buffer, bufferSize, widthMipmap1, heightMipmap1, Pixel::RGBA8888, PixelData::FREE);
458 texture.Upload(pixelDataMipmap1, CubeMapLayer::NEGATIVE_X, 1u, 0u, 0u, widthMipmap1, heightMipmap1);
459 application.SendNotification();
460 application.Render();
462 //TexImage2D should be called to upload the data to mipmaps 0 and 1
464 std::stringstream out;
465 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
466 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
469 std::stringstream out;
470 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 1u << ", " << widthMipmap1 << ", " << heightMipmap1;
471 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
477 int UtcDaliTextureUpload05(void)
479 Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
481 Pixel::COMPRESSED_R11_EAC,
482 Pixel::COMPRESSED_SIGNED_R11_EAC,
483 Pixel::COMPRESSED_RG11_EAC,
484 Pixel::COMPRESSED_SIGNED_RG11_EAC,
485 Pixel::COMPRESSED_RGB8_ETC2,
486 Pixel::COMPRESSED_SRGB8_ETC2,
487 Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
488 Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
489 Pixel::COMPRESSED_RGBA8_ETC2_EAC,
490 Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
491 Pixel::COMPRESSED_RGB8_ETC1,
492 Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
493 Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
494 Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
495 Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
496 Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
497 Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
498 Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
499 Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
500 Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
501 Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
502 Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
503 Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
504 Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
505 Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
506 Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
507 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
508 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
509 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
510 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
511 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
512 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
513 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
514 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
515 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
516 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
517 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
518 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
519 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
520 Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
522 const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof(COMPRESSED_PIXEL_FORMATS) / sizeof(Pixel::Format);
524 for(unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index)
526 TestApplication application;
528 //Create a texture with a compressed format
529 unsigned int width(64);
530 unsigned int height(64);
531 Texture texture = CreateTexture(TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height);
533 application.GetGlAbstraction().EnableTextureCallTrace(true);
535 application.SendNotification();
536 application.Render();
538 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
540 tet_infoline("CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
542 std::stringstream out;
543 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
544 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
547 //Upload data to the texture
550 unsigned int bufferSize(width * height * 4);
551 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
552 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
553 texture.Upload(pixelData);
554 application.SendNotification();
555 application.Render();
557 //CompressedTexImage2D should be called to upload the data
559 std::stringstream out;
560 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
561 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str()));
564 //Upload part of the texture
566 bufferSize = width * height;
567 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
568 PixelData pixelDataSubImage = PixelData::New(buffer, bufferSize, width / 2, height / 2, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE);
569 texture.Upload(pixelDataSubImage, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
570 application.SendNotification();
571 application.Render();
573 //CompressedTexSubImage2D should be called to upload the data
575 std::stringstream out;
576 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
577 DALI_TEST_CHECK(callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str()));
580 application.GetGlAbstraction().ResetTextureCallStack();
586 int UtcDaliTextureUpload06(void)
588 TestApplication application;
591 unsigned int width(64);
592 unsigned int height(64);
593 tet_infoline("Creating a Texure with an alpha channel");
594 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
596 application.GetGlAbstraction().EnableTextureCallTrace(true);
598 application.SendNotification();
599 application.Render();
601 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
603 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
605 std::stringstream out;
606 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
607 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
610 tet_infoline("Upload data to the texture");
613 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
614 unsigned int bufferSize(width * height * 3);
615 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
616 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
617 texture.Upload(pixelData);
618 application.SendNotification();
619 application.Render();
621 tet_infoline("TexImage2D should be called to upload the data");
623 std::stringstream out;
624 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
625 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
631 int UtcDaliTextureUpload07(void)
633 Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
638 const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof(FLOATING_POINT_PIXEL_FORMATS) / sizeof(Pixel::Format);
640 for(unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index)
642 TestApplication application;
645 unsigned int width(64);
646 unsigned int height(64);
647 tet_infoline("Creating a floating point texture");
648 Texture texture = CreateTexture(TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height);
650 application.GetGlAbstraction().EnableTextureCallTrace(true);
652 application.SendNotification();
653 application.Render();
655 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
657 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
659 std::stringstream out;
660 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
661 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
664 tet_infoline("Upload data to the texture");
667 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
668 unsigned int bufferSize(width * height * 3);
669 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
670 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE);
671 texture.Upload(pixelData);
672 application.SendNotification();
673 application.Render();
675 tet_infoline("TexImage2D should be called to upload the data");
677 std::stringstream out;
678 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
679 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
686 int UtcDaliTextureUpload08(void)
688 TestApplication application;
690 //Create the texture without pixel information
691 tet_infoline("Creating a Texure without any size/format information");
692 Texture texture = Texture::New(TextureType::TEXTURE_2D);
694 application.GetGlAbstraction().EnableTextureCallTrace(true);
696 application.SendNotification();
697 application.Render();
699 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
701 tet_infoline("TexImage2D should not be called with a null pointer to reserve storage for the texture in the gpu");
702 DALI_TEST_CHECK(!callStack.FindMethod("GenTextures"));
703 DALI_TEST_CHECK(!callStack.FindMethod("TexImage2D"));
705 tet_infoline("Upload data to the texture");
706 unsigned int width(64);
707 unsigned int height(64);
710 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
711 unsigned int bufferSize(width * height * 3);
712 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
713 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE);
714 texture.Upload(pixelData);
715 application.SendNotification();
716 application.Render();
718 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
719 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
720 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
721 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
723 tet_infoline("TexImage2D should be called to upload the data");
724 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
726 std::stringstream out;
727 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
728 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
731 tet_infoline("Upload another data to the texture");
736 tet_infoline("Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly");
737 bufferSize = width * height * 4;
738 buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
739 pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
740 texture.Upload(pixelData);
741 application.SendNotification();
742 application.Render();
744 tet_infoline("TexImage2D should be generate new graphics, and be called to upload the data");
745 DALI_TEST_CHECK(callStack.FindMethod("GenTextures"));
747 std::stringstream out;
748 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
749 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
752 tet_infoline("GetWidth / GetHeight / GetPixelFormat will return uploaded value");
753 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
754 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
755 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
760 int UtcDaliTextureUpload09(void)
762 TestApplication application;
766 uint32_t height(64u);
767 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
769 application.GetGlAbstraction().EnableTextureCallTrace(true);
771 application.SendNotification();
772 application.Render();
774 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
776 //Upload data to the texture
779 uint32_t bufferSize(width * height * 4u);
780 uint8_t* buffer = reinterpret_cast<uint8_t*>(malloc(bufferSize));
783 PixelData pixelData = Dali::Integration::NewPixelDataWithReleaseAfterUpload(buffer, bufferSize, width, height, 0u, Pixel::RGBA8888, PixelData::FREE);
784 DALI_TEST_CHECK(pixelData);
786 Dali::Integration::PixelDataBuffer pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
788 DALI_TEST_EQUALS(pixelDataBuffer.bufferSize, bufferSize, TEST_LOCATION);
789 DALI_TEST_EQUALS(pixelDataBuffer.buffer[0], static_cast<uint8_t>('a'), TEST_LOCATION);
791 texture.Upload(pixelData);
793 application.SendNotification();
794 application.Render();
796 //TexImage2D should be called to upload the data
798 std::stringstream out;
799 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
800 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
803 // Check whether the buffer become nullptr after texture uploaded.
804 pixelDataBuffer = Dali::Integration::GetPixelDataBuffer(pixelData);
806 DALI_TEST_CHECK(pixelDataBuffer.buffer == nullptr);
811 int UtcDaliTextureUploadSubPixelData01(void)
813 TestApplication application;
816 unsigned int width(64);
817 unsigned int height(64);
818 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
820 application.GetGlAbstraction().EnableTextureCallTrace(true);
822 application.SendNotification();
823 application.Render();
825 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
827 //Upload data to the texture
830 uint32_t bufferWidth = width * 2;
831 uint32_t bufferHeight = height * 2;
832 uint32_t bufferXOffset = width;
833 uint32_t bufferYOffset = height;
835 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
836 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
837 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
838 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height);
839 application.SendNotification();
840 application.Render();
842 //TexImage2D should be called to upload the data
844 std::stringstream out;
845 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
846 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
849 //Upload part of the texture
851 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width / 2, height / 2, 0u, 0u, width / 2, height / 2, width / 2, height / 2);
852 application.SendNotification();
853 application.Render();
855 //TexSubImage2D should be called to upload the data
857 std::stringstream out;
858 out << GL_TEXTURE_2D << ", " << 0u << ", " << width / 2 << ", " << height / 2 << ", " << width / 2 << ", " << height / 2;
859 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexSubImage2D", out.str().c_str()));
865 int UtcDaliTextureUploadSubPixelData02(void)
867 TestApplication application;
870 unsigned int width(64);
871 unsigned int height(64);
872 Texture texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
874 application.GetGlAbstraction().EnableTextureCallTrace(true);
876 application.SendNotification();
877 application.Render();
879 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
881 tet_infoline("TexImage2D should be called six times with a null pointer to reserve storage for the six textures of the cube map");
882 for(unsigned int i(0); i < 6; ++i)
884 std::stringstream out;
885 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X + i << ", " << 0u << ", " << width << ", " << height;
886 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
889 uint32_t bufferWidth = width * 2;
890 uint32_t bufferHeight = height * 2;
891 uint32_t bufferXOffset = width;
892 uint32_t bufferYOffset = height;
894 unsigned int bufferSize(bufferWidth * bufferHeight * 4);
895 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
896 PixelData pixelData = PixelData::New(buffer, bufferSize, bufferWidth, bufferHeight, Pixel::RGBA8888, PixelData::FREE);
898 //Upload data to the POSITIVE_X face of the texture
902 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_X, 0u, 0u, 0u, width, height);
903 application.SendNotification();
904 application.Render();
906 //TexImage2D should be called to upload the data to the POSITIVE_X face
908 std::stringstream out;
909 out << GL_TEXTURE_CUBE_MAP_POSITIVE_X << ", " << 0u << ", " << width << ", " << height;
910 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
914 //Upload data to the NEGATIVE_X face of the texture
918 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_X, 0u, 0u, 0u, width, height);
919 application.SendNotification();
920 application.Render();
922 //TexImage2D should be called to upload the data to the NEGATIVE_X face
924 std::stringstream out;
925 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_X << ", " << 0u << ", " << width << ", " << height;
926 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
930 //Upload data to the POSITIVE_Y face of the texture
933 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Y, 0u, 0u, 0u, width, height);
934 application.SendNotification();
935 application.Render();
937 //TexImage2D should be called to upload the data to the POSITIVE_Y face
939 std::stringstream out;
940 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Y << ", " << 0u << ", " << width << ", " << height;
941 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
945 //Upload data to the NEGATIVE_Y face of the texture
948 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Y, 0u, 0u, 0u, width, height);
949 application.SendNotification();
950 application.Render();
952 //TexImage2D should be called to upload the data to the NEGATIVE_Y face
954 std::stringstream out;
955 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Y << ", " << 0u << ", " << width << ", " << height;
956 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
960 //Upload data to the POSITIVE_Z face of the texture
963 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::POSITIVE_Z, 0u, 0u, 0u, width, height);
964 application.SendNotification();
965 application.Render();
967 //TexImage2D should be called to upload the data to the POSITIVE_Z face
969 std::stringstream out;
970 out << GL_TEXTURE_CUBE_MAP_POSITIVE_Z << ", " << 0u << ", " << width << ", " << height;
971 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
975 //Upload data to the NEGATIVE_Z face of the texture
978 DevelTexture::UploadSubPixelData(texture, pixelData, bufferXOffset, bufferYOffset, width, height, CubeMapLayer::NEGATIVE_Z, 0u, 0u, 0u, width, height);
979 application.SendNotification();
980 application.Render();
982 //TexImage2D should be called to upload the data to the NEGATIVE_Z face
984 std::stringstream out;
985 out << GL_TEXTURE_CUBE_MAP_NEGATIVE_Z << ", " << 0u << ", " << width << ", " << height;
986 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
993 int UtcDaliTextureUploadPixelFormats(void)
995 TestApplication application;
996 application.GetGlAbstraction().EnableTextureCallTrace(true);
999 unsigned int width(64);
1000 unsigned int height(64);
1002 std::vector<Pixel::Format> formats =
1018 Pixel::DEPTH_UNSIGNED_INT,
1020 Pixel::DEPTH_STENCIL,
1024 Pixel::CHROMINANCE_U,
1025 Pixel::CHROMINANCE_V};
1027 for(auto format : formats)
1029 tet_infoline("Creating a Texure with a new or recent format");
1030 Texture texture = CreateTexture(TextureType::TEXTURE_2D, format, width, height);
1032 application.SendNotification();
1033 application.Render();
1035 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1037 tet_infoline("TexImage2D should be called twice per texture");
1038 DALI_TEST_EQUALS(callStack.CountMethod("TexImage2D"), 2, TEST_LOCATION);
1040 std::stringstream out;
1041 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1042 DALI_TEST_CHECK(callStack.FindMethodAndParams("TexImage2D", out.str().c_str()));
1050 int UtcDaliTextureUploadSmallerThanSize(void)
1052 TestApplication application;
1054 //Create the texture
1055 unsigned int width(64);
1056 unsigned int height(64);
1057 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1059 application.GetGlAbstraction().EnableTextureCallTrace(true);
1061 application.SendNotification();
1062 application.Render();
1064 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1065 callStack.EnableLogging(true);
1066 TraceCallStack& texParamCallStack = application.GetGlAbstraction().GetTexParameterTrace();
1067 texParamCallStack.EnableLogging(true);
1069 tet_infoline("TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu");
1071 std::stringstream out;
1072 out << GL_TEXTURE_2D << ", " << 0u << ", " << width << ", " << height;
1074 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexImage2D", params));
1075 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1078 //Upload data to the texture
1081 unsigned int bufferSize(width * height * 4);
1082 unsigned char* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1083 PixelData pixelData = PixelData::New(buffer, bufferSize, width / 2, height / 2, Pixel::RGBA8888, PixelData::FREE);
1084 texture.Upload(pixelData);
1085 application.SendNotification();
1086 application.Render();
1088 //TexSubImage2D should be called to upload the data
1090 std::stringstream out;
1091 out << GL_TEXTURE_2D << ", " << 0u << ", " << 0u << ", " << 0u << ", " << width / 2 << ", " << height / 2;
1093 DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("TexSubImage2D", params));
1094 DALI_TEST_EQUALS(out.str(), params, TEST_LOCATION);
1099 int UtcDaliTextureGenerateMipmaps(void)
1101 TestApplication application;
1102 unsigned int width(64);
1103 unsigned int height(64);
1105 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1106 texture.GenerateMipmaps();
1108 Texture textureCubemap = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1109 textureCubemap.GenerateMipmaps();
1111 application.GetGlAbstraction().EnableTextureCallTrace(true);
1112 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1113 application.SendNotification();
1114 application.Render();
1117 std::stringstream out;
1118 out << GL_TEXTURE_2D;
1119 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1122 std::stringstream out;
1123 out << GL_TEXTURE_CUBE_MAP;
1124 DALI_TEST_CHECK(callStack.FindMethodAndParams("GenerateMipmap", out.str().c_str()));
1130 int UtcDaliTextureGenerateMipmapsCompressedFormat(void)
1132 TestApplication application;
1133 unsigned int width(64);
1134 unsigned int height(64);
1136 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA8_ETC2_EAC, width, height);
1137 texture.GenerateMipmaps();
1139 application.GetGlAbstraction().EnableTextureCallTrace(true);
1140 TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
1141 application.SendNotification();
1142 application.Render();
1144 // Check generate mipmap didn't called when we use compressed pixel format.
1145 DALI_TEST_CHECK(!callStack.FindMethod("GenerateMipmap"));
1150 int UtcDaliTextureGetWidth(void)
1152 TestApplication application;
1153 unsigned int width(64);
1154 unsigned int height(64);
1156 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1157 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1161 int UtcDaliTextureGetHeight(void)
1163 TestApplication application;
1164 unsigned int width(64);
1165 unsigned int height(64);
1167 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1168 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1173 int UtcDaliTextureGetTextureType(void)
1175 TestApplication application;
1176 unsigned int width(64);
1177 unsigned int height(64);
1179 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1180 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_2D, TEST_LOCATION);
1182 texture = CreateTexture(TextureType::TEXTURE_CUBE, Pixel::RGBA8888, width, height);
1183 DALI_TEST_EQUALS(Integration::GetTextureType(texture), TextureType::TEXTURE_CUBE, TEST_LOCATION);
1188 int UtcDaliTextureSetSize(void)
1190 TestApplication application;
1191 unsigned int width(64);
1192 unsigned int height(64);
1194 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1195 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1196 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1197 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1202 Integration::SetTextureSize(texture, ImageDimensions(width, height));
1203 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1204 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1205 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1207 application.SendNotification();
1208 application.Render();
1213 int UtcDaliTextureSetPixelFormat(void)
1215 TestApplication application;
1216 unsigned int width(64);
1217 unsigned int height(64);
1219 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1220 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1221 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1222 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1224 Integration::SetTexturePixelFormat(texture, Pixel::BGRA5551);
1225 DALI_TEST_EQUALS(texture.GetWidth(), width, TEST_LOCATION);
1226 DALI_TEST_EQUALS(texture.GetHeight(), height, TEST_LOCATION);
1227 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::BGRA5551, TEST_LOCATION);
1229 application.SendNotification();
1230 application.Render();
1235 int UtcDaliTextureContextLoss(void)
1237 tet_infoline("UtcDaliTextureContextLoss\n");
1238 TestApplication application;
1240 //Create the texture
1241 unsigned int width(64);
1242 unsigned int height(64);
1243 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1244 DALI_TEST_CHECK(texture);
1246 application.SendNotification();
1247 application.Render(16);
1249 // Lose & regain context (in render 'thread')
1250 application.ResetContext();
1251 DALI_TEST_CHECK(texture);
1256 int UtcDaliNativeImageTexture01(void)
1258 TestApplication application;
1259 tet_infoline("UtcDaliNativeImageTexture01");
1261 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1263 Texture texture = Texture::New(*(imageInterface.Get()));
1264 Actor actor = CreateRenderableActor(texture, "", "");
1265 application.GetScene().Add(actor);
1267 DALI_TEST_CHECK(texture);
1269 application.SendNotification();
1270 application.Render(16);
1272 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1273 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 0, TEST_LOCATION);
1274 DALI_TEST_EQUALS(actor.GetProperty(Actor::Property::SIZE), Property::Value(Vector3(16, 16, 0)), TEST_LOCATION);
1276 UnparentAndReset(actor);
1278 application.SendNotification();
1279 application.Render(16);
1281 application.SendNotification();
1282 application.Render(16);
1284 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION);
1285 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1290 int UtcDaliNativeImageTexture02(void)
1292 TestApplication application;
1293 tet_infoline("UtcDaliNativeImageTexture02 - test error on TargetTexture");
1295 TestNativeImagePointer imageInterface = TestNativeImage::New(16, 16);
1296 imageInterface->mTargetTextureError = 1u;
1298 Texture texture = Texture::New(*(imageInterface.Get()));
1299 Actor actor = CreateRenderableActor(texture, "", "");
1300 application.GetScene().Add(actor);
1302 DALI_TEST_CHECK(texture);
1304 application.SendNotification();
1305 application.Render(16);
1307 // Expect 2 attempts to create the texture - once when adding the texture
1308 // to the scene-graph, and again since that failed, during the Bind.
1309 // The second one succeeds (TargetTexture only errors once)
1310 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1311 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 1, TEST_LOCATION);
1313 UnparentAndReset(actor);
1315 application.SendNotification();
1316 application.Render(16);
1318 application.SendNotification();
1319 application.Render(16);
1321 // Expect that there are no further calls to create/destroy resource
1322 DALI_TEST_EQUALS(imageInterface->mExtensionCreateCalls, 2, TEST_LOCATION);
1323 DALI_TEST_EQUALS(imageInterface->mExtensionDestroyCalls, 2, TEST_LOCATION);
1328 int UtcDaliTextureGenerateMipmapsNegative(void)
1330 TestApplication application;
1331 Dali::Texture instance;
1334 instance.GenerateMipmaps();
1335 DALI_TEST_CHECK(false); // Should not get here
1339 DALI_TEST_CHECK(true); // We expect an assert
1344 int UtcDaliTextureUploadNegative01(void)
1346 TestApplication application;
1347 Dali::Texture instance;
1350 Dali::PixelData arg1;
1351 instance.Upload(arg1);
1352 DALI_TEST_CHECK(false); // Should not get here
1356 DALI_TEST_CHECK(true); // We expect an assert
1361 int UtcDaliTextureUploadNegative02(void)
1363 TestApplication application;
1364 Dali::Texture instance;
1367 Dali::PixelData arg1;
1368 unsigned int arg2(0u);
1369 unsigned int arg3(0u);
1370 unsigned int arg4(0u);
1371 unsigned int arg5(0u);
1372 unsigned int arg6(0u);
1373 unsigned int arg7(0u);
1374 instance.Upload(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1375 DALI_TEST_CHECK(false); // Should not get here
1379 DALI_TEST_CHECK(true); // We expect an assert
1384 int UtcDaliTextureGetWidthNegative(void)
1386 TestApplication application;
1387 Dali::Texture instance;
1390 instance.GetWidth();
1391 DALI_TEST_CHECK(false); // Should not get here
1395 DALI_TEST_CHECK(true); // We expect an assert
1400 int UtcDaliTextureGetHeightNegative(void)
1402 TestApplication application;
1403 Dali::Texture instance;
1406 instance.GetHeight();
1407 DALI_TEST_CHECK(false); // Should not get here
1411 DALI_TEST_CHECK(true); // We expect an assert
1416 int UtcDaliTextureCheckNativeP(void)
1418 TestApplication application;
1419 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1420 Texture nativeTexture = Texture::New(*testNativeImage);
1422 DALI_TEST_CHECK(nativeTexture);
1423 DALI_TEST_CHECK(DevelTexture::IsNative(nativeTexture));
1427 int UtcDaliTextureCheckNativeN1(void)
1429 TestApplication application;
1430 unsigned int width(64);
1431 unsigned int height(64);
1432 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1434 DALI_TEST_CHECK(texture);
1435 DALI_TEST_CHECK(!DevelTexture::IsNative(texture));
1439 int UtcDaliTextureCheckNativeN2(void)
1441 TestApplication application;
1445 bool native = DevelTexture::IsNative(texture);
1446 DALI_TEST_CHECK(native != native);
1450 DALI_TEST_CHECK(true);
1455 int UtcDaliTextureApplyFragShaderP1(void)
1457 TestApplication application;
1458 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1459 Texture nativeTexture = Texture::New(*testNativeImage);
1460 DALI_TEST_CHECK(nativeTexture);
1462 const std::string baseFragShader =
1463 "varying mediump vec4 uColor;\n"
1465 " gl_FragColor=uColor;\n"
1467 std::string fragShader = baseFragShader;
1468 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1470 std::string fragPrefix = "#extension GL_OES_EGL_image_external:require\n";
1472 DALI_TEST_CHECK(applied);
1473 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1474 DALI_TEST_CHECK(fragShader.compare(fragPrefix + baseFragShader) == 0);
1475 DALI_TEST_CHECK(!fragShader.empty());
1479 int UtcDaliTextureApplyFragShaderP2(void)
1481 TestApplication application;
1482 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1483 Texture nativeTexture = Texture::New(*testNativeImage);
1484 DALI_TEST_CHECK(nativeTexture);
1486 const std::string baseFragShader =
1487 "varying mediump vec4 uColor;\n"
1488 "varying vec2 vTexCoord;\n"
1489 "uniform sampler2D uNative;\n"
1491 " gl_FragColor=uColor*texture2D(uNative, vTexCoord);\n"
1493 std::string fragShader = baseFragShader;
1494 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1496 DALI_TEST_CHECK(applied);
1497 DALI_TEST_CHECK(baseFragShader.compare(fragShader));
1498 DALI_TEST_CHECK(!fragShader.empty());
1499 DALI_TEST_CHECK(fragShader.find("samplerExternalOES") < fragShader.length());
1503 int UtcDaliTextureApplyFragShaderN1(void)
1505 TestApplication application;
1506 TestNativeImagePointer testNativeImage = TestNativeImage::New(64u, 64u);
1507 Texture nativeTexture = Texture::New(*testNativeImage);
1508 DALI_TEST_CHECK(nativeTexture);
1510 std::string fragShader;
1511 bool applied = DevelTexture::ApplyNativeFragmentShader(nativeTexture, fragShader);
1513 DALI_TEST_CHECK(!applied);
1514 DALI_TEST_CHECK(fragShader.empty());
1518 int UtcDaliTextureApplyFragShaderN2(void)
1520 TestApplication application;
1521 unsigned int width(64);
1522 unsigned int height(64);
1523 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1525 const std::string baseFragShader =
1526 "varying mediump vec4 uColor;\n"
1528 " gl_FragColor=uColor;\n"
1530 std::string fragShader = baseFragShader;
1531 bool applied = DevelTexture::ApplyNativeFragmentShader(texture, fragShader);
1533 DALI_TEST_CHECK(!applied);
1534 DALI_TEST_CHECK(!baseFragShader.compare(fragShader));
1538 int UtcDaliTextureGetPixelFormat(void)
1540 TestApplication application;
1542 uint32_t height(64);
1544 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1545 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION);
1547 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGB888, width, height);
1548 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION);
1550 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::L8, width, height);
1551 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::L8, TEST_LOCATION);
1553 texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::CHROMINANCE_U, width, height);
1554 DALI_TEST_EQUALS(texture.GetPixelFormat(), Pixel::CHROMINANCE_U, TEST_LOCATION);
1559 int utcDaliTexturePartialUpdate01(void)
1561 TestApplication application(
1562 TestApplication::DEFAULT_SURFACE_WIDTH,
1563 TestApplication::DEFAULT_SURFACE_HEIGHT,
1564 TestApplication::DEFAULT_HORIZONTAL_DPI,
1565 TestApplication::DEFAULT_VERTICAL_DPI,
1569 tet_infoline("Check the damaged rect with partial update and texture change");
1571 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1573 std::vector<Rect<int32_t>> damagedRects;
1574 Rect<int32_t> clippingRect;
1576 Geometry geometry = CreateQuadGeometry();
1577 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1578 Renderer renderer = Renderer::New(geometry, shader);
1582 Texture texture = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1583 TextureSet textureSet = TextureSet::New();
1584 textureSet.SetTexture(0u, texture);
1585 renderer.SetTextures(textureSet);
1587 Actor actor = Actor::New();
1588 actor.AddRenderer(renderer);
1590 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1591 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1592 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1593 application.GetScene().Add(actor);
1595 damagedRects.clear();
1596 application.SendNotification();
1597 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1598 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1601 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1602 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1603 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1604 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1605 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1606 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1607 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1609 damagedRects.clear();
1610 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1611 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1613 // Ensure the damaged rect is empty
1614 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1617 uint32_t bufferSize(width * height * 4);
1618 uint8_t* buffer = reinterpret_cast<unsigned char*>(malloc(bufferSize));
1619 PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, Pixel::RGBA8888, PixelData::FREE);
1620 texture.Upload(pixelData);
1622 damagedRects.clear();
1623 application.SendNotification();
1624 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1625 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1628 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates
1629 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1630 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1631 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1632 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1633 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1634 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1636 damagedRects.clear();
1637 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1638 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1640 // Ensure the damaged rect is empty
1641 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1646 int utcDaliTexturePartialUpdate02(void)
1648 TestApplication application(
1649 TestApplication::DEFAULT_SURFACE_WIDTH,
1650 TestApplication::DEFAULT_SURFACE_HEIGHT,
1651 TestApplication::DEFAULT_HORIZONTAL_DPI,
1652 TestApplication::DEFAULT_VERTICAL_DPI,
1656 tet_infoline("Check the damaged rect with partial update and texture change");
1658 const TestGlAbstraction::ScissorParams& glScissorParams(application.GetGlAbstraction().GetScissorParams());
1660 std::vector<Rect<int32_t>> damagedRects;
1661 Rect<int32_t> clippingRect;
1663 Geometry geometry = CreateQuadGeometry();
1664 Shader shader = Shader::New("vertexSrc", "fragmentSrc");
1665 Renderer renderer = Renderer::New(geometry, shader);
1669 Texture texture1 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1670 Texture texture2 = CreateTexture(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
1671 TextureSet textureSet = TextureSet::New();
1672 textureSet.SetTexture(0u, texture1);
1673 renderer.SetTextures(textureSet);
1675 Actor actor = Actor::New();
1676 actor.AddRenderer(renderer);
1678 actor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1679 actor.SetProperty(Actor::Property::POSITION, Vector3(16.0f, 16.0f, 0.0f));
1680 actor.SetProperty(Actor::Property::SIZE, Vector3(16.0f, 16.0f, 0.0f));
1681 application.GetScene().Add(actor);
1683 damagedRects.clear();
1684 application.SendNotification();
1685 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1686 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1689 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1690 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1691 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1692 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1693 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1694 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1695 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1697 damagedRects.clear();
1698 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1699 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1701 // Ensure the damaged rect is empty
1702 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1704 // Set another texture
1705 textureSet.SetTexture(0u, texture2);
1707 damagedRects.clear();
1708 application.SendNotification();
1709 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1710 DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
1713 clippingRect = Rect<int32_t>(16, 768, 32, 32); // in screen coordinates, includes 3 last frames updates
1714 DALI_TEST_EQUALS<Rect<int32_t>>(clippingRect, damagedRects[0], TEST_LOCATION);
1715 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1716 DALI_TEST_EQUALS(clippingRect.x, glScissorParams.x, TEST_LOCATION);
1717 DALI_TEST_EQUALS(clippingRect.y, glScissorParams.y, TEST_LOCATION);
1718 DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
1719 DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
1721 damagedRects.clear();
1722 application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
1723 application.RenderWithPartialUpdate(damagedRects, clippingRect);
1725 // Ensure the damaged rect is empty
1726 DALI_TEST_EQUALS(damagedRects.size(), 0, TEST_LOCATION);
1731 int UtcDaliTextureDestructWorkerThreadN(void)
1733 TestApplication application;
1734 tet_infoline("UtcDaliTextureDestructWorkerThreadN Test, for line coverage");
1738 class TestThread : public Thread
1743 tet_printf("Run TestThread\n");
1744 // Upload at worker thread
1745 uint8_t* rawBuffer = new uint8_t[4];
1746 Dali::PixelData pixelData = Dali::PixelData::New(rawBuffer, 4, 1, 1, Pixel::RGBA8888, Dali::PixelData::DELETE_ARRAY);
1748 // Use try-catch to avoid memory leak false alarm
1751 // Upload, GenerateMipmaps, and Destruct at worker thread.
1752 mTexture.Upload(pixelData);
1753 mTexture.GenerateMipmaps();
1761 Dali::Texture mTexture;
1765 Dali::Texture texture = Dali::Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::RGBA8888, 100, 100);
1766 thread.mTexture = std::move(texture);
1778 DALI_TEST_CHECK(true);