diff options
| author | [email protected] <[email protected]> | 2011-06-05 15:16:41 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2011-06-05 15:16:41 +0000 |
| commit | bbf68d15e513d4799f651acd4fd9f88fe3a03ffd (patch) | |
| tree | 373cff350b3df4b8326df7a6e698a41a9f496c19 /components/rtgui/common | |
| parent | b936b13ed25d596694517bff813c0c72c3769b3c (diff) | |
change graphic driver as RT-Thread device driver
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1454 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/common')
| -rw-r--r-- | components/rtgui/common/dc_client.c | 22 | ||||
| -rw-r--r-- | components/rtgui/common/dc_hw.c | 18 | ||||
| -rw-r--r-- | components/rtgui/common/framebuffer_driver.c | 225 | ||||
| -rw-r--r-- | components/rtgui/common/pixel_driver.c | 92 |
4 files changed, 337 insertions, 20 deletions
diff --git a/components/rtgui/common/dc_client.c b/components/rtgui/common/dc_client.c index 2e29a17160..f2db68d8e8 100644 --- a/components/rtgui/common/dc_client.c +++ b/components/rtgui/common/dc_client.c @@ -194,7 +194,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc) rt_kprintf("show cursor\n"); #endif /* update screen */ - hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ @@ -202,7 +202,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc) #endif /* update screen */ - hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #endif } } @@ -222,7 +222,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc) rt_kprintf("show cursor\n"); #endif /* update screen */ - hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(hw_driver, &(owner->extent)); #else /* send to server to end drawing */ struct rtgui_event_update_end eupdate; @@ -258,7 +258,7 @@ static void rtgui_dc_client_draw_point(struct rtgui_dc* self, int x, int y) if (rtgui_region_contains_point(&(owner->clip), x, y, &rect) == RT_EOK) { /* draw this point */ - hw_driver->set_pixel(&(owner->gc.foreground), x, y); + hw_driver->ops->set_pixel(&(owner->gc.foreground), x, y); } } @@ -279,7 +279,7 @@ static void rtgui_dc_client_draw_color_point(struct rtgui_dc* self, int x, int y if (rtgui_region_contains_point(&(owner->clip), x, y, &rect) == RT_EOK) { /* draw this point */ - hw_driver->set_pixel(&color, x, y); + hw_driver->ops->set_pixel(&color, x, y); } } @@ -316,7 +316,7 @@ static void rtgui_dc_client_draw_vline(struct rtgui_dc* self, int x, int y1, int if (prect->y2 < y2) y2 = prect->y2; /* draw vline */ - hw_driver->draw_vline(&(owner->gc.foreground), x, y1, y2); + hw_driver->ops->draw_vline(&(owner->gc.foreground), x, y1, y2); } else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); index ++) { @@ -335,7 +335,7 @@ static void rtgui_dc_client_draw_vline(struct rtgui_dc* self, int x, int y1, int if (prect->y2 < y2) draw_y2 = prect->y2; /* draw vline */ - hw_driver->draw_vline(&(owner->gc.foreground), x, draw_y1, draw_y2); + hw_driver->ops->draw_vline(&(owner->gc.foreground), x, draw_y1, draw_y2); } } @@ -373,7 +373,7 @@ static void rtgui_dc_client_draw_hline(struct rtgui_dc* self, int x1, int x2, in if (prect->x2 < x2) x2 = prect->x2; /* draw hline */ - hw_driver->draw_hline(&(owner->gc.foreground), x1, x2, y); + hw_driver->ops->draw_hline(&(owner->gc.foreground), x1, x2, y); } else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); index ++) { @@ -392,7 +392,7 @@ static void rtgui_dc_client_draw_hline(struct rtgui_dc* self, int x1, int x2, in if (prect->x2 < x2) draw_x2 = prect->x2; /* draw hline */ - hw_driver->draw_hline(&(owner->gc.foreground), draw_x1, draw_x2, y); + hw_driver->ops->draw_hline(&(owner->gc.foreground), draw_x1, draw_x2, y); } } @@ -455,7 +455,7 @@ static void rtgui_dc_client_blit_line (struct rtgui_dc* self, int x1, int x2, in if (prect->x2 < x2) x2 = prect->x2; /* draw hline */ - hw_driver->draw_raw_hline(line_data, x1, x2, y); + hw_driver->ops->draw_raw_hline(line_data, x1, x2, y); } else for (index = 0; index < rtgui_region_num_rects(&(owner->clip)); 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->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->byte_per_pixel, draw_x1, draw_x2, y); } } diff --git a/components/rtgui/common/dc_hw.c b/components/rtgui/common/dc_hw.c index 4dc9264e41..c0dac5c6ea 100644 --- a/components/rtgui/common/dc_hw.c +++ b/components/rtgui/common/dc_hw.c @@ -170,7 +170,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc) rt_kprintf("show cursor\n"); #endif /* update screen */ - self->hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #else #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ @@ -178,7 +178,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc) #endif /* update screen */ - self->hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #endif } } @@ -198,7 +198,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc) rt_kprintf("show cursor\n"); #endif /* update screen */ - self->hw_driver->screen_update(&(owner->extent)); + rtgui_graphic_driver_screen_update(self->hw_driver, &(owner->extent)); #else /* send to server to end drawing */ struct rtgui_event_update_end eupdate; @@ -230,7 +230,7 @@ static void rtgui_dc_hw_draw_point(struct rtgui_dc* self, int x, int y) y = y + dc->owner->extent.y1; /* draw this point */ - dc->hw_driver->set_pixel(&(dc->owner->gc.foreground), x, y); + dc->hw_driver->ops->set_pixel(&(dc->owner->gc.foreground), x, y); } static void rtgui_dc_hw_draw_color_point(struct rtgui_dc* self, int x, int y, rtgui_color_t color) @@ -244,7 +244,7 @@ static void rtgui_dc_hw_draw_color_point(struct rtgui_dc* self, int x, int y, rt y = y + dc->owner->extent.y1; /* draw this point */ - dc->hw_driver->set_pixel(&color, x, y); + dc->hw_driver->ops->set_pixel(&color, x, y); } /* @@ -262,7 +262,7 @@ static void rtgui_dc_hw_draw_vline(struct rtgui_dc* self, int x, int y1, int y2) y2 = y2 + dc->owner->extent.y1; /* draw vline */ - dc->hw_driver->draw_vline(&(dc->owner->gc.foreground), x, y1, y2); + dc->hw_driver->ops->draw_vline(&(dc->owner->gc.foreground), x, y1, y2); } /* @@ -281,7 +281,7 @@ static void rtgui_dc_hw_draw_hline(struct rtgui_dc* self, int x1, int x2, int y) y = y + dc->owner->extent.y1; /* draw hline */ - dc->hw_driver->draw_hline(&(dc->owner->gc.foreground), x1, x2, y); + dc->hw_driver->ops->draw_hline(&(dc->owner->gc.foreground), x1, x2, y); } static void rtgui_dc_hw_fill_rect (struct rtgui_dc* self, struct rtgui_rect* rect) @@ -302,7 +302,7 @@ static void rtgui_dc_hw_fill_rect (struct rtgui_dc* self, struct rtgui_rect* rec /* fill rect */ for (index = dc->owner->extent.y1 + rect->y1; index < dc->owner->extent.y1 + rect->y2; index ++) { - dc->hw_driver->draw_hline(&color, x1, x2, index); + dc->hw_driver->ops->draw_hline(&color, x1, x2, index); } } @@ -318,7 +318,7 @@ static void rtgui_dc_hw_blit_line (struct rtgui_dc* self, int x1, int x2, int y, x2 = x2 + dc->owner->extent.x1; y = y + dc->owner->extent.y1; - dc->hw_driver->draw_raw_hline(line_data, x1, x2, y); + dc->hw_driver->ops->draw_raw_hline(line_data, x1, x2, y); } static void rtgui_dc_hw_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect) diff --git a/components/rtgui/common/framebuffer_driver.c b/components/rtgui/common/framebuffer_driver.c new file mode 100644 index 0000000000..477e096eed --- /dev/null +++ b/components/rtgui/common/framebuffer_driver.c @@ -0,0 +1,225 @@ +#include <rtgui/rtgui_system.h>
+#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)
+
+static void _rgb565_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t 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)
+{
+ rt_uint16_t pixel;
+
+ pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
+
+ /* get pixel from color */
+ *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)
+{
+ rt_ubase_t index;
+ rt_uint16_t pixel;
+ rt_uint16_t *pixel_ptr;
+
+ /* get pixel from color */
+ pixel = rtgui_color_to_565(*c);
+
+ /* get pixel pointer in framebuffer */
+ pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
+
+ for (index = x1; index < x2; index ++)
+ {
+ *pixel_ptr = pixel;
+ pixel_ptr ++;
+ }
+}
+
+static void _rgb565_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
+{
+ rt_uint8_t *dst;
+ rt_uint16_t pixel;
+ rt_ubase_t index;
+
+ pixel = rtgui_color_to_565(*c);
+ dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
+ for (index = y1; index < y2; index ++)
+ {
+ *(rt_uint16_t*)dst = pixel;
+ dst += rtgui_graphic_get_device()->pitch;
+ }
+}
+
+static void _rgb565p_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t 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)
+{
+ rt_uint16_t pixel;
+
+ pixel = *GET_PIXEL(rtgui_graphic_get_device(), x, y, rt_uint16_t);
+
+ /* get pixel from color */
+ *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)
+{
+ rt_ubase_t index;
+ rt_uint16_t pixel;
+ rt_uint16_t *pixel_ptr;
+
+ /* get pixel from color */
+ pixel = rtgui_color_to_565p(*c);
+
+ /* get pixel pointer in framebuffer */
+ pixel_ptr = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint16_t);
+
+ for (index = x1; index < x2; index ++)
+ {
+ *pixel_ptr = pixel;
+ pixel_ptr ++;
+ }
+}
+
+static void _rgb565p_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
+{
+ rt_uint8_t *dst;
+ rt_uint16_t pixel;
+ rt_ubase_t index;
+
+ pixel = rtgui_color_to_565p(*c);
+ dst = GET_PIXEL(rtgui_graphic_get_device(), x, y1, rt_uint8_t);
+ for (index = y1; index < y2; index ++)
+ {
+ *(rt_uint16_t*)dst = pixel;
+ dst += rtgui_graphic_get_device()->pitch;
+ }
+}
+
+/* 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)
+{
+ 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);
+}
+
+const struct rtgui_graphic_driver_ops _framebuffer_rgb565_ops =
+{
+ _rgb565_set_pixel,
+ _rgb565_get_pixel,
+ _rgb565_draw_hline,
+ _rgb565_draw_vline,
+ framebuffer_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops _framebuffer_rgb565p_ops =
+{
+ _rgb565p_set_pixel,
+ _rgb565p_get_pixel,
+ _rgb565p_draw_hline,
+ _rgb565p_draw_vline,
+ framebuffer_draw_raw_hline,
+};
+
+#define FRAMEBUFFER (rtgui_graphic_get_device()->framebuffer)
+#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)
+{
+ if (*c == white)
+ MONO_PIXEL(FRAMEBUFFER, x, y) &= ~(1 << (y%8));
+ else
+ 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)
+{
+ if (MONO_PIXEL(FRAMEBUFFER, x, y) & (1 << (y%8)))
+ *c = black;
+ else
+ *c = white;
+}
+
+static void _mono_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
+{
+ rt_ubase_t index;
+
+ if (*c == white)
+ for (index = x1; index < x2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
+ }
+ else
+ for (index = x1; index < x2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
+ }
+}
+
+static void _mono_draw_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
+{
+ rt_ubase_t index;
+
+ if (*c == white)
+ for (index = y1; index < y2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, x, index) &= ~(1 << (index%8));
+ }
+ else
+ for (index = y1; index < y2; index ++)
+ {
+ MONO_PIXEL(FRAMEBUFFER, x, index) |= (1 << (index%8));
+ }
+}
+
+/* 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)
+{
+ rt_ubase_t index;
+
+ for (index = x1; index < x2; index ++)
+ {
+ if (pixels[index/8] && (1 << (index % 8)))
+ MONO_PIXEL(FRAMEBUFFER, index, y) |= (1 << (y%8));
+ else
+ MONO_PIXEL(FRAMEBUFFER, index, y) &= ~(1 << (y%8));
+ }
+}
+
+const struct rtgui_graphic_driver_ops _framebuffer_mono_ops =
+{
+ _mono_set_pixel,
+ _mono_get_pixel,
+ _mono_draw_hline,
+ _mono_draw_vline,
+ _mono_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format)
+{
+ switch (pixel_format)
+ {
+ case PIXEL_FORMAT_MONO:
+ return &_framebuffer_mono_ops;
+ case PIXEL_FORMAT_GRAY4:
+ break;
+ case PIXEL_FORMAT_GRAY16:
+ break;
+ case PIXEL_FORMAT_RGB565:
+ return &_framebuffer_rgb565_ops;
+ case PIXEL_FORMAT_RGB565P:
+ return &_framebuffer_rgb565p_ops;
+ }
+
+ return RT_NULL;
+}
+
diff --git a/components/rtgui/common/pixel_driver.c b/components/rtgui/common/pixel_driver.c new file mode 100644 index 0000000000..1140acc66c --- /dev/null +++ b/components/rtgui/common/pixel_driver.c @@ -0,0 +1,92 @@ +#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)
+{
+ switch (rtgui_graphic_get_device()->pixel_format)
+ {
+ case 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,
+ sizeof(pixel));
+ }
+ break;
+
+ case 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,
+ 3);
+ }
+
+ break;
+ }
+}
+
+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:
+ {
+ rt_uint16_t pixel;
+ rt_device_read(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
+ rtgui_graphic_get_device()->byte_per_pixel);
+ /* get pixel from color */
+ *c = rtgui_color_from_565(pixel);
+ }
+ break;
+
+ case PIXEL_FORMAT_RGB888:
+ {
+ rt_uint32_t pixel;
+ rt_device_read(rtgui_graphic_get_device()->device, PIXEL_POSITION(x, y), &pixel,
+ 3);
+ /* get pixel from color */
+ *c = rtgui_color_from_888(pixel);
+ }
+ break;
+ }
+}
+
+static void _pixeldevice_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y)
+{
+ rt_ubase_t index;
+
+ for (index = x1; index < x2; index ++)
+ _pixeldevice_set_pixel(c, index, y);
+}
+
+static void _pixeldevice_vline(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2)
+{
+ rt_ubase_t index;
+
+ for (index = y1; index < y2; index ++)
+ _pixeldevice_set_pixel(c, x, index);
+}
+
+/* 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);
+}
+
+/* pixel device */
+const struct rtgui_graphic_driver_ops _pixeldevice_ops =
+{
+ _pixeldevice_set_pixel,
+ _pixeldevice_get_pixel,
+ _pixeldevice_draw_hline,
+ _pixeldevice_vline,
+ _pixeldevice_draw_raw_hline,
+};
+
+const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pixel_format)
+{
+ return &_pixeldevice_ops;
+}
+
|
