move the basic routine of dc to inline; add hdc memory image type; move event buffer from stack to gui thread structure.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@755 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong@gmail.com 2010-05-30 22:44:21 +00:00
parent ea6e5155ef
commit a1ee019309
13 changed files with 173 additions and 177 deletions

View File

@ -31,46 +31,6 @@ void rtgui_dc_destory(struct rtgui_dc* dc)
rtgui_free(dc);
}
/*
* draw a point on dc
*/
void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y)
{
if (dc == RT_NULL) return;
dc->draw_point(dc, x, y);
}
/*
* draw a color point on dc
*/
void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgui_color_t color)
{
if (dc == RT_NULL) return;
dc->draw_color_point(dc, x, y, color);
}
/*
* draw a vertical line on dc
*/
void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2)
{
if (dc == RT_NULL) return;
dc->draw_vline(dc, x, y1, y2);
}
/*
* draw a horizontal line on dc
*/
void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y)
{
if (dc == RT_NULL) return;
dc->draw_hline(dc, x1, x2, y);
}
void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2)
{
if (dc == RT_NULL) return;
@ -163,20 +123,6 @@ void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect)
rtgui_dc_draw_vline(dc, rect->x2, rect->y1 + r, rect->y2 - r);
}
void rtgui_dc_fill_rect (struct rtgui_dc* dc, struct rtgui_rect* rect)
{
if (dc == RT_NULL) return;
dc->fill_rect(dc, rect);
}
void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect)
{
if (dc == RT_NULL || dest == RT_NULL || rect == RT_NULL) return;
dc->blit(dc, dc_point, dest, rect);
}
void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect)
{
rt_uint32_t len;
@ -236,67 +182,33 @@ void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rec
#endif
}
/*
* draw a monochrome color bitmap data
*/
void rtgui_dc_draw_mono_bmp(struct rtgui_dc* dc, int x, int y, int w, int h, const rt_uint8_t* data)
{
int word_bytes;
int i, j, k;
/* get word bytes */
word_bytes = (w + 7)/8;
/* draw mono bitmap data */
for (i = 0; i < h; i ++)
for (j = 0; j < word_bytes; j++)
for (k = 0; k < 8; k++)
if ( ((data[i*2 + j] >> (7-k)) & 0x01) != 0)
rtgui_dc_draw_point(dc, x + 8*j + k, y + i);
}
void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{
int i, k;
/* draw byte */
for (i=0; i < h; i ++)
{
for (k=0; k < 8; k++)
{
if (((data[i] >> (7-k)) & 0x01) != 0)
{
rtgui_dc_draw_point(dc, x + k, y + i);
}
}
}
rtgui_dc_draw_mono_bmp(dc, x, y, 8, h, data);
}
void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{
int i, j, k;
/* draw word */
for (i=0; i < h; i ++)
{
for (j=0; j < 2; j++)
for (k=0; k < 8; k++)
{
if (((data[i * 2 + j] >> (7-k)) & 0x01) != 0)
{
rtgui_dc_draw_point(dc, x + 8*j + k, y + i);
}
}
}
}
void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc)
{
if (dc != RT_NULL)
{
dc->set_gc(dc, gc);
}
}
rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc)
{
if (dc != RT_NULL)
{
return dc->get_gc(dc);
}
return RT_NULL;
}
rt_bool_t rtgui_dc_get_visible(struct rtgui_dc* dc)
{
if (dc != RT_NULL)
{
return dc->get_visible(dc);
}
return RT_FALSE;
rtgui_dc_draw_mono_bmp(dc, x, y, 16, h, data);
}
void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect,
@ -1295,11 +1207,3 @@ void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect)
rtgui_dc_draw_point(dc, rect->x2, i);
}
}
void rtgui_dc_get_rect(struct rtgui_dc*dc, rtgui_rect_t* rect)
{
if (dc != RT_NULL && rect != RT_NULL)
{
dc->get_rect(dc, rect);
}
}

View File

