From: Seungho Baek Date: Wed, 3 Nov 2021 14:21:43 +0000 (+0900) Subject: Resolve memory issues of webp X-Git-Tag: dali_2.0.52~4^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git;a=commitdiff_plain;h=c822dae30eecb58678d075a875624cab7dac4843 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: Ibbee0b5e410edeb49593648975e19eeb82e929f8 Signed-off-by: Seungho Baek --- 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..707821b 100644 --- a/dali/internal/imaging/common/webp-loading.cpp +++ b/dali/internal/imaging/common/webp-loading.cpp @@ -116,7 +116,7 @@ public: { Internal::Platform::FileReader fileReader(mUrl); fp = fileReader.GetFile(); - if(fp == NULL) + if(fp == nullptr) { return false; } @@ -165,28 +165,37 @@ 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) + if(&mWebPData != nullptr) { mWebPData.bytes = nullptr; WebPDataInit(&mWebPData); } - if(mWebPAnimDecoder) + if(mWebPAnimDecoder != nullptr) { WebPAnimDecoderDelete(mWebPAnimDecoder); + mWebPAnimDecoder = nullptr; } #endif - free((void*)mBuffer); - mBuffer = nullptr; + if(mBuffer != nullptr) + { + 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