| 1 |
#include "lv_draw_dave2d.h" |
| 2 |
#if LV_USE_DRAW_DAVE2D |
| 3 |
|
| 4 |
#include "../../lv_draw_label_private.h" |
| 5 |
#include "../../../misc/lv_area_private.h" |
| 6 |
|
| 7 |
static void lv_draw_dave2d_draw_letter_cb(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc, |
| 8 |
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area); |
| 9 |
|
| 10 |
void lv_draw_dave2d_label(lv_draw_task_t * t, const lv_draw_label_dsc_t * dsc, const lv_area_t * coords) |
| 11 |
{ |
| 12 |
if(dsc->opa <= LV_OPA_MIN) return; |
| 13 |
|
| 14 |
lv_draw_label_iterate_characters(t, dsc, coords, lv_draw_dave2d_draw_letter_cb); |
| 15 |
|
| 16 |
} |
| 17 |
|
| 18 |
static void lv_draw_dave2d_draw_letter_cb(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc, |
| 19 |
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area) |
| 20 |
{ |
| 21 |
if(glyph_draw_dsc) { |
| 22 |
d2_u8 current_fillmode; |
| 23 |
lv_area_t clip_area; |
| 24 |
lv_area_t letter_coords; |
| 25 |
|
| 26 |
int32_t x; |
| 27 |
int32_t y; |
| 28 |
|
| 29 |
letter_coords = *glyph_draw_dsc->letter_coords; |
| 30 |
lv_draw_dave2d_unit_t * unit = (lv_draw_dave2d_unit_t *)t->draw_unit; |
| 31 |
|
| 32 |
bool is_common; |
| 33 |
is_common = lv_area_intersect(&clip_area, glyph_draw_dsc->letter_coords, &t->clip_area); |
| 34 |
if(!is_common) return; |
| 35 |
|
| 36 |
x = 0 - t->target_layer->buf_area.x1; |
| 37 |
y = 0 - t->target_layer->buf_area.y1; |
| 38 |
|
| 39 |
lv_area_move(&clip_area, x, y); |
| 40 |
lv_area_move(&letter_coords, x, y); |
| 41 |
|
| 42 |
#if LV_USE_OS |
| 43 |
lv_result_t status; |
| 44 |
status = lv_mutex_lock(unit->pd2Mutex); |
| 45 |
LV_ASSERT(LV_RESULT_OK == status); |
| 46 |
#endif |
| 47 |
|
| 48 |
d2_selectrenderbuffer(unit->d2_handle, unit->label_renderbuffer); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
d2_framebuffer_from_layer(unit->d2_handle, t->target_layer); |
| 55 |
|
| 56 |
current_fillmode = d2_getfillmode(unit->d2_handle); |
| 57 |
|
| 58 |
d2_cliprect(unit->d2_handle, (d2_border)clip_area.x1, (d2_border)clip_area.y1, (d2_border)clip_area.x2, |
| 59 |
(d2_border)clip_area.y2); |
| 60 |
|
| 61 |
switch(glyph_draw_dsc->format) { |
| 62 |
case LV_FONT_GLYPH_FORMAT_NONE: { |
| 63 |
#if LV_USE_FONT_PLACEHOLDER |
| 64 |
|
| 65 |
lv_draw_border_dsc_t border_draw_dsc; |
| 66 |
lv_draw_border_dsc_init(&border_draw_dsc); |
| 67 |
border_draw_dsc.opa = glyph_draw_dsc->opa; |
| 68 |
border_draw_dsc.color = glyph_draw_dsc->color; |
| 69 |
border_draw_dsc.width = 1; |
| 70 |
|
| 71 |
lv_draw_dave2d_border(t, &border_draw_dsc, glyph_draw_dsc->bg_coords); |
| 72 |
#endif |
| 73 |
} |
| 74 |
break; |
| 75 |
case LV_FONT_GLYPH_FORMAT_A1 ... LV_FONT_GLYPH_FORMAT_A8: { |
| 76 |
glyph_draw_dsc->glyph_data = lv_font_get_glyph_bitmap(glyph_draw_dsc->g, glyph_draw_dsc->_draw_buf); |
| 77 |
lv_area_t mask_area = letter_coords; |
| 78 |
mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1; |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
const lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data; |
| 90 |
|
| 91 |
#if defined(RENESAS_CORTEX_M85) || defined(_RENESAS_RZA_) |
| 92 |
#if (BSP_CFG_DCACHE_ENABLED) || defined(_RENESAS_RZA_) |
| 93 |
d1_cacheblockflush(unit->d2_handle, 0, draw_buf->data, draw_buf->data_size); |
| 94 |
#endif |
| 95 |
#endif |
| 96 |
d2_settexture(unit->d2_handle, (void *)draw_buf->data, |
| 97 |
(d2_s32)lv_draw_buf_width_to_stride((uint32_t)lv_area_get_width(&letter_coords), LV_COLOR_FORMAT_A8), |
| 98 |
lv_area_get_width(&letter_coords), lv_area_get_height(&letter_coords), d2_mode_alpha8); |
| 99 |
d2_settexopparam(unit->d2_handle, d2_cc_red, glyph_draw_dsc->color.red, 0); |
| 100 |
d2_settexopparam(unit->d2_handle, d2_cc_green, glyph_draw_dsc->color.green, 0); |
| 101 |
d2_settexopparam(unit->d2_handle, d2_cc_blue, glyph_draw_dsc->color.blue, 0); |
| 102 |
d2_settexopparam(unit->d2_handle, d2_cc_alpha, glyph_draw_dsc->opa, 0); |
| 103 |
|
| 104 |
d2_settextureoperation(unit->d2_handle, d2_to_multiply, d2_to_multiply, d2_to_multiply, d2_to_multiply); |
| 105 |
|
| 106 |
d2_settexturemapping(unit->d2_handle, D2_FIX4(letter_coords.x1), D2_FIX4(letter_coords.y1), D2_FIX16(0), D2_FIX16(0), |
| 107 |
D2_FIX16(1), D2_FIX16(0), D2_FIX16(0), D2_FIX16(1)); |
| 108 |
|
| 109 |
d2_settexturemode(unit->d2_handle, d2_tm_filter); |
| 110 |
|
| 111 |
d2_setfillmode(unit->d2_handle, d2_fm_texture); |
| 112 |
|
| 113 |
d2_renderbox(unit->d2_handle, (d2_point)D2_FIX4(letter_coords.x1), |
| 114 |
(d2_point)D2_FIX4(letter_coords.y1), |
| 115 |
(d2_point)D2_FIX4(lv_area_get_width(&letter_coords)), |
| 116 |
(d2_point)D2_FIX4(lv_area_get_height(&letter_coords))); |
| 117 |
|
| 118 |
d2_setfillmode(unit->d2_handle, current_fillmode); |
| 119 |
} |
| 120 |
break; |
| 121 |
case LV_FONT_GLYPH_FORMAT_IMAGE: { |
| 122 |
#if LV_USE_IMGFONT |
| 123 |
glyph_draw_dsc->glyph_data = lv_font_get_glyph_bitmap(glyph_draw_dsc->g, glyph_draw_dsc->_draw_buf); |
| 124 |
lv_draw_image_dsc_t img_dsc; |
| 125 |
lv_draw_image_dsc_init(&img_dsc); |
| 126 |
img_dsc.rotation = 0; |
| 127 |
img_dsc.scale_x = LV_SCALE_NONE; |
| 128 |
img_dsc.scale_y = LV_SCALE_NONE; |
| 129 |
img_dsc.opa = glyph_draw_dsc->opa; |
| 130 |
img_dsc.src = glyph_draw_dsc->glyph_data; |
| 131 |
|
| 132 |
#endif |
| 133 |
} |
| 134 |
break; |
| 135 |
default: |
| 136 |
break; |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
d2_executerenderbuffer(unit->d2_handle, unit->label_renderbuffer, 0); |
| 147 |
d2_flushframe(unit->d2_handle); |
| 148 |
d2_selectrenderbuffer(unit->d2_handle, unit->renderbuffer); |
| 149 |
|
| 150 |
#if LV_USE_OS |
| 151 |
status = lv_mutex_unlock(unit->pd2Mutex); |
| 152 |
LV_ASSERT(LV_RESULT_OK == status); |
| 153 |
#endif |
| 154 |
} |
| 155 |
|
| 156 |
if(fill_draw_dsc && fill_area) { |
| 157 |
lv_draw_dave2d_fill(t, fill_draw_dsc, fill_area); |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
#endif |