From fa559234c4db4402fa1b6e7c6b49cacb948805c6 Mon Sep 17 00:00:00 2001 From: Seungho Baek Date: Wed, 3 Nov 2021 23:23:18 +0900 Subject: [PATCH] [Tizen] Resolve memory issues of webp - If an webp is loaded by image-visual, the image-visual loads only the first frame and renders. - So, after the first frame is loaded, the opened file should be closed. - And if a single frame webp is loaded by animated-image-visual, we don't keep the buffer until the loader is deleted. Change-Id: I2f8f962cdf97ef0146321e8b206d93a7a66522db Signed-off-by: Seungho Baek --- dali/internal/imaging/common/loader-webp.cpp | 2 ++ dali/internal/imaging/common/webp-loading.cpp | 34 +++++++++++++++++---------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/dali/internal/imaging/common/loader-webp.cpp b/dali/internal/imaging/common/loader-webp.cpp index e388712..da82a89 100644 --- a/dali/internal/imaging/common/loader-webp.cpp +++ b/dali/internal/imaging/common/loader-webp.cpp @@ -130,6 +130,7 @@ bool LoadWebpHeader(const Dali::ImageLoader::Input& input, unsigned int& width, WebPAnimDecoderGetInfo(webPAnimDecoder, &webPAnimInfo); width = webPAnimInfo.canvas_width; height = webPAnimInfo.canvas_height; + ReleaseResource(webPData, webPAnimDecoder); return true; } } @@ -225,6 +226,7 @@ bool LoadBitmapFromWebp(const Dali::ImageLoader::Input& input, Dali::Devel::Pixe bitmap = Dali::Devel::PixelBuffer::New(webPAnimInfo.canvas_width, webPAnimInfo.canvas_height, Dali::Pixel::RGBA8888); const int32_t bufferSize = webPAnimInfo.canvas_width * webPAnimInfo.canvas_height * sizeof(uint32_t); memcpy(bitmap.GetBuffer(), frameBuffer, bufferSize); + ReleaseResource(webPData, webPAnimDecoder); return true; } } diff --git a/dali/internal/imaging/common/webp-loading.cpp b/dali/internal/imaging/common/webp-loading.cpp index dc758fa..1ba9cc4 100644 --- a/dali/internal/imaging/common/webp-loading.cpp +++ b/dali/internal/imaging/common/webp-loading.cpp @@ -165,14 +165,7 @@ public: return false; } - // Moveable but not copyable - - Impl(const Impl&) = delete; - Impl& operator=(const Impl&) = delete; - Impl(Impl&&) = default; - Impl& operator=(Impl&&) = default; - - ~Impl() + void ReleaseResource() { #ifdef DALI_ANIMATED_WEBP_ENABLED if(&mWebPData != NULL) @@ -180,13 +173,29 @@ public: mWebPData.bytes = nullptr; WebPDataInit(&mWebPData); } - if(mWebPAnimDecoder) + if(mWebPAnimDecoder != nullptr) { WebPAnimDecoderDelete(mWebPAnimDecoder); + mWebPAnimDecoder = nullptr; } #endif - free((void*)mBuffer); - mBuffer = nullptr; + if(mBuffer != NULL) + { + free((void*)mBuffer); + mBuffer = nullptr; + } + } + + // Moveable but not copyable + + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + Impl(Impl&&) = default; + Impl& operator=(Impl&&) = default; + + ~Impl() + { + ReleaseResource(); } std::string mUrl; @@ -279,8 +288,9 @@ Dali::Devel::PixelBuffer WebPLoading::LoadFrame(uint32_t frameIndex) const int32_t imageBufferSize = width * height * sizeof(uint8_t) * channelNumber; memcpy(pixelBuffer.GetBuffer(), frameBuffer, imageBufferSize); free((void*)frameBuffer); - return pixelBuffer; } + mImpl->ReleaseResource(); + return pixelBuffer; } #endif -- 2.7.4