From 77d6674e6b85e424b85cbd99579eda25bdf647fb Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Fri, 21 Oct 2016 17:48:39 +0100 Subject: [PATCH] Fix a bug in texture where Upload without parameters was incorrectly using the Texture size rather than the PixelData size Change-Id: Id50e635172be645f9be17a3bac5fad7320dab766 --- .../test-trace-call-stack.cpp | 15 +++++++ .../dali-test-suite-utils/test-trace-call-stack.h | 8 ++++ automated-tests/src/dali/utc-Dali-Texture.cpp | 47 ++++++++++++++++++++++ dali/internal/event/rendering/texture-impl.cpp | 2 +- 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.cpp index 0054e59..9b6e9a5 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.cpp @@ -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; diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h index e1882ea..c3f3358 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-trace-call-stack.h @@ -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 diff --git a/automated-tests/src/dali/utc-Dali-Texture.cpp b/automated-tests/src/dali/utc-Dali-Texture.cpp index 1eada6c..93965de 100644 --- a/automated-tests/src/dali/utc-Dali-Texture.cpp +++ b/automated-tests/src/dali/utc-Dali-Texture.cpp @@ -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( 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; diff --git a/dali/internal/event/rendering/texture-impl.cpp b/dali/internal/event/rendering/texture-impl.cpp index c0f658c..1b2bc63 100644 --- a/dali/internal/event/rendering/texture-impl.cpp +++ b/dali/internal/event/rendering/texture-impl.cpp @@ -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, -- 2.7.4