From 684a8eff899ad49d88870937d8f39c09ff64256f Mon Sep 17 00:00:00 2001 From: chaac Date: Sat, 29 Jul 2006 11:22:52 +0000 Subject: [PATCH] 2006-07-29 Vesa Jaaskelainen * include/grub/video.h: Code cleanup. * include/grub/i386/pc/vbe.h: Likewise. * video/i386/pc/vbe.c: Likewise. * video/i386/pc/vbeblit.c: Likewise. * video/i386/pc/vbefill.c: Likewise. * video/video.c: Likewise. Also added more comments. --- ChangeLog | 14 ++ include/grub/i386/pc/vbe.h | 10 +- include/grub/video.h | 163 +++++++----------- video/i386/pc/vbe.c | 328 ++++++++++++++++++------------------- video/i386/pc/vbeblit.c | 78 +++++---- video/i386/pc/vbefill.c | 13 +- video/video.c | 49 ++++-- 7 files changed, 316 insertions(+), 339 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54c9cff5f..f231d1ae0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2006-07-29 Vesa Jaaskelainen + + * include/grub/video.h: Code cleanup. + + * include/grub/i386/pc/vbe.h: Likewise. + + * video/i386/pc/vbe.c: Likewise. + + * video/i386/pc/vbeblit.c: Likewise. + + * video/i386/pc/vbefill.c: Likewise. + + * video/video.c: Likewise. Also added more comments. + 2006-07-29 Vesa Jaaskelainen * disk/i386/pc/biosdisk.c (struct grub_biosdisk_drp): Moved to ... diff --git a/include/grub/i386/pc/vbe.h b/include/grub/i386/pc/vbe.h index e33cfac3e..5cb15bd19 100644 --- a/include/grub/i386/pc/vbe.h +++ b/include/grub/i386/pc/vbe.h @@ -36,10 +36,10 @@ #define GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR 0x06 /* Note: - + Please refer to VESA BIOS Extension 3.0 Specification for more descriptive meanings of following structures and how they should be used. - + I have tried to maintain field name comatibility against specification while following naming convetions used in GRUB. */ @@ -206,11 +206,9 @@ grub_err_t grub_vbe_get_video_mode_info (grub_uint32_t mode, /* VBE module internal prototypes (should not be used from elsewhere). */ grub_uint8_t * grub_video_vbe_get_video_ptr (struct grub_video_render_target *source, - grub_uint32_t x, - grub_uint32_t y); + grub_uint32_t x, grub_uint32_t y); -grub_video_color_t grub_video_vbe_map_rgb (grub_uint8_t red, - grub_uint8_t green, +grub_video_color_t grub_video_vbe_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue); void grub_video_vbe_unmap_color (struct grub_video_render_target * source, diff --git a/include/grub/video.h b/include/grub/video.h index bc419f643..5c99e0d39 100644 --- a/include/grub/video.h +++ b/include/grub/video.h @@ -64,7 +64,7 @@ struct grub_video_mode_info { /* Width of the screen. */ unsigned int width; - + /* Height of the screen. */ unsigned int height; @@ -74,10 +74,10 @@ struct grub_video_mode_info /* Bits per pixel. */ unsigned int bpp; - + /* Bytes per pixel. */ unsigned int bytes_per_pixel; - + /* Pitch of one scanline. How many bytes there are for scanline. */ unsigned int pitch; @@ -130,7 +130,7 @@ struct grub_video_render_target /* Indicates wether the data has been allocated by us and must be freed when render target is destroyed. */ int is_allocated; - + /* Pointer to data. Can either be in video card memory or in local host's memory. */ void *data; @@ -158,78 +158,52 @@ struct grub_video_adapter /* Clean up the video adapter. */ grub_err_t (*fini) (void); - grub_err_t (*setup) (unsigned int width, - unsigned int height, - unsigned int mode_type); + grub_err_t (*setup) (unsigned int width, unsigned int height, + unsigned int mode_type); grub_err_t (*get_info) (struct grub_video_mode_info *mode_info); - - grub_err_t (*set_palette) (unsigned int start, - unsigned int count, - struct grub_video_palette_data *palette_data); - grub_err_t (*get_palette) (unsigned int start, - unsigned int count, - struct grub_video_palette_data *palette_data); + grub_err_t (*set_palette) (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); - grub_err_t (*set_viewport) (unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height); + grub_err_t (*get_palette) (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); - grub_err_t (*get_viewport) (unsigned int *x, - unsigned int *y, - unsigned int *width, - unsigned int *height); + grub_err_t (*set_viewport) (unsigned int x, unsigned int y, + unsigned int width, unsigned int height); + + grub_err_t (*get_viewport) (unsigned int *x, unsigned int *y, + unsigned int *width, unsigned int *height); grub_video_color_t (*map_color) (grub_uint32_t color_name); - - grub_video_color_t (*map_rgb) (grub_uint8_t red, - grub_uint8_t green, - grub_uint8_t blue); - grub_video_color_t (*map_rgba) (grub_uint8_t red, - grub_uint8_t green, - grub_uint8_t blue, - grub_uint8_t alpha); + grub_video_color_t (*map_rgb) (grub_uint8_t red, grub_uint8_t green, + grub_uint8_t blue); - grub_err_t (*fill_rect) (grub_video_color_t color, - int x, - int y, - unsigned int width, - unsigned int height); + grub_video_color_t (*map_rgba) (grub_uint8_t red, grub_uint8_t green, + grub_uint8_t blue, grub_uint8_t alpha); + + grub_err_t (*fill_rect) (grub_video_color_t color, int x, int y, + unsigned int width, unsigned int height); grub_err_t (*blit_glyph) (struct grub_font_glyph *glyph, - grub_video_color_t color, - int x, - int y); + grub_video_color_t color, int x, int y); grub_err_t (*blit_bitmap) (struct grub_video_bitmap *bitmap, - int x, - int y, - int offset_x, - int offset_y, - unsigned int width, - unsigned int height); + int x, int y, int offset_x, int offset_y, + unsigned int width, unsigned int height); grub_err_t (*blit_render_target) (struct grub_video_render_target *source, - int x, - int y, - int offset_x, - int offset_y, - unsigned int width, - unsigned int height); + int x, int y, int offset_x, int offset_y, + unsigned int width, unsigned int height); - grub_err_t (*scroll) (grub_video_color_t color, - int dx, - int dy); + grub_err_t (*scroll) (grub_video_color_t color, int dx, int dy); grub_err_t (*swap_buffers) (void); grub_err_t (*create_render_target) (struct grub_video_render_target **result, - unsigned int width, - unsigned int height, - unsigned int mode_type); + unsigned int width, unsigned int height, + unsigned int mode_type); grub_err_t (*delete_render_target) (struct grub_video_render_target *target); @@ -244,9 +218,8 @@ void grub_video_register (grub_video_adapter_t adapter); void grub_video_unregister (grub_video_adapter_t adapter); void grub_video_iterate (int (*hook) (grub_video_adapter_t adapter)); -grub_err_t grub_video_setup (unsigned int width, - unsigned int height, - unsigned int mode_type); +grub_err_t grub_video_setup (unsigned int width, unsigned int height, + unsigned int mode_type); grub_err_t grub_video_restore (void); @@ -254,72 +227,50 @@ grub_err_t grub_video_get_info (struct grub_video_mode_info *mode_info); enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info); -grub_err_t grub_video_set_palette (unsigned int start, - unsigned int count, - struct grub_video_palette_data *palette_data); +grub_err_t grub_video_set_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); -grub_err_t grub_video_get_palette (unsigned int start, - unsigned int count, - struct grub_video_palette_data *palette_data); +grub_err_t grub_video_get_palette (unsigned int start, unsigned int count, + struct grub_video_palette_data *palette_data); -grub_err_t grub_video_set_viewport (unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height); +grub_err_t grub_video_set_viewport (unsigned int x, unsigned int y, + unsigned int width, unsigned int height); -grub_err_t grub_video_get_viewport (unsigned int *x, - unsigned int *y, - unsigned int *width, - unsigned int *height); +grub_err_t grub_video_get_viewport (unsigned int *x, unsigned int *y, + unsigned int *width, unsigned int *height); grub_video_color_t grub_video_map_color (grub_uint32_t color_name); -grub_video_color_t grub_video_map_rgb (grub_uint8_t red, - grub_uint8_t green, - grub_uint8_t blue); +grub_video_color_t grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, + grub_uint8_t blue); -grub_video_color_t grub_video_map_rgba (grub_uint8_t red, - grub_uint8_t green, - grub_uint8_t blue, - grub_uint8_t alpha); +grub_video_color_t grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, + grub_uint8_t blue, grub_uint8_t alpha); -grub_err_t grub_video_fill_rect (grub_video_color_t color, - int x, - int y, - unsigned int width, - unsigned int height); +grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y, + unsigned int width, unsigned int height); grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph, - grub_video_color_t color, - int x, - int y); + grub_video_color_t color, int x, int y); grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, - int x, - int y, - int offset_x, - int offset_y, - unsigned int width, - unsigned int height); + int x, int y, int offset_x, int offset_y, + unsigned int width, unsigned int height); grub_err_t grub_video_blit_render_target (struct grub_video_render_target *source, - int x, - int y, - int offset_x, - int offset_y, - unsigned int width, - unsigned int height); + int x, int y, + int offset_x, int offset_y, + unsigned int width, + unsigned int height); -grub_err_t grub_video_scroll (grub_video_color_t color, - int dx, - int dy); +grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy); grub_err_t grub_video_swap_buffers (void); grub_err_t grub_video_create_render_target (struct grub_video_render_target **result, - unsigned int width, - unsigned int height, - unsigned int mode_type); + unsigned int width, + unsigned int height, + unsigned int mode_type); grub_err_t grub_video_delete_render_target (struct grub_video_render_target *target); diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index f36fbdbbf..846f12437 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -68,7 +68,7 @@ static struct grub_uint8_t *ptr; int index_color_mode; struct grub_video_palette_data palette[256]; -} framebuffer; +} framebuffer; static struct grub_video_render_target *render_target; static grub_uint32_t initial_mode; @@ -91,7 +91,7 @@ grub_vbe_probe (struct grub_vbe_info_block *info_block) { struct grub_vbe_info_block *vbe_ib; grub_vbe_status_t status; - + /* Clear caller's controller info block. */ if (info_block) grub_memset (info_block, 0, sizeof (*info_block)); @@ -104,29 +104,29 @@ grub_vbe_probe (struct grub_vbe_info_block *info_block) /* Mark VESA BIOS extension as undetected. */ vbe_detected = 0; - + /* Use low memory scratch area as temporary storage - for VESA BIOS call. */ + for VESA BIOS call. */ vbe_ib = (struct grub_vbe_info_block *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; - + /* Prepare info block. */ grub_memset (vbe_ib, 0, sizeof (*vbe_ib)); - + vbe_ib->signature[0] = 'V'; vbe_ib->signature[1] = 'B'; vbe_ib->signature[2] = 'E'; vbe_ib->signature[3] = '2'; - + /* Try to get controller info block. */ status = grub_vbe_bios_get_controller_info (vbe_ib); if (status == 0x004F) - { - /* Copy it for later usage. */ - grub_memcpy (&controller_info, vbe_ib, sizeof (controller_info)); - - /* Mark VESA BIOS extension as detected. */ - vbe_detected = 1; - } + { + /* Copy it for later usage. */ + grub_memcpy (&controller_info, vbe_ib, sizeof (controller_info)); + + /* Mark VESA BIOS extension as detected. */ + vbe_detected = 1; + } } if (! vbe_detected) @@ -145,7 +145,7 @@ grub_vbe_set_video_mode (grub_uint32_t mode, { grub_vbe_status_t status; grub_uint32_t old_mode; - + /* Make sure that VBE is supported. */ grub_vbe_probe (0); if (grub_errno != GRUB_ERR_NONE) @@ -164,27 +164,27 @@ grub_vbe_set_video_mode (grub_uint32_t mode, /* Determine frame buffer pixel format. */ switch (active_mode_info.memory_model) - { - case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL: - framebuffer.index_color_mode = 1; - break; - - case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR: - framebuffer.index_color_mode = 0; - break; - - default: - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, - "unsupported pixel format 0x%x", - active_mode_info.memory_model); - } + { + case GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL: + framebuffer.index_color_mode = 1; + break; + + case GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR: + framebuffer.index_color_mode = 0; + break; + + default: + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, + "unsupported pixel format 0x%x", + active_mode_info.memory_model); + } } /* Get current mode. */ grub_vbe_get_video_mode (&old_mode); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - + /* Try to set video mode. */ status = grub_vbe_bios_set_mode (mode, 0); if (status != GRUB_VBE_STATUS_OK) @@ -204,11 +204,11 @@ grub_vbe_set_video_mode (grub_uint32_t mode, framebuffer.ptr = (grub_uint8_t *) active_mode_info.phys_base_addr; if (controller_info.version >= 0x300) - framebuffer.bytes_per_scan_line = active_mode_info.lin_bytes_per_scan_line; + framebuffer.bytes_per_scan_line = active_mode_info.lin_bytes_per_scan_line; else - framebuffer.bytes_per_scan_line = active_mode_info.bytes_per_scan_line; + framebuffer.bytes_per_scan_line = active_mode_info.bytes_per_scan_line; } - + /* Calculate bytes_per_pixel value. */ switch(active_mode_info.bits_per_pixel) { @@ -217,7 +217,7 @@ grub_vbe_set_video_mode (grub_uint32_t mode, case 16: framebuffer.bytes_per_pixel = 2; break; case 15: framebuffer.bytes_per_pixel = 2; break; case 8: framebuffer.bytes_per_pixel = 1; break; - default: + default: grub_vbe_bios_set_mode (old_mode, 0); return grub_error (GRUB_ERR_BAD_DEVICE, "cannot set VBE mode %x", @@ -229,7 +229,7 @@ grub_vbe_set_video_mode (grub_uint32_t mode, if (framebuffer.index_color_mode) { struct grub_vbe_palette_data *palette - = (struct grub_vbe_palette_data *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; + = (struct grub_vbe_palette_data *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR; /* Make sure that the BIOS can reach the palette. */ grub_memcpy (palette, vga_colors, sizeof (vga_colors)); @@ -238,15 +238,7 @@ grub_vbe_set_video_mode (grub_uint32_t mode, 0, palette); - /* For now, ignore the status. Not sure if this is fatal. */ -#if 0 - if (status != GRUB_VBE_STATUS_OK) - { - grub_vbe_bios_set_mode (old_mode, 0); - return grub_error (GRUB_ERR_BAD_DEVICE, - "cannot set the default VGA palette"); - } -#endif + /* Just ignore the status. */ } /* Copy mode info for caller. */ @@ -293,8 +285,8 @@ grub_vbe_get_video_mode_info (grub_uint32_t mode, /* Try to get mode info from VESA BIOS. */ status = grub_vbe_bios_get_mode_info (mode, mi_tmp); if (status != GRUB_VBE_STATUS_OK) - return grub_error (GRUB_ERR_BAD_DEVICE, - "cannot get information on the mode %x", mode); + return grub_error (GRUB_ERR_BAD_DEVICE, + "cannot get information on the mode %x", mode); /* Make copy of mode info block. */ grub_memcpy (mode_info, mi_tmp, sizeof (*mode_info)); @@ -311,7 +303,7 @@ grub_video_vbe_get_video_ptr (struct grub_video_render_target *source, grub_uint32_t x, grub_uint32_t y) { grub_uint8_t *ptr = 0; - + switch (source->mode_info.bpp) { case 32: @@ -336,10 +328,10 @@ grub_video_vbe_get_video_ptr (struct grub_video_render_target *source, case 8: ptr = (grub_uint8_t *)source->data + y * source->mode_info.pitch - + x; + + x; break; } - + return ptr; } @@ -357,48 +349,48 @@ grub_video_vbe_draw_pixel (grub_uint32_t x, grub_uint32_t y, { case 32: { - grub_uint32_t *ptr; - + grub_uint32_t *ptr; + ptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (render_target, x, y); - - *ptr = color; + + *ptr = color; } break; - + case 24: { - grub_uint8_t *ptr; - grub_uint8_t *ptr2 = (grub_uint8_t *) &color; - + grub_uint8_t *ptr; + grub_uint8_t *ptr2 = (grub_uint8_t *) &color; + ptr = grub_video_vbe_get_video_ptr (render_target, x, y); - - ptr[0] = ptr2[0]; - ptr[1] = ptr2[1]; - ptr[2] = ptr2[2]; + + ptr[0] = ptr2[0]; + ptr[1] = ptr2[1]; + ptr[2] = ptr2[2]; } break; case 16: case 15: { - grub_uint16_t *ptr; - + grub_uint16_t *ptr; + ptr = (grub_uint16_t *)grub_video_vbe_get_video_ptr (render_target, x, y); - - *ptr = (grub_uint16_t) (color & 0xFFFF); + + *ptr = (grub_uint16_t) (color & 0xFFFF); } break; case 8: { - grub_uint8_t *ptr; - + grub_uint8_t *ptr; + ptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (render_target, x, y); - - *ptr = (grub_uint8_t) (color & 0xFF); + + *ptr = (grub_uint8_t) (color & 0xFF); } break; @@ -412,7 +404,7 @@ grub_video_vbe_get_pixel (struct grub_video_render_target *source, grub_uint32_t x, grub_uint32_t y) { grub_video_color_t color = 0; - + if (x >= source->mode_info.width) return 0; @@ -424,10 +416,10 @@ grub_video_vbe_get_pixel (struct grub_video_render_target *source, case 32: color = *(grub_uint32_t *)grub_video_vbe_get_video_ptr (source, x, y); break; - + case 24: { - grub_uint8_t *ptr; + grub_uint8_t *ptr; ptr = grub_video_vbe_get_video_ptr (source, x, y); color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16); } @@ -437,16 +429,16 @@ grub_video_vbe_get_pixel (struct grub_video_render_target *source, case 15: color = *(grub_uint16_t *)grub_video_vbe_get_video_ptr (source, x, y); break; - + case 8: color = *(grub_uint8_t *)grub_video_vbe_get_video_ptr (source, x, y); break; - + default: break; } - return color; + return color; } static grub_err_t @@ -458,7 +450,7 @@ grub_video_vbe_init (void) struct grub_vbe_info_block info_block; /* Check if there is adapter present. - + Firmware note: There has been a report that some cards store video mode list in temporary memory. So we must first use vbe probe to get refreshed information to receive valid pointers and data, and then @@ -466,12 +458,12 @@ grub_video_vbe_init (void) grub_vbe_probe (&info_block); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - + /* Copy modelist to local memory. */ p = rm_mode_list = real2pm (info_block.video_mode_ptr); while(*p++ != 0xFFFF) ; - + mode_list_size = (grub_addr_t) p - (grub_addr_t) rm_mode_list; mode_list = grub_malloc (mode_list_size); if (! mode_list) @@ -485,7 +477,7 @@ grub_video_vbe_init (void) /* Free allocated resources. */ grub_free (mode_list); mode_list = 0; - + return grub_errno; } @@ -500,19 +492,19 @@ static grub_err_t grub_video_vbe_fini (void) { grub_vbe_status_t status; - + /* Restore old video mode. */ status = grub_vbe_bios_set_mode (initial_mode, 0); if (status != GRUB_VBE_STATUS_OK) /* TODO: Decide, is this something we want to do. */ return grub_errno; - + /* TODO: Free any resources allocated by driver. */ grub_free (mode_list); mode_list = 0; /* TODO: destroy render targets. */ - + /* Return success to caller. */ return GRUB_ERR_NONE; } @@ -527,16 +519,16 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, grub_uint32_t best_mode = 0; int depth; unsigned int i; - + /* Decode depth from mode_type. If it is zero, then autodetect. */ depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK) >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS; - + /* Walk thru mode list and try to find matching mode. */ for (p = mode_list; *p != 0xFFFF; p++) { grub_uint32_t mode = *p; - + grub_vbe_get_video_mode_info (mode, &mode_info); if (grub_errno != GRUB_ERR_NONE) { @@ -564,12 +556,12 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, if ((mode_info.mode_attributes & 0x010) == 0) /* We allow only graphical modes. */ continue; - + if ((mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL) && (mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)) /* Not compatible memory model. */ continue; - + if ((mode_info.x_resolution != width) || (mode_info.y_resolution != height)) /* Non matching resolution. */ @@ -588,16 +580,16 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, /* Requested only RGB modes. */ continue; } - + /* If there is a request for specific depth, ignore others. */ if ((depth != 0) && (mode_info.bits_per_pixel != depth)) continue; - + /* Select mode with most number of bits per pixel. */ if (best_mode != 0) if (mode_info.bits_per_pixel < best_mode_info.bits_per_pixel) continue; - + /* Save so far best mode information for later use. */ best_mode = mode; grub_memcpy (&best_mode_info, &mode_info, sizeof (mode_info)); @@ -611,14 +603,14 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, grub_vbe_set_video_mode (best_mode, &active_mode_info); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - + /* Now we are happily in requested video mode. Cache some info in order to fasten later operations. */ mode_in_use = best_mode; /* Reset render target to framebuffer one. */ render_target = &framebuffer.render_target; - + /* Fill mode info details in framebuffer's render target. */ render_target->mode_info.width = active_mode_info.x_resolution; render_target->mode_info.height = active_mode_info.y_resolution; @@ -642,7 +634,7 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, render_target->mode_info.reserved_field_pos = active_mode_info.rsvd_field_position; render_target->mode_info.blit_format = grub_video_get_blit_format (&render_target->mode_info); - + /* Reset viewport to match new mode. */ render_target->viewport.x = 0; render_target->viewport.y = 0; @@ -678,7 +670,7 @@ grub_video_vbe_get_info (struct grub_video_mode_info *mode_info) /* Copy mode info from active render target. */ grub_memcpy (mode_info, &render_target->mode_info, sizeof (struct grub_video_mode_info)); - + return GRUB_ERR_NONE; } @@ -687,7 +679,7 @@ grub_video_vbe_set_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data) { unsigned int i; - + if (framebuffer.index_color_mode) { /* TODO: Implement setting indexed color mode palette to hardware. */ @@ -695,7 +687,7 @@ grub_video_vbe_set_palette (unsigned int start, unsigned int count, // / sizeof (struct grub_vbe_palette_data), // 0, // palette); - + } /* Then set color to emulated palette. */ @@ -729,13 +721,13 @@ grub_video_vbe_set_viewport (unsigned int x, unsigned int y, x = 0; width = 0; } - + if (y > active_mode_info.y_resolution) { y = 0; height = 0; } - + if (x + width > active_mode_info.x_resolution) width = active_mode_info.x_resolution - x; @@ -758,7 +750,7 @@ grub_video_vbe_get_viewport (unsigned int *x, unsigned int *y, if (y) *y = render_target->viewport.y; if (width) *width = render_target->viewport.width; if (height) *height = render_target->viewport.height; - + return GRUB_ERR_NONE; } @@ -766,7 +758,7 @@ static grub_video_color_t grub_video_vbe_map_color (grub_uint32_t color_name) { /* TODO: implement color theme mapping code. */ - + if (color_name < 256) { if ((render_target->mode_info.mode_type @@ -775,15 +767,15 @@ grub_video_vbe_map_color (grub_uint32_t color_name) else { grub_video_color_t color; - + color = grub_video_vbe_map_rgb (framebuffer.palette[color_name].r, framebuffer.palette[color_name].g, framebuffer.palette[color_name].b); - + return color; } } - + return 0; } @@ -799,7 +791,7 @@ grub_video_vbe_map_rgb (grub_uint8_t red, grub_uint8_t green, int tmp; int val; int i; - + /* Find best matching color. */ for (i = 0; i < 256; i++) { @@ -809,10 +801,10 @@ grub_video_vbe_map_rgb (grub_uint8_t red, grub_uint8_t green, tmp += val * val; val = framebuffer.palette[i].b - blue; tmp += val * val; - + if (i == 0) delta = tmp; - + if (tmp < delta) { delta = tmp; @@ -821,14 +813,14 @@ grub_video_vbe_map_rgb (grub_uint8_t red, grub_uint8_t green, break; } } - + return minindex; } else { grub_uint32_t value; grub_uint8_t alpha = 255; /* Opaque color. */ - + red >>= 8 - render_target->mode_info.red_mask_size; green >>= 8 - render_target->mode_info.green_mask_size; blue >>= 8 - render_target->mode_info.blue_mask_size; @@ -838,7 +830,7 @@ grub_video_vbe_map_rgb (grub_uint8_t red, grub_uint8_t green, value |= green << render_target->mode_info.green_field_pos; value |= blue << render_target->mode_info.blue_field_pos; value |= alpha << render_target->mode_info.reserved_field_pos; - + return value; } @@ -856,7 +848,7 @@ grub_video_vbe_map_rgba (grub_uint8_t red, grub_uint8_t green, else { grub_uint32_t value; - + red >>= 8 - render_target->mode_info.red_mask_size; green >>= 8 - render_target->mode_info.green_mask_size; blue >>= 8 - render_target->mode_info.blue_mask_size; @@ -866,7 +858,7 @@ grub_video_vbe_map_rgba (grub_uint8_t red, grub_uint8_t green, value |= green << render_target->mode_info.green_field_pos; value |= blue << render_target->mode_info.blue_field_pos; value |= alpha << render_target->mode_info.reserved_field_pos; - + return value; } } @@ -889,7 +881,7 @@ grub_video_vbe_unmap_color (struct grub_video_render_target * source, *alpha = 0; return; } - + *red = framebuffer.palette[color].r; *green = framebuffer.palette[color].g; *blue = framebuffer.palette[color].b; @@ -897,9 +889,9 @@ grub_video_vbe_unmap_color (struct grub_video_render_target * source, return; } else - { + { grub_uint32_t tmp; - + /* Get red component. */ tmp = color >> source->mode_info.red_field_pos; tmp &= (1 << source->mode_info.red_mask_size) - 1; @@ -960,7 +952,7 @@ grub_video_vbe_fill_rect (grub_video_color_t color, int x, int y, height += y; y = 0; } - + if ((x + width) > render_target->viewport.width) width = render_target->viewport.width - x; if ((y + height) > render_target->viewport.height) @@ -984,19 +976,19 @@ grub_video_vbe_fill_rect (grub_video_color_t color, int x, int y, width, height); return GRUB_ERR_NONE; } - + if (render_target->mode_info.blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR) { grub_video_i386_vbefill_index (render_target, color, x, y, width, height); return GRUB_ERR_NONE; } - + /* Use backup method to fill area. */ for (j = 0; j < height; j++) for (i = 0; i < width; i++) grub_video_vbe_draw_pixel (x+i, y+j, color); - + return GRUB_ERR_NONE; } @@ -1011,11 +1003,11 @@ grub_video_vbe_blit_glyph (struct grub_font_glyph * glyph, unsigned int j; unsigned int x_offset = 0; unsigned int y_offset = 0; - + /* Make sure there is something to do. */ if (x >= (int)render_target->viewport.width) return GRUB_ERR_NONE; - + if (y >= (int)render_target->viewport.height) return GRUB_ERR_NONE; @@ -1023,10 +1015,10 @@ grub_video_vbe_blit_glyph (struct grub_font_glyph * glyph, width = ((glyph->width + 7) / 8) * 8; charwidth = width; height = glyph->height; - + if (x + (int)width < 0) return GRUB_ERR_NONE; - + if (y + (int)height < 0) return GRUB_ERR_NONE; @@ -1043,7 +1035,7 @@ grub_video_vbe_blit_glyph (struct grub_font_glyph * glyph, y_offset = (unsigned int)-y; y = 0; } - + if ((x + width) > render_target->viewport.width) width = render_target->viewport.width - x; if ((y + height) > render_target->viewport.height) @@ -1052,7 +1044,7 @@ grub_video_vbe_blit_glyph (struct grub_font_glyph * glyph, /* Add viewport offset. */ x += render_target->viewport.x; y += render_target->viewport.y; - + /* Draw glyph. */ for (j = 0; j < height; j++) for (i = 0; i < width; i++) @@ -1082,7 +1074,7 @@ grub_video_vbe_blit_bitmap (struct grub_video_bitmap * bitmap, x -= offset_x; offset_x = 0; } - + if (offset_y < 0) { height += offset_y; @@ -1102,7 +1094,7 @@ grub_video_vbe_blit_bitmap (struct grub_video_bitmap * bitmap, offset_y += (unsigned int)-y; y = 0; } - + if ((x + width) > render_target->viewport.width) width = render_target->viewport.width - x; if ((y + height) > render_target->viewport.height) @@ -1152,43 +1144,43 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, x -= offset_x; offset_x = 0; } - + if (offset_y < 0) { height += offset_y; y -= offset_y; offset_y = 0; } - + if (x < 0) { width += x; offset_x += (unsigned int)-x; x = 0; } - + if (y < 0) { height += y; offset_y += (unsigned int)-y; y = 0; } - + /* Do not allow drawing out of viewport. */ if ((x + width) > render_target->viewport.width) width = render_target->viewport.width - x; if ((y + height) > render_target->viewport.height) height = render_target->viewport.height - y; - + if ((offset_x + width) > source->mode_info.width) width = source->mode_info.width - offset_x; if ((offset_y + height) > source->mode_info.height) height = source->mode_info.height - offset_y; - + /* Limit drawing to source render target dimensions. */ if (width > source->mode_info.width) width = source->mode_info.width; - + if (height > source->mode_info.height) height = source->mode_info.height; @@ -1222,7 +1214,7 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, offset_x, offset_y); return GRUB_ERR_NONE; } - } + } if (source->mode_info.blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8) { @@ -1249,7 +1241,7 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, offset_x, offset_y); return GRUB_ERR_NONE; } - } + } if (source->mode_info.blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR) { @@ -1260,13 +1252,13 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, offset_x, offset_y); return GRUB_ERR_NONE; } - } + } /* Use backup method to render. */ for (j = 0; j < height; j++) { for (i = 0; i < width; i++) - { + { grub_uint8_t src_red; grub_uint8_t src_green; grub_uint8_t src_blue; @@ -1277,14 +1269,14 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, grub_uint8_t dst_alpha; grub_video_color_t src_color; grub_video_color_t dst_color; - + src_color = grub_video_vbe_get_pixel (source, i + offset_x, j + offset_y); grub_video_vbe_unmap_color (source, src_color, &src_red, &src_green, &src_blue, &src_alpha); - + if (src_alpha == 0) continue; - + if (src_alpha == 255) { dst_color = grub_video_vbe_map_rgba (src_red, src_green, @@ -1294,17 +1286,17 @@ grub_video_vbe_blit_render_target (struct grub_video_render_target *source, } dst_color = grub_video_vbe_get_pixel (render_target, x + i, y + j); - + grub_video_vbe_unmap_color (render_target, dst_color, &dst_red, &dst_green, &dst_blue, &dst_alpha); - + dst_red = (((src_red * src_alpha) + (dst_red * (255 - src_alpha))) / 255); dst_green = (((src_green * src_alpha) + (dst_green * (255 - src_alpha))) / 255); dst_blue = (((src_blue * src_alpha) + (dst_blue * (255 - src_alpha))) / 255); - + dst_alpha = src_alpha; dst_color = grub_video_vbe_map_rgba (dst_red, dst_green, dst_blue, dst_alpha); @@ -1325,14 +1317,14 @@ grub_video_vbe_scroll (grub_video_color_t color, int dx, int dy) int src_y; int dst_x; int dst_y; - + /* 1. Check if we have something to do. */ if ((dx == 0) && (dy == 0)) return GRUB_ERR_NONE; width = render_target->viewport.width - grub_abs (dx); height = render_target->viewport.height - grub_abs (dy); - + if (dx < 0) { src_x = render_target->viewport.x - dx; @@ -1363,7 +1355,7 @@ grub_video_vbe_scroll (grub_video_color_t color, int dx, int dy) grub_uint8_t *src; grub_uint8_t *dst; int j; - + for (j = 0; j < height; j++) { dst = grub_video_vbe_get_video_ptr (render_target, dst_x, dst_y + j); @@ -1372,7 +1364,7 @@ grub_video_vbe_scroll (grub_video_color_t color, int dx, int dy) width * render_target->mode_info.bytes_per_pixel); } } - + /* 4. Fill empty space with specified color. In this implementation there might be colliding areas but at the moment there is no need to optimize this. */ @@ -1384,7 +1376,7 @@ grub_video_vbe_scroll (grub_video_color_t color, int dx, int dy) { if (render_target->viewport.height < grub_abs (dy)) dy = -render_target->viewport.height; - + grub_video_vbe_fill_rect (color, 0, render_target->viewport.height + dy, render_target->viewport.width, -dy); } @@ -1397,11 +1389,11 @@ grub_video_vbe_scroll (grub_video_color_t color, int dx, int dy) { if (render_target->viewport.width < grub_abs (dx)) dx = -render_target->viewport.width; - + grub_video_vbe_fill_rect (color, render_target->viewport.width + dx, 0, -dx, render_target->viewport.height); } - + return GRUB_ERR_NONE; } @@ -1419,14 +1411,14 @@ grub_video_vbe_create_render_target (struct grub_video_render_target **result, { struct grub_video_render_target *target; unsigned int size; - + /* Validate arguments. */ if ((! result) || (width == 0) || (height == 0)) return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument given."); - + /* Allocate memory for render target. */ target = grub_malloc (sizeof (struct grub_video_render_target)); if (! target) @@ -1434,10 +1426,10 @@ grub_video_vbe_create_render_target (struct grub_video_render_target **result, /* TODO: Implement other types too. Currently only 32bit render targets are supported. */ - + /* Mark render target as allocated. */ target->is_allocated = 1; - + /* Maximize viewport. */ target->viewport.x = 0; target->viewport.y = 0; @@ -1466,22 +1458,22 @@ grub_video_vbe_create_render_target (struct grub_video_render_target **result, /* Calculate size needed for the data. */ size = (width * target->mode_info.bytes_per_pixel) * height; - + target->data = grub_malloc (size); if (! target->data) { grub_free (target); return grub_errno; } - + /* Clear render target with black and maximum transparency. */ grub_memset (target->data, 0, size); /* TODO: Add render target to render target list. */ - + /* Save result to caller. */ *result = target; - + return GRUB_ERR_NONE; } @@ -1491,16 +1483,16 @@ grub_video_vbe_delete_render_target (struct grub_video_render_target *target) /* If there is no target, then just return without error. */ if (! target) return GRUB_ERR_NONE; - + /* TODO: Delist render target fron render target list. */ - + /* If this is software render target, free it's memory. */ if (target->is_allocated) grub_free (target->data); - + /* Free render target. */ grub_free (target); - + return GRUB_ERR_NONE; } @@ -1510,20 +1502,20 @@ grub_video_vbe_set_active_render_target (struct grub_video_render_target *target if (target == GRUB_VIDEO_RENDER_TARGET_FRONT_BUFFER) { render_target = &framebuffer.render_target; - + return GRUB_ERR_NONE; } - + if (target == GRUB_VIDEO_RENDER_TARGET_BACK_BUFFER) return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "double buffering not implemented yet."); - + if (! target->data) return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid render target given."); - + render_target = target; - + return GRUB_ERR_NONE; } @@ -1551,7 +1543,7 @@ static struct grub_video_adapter grub_video_vbe_adapter = .create_render_target = grub_video_vbe_create_render_target, .delete_render_target = grub_video_vbe_delete_render_target, .set_active_render_target = grub_video_vbe_set_active_render_target, - + .next = 0 }; diff --git a/video/i386/pc/vbeblit.c b/video/i386/pc/vbeblit.c index e14233af2..9cce2541c 100644 --- a/video/i386/pc/vbeblit.c +++ b/video/i386/pc/vbeblit.c @@ -46,10 +46,10 @@ grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_render_target *dst, unsigned int dr; unsigned int dg; unsigned int db; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x, @@ -60,9 +60,9 @@ grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_render_target *dst, for (i = 0; i < width; i++) { color = *srcptr++; - + a = color >> 24; - + if (a == 0) { dstptr++; @@ -74,24 +74,24 @@ grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (struct grub_video_render_target *dst, *dstptr++ = color; continue; } - + sr = (color >> 0) & 0xFF; sg = (color >> 8) & 0xFF; sb = (color >> 16) & 0xFF; - + color = *dstptr; - + dr = (color >> 0) & 0xFF; dg = (color >> 8) & 0xFF; db = (color >> 16) & 0xFF; - + dr = (dr * (255 - a) + sr * a) / 255; dg = (dg * (255 - a) + sg * a) / 255; db = (db * (255 - a) + sb * a) / 255; - + color = (a << 24) | (db << 16) | (dg << 8) | dr; - *dstptr++ = color; + *dstptr++ = color; } } } @@ -114,10 +114,10 @@ grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_render_target *dst, unsigned int dr; unsigned int dg; unsigned int db; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x, @@ -128,9 +128,9 @@ grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_render_target *dst, for (i = 0; i < width; i++) { color = *srcptr++; - + a = color >> 24; - + if (a == 0) { dstptr += 3; @@ -146,18 +146,18 @@ grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (struct grub_video_render_target *dst, *dstptr++ = sr; *dstptr++ = sg; *dstptr++ = sb; - + continue; } - + dr = dstptr[0]; dg = dstptr[1]; db = dstptr[2]; - + dr = (dr * (255 - a) + sr * a) / 255; dg = (dg * (255 - a) + sg * a) / 255; db = (db * (255 - a) + sb * a) / 255; - + *dstptr++ = dr; *dstptr++ = dg; *dstptr++ = db; @@ -184,10 +184,10 @@ grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_render_target *dst, unsigned char dg; unsigned char db; unsigned char da; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (src, offset_x, @@ -198,9 +198,9 @@ grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_render_target *dst, for (i = 0; i < width; i++) { color = *srcptr++; - + a = color >> 24; - + if (a == 0) { dstptr++; @@ -210,20 +210,20 @@ grub_video_i386_vbeblit_index_R8G8B8A8 (struct grub_video_render_target *dst, sr = (color >> 0) & 0xFF; sg = (color >> 8) & 0xFF; sb = (color >> 16) & 0xFF; - + if (a == 255) { color = grub_video_vbe_map_rgb(sr, sg, sb); - *dstptr++ = color & 0xFF; + *dstptr++ = color & 0xFF; continue; } - + grub_video_vbe_unmap_color (dst, *dstptr, &dr, &dg, &db, &da); - + dr = (dr * (255 - a) + sr * a) / 255; dg = (dg * (255 - a) + sg * a) / 255; db = (db * (255 - a) + sb * a) / 255; - + color = grub_video_vbe_map_rgb(dr, dg, db); *dstptr++ = color & 0xFF; @@ -245,10 +245,10 @@ grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_render_target *dst, unsigned int sr; unsigned int sg; unsigned int sb; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x, @@ -263,13 +263,12 @@ grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (struct grub_video_render_target *dst, sb = *srcptr++; color = 0xFF000000 | (sb << 16) | (sg << 8) | sr; - + *dstptr++ = color; } } } - void grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_render_target *dst, struct grub_video_render_target *src, @@ -280,10 +279,10 @@ grub_video_i386_vbeblit_R8G8B8_R8G8B8 (struct grub_video_render_target *dst, int j; grub_uint8_t *srcptr; grub_uint8_t *dstptr; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, @@ -317,10 +316,10 @@ grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_render_target *dst, unsigned int sr; unsigned int sg; unsigned int sb; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x, @@ -333,7 +332,7 @@ grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_render_target *dst, sr = *srcptr++; sg = *srcptr++; sb = *srcptr++; - + color = grub_video_vbe_map_rgb(sr, sg, sb); *dstptr++ = color & 0xFF; @@ -341,7 +340,6 @@ grub_video_i386_vbeblit_index_R8G8B8 (struct grub_video_render_target *dst, } } - void grub_video_i386_vbeblit_index_index (struct grub_video_render_target *dst, struct grub_video_render_target *src, @@ -352,15 +350,15 @@ grub_video_i386_vbeblit_index_index (struct grub_video_render_target *dst, int j; grub_uint8_t *srcptr; grub_uint8_t *dstptr; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { srcptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (src, offset_x, j + offset_y); - + dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) diff --git a/video/i386/pc/vbefill.c b/video/i386/pc/vbefill.c index 9c8cf19eb..d31e21af4 100644 --- a/video/i386/pc/vbefill.c +++ b/video/i386/pc/vbefill.c @@ -36,10 +36,10 @@ grub_video_i386_vbefill_R8G8B8A8 (struct grub_video_render_target *dst, int i; int j; grub_uint32_t *dstptr; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { dstptr = (grub_uint32_t *)grub_video_vbe_get_video_ptr (dst, x, y + j); @@ -60,10 +60,10 @@ grub_video_i386_vbefill_R8G8B8 (struct grub_video_render_target *dst, grub_uint8_t fillr = (grub_uint8_t)((color >> 0) & 0xFF); grub_uint8_t fillg = (grub_uint8_t)((color >> 8) & 0xFF); grub_uint8_t fillb = (grub_uint8_t)((color >> 16) & 0xFF); - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j); @@ -77,7 +77,6 @@ grub_video_i386_vbefill_R8G8B8 (struct grub_video_render_target *dst, } } - void grub_video_i386_vbefill_index (struct grub_video_render_target *dst, grub_video_color_t color, int x, int y, @@ -87,10 +86,10 @@ grub_video_i386_vbefill_index (struct grub_video_render_target *dst, int j; grub_uint8_t *dstptr; grub_uint8_t fill = (grub_uint8_t)color & 0xFF; - + /* We do not need to worry about data being out of bounds as we assume that everything has been checked before. */ - + for (j = 0; j < height; j++) { dstptr = (grub_uint8_t *)grub_video_vbe_get_video_ptr (dst, x, y + j); diff --git a/video/video.c b/video/video.c index 3401a5508..ac0714fd2 100644 --- a/video/video.c +++ b/video/video.c @@ -27,6 +27,7 @@ static grub_video_adapter_t grub_video_adapter_list; /* Active video adapter. */ static grub_video_adapter_t grub_video_adapter_active; +/* Register video driver. */ void grub_video_register (grub_video_adapter_t adapter) { @@ -34,29 +35,32 @@ grub_video_register (grub_video_adapter_t adapter) grub_video_adapter_list = adapter; } +/* Unregister video driver. */ void grub_video_unregister (grub_video_adapter_t adapter) { grub_video_adapter_t *p, q; - + for (p = &grub_video_adapter_list, q = *p; q; p = &(q->next), q = q->next) if (q == adapter) { *p = q->next; break; - } + } } +/* Iterate thru all registered video drivers. */ void grub_video_iterate (int (*hook) (grub_video_adapter_t adapter)) { grub_video_adapter_t p; - + for (p = grub_video_adapter_list; p; p = p->next) if (hook (p)) break; } +/* Setup specified video mode. */ grub_err_t grub_video_setup (unsigned int width, unsigned int height, unsigned int mode_type) @@ -70,11 +74,11 @@ grub_video_setup (unsigned int width, unsigned int height, grub_video_adapter_active->fini (); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - + /* Mark active adapter as not set. */ grub_video_adapter_active = 0; } - + /* Loop thru all possible video adapter trying to find requested mode. */ for (p = grub_video_adapter_list; p; p = p->next) { @@ -86,7 +90,7 @@ grub_video_setup (unsigned int width, unsigned int height, continue; } - /* Try to initialize video mode. */ + /* Try to initialize video mode. */ p->setup (width, height, mode_type); if (grub_errno == GRUB_ERR_NONE) { @@ -96,19 +100,20 @@ grub_video_setup (unsigned int width, unsigned int height, return GRUB_ERR_NONE; } else - grub_errno = GRUB_ERR_NONE; + grub_errno = GRUB_ERR_NONE; /* No valid mode found in this adapter, finalize adapter. */ p->fini (); if (grub_errno != GRUB_ERR_NONE) return grub_errno; } - + /* We couldn't find suitable adapter for specified mode. */ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Can't locate valid adapter for mode"); } +/* Restore back to initial mode (where applicaple). */ grub_err_t grub_video_restore (void) { @@ -117,21 +122,23 @@ grub_video_restore (void) grub_video_adapter_active->fini (); if (grub_errno != GRUB_ERR_NONE) return grub_errno; - + grub_video_adapter_active = 0; } return GRUB_ERR_NONE; } +/* Get information about active video mode. */ grub_err_t grub_video_get_info (struct grub_video_mode_info *mode_info) { if (! grub_video_adapter_active) return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated"); - + return grub_video_adapter_active->get_info (mode_info); } +/* Determine optimized blitting formation for specified video mode info. */ enum grub_video_blit_format grub_video_get_blit_format (struct grub_video_mode_info *mode_info) { @@ -179,26 +186,29 @@ grub_video_get_blit_format (struct grub_video_mode_info *mode_info) return GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR; } +/* Set new indexed color palette entries. */ grub_err_t grub_video_set_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data) { if (! grub_video_adapter_active) return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated"); - + return grub_video_adapter_active->set_palette (start, count, palette_data); } +/* Get indexed color palette entries. */ grub_err_t grub_video_get_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data) { if (! grub_video_adapter_active) return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated"); - + return grub_video_adapter_active->get_palette (start, count, palette_data); } +/* Set viewport dimensions. */ grub_err_t grub_video_set_viewport (unsigned int x, unsigned int y, unsigned int width, unsigned int height) @@ -209,6 +219,7 @@ grub_video_set_viewport (unsigned int x, unsigned int y, return grub_video_adapter_active->set_viewport (x, y, width, height); } +/* Get viewport dimensions. */ grub_err_t grub_video_get_viewport (unsigned int *x, unsigned int *y, unsigned int *width, unsigned int *height) @@ -219,6 +230,7 @@ grub_video_get_viewport (unsigned int *x, unsigned int *y, return grub_video_adapter_active->get_viewport (x, y, width, height); } +/* Map color name to adapter specific color. */ grub_video_color_t grub_video_map_color (grub_uint32_t color_name) { @@ -228,6 +240,7 @@ grub_video_map_color (grub_uint32_t color_name) return grub_video_adapter_active->map_color (color_name); } +/* Map RGB value to adapter specific color. */ grub_video_color_t grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue) { @@ -237,6 +250,7 @@ grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue) return grub_video_adapter_active->map_rgb (red, green, blue); } +/* Map RGBA value to adapter specific color. */ grub_video_color_t grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue, grub_uint8_t alpha) @@ -247,6 +261,7 @@ grub_video_map_rgba (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue, return grub_video_adapter_active->map_rgba (red, green, blue, alpha); } +/* Fill rectangle using specified color. */ grub_err_t grub_video_fill_rect (grub_video_color_t color, int x, int y, unsigned int width, unsigned int height) @@ -257,6 +272,7 @@ grub_video_fill_rect (grub_video_color_t color, int x, int y, return grub_video_adapter_active->fill_rect (color, x, y, width, height); } +/* Blit glyph to screen using specified color. */ grub_err_t grub_video_blit_glyph (struct grub_font_glyph *glyph, grub_video_color_t color, int x, int y) @@ -267,6 +283,7 @@ grub_video_blit_glyph (struct grub_font_glyph *glyph, return grub_video_adapter_active->blit_glyph (glyph, color, x, y); } +/* Blit bitmap to screen. */ grub_err_t grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, int x, int y, int offset_x, int offset_y, @@ -280,6 +297,7 @@ grub_video_blit_bitmap (struct grub_video_bitmap *bitmap, width, height); } +/* Blit render target to active render target. */ grub_err_t grub_video_blit_render_target (struct grub_video_render_target *target, int x, int y, int offset_x, int offset_y, @@ -293,6 +311,7 @@ grub_video_blit_render_target (struct grub_video_render_target *target, width, height); } +/* Scroll viewport and fill new areas with specified color. */ grub_err_t grub_video_scroll (grub_video_color_t color, int dx, int dy) { @@ -302,6 +321,7 @@ grub_video_scroll (grub_video_color_t color, int dx, int dy) return grub_video_adapter_active->scroll (color, dx, dy); } +/* Swap buffers (swap active render target). */ grub_err_t grub_video_swap_buffers (void) { @@ -311,6 +331,7 @@ grub_video_swap_buffers (void) return grub_video_adapter_active->swap_buffers (); } +/* Create new render target. */ grub_err_t grub_video_create_render_target (struct grub_video_render_target **result, unsigned int width, unsigned int height, @@ -324,6 +345,7 @@ grub_video_create_render_target (struct grub_video_render_target **result, mode_type); } +/* Delete render target. */ grub_err_t grub_video_delete_render_target (struct grub_video_render_target *target) { @@ -333,6 +355,7 @@ grub_video_delete_render_target (struct grub_video_render_target *target) return grub_video_adapter_active->delete_render_target (target); } +/* Set active render target. */ grub_err_t grub_video_set_active_render_target (struct grub_video_render_target *target) { @@ -342,12 +365,14 @@ grub_video_set_active_render_target (struct grub_video_render_target *target) return grub_video_adapter_active->set_active_render_target (target); } +/* Initialize Video API module. */ GRUB_MOD_INIT(video_video) { grub_video_adapter_active = 0; grub_video_adapter_list = 0; } +/* Finalize Video API module. */ GRUB_MOD_FINI(video_video) { }