change to graphic device.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1459 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
5284d6d52e
commit
80da4b9775
@ -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 ++)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user