summaryrefslogtreecommitdiffstats
path: root/thirdparty/thorvg/src/renderer/tvgLoadModule.h
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/thorvg/src/renderer/tvgLoadModule.h')
-rw-r--r--thirdparty/thorvg/src/renderer/tvgLoadModule.h74
1 files changed, 56 insertions, 18 deletions
diff --git a/thirdparty/thorvg/src/renderer/tvgLoadModule.h b/thirdparty/thorvg/src/renderer/tvgLoadModule.h
index 29ceba3fcc..0ea766395e 100644
--- a/thirdparty/thorvg/src/renderer/tvgLoadModule.h
+++ b/thirdparty/thorvg/src/renderer/tvgLoadModule.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020 - 2023 the ThorVG project. All rights reserved.
+ * Copyright (c) 2020 - 2024 the ThorVG project. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,35 +24,73 @@
#define _TVG_LOAD_MODULE_H_
#include "tvgRender.h"
+#include "tvgInlist.h"
-namespace tvg
-{
-class LoadModule
+struct LoadModule
{
-public:
- float w = 0, h = 0; //default image size
- ColorSpace cs = ColorSpace::Unsupported; //must be clarified at open()
+ INLIST_ITEM(LoadModule);
+
+ //Use either hashkey(data) or hashpath(path)
+ uint64_t hashkey;
+ char* hashpath = nullptr;
- virtual ~LoadModule() {}
+ FileType type; //current loader file type
+ uint16_t sharing = 0; //reference count
+ bool readied = false; //read done already.
+
+ LoadModule(FileType type) : type(type) {}
+ virtual ~LoadModule()
+ {
+ free(hashpath);
+ }
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; }
-
- //Override this if the vector-format has own resizing policy.
virtual bool resize(Paint* paint, float w, float h) { return false; }
-
- virtual bool animatable() { return false; } //true if this loader supports animation.
virtual void sync() {}; //finish immediately if any async update jobs.
- virtual bool read() = 0;
- virtual bool close() = 0;
+ virtual bool read()
+ {
+ if (readied) return false;
+ readied = true;
+ return true;
+ }
- virtual unique_ptr<Surface> bitmap() { return nullptr; }
- virtual unique_ptr<Paint> paint() { return nullptr; }
+ virtual bool close()
+ {
+ if (sharing == 0) return true;
+ --sharing;
+ return false;
+ }
};
-}
+
+struct ImageLoader : LoadModule
+{
+ float w = 0, h = 0; //default image size
+ Surface surface;
+
+ ImageLoader(FileType type) : LoadModule(type) {}
+
+ virtual bool animatable() { return false; } //true if this loader supports animation.
+ virtual Paint* paint() { return nullptr; }
+
+ virtual Surface* bitmap()
+ {
+ if (surface.data) return &surface;
+ return nullptr;
+ }
+};
+
+
+struct FontLoader : LoadModule
+{
+ float scale = 1.0f;
+
+ FontLoader(FileType type) : LoadModule(type) {}
+
+ virtual bool request(Shape* shape, char* text, bool italic = false) = 0;
+};
#endif //_TVG_LOAD_MODULE_H_