Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dcs_lcd_display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ static void do_update(Context *ctx, term display_list)
bool transaction_in_progress = false;

for (int ypos = 0; ypos < screen_height; ypos++) {
BaseDisplayItem *row = display_items_row(items, len, ypos);
int xpos = 0;
while (xpos < screen_width) {
int drawn_pixels = dcs_lcd_draw_x(&driver->screen, xpos, ypos, items, len);
int drawn_pixels = dcs_lcd_draw_x(&driver->screen, xpos, ypos, row);
xpos += drawn_pixels;
}

Expand Down
10 changes: 3 additions & 7 deletions dcs_lcd_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,12 @@ int dcs_lcd_draw_scaled_cropped_img_x(const struct DCSLCDScreen *screen,
}

int dcs_lcd_draw_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
int xpos, int ypos, BaseDisplayItem *row)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
for (BaseDisplayItem *item = row; item != NULL; item = item->next) {
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
Expand All @@ -233,7 +229,7 @@ int dcs_lcd_draw_x(const struct DCSLCDScreen *screen,
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
switch (item->primitive) {
case PrimitiveImage:
drawn_pixels = dcs_lcd_draw_image_x(screen, xpos, ypos, max_line_len, item);
break;
Expand Down
2 changes: 1 addition & 1 deletion dcs_lcd_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ int dcs_lcd_draw_scaled_cropped_img_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, int max_line_len, BaseDisplayItem *item);

int dcs_lcd_draw_x(const struct DCSLCDScreen *screen,
int xpos, int ypos, BaseDisplayItem items[], size_t items_len);
int xpos, int ypos, BaseDisplayItem *row);

#endif
21 changes: 21 additions & 0 deletions display_items.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ struct BaseDisplayItem
int y_scale;

bool owns_data;

// Rendering scratch, never compared: the next item that covers the row being drawn, see
// display_items_row()
struct BaseDisplayItem *next;
};

typedef struct BaseDisplayItem BaseDisplayItem;
Expand All @@ -95,6 +99,23 @@ typedef enum
DisplayItemsOutOfMemory
} display_items_result_t;

// Links the items that cover row ypos through their next field, in display list order, and
// returns the first of them, or NULL if none does.
static inline BaseDisplayItem *display_items_row(BaseDisplayItem items[], size_t items_len, int ypos)
{
BaseDisplayItem *head = NULL;
BaseDisplayItem **link = &head;
for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if (ypos >= item->y && ypos < item->y + item->height) {
*link = item;
link = &item->next;
}
}
*link = NULL;
return head;
}

void display_items_init_item(BaseDisplayItem *item, term req, Context *ctx);

display_items_result_t display_items_new_list(term display_list, BaseDisplayItem **items, size_t *items_len, Context *ctx);
Expand Down
3 changes: 2 additions & 1 deletion epaper_display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ static void do_update(Context *ctx, term display_list)
spi_device_get_trans_result(driver->bus.spi_disp.handle, &trans, portMAX_DELAY);
}

BaseDisplayItem *row = display_items_row(items, len, ypos);
int xpos = 0;
while (xpos < screen_width) {
int drawn_pixels = epaper_draw_x(&driver->screen, buf, xpos, ypos, items, len);
int drawn_pixels = epaper_draw_x(&driver->screen, buf, xpos, ypos, row);
xpos += drawn_pixels;
}

Expand Down
10 changes: 3 additions & 7 deletions epaper_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,12 @@ int epaper_draw_scaled_cropped_img_x(const struct EpaperScreen *screen,

int epaper_draw_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len)
BaseDisplayItem *row)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
for (BaseDisplayItem *item = row; item != NULL; item = item->next) {
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
Expand All @@ -298,7 +294,7 @@ int epaper_draw_x(const struct EpaperScreen *screen,
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
switch (item->primitive) {
case PrimitiveImage:
drawn_pixels = epaper_draw_image_x(screen, line_buf, xpos, ypos, max_line_len, item);
break;
Expand Down
2 changes: 1 addition & 1 deletion epaper_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ int epaper_draw_scaled_cropped_img_x(const struct EpaperScreen *screen,

int epaper_draw_x(const struct EpaperScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len);
BaseDisplayItem *row);

#endif
3 changes: 2 additions & 1 deletion memory_display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ static void do_update(Context *ctx, term display_list)

memset(buf + 2, 0xFF, DISPLAY_WIDTH / 8);

BaseDisplayItem *row = display_items_row(items, len, ypos);
int xpos = 0;
while (xpos < screen_width) {
int drawn_pixels = mono_draw_x(&driver->screen, buf + 2, xpos, ypos, items, len);
int drawn_pixels = mono_draw_x(&driver->screen, buf + 2, xpos, ypos, row);
xpos += drawn_pixels;
}

Expand Down
10 changes: 3 additions & 7 deletions mono_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,12 @@ int mono_draw_scaled_cropped_img_x(const struct MonoScreen *screen,

int mono_draw_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len)
BaseDisplayItem *row)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
for (BaseDisplayItem *item = row; item != NULL; item = item->next) {
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
Expand All @@ -323,7 +319,7 @@ int mono_draw_x(const struct MonoScreen *screen,
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
switch (item->primitive) {
case PrimitiveImage:
//fprintf(stderr, "Image\n");
drawn_pixels = mono_draw_image_x(screen, line_buf, xpos, ypos, max_line_len, item);
Expand Down
2 changes: 1 addition & 1 deletion mono_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ int mono_draw_scaled_cropped_img_x(const struct MonoScreen *screen,

int mono_draw_x(const struct MonoScreen *screen,
uint8_t *line_buf, int xpos, int ypos,
BaseDisplayItem items[], size_t items_len);
BaseDisplayItem *row);

#endif
3 changes: 2 additions & 1 deletion oled_display_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ static void do_update(Context *ctx, term display_list)
}

for (int ypos = 0; ypos < screen_height; ypos++) {
BaseDisplayItem *row = display_items_row(items, len, ypos);
int xpos = 0;
while (xpos < screen_width) {
int drawn_pixels = mono_draw_x(&driver->screen, buf, xpos, ypos, items, len);
int drawn_pixels = mono_draw_x(&driver->screen, buf, xpos, ypos, row);
xpos += drawn_pixels;
}

Expand Down
13 changes: 5 additions & 8 deletions sdl_display/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,12 @@ static int draw_text_x(int xpos, int ypos, int max_line_len, BaseDisplayItem *it
return drawn_pixels;
}

static int draw_x(int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
static int draw_x(int xpos, int ypos, BaseDisplayItem *row)
{
int line_len = screen->w - xpos;
bool below = false;

for (size_t i = 0; i < items_len; i++) {
BaseDisplayItem *item = &items[i];
if ((ypos < item->y) || (ypos >= item->y + item->height)) {
continue;
}
for (BaseDisplayItem *item = row; item != NULL; item = item->next) {
if (xpos < item->x) {
int len_to_item = item->x - xpos;
if (len_to_item < line_len) {
Expand All @@ -293,7 +289,7 @@ static int draw_x(int xpos, int ypos, BaseDisplayItem items[], size_t items_len)
int max_line_len = below ? 1 : line_len;

int drawn_pixels = 0;
switch (items[i].primitive) {
switch (item->primitive) {
case PrimitiveImage:
drawn_pixels = draw_image_x(xpos, ypos, max_line_len, item);
break;
Expand Down Expand Up @@ -334,9 +330,10 @@ static void do_update(Context *ctx, term display_list)
}

for (int ypos = 0; ypos < screen->h; ypos++) {
BaseDisplayItem *row = display_items_row(items, len, ypos);
int xpos = 0;
while (xpos < screen->w) {
xpos += draw_x(xpos, ypos, items, len);
xpos += draw_x(xpos, ypos, row);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/items/test_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,11 @@ static void render(term display_list, uint16_t *frame)
screen.pixels = line;

for (int ypos = 0; ypos < SCREEN_H; ypos++) {
BaseDisplayItem *row = display_items_row(items, len, ypos);
memset(line, 0, sizeof(line));
int xpos = 0;
while (xpos < SCREEN_W) {
int drawn_pixels = dcs_lcd_draw_x(&screen, xpos, ypos, items, len);
int drawn_pixels = dcs_lcd_draw_x(&screen, xpos, ypos, row);
if (drawn_pixels <= 0) {
fprintf(stderr, "dcs_lcd_draw_x returned %d at (%d, %d)\n", drawn_pixels, xpos, ypos);
abort();
Expand Down
Loading