lv_gpu_n9h30_ge2d.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-12-17 Wayne The first version
  9. */
  10. /**
  11. * @file lv_gpu_n9h30_ge2d.c
  12. *
  13. */
  14. /*********************
  15. * INCLUDES
  16. *********************/
  17. #include <lvgl.h>
  18. #if LV_USE_GPU_N9H30_GE2D && LV_VERSION_CHECK(8, 2, 0)
  19. #include "lv_gpu_n9h30_ge2d.h"
  20. #include "nu_2d.h"
  21. #include "mmu.h"
  22. /*********************
  23. * DEFINES
  24. *********************/
  25. #if LV_COLOR_16_SWAP
  26. #error "Can't use GE2D with LV_COLOR_16_SWAP 1"
  27. #endif
  28. #if !((LV_COLOR_DEPTH == 16) || (LV_COLOR_DEPTH == 32))
  29. /*Can't use GPU with other formats*/
  30. #error "Can't use GPU with other formats"
  31. #endif
  32. /**********************
  33. * TYPEDEFS
  34. **********************/
  35. /**********************
  36. * STATIC PROTOTYPES
  37. **********************/
  38. static void lv_draw_n9h30_ge2d_blend_fill(lv_color_t *dest_buf, lv_coord_t dest_stride, const lv_area_t *fill_area,
  39. lv_color_t color);
  40. static void lv_draw_n9h30_ge2d_blend_map(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride,
  41. const lv_color_t *src_buf, lv_coord_t src_stride, lv_opa_t opa);
  42. /**********************
  43. * STATIC VARIABLES
  44. **********************/
  45. /**********************
  46. * MACROS
  47. **********************/
  48. /**********************
  49. * GLOBAL FUNCTIONS
  50. **********************/
  51. /**
  52. * Turn on the peripheral and set output color mode, this only needs to be done once
  53. */
  54. void lv_draw_n9h30_ge2d_ctx_init(lv_disp_drv_t *drv, lv_draw_ctx_t *draw_ctx)
  55. {
  56. lv_draw_sw_init_ctx(drv, draw_ctx);
  57. lv_draw_n9h30_ge2d_ctx_t *ge2d_draw_ctx = (lv_draw_sw_ctx_t *)draw_ctx;
  58. ge2d_draw_ctx->blend = lv_draw_n9h30_ge2d_blend;
  59. ge2d_draw_ctx->base_draw.wait_for_finish = lv_gpu_n9h30_ge2d_wait_cb;
  60. }
  61. void lv_draw_n9h30_ge2d_ctx_deinit(lv_disp_drv_t *drv, lv_draw_ctx_t *draw_ctx)
  62. {
  63. LV_UNUSED(drv);
  64. LV_UNUSED(draw_ctx);
  65. }
  66. void lv_draw_n9h30_ge2d_blend(lv_draw_ctx_t *draw_ctx, const lv_draw_sw_blend_dsc_t *dsc)
  67. {
  68. lv_area_t blend_area;
  69. int32_t blend_area_w;
  70. bool done = false;
  71. if (!_lv_area_intersect(&blend_area, dsc->blend_area, draw_ctx->clip_area)) return;
  72. blend_area_w = lv_area_get_width(&blend_area);
  73. if ((lv_area_get_size(&blend_area) > 7200) &&
  74. (((blend_area_w * (LV_COLOR_DEPTH / 2)) & 0x3) == 0) &&
  75. (dsc->mask_buf == NULL) && (dsc->blend_mode == LV_BLEND_MODE_NORMAL))
  76. {
  77. lv_coord_t dest_stride = lv_area_get_width(draw_ctx->buf_area);
  78. lv_color_t *dest_buf = draw_ctx->buf;
  79. dest_buf += dest_stride * (blend_area.y1 - draw_ctx->buf_area->y1) + (blend_area.x1 - draw_ctx->buf_area->x1);
  80. const lv_color_t *src_buf = dsc->src_buf;
  81. if (src_buf)
  82. {
  83. lv_coord_t src_stride;
  84. src_stride = lv_area_get_width(dsc->blend_area);
  85. src_buf += src_stride * (blend_area.y1 - dsc->blend_area->y1) + (blend_area.x1 - dsc->blend_area->x1);
  86. lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
  87. lv_draw_n9h30_ge2d_blend_map(dest_buf, &blend_area, dest_stride, src_buf, src_stride, dsc->opa);
  88. done = true;
  89. }
  90. else if (dsc->opa >= LV_OPA_MAX)
  91. {
  92. lv_area_move(&blend_area, -draw_ctx->buf_area->x1, -draw_ctx->buf_area->y1);
  93. lv_draw_n9h30_ge2d_blend_fill(dest_buf, dest_stride, &blend_area, dsc->color);
  94. done = true;
  95. }
  96. }
  97. if (!done) lv_draw_sw_blend_basic(draw_ctx, dsc);
  98. }
  99. static void lv_draw_n9h30_ge2d_blend_fill(lv_color_t *dest_buf, lv_coord_t dest_stride, const lv_area_t *fill_area,
  100. lv_color_t color)
  101. {
  102. int32_t fill_area_w = lv_area_get_width(fill_area);
  103. int32_t fill_area_h = lv_area_get_height(fill_area);
  104. lv_color_t *start_buf = dest_buf - (fill_area->y1 * dest_stride) - fill_area->x1;
  105. //rt_kprintf("[blend_fill %d %08x] %dx%d %d %d\n", lv_area_get_size(fill_area), dest_buf, fill_area_w, fill_area_h, fill_area->x1, fill_area->y1 );
  106. if (IS_CACHEABLE_VRAM(dest_buf))
  107. mmu_clean_invalidated_dcache((uint32_t)dest_buf, sizeof(lv_color_t) * (dest_stride * fill_area_h + fill_area_w));
  108. /*Hardware filling*/
  109. // Enter GE2D ->
  110. ge2dInit(sizeof(lv_color_t) * 8, dest_stride, fill_area->y2, (void *)start_buf);
  111. ge2dClip_SetClip(fill_area->x1, fill_area->y1, fill_area->x2, fill_area->y2);
  112. if (sizeof(lv_color_t) == 4)
  113. ge2dFill_Solid(fill_area->x1, fill_area->y1, fill_area_w, fill_area_h, color.full);
  114. else if (sizeof(lv_color_t) == 2)
  115. ge2dFill_Solid_RGB565(fill_area->x1, fill_area->y1, fill_area_w, fill_area_h, color.full);
  116. ge2dClip_SetClip(-1, 0, 0, 0);
  117. // -> Leave GE2D
  118. }
  119. static void lv_draw_n9h30_ge2d_blend_map(lv_color_t *dest_buf, const lv_area_t *dest_area, lv_coord_t dest_stride,
  120. const lv_color_t *src_buf, lv_coord_t src_stride, lv_opa_t opa)
  121. {
  122. /*Simple copy*/
  123. int32_t dest_x = dest_area->x1;
  124. int32_t dest_y = dest_area->y1;
  125. int32_t dest_w = lv_area_get_width(dest_area);
  126. int32_t dest_h = lv_area_get_height(dest_area);
  127. const lv_color_t *dest_start_buf = dest_buf - (dest_area->y1 * dest_stride) - dest_area->x1;
  128. //rt_kprintf("[blend_map %d %08x -> %08x] (x:%d y:%d, %dx%d) <stride src:%d dst:%d>\n", lv_area_get_size(dest_area), src_buf, dest_buf, dest_x, dest_y, dest_w, dest_h, src_stride, dest_stride);
  129. // Enter GE2D ->
  130. ge2dInit(sizeof(lv_color_t) * 8, dest_stride, dest_area->y2, (void *)dest_start_buf);
  131. if (opa >= LV_OPA_MAX)
  132. {
  133. ge2dBitblt_SetAlphaMode(0, 0, 0);
  134. ge2dBitblt_SetDrawMode(0, 0, 0);
  135. }
  136. else
  137. {
  138. ge2dBitblt_SetAlphaMode(1, opa, opa);
  139. }
  140. // flush
  141. mmu_clean_dcache((uint32_t)src_buf, sizeof(lv_color_t) * (src_stride * dest_h + dest_w));
  142. ge2dSpriteBlt_Screen(dest_x, dest_y, dest_w, dest_h, (void *)src_buf);
  143. // -> Leave GE2D
  144. }
  145. void lv_gpu_n9h30_ge2d_wait_cb(lv_draw_ctx_t *draw_ctx)
  146. {
  147. lv_draw_sw_wait_for_finish(draw_ctx);
  148. }
  149. /**********************
  150. * STATIC FUNCTIONS
  151. **********************/
  152. #endif // #if (LV_USE_GPU_N9H30_GE2D && LV_VERSION_CHECK(8, 2, 0))