update graphic driver interface.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1463 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
34d4a1bf2f
commit
ce5a42cc18
|
@ -4,12 +4,12 @@
|
|||
#define GET_PIXEL(dst, x, y, type) \
|
||||
(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)
|
||||
static void _rgb565_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
*GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565(*c);
|
||||
}
|
||||
|
||||
static void _rgb565_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _rgb565_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
|
@ -19,7 +19,7 @@ static void _rgb565_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|||
*c = rtgui_color_from_565(pixel);
|
||||
}
|
||||
|
||||
static void _rgb565_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void _rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint16_t pixel;
|
||||
|
@ -38,7 +38,7 @@ static void _rgb565_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_
|
|||
}
|
||||
}
|
||||
|
||||
static void _rgb565_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
|
||||
static void _rgb565_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
rt_uint16_t pixel;
|
||||
|
@ -53,12 +53,12 @@ static void _rgb565_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_
|
|||
}
|
||||
}
|
||||
|
||||
static void _rgb565p_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
*GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t) = rtgui_color_to_565p(*c);
|
||||
}
|
||||
|
||||
static void _rgb565p_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
|
@ -68,7 +68,7 @@ static void _rgb565p_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|||
*c = rtgui_color_from_565p(pixel);
|
||||
}
|
||||
|
||||
static void _rgb565p_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void _rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint16_t pixel;
|
||||
|
@ -87,7 +87,7 @@ static void _rgb565p_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt
|
|||
}
|
||||
}
|
||||
|
||||
static void _rgb565p_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
|
||||
static void _rgb565p_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
rt_uint16_t pixel;
|
||||
|
@ -103,7 +103,7 @@ static void _rgb565p_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt
|
|||
}
|
||||
|
||||
/* draw raw hline */
|
||||
static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint8_t *dst;
|
||||
|
||||
|
@ -133,7 +133,7 @@ const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
|
|||
#define MONO_PIXEL(framebuffer, x, y) \
|
||||
((rt_uint8_t**)(framebuffer))[y/8][x]
|
||||
|
||||
static void _mono_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _mono_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
if (*c == white)
|
||||
MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y%8));
|
||||
|
@ -141,7 +141,7 @@ static void _mono_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|||
MONO_PIXEL(FRAMEBUFFER, x, y) |= (1 << (y%8));
|
||||
}
|
||||
|
||||
static void _mono_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _mono_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y%8)))
|
||||
*c = black;
|
||||
|
@ -149,7 +149,7 @@ static void _mono_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
|||
*c = white;
|
||||
}
|
||||
|
||||
static void _mono_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void _mono_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
|
@ -165,7 +165,7 @@ static void _mono_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_ba
|
|||
}
|
||||
}
|
||||
|
||||
static void _mono_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
|
||||
static void _mono_draw_vline(rtgui_color_t *c, int x , int y1, int y2)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
|
@ -182,7 +182,7 @@ static void _mono_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_ba
|
|||
}
|
||||
|
||||
/* draw raw hline */
|
||||
static void _mono_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void _mono_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
|
||||
|
|
|
@ -1,92 +1,154 @@
|
|||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
static void _pixeldevice_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
#define gfx_device (rtgui_graphic_get_device()->device)
|
||||
#define gfx_device_ops rt_graphix_ops(gfx_device)
|
||||
|
||||
static void _pixel_rgb565p_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
switch (rtgui_graphic_get_device()->pixel_format)
|
||||
{
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
||||
sizeof(pixel));
|
||||
}
|
||||
break;
|
||||
rt_uint16_t pixel;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x, y), &pixel,
|
||||
3);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->set_pixel((char*)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixeldevice_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y)
|
||||
static void _pixel_rgb565_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
switch (rtgui_graphic_get_device()->pixel_format)
|
||||
{
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
||||
{
|
||||
rt_uint16_t 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;
|
||||
rt_uint16_t pixel;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
||||
{
|
||||
rt_uint32_t 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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->set_pixel((char*)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixeldevice_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
|
||||
static void _pixel_rgb888_set_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint32_t pixel;
|
||||
|
||||
for (index = x1; index < x2; index ++)
|
||||
_pixeldevice_set_pixel(c, index, y);
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->set_pixel((char*)&pixel, x, y);
|
||||
}
|
||||
|
||||
static void _pixeldevice_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
|
||||
static void _pixel_rgb565p_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_ubase_t index;
|
||||
rt_uint16_t pixel;
|
||||
|
||||
for (index = y1; index < y2; index ++)
|
||||
_pixeldevice_set_pixel(c, x, index);
|
||||
gfx_device_ops->get_pixel((char*)&pixel, x, y);
|
||||
*c = rtgui_color_from_565p(pixel);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
static void _pixel_rgb565_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_device_write(rtgui_graphic_get_device()->device, RTGRAPHIC_PIXEL_POSITION(x1, y), pixels,
|
||||
(x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8));
|
||||
rt_uint16_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char*)&pixel, x, y);
|
||||
*c = rtgui_color_from_565(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_get_pixel(rtgui_color_t *c, int x, int y)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
gfx_device_ops->get_pixel((char*)&pixel, x, y);
|
||||
*c = rtgui_color_from_888(pixel);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_draw_hline(rtgui_color_t *c, int x1, int x2, int y)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->draw_hline((char*)&pixel, x1, x2, y);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565p_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565p(*c);
|
||||
gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_rgb565_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint16_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_565(*c);
|
||||
gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_rgb888_draw_vline(rtgui_color_t *c, int x, int y1, int y2)
|
||||
{
|
||||
rt_uint32_t pixel;
|
||||
|
||||
pixel = rtgui_color_to_888(*c);
|
||||
gfx_device_ops->draw_vline((char*)&pixel, x, y1, y2);
|
||||
}
|
||||
|
||||
static void _pixel_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y)
|
||||
{
|
||||
if (x2 > x1)
|
||||
gfx_device_ops->blit_line((char*)pixels, x1, y, (x2 - x1));
|
||||
else
|
||||
gfx_device_ops->blit_line((char*)pixels, x2, y, (x1 - x2));
|
||||
}
|
||||
|
||||
/* pixel device */
|
||||
const struct rtgui_graphic_driver_ops _pixeldevice_ops =
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb565p_ops =
|
||||
{
|
||||
_pixeldevice_set_pixel,
|
||||
_pixeldevice_get_pixel,
|
||||
_pixeldevice_draw_hline,
|
||||
_pixeldevice_vline,
|
||||
_pixeldevice_draw_raw_hline,
|
||||
_pixel_rgb565p_set_pixel,
|
||||
_pixel_rgb565p_get_pixel,
|
||||
_pixel_rgb565p_draw_hline,
|
||||
_pixel_rgb565p_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb565_ops =
|
||||
{
|
||||
_pixel_rgb565_set_pixel,
|
||||
_pixel_rgb565_get_pixel,
|
||||
_pixel_rgb565_draw_hline,
|
||||
_pixel_rgb565_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops _pixel_rgb888_ops =
|
||||
{
|
||||
_pixel_rgb888_set_pixel,
|
||||
_pixel_rgb888_get_pixel,
|
||||
_pixel_rgb888_draw_hline,
|
||||
_pixel_rgb888_draw_vline,
|
||||
_pixel_draw_raw_hline,
|
||||
};
|
||||
|
||||
const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
|
||||
{
|
||||
return &_pixeldevice_ops;
|
||||
}
|
||||
switch (pixel_format)
|
||||
{
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565:
|
||||
return &_pixel_rgb565_ops;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB565P:
|
||||
return &_pixel_rgb565p_ops;
|
||||
|
||||
case RTGRAPHIC_PIXEL_FORMAT_RGB888:
|
||||
return &_pixel_rgb888_ops;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
struct rtgui_graphic_driver_ops
|
||||
{
|
||||
/* set and get pixel in (x, y) */
|
||||
void (*set_pixel) (rtgui_color_t *c, rt_base_t x, rt_base_t y);
|
||||
void (*get_pixel) (rtgui_color_t *c, rt_base_t x, rt_base_t y);
|
||||
void (*set_pixel) (rtgui_color_t *c, int x, int y);
|
||||
void (*get_pixel) (rtgui_color_t *c, int x, int y);
|
||||
|
||||
void (*draw_hline)(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
|
||||
void (*draw_vline)(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2);
|
||||
void (*draw_hline)(rtgui_color_t *c, int x1, int x2, int y);
|
||||
void (*draw_vline)(rtgui_color_t *c, int x , int y1, int y2);
|
||||
|
||||
/* draw raw hline */
|
||||
void (*draw_raw_hline)(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y);
|
||||
void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y);
|
||||
};
|
||||
|
||||
struct rtgui_graphic_driver
|
||||
|
|
Loading…
Reference in New Issue