From 9fb66973f0f56c1a5da1d9640e16fa253a5ad664 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 27 Apr 2023 18:34:16 +0900 Subject: [PATCH] common picture: tiny optimization. Currently Picture doesn't allow to change the image source. Thus reloading is not non-sense. --- src/lib/tvgPicture.cpp | 2 +- src/lib/tvgPictureImpl.h | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/lib/tvgPicture.cpp b/src/lib/tvgPicture.cpp index 98ffe901..897f7849 100644 --- a/src/lib/tvgPicture.cpp +++ b/src/lib/tvgPicture.cpp @@ -107,7 +107,7 @@ Result Picture::size(float* w, float* h) const noexcept const uint32_t* Picture::data(uint32_t* w, uint32_t* h) const noexcept { //Try it, If not loaded yet. - pImpl->reload(); + pImpl->load(); if (pImpl->loader) { if (w) *w = static_cast(pImpl->loader->w); diff --git a/src/lib/tvgPictureImpl.h b/src/lib/tvgPictureImpl.h index 6dbb423c..a186633f 100644 --- a/src/lib/tvgPictureImpl.h +++ b/src/lib/tvgPictureImpl.h @@ -85,7 +85,7 @@ struct Picture::Impl return ret; } - uint32_t reload() + uint32_t load() { if (loader) { if (!paint) { @@ -103,10 +103,11 @@ struct Picture::Impl if (paint) return RenderUpdateFlag::None; } } - free(surface); - if ((surface = loader->bitmap().release())) { - loader->close(); - return RenderUpdateFlag::Image; + if (!surface) { + if ((surface = loader->bitmap().release())) { + loader->close(); + return RenderUpdateFlag::Image; + } } } return RenderUpdateFlag::None; @@ -128,7 +129,7 @@ struct Picture::Impl RenderData update(RenderMethod &renderer, const RenderTransform* pTransform, uint32_t opacity, Array& clips, RenderUpdateFlag pFlag, bool clipper) { - auto flag = reload(); + auto flag = load(); if (surface) { auto transform = resizeTransform(pTransform); @@ -265,7 +266,7 @@ struct Picture::Impl Paint* duplicate() { - reload(); + load(); auto ret = Picture::gen(); @@ -297,7 +298,7 @@ struct Picture::Impl Iterator* iterator() { - reload(); + load(); return new PictureIterator(paint); } };