Skip to content

Commit de52d1d

Browse files
faxe1008nashif
authored andcommitted
drivers: display: sdl: Move sdl_bottom parameters into structs
Since the number of function arguments grows out of hand, place them into structs and pass a struct to the method instead. Signed-off-by: Fabian Blatz <[email protected]>
1 parent ef45a64 commit de52d1d

File tree

3 files changed

+267
-173
lines changed

3 files changed

+267
-173
lines changed

drivers/display/display_sdl.c

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,36 @@ static void exec_sdl_task(const struct device *dev, const struct sdl_display_tas
8383
struct sdl_display_data *disp_data = dev->data;
8484

8585
switch (task->op) {
86-
case SDL_WRITE:
87-
sdl_display_write_bottom(task->write.desc->height, task->write.desc->width,
88-
task->write.x, task->write.y, disp_data->renderer,
89-
disp_data->mutex, disp_data->texture,
90-
disp_data->background_texture, disp_data->buf,
91-
disp_data->display_on, task->write.desc->frame_incomplete,
92-
CONFIG_SDL_DISPLAY_COLOR_TINT, disp_data->round_disp_mask);
86+
case SDL_WRITE: {
87+
struct sdl_display_write_params write_params = {
88+
.height = task->write.desc->height,
89+
.width = task->write.desc->width,
90+
.x = task->write.x,
91+
.y = task->write.y,
92+
.renderer = disp_data->renderer,
93+
.mutex = disp_data->mutex,
94+
.texture = disp_data->texture,
95+
.background_texture = disp_data->background_texture,
96+
.buf = disp_data->buf,
97+
.display_on = disp_data->display_on,
98+
.frame_incomplete = task->write.desc->frame_incomplete,
99+
.color_tint = CONFIG_SDL_DISPLAY_COLOR_TINT,
100+
.round_disp_mask = disp_data->round_disp_mask,
101+
};
102+
sdl_display_write_bottom(&write_params);
93103
break;
94-
case SDL_BLANKING_OFF:
95-
sdl_display_blanking_off_bottom(
96-
disp_data->renderer, disp_data->texture, disp_data->background_texture,
97-
CONFIG_SDL_DISPLAY_COLOR_TINT, disp_data->round_disp_mask);
104+
}
105+
case SDL_BLANKING_OFF: {
106+
struct sdl_display_blanking_off_params blanking_off_params = {
107+
.renderer = disp_data->renderer,
108+
.texture = disp_data->texture,
109+
.background_texture = disp_data->background_texture,
110+
.color_tint = CONFIG_SDL_DISPLAY_COLOR_TINT,
111+
.round_disp_mask = disp_data->round_disp_mask,
112+
};
113+
sdl_display_blanking_off_bottom(&blanking_off_params);
98114
break;
115+
}
99116
case SDL_BLANKING_ON:
100117
sdl_display_blanking_on_bottom(disp_data->renderer);
101118
break;
@@ -118,15 +135,28 @@ static void sdl_task_thread(void *p1, void *p2, void *p3)
118135
sdl_display_zoom_pct = CONFIG_SDL_DISPLAY_ZOOM_PCT;
119136
}
120137

121-
int rc = sdl_display_init_bottom(
122-
config->height, config->width, sdl_display_zoom_pct, use_accelerator,
123-
&disp_data->window, dev, config->title, &disp_data->renderer, &disp_data->mutex,
124-
&disp_data->texture, &disp_data->read_texture, &disp_data->background_texture,
125-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_1,
126-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_2,
127-
CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_SIZE,
128-
COND_CODE_1(CONFIG_SDL_DISPLAY_ROUNDED_MASK, (&disp_data->round_disp_mask), (NULL)),
129-
CONFIG_SDL_DISPLAY_ROUNDED_MASK_COLOR);
138+
struct sdl_display_init_params init_params = {
139+
.height = config->height,
140+
.width = config->width,
141+
.zoom_pct = sdl_display_zoom_pct,
142+
.use_accelerator = use_accelerator,
143+
.window = &disp_data->window,
144+
.window_user_data = dev,
145+
.title = config->title,
146+
.renderer = &disp_data->renderer,
147+
.mutex = &disp_data->mutex,
148+
.texture = &disp_data->texture,
149+
.read_texture = &disp_data->read_texture,
150+
.background_texture = &disp_data->background_texture,
151+
.transparency_grid_color1 = CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_1,
152+
.transparency_grid_color2 = CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_COLOR_2,
153+
.transparency_grid_cell_size = CONFIG_SDL_DISPLAY_TRANSPARENCY_GRID_CELL_SIZE,
154+
.round_disp_mask = COND_CODE_1(CONFIG_SDL_DISPLAY_ROUNDED_MASK,
155+
(&disp_data->round_disp_mask), NULL),
156+
.mask_color = CONFIG_SDL_DISPLAY_ROUNDED_MASK_COLOR,
157+
};
158+
159+
int rc = sdl_display_init_bottom(&init_params);
130160

131161
k_sem_give(&disp_data->task_sem);
132162

@@ -612,9 +642,20 @@ static int sdl_display_read(const struct device *dev, const uint16_t x, const ui
612642
k_mutex_lock(&disp_data->task_mutex, K_FOREVER);
613643
memset(disp_data->read_buf, 0, desc->pitch * desc->height * 4);
614644

615-
err = sdl_display_read_bottom(desc->height, desc->width, x, y, disp_data->renderer,
616-
disp_data->read_buf, desc->pitch, disp_data->mutex,
617-
disp_data->texture, disp_data->read_texture);
645+
struct sdl_display_read_params read_params = {
646+
.height = desc->height,
647+
.width = desc->width,
648+
.x = x,
649+
.y = y,
650+
.renderer = disp_data->renderer,
651+
.buf = disp_data->read_buf,
652+
.pitch = desc->pitch,
653+
.mutex = disp_data->mutex,
654+
.texture = disp_data->texture,
655+
.read_texture = disp_data->read_texture,
656+
};
657+
658+
err = sdl_display_read_bottom(&read_params);
618659

619660
if (err) {
620661
k_mutex_unlock(&disp_data->task_mutex);
@@ -780,9 +821,16 @@ static int sdl_display_set_pixel_format(const struct device *dev,
780821

781822
static void sdl_display_cleanup(struct sdl_display_data *disp_data)
782823
{
783-
sdl_display_cleanup_bottom(&disp_data->window, &disp_data->renderer, &disp_data->mutex,
784-
&disp_data->texture, &disp_data->read_texture,
785-
&disp_data->background_texture, &disp_data->round_disp_mask);
824+
struct sdl_display_cleanup_params cleanup_params = {
825+
.window = &disp_data->window,
826+
.renderer = &disp_data->renderer,
827+
.mutex = &disp_data->mutex,
828+
.texture = &disp_data->texture,
829+
.read_texture = &disp_data->read_texture,
830+
.background_texture = &disp_data->background_texture,
831+
.round_disp_mask = &disp_data->round_disp_mask,
832+
};
833+
sdl_display_cleanup_bottom(&cleanup_params);
786834
}
787835

788836
static DEVICE_API(display, sdl_display_api) = {

0 commit comments

Comments
 (0)