diff options
| author | [email protected] <[email protected]> | 2011-06-06 09:10:13 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-06-06 09:10:13 +0000 |
| commit | 80da4b977588119a2e66566fb9a2e7a0c3588a62 (patch) | |
| tree | 6d0f4b18be36779a0f6fdd9bfe83913026064f10 /components/rtgui | |
| parent | 5284d6d52e39faefcf96dedad6695bb46d2d5579 (diff) | |
change to graphic device.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1459 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui')
| -rw-r--r-- | components/rtgui/common/dc_buffer.c | 15 | ||||
| -rw-r--r-- | components/rtgui/common/dc_client.c | 2 | ||||
| -rw-r--r-- | components/rtgui/common/framebuffer_driver.c | 14 | ||||
| -rw-r--r-- | components/rtgui/common/image_bmp.c | 10 | ||||
| -rw-r--r-- | components/rtgui/common/image_hdc.c | 2 | ||||
| -rw-r--r-- | components/rtgui/common/pixel_driver.c | 22 | ||||
| -rw-r--r-- | components/rtgui/include/rtgui/driver.h | 34 | ||||
| -rw-r--r-- | components/rtgui/server/driver.c | 16 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.c | 2 | ||||
| -rw-r--r-- | components/rtgui/widgets/scrollbar.c | 4 |
10 files changed, 52 insertions, 69 deletions
diff --git a/components/rtgui/common/dc_buffer.c b/components/rtgui/common/dc_buffer.c index 730156e89c..7677fa9dd5 100644 --- a/components/rtgui/common/dc_buffer.c +++ b/components/rtgui/common/dc_buffer.c @@ -20,6 +20,11 @@ #define hw_driver (rtgui_graphic_driver_get_default()) +#define RTGUI_BLENDMODE_NONE 0x00 +#define RTGUI_BLENDMODE_BLEND 0x01 +#define RTGUI_BLENDMODE_ADD 0x02 +#define RTGUI_BLENDMODE_MOD 0x03 + struct rtgui_dc_buffer { struct rtgui_dc parent; @@ -27,6 +32,10 @@ struct rtgui_dc_buffer /* graphic context */ rtgui_gc_t gc; + /* pixel format */ + rt_uint8_t pixel_format; + rt_uint8_t blend_mode; + /* width and height */ rt_uint16_t width, height; rt_uint16_t pitch; @@ -240,7 +249,7 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p /* prepare pixel line */ pixels = dc->pixel + dc_point->y * dc->pitch + dc_point->x * sizeof(rtgui_color_t); - if (hw_driver->byte_per_pixel == sizeof(rtgui_color_t)) + if (hw_driver->bits_per_pixel == sizeof(rtgui_color_t) * 8) { /* it's the same byte per pixel, draw it directly */ for (index = rect->y1; index < rect->y1 + rect_height; index++) @@ -252,11 +261,11 @@ static void rtgui_dc_buffer_blit(struct rtgui_dc* self, struct rtgui_point* dc_p else { /* get blit line function */ - blit_line = rtgui_blit_line_get(hw_driver->byte_per_pixel, 4); + blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8, 4); /* calculate pitch */ pitch = rect_width * sizeof(rtgui_color_t); /* create line buffer */ - line_ptr = (rt_uint8_t*) rtgui_malloc(rect_width * hw_driver->byte_per_pixel); + line_ptr = (rt_uint8_t*) rtgui_malloc(rect_width * hw_driver->bits_per_pixel/8); /* draw each line */ for (index = rect->y1; index < rect->y1 + rect_height; index ++) diff --git a/components/rtgui/common/dc_client.c b/components/rtgui/common/dc_client.c index f2db68d8e8..a3559a8842 100644 --- a/components/rtgui/common/dc_client.c +++ b/components/rtgui/common/dc_client.c @@ -474,7 +474,7 @@ static void rtgui_dc_client_blit_line (struct rtgui_dc* self, int x1, int x2, in if (prect->x2 < x2) draw_x2 = prect->x2; /* draw hline */ - hw_driver->ops->draw_raw_hline(line_data + (draw_x1 - x1) * hw_driver->byte_per_pixel, draw_x1, draw_x2, y); + hw_driver->ops->draw_raw_hline(line_data + (draw_x1 - x1) * hw_driver->bits_per_pixel/8, draw_x1, draw_x2, y); } } diff --git a/components/rtgui/common/framebuffer_driver.c b/components/rtgui/common/framebuffer_driver.c index 477e096eed..ed411f23c4 100644 --- a/components/rtgui/common/framebuffer_driver.c +++ b/components/rtgui/common/framebuffer_driver.c @@ -2,7 +2,7 @@ #include <rtgui/driver.h>
#define GET_PIXEL(dst, x, y, type) \
- (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * (dst)->byte_per_pixel)
+ (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * ((dst)->bits_per_pixel/8))
static void _rgb565_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
{
@@ -108,7 +108,7 @@ static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base rt_uint8_t *dst;
dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t);
- rt_memcpy(dst, pixels, (x2 - x1) * rtgui_graphic_get_device()->byte_per_pixel);
+ rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
}
const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
@@ -208,15 +208,15 @@ const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_forma {
switch (pixel_format)
{
- case PIXEL_FORMAT_MONO:
+ case RTGRAPHIC_PIXEL_FORMAT_MONO:
return &_framebuffer_mono_ops;
- case PIXEL_FORMAT_GRAY4:
+ case RTGRAPHIC_PIXEL_FORMAT_GRAY4:
break;
- case PIXEL_FORMAT_GRAY16:
+ case RTGRAPHIC_PIXEL_FORMAT_GRAY16:
break;
- case PIXEL_FORMAT_RGB565:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565:
return &_framebuffer_rgb565_ops;
- case PIXEL_FORMAT_RGB565P:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
return &_framebuffer_rgb565p_ops;
}
diff --git a/components/rtgui/common/image_bmp.c b/components/rtgui/common/image_bmp.c index f68dd507e6..9dd9798675 100644 --- a/components/rtgui/common/image_bmp.c +++ b/components/rtgui/common/image_bmp.c @@ -462,7 +462,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, /* get pixel pointer */
ptr = bmp->pixels;
- if (bmp->byte_per_pixel == hw_driver->byte_per_pixel)
+ if (bmp->byte_per_pixel == hw_driver->bits_per_pixel/8)
{
for (y = 0; y < h; y ++)
{
@@ -481,8 +481,8 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, if (image->palette == RT_NULL)
{
rtgui_blit_line_func blit_line;
- line_ptr = (rt_uint8_t*) rtgui_malloc(hw_driver->byte_per_pixel * w);
- blit_line = rtgui_blit_line_get(hw_driver->byte_per_pixel , bmp->byte_per_pixel);
+ line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
+ blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
pitch = w * bmp->byte_per_pixel;
if (line_ptr != RT_NULL)
{
@@ -585,7 +585,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, }
else
{
- rt_uint8_t *line_ptr = (rt_uint8_t*) rtgui_malloc(hw_driver->byte_per_pixel * w);
+ rt_uint8_t *line_ptr = (rt_uint8_t*) rtgui_malloc((hw_driver->bits_per_pixel/8) * w);
if (line_ptr == RT_NULL) return;
/* draw each line */
@@ -607,7 +607,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, {
int pitch;
rtgui_blit_line_func blit_line;
- blit_line = rtgui_blit_line_get(hw_driver->byte_per_pixel , bmp->byte_per_pixel);
+ blit_line = rtgui_blit_line_get(hw_driver->bits_per_pixel/8 , bmp->byte_per_pixel);
pitch = w * bmp->byte_per_pixel;
if (line_ptr != RT_NULL)
{
diff --git a/components/rtgui/common/image_hdc.c b/components/rtgui/common/image_hdc.c index c64db4f3bf..8e19a1c05a 100644 --- a/components/rtgui/common/image_hdc.c +++ b/components/rtgui/common/image_hdc.c @@ -94,7 +94,7 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi image->engine = &rtgui_image_hdc_engine; image->data = hdc; hdc->filerw = file; - hdc->byte_per_pixel = hdc->hw_driver->byte_per_pixel; + hdc->byte_per_pixel = hdc->hw_driver->bits_per_pixel/8; hdc->pitch = image->w * hdc->byte_per_pixel; hdc->pixel_offset = rtgui_filerw_tell(file); diff --git a/components/rtgui/common/pixel_driver.c b/components/rtgui/common/pixel_driver.c index 1140acc66c..3ee321ba66 100644 --- a/components/rtgui/common/pixel_driver.c +++ b/components/rtgui/common/pixel_driver.c @@ -5,20 +5,20 @@ static void _pixeldevice_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) {
switch (rtgui_graphic_get_device()->pixel_format)
{
- case PIXEL_FORMAT_RGB565:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565:
{
rt_uint16_t pixel;
pixel = rtgui_color_to_565(*c);
- rt_device_write(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
+ rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
sizeof(pixel));
}
break;
- case PIXEL_FORMAT_RGB888:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB888:
{
rt_uint32_t pixel;
pixel = rtgui_color_to_888(*c);
- rt_device_write(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
+ rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
3);
}
@@ -30,20 +30,20 @@ static void _pixeldevice_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y) {
switch (rtgui_graphic_get_device()->pixel_format)
{
- case PIXEL_FORMAT_RGB565:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB565:
{
rt_uint16_t pixel;
- rt_device_read(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
- rtgui_graphic_get_device()->byte_per_pixel);
+ rt_device_read(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
+ (rtgui_graphic_get_device()->bits_per_pixel/8));
/* get pixel from color */
*c = rtgui_color_from_565(pixel);
}
break;
- case PIXEL_FORMAT_RGB888:
+ case RTGRAPHIC_PIXEL_FORMAT_RGB888:
{
rt_uint32_t pixel;
- rt_device_read(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
+ rt_device_read(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
3);
/* get pixel from color */
*c = rtgui_color_from_888(pixel);
@@ -71,8 +71,8 @@ static void _pixeldevice_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_ /* draw raw hline */
static void _pixeldevice_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
{
- rt_device_write(rtgui_graphic_get_device()->device, PIXEL_POSITION(x1, y), pixels,
- (x2 - x1) * rtgui_graphic_get_device()->byte_per_pixel);
+ rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x1, y), pixels,
+ (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
}
/* pixel device */
diff --git a/components/rtgui/include/rtgui/driver.h b/components/rtgui/include/rtgui/driver.h index 4cc187fb2d..1f929d2b02 100644 --- a/components/rtgui/include/rtgui/driver.h +++ b/components/rtgui/include/rtgui/driver.h @@ -17,38 +17,6 @@ #include <rtgui/list.h>
#include <rtgui/color.h>
-#define LCD_RECT_UPDATE 0
-#define LCD_ON 1
-#define LCD_OFF 2
-#define LCD_GET_INFO 3
-#define LCD_MODE_SET 4
-
-enum
-{
- PIXEL_FORMAT_MONO = 0,
- PIXEL_FORMAT_GRAY4,
- PIXEL_FORMAT_GRAY16,
- PIXEL_FORMAT_RGB332,
- PIXEL_FORMAT_RGB444,
- PIXEL_FORMAT_RGB565,
- PIXEL_FORMAT_RGB565P,
- PIXEL_FORMAT_RGB666,
- PIXEL_FORMAT_RGB888,
- PIXEL_FORMAT_ARGB888
-};
-#define PIXEL_POSITION(x, y) ((x << 16) | y)
-
-struct rt_lcd_info
-{
- rt_uint8_t pixel_format;
- rt_uint8_t byte_per_pixel;
-
- rt_uint16_t width;
- rt_uint16_t height;
-
- rt_uint8_t *framebuffer;
-};
-
struct rtgui_graphic_driver_ops
{
/* set and get pixel in (x, y) */
@@ -66,7 +34,7 @@ struct rtgui_graphic_driver {
/* pixel format and byte per pixel */
rt_uint8_t pixel_format;
- rt_uint8_t byte_per_pixel;
+ rt_uint8_t bits_per_pixel;
rt_uint16_t pitch;
/* screen width and height */
diff --git a/components/rtgui/server/driver.c b/components/rtgui/server/driver.c index 43b4b8ac43..93f0195d69 100644 --- a/components/rtgui/server/driver.c +++ b/components/rtgui/server/driver.c @@ -11,6 +11,7 @@ * Date Author Notes * 2009-10-04 Bernard first version */ +#include <rtthread.h> #include <rtgui/driver.h> struct rtgui_graphic_driver _driver; @@ -37,10 +38,10 @@ void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rt rt_err_t rtgui_graphic_set_device(rt_device_t device) { rt_err_t result; - struct rt_lcd_info info; + struct rt_device_graphic_info info; /* get framebuffer address */ - result = rt_device_control(device, LCD_GET_INFO, &info); + result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); if (result != RT_EOK) { /* get device information failed */ @@ -50,10 +51,10 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device) /* initialize framebuffer driver */ _driver.device = device; _driver.pixel_format = info.pixel_format; - _driver.byte_per_pixel = info.byte_per_pixel; + _driver.bits_per_pixel = info.bits_per_pixel; _driver.width = info.width; _driver.height = info.height; - _driver.pitch = _driver.width * _driver.byte_per_pixel; + _driver.pitch = _driver.width * _driver.bits_per_pixel/8; _driver.framebuffer = info.framebuffer; if (info.framebuffer != RT_NULL) @@ -73,7 +74,12 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device) /* screen update */ void rtgui_graphic_driver_screen_update(struct rtgui_graphic_driver* driver, rtgui_rect_t *rect) { - rt_device_control(driver->device, LCD_RECT_UPDATE, rect); + struct rt_device_rect_info rect_info; + + rect_info.x = rect->x1; rect_info.y = rect->y1; + rect_info.width = rect->x2 - rect->x1; + rect_info.height = rect->y2 - rect->y1; + rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info); } /* get video frame buffer */ diff --git a/components/rtgui/server/mouse.c b/components/rtgui/server/mouse.c index a28087cd0b..ff4ab0c2e5 100644 --- a/components/rtgui/server/mouse.c +++ b/components/rtgui/server/mouse.c @@ -139,7 +139,7 @@ void rtgui_mouse_init() #endif /* init cursor */ - _rtgui_cursor->bpp = gd->byte_per_pixel; + _rtgui_cursor->bpp = gd->bits_per_pixel/8; _rtgui_cursor->framebuffer = rtgui_graphic_driver_get_framebuffer(gd); _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width; diff --git a/components/rtgui/widgets/scrollbar.c b/components/rtgui/widgets/scrollbar.c index d611691cc7..5581ba0560 100644 --- a/components/rtgui/widgets/scrollbar.c +++ b/components/rtgui/widgets/scrollbar.c @@ -72,7 +72,7 @@ void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect) /* vertical scroll bar */
rect->x1 = scrollbar_rect.x1;
- rect->x2 = scrollbar_rect.x2 - 1;
+ rect->x2 = scrollbar_rect.x2;
rect->y1 = scrollbar_rect.y1 + btn_width + _rtgui_scrollbar_get_thumb_position(bar);
rect->y2 = rect->y1 + btn_width;
}
@@ -85,7 +85,7 @@ void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect) rect->x2 = rect->x1 + btn_height;
rect->y1 = scrollbar_rect.y1;
- rect->y2 = scrollbar_rect.y2 - 1;
+ rect->y2 = scrollbar_rect.y2;
}
}
|
