dc_buffer.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. /*
  2. * File : dc_buffer.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-16 Bernard first version
  13. */
  14. #include <rtgui/rtgui.h>
  15. #include <rtgui/dc.h>
  16. #include <rtgui/blit.h>
  17. #include <rtgui/dc_hw.h>
  18. #include <rtgui/color.h>
  19. #include <rtgui/rtgui_system.h>
  20. #include <rtgui/dc_draw.h>
  21. #include <string.h>
  22. static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc);
  23. static void rtgui_dc_buffer_draw_point(struct rtgui_dc *dc, int x, int y);
  24. static void rtgui_dc_buffer_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color);
  25. static void rtgui_dc_buffer_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2);
  26. static void rtgui_dc_buffer_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y);
  27. static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *dc, struct rtgui_rect *rect);
  28. static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data);
  29. static void rtgui_dc_buffer_blit(struct rtgui_dc *self, struct rtgui_point *dc_point,
  30. struct rtgui_dc *dest, rtgui_rect_t *rect);
  31. const struct rtgui_dc_engine dc_buffer_engine =
  32. {
  33. rtgui_dc_buffer_draw_point,
  34. rtgui_dc_buffer_draw_color_point,
  35. rtgui_dc_buffer_draw_vline,
  36. rtgui_dc_buffer_draw_hline,
  37. rtgui_dc_buffer_fill_rect,
  38. rtgui_dc_buffer_blit_line,
  39. rtgui_dc_buffer_blit,
  40. rtgui_dc_buffer_fini,
  41. };
  42. #define _dc_get_pitch(dc) \
  43. (dc->pitch)
  44. #define _dc_get_pixel(dc, x, y) \
  45. ((dc)->pixel + (y) * (dc)->pitch + (x) * rtgui_color_get_bpp((dc)->pixel_format))
  46. #define _dc_get_bits_per_pixel(dc) \
  47. rtgui_color_get_bits(dc->pixel_format)
  48. #define _hw_get_pixel(dst, x, y, type) \
  49. (type *)((rt_uint8_t*)((dst)->framebuffer) + (y) * (dst)->pitch + (x) * _UI_BITBYTES((dst)->bits_per_pixel))
  50. struct rtgui_dc *rtgui_dc_buffer_create(int w, int h)
  51. {
  52. rt_uint8_t pixel_format;
  53. pixel_format = rtgui_graphic_driver_get_default()->pixel_format;
  54. /* create a dc_buffer with hardware driver pixel format */
  55. return rtgui_dc_buffer_create_pixformat(pixel_format, w, h);
  56. }
  57. RTM_EXPORT(rtgui_dc_buffer_create);
  58. struct rtgui_dc *rtgui_dc_buffer_create_pixformat(rt_uint8_t pixel_format, int w, int h)
  59. {
  60. struct rtgui_dc_buffer *dc;
  61. dc = (struct rtgui_dc_buffer *)rtgui_malloc(sizeof(struct rtgui_dc_buffer));
  62. if (dc)
  63. {
  64. dc->parent.type = RTGUI_DC_BUFFER;
  65. dc->parent.engine = &dc_buffer_engine;
  66. dc->gc.foreground = default_foreground;
  67. dc->gc.background = default_background;
  68. dc->gc.font = rtgui_font_default();
  69. dc->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
  70. dc->pixel_format = pixel_format;
  71. dc->width = w;
  72. dc->height = h;
  73. dc->pitch = w * rtgui_color_get_bpp(pixel_format);
  74. dc->pixel = rtgui_malloc(h * dc->pitch);
  75. if (!dc->pixel)
  76. {
  77. rtgui_free(dc);
  78. return RT_NULL;
  79. }
  80. rt_memset(dc->pixel, 0, h * dc->pitch);
  81. return &(dc->parent);
  82. }
  83. return RT_NULL;
  84. }
  85. RTM_EXPORT(rtgui_dc_buffer_create_pixformat);
  86. struct rtgui_dc *rtgui_dc_buffer_create_from_dc(struct rtgui_dc* dc)
  87. {
  88. struct rtgui_dc_buffer *buffer;
  89. if (dc == RT_NULL)
  90. return RT_NULL;
  91. if (dc->type == RTGUI_DC_BUFFER)
  92. {
  93. struct rtgui_dc_buffer *d = (struct rtgui_dc_buffer*) dc;
  94. /* buffer clone */
  95. buffer = (struct rtgui_dc_buffer*)rtgui_dc_buffer_create_pixformat(d->pixel_format,
  96. d->width,
  97. d->height);
  98. if (buffer != RT_NULL)
  99. {
  100. rt_memcpy(buffer->pixel, d->pixel, d->pitch * d->height);
  101. return RTGUI_DC(buffer);
  102. }
  103. }
  104. return RT_NULL;
  105. }
  106. RTM_EXPORT(rtgui_dc_buffer_create_from_dc);
  107. rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc)
  108. {
  109. struct rtgui_dc_buffer *dc_buffer;
  110. dc_buffer = (struct rtgui_dc_buffer *)dc;
  111. return dc_buffer->pixel;
  112. }
  113. RTM_EXPORT(rtgui_dc_buffer_get_pixel);
  114. static rt_bool_t rtgui_dc_buffer_fini(struct rtgui_dc *dc)
  115. {
  116. struct rtgui_dc_buffer *buffer = (struct rtgui_dc_buffer *)dc;
  117. if (dc->type != RTGUI_DC_BUFFER) return RT_FALSE;
  118. rtgui_free(buffer->pixel);
  119. buffer->pixel = RT_NULL;
  120. return RT_TRUE;
  121. }
  122. static void rtgui_dc_buffer_draw_point(struct rtgui_dc *self, int x, int y)
  123. {
  124. struct rtgui_dc_buffer *dst;
  125. unsigned r, g, b, a;
  126. dst = (struct rtgui_dc_buffer *)self;
  127. /* does not draw point out of dc */
  128. if ((x >= dst->width) || (y >= dst->height)) return;
  129. if (x < 0 || y < 0) return;
  130. r = RTGUI_RGB_R(dst->gc.foreground);
  131. g = RTGUI_RGB_G(dst->gc.foreground);
  132. b = RTGUI_RGB_B(dst->gc.foreground);
  133. a = RTGUI_RGB_A(dst->gc.foreground);
  134. switch (dst->pixel_format)
  135. {
  136. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  137. DRAW_SETPIXELXY_RGB565(x, y);
  138. break;
  139. case RTGRAPHIC_PIXEL_FORMAT_BGR565:
  140. DRAW_SETPIXELXY_BGR565(x, y);
  141. break;
  142. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  143. DRAW_SETPIXELXY_RGB888(x, y);
  144. break;
  145. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  146. DRAW_SETPIXELXY_ARGB8888(x, y);
  147. break;
  148. }
  149. }
  150. static void rtgui_dc_buffer_draw_color_point(struct rtgui_dc *self, int x, int y, rtgui_color_t color)
  151. {
  152. struct rtgui_dc_buffer *dst;
  153. unsigned r, g, b, a;
  154. dst = (struct rtgui_dc_buffer *)self;
  155. /* does not draw point out of dc */
  156. if ((x >= dst->width) || (y >= dst->height)) return;
  157. if (x < 0 || y < 0) return;
  158. r = RTGUI_RGB_R(color);
  159. g = RTGUI_RGB_G(color);
  160. b = RTGUI_RGB_B(color);
  161. a = RTGUI_RGB_A(color);
  162. switch (dst->pixel_format)
  163. {
  164. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  165. DRAW_SETPIXELXY_RGB565(x, y);
  166. break;
  167. case RTGRAPHIC_PIXEL_FORMAT_BGR565:
  168. DRAW_SETPIXELXY_BGR565(x, y);
  169. break;
  170. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  171. DRAW_SETPIXELXY_RGB888(x, y);
  172. break;
  173. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  174. DRAW_SETPIXELXY_ARGB8888(x, y);
  175. break;
  176. }
  177. }
  178. static void rtgui_dc_buffer_draw_vline(struct rtgui_dc *self, int x1, int y1, int y2)
  179. {
  180. struct rtgui_dc_buffer *dst;
  181. unsigned r, g, b, a;
  182. dst = (struct rtgui_dc_buffer *)self;
  183. if (x1 < 0 || x1 >= dst->width) return;
  184. if (y1 >= dst->height) return;
  185. if (y1 < 0) y1 = 0;
  186. if (y2 > dst->height) y2 = dst->height;
  187. r = RTGUI_RGB_R(dst->gc.foreground);
  188. g = RTGUI_RGB_G(dst->gc.foreground);
  189. b = RTGUI_RGB_B(dst->gc.foreground);
  190. a = RTGUI_RGB_A(dst->gc.foreground);
  191. switch (dst->pixel_format)
  192. {
  193. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  194. VLINE(rt_uint16_t, DRAW_SETPIXEL_RGB565, 0);
  195. break;
  196. case RTGRAPHIC_PIXEL_FORMAT_BGR565:
  197. VLINE(rt_uint16_t, DRAW_SETPIXEL_BGR565, 0);
  198. break;
  199. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  200. VLINE(rt_uint16_t, DRAW_SETPIXEL_RGB888, 0);
  201. break;
  202. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  203. VLINE(rt_uint32_t, DRAW_SETPIXEL_ARGB8888, 0);
  204. break;
  205. }
  206. }
  207. static void rtgui_dc_buffer_draw_hline(struct rtgui_dc *self, int x1, int x2, int y1)
  208. {
  209. struct rtgui_dc_buffer *dst;
  210. unsigned r, g, b, a;
  211. dst = (struct rtgui_dc_buffer *)self;
  212. /* parameter checking */
  213. if (y1 < 0 || y1 >= dst->height) return;
  214. if (x1 >= dst->width) return;
  215. if (x1 < 0) x1 = 0;
  216. if (x2 > dst->width) x2 = dst->width;
  217. r = RTGUI_RGB_R(dst->gc.foreground);
  218. g = RTGUI_RGB_G(dst->gc.foreground);
  219. b = RTGUI_RGB_B(dst->gc.foreground);
  220. a = RTGUI_RGB_A(dst->gc.foreground);
  221. switch (dst->pixel_format)
  222. {
  223. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  224. HLINE(rt_uint16_t, DRAW_SETPIXEL_RGB565, 0);
  225. break;
  226. case RTGRAPHIC_PIXEL_FORMAT_BGR565:
  227. HLINE(rt_uint16_t, DRAW_SETPIXEL_BGR565, 0);
  228. break;
  229. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  230. HLINE(rt_uint16_t, DRAW_SETPIXEL_RGB888, 0);
  231. break;
  232. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  233. HLINE(rt_uint32_t, DRAW_SETPIXEL_ARGB8888, 0);
  234. break;
  235. }
  236. }
  237. static void rtgui_dc_buffer_fill_rect(struct rtgui_dc *self, struct rtgui_rect *dst_rect)
  238. {
  239. struct rtgui_dc_buffer *dst;
  240. unsigned r, g, b, a;
  241. rtgui_rect_t _r, *rect;
  242. RT_ASSERT(self);
  243. if (dst_rect == RT_NULL) rtgui_dc_get_rect(self, &_r);
  244. else _r = *dst_rect;
  245. dst = (struct rtgui_dc_buffer *)self;
  246. if (_r.x2 < 0 || _r.y2 < 0) return; /* out of rect */
  247. /* parameter checking */
  248. if (_r.x1 >= dst->width)
  249. return;
  250. else if (_r.x1 < 0)
  251. _r.x1 = 0;
  252. if (_r.x2 > dst->width)
  253. _r.x2 = dst->width;
  254. if (_r.y1 >= dst->height)
  255. return;
  256. else if (_r.y1 < 0)
  257. _r.y1 = 0;
  258. if (_r.y2 > dst->height)
  259. _r.y2 = dst->height;
  260. rect = &_r;
  261. r = RTGUI_RGB_R(dst->gc.background);
  262. g = RTGUI_RGB_G(dst->gc.background);
  263. b = RTGUI_RGB_B(dst->gc.background);
  264. a = RTGUI_RGB_A(dst->gc.background);
  265. switch (dst->pixel_format)
  266. {
  267. case RTGRAPHIC_PIXEL_FORMAT_RGB565:
  268. FILLRECT(rt_uint16_t, DRAW_SETPIXEL_RGB565);
  269. break;
  270. case RTGRAPHIC_PIXEL_FORMAT_BGR565:
  271. FILLRECT(rt_uint16_t, DRAW_SETPIXEL_BGR565);
  272. break;
  273. case RTGRAPHIC_PIXEL_FORMAT_RGB888:
  274. FILLRECT(rt_uint32_t, DRAW_SETPIXEL_RGB888);
  275. break;
  276. case RTGRAPHIC_PIXEL_FORMAT_ARGB888:
  277. FILLRECT(rt_uint32_t, DRAW_SETPIXEL_ARGB8888);
  278. break;
  279. }
  280. }
  281. /* blit a dc to another dc */
  282. static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
  283. struct rtgui_point *dc_pt,
  284. struct rtgui_dc *dest,
  285. rtgui_rect_t *rect)
  286. {
  287. int pitch;
  288. rt_uint16_t rect_width, rect_height;
  289. struct rtgui_rect _rect, *dest_rect;
  290. struct rtgui_point dc_point;
  291. struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
  292. if (rtgui_dc_get_visible(dest) == RT_FALSE)
  293. return;
  294. /* use the (0,0) origin point */
  295. if (dc_pt == RT_NULL)
  296. dc_point = rtgui_empty_point;
  297. else
  298. {
  299. dc_point = *dc_pt;
  300. }
  301. rtgui_dc_get_rect(dest, &_rect);
  302. /* use the rect of dest dc */
  303. if (rect == RT_NULL)
  304. {
  305. dest_rect = &_rect;
  306. }
  307. else
  308. {
  309. dest_rect = rect;
  310. if (dest_rect->x1 >= _rect.x2 || dest_rect->y1 >= _rect.y2)
  311. return;
  312. if (dest_rect->x1 < 0)
  313. {
  314. if (-dest_rect->x1 >= dc->width)
  315. return;
  316. dc_point.x += -dest_rect->x1;
  317. dest_rect->x1 = 0;
  318. }
  319. if (dest_rect->y1 < 0)
  320. {
  321. if (-dest_rect->y1 >= dc->height)
  322. return;
  323. dc_point.y += -dest_rect->y1;
  324. dest_rect->y1 = 0;
  325. }
  326. if (dest_rect->x2 > _rect.x2)
  327. dest_rect->x2 = _rect.x2;
  328. if (dest_rect->y2 > _rect.y2)
  329. dest_rect->y2 = _rect.y2;
  330. }
  331. if (dest_rect->x2 < dest_rect->x1 || dest_rect->y2 < dest_rect->y1) return;
  332. if (dc_point.x >= dc->width || dc_point.y >= dc->height) return;
  333. /* get the minimal width and height */
  334. rect_width = _UI_MIN(rtgui_rect_width(*dest_rect), dc->width - dc_point.x);
  335. rect_height = _UI_MIN(rtgui_rect_height(*dest_rect), dc->height - dc_point.y);
  336. if ((dest->type == RTGUI_DC_HW) || (dest->type == RTGUI_DC_CLIENT))
  337. {
  338. int index;
  339. rt_uint8_t *line_ptr, *pixels;
  340. rtgui_blit_line_func blit_line;
  341. struct rtgui_graphic_driver *hw_driver;
  342. hw_driver = rtgui_graphic_driver_get_default();
  343. /* prepare pixel line */
  344. pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);
  345. if (hw_driver->bits_per_pixel == _dc_get_bits_per_pixel(dc))
  346. {
  347. if (dest->type == RTGUI_DC_HW && hw_driver->framebuffer != RT_NULL)
  348. {
  349. rt_uint8_t *hw_pixels;
  350. struct rtgui_dc_hw *hw;
  351. hw = (struct rtgui_dc_hw*)dest;
  352. /* NOTES: the rect of DC is the logic coordination.
  353. * It should be converted to client
  354. */
  355. if (dest_rect != &_rect)
  356. {
  357. /* use local rect */
  358. _rect = *dest_rect;
  359. dest_rect = &_rect;
  360. }
  361. rtgui_rect_moveto(dest_rect, hw->owner->extent.x1, hw->owner->extent.y1);
  362. pitch = rtgui_color_get_bpp(hw_driver->pixel_format) * rect_width;
  363. hw_pixels = (rt_uint8_t*)(hw_driver->framebuffer + dest_rect->y1 * hw_driver->pitch +
  364. dest_rect->x1 * rtgui_color_get_bpp(hw_driver->pixel_format));
  365. /* do the blit with memory copy */
  366. for (index = 0; index < rect_height; index ++)
  367. {
  368. rt_memcpy(hw_pixels, pixels, pitch);
  369. pixels += dc->pitch;
  370. hw_pixels += hw_driver->pitch;
  371. }
  372. }
  373. else
  374. {
  375. /* it's the same bits per pixel, draw it directly */
  376. for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index++)
  377. {
  378. dest->engine->blit_line(dest, dest_rect->x1, dest_rect->x1 + rect_width, index, pixels);
  379. pixels += dc->pitch;
  380. }
  381. }
  382. }
  383. else
  384. {
  385. struct rtgui_graphic_driver *hw_driver;
  386. hw_driver = rtgui_graphic_driver_get_default();
  387. if ((dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_ARGB888) &&
  388. (dest->type == RTGUI_DC_HW) &&
  389. (hw_driver->framebuffer != RT_NULL) &&
  390. (hw_driver->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565))
  391. {
  392. /* do the fast ARGB to RGB565 blit */
  393. struct rtgui_blit_info info;
  394. struct rtgui_widget *owner;
  395. /* blit source */
  396. info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
  397. info.src_fmt = dc->pixel_format;
  398. info.src_h = rect_height;
  399. info.src_w = rect_width;
  400. info.src_pitch = dc->pitch;
  401. info.src_skip = info.src_pitch - info.src_w * rtgui_color_get_bpp(dc->pixel_format);
  402. owner = ((struct rtgui_dc_hw*)dest)->owner;
  403. /* blit destination */
  404. info.dst = (rt_uint8_t*)hw_driver->framebuffer;
  405. info.dst = info.dst + (owner->extent.y1 + dest_rect->y1) * hw_driver->pitch +
  406. (owner->extent.x1 + dest_rect->x1) * rtgui_color_get_bpp(hw_driver->pixel_format);
  407. info.dst_fmt = hw_driver->pixel_format;
  408. info.dst_h = rect_height;
  409. info.dst_w = rect_width;
  410. info.dst_pitch = hw_driver->pitch;
  411. info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(hw_driver->pixel_format);
  412. rtgui_blit(&info);
  413. }
  414. else
  415. {
  416. /* calculate pitch */
  417. pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);
  418. /* get blit line function */
  419. blit_line = rtgui_blit_line_get(_UI_BITBYTES(hw_driver->bits_per_pixel),
  420. rtgui_color_get_bpp(dc->pixel_format));
  421. if (hw_driver->framebuffer != RT_NULL)
  422. {
  423. struct rtgui_widget* owner;
  424. if (dest->type == RTGUI_DC_HW) owner = ((struct rtgui_dc_hw*) dest)->owner;
  425. else if (dest->type == RTGUI_DC_CLIENT) owner = RTGUI_CONTAINER_OF(dest, struct rtgui_widget, dc_type);
  426. else RT_ASSERT(0);
  427. /* change the logic coordinate to the device coordinate */
  428. rtgui_rect_moveto(dest_rect, owner->extent.x1, owner->extent.y1);
  429. for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index ++)
  430. {
  431. line_ptr = _hw_get_pixel(hw_driver, dest_rect->x1, index, rt_uint8_t);
  432. blit_line(line_ptr, (rt_uint8_t*)pixels, pitch);
  433. pixels += dc->pitch;
  434. }
  435. }
  436. else
  437. {
  438. /* calculate pitch */
  439. pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);
  440. /* create line buffer */
  441. line_ptr = (rt_uint8_t *) rtgui_malloc(rect_width * _UI_BITBYTES(hw_driver->bits_per_pixel));
  442. /* draw each line */
  443. for (index = dest_rect->y1; index < dest_rect->y1 + rect_height; index ++)
  444. {
  445. /* blit on line buffer */
  446. blit_line(line_ptr, (rt_uint8_t *)pixels, pitch);
  447. pixels += dc->pitch;
  448. /* draw on hardware dc */
  449. dest->engine->blit_line(dest, dest_rect->x1, dest_rect->x1 + rect_width,
  450. index, line_ptr);
  451. }
  452. /* release line buffer */
  453. rtgui_free(line_ptr);
  454. }
  455. }
  456. }
  457. }
  458. else if (dest->type == RTGUI_DC_BUFFER)
  459. {
  460. struct rtgui_dc_buffer *dest_dc = (struct rtgui_dc_buffer*)dest;
  461. if (dest_dc->pixel_format == dc->pixel_format && dest_dc->pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565)
  462. {
  463. int index;
  464. rt_uint8_t *pixels, *dest_pixels;
  465. /* get pitch */
  466. pitch = rect_width * rtgui_color_get_bpp(dc->pixel_format);
  467. pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);
  468. dest_pixels = _dc_get_pixel(dest_dc, dest_rect->x1, dest_rect->y1);
  469. for (index = 0; index < rect_height; index ++)
  470. {
  471. rt_memcpy(dest_pixels, pixels, pitch);
  472. pixels += dc->pitch;
  473. dest_pixels += dest_dc->pitch;
  474. }
  475. }
  476. else /* use rtgui_blit to handle buffer blit */
  477. {
  478. /* do the fast ARGB to RGB565 blit */
  479. struct rtgui_blit_info info;
  480. /* blit source */
  481. info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
  482. info.src_fmt = dc->pixel_format;
  483. info.src_h = rect_height;
  484. info.src_w = rect_width;
  485. info.src_pitch = dc->pitch;
  486. info.src_skip = info.src_pitch - info.src_w * rtgui_color_get_bpp(dc->pixel_format);
  487. /* blit destination */
  488. info.dst = _dc_get_pixel(dest_dc, dest_rect->x1, dest_rect->y1);
  489. info.dst_fmt = dest_dc->pixel_format;
  490. info.dst_h = rect_height;
  491. info.dst_w = rect_width;
  492. info.dst_pitch = dest_dc->pitch;
  493. info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(dest_dc->pixel_format);
  494. rtgui_blit(&info);
  495. }
  496. }
  497. }
  498. static void rtgui_dc_buffer_blit_line(struct rtgui_dc *self, int x1, int x2, int y, rt_uint8_t *line_data)
  499. {
  500. rt_uint8_t *pixel;
  501. struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;
  502. RT_ASSERT(dc != RT_NULL);
  503. RT_ASSERT(line_data != RT_NULL);
  504. /* out of range */
  505. if ((x1 >= dc->width) || (y >= dc->height) || y < 0 || x1 == x2)
  506. return;
  507. /* check range */
  508. if (x1 < 0)
  509. x1 = 0;
  510. if (x2 >= dc->width)
  511. x2 = dc->width-1;
  512. pixel = _dc_get_pixel(dc,x1,y);
  513. rt_memcpy(pixel, line_data, (x2 - x1) * rtgui_color_get_bpp(dc->pixel_format));
  514. }