| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#ifndef _TVG_LOAD_MODULE_H_ |
| 24 |
#define _TVG_LOAD_MODULE_H_ |
| 25 |
|
| 26 |
#include <atomic> |
| 27 |
#include "tvgCommon.h" |
| 28 |
#include "tvgRender.h" |
| 29 |
#include "tvgInlist.h" |
| 30 |
|
| 31 |
|
| 32 |
struct LoadModule |
| 33 |
{ |
| 34 |
INLIST_ITEM(LoadModule); |
| 35 |
|
| 36 |
|
| 37 |
union { |
| 38 |
uintptr_t hashkey; |
| 39 |
char* hashpath = nullptr; |
| 40 |
}; |
| 41 |
|
| 42 |
FileType type; |
| 43 |
atomic<uint16_t> sharing{}; |
| 44 |
bool readied = false; |
| 45 |
bool pathcache = false; |
| 46 |
|
| 47 |
LoadModule(FileType type) : type(type) {} |
| 48 |
virtual ~LoadModule() |
| 49 |
{ |
| 50 |
if (pathcache) free(hashpath); |
| 51 |
} |
| 52 |
|
| 53 |
virtual bool open(const string& path) { return false; } |
| 54 |
virtual bool open(const char* data, uint32_t size, bool copy) { return false; } |
| 55 |
virtual bool resize(Paint* paint, float w, float h) { return false; } |
| 56 |
virtual void sync() {}; |
| 57 |
|
| 58 |
virtual bool read() |
| 59 |
{ |
| 60 |
if (readied) return false; |
| 61 |
readied = true; |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
bool cached() |
| 66 |
{ |
| 67 |
if (hashkey) return true; |
| 68 |
return false; |
| 69 |
} |
| 70 |
|
| 71 |
virtual bool close() |
| 72 |
{ |
| 73 |
if (sharing == 0) return true; |
| 74 |
--sharing; |
| 75 |
return false; |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
struct ImageLoader : LoadModule |
| 81 |
{ |
| 82 |
static atomic<ColorSpace> cs; |
| 83 |
|
| 84 |
float w = 0, h = 0; |
| 85 |
RenderSurface surface; |
| 86 |
|
| 87 |
ImageLoader(FileType type) : LoadModule(type) {} |
| 88 |
|
| 89 |
virtual bool animatable() { return false; } |
| 90 |
virtual Paint* paint() { return nullptr; } |
| 91 |
|
| 92 |
virtual RenderSurface* bitmap() |
| 93 |
{ |
| 94 |
if (surface.data) return &surface; |
| 95 |
return nullptr; |
| 96 |
} |
| 97 |
}; |
| 98 |
|
| 99 |
|
| 100 |
struct FontMetrics |
| 101 |
{ |
| 102 |
|
| 103 |
float minw; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
struct FontLoader : LoadModule |
| 108 |
{ |
| 109 |
FontLoader(FileType type) : LoadModule(type) {} |
| 110 |
|
| 111 |
using LoadModule::read; |
| 112 |
|
| 113 |
virtual bool read(Shape* shape, char* text, FontMetrics& out) = 0; |
| 114 |
virtual float transform(Paint* paint, FontMetrics& mertrics, float fontSize, bool italic) = 0; |
| 115 |
}; |
| 116 |
|
| 117 |
#endif |