@ -116,7 +116,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
/* draw word */
for (i=0; i < h; i ++)
{
for (j=0; j < 2; j++)
for (j=0; j < word_bytes; j++)
for (k=0; k < 8; k++)
{
if ( ((font_ptr[i*2 + j] >> (7-k)) & 0x01) != 0 &&

View File

@ -37,7 +37,7 @@ struct rtgui_image_engine rtgui_image_hdc_engine =
rtgui_image_hdc_blit
};
struct rtgui_image_engine rtgui_image_hdcmm_engine =
const struct rtgui_image_engine rtgui_image_hdcmm_engine =
{
"hdcmm",
{RT_NULL},

View File

@ -2202,14 +2202,14 @@ void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest)
if (dest->y2 > src->y2) dest->y2 = src->y2;
}
int rtgui_rect_contains_point(rtgui_rect_t *rect, int x, int y)
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y)
{
if (INBOX(rect, x, y)) return RT_EOK;
return -RT_ERROR;
}
int rtgui_rect_is_intersect(rtgui_rect_t *rect1, rtgui_rect_t *rect2)
int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2)
{
if (INBOX(rect1, rect2->x1, rect2->y1) ||
INBOX(rect1, rect2->x1, rect2->y2) ||

View File

@ -29,9 +29,6 @@
void rtgui_system_server_init()
{
/* init rtgui_thread */
rtgui_thread_system_init();
/* init image */
rtgui_system_image_init();
/* init font */
@ -276,13 +273,6 @@ static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
#define rtgui_event_dump(tid, event)
#endif
struct rt_semaphore _rtgui_thread_hash_semaphore;
void rtgui_thread_system_init()
{
rt_sem_init(&_rtgui_thread_hash_semaphore, "rtgui", 1, RT_IPC_FLAG_FIFO);
}
rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
{
rtgui_thread_t* thread = rtgui_malloc(sizeof(struct rtgui_thread));
@ -296,12 +286,8 @@ rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
thread->mq = mq;
thread->widget = RT_NULL;
/* take semaphore */
rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER);
/* set user thread */
tid->user_data = (rt_uint32_t)thread;
/* release semaphore */
rt_sem_release(&_rtgui_thread_hash_semaphore);
}
return thread;
@ -316,18 +302,27 @@ void rtgui_thread_deregister(rt_thread_t tid)
if (thread != RT_NULL)
{
/* take semaphore */
rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER);
/* remove rtgui_thread */
tid->user_data = 0;
/* release semaphore */
rt_sem_release(&_rtgui_thread_hash_semaphore);
/* free rtgui_thread */
rtgui_free(thread);
}
}
/* get current gui thread */
rtgui_thread_t* rtgui_thread_self()
{
struct rtgui_thread* thread;
rt_thread_t self;
/* get current thread */
self = rt_thread_self();
thread = (struct rtgui_thread*)(self->user_data);
return thread;
}
extern rt_thread_t rt_thread_find(char* name);
rt_thread_t rtgui_thread_get_server()
{

View File

@ -488,7 +488,7 @@ void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t i
{
struct rtgui_dc* dc;
struct rtgui_rect rect, item_rect;
rt_size_t item_size, bord_size;
int item_size, bord_size;
/* begin drawing */
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(radiobox));
@ -572,7 +572,7 @@ void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox)
{
struct rtgui_dc* dc;
struct rtgui_rect rect, item_rect;
rt_size_t item_size, bord_size, index;
int item_size, bord_size, index;
rtgui_color_t fc;
/* begin drawing */

View File

@ -69,25 +69,13 @@ void rtgui_dc_end_drawing(struct rtgui_dc* dc);
/* destroy a dc */
void rtgui_dc_destory(struct rtgui_dc* dc);
void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y);
void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgui_color_t color);
void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2);
void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y);
void rtgui_dc_fill_rect (struct rtgui_dc* dc, struct rtgui_rect* rect);
void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect);
void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc);
rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc);
rt_bool_t rtgui_dc_get_visible(struct rtgui_dc* dc);
void rtgui_dc_get_rect(struct rtgui_dc*dc, rtgui_rect_t* rect);
void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2);
void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect);
void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect);
void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect);
void rtgui_dc_draw_mono_bmp(struct rtgui_dc* dc, int x, int y, int w, int h, const rt_uint8_t* data);
void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data);
void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data);
@ -107,4 +95,96 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry);
/*
* dc inline function
*
* Note:
* In order to improve drawing speed, put most of common function of dc to inline
*/
/*
* draw a point on dc
*/
rt_inline void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y)
{
dc->draw_point(dc, x, y);
}
/*
* draw a color point on dc
*/
rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgui_color_t color)
{
dc->draw_color_point(dc, x, y, color);
}
/*
* draw a vertical line on dc
*/
rt_inline void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2)
{
dc->draw_vline(dc, x, y1, y2);
}
/*
* draw a horizontal line on dc
*/
rt_inline void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y)
{
dc->draw_hline(dc, x1, x2, y);
}
/*
* fill a rect with background color
*/
rt_inline void rtgui_dc_fill_rect (struct rtgui_dc* dc, struct rtgui_rect* rect)
{
dc->fill_rect(dc, rect);
}
/*
* blit a dc on hardware dc
*/
rt_inline void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect)
{
if (dest == RT_NULL || rect == RT_NULL) return;
dc->blit(dc, dc_point, dest, rect);
}
/*
* set gc of dc
*/
rt_inline void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc)
{
dc->set_gc(dc, gc);
}
/*
* get gc of dc
*/
rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc)
{
return dc->get_gc(dc);
}
/*
* get visible status of dc
*/
rt_inline rt_bool_t rtgui_dc_get_visible(struct rtgui_dc* dc)
{
return dc->get_visible(dc);
}
/*
* get rect of dc
*/
rt_inline void rtgui_dc_get_rect(struct rtgui_dc*dc, rtgui_rect_t* rect)
{
if (rect != RT_NULL)
{
dc->get_rect(dc, rect);
}
}
#endif

View File

@ -39,7 +39,7 @@ struct rtgui_image
rt_uint16_t w, h;
/* image engine */
struct rtgui_image_engine* engine;
const struct rtgui_image_engine* engine;
/* image private data */
void* data;

View File

@ -28,7 +28,7 @@ struct rtgui_image_hdcmm
};
void rtgui_image_hdc_init(void);
extern struct rtgui_image_engine rtgui_image_hdcmm_engine;
extern const struct rtgui_image_engine rtgui_image_hdcmm_engine;
#define HDC_HEADER_SIZE (5 * 4)
#define RTGUI_IMAGE_HDC_DEF(bpp, w, h, pixels) \

View File

@ -14,7 +14,7 @@
#ifndef __RTGUI_REGION_H__
#define __RTGUI_REGION_H__
#include <rtgui/rtgui.h>
#include <rtgui/rtgui.h>
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
@ -83,15 +83,15 @@ void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t* rect);
void rtgui_region_empty (rtgui_region_t *region);
void rtgui_region_dump(rtgui_region_t* region);
/* rect functions */
extern rtgui_rect_t rtgui_empty_rect;
/* rect functions */
extern rtgui_rect_t rtgui_empty_rect;
void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y);
void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
int rtgui_rect_contains_point(rtgui_rect_t *rect, int x, int y);
int rtgui_rect_is_intersect(rtgui_rect_t *rect1, rtgui_rect_t *rect2);
void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align);
void rtgui_rect_inflate(rtgui_rect_t *rect, int d);
void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest);
int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y);
int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2);
#if defined(__cplusplus) || defined(c_plusplus)
}

View File

@ -21,6 +21,12 @@ struct rtgui_dc;
struct rtgui_event;
struct rtgui_widget;
#ifdef RTGUI_USING_SMALL_SIZE
#define RTGUI_EVENT_BUFFER_SIZE 64
#else
#define RTGUI_EVENT_BUFFER_SIZE 256
#endif
struct rtgui_thread
{
/* the thread id */
@ -31,6 +37,8 @@ struct rtgui_thread
/* the owner of thread */
struct rtgui_widget* widget;
/* event buffer */
rt_uint8_t event_buffer[RTGUI_EVENT_BUFFER_SIZE];
};
typedef struct rtgui_thread rtgui_thread_t;
struct rtgui_timer;
@ -55,9 +63,9 @@ void rtgui_timer_destory(rtgui_timer_t* timer);
void rtgui_timer_start(rtgui_timer_t* timer);
void rtgui_timer_stop (rtgui_timer_t* timer);
void rtgui_thread_system_init(void);
rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq);
void rtgui_thread_deregister(rt_thread_t tid);
rtgui_thread_t* rtgui_thread_self(void);
rt_thread_t rtgui_thread_get_server(void);

View File

@ -522,16 +522,20 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
/* windows event loop */
void rtgui_win_event_loop(rtgui_win_t* wnd)
{
/* the buffer uses to receive event */
char event_buf[256];
rtgui_thread_t* tid;
struct rtgui_event* event;
struct rtgui_event* event = (struct rtgui_event*)&event_buf[0];
tid = rtgui_thread_self();
RT_ASSERT(tid != RT_NULL);
/* point to event buffer */
event = (struct rtgui_event*)tid->event_buffer;
if (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
{
while (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
{
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
if (rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE) == RT_EOK)
{
/* perform event handler */
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
@ -542,7 +546,7 @@ void rtgui_win_event_loop(rtgui_win_t* wnd)
{
while (!(wnd->style & RTGUI_WIN_STYLE_CLOSED))
{
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
if (rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE) == RT_EOK)
{
/* perform event handler */
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);

View File

@ -162,16 +162,21 @@ void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag)
rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
{
/* the buffer uses to receive event */
char event_buf[256];
struct rtgui_event* event = (struct rtgui_event*)&event_buf[0];
rtgui_thread_t* tid;
struct rtgui_event* event;
tid = rtgui_thread_self();
RT_ASSERT(tid != RT_NULL);
/* point to event buffer */
event = (struct rtgui_event*)tid->event_buffer;
if (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
{
/* event loop for modal mode shown view */
while (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
{
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
if (rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE) == RT_EOK)
{
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
}
@ -184,7 +189,7 @@ rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
while (!(workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED))
{
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
if (rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE) == RT_EOK)
{
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
}