summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--legacy/evas/evas.c.in30
-rw-r--r--legacy/evas/src/lib/Evas.h6
-rw-r--r--legacy/evas/src/lib/canvas/evas_callbacks.c138
-rw-r--r--legacy/evas/src/lib/include/evas_private.h12
-rw-r--r--legacy/evas/src/lib/main.c90
5 files changed, 237 insertions, 39 deletions
diff --git a/legacy/evas/evas.c.in b/legacy/evas/evas.c.in
index efab0aa23c..b50c552567 100644
--- a/legacy/evas/evas.c.in
+++ b/legacy/evas/evas.c.in
@@ -14,7 +14,7 @@ These routines are used for Evas Library interaction
14@author Carsten Haitzler <raster@rasterman.com> 14@author Carsten Haitzler <raster@rasterman.com>
15@author Till Adam <till@adam-lilienthal.de> 15@author Till Adam <till@adam-lilienthal.de>
16@author Steve Ireland <sireland@pobox.com> 16@author Steve Ireland <sireland@pobox.com>
17@date 2001-2002 17@date 2000-2002
18 18
19 19
20 20
@@ -238,18 +238,25 @@ To be documented...
238 238
239 239
240@todo Document API 240@todo Document API
241@todo Document Engine API
242@todo Add keyboard callbacks/event feeds and focus 241@todo Add keyboard callbacks/event feeds and focus
243@todo Make freetype optional and put in optional graymap font engine 242@todo Make freetype optional and put in optional graymap font engine
244@todo Add external image loaders (application provided callbacks to load)
245@todo Add loadable image loader module support (evas loads file.so)
246@todo Add external image lodaer modules (application proivdes path to file.so)
247@todo Define image load errors (and maybe have an error to string func)
248@todo Add ability to check image comments & disk format 243@todo Add ability to check image comments & disk format
249@todo Add immediate mode drawing commands to image objects 244@todo Define image load errors (and maybe have an error to string func)
250@todo Add text styles (outline etc.) 245@todo Add text styles (outline etc.)
251@todo Add font load query calls (so we know if a font load failed) 246@todo Add font load query calls (so we know if a font load failed)
252@todo Add font listing calls 247@todo Add font listing calls
248@todo Free images if object invisible (and put back in chache)
249@todo Check robustness of malloc/calloc/realloc failures.
250@todo Add memory use reduction code if any allocations fail
251@todo If image loads fails due to memory allocatue failure, load reduced res version
252@todo If image load fails due to memory allocation failure, try split it up into tiles and demand-load them
253@todo Add auto-detection of what engines to build based on system/libs etc.
254@todo Add overall engine configure parameters (so you can configure an engine with defaults with 1 configure option)
255@todo Document Engine API
256@todo Add external image loaders (application provided callbacks to load)
257@todo Add loadable image loader module support (evas loads file.so)
258@todo Add external image lodaer modules (application proivdes path to file.so)
259@todo Add immediate mode drawing commands to image objects
253@todo Add OpenGL GLX Engine 260@todo Add OpenGL GLX Engine
254@todo Add Win32 OpenGL Engine 261@todo Add Win32 OpenGL Engine
255@todo Add Apple OpenGL Engine 262@todo Add Apple OpenGL Engine
@@ -257,19 +264,12 @@ To be documented...
257@todo Add SDL Engine 264@todo Add SDL Engine
258@todo Add Symbian Engine 265@todo Add Symbian Engine
259@todo Add PalmOS Engine 266@todo Add PalmOS Engine
260@todo Fix FB engine to allocat vt and release properly 267@todo Fix FB engine to allocate vt and release properly
261@todo Add ellipse objects (circle, arc, ellipse etc.) 268@todo Add ellipse objects (circle, arc, ellipse etc.)
262@todo Add video/movie/animation objects 269@todo Add video/movie/animation objects
263@todo Make software engine draw lines & polys with aa 270@todo Make software engine draw lines & polys with aa
264@todo Add radial gradients to gradient objects 271@todo Add radial gradients to gradient objects
265@todo Allow any object to clip any other object, and not just rectangles 272@todo Allow any object to clip any other object, and not just rectangles
266@todo Free images if object invisible (and put back in chache)
267@todo Check robustness of malloc/calloc/realloc failures.
268@todo Add memory use reduction code if any allocations fail
269@todo If image loads fails due to memory allocatue failure, load reduced res version
270@todo If image load fails due to memory allocation failure, try split it up into tiles and demand-load them
271@todo Add auto-detection of what engines to build based on system/libs etc.
272@todo Add overall engine configure parameters (so you can configure an engine with defaults with 1 configure option)
273@todo Add more evas demos 273@todo Add more evas demos
274 274
275*/ 275*/
diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h
index f0ddf16dd5..dc18245591 100644
--- a/legacy/evas/src/lib/Evas.h
+++ b/legacy/evas/src/lib/Evas.h
@@ -91,6 +91,10 @@ typedef struct _Evas_Event_Key_Up Evas_Event_Key_Up;
91#define EVAS_LOAD_ERROR_CORRUPT_FILE 5 91#define EVAS_LOAD_ERROR_CORRUPT_FILE 5
92#define EVAS_LOAD_ERROR_UNKNOWN_FORMAT 6 92#define EVAS_LOAD_ERROR_UNKNOWN_FORMAT 6
93 93
94#define EVAS_ALLOC_ERROR_NONE 0
95#define EVAS_ALLOC_ERROR_FATAL 1
96#define EVAS_ALLOC_ERROR_RECOVERED 2
97
94struct _Evas_Engine_Info 98struct _Evas_Engine_Info
95{ 99{
96 int magic; 100 int magic;
@@ -449,6 +453,8 @@ extern "C" {
449 453
450 void evas_object_event_callback_add (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), void *data); 454 void evas_object_event_callback_add (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), void *data);
451 void *evas_object_event_callback_del (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info)); 455 void *evas_object_event_callback_del (Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info));
456
457 int evas_alloc_error (void);
452 458
453#ifdef __cplusplus 459#ifdef __cplusplus
454} 460}
diff --git a/legacy/evas/src/lib/canvas/evas_callbacks.c b/legacy/evas/src/lib/canvas/evas_callbacks.c
index f0d1ced057..3a3e438b42 100644
--- a/legacy/evas/src/lib/canvas/evas_callbacks.c
+++ b/legacy/evas/src/lib/canvas/evas_callbacks.c
@@ -5,6 +5,7 @@
5void 5void
6evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void *event_info) 6evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void *event_info)
7{ 7{
8 /* MEM OK */
8 Evas_Object_List **l_mod, *l; 9 Evas_Object_List **l_mod, *l;
9 10
10 switch (type) 11 switch (type)
@@ -41,10 +42,83 @@ evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void
41} 42}
42 43
43/* public functions */ 44/* public functions */
44 45/**
46 * Add a callback function to an object
47 * @param obj Object to attach a callback to
48 * @param type The type of event that will trigger the callback
49 * @param func The function to be called when the event is triggered
50 * @param data The data pointer to be passed to @p func
51 *
52 * This function adds a function callback to an object when the event of type
53 * @p type occurs on object @p obj. The function will be passed the pointer
54 * @p data when it is called. A callback function must look like this:
55 *
56 * @code
57 * void callback (void *data, Evas *e, Evas_Object *obj, void *event_info);
58 * @endcode
59 *
60 * The first parameter @p data in this function will be the same value passed
61 * to evas_object_event_callback_add() as the @p data parameter. The second
62 * parameter is a convenience for the programmer to know what evas canvas the
63 * event occured on. The third parameter @p obj is the Object handle on which
64 * the event occured. The foruth parameter @p event_info is a pointer to a
65 * data structure that may or may not be passed to the callback, depending on
66 * the event type that triggered the callback.
67 *
68 * The event type @p type to trigger the function mys be one of
69 * EVAS_CALLBACK_MOUSE_IN, EVAS_CALLBACK_MOUSE_OUT, EVAS_CALLBACK_MOUSE_DOWN,
70 * EVAS_CALLBACK_MOUSE_UP, EVAS_CALLBACK_MOUSE_MOVE, EVAS_CALLBACK_FREE,
71 * EVAS_CALLBACK_KEY_DOWN, EVAS_CALLBACK_KEY_UP, EVAS_CALLBACK_FOCUS_IN
72 * or EVAS_CALLBACK_FOCUS_OUT. This determines the kind of event that will
73 * trigger the callback to be called. The @p event_info pointer passed to the
74 * callback will be one of the following, depending on the event tiggering it:
75 *
76 * EVAS_CALLBACK_MOUSE_IN: event_info = pointer to Evas_Event_Mouse_In
77 *
78 * This event is triggered when the mouse pointer enters the region of
79 * the object @p obj. This may occur by the mouse pointer being moved by
80 * evas_event_feed_mouse_move() or evas_event_feed_mouse_move_data() calls,
81 * or by the object being shown, raised, moved, resized, or other objects
82 * being moved out of the way, hidden, lowered or moved out of the way.
83 *
84 * EVAS_CALLBACK_MOUSE_OUT: event_info = pointer to Evas_Event_Mouse_Out
85 *
86 * This event is triggered exactly like EVAS_CALLBACK_MOUSE_IN is, but occurs
87 * when the mouse pointer exits an object. Note that no out events will be
88 * reported if the mouse pointer is implicitly grabbed to an object (the
89 * mouse buttons are down at all and any were pressed on that object). An
90 * out event will be reported as soon as the mouse is no longer grabbed
91 * (no mouse buttons are depressed).
92 *
93 * EVAS_CALLBACK_MOUSE_DOWN: event_info = pointer to Evas_Event_Mouse_Down
94 *
95 * EVAS_CALLBACK_MOUSE_UP: event_info = pointer to Evas_Event_Mouse_Up
96 *
97 * EVAS_CALLBACK_FREE: event_info = NULL
98 *
99 * EVAS_CALLBACK_KEY_DOWN: event_info = pointer to Evas_Event_Key_Down
100 *
101 * EVAS_CALLBACK_KEY_UP: event_info = pointer to Evas_Event_Key_Up
102 *
103 * EVAS_CALLBACK_FOCUS_IN: event_info = NULL
104 *
105 * EVAS_CALLBACK_FOCUS_OUT: event_info = NULL
106 *
107 * Example:
108 * @code
109 * extern Evas_Object *object;
110 * extern void *my_data;
111 * void down_callback(void *data, Evas *e, Evas_Object *obj, void *event_info);
112 * void up_callback(void *data, Evas *e, Evas_Object *obj, void *event_info);
113 *
114 * evas_object_event_callback_add(object, EVAS_CALLBACK_MOUSE_UP, up_callback, my_data);
115 * evas_object_event_callback_add(object, EVAS_CALLBACK_MOUSE_DOWN, down_callback, my_data);
116 * @endcode
117 */
45void 118void
46evas_object_event_callback_add(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), void *data) 119evas_object_event_callback_add(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info), void *data)
47{ 120{
121 /* MEM OK */
48 Evas_Func_Node *fn; 122 Evas_Func_Node *fn;
49 123
50 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); 124 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
@@ -54,39 +128,55 @@ evas_object_event_callback_add(Evas_Object *obj, Evas_Callback_Type type, void (
54 if (!func) return; 128 if (!func) return;
55 if (obj->smart.smart) return; 129 if (obj->smart.smart) return;
56 130
57 fn = calloc(1, sizeof(Evas_Func_Node)); 131 fn = evas_mem_calloc(sizeof(Evas_Func_Node));
58 if (!fn) return; 132 if (!fn) return;
59 fn->func = func; 133 fn->func = func;
60 fn->data = data; 134 fn->data = data;
61 switch (type) 135 do
62 { 136 {
63 case EVAS_CALLBACK_MOUSE_IN: 137 switch (type)
64 obj->callbacks.in = evas_object_list_prepend(obj->callbacks.in, fn); 138 {
65 break; 139 case EVAS_CALLBACK_MOUSE_IN:
66 case EVAS_CALLBACK_MOUSE_OUT: 140 obj->callbacks.in = evas_object_list_prepend(obj->callbacks.in, fn);
67 obj->callbacks.out = evas_object_list_prepend(obj->callbacks.out, fn); 141 break;
68 break; 142 case EVAS_CALLBACK_MOUSE_OUT:
69 case EVAS_CALLBACK_MOUSE_DOWN: 143 obj->callbacks.out = evas_object_list_prepend(obj->callbacks.out, fn);
70 obj->callbacks.down = evas_object_list_prepend(obj->callbacks.down, fn); 144 break;
71 break; 145 case EVAS_CALLBACK_MOUSE_DOWN:
72 case EVAS_CALLBACK_MOUSE_UP: 146 obj->callbacks.down = evas_object_list_prepend(obj->callbacks.down, fn);
73 obj->callbacks.up = evas_object_list_prepend(obj->callbacks.up, fn); 147 break;
74 break; 148 case EVAS_CALLBACK_MOUSE_UP:
75 case EVAS_CALLBACK_MOUSE_MOVE: 149 obj->callbacks.up = evas_object_list_prepend(obj->callbacks.up, fn);
76 obj->callbacks.move = evas_object_list_prepend(obj->callbacks.move, fn); 150 break;
77 break; 151 case EVAS_CALLBACK_MOUSE_MOVE:
78 case EVAS_CALLBACK_FREE: 152 obj->callbacks.move = evas_object_list_prepend(obj->callbacks.move, fn);
79 obj->callbacks.free = evas_object_list_prepend(obj->callbacks.free, fn); 153 break;
80 break; 154 case EVAS_CALLBACK_FREE:
81 default: 155 obj->callbacks.free = evas_object_list_prepend(obj->callbacks.free, fn);
82 return; 156 break;
83 break; 157 default:
158 free(fn);
159 return;
160 break;
161 }
162 if (!evas_list_alloc_error()) return;
163 MERR_BAD();
164 if (!evas_mem_free(sizeof(Evas_List)))
165 {
166 if (!evas_mem_degrade(sizeof(Evas_List)))
167 {
168 MERR_FATAL();
169 return;
170 }
171 }
84 } 172 }
173 while (evas_list_alloc_error());
85} 174}
86 175
87void * 176void *
88evas_object_event_callback_del(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info)) 177evas_object_event_callback_del(Evas_Object *obj, Evas_Callback_Type type, void (*func) (void *data, Evas *e, Evas_Object *obj, void *event_info))
89{ 178{
179 /* MEM OK */
90 Evas_Object_List **l_mod, *l; 180 Evas_Object_List **l_mod, *l;
91 181
92 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); 182 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
diff --git a/legacy/evas/src/lib/include/evas_private.h b/legacy/evas/src/lib/include/evas_private.h
index c1d0586096..682a17b886 100644
--- a/legacy/evas/src/lib/include/evas_private.h
+++ b/legacy/evas/src/lib/include/evas_private.h
@@ -82,6 +82,13 @@ if (_r) \
82 (_r)->w = (_w); (_r)->h = (_h); \ 82 (_r)->w = (_w); (_r)->h = (_h); \
83}} 83}}
84 84
85#define MERR_NONE() _evas_alloc_error = EVAS_ALLOC_ERROR_NONE
86#define MERR_FATAL() _evas_alloc_error = EVAS_ALLOC_ERROR_FATAL
87#define MERR_BAD() _evas_alloc_error = EVAS_ALLOC_ERROR_RECOVERED
88
89#define MEM_TRY_CALLOC(_ptr, _size)
90
91
85struct _Evas_Smart 92struct _Evas_Smart
86{ 93{
87 DATA32 magic; 94 DATA32 magic;
@@ -443,6 +450,8 @@ int evas_file_path_is_file(char *path);
443int evas_file_path_is_dir(char *path); 450int evas_file_path_is_dir(char *path);
444Evas_List *evas_file_path_list(char *path, char *match, int match_case); 451Evas_List *evas_file_path_list(char *path, char *match, int match_case);
445DATA64 evas_file_modified_time(const char *file); 452DATA64 evas_file_modified_time(const char *file);
453int evas_mem_free(int mem_required);
454int evas_mem_degrade(int mem_required);
446void evas_debug_error(void); 455void evas_debug_error(void);
447void evas_debug_input_null(void); 456void evas_debug_input_null(void);
448void evas_debug_magic_null(void); 457void evas_debug_magic_null(void);
@@ -452,7 +461,10 @@ void evas_object_smart_use(Evas_Smart *s);
452void evas_object_smart_unuse(Evas_Smart *s); 461void evas_object_smart_unuse(Evas_Smart *s);
453void evas_object_smart_del(Evas_Object *obj); 462void evas_object_smart_del(Evas_Object *obj);
454void evas_object_smart_cleanup(Evas_Object *obj); 463void evas_object_smart_cleanup(Evas_Object *obj);
464void *evas_mem_calloc(int size);
455 465
466extern int _evas_alloc_error;
467
456#ifdef __cplusplus 468#ifdef __cplusplus
457} 469}
458#endif 470#endif
diff --git a/legacy/evas/src/lib/main.c b/legacy/evas/src/lib/main.c
index 823acfd88a..70caf5f724 100644
--- a/legacy/evas/src/lib/main.c
+++ b/legacy/evas/src/lib/main.c
@@ -2,6 +2,93 @@
2#include "evas_private.h" 2#include "evas_private.h"
3#include "Evas.h" 3#include "Evas.h"
4 4
5int _evas_alloc_error = 0;
6
7/**
8 * Return if any allocation errors have occured during the prior function
9 * @return The allocation error flag
10 *
11 * This function will return if any memory allocation errors occured during,
12 * and what kind they were. The return value will be one of
13 * EVAS_ALLOC_ERROR_NONE, EVAS_ALLOC_ERROR_FATAL or EVAS_ALLOC_ERROR_RECOVERED
14 * with each meaning something different.
15 *
16 * EVAS_ALLOC_ERROR_NONE means that no errors occured at all and the function
17 * worked as expected.
18 *
19 * EVAS_ALLOC_ERROR_FATAL means the function was completely unable to perform
20 * its job and will have exited as cleanly as possible. The programmer
21 * should consider this as a sign of very low memory and should try and safely
22 * recover from the prior functions failure (or try free up memory elsewhere
23 * and try again after more memory is freed).
24 *
25 * EVAS_ALLOC_ERROR_RECOVERED means that an allocation error occured, but was
26 * recovered from by evas finding memory of its own it has allocated and
27 * freeing what it sees as not really usefully allocated memory. What is freed
28 * may vary. Evas may reduce the resolution of images, free cached images or
29 * fonts, trhow out pre-rendered data, reduce the complexity of change lists
30 * etc. Evas and the program will function as per normal after this, but this
31 * is a sign of low memory, and it is suggested that the program try and
32 * identify memory it doesn't need, and free it.
33 *
34 * Example:
35 * @code
36 * extern Evas_Object *object;
37 * void callback (void *data, Evas *e, Evas_Object *obj, void *event_info);
38 *
39 * evas_object_event_callback_add(object, EVAS_CALLBACK_MOUSE_DOWN, callback, NULL);
40 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_FATAL)
41 * {
42 * fprintf(stderr, "ERROR: Completely unable to attach callabck. Must\n");
43 * fprintf(stderr, " destroy object now as it cannot be used.\n");
44 * evas_object_del(object);
45 * object = NULL;
46 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
47 * my_memory_cleanup();
48 * }
49 * if (evas_alloc_error() == EVAS_ALLOC_ERROR_RECOVERED)
50 * {
51 * fprintf(stderr, "WARNING: Memory is really low. Cleaning out RAM.\n");
52 * my_memory_cleanup();
53 * }
54 * @endcode
55 */
56int
57evas_alloc_error(void)
58{
59 return _evas_alloc_error;
60}
61
62/* free cached items only in ram for speed reasons. return 0 if cant free */
63int
64evas_mem_free(int mem_required)
65{
66 return 0;
67}
68
69/* start reducing quality of images etc. return 0 if cant free anything */
70int
71evas_mem_degrade(int mem_required)
72{
73 return 0;
74}
75
76void *
77evas_mem_calloc(int size)
78{
79 void *ptr;
80
81 ptr = calloc(1, size);
82 if (ptr) return ptr;
83 MERR_BAD();
84 while ((!ptr) && (evas_mem_free(size))) ptr = calloc(1, size);
85 if (ptr) return ptr;
86 while ((!ptr) && (evas_mem_degrade(size))) ptr = calloc(1, size);
87 if (ptr) return ptr;
88 MERR_FATAL();
89 return NULL;
90}
91
5void 92void
6evas_debug_error(void) 93evas_debug_error(void)
7{ 94{
@@ -63,6 +150,9 @@ evas_debug_magic_string_get(DATA32 magic)
63 case MAGIC_OBJ_TEXT: 150 case MAGIC_OBJ_TEXT:
64 return "Evas_Object (Text)"; 151 return "Evas_Object (Text)";
65 break; 152 break;
153 case MAGIC_OBJ_SMART:
154 return "Evas_Object (Smart)";
155 break;
66 default: 156 default:
67 return "<UNKNOWN>"; 157 return "<UNKNOWN>";
68 }; 158 };