forked from enlightenment/efl
* move evas_mempool from main.c to it's own file in data/ as it's only
used by evas_list * add a header files for evas_cache, evas_path and evas_module * remove trailing spaces in evas_list.c SVN revision: 35052
This commit is contained in:
parent
11a6fd276c
commit
9b35bc26f3
|
@ -15,3 +15,5 @@ evas_cache_image.c \
|
||||||
evas_cache_engine_image.c
|
evas_cache_engine_image.c
|
||||||
|
|
||||||
libevas_cache_la_DEPENDENCIES = $(top_builddir)/config.h
|
libevas_cache_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||||
|
|
||||||
|
EXTRA_DIST = evas_cache.h
|
||||||
|
|
|
@ -0,0 +1,153 @@
|
||||||
|
#ifndef _EVAS_CACHE_H
|
||||||
|
#define _EVAS_CACHE_H
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _Evas_Cache_Image Evas_Cache_Image;
|
||||||
|
typedef struct _Evas_Cache_Image_Func Evas_Cache_Image_Func;
|
||||||
|
typedef struct _Evas_Cache_Engine_Image Evas_Cache_Engine_Image;
|
||||||
|
typedef struct _Evas_Cache_Engine_Image_Func Evas_Cache_Engine_Image_Func;
|
||||||
|
|
||||||
|
|
||||||
|
struct _Evas_Cache_Image_Func
|
||||||
|
{
|
||||||
|
Image_Entry *(*alloc)(void);
|
||||||
|
void (*dealloc)(Image_Entry *im);
|
||||||
|
|
||||||
|
/* The cache provide some helpers for surface manipulation. */
|
||||||
|
int (*surface_alloc)(Image_Entry *im, int w, int h);
|
||||||
|
void (*surface_delete)(Image_Entry *im);
|
||||||
|
DATA32 *(*surface_pixels)(Image_Entry *im);
|
||||||
|
|
||||||
|
/* The cache is doing the allocation and deallocation, you must just do the rest. */
|
||||||
|
int (*constructor)(Image_Entry *im);
|
||||||
|
void (*destructor)(Image_Entry *im);
|
||||||
|
|
||||||
|
void (*dirty_region)(Image_Entry *im, int x, int y, int w, int h);
|
||||||
|
/* Only called when references > 0. Need to provide a fresh copie of im. */
|
||||||
|
/* The destination surface does have a surface, but no allocated pixel data. */
|
||||||
|
int (*dirty)(Image_Entry *dst, const Image_Entry *src);
|
||||||
|
/* Only called when references == 1. We will call drop on `im'. */
|
||||||
|
/* The destination surface does not have any surface. */
|
||||||
|
int (*size_set)(Image_Entry *dst, const Image_Entry *src, int w, int h);
|
||||||
|
|
||||||
|
/* The destination surface does not have any surface. */
|
||||||
|
int (*copied_data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
||||||
|
/* The destination surface does not have any surface. */
|
||||||
|
int (*data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
||||||
|
int (*color_space)(Image_Entry *dst, int cspace);
|
||||||
|
|
||||||
|
/* This function need to update im->w and im->h. */
|
||||||
|
int (*load)(Image_Entry *im);
|
||||||
|
int (*mem_size_get)(Image_Entry *im);
|
||||||
|
void (*debug)(const char *context, Image_Entry *im);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _Evas_Cache_Image
|
||||||
|
{
|
||||||
|
Evas_Cache_Image_Func func;
|
||||||
|
|
||||||
|
Evas_Object_List *dirty;
|
||||||
|
|
||||||
|
Evas_Object_List *lru;
|
||||||
|
Evas_Object_List *lru_nodata;
|
||||||
|
Evas_Hash *inactiv;
|
||||||
|
Evas_Hash *activ;
|
||||||
|
void *data;
|
||||||
|
|
||||||
|
int usage;
|
||||||
|
int limit;
|
||||||
|
int references;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _Evas_Cache_Engine_Image_Func
|
||||||
|
{
|
||||||
|
/* Must return a char* allocated with evas_stringshare_add. */
|
||||||
|
char* (*key)(Image_Entry *im, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
|
||||||
|
|
||||||
|
Engine_Image_Entry* (*alloc)(void);
|
||||||
|
void (*dealloc)(Engine_Image_Entry *eim);
|
||||||
|
|
||||||
|
int (*constructor)(Engine_Image_Entry *eim, void* data);
|
||||||
|
void (*destructor)(Engine_Image_Entry *eim);
|
||||||
|
|
||||||
|
void (*dirty_region)(Engine_Image_Entry *eim, int x, int y, int w, int h);
|
||||||
|
/* Only called when references > 0. Need to provide a fresh copie of im. */
|
||||||
|
int (*dirty)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
|
||||||
|
/* Only called when references == 1. We will call drop on `im'. */
|
||||||
|
int (*size_set)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
|
||||||
|
|
||||||
|
int (*update_data)(Engine_Image_Entry* dst, void* data);
|
||||||
|
|
||||||
|
void (*load)(Engine_Image_Entry *eim, const Image_Entry* im);
|
||||||
|
int (*mem_size_get)(Engine_Image_Entry *eim);
|
||||||
|
void (*debug)(const char* context, Engine_Image_Entry *eim);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _Evas_Cache_Engine_Image
|
||||||
|
{
|
||||||
|
Evas_Cache_Engine_Image_Func func;
|
||||||
|
|
||||||
|
Evas_Object_List* dirty;
|
||||||
|
|
||||||
|
Evas_Hash* activ;
|
||||||
|
Evas_Hash* inactiv;
|
||||||
|
Evas_Object_List* lru;
|
||||||
|
|
||||||
|
Evas_Cache_Image* parent;
|
||||||
|
Evas_Cache_Engine_Image* brother;
|
||||||
|
|
||||||
|
int usage;
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
int references;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
EAPI Evas_Cache_Image* evas_cache_image_init(const Evas_Cache_Image_Func *cb);
|
||||||
|
EAPI void evas_cache_image_shutdown(Evas_Cache_Image *cache);
|
||||||
|
EAPI Image_Entry* evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
|
||||||
|
EAPI void evas_cache_image_drop(Image_Entry *im);
|
||||||
|
EAPI void evas_cache_image_data_not_needed(Image_Entry *im);
|
||||||
|
EAPI int evas_cache_image_flush(Evas_Cache_Image *cache);
|
||||||
|
EAPI void evas_cache_private_set(Evas_Cache_Image *cache, const void *data);
|
||||||
|
EAPI void* evas_cache_private_get(Evas_Cache_Image *cache);
|
||||||
|
EAPI void* evas_cache_private_from_image_entry_get(Image_Entry *im);
|
||||||
|
|
||||||
|
EAPI int evas_cache_image_usage_get(Evas_Cache_Image *cache);
|
||||||
|
EAPI int evas_cache_image_get(Evas_Cache_Image *cache);
|
||||||
|
EAPI void evas_cache_image_set(Evas_Cache_Image *cache, int size);
|
||||||
|
|
||||||
|
EAPI Image_Entry* evas_cache_image_alone(Image_Entry *im);
|
||||||
|
EAPI Image_Entry* evas_cache_image_dirty(Image_Entry *im, int x, int y, int w, int h);
|
||||||
|
EAPI void evas_cache_image_load_data(Image_Entry *im);
|
||||||
|
EAPI void evas_cache_image_surface_alloc(Image_Entry *im, int w, int h);
|
||||||
|
EAPI DATA32* evas_cache_image_pixels(Image_Entry *im);
|
||||||
|
EAPI Image_Entry* evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
||||||
|
EAPI Image_Entry* evas_cache_image_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
||||||
|
EAPI void evas_cache_image_colorspace(Image_Entry *im, int cspace);
|
||||||
|
EAPI Image_Entry* evas_cache_image_empty(Evas_Cache_Image *cache);
|
||||||
|
EAPI Image_Entry* evas_cache_image_size_set(Image_Entry *im, int w, int h);
|
||||||
|
|
||||||
|
EAPI Evas_Cache_Engine_Image* evas_cache_engine_image_init(const Evas_Cache_Engine_Image_Func *cb, Evas_Cache_Image *parent);
|
||||||
|
EAPI void evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache);
|
||||||
|
|
||||||
|
EAPI void evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache);
|
||||||
|
EAPI int evas_cache_engine_image_usage_get(Evas_Cache_Engine_Image *cache);
|
||||||
|
EAPI int evas_cache_engine_image_get(Evas_Cache_Engine_Image *cache);
|
||||||
|
EAPI void evas_cache_engine_image_set(Evas_Cache_Engine_Image *cache, int limit);
|
||||||
|
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, void *engine_data, int *error);
|
||||||
|
EAPI void evas_cache_engine_parent_not_needed(Engine_Image_Entry *eim);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data);
|
||||||
|
EAPI void evas_cache_engine_image_drop(Engine_Image_Entry *eim);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_alone(Engine_Image_Entry *eim, void *data);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_dirty(Engine_Image_Entry *eim, int x, int y, int w, int h);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
|
||||||
|
EAPI void evas_cache_engine_image_colorspace(Engine_Image_Entry *eim, int cspace, void *engine_data);
|
||||||
|
EAPI Engine_Image_Entry* evas_cache_engine_image_size_set(Engine_Image_Entry *eim, int w, int h);
|
||||||
|
|
||||||
|
EAPI void evas_cache_engine_image_load_data(Engine_Image_Entry *eim);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _EVAS_CACHE_H */
|
|
@ -16,6 +16,9 @@ evas_list.c \
|
||||||
evas_array.c \
|
evas_array.c \
|
||||||
evas_object_list.c \
|
evas_object_list.c \
|
||||||
evas_stringshare.c \
|
evas_stringshare.c \
|
||||||
evas_array_hash.c
|
evas_array_hash.c \
|
||||||
|
evas_mempool.c
|
||||||
|
|
||||||
libevas_data_la_DEPENDENCIES = $(top_builddir)/config.h
|
libevas_data_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||||
|
|
||||||
|
EXTRA_DIST = evas_mempool.h
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||||
*/
|
*/
|
||||||
#include "evas_common.h"
|
#include "evas_common.h"
|
||||||
#include "evas_private.h"
|
#include "evas_mempool.h"
|
||||||
|
|
||||||
typedef struct _Evas_List_Accounting Evas_List_Accounting;
|
typedef struct _Evas_List_Accounting Evas_List_Accounting;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,183 @@
|
||||||
|
/*
|
||||||
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "evas_mempool.h"
|
||||||
|
|
||||||
|
//#define NOPOOL
|
||||||
|
|
||||||
|
typedef struct _Pool Pool;
|
||||||
|
|
||||||
|
struct _Pool
|
||||||
|
{
|
||||||
|
int usage;
|
||||||
|
void *base;
|
||||||
|
Pool *prev, *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Pool *
|
||||||
|
_evas_mp_pool_new(Evas_Mempool *pool)
|
||||||
|
#ifdef NOPOOL
|
||||||
|
{
|
||||||
|
static Pool thepool;
|
||||||
|
return &thepool;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
Pool *p;
|
||||||
|
void **ptr;
|
||||||
|
int item_alloc, i;
|
||||||
|
|
||||||
|
item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
|
||||||
|
p = malloc(sizeof(Pool) + (pool->pool_size * item_alloc));
|
||||||
|
ptr = (void **)(((unsigned char *)p) + sizeof(Pool));
|
||||||
|
p->usage = 0;
|
||||||
|
p->base = ptr;
|
||||||
|
for (i = 0; i < pool->pool_size - 1; i++)
|
||||||
|
{
|
||||||
|
*ptr = (void **)(((unsigned char *)ptr) + item_alloc);
|
||||||
|
ptr = *ptr;
|
||||||
|
}
|
||||||
|
*ptr = NULL;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
_evas_mp_pool_free(Pool *p)
|
||||||
|
#ifdef NOPOOL
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *
|
||||||
|
evas_mempool_malloc(Evas_Mempool *pool, int size)
|
||||||
|
#ifdef NOPOOL
|
||||||
|
{
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
Pool *p;
|
||||||
|
void *mem;
|
||||||
|
|
||||||
|
for (p = pool->first; p; p = p->next) // look 4 pool from 2nd bucket on
|
||||||
|
{
|
||||||
|
if (p->base) // base is not NULL - has a free slot
|
||||||
|
{
|
||||||
|
if (p->prev)
|
||||||
|
{
|
||||||
|
if (pool->last == p) pool->last = p->prev;
|
||||||
|
p->prev->next = p->next;
|
||||||
|
p->prev = NULL;
|
||||||
|
p->next = pool->first;
|
||||||
|
p->next->prev = p;
|
||||||
|
pool->first = p;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!p) // we have reached the end of the list - no free pools
|
||||||
|
{
|
||||||
|
p = _evas_mp_pool_new(pool);
|
||||||
|
if (!p) return NULL;
|
||||||
|
p->prev = NULL;
|
||||||
|
p->next = pool->first;
|
||||||
|
if (p->next) p->next->prev = p;
|
||||||
|
if (!pool->last) pool->last = p;
|
||||||
|
pool->first = p;
|
||||||
|
}
|
||||||
|
mem = p->base; // this points to the next free block - so take it
|
||||||
|
p->base = *((void **)mem); // base now points to the next free block
|
||||||
|
if (!p->base) // move to end - it just filled up
|
||||||
|
{
|
||||||
|
if (p->next)
|
||||||
|
{
|
||||||
|
if (p->prev) p->prev->next = p->next;
|
||||||
|
else pool->first = p->next;
|
||||||
|
p->next->prev = p->prev;
|
||||||
|
((Pool *)pool->last)->next = p;
|
||||||
|
p->prev = pool->last;
|
||||||
|
p->next = NULL;
|
||||||
|
pool->last = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p->usage++;
|
||||||
|
pool->usage++;
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
evas_mempool_free(Evas_Mempool *pool, void *ptr)
|
||||||
|
#ifdef NOPOOL
|
||||||
|
{
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
Pool *p;
|
||||||
|
void *pmem;
|
||||||
|
int item_alloc, psize;
|
||||||
|
|
||||||
|
item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
|
||||||
|
psize = item_alloc * pool->pool_size;
|
||||||
|
for (p = (Pool *)(pool->first); p; p = p->next) // look 4 pool
|
||||||
|
{
|
||||||
|
pmem = (void *)(((unsigned char *)p) + sizeof(Pool)); // pool mem base
|
||||||
|
if ((ptr >= pmem) && ((unsigned char *)ptr < (((unsigned char *)pmem) + psize))) // is it in pool mem?
|
||||||
|
{
|
||||||
|
*((void **)ptr) = p->base; // freed node points to prev free node
|
||||||
|
p->base = ptr; // next free node is now the one we freed
|
||||||
|
p->usage--;
|
||||||
|
pool->usage--;
|
||||||
|
if (p->usage == 0) // free bucket
|
||||||
|
{
|
||||||
|
if (p->prev) p->prev->next = p->next;
|
||||||
|
if (p->next) p->next->prev = p->prev;
|
||||||
|
if (pool->last == p) pool->last = p->prev;
|
||||||
|
if (pool->first == p) pool->first = p->next;
|
||||||
|
_evas_mp_pool_free(p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (p->prev) // if not the first - move to front
|
||||||
|
{
|
||||||
|
p->prev->next = p->next;
|
||||||
|
if (p->next) p->next->prev = p->prev;
|
||||||
|
if (pool->last == p) pool->last = p->prev;
|
||||||
|
p->prev = NULL;
|
||||||
|
p->next = pool->first;
|
||||||
|
p->next->prev = p;
|
||||||
|
pool->first = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *
|
||||||
|
evas_mempool_calloc(Evas_Mempool *pool, int size)
|
||||||
|
#ifdef NOPOOL
|
||||||
|
{
|
||||||
|
return calloc(1, size);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
void *mem;
|
||||||
|
|
||||||
|
mem = evas_mempool_malloc(pool, size);
|
||||||
|
memset(mem, 0, size);
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef _EVAS_MEMPOOL_H
|
||||||
|
#define _EVAS_MEMPOOL_H
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _Evas_Mempool Evas_Mempool;
|
||||||
|
|
||||||
|
struct _Evas_Mempool
|
||||||
|
{
|
||||||
|
int item_size;
|
||||||
|
int pool_size;
|
||||||
|
int usage;
|
||||||
|
void *first, *last;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void *evas_mempool_malloc(Evas_Mempool *pool, int size);
|
||||||
|
void evas_mempool_free(Evas_Mempool *pool, void *ptr);
|
||||||
|
void *evas_mempool_calloc(Evas_Mempool *pool, int size);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _EVAS_MEMPOOL_H */
|
|
@ -19,3 +19,5 @@ evas_path.c \
|
||||||
evas_module.c
|
evas_module.c
|
||||||
libevas_file_la_LIBADD = @EVIL_LIBS@
|
libevas_file_la_LIBADD = @EVIL_LIBS@
|
||||||
libevas_file_la_DEPENDENCIES = $(top_builddir)/config.h
|
libevas_file_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||||
|
|
||||||
|
EXTRA_DIST = evas_module.h evas_path.h
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
#ifndef _EVAS_MODULE_H
|
||||||
|
#define _EVAS_MODULE_H
|
||||||
|
|
||||||
|
|
||||||
|
/* the module api version */
|
||||||
|
#define EVAS_MODULE_API_VERSION 1
|
||||||
|
|
||||||
|
|
||||||
|
/* the module types */
|
||||||
|
typedef enum _Evas_Module_Type
|
||||||
|
{
|
||||||
|
EVAS_MODULE_TYPE_ENGINE,
|
||||||
|
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
||||||
|
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
||||||
|
EVAS_MODULE_TYPE_OBJECT
|
||||||
|
} Evas_Module_Type;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _Evas_Module_Api Evas_Module_Api;
|
||||||
|
typedef struct _Evas_Module Evas_Module;
|
||||||
|
typedef struct _Evas_Module_Path Evas_Module_Path;
|
||||||
|
typedef struct _Evas_Module_Engine Evas_Module_Engine;
|
||||||
|
|
||||||
|
/* the module api structure, all modules should define this struct */
|
||||||
|
struct _Evas_Module_Api
|
||||||
|
{
|
||||||
|
int version;
|
||||||
|
Evas_Module_Type type;
|
||||||
|
const char *name;
|
||||||
|
const char *author;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* the module structure */
|
||||||
|
struct _Evas_Module
|
||||||
|
{
|
||||||
|
Evas_Module_Api *api;
|
||||||
|
void *handle; /* the dlopen handle */
|
||||||
|
char *path; /* the path where this modules is */
|
||||||
|
char *name; /* the name of the dir where this module is */
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int (*open)(Evas_Module *);
|
||||||
|
void (*close)(Evas_Module *);
|
||||||
|
} func;
|
||||||
|
void *functions; /* this are the functions exported by the module */
|
||||||
|
void *data; /* some internal data for the module i.e the id for engines */
|
||||||
|
|
||||||
|
Evas_Module_Type type; /* the type detected by the path */
|
||||||
|
|
||||||
|
int ref; /* how many refs */
|
||||||
|
int last_used; /* the cycle count when it was last used */
|
||||||
|
|
||||||
|
unsigned char loaded : 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* the internals of the module api use this struct to reference a path with a module type
|
||||||
|
* instead of deduce the type from the path.
|
||||||
|
* */
|
||||||
|
struct _Evas_Module_Path
|
||||||
|
{
|
||||||
|
Evas_Module_Type type;
|
||||||
|
char *path;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _Evas_Module_Engine
|
||||||
|
{
|
||||||
|
int id;
|
||||||
|
};
|
||||||
|
|
||||||
|
void evas_module_paths_init (void);
|
||||||
|
void evas_module_init (void);
|
||||||
|
Evas_Module *evas_module_find_type (Evas_Module_Type type, const char *name);
|
||||||
|
int evas_module_load (Evas_Module *em);
|
||||||
|
void evas_module_unload (Evas_Module *em);
|
||||||
|
void evas_module_ref (Evas_Module *em);
|
||||||
|
void evas_module_unref (Evas_Module *em);
|
||||||
|
void evas_module_use (Evas_Module *em);
|
||||||
|
void evas_module_clean (void);
|
||||||
|
void evas_module_shutdown (void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _EVAS_MODULE_H */
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef _EVAS_PATH_H
|
||||||
|
#define _EVAS_PATH_H
|
||||||
|
|
||||||
|
|
||||||
|
int evas_file_path_is_full_path (const char *path);
|
||||||
|
char *evas_file_path_join (const char *path, const char *end);
|
||||||
|
int evas_file_path_exists (const char *path);
|
||||||
|
int evas_file_path_is_file (const char *path);
|
||||||
|
int evas_file_path_is_dir (const char *path);
|
||||||
|
Evas_List *evas_file_path_list (char *path, const char *match, int match_case);
|
||||||
|
DATA64 evas_file_modified_time (const char *file);
|
||||||
|
char *evas_file_path_resolve (const char *file);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _EVAS_PATH_H */
|
|
@ -166,11 +166,6 @@ typedef struct _Regionbuf Regionbuf;
|
||||||
typedef struct _Regionspan Regionspan;
|
typedef struct _Regionspan Regionspan;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _Evas_Cache_Image Evas_Cache_Image;
|
|
||||||
typedef struct _Evas_Cache_Image_Func Evas_Cache_Image_Func;
|
|
||||||
typedef struct _Evas_Cache_Engine_Image Evas_Cache_Engine_Image;
|
|
||||||
typedef struct _Evas_Cache_Engine_Image_Func Evas_Cache_Engine_Image_Func;
|
|
||||||
|
|
||||||
typedef void (*RGBA_Gfx_Func) (DATA32 *src, DATA8 *mask, DATA32 col, DATA32 *dst, int len);
|
typedef void (*RGBA_Gfx_Func) (DATA32 *src, DATA8 *mask, DATA32 col, DATA32 *dst, int len);
|
||||||
typedef void (*RGBA_Gfx_Pt_Func) (DATA32 src, DATA8 mask, DATA32 col, DATA32 *dst);
|
typedef void (*RGBA_Gfx_Pt_Func) (DATA32 src, DATA8 mask, DATA32 col, DATA32 *dst);
|
||||||
typedef void (*Gfx_Func_Copy) (DATA32 *src, DATA32 *dst, int len);
|
typedef void (*Gfx_Func_Copy) (DATA32 *src, DATA32 *dst, int len);
|
||||||
|
@ -182,6 +177,8 @@ typedef void (*Gfx_Func_Gradient_Fill)(DATA32 *src, int src_len,
|
||||||
int x, int y, int axx, int axy, int ayx, int ayy,
|
int x, int y, int axx, int axy, int ayx, int ayy,
|
||||||
void *geom_data);
|
void *geom_data);
|
||||||
|
|
||||||
|
#include "../cache/evas_cache.h"
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
typedef enum _RGBA_Image_Flags
|
typedef enum _RGBA_Image_Flags
|
||||||
|
@ -725,99 +722,6 @@ struct _Convert_Pal
|
||||||
};
|
};
|
||||||
|
|
||||||
/****/
|
/****/
|
||||||
struct _Evas_Cache_Image_Func
|
|
||||||
{
|
|
||||||
Image_Entry *(*alloc)(void);
|
|
||||||
void (*dealloc)(Image_Entry *im);
|
|
||||||
|
|
||||||
/* The cache provide some helpers for surface manipulation. */
|
|
||||||
int (*surface_alloc)(Image_Entry *im, int w, int h);
|
|
||||||
void (*surface_delete)(Image_Entry *im);
|
|
||||||
DATA32 *(*surface_pixels)(Image_Entry *im);
|
|
||||||
|
|
||||||
/* The cache is doing the allocation and deallocation, you must just do the rest. */
|
|
||||||
int (*constructor)(Image_Entry *im);
|
|
||||||
void (*destructor)(Image_Entry *im);
|
|
||||||
|
|
||||||
void (*dirty_region)(Image_Entry *im, int x, int y, int w, int h);
|
|
||||||
/* Only called when references > 0. Need to provide a fresh copie of im. */
|
|
||||||
/* The destination surface does have a surface, but no allocated pixel data. */
|
|
||||||
int (*dirty)(Image_Entry *dst, const Image_Entry *src);
|
|
||||||
/* Only called when references == 1. We will call drop on `im'. */
|
|
||||||
/* The destination surface does not have any surface. */
|
|
||||||
int (*size_set)(Image_Entry *dst, const Image_Entry *src, int w, int h);
|
|
||||||
|
|
||||||
/* The destination surface does not have any surface. */
|
|
||||||
int (*copied_data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
|
||||||
/* The destination surface does not have any surface. */
|
|
||||||
int (*data)(Image_Entry *dst, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
|
||||||
int (*color_space)(Image_Entry *dst, int cspace);
|
|
||||||
|
|
||||||
/* This function need to update im->w and im->h. */
|
|
||||||
int (*load)(Image_Entry *im);
|
|
||||||
int (*mem_size_get)(Image_Entry *im);
|
|
||||||
void (*debug)(const char *context, Image_Entry *im);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Evas_Cache_Image
|
|
||||||
{
|
|
||||||
Evas_Cache_Image_Func func;
|
|
||||||
|
|
||||||
Evas_Object_List *dirty;
|
|
||||||
|
|
||||||
Evas_Object_List *lru;
|
|
||||||
Evas_Object_List *lru_nodata;
|
|
||||||
Evas_Hash *inactiv;
|
|
||||||
Evas_Hash *activ;
|
|
||||||
void *data;
|
|
||||||
|
|
||||||
int usage;
|
|
||||||
int limit;
|
|
||||||
int references;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Evas_Cache_Engine_Image_Func
|
|
||||||
{
|
|
||||||
/* Must return a char* allocated with evas_stringshare_add. */
|
|
||||||
char* (*key)(Image_Entry *im, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
|
|
||||||
|
|
||||||
Engine_Image_Entry* (*alloc)(void);
|
|
||||||
void (*dealloc)(Engine_Image_Entry *eim);
|
|
||||||
|
|
||||||
int (*constructor)(Engine_Image_Entry *eim, void* data);
|
|
||||||
void (*destructor)(Engine_Image_Entry *eim);
|
|
||||||
|
|
||||||
void (*dirty_region)(Engine_Image_Entry *eim, int x, int y, int w, int h);
|
|
||||||
/* Only called when references > 0. Need to provide a fresh copie of im. */
|
|
||||||
int (*dirty)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
|
|
||||||
/* Only called when references == 1. We will call drop on `im'. */
|
|
||||||
int (*size_set)(Engine_Image_Entry *dst, const Engine_Image_Entry *src);
|
|
||||||
|
|
||||||
int (*update_data)(Engine_Image_Entry* dst, void* data);
|
|
||||||
|
|
||||||
void (*load)(Engine_Image_Entry *eim, const Image_Entry* im);
|
|
||||||
int (*mem_size_get)(Engine_Image_Entry *eim);
|
|
||||||
void (*debug)(const char* context, Engine_Image_Entry *eim);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _Evas_Cache_Engine_Image
|
|
||||||
{
|
|
||||||
Evas_Cache_Engine_Image_Func func;
|
|
||||||
|
|
||||||
Evas_Object_List* dirty;
|
|
||||||
|
|
||||||
Evas_Hash* activ;
|
|
||||||
Evas_Hash* inactiv;
|
|
||||||
Evas_Object_List* lru;
|
|
||||||
|
|
||||||
Evas_Cache_Image* parent;
|
|
||||||
Evas_Cache_Engine_Image* brother;
|
|
||||||
|
|
||||||
int usage;
|
|
||||||
int limit;
|
|
||||||
|
|
||||||
int references;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
#include "evas_macros.h"
|
#include "evas_macros.h"
|
||||||
|
@ -1260,52 +1164,6 @@ EAPI void evas_common_pipe_image_draw(RGBA_Image *src, RGBA_Image *dst, RGBA_Dra
|
||||||
void evas_font_dir_cache_free(void);
|
void evas_font_dir_cache_free(void);
|
||||||
|
|
||||||
/****/
|
/****/
|
||||||
EAPI Evas_Cache_Image* evas_cache_image_init(const Evas_Cache_Image_Func *cb);
|
|
||||||
EAPI void evas_cache_image_shutdown(Evas_Cache_Image *cache);
|
|
||||||
EAPI Image_Entry* evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *key, RGBA_Image_Loadopts *lo, int *error);
|
|
||||||
EAPI void evas_cache_image_drop(Image_Entry *im);
|
|
||||||
EAPI void evas_cache_image_data_not_needed(Image_Entry *im);
|
|
||||||
EAPI int evas_cache_image_flush(Evas_Cache_Image *cache);
|
|
||||||
EAPI void evas_cache_private_set(Evas_Cache_Image *cache, const void *data);
|
|
||||||
EAPI void* evas_cache_private_get(Evas_Cache_Image *cache);
|
|
||||||
EAPI void* evas_cache_private_from_image_entry_get(Image_Entry *im);
|
|
||||||
|
|
||||||
EAPI int evas_cache_image_usage_get(Evas_Cache_Image *cache);
|
|
||||||
EAPI int evas_cache_image_get(Evas_Cache_Image *cache);
|
|
||||||
EAPI void evas_cache_image_set(Evas_Cache_Image *cache, int size);
|
|
||||||
|
|
||||||
EAPI Image_Entry* evas_cache_image_alone(Image_Entry *im);
|
|
||||||
EAPI Image_Entry* evas_cache_image_dirty(Image_Entry *im, int x, int y, int w, int h);
|
|
||||||
EAPI void evas_cache_image_load_data(Image_Entry *im);
|
|
||||||
EAPI void evas_cache_image_surface_alloc(Image_Entry *im, int w, int h);
|
|
||||||
EAPI DATA32* evas_cache_image_pixels(Image_Entry *im);
|
|
||||||
EAPI Image_Entry* evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
|
||||||
EAPI Image_Entry* evas_cache_image_data(Evas_Cache_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace);
|
|
||||||
EAPI void evas_cache_image_colorspace(Image_Entry *im, int cspace);
|
|
||||||
EAPI Image_Entry* evas_cache_image_empty(Evas_Cache_Image *cache);
|
|
||||||
EAPI Image_Entry* evas_cache_image_size_set(Image_Entry *im, int w, int h);
|
|
||||||
|
|
||||||
EAPI Evas_Cache_Engine_Image* evas_cache_engine_image_init(const Evas_Cache_Engine_Image_Func *cb, Evas_Cache_Image *parent);
|
|
||||||
EAPI void evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache);
|
|
||||||
|
|
||||||
EAPI void evas_cache_engine_image_shutdown(Evas_Cache_Engine_Image *cache);
|
|
||||||
EAPI int evas_cache_engine_image_usage_get(Evas_Cache_Engine_Image *cache);
|
|
||||||
EAPI int evas_cache_engine_image_get(Evas_Cache_Engine_Image *cache);
|
|
||||||
EAPI void evas_cache_engine_image_set(Evas_Cache_Engine_Image *cache, int limit);
|
|
||||||
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_request(Evas_Cache_Engine_Image *cache, const char *file, const char *key,
|
|
||||||
RGBA_Image_Loadopts *lo, void *engine_data, int *error);
|
|
||||||
EAPI void evas_cache_engine_parent_not_needed(Engine_Image_Entry *eim);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_engine(Evas_Cache_Engine_Image *cache, void *engine_data);
|
|
||||||
EAPI void evas_cache_engine_image_drop(Engine_Image_Entry *eim);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_alone(Engine_Image_Entry *eim, void *data);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_dirty(Engine_Image_Entry *eim, int x, int y, int w, int h);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_copied_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_data(Evas_Cache_Engine_Image *cache, int w, int h, DATA32 *image_data, int alpha, int cspace, void *engine_data);
|
|
||||||
EAPI void evas_cache_engine_image_colorspace(Engine_Image_Entry *eim, int cspace, void *engine_data);
|
|
||||||
EAPI Engine_Image_Entry* evas_cache_engine_image_size_set(Engine_Image_Entry *eim, int w, int h);
|
|
||||||
|
|
||||||
EAPI void evas_cache_engine_image_load_data(Engine_Image_Entry *eim);
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
|
@ -7,73 +7,9 @@
|
||||||
|
|
||||||
#include "Evas.h"
|
#include "Evas.h"
|
||||||
|
|
||||||
/* the evas module api */
|
#include "../file/evas_module.h"
|
||||||
/***********************/
|
#include "../file/evas_path.h"
|
||||||
/* the module api version */
|
|
||||||
#define EVAS_MODULE_API_VERSION 1
|
|
||||||
|
|
||||||
/* the module types */
|
|
||||||
typedef enum _Evas_Module_Type
|
|
||||||
{
|
|
||||||
EVAS_MODULE_TYPE_ENGINE,
|
|
||||||
EVAS_MODULE_TYPE_IMAGE_LOADER,
|
|
||||||
EVAS_MODULE_TYPE_IMAGE_SAVER,
|
|
||||||
EVAS_MODULE_TYPE_OBJECT
|
|
||||||
} Evas_Module_Type;
|
|
||||||
|
|
||||||
/* the module api structure, all modules should define this struct */
|
|
||||||
typedef struct _Evas_Module_Api Evas_Module_Api;
|
|
||||||
struct _Evas_Module_Api
|
|
||||||
{
|
|
||||||
int version;
|
|
||||||
Evas_Module_Type type;
|
|
||||||
const char *name;
|
|
||||||
const char *author;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* the module structure */
|
|
||||||
typedef struct _Evas_Module Evas_Module;
|
|
||||||
struct _Evas_Module
|
|
||||||
{
|
|
||||||
Evas_Module_Api *api;
|
|
||||||
void *handle; /* the dlopen handle */
|
|
||||||
char *path; /* the path where this modules is */
|
|
||||||
char *name; /* the name of the dir where this module is */
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
int (*open)(Evas_Module *);
|
|
||||||
void (*close)(Evas_Module *);
|
|
||||||
} func;
|
|
||||||
void *functions; /* this are the functions exported by the module */
|
|
||||||
void *data; /* some internal data for the module i.e the id for engines */
|
|
||||||
|
|
||||||
Evas_Module_Type type; /* the type detected by the path */
|
|
||||||
|
|
||||||
int ref; /* how many refs */
|
|
||||||
int last_used; /* the cycle count when it was last used */
|
|
||||||
|
|
||||||
unsigned char loaded : 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* the internals of the module api use this struct to reference a path with a module type
|
|
||||||
* instead of deduce the type from the path.
|
|
||||||
* */
|
|
||||||
typedef struct _Evas_Module_Path Evas_Module_Path;
|
|
||||||
struct _Evas_Module_Path
|
|
||||||
{
|
|
||||||
Evas_Module_Type type;
|
|
||||||
char *path;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct _Evas_Module_Engine Evas_Module_Engine;
|
|
||||||
struct _Evas_Module_Engine
|
|
||||||
{
|
|
||||||
int id;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* end of evas module api */
|
|
||||||
/**************************/
|
|
||||||
|
|
||||||
/* complain when peole pass in wrong object types etc. */
|
/* complain when peole pass in wrong object types etc. */
|
||||||
#define MAGIC_DEBUG
|
#define MAGIC_DEBUG
|
||||||
|
@ -728,14 +664,6 @@ int evas_object_was_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
|
||||||
int evas_object_clippers_was_visible(Evas_Object *obj);
|
int evas_object_clippers_was_visible(Evas_Object *obj);
|
||||||
void evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void *event_info);
|
void evas_object_event_callback_call(Evas_Object *obj, Evas_Callback_Type type, void *event_info);
|
||||||
Evas_List *evas_event_objects_event_list(Evas *e, Evas_Object *stop, int x, int y);
|
Evas_List *evas_event_objects_event_list(Evas *e, Evas_Object *stop, int x, int y);
|
||||||
int evas_file_path_is_full_path(const char *path);
|
|
||||||
char *evas_file_path_join(const char *path, const char *end);
|
|
||||||
int evas_file_path_exists(const char *path);
|
|
||||||
int evas_file_path_is_file(const char *path);
|
|
||||||
int evas_file_path_is_dir(const char *path);
|
|
||||||
Evas_List *evas_file_path_list(char *path, const char *match, int match_case);
|
|
||||||
DATA64 evas_file_modified_time(const char *file);
|
|
||||||
char *evas_file_path_resolve(const char *file);
|
|
||||||
int evas_mem_free(int mem_required);
|
int evas_mem_free(int mem_required);
|
||||||
int evas_mem_degrade(int mem_required);
|
int evas_mem_degrade(int mem_required);
|
||||||
void evas_debug_error(void);
|
void evas_debug_error(void);
|
||||||
|
@ -801,31 +729,6 @@ struct _Evas_Imaging_Font
|
||||||
RGBA_Font *font;
|
RGBA_Font *font;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _Evas_Mempool Evas_Mempool;
|
|
||||||
|
|
||||||
struct _Evas_Mempool
|
|
||||||
{
|
|
||||||
int item_size;
|
|
||||||
int pool_size;
|
|
||||||
int usage;
|
|
||||||
void *first, *last;
|
|
||||||
};
|
|
||||||
|
|
||||||
void *evas_mempool_malloc(Evas_Mempool *pool, int size);
|
|
||||||
void evas_mempool_free(Evas_Mempool *pool, void *ptr);
|
|
||||||
void *evas_mempool_calloc(Evas_Mempool *pool, int size);
|
|
||||||
|
|
||||||
void evas_module_paths_init(void);
|
|
||||||
void evas_module_init(void);
|
|
||||||
Evas_Module * evas_module_find_type(Evas_Module_Type type, const char *name);
|
|
||||||
int evas_module_load(Evas_Module *em);
|
|
||||||
void evas_module_unload(Evas_Module *em);
|
|
||||||
void evas_module_ref(Evas_Module *em);
|
|
||||||
void evas_module_unref(Evas_Module *em);
|
|
||||||
void evas_module_use(Evas_Module *em);
|
|
||||||
void evas_module_clean(void);
|
|
||||||
void evas_module_shutdown(void);
|
|
||||||
|
|
||||||
int evas_async_events_init(void);
|
int evas_async_events_init(void);
|
||||||
int evas_async_events_shutdown(void);
|
int evas_async_events_shutdown(void);
|
||||||
|
|
||||||
|
|
|
@ -207,184 +207,3 @@ evas_debug_magic_string_get(DATA32 magic)
|
||||||
};
|
};
|
||||||
return "<UNKNOWN>";
|
return "<UNKNOWN>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#define NOPOOL
|
|
||||||
|
|
||||||
typedef struct _Pool Pool;
|
|
||||||
|
|
||||||
struct _Pool
|
|
||||||
{
|
|
||||||
int usage;
|
|
||||||
void *base;
|
|
||||||
Pool *prev, *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
Pool *
|
|
||||||
_evas_mp_pool_new(Evas_Mempool *pool)
|
|
||||||
#ifdef NOPOOL
|
|
||||||
{
|
|
||||||
static Pool thepool;
|
|
||||||
return &thepool;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
Pool *p;
|
|
||||||
void **ptr;
|
|
||||||
int item_alloc, i;
|
|
||||||
|
|
||||||
item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
|
|
||||||
p = malloc(sizeof(Pool) + (pool->pool_size * item_alloc));
|
|
||||||
ptr = (void **)(((unsigned char *)p) + sizeof(Pool));
|
|
||||||
p->usage = 0;
|
|
||||||
p->base = ptr;
|
|
||||||
for (i = 0; i < pool->pool_size - 1; i++)
|
|
||||||
{
|
|
||||||
*ptr = (void **)(((unsigned char *)ptr) + item_alloc);
|
|
||||||
ptr = *ptr;
|
|
||||||
}
|
|
||||||
*ptr = NULL;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
_evas_mp_pool_free(Pool *p)
|
|
||||||
#ifdef NOPOOL
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void *
|
|
||||||
evas_mempool_malloc(Evas_Mempool *pool, int size)
|
|
||||||
#ifdef NOPOOL
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
Pool *p;
|
|
||||||
void *mem;
|
|
||||||
|
|
||||||
for (p = pool->first; p; p = p->next) // look 4 pool from 2nd bucket on
|
|
||||||
{
|
|
||||||
if (p->base) // base is not NULL - has a free slot
|
|
||||||
{
|
|
||||||
if (p->prev)
|
|
||||||
{
|
|
||||||
if (pool->last == p) pool->last = p->prev;
|
|
||||||
p->prev->next = p->next;
|
|
||||||
p->prev = NULL;
|
|
||||||
p->next = pool->first;
|
|
||||||
p->next->prev = p;
|
|
||||||
pool->first = p;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!p) // we have reached the end of the list - no free pools
|
|
||||||
{
|
|
||||||
p = _evas_mp_pool_new(pool);
|
|
||||||
if (!p) return NULL;
|
|
||||||
p->prev = NULL;
|
|
||||||
p->next = pool->first;
|
|
||||||
if (p->next) p->next->prev = p;
|
|
||||||
if (!pool->last) pool->last = p;
|
|
||||||
pool->first = p;
|
|
||||||
}
|
|
||||||
mem = p->base; // this points to the next free block - so take it
|
|
||||||
p->base = *((void **)mem); // base now points to the next free block
|
|
||||||
if (!p->base) // move to end - it just filled up
|
|
||||||
{
|
|
||||||
if (p->next)
|
|
||||||
{
|
|
||||||
if (p->prev) p->prev->next = p->next;
|
|
||||||
else pool->first = p->next;
|
|
||||||
p->next->prev = p->prev;
|
|
||||||
((Pool *)pool->last)->next = p;
|
|
||||||
p->prev = pool->last;
|
|
||||||
p->next = NULL;
|
|
||||||
pool->last = p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p->usage++;
|
|
||||||
pool->usage++;
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
evas_mempool_free(Evas_Mempool *pool, void *ptr)
|
|
||||||
#ifdef NOPOOL
|
|
||||||
{
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
Pool *p;
|
|
||||||
void *pmem;
|
|
||||||
int item_alloc, psize;
|
|
||||||
|
|
||||||
item_alloc = ((pool->item_size + sizeof(void *) - 1) / sizeof(void *)) * sizeof(void *);
|
|
||||||
psize = item_alloc * pool->pool_size;
|
|
||||||
for (p = (Pool *)(pool->first); p; p = p->next) // look 4 pool
|
|
||||||
{
|
|
||||||
pmem = (void *)(((unsigned char *)p) + sizeof(Pool)); // pool mem base
|
|
||||||
if ((ptr >= pmem) && ((unsigned char *)ptr < (((unsigned char *)pmem) + psize))) // is it in pool mem?
|
|
||||||
{
|
|
||||||
*((void **)ptr) = p->base; // freed node points to prev free node
|
|
||||||
p->base = ptr; // next free node is now the one we freed
|
|
||||||
p->usage--;
|
|
||||||
pool->usage--;
|
|
||||||
if (p->usage == 0) // free bucket
|
|
||||||
{
|
|
||||||
if (p->prev) p->prev->next = p->next;
|
|
||||||
if (p->next) p->next->prev = p->prev;
|
|
||||||
if (pool->last == p) pool->last = p->prev;
|
|
||||||
if (pool->first == p) pool->first = p->next;
|
|
||||||
_evas_mp_pool_free(p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (p->prev) // if not the first - move to front
|
|
||||||
{
|
|
||||||
p->prev->next = p->next;
|
|
||||||
if (p->next) p->next->prev = p->prev;
|
|
||||||
if (pool->last == p) pool->last = p->prev;
|
|
||||||
p->prev = NULL;
|
|
||||||
p->next = pool->first;
|
|
||||||
p->next->prev = p;
|
|
||||||
pool->first = p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void *
|
|
||||||
evas_mempool_calloc(Evas_Mempool *pool, int size)
|
|
||||||
#ifdef NOPOOL
|
|
||||||
{
|
|
||||||
return calloc(1, size);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
void *mem;
|
|
||||||
|
|
||||||
mem = evas_mempool_malloc(pool, size);
|
|
||||||
memset(mem, 0, size);
|
|
||||||
return mem;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue