rgb_lcd: optimise rgb_panel_draw_bitmap

by using memcpy instead of coping in a nested for loop
This commit is contained in:
TDA2030
2022-05-07 11:27:05 +08:00
committed by morris
parent 3a6831b1b4
commit 30ab6a9246

View File

@ -312,19 +312,21 @@ static esp_err_t rgb_panel_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int
// convert the frame buffer to 3D array // convert the frame buffer to 3D array
int bytes_per_pixel = rgb_panel->data_width / 8; int bytes_per_pixel = rgb_panel->data_width / 8;
int pixels_per_line = rgb_panel->timings.h_res; int pixels_per_line = rgb_panel->timings.h_res;
uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line;
const uint8_t *from = (const uint8_t *)color_data; const uint8_t *from = (const uint8_t *)color_data;
uint8_t (*to)[pixels_per_line][bytes_per_pixel] = (uint8_t (*)[pixels_per_line][bytes_per_pixel])rgb_panel->fb;
// manipulate the frame buffer // manipulate the frame buffer
for (int j = y_start; j < y_end; j++) { uint32_t copy_bytes_per_line = (x_end - x_start) * bytes_per_pixel;
for (int i = x_start; i < x_end; i++) { uint8_t *to = rgb_panel->fb + (y_start * pixels_per_line + x_start) * bytes_per_pixel;
for (int k = 0; k < bytes_per_pixel; k++) { for (int y = y_start; y < y_end; y++) {
to[j][i][k] = *from++; memcpy(to, from, copy_bytes_per_line);
} to += bytes_per_line;
} from += copy_bytes_per_line;
} }
if (rgb_panel->flags.fb_in_psram) { if (rgb_panel->flags.fb_in_psram) {
// CPU writes data to PSRAM through DCache, data in PSRAM might not get updated, so write back // CPU writes data to PSRAM through DCache, data in PSRAM might not get updated, so write back
Cache_WriteBack_Addr((uint32_t)&to[y_start][0][0], (y_end - y_start) * rgb_panel->timings.h_res * bytes_per_pixel); uint32_t bytes_to_flush = (y_end - y_start) * bytes_per_line;
Cache_WriteBack_Addr((uint32_t)(rgb_panel->fb + y_start * bytes_per_line), bytes_to_flush);
} }
// restart the new transmission // restart the new transmission