[dali_1.9.6] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
index 1eada6c..0222064 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
  */
 
 #include <dali/public-api/dali-core.h>
+#include <dali/devel-api/images/pixel-data-devel.h>
 #include <dali-test-suite-utils.h>
 #include <test-native-image.h>
 
@@ -408,12 +409,122 @@ int UtcDaliTextureUpload04(void)
 
 int UtcDaliTextureUpload05(void)
 {
+  Pixel::Format COMPRESSED_PIXEL_FORMATS[] =
+  {
+    Pixel::COMPRESSED_R11_EAC,
+    Pixel::COMPRESSED_SIGNED_R11_EAC,
+    Pixel::COMPRESSED_RG11_EAC,
+    Pixel::COMPRESSED_SIGNED_RG11_EAC,
+    Pixel::COMPRESSED_RGB8_ETC2,
+    Pixel::COMPRESSED_SRGB8_ETC2,
+    Pixel::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+    Pixel::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
+    Pixel::COMPRESSED_RGBA8_ETC2_EAC,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
+    Pixel::COMPRESSED_RGB8_ETC1,
+    Pixel::COMPRESSED_RGB_PVRTC_4BPPV1,
+    Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_5x4_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_5x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_6x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_6x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_8x8_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x5_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x6_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x8_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_10x10_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_12x10_KHR,
+    Pixel::COMPRESSED_RGBA_ASTC_12x12_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,
+    Pixel::COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
+  };
+  const unsigned int NUMBER_OF_COMPRESSED_PIXEL_FORMATS = sizeof( COMPRESSED_PIXEL_FORMATS ) / sizeof( Pixel::Format );
+
+  for( unsigned int index = 0; index < NUMBER_OF_COMPRESSED_PIXEL_FORMATS; ++index )
+  {
+    TestApplication application;
+
+    //Create a texture with a compressed format
+    unsigned int width(64);
+    unsigned int height(64);
+    Texture texture = Texture::New( TextureType::TEXTURE_2D, COMPRESSED_PIXEL_FORMATS[index], width, height );
+
+    application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+    application.SendNotification();
+    application.Render();
+
+    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+    //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    }
+
+    //Upload data to the texture
+    callStack.Reset();
+
+    unsigned int bufferSize( width * height * 4 );
+    unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelData );
+    application.SendNotification();
+    application.Render();
+
+    //CompressedTexImage2D should be called to upload the data
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    }
+
+    //Upload part of the texture
+    callStack.Reset();
+    bufferSize =  width * height * 2;
+    buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, COMPRESSED_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
+    application.SendNotification();
+    application.Render();
+
+    //CompressedTexSubImage2D should be called to upload the data
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
+    }
+
+    application.GetGlAbstraction().ResetTextureCallStack();
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureUpload06(void)
+{
   TestApplication application;
 
-  //Create a texture with a compressed format
+  //Create the texture
   unsigned int width(64);
   unsigned int height(64);
-  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, width, height );
+  tet_infoline( "Creating a Texure with an alpha channel" );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
 
   application.GetGlAbstraction().EnableTextureCallTrace(true);
 
@@ -422,46 +533,132 @@ int UtcDaliTextureUpload05(void)
 
   TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
 
-  //CompressedTexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
+  tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
   {
     std::stringstream out;
     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
   }
 
-  //Upload data to the texture
+  tet_infoline( "Upload data to the texture" );
   callStack.Reset();
 
-  unsigned int bufferSize( width * height * 4 );
+  tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
+  unsigned int bufferSize( width * height * 3 );
   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
   texture.Upload( pixelData );
   application.SendNotification();
   application.Render();
 
-  //CompressedTexImage2D should be called to upload the data
+  tet_infoline( "TexImage2D should be called to upload the data" );
   {
     std::stringstream out;
     out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexImage2D", out.str().c_str() ) );
+    DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
   }
 
