Fix a bug in texture where Upload without parameters was incorrectly using the Textur... 33/93333/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Fri, 21 Oct 2016 16:48:39 +0000 (17:48 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 26 Oct 2016 18:09:56 +0000 (19:09 +0100)
Change-Id: Id50e635172be645f9be17a3bac5fad7320dab766

automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.cpp
automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h
automated-tests/src/dali/utc-Dali-Texture.cpp
dali/internal/event/rendering/texture-impl.cpp

index 0054e59..9b6e9a5 100644 (file)
@@ -101,6 +101,21 @@ bool TraceCallStack::FindMethod(std::string method) const
   return found;
 }
 
+bool TraceCallStack::FindMethodAndGetParameters(std::string method, std::string& params ) const
+{
+  bool found = false;
+  for( size_t i=0; i < mCallStack.size(); i++ )
+  {
+    if( 0 == mCallStack[i].method.compare(method) )
+    {
+      found = true;
+      params = mCallStack[i].paramList;
+      break;
+    }
+  }
+  return found;
+}
+
 int TraceCallStack::CountMethod(std::string method) const
 {
   int numCalls = 0;
index e1882ea..c3f3358 100644 (file)
@@ -79,6 +79,14 @@ public:
   bool FindMethod(std::string method) const;
 
   /**
+   * Search for a method in the stack and return its parameters if found
+   * @param[in] method The name of the method
+   * @param[out] params of the method
+   * @return true if the method was in the stack
+   */
+  bool FindMethodAndGetParameters(std::string method, std::string& params ) const;
+
+  /**
    * Count how many times a method was called
    * @param[in] method The name of the method
    * @return The number of times it was called
index 1eada6c..93965de 100644 (file)
@@ -466,6 +466,53 @@ int UtcDaliTextureUpload05(void)
   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;
index c0f658c..1b2bc63 100644 (file)
@@ -95,7 +95,7 @@ NewTexture::~NewTexture()
 
 bool NewTexture::Upload( PixelDataPtr pixelData )
 {
-  return Upload( pixelData, 0u, 0u, 0u, 0u, mWidth, mHeight );
+  return Upload( pixelData, 0u, 0u, 0u, 0u, pixelData->GetWidth(), pixelData->GetHeight() );
 }
 
 bool NewTexture::Upload( PixelDataPtr pixelData,