common loader: code refactoring.

replace from Scene to Paint at the internal interface.

Picture doesn't need to know the returned Node type.
base class, Paint is enough to in the data passing.
This commit is contained in:
Hermet Park 2021-07-28 13:40:45 +09:00 committed by Hermet Park
parent f7f241cff5
commit 3cb0caf2c4
6 changed files with 10 additions and 11 deletions

View file

@ -40,13 +40,13 @@ public:
virtual ~LoadModule() {}
virtual bool open(const string& path) { /* Not supported */ return false; };
virtual bool open(const char* data, uint32_t size, bool copy) { /* Not supported */ return false; };
virtual bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) { /* Not supported */ return false; };
virtual bool open(const string& path) { return false; };
virtual bool open(const char* data, uint32_t size, bool copy) { return false; };
virtual bool open(const uint32_t* data, uint32_t w, uint32_t h, bool copy) { return false; };
virtual bool read() = 0;
virtual bool close() = 0;
virtual const uint32_t* pixels() { return nullptr; };
virtual unique_ptr<Scene> scene() { return nullptr; };
virtual unique_ptr<Paint> paint() { return nullptr; };
};
}

View file

@ -112,9 +112,8 @@ struct Picture::Impl
{
if (loader) {
if (!paint) {
auto scene = loader->scene();
if (scene) {
paint = scene.release();
if (auto p = loader->paint()) {
paint = p.release();
loader->close();
if (w != loader->w && h != loader->h) resize();
if (paint) return RenderUpdateFlag::None;

View file

@ -2885,7 +2885,7 @@ bool SvgLoader::close()
}
unique_ptr<Scene> SvgLoader::scene()
unique_ptr<Paint> SvgLoader::paint()
{
this->done();
if (root) return move(root);

View file

@ -49,7 +49,7 @@ public:
bool close() override;
void run(unsigned tid) override;
unique_ptr<Scene> scene() override;
unique_ptr<Paint> paint() override;
private:
void clear();

View file

@ -125,7 +125,7 @@ void TvgLoader::run(unsigned tid)
if (!root) clear();
}
unique_ptr<Scene> TvgLoader::scene()
unique_ptr<Paint> TvgLoader::paint()
{
this->done();
if (root) return move(root);

View file

@ -45,7 +45,7 @@ public:
bool close() override;
void run(unsigned tid) override;
unique_ptr<Scene> scene() override;
unique_ptr<Paint> paint() override;
private:
void clear();