-  //Upload part of the texture
-  callStack.Reset();
-  bufferSize =  width * height * 2;
-  buffer = reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
-  PixelData pixelDataSubImage = PixelData::New( buffer, bufferSize, width, height, Pixel::COMPRESSED_RGBA_ASTC_4x4_KHR, PixelData::FREE );
-  texture.Upload( pixelDataSubImage, 0u, 0u, width/2, height/2, width/2, height/2 );
+  END_TEST;
+}
+
+int UtcDaliTextureUpload07(void)
+{
+  Pixel::Format FLOATING_POINT_PIXEL_FORMATS[] =
+  {
+    Pixel::RGB16F,
+    Pixel::RGB32F,
+  };
+  const unsigned int NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS = sizeof( FLOATING_POINT_PIXEL_FORMATS ) / sizeof( Pixel::Format );
+
+  for( unsigned int index = 0; index < NUMBER_OF_FLOATING_POINT_PIXEL_FORMATS; ++index )
+  {
+    TestApplication application;
+
+    //Create the texture
+    unsigned int width(64);
+    unsigned int height(64);
+    tet_infoline( "Creating a floating point texture" );
+    Texture texture = Texture::New( TextureType::TEXTURE_2D, FLOATING_POINT_PIXEL_FORMATS[index], width, height );
+
+    application.GetGlAbstraction().EnableTextureCallTrace(true);
+
+    application.SendNotification();
+    application.Render();
+
+    TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+    tet_infoline( "TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu" );
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+
+    tet_infoline( "Upload data to the texture" );
+    callStack.Reset();
+
+    tet_infoline( "Creating a RGB pixel buffer and adding that to the texture to ensure it is handled correctly" );
+    unsigned int bufferSize( width * height * 3 );
+    unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+    PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, FLOATING_POINT_PIXEL_FORMATS[index], PixelData::FREE );
+    texture.Upload( pixelData );
+    application.SendNotification();
+    application.Render();
+
+    tet_infoline( "TexImage2D should be called to upload the data" );
+    {
+      std::stringstream out;
+      out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+      DALI_TEST_CHECK( callStack.FindMethodAndParams("TexImage2D", out.str().c_str() ) );
+    }
+  }
+
+  END_TEST;
+}
+
+int UtcDaliTextureUploadSmallerThanSize(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+
+  application.GetGlAbstraction().EnableTextureCallTrace(true);
+
   application.SendNotification();
   application.Render();
 
-  //CompressedTexSubImage2D should be called to upload the data
+  TraceCallStack& callStack = application.GetGlAbstraction().GetTextureTrace();
+
+  //TexImage2D should be called with a null pointer to reserve storage for the texture in the gpu
   {
     std::stringstream out;
-    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width/2 << ", " <<  height/2 << ", " << width/2 << ", " <<  height/2;
-    DALI_TEST_CHECK( callStack.FindMethodAndParams("CompressedTexSubImage2D", out.str().c_str() ) );
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << width <<", "<< height;
+    std::string params;
+    DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexImage2D", params ) );
+    DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
   }
 
+  //Upload data to the texture
+  callStack.Reset();
+
+  unsigned int bufferSize( width * height * 4 );
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width/2, height/2, Pixel::RGBA8888, PixelData::FREE );
+  texture.Upload( pixelData );
+  application.SendNotification();
+  application.Render();
+
+  //TexImage2D should be called to upload the data
+  {
+    std::stringstream out;
+    out << GL_TEXTURE_2D <<", "<< 0u << ", " << 0u << ", " <<  0u << ", " << width/2 << ", " <<  height/2;
+    std::string params;
+    DALI_TEST_CHECK( callStack.FindMethodAndGetParameters("TexSubImage2D", params ) );
+    DALI_TEST_EQUALS( out.str(), params, TEST_LOCATION );
+  }
 
   END_TEST;
 }
@@ -520,3 +717,41 @@ int UtcDaliTextureGetHeight(void)
   END_TEST;
 }
 
+int UtcDaliTextureContextLoss(void)
+{
+  tet_infoline("UtcDaliTextureContextLoss\n");
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  DALI_TEST_CHECK( texture );
+
+  application.SendNotification();
+  application.Render(16);
+
+  // Lose & regain context (in render 'thread')
+  application.ResetContext();
+  DALI_TEST_CHECK( texture );
+
+  END_TEST;
+}
+
+int UtcDaliNativeImageTexture(void)
+{
+  TestApplication application;
+  tet_infoline( "UtcDaliNativeImageTexture" );
+
+  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
+  Texture texture = Texture::New( *(imageInterface.Get()) );
+  DALI_TEST_CHECK( texture );
+
+  application.SendNotification();
+  application.Render(16);
+
+  DALI_TEST_CHECK( texture );
+
+  END_TEST;
+}
+