Merge "Simplified actor depth traversal algorithms" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Texture.cpp
index 436bcdc..5613e17 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
@@ -17,6 +17,7 @@
 
 #include <dali/public-api/dali-core.h>
 #include <dali-test-suite-utils.h>
+#include <test-native-image.h>
 
 using namespace Dali;
 
@@ -52,6 +53,22 @@ int UtcDaliTextureNew02(void)
   END_TEST;
 }
 
+int UtcDaliTextureNew03(void)
+{
+  TestApplication application;
+
+  // Create a native image source.
+  TestNativeImageNoExtPointer testNativeImage = TestNativeImageNoExt::New( 64u, 64u );
+
+  // Create a texture from the native image source.
+  Texture nativeTexture = Texture::New( *testNativeImage );
+
+  // Check the texture was created OK.
+  DALI_TEST_CHECK( nativeTexture );
+
+  END_TEST;
+}
+
 int UtcDaliTextureCopyConstructor(void)
 {
   TestApplication application;
@@ -449,6 +466,98 @@ int UtcDaliTextureUpload05(void)
   END_TEST;
 }
 
+int UtcDaliTextureUpload06(void)
+{
+  TestApplication application;
+
+  //Create the texture
+  unsigned int width(64);
+  unsigned int height(64);
+  tet_infoline( "Creating a Texure with an alpha channel" );
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, 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, Pixel::RGB888, 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();
+
+  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 <<", "<< 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;
+}
+
 int UtcDaliTextureGenerateMipmaps(void)
 {
   TestApplication application;
@@ -503,3 +612,41 @@ int UtcDaliTextureGetHeight(void)
   END_TEST;
 }
 
+int UtcDaliTextureContextLoss(void)
+{
+  tet_infoline("UtcDaliTextureContextLoss\n");
+  TestApplication application; // Default config: DALI_DISCARDS_ALL_DATA
+
+  //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;
+}
+