add rt_memory_info function in kernel; cleanup code in dfs_posix.c; add Chinese Font(file cached) support in RTGUI;
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@166 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
3344963e4b
commit
2ea6844081
|
@ -63,16 +63,21 @@ int open(const char *file, int flags, int mode)
|
|||
|
|
||||
+------------------------------------------------------------------------------
|
||||
*/
|
||||
int close(int d)
|
||||
int close(int fd)
|
||||
{
|
||||
int result;
|
||||
struct dfs_fd* fd;
|
||||
struct dfs_fd* d;
|
||||
|
||||
fd = fd_get(d);
|
||||
d = fd_get(fd);
|
||||
if (d == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dfile_raw_close(fd);
|
||||
fd_put(fd);
|
||||
fd_put(fd);
|
||||
result = dfile_raw_close(d);
|
||||
fd_put(d);
|
||||
fd_put(d);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
|
@ -100,6 +105,11 @@ int read(int fd, char *buf, int len)
|
|||
|
||||
/* get the fd */
|
||||
d = fd_get(fd);
|
||||
if (d == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dfile_raw_read(d, buf, len);
|
||||
if (result < 0)
|
||||
|
@ -133,6 +143,11 @@ int write(int fd, char *buf, int len)
|
|||
|
||||
/* get the fd */
|
||||
d = fd_get(fd);
|
||||
if (d == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dfile_raw_write(d, buf, len);
|
||||
if (result < 0)
|
||||
|
@ -165,6 +180,11 @@ int lseek(int fd, int offset, int dir)
|
|||
struct dfs_fd* d;
|
||||
|
||||
d = fd_get(fd);
|
||||
if (d == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
|
@ -391,6 +411,11 @@ struct dfs_dirent* readdir(DIR *d)
|
|||
struct dfs_fd* fd;
|
||||
|
||||
fd = fd_get(d->fd);
|
||||
if (fd == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
if (!d->num || (d->cur += ((struct dfs_dirent*)(d->buf + d->cur))->d_reclen) >= d->num)
|
||||
{
|
||||
|
@ -428,6 +453,12 @@ rt_off_t telldir(DIR *d)
|
|||
rt_off_t result;
|
||||
|
||||
fd = fd_get(d->fd);
|
||||
if (fd == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = fd->pos - d->num + d->cur;
|
||||
fd_put(fd);
|
||||
|
||||
|
@ -450,6 +481,12 @@ void seekdir(DIR *d, rt_off_t offset)
|
|||
struct dfs_fd* fd;
|
||||
|
||||
fd = fd_get(d->fd);
|
||||
if (fd == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return ;
|
||||
}
|
||||
|
||||
if (dfile_raw_lseek(fd, offset) >= 0) d->num = d->cur = 0;
|
||||
fd_put(fd);
|
||||
}
|
||||
|
@ -470,6 +507,12 @@ void rewinddir(DIR *d)
|
|||
struct dfs_fd* fd;
|
||||
|
||||
fd = fd_get(d->fd);
|
||||
if (fd == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return ;
|
||||
}
|
||||
|
||||
if (dfile_raw_lseek(fd, 0) >= 0) d->num = d->cur = 0;
|
||||
fd_put(fd);
|
||||
}
|
||||
|
@ -491,6 +534,12 @@ int closedir(DIR* d)
|
|||
struct dfs_fd* fd;
|
||||
|
||||
fd = fd_get(d->fd);
|
||||
if (fd == RT_NULL)
|
||||
{
|
||||
rt_set_errno(-RT_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = dfile_raw_close(fd);
|
||||
fd_put(fd);
|
||||
|
||||
|
|
|
@ -173,6 +173,10 @@ void rt_free (void *ptr);
|
|||
void* rt_realloc(void *ptr, rt_size_t nbytes);
|
||||
void *rt_calloc(rt_size_t count, rt_size_t size);
|
||||
|
||||
void rt_memory_info(rt_uint32_t *total,
|
||||
rt_uint32_t *used,
|
||||
rt_uint32_t *max_used);
|
||||
|
||||
#ifdef RT_USING_HOOK
|
||||
void rt_malloc_sethook(void (*hook)(void *ptr, rt_uint32_t size));
|
||||
void rt_free_sethook(void (*hook)(void *ptr));
|
||||
|
|
|
@ -37,18 +37,33 @@ void rtgui_font_system_init()
|
|||
rtgui_font_system_add_font(&rtgui_font_hz16);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
rtgui_font_system_add_font(&rtgui_font_asc12);
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
rtgui_font_system_add_font(&rtgui_font_hz12);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
rtgui_font_set_defaut(&rtgui_font_asc12);
|
||||
#elif defined(RTGUI_USING_FONT16)
|
||||
rtgui_font_set_defaut(&rtgui_font_asc16);
|
||||
#endif
|
||||
}
|
||||
|
||||
void rtgui_font_system_add_font(struct rtgui_font* font)
|
||||
{
|
||||
rtgui_list_init(&(font->list));
|
||||
rtgui_list_append(&_rtgui_font_list, &(font->list));
|
||||
|
||||
/* init font */
|
||||
if (font->engine->font_init != RT_NULL)
|
||||
font->engine->font_init(font);
|
||||
|
||||
/* first refer, load it */
|
||||
if (font->engine->font_load != RT_NULL)
|
||||
font->engine->font_load(font);
|
||||
}
|
||||
|
||||
void rtgui_font_system_remove_font(struct rtgui_font* font)
|
||||
|
|
|
@ -7,30 +7,7 @@
|
|||
#include <rtgui/rtgui_system.h>
|
||||
#include <dfs_posix.h>
|
||||
|
||||
#define HZ_DATA_SIZE (2 * 16)
|
||||
#define HZ_CACHE_MAX 64
|
||||
SPLAY_HEAD(cache_tree, hz_cache);
|
||||
struct hz_cache
|
||||
{
|
||||
SPLAY_ENTRY(hz_cache) hz_node;
|
||||
|
||||
rt_uint16_t hz_id;
|
||||
};
|
||||
|
||||
struct rtgui_hz_file_font
|
||||
{
|
||||
struct cache_tree cache_root;
|
||||
rt_uint16_t cache_size;
|
||||
|
||||
/* font size */
|
||||
rt_uint16_t font_size;
|
||||
|
||||
/* file descriptor */
|
||||
int fd;
|
||||
|
||||
/* font file name */
|
||||
const char* font_fn;
|
||||
};
|
||||
|
||||
static int _font_cache_compare(struct hz_cache* node1, struct hz_cache* node2);
|
||||
|
||||
|
@ -70,17 +47,17 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
|
|||
}
|
||||
|
||||
/* can not find it, load to cache */
|
||||
cache = (struct hz_cache*) rtgui_malloc(sizeof(struct hz_cache) + HZ_DATA_SIZE);
|
||||
cache = (struct hz_cache*) rtgui_malloc(sizeof(struct hz_cache) + font->font_data_size);
|
||||
if (cache == RT_NULL) return RT_NULL; /* no memory yet */
|
||||
|
||||
cache->hz_id = hz_id;
|
||||
seek = 94 * ((hz_id & 0xff - 0xA0) - 1) + ((hz_id >> 8) - 0xA0);
|
||||
seek = seek * HZ_DATA_SIZE;
|
||||
seek = 94 * (((hz_id & 0xff) - 0xA0) - 1) + ((hz_id >> 8) - 0xA0) - 1;
|
||||
seek *= font->font_data_size;
|
||||
|
||||
/* read hz font data */
|
||||
if ((lseek(font->fd, seek, SEEK_SET) < 0) ||
|
||||
read(font->fd, (char*)(cache + 1), HZ_DATA_SIZE) !=
|
||||
HZ_DATA_SIZE)
|
||||
read(font->fd, (char*)(cache + 1), font->font_data_size) !=
|
||||
font->font_data_size)
|
||||
{
|
||||
rtgui_free(cache);
|
||||
return RT_NULL;
|
||||
|
@ -88,6 +65,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
|
|||
|
||||
/* insert to cache */
|
||||
SPLAY_INSERT(cache_tree, &(font->cache_root), cache);
|
||||
font->cache_size ++;
|
||||
|
||||
if (font->cache_size > HZ_CACHE_MAX)
|
||||
{
|
||||
|
@ -98,6 +76,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
|
|||
|
||||
/* remove the left node */
|
||||
SPLAY_REMOVE(cache_tree, &(font->cache_root), left);
|
||||
font->cache_size --;
|
||||
}
|
||||
|
||||
return (rt_uint8_t*)(cache + 1);
|
||||
|
@ -105,7 +84,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t
|
|||
|
||||
static void rtgui_hz_file_font_load(struct rtgui_font* font)
|
||||
{
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font;
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data;
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0);
|
||||
|
@ -115,7 +94,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
|
|||
{
|
||||
rt_base_t h;
|
||||
rt_uint8_t* str;
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font;
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data;
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
/* drawing height */
|
||||
|
@ -130,7 +109,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
|
|||
register rt_base_t i, j, k;
|
||||
|
||||
/* get font pixel data */
|
||||
font_ptr = _font_cache_get(hz_file_font, *(rt_uint16_t*)str);
|
||||
font_ptr = _font_cache_get(hz_file_font, *str | (*(str+1) << 8));
|
||||
|
||||
/* draw word */
|
||||
for (i=0; i < h; i ++)
|
||||
|
@ -155,7 +134,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
|
|||
|
||||
static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect)
|
||||
{
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font;
|
||||
struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data;
|
||||
RT_ASSERT(hz_file_font != RT_NULL);
|
||||
|
||||
/* set metrics rect */
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <rtgui/font.h>
|
||||
|
||||
#ifdef RTGUI_USING_FONT12
|
||||
#ifndef RTGUI_USING_HZ_FILE
|
||||
const unsigned char hz12_font[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
@ -12311,3 +12312,4 @@ struct rtgui_font rtgui_font_hz12 =
|
|||
(void*)&hz12, /* font private data */
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <rtgui/font.h>
|
||||
|
||||
#ifdef RTGUI_USING_FONT16
|
||||
#ifndef RTGUI_USING_HZ_FILE
|
||||
const unsigned char hz16_font[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
@ -16753,19 +16754,20 @@ const struct rtgui_font rtgui_font_hz16 =
|
|||
struct rtgui_hz_file_font hz16 =
|
||||
{
|
||||
{RT_NULL}, /* cache root */
|
||||
0, /* cache_size */
|
||||
16, /* font_size */
|
||||
0, /* cache size */
|
||||
16, /* font size */
|
||||
32, /* font data size */
|
||||
-1, /* fd */
|
||||
"/resource/hz16" /* font_fn */
|
||||
"/resource/hzk16.fnt" /* font_fn */
|
||||
};
|
||||
|
||||
extern struct rtgui_hz_file_font_engine hz_file_font_engine;
|
||||
const struct rtgui_font rtgui_font_hz16 =
|
||||
struct rtgui_font rtgui_font_hz16 =
|
||||
{
|
||||
"hz", /* family */
|
||||
16, /* height */
|
||||
1, /* refer count */
|
||||
&hz_file_font_engine,/* font engine */
|
||||
&rtgui_hz_file_font_engine,/* font engine */
|
||||
(void*)&hz16, /* font private data */
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -566,6 +566,7 @@ color_none:
|
|||
}
|
||||
|
||||
free_colorhash(colors_table);
|
||||
rtgui_filerw_close(file);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,32 @@ struct rtgui_font_bitmap
|
|||
};
|
||||
extern struct rtgui_font_engine bmp_font_engine;
|
||||
|
||||
#include <rtgui/tree.h>
|
||||
SPLAY_HEAD(cache_tree, hz_cache);
|
||||
struct hz_cache
|
||||
{
|
||||
SPLAY_ENTRY(hz_cache) hz_node;
|
||||
|
||||
rt_uint16_t hz_id;
|
||||
};
|
||||
|
||||
struct rtgui_hz_file_font
|
||||
{
|
||||
struct cache_tree cache_root;
|
||||
rt_uint16_t cache_size;
|
||||
|
||||
/* font size */
|
||||
rt_uint16_t font_size;
|
||||
rt_uint16_t font_data_size;
|
||||
|
||||
/* file descriptor */
|
||||
int fd;
|
||||
|
||||
/* font file name */
|
||||
const char* font_fn;
|
||||
};
|
||||
extern struct rtgui_font_engine rtgui_hz_file_font_engine;
|
||||
|
||||
struct rtgui_font
|
||||
{
|
||||
/* font name */
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
/* #define RTGUI_USING_MOUSE_CURSOR */
|
||||
|
||||
#define RTGUI_USING_FONT16
|
||||
#define RTGUI_USING_FONTHZ
|
||||
|
||||
#define RTGUI_USING_HZ_FILE
|
||||
|
||||
// #define RT_USING_STDIO_FILERW
|
||||
#define RT_USING_DFS_FILERW
|
||||
|
|
|
@ -41,6 +41,8 @@ struct rtgui_view
|
|||
};
|
||||
typedef struct rtgui_view rtgui_view_t;
|
||||
|
||||
rtgui_type_t *rtgui_view_type_get(void);
|
||||
|
||||
rtgui_view_t* rtgui_view_create(const char* title);
|
||||
void rtgui_view_destroy(rtgui_view_t* view);
|
||||
|
||||
|
|
|
@ -488,6 +488,15 @@ void rt_free(void *rmem)
|
|||
}
|
||||
|
||||
#ifdef RT_MEM_STATS
|
||||
void rt_memory_info(rt_uint32_t *total,
|
||||
rt_uint32_t *used,
|
||||
rt_uint32_t *max_used)
|
||||
{
|
||||
if (total != RT_NULL) *total = mem_size_aligned;
|
||||
if (used != RT_NULL) *used = used_mem;
|
||||
if (max_used != RT_NULL) *max_used = max_mem;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
void list_mem()
|
||||
|
|
Loading…
Reference in New Issue