GRUB_MOD_LICENSE ("GPLv3+");
-static unsigned height, width, depth;
-static struct grub_video_mode_info *current_mode;
+struct hook_ctx
+{
+ unsigned height, width, depth;
+ struct grub_video_mode_info *current_mode;
+};
static int
-hook (const struct grub_video_mode_info *info)
+hook (const struct grub_video_mode_info *info, void *hook_arg)
{
- if (height && width && (info->width != width || info->height != height))
+ struct hook_ctx *ctx = hook_arg;
+
+ if (ctx->height && ctx->width && (info->width != ctx->width || info->height != ctx->height))
return 0;
- if (depth && info->bpp != depth)
+ if (ctx->depth && info->bpp != ctx->depth)
return 0;
if (info->mode_number == GRUB_VIDEO_MODE_NUMBER_INVALID)
grub_printf (" ");
else
{
- if (current_mode && info->mode_number == current_mode->mode_number)
+ if (ctx->current_mode && info->mode_number == ctx->current_mode->mode_number)
grub_printf ("*");
else
grub_printf (" ");
{
grub_video_adapter_t adapter;
grub_video_driver_id_t id;
+ struct hook_ctx ctx;
- height = width = depth = 0;
+ ctx.height = ctx.width = ctx.depth = 0;
if (argc)
{
char *ptr;
ptr = args[0];
- width = grub_strtoul (ptr, &ptr, 0);
+ ctx.width = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
if (*ptr != 'x')
N_("invalid video mode specification `%s'"),
args[0]);
ptr++;
- height = grub_strtoul (ptr, &ptr, 0);
+ ctx.height = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
if (*ptr == 'x')
{
ptr++;
- depth = grub_strtoul (ptr, &ptr, 0);
+ ctx.depth = grub_strtoul (ptr, &ptr, 0);
if (grub_errno)
return grub_errno;
}
continue;
}
- current_mode = NULL;
+ ctx.current_mode = NULL;
if (adapter->id == id)
{
if (grub_video_get_info (&info) == GRUB_ERR_NONE)
- current_mode = &info;
+ ctx.current_mode = &info;
else
/* Don't worry about errors. */
grub_errno = GRUB_ERR_NONE;
if (adapter->print_adapter_specific_info)
adapter->print_adapter_specific_info ();
- adapter->iterate (hook);
+ adapter->iterate (hook, &ctx);
if (adapter->get_edid && adapter->get_edid (&edid_info) == GRUB_ERR_NONE)
print_edid (&edid_info);
else
grub_errno = GRUB_ERR_NONE;
- current_mode = NULL;
+ ctx.current_mode = NULL;
if (adapter->id != id)
{
static grub_efi_handle_t gop_handle;
static int
-grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info));
+grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg);
static struct
{
grub_uint8_t *offscreen;
} framebuffer;
+static int
+check_protocol_hook (const struct grub_video_mode_info *info __attribute__ ((unused)), void *hook_arg)
+{
+ int *have_usable_mode = hook_arg;
+ *have_usable_mode = 1;
+ return 1;
+}
+
static int
check_protocol (void)
grub_efi_uintn_t num_handles, i;
int have_usable_mode = 0;
- auto int hook (const struct grub_video_mode_info *info);
- int hook (const struct grub_video_mode_info *info __attribute__ ((unused)))
- {
- have_usable_mode = 1;
- return 1;
- }
-
handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL,
&graphics_output_guid, NULL, &num_handles);
if (!handles || num_handles == 0)
gop_handle = handles[i];
gop = grub_efi_open_protocol (gop_handle, &graphics_output_guid,
GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
- grub_video_gop_iterate (hook);
+ grub_video_gop_iterate (check_protocol_hook, &have_usable_mode);
if (have_usable_mode)
{
grub_free (handles);
}
static int
-grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info))
+grub_video_gop_iterate (int (*hook) (const struct grub_video_mode_info *info, void *hook_arg), void *hook_arg)
{
unsigned mode;
grub_errno = GRUB_ERR_NONE;
continue;
}
- if (hook (&mode_info))
+ if (hook (&mode_info, hook_arg))
return 1;
}
return 0;