renderer/loader: optimization++

removed the internal unique_ptr usage to reduce the binary size(-553)
This commit is contained in:
Hermet Park 2023-12-08 14:17:19 +09:00 committed by Hermet Park
parent 20fdcb4ccd
commit a9d39eaf56
12 changed files with 23 additions and 25 deletions

View file

@ -292,12 +292,12 @@ bool LottieLoader::read()
} }
unique_ptr<Paint> LottieLoader::paint() Paint* LottieLoader::paint()
{ {
this->done(); this->done();
if (!comp) return nullptr; if (!comp) return nullptr;
comp->initiated = true; comp->initiated = true;
return cast<Paint>(comp->scene); return comp->scene;
} }

View file

@ -54,7 +54,7 @@ public:
bool open(const char* data, uint32_t size, const std::string& rpath, bool copy) override; bool open(const char* data, uint32_t size, const std::string& rpath, bool copy) override;
bool resize(Paint* paint, float w, float h) override; bool resize(Paint* paint, float w, float h) override;
bool read() override; bool read() override;
unique_ptr<Paint> paint() override; Paint* paint() override;
//Frame Controls //Frame Controls
bool frame(float no) override; bool frame(float no) override;

View file

@ -3555,7 +3555,7 @@ void SvgLoader::run(unsigned tid)
//According to the SVG standard the value of the width/height of the viewbox set to 0 disables rendering //According to the SVG standard the value of the width/height of the viewbox set to 0 disables rendering
if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vw) <= FLT_EPSILON || fabsf(vh) <= FLT_EPSILON)) { if ((viewFlag & SvgViewFlag::Viewbox) && (fabsf(vw) <= FLT_EPSILON || fabsf(vh) <= FLT_EPSILON)) {
TVGLOG("SVG", "The <viewBox> width and/or height set to 0 - rendering disabled."); TVGLOG("SVG", "The <viewBox> width and/or height set to 0 - rendering disabled.");
root = Scene::gen(); root = Scene::gen().release();
return; return;
} }
@ -3748,8 +3748,8 @@ bool SvgLoader::close()
} }
unique_ptr<Paint> SvgLoader::paint() Paint* SvgLoader::paint()
{ {
this->done(); this->done();
return std::move(root); return root;
} }

View file

@ -35,7 +35,7 @@ public:
uint32_t size = 0; uint32_t size = 0;
SvgLoaderData loaderData; SvgLoaderData loaderData;
unique_ptr<Scene> root; Scene* root = nullptr;
bool copy = false; bool copy = false;
@ -49,7 +49,7 @@ public:
bool read() override; bool read() override;
bool close() override; bool close() override;
unique_ptr<Paint> paint() override; Paint* paint() override;
private: private:
SvgViewFlag viewFlag = SvgViewFlag::None; SvgViewFlag viewFlag = SvgViewFlag::None;

View file

@ -845,7 +845,7 @@ static void _updateInvalidViewSize(const Scene* scene, Box& vBox, float& w, floa
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
unique_ptr<Scene> svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag) Scene* svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag)
{ {
//TODO: aspect ratio is valid only if viewBox was set //TODO: aspect ratio is valid only if viewBox was set
@ -880,5 +880,5 @@ unique_ptr<Scene> svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, fl
loaderData.doc->node.doc.w = w; loaderData.doc->node.doc.w = w;
loaderData.doc->node.doc.h = h; loaderData.doc->node.doc.h = h;
return root; return root.release();
} }

View file

@ -25,6 +25,6 @@
#include "tvgCommon.h" #include "tvgCommon.h"
unique_ptr<Scene> svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag); Scene* svgSceneBuild(SvgLoaderData& loaderData, Box vBox, float w, float h, AspectRatioAlign align, AspectRatioMeetOrSlice meetOrSlice, const string& svgPath, SvgViewFlag viewFlag);
#endif //_TVG_SVG_SCENE_BUILDER_H_ #endif //_TVG_SVG_SCENE_BUILDER_H_

