DynamicLoading
History Key
- New content
Removed content
Recent Versions
Choose two versions to compare, or click the link to view it.
Revision
- 2008/11/8
- Add DOM API
Introduction
MadButterfly is a SVG-based toolkit designed for user interface. However, loading SVG directly will spend significant time in parsing the XML document. The MadButterfly translate the XML into a C source file in order to reduce the overhead. Currently, the translated C source file is linked into the executable directly. This limit the possibility to chage the SVG without recompiling the executable. This document will propose a framework to load SVG file dynamically.
In addition, we will discuss how to implement SVG by using the DOM operation so that we can use it to implement animation in tyhe C level.
Dynamic loading
Each SVG file will be translated into a C file which contains a constructor and a destructor. The constructor contains C representation of the SVG file. It will create an instance of the rdman_object_t. The destructor will free the rdman_object_)t and all resources attached to it.
In addition, a public variable Plugin should be defined as
void *Plugin[] = {xxx_constructor,xxx_destructor};
The C source file will be compiled as a relinkable object file by using
gcc -shared -o svg.so svg.c
The svg.so can be loaded latter by the rdman_loadSVG latter.The rdman_loadSVG will return an class factory object of type rdman_factory_t.
typedef struct {
rdman_object_t *(*new)();
void (*free)(rdman_object_t *);
} rdman_factory_t;
We can use the following code to load and create an object for a SVG file.
class = rdman_loadSVG("svg.so");
obj = class->new();
dobj = obj->duplicate(obj);
....
dobj->free(dobj);
obj->free(obj);
Comparing to the current implementation. There are some differences.
- We will always return rdman_object_t. It means that we don't need to generate the header files any more.
- We need to create an class instance by using the *.so file. The call to the constructor must through the class instance.
- The DOM should be implemented in order to access the internal of the SVG object since the header file will not be generated any more.The rdman_object_t will be the elementary unit of the DOM tree.