View file

@ -483,7 +483,7 @@ static Paint* _parsePaint(TvgBinBlock baseBlock)
/* External Class Implementation */ /* External Class Implementation */
/************************************************************************/ /************************************************************************/
unique_ptr<Scene> TvgBinInterpreter::run(const char *ptr, const char* end) Scene* TvgBinInterpreter::run(const char *ptr, const char* end)
{ {
auto scene = Scene::gen(); auto scene = Scene::gen();
if (!scene) return nullptr; if (!scene) return nullptr;
@ -498,5 +498,5 @@ unique_ptr<Scene> TvgBinInterpreter::run(const char *ptr, const char* end)
ptr = block.end; ptr = block.end;
} }
return scene; return scene.release();
} }

View file

@ -39,7 +39,7 @@ public:
/* ptr: points the tvg binary body (after header) /* ptr: points the tvg binary body (after header)
end: end of the tvg binary data */ end: end of the tvg binary data */
virtual unique_ptr<Scene> run(const char* ptr, const char* end) = 0; virtual Scene* run(const char* ptr, const char* end) = 0;
}; };
@ -47,7 +47,7 @@ public:
class TvgBinInterpreter : public TvgBinInterpreterBase class TvgBinInterpreter : public TvgBinInterpreterBase
{ {
public: public:
unique_ptr<Scene> run(const char* ptr, const char* end) override; Scene* run(const char* ptr, const char* end) override;
}; };

View file

@ -103,8 +103,6 @@ bool TvgLoader::readHeader()
void TvgLoader::run(unsigned tid) void TvgLoader::run(unsigned tid)
{ {
if (root) root.reset();
auto data = const_cast<char*>(ptr); auto data = const_cast<char*>(ptr);
if (compressed) { if (compressed) {
@ -223,8 +221,8 @@ bool TvgLoader::read()
} }
unique_ptr<Paint> TvgLoader::paint() Paint* TvgLoader::paint()
{ {
this->done(); this->done();
return std::move(root); return root;
} }

View file

@ -34,7 +34,7 @@ public:
const char* ptr = nullptr; const char* ptr = nullptr;
uint32_t size = 0; uint32_t size = 0;
uint16_t version = 0; uint16_t version = 0;
unique_ptr<Scene> root = nullptr; Scene* root = nullptr;
TvgBinInterpreterBase* interpreter = nullptr; TvgBinInterpreterBase* interpreter = nullptr;
uint32_t uncompressedSize = 0; uint32_t uncompressedSize = 0;
uint32_t compressedSize = 0; uint32_t compressedSize = 0;
@ -51,7 +51,7 @@ public:
bool read() override; bool read() override;
bool resize(Paint* paint, float w, float h) override; bool resize(Paint* paint, float w, float h) override;
unique_ptr<Paint> paint() override; Paint* paint() override;
private: private:
bool readHeader(); bool readHeader();

View file

@ -70,7 +70,7 @@ struct LoadModule
} }
virtual unique_ptr<Surface> bitmap() { return nullptr; } virtual unique_ptr<Surface> bitmap() { return nullptr; }
virtual unique_ptr<Paint> paint() { return nullptr; } virtual Paint* paint() { return nullptr; }
}; };
} }

View file

@ -30,8 +30,8 @@ RenderUpdateFlag Picture::Impl::load()
{ {
if (loader) { if (loader) {
if (!paint) { if (!paint) {
if (auto p = loader->paint()) { paint = loader->paint();
paint = p.release(); if (paint) {
if (w != loader->w || h != loader->h) { if (w != loader->w || h != loader->h) {
if (!resizing) { if (!resizing) {
w = loader->w; w = loader->w;
@ -40,7 +40,7 @@ RenderUpdateFlag Picture::Impl::load()
loader->resize(paint, w, h); loader->resize(paint, w, h);
resizing = false; resizing = false;
} }
if (paint) return RenderUpdateFlag::None; return RenderUpdateFlag::None;
} }
} else loader->sync(); } else loader->sync();