bd0d7896cf
* DISTLIST: Added include/grub/video.h, term/gfxterm.c, video/video.c, commands/videotest.c. Removed term/i386/pc/vesafb.c. * conf/i386-pc.rmk (pkgdata_MODULES): Added video.mod, gfxterm.mod, videotest.mod. Removed vga.mod, vesafb.mod. (video_mod_SOURCES): Added. (video_mod_CFLAGS): Likewise. (video_mod_LDFLAGS): Likewise. (gfxterm_mod_SOURCES): Likewise. (gfxterm_mod_CFLAGS): Likewise. (gfxterm_mod_LDFLAGS): Likewise. (videotest_mod_SOURCES): Likewise. (videotest_mod_CFLAGS): Likewise. (videotest_mod_LDFLAGS): Likewise. (vesafb_mod_SOURCES): Removed. (vesafb_mod_CFLAGS): Likewise. (vesafb_mod_LDFLAGS): Likewise. (vga_mod_SOURCES): Likewise. (vga_mod_CFLAGS): Likewise. (vga_mod_LDFLAGS): Likewise. * commands/videotest.c: New file. * font/manager.c (fill_with_default_glyph): Modified to use grub_font_glyph. (grub_font_get_glyph): Likewise. (fontmanager): Renamed from this... (font_manager): ... to this. * include/grub/font.h (grub_font_glyph): Added new structure. (grub_font_get_glyph): Modified to use grub_font_glyph. * include/grub/misc.h (grub_abs): Added as inline function. * include/grub/video.h: New file. * include/grub/i386/pc/vbe.h (GRUB_VBE_STATUS_OK): New macro. (GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL): Likewise. (GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR): Likewise. (grub_vbe_get_controller_info): Renamed from this... (grub_vbe_bios_get_controller_info): ... to this. (grub_vbe_get_mode_info): Renamed from this... (grub_vbe_bios_get_mode_info): ... to this. (grub_vbe_set_mode): Renamed from this... (grub_vbe_bios_set_mode): ... to this. (grub_vbe_get_mode): Renamed from this... (grub_vbe_bios_get_mode): ... to this. (grub_vbe_set_memory_window): Renamed from this... (grub_vbe_bios_set_memory_window): ... to this. (grub_vbe_get_memory_window): Renamed from this... (grub_vbe_bios_get_memory_window): ... to this. (grub_vbe_set_scanline_length): Renamed from this... (grub_vbe_set_scanline_length): ... to this. (grub_vbe_get_scanline_length): Renamed from this... (grub_vbe_bios_get_scanline_length): ... to this. (grub_vbe_set_display_start): Renamed from this... (grub_vbe_bios_set_display_start): ... to this. (grub_vbe_get_display_start): Renamed from this... (grub_vbe_bios_get_display_start): ... to this. (grub_vbe_set_palette_data): Renamed from this... (grub_vbe_bios_set_palette_data): ... to this. (grub_vbe_set_pixel_rgb): Removed. (grub_vbe_set_pixel_index): Likewise. * kern/i386/pc/startup.S (grub_vbe_get_controller_info): Renamed from this... (grub_vbe_bios_get_controller_info): ... to this. (grub_vbe_get_mode_info): Renamed from this... (grub_vbe_bios_get_mode_info): ... to this. (grub_vbe_set_mode): Renamed from this... (grub_vbe_bios_set_mode): ... to this. (grub_vbe_get_mode): Renamed from this... (grub_vbe_bios_get_mode): ... to this. (grub_vbe_set_memory_window): Renamed from this... (grub_vbe_bios_set_memory_window): ... to this. (grub_vbe_get_memory_window): Renamed from this... (grub_vbe_bios_get_memory_window): ... to this. (grub_vbe_set_scanline_length): Renamed from this... (grub_vbe_set_scanline_length): ... to this. (grub_vbe_get_scanline_length): Renamed from this... (grub_vbe_bios_get_scanline_length): ... to this. (grub_vbe_set_display_start): Renamed from this... (grub_vbe_bios_set_display_start): ... to this. (grub_vbe_get_display_start): Renamed from this... (grub_vbe_bios_get_display_start): ... to this. (grub_vbe_set_palette_data): Renamed from this... (grub_vbe_bios_set_palette_data): ... to this. (grub_vbe_bios_get_controller_info): Fixed problem with registers getting corrupted after calling it. Added more pushes and pops. (grub_vbe_bios_set_mode): Likewise. (grub_vbe_bios_get_mode): Likewise. (grub_vbe_bios_get_memory_window): Likewise. (grub_vbe_bios_set_scanline_length): Likewise. (grub_vbe_bios_get_scanline_length): Likewise. (grub_vbe_bios_get_display_start): Likewise. (grub_vbe_bios_set_palette_data): Likewise. * normal/cmdline.c (cl_set_pos): Refresh the screen. (cl_insert): Likewise. (cl_delete): Likewise. * term/gfxterm.c: New file. * term/i386/pc/vesafb.c: Removed file. * video/video.c: New file. * video/i386/pc/vbe.c (real2pm): Added new function. (grub_video_vbe_draw_pixel): Likewise. (grub_video_vbe_get_video_ptr): Likewise. (grub_video_vbe_get_pixel): Likewise (grub_video_vbe_init): Likewise. (grub_video_vbe_fini): Likewise. (grub_video_vbe_setup): Likewise. (grub_video_vbe_get_info): Likewise. (grub_video_vbe_set_palette): Likewise. (grub_video_vbe_get_palette): Likewise. (grub_video_vbe_set_viewport): Likewise. (grub_video_vbe_get_viewport): Likewise. (grub_video_vbe_map_color): Likewise. (grub_video_vbe_map_rgb): Likewise. (grub_video_vbe_map_rgba): Likewise. (grub_video_vbe_unmap_color): Likewise. (grub_video_vbe_fill_rect): Likewise. (grub_video_vbe_blit_glyph): Likewise. (grub_video_vbe_blit_bitmap): Likewise. (grub_video_vbe_blit_render_target): Likewise. (grub_video_vbe_scroll): Likewise. (grub_video_vbe_swap_buffers): Likewise. (grub_video_vbe_create_render_target): Likewise. (grub_video_vbe_delete_render_target): Likewise. (grub_video_vbe_set_active_render_target): Likewise. (grub_vbe_set_pixel_rgb): Remove function. (grub_vbe_set_pixel_index): Likewise. (index_color_mode): Remove static variable. (active_mode): Likewise. (framebuffer): Likewise. (bytes_per_scan_line): Likewise. (grub_video_vbe_adapter): Added new static variable. (framebuffer): Likewise. (render_target): Likewise. (initial_mode): Likewise. (mode_in_use): Likewise. (mode_list): Likewise.
306 lines
8.9 KiB
C
306 lines
8.9 KiB
C
/*
|
|
* GRUB -- GRand Unified Bootloader
|
|
* Copyright (C) 2006 Free Software Foundation, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include <grub/video.h>
|
|
#include <grub/types.h>
|
|
#include <grub/dl.h>
|
|
|
|
/* The list of video adapters registerd to system. */
|
|
static grub_video_adapter_t grub_video_adapter_list;
|
|
|
|
/* Active video adapter. */
|
|
static grub_video_adapter_t grub_video_adapter_active;
|
|
|
|
void
|
|
grub_video_register (grub_video_adapter_t adapter)
|
|
{
|
|
adapter->next = grub_video_adapter_list;
|
|
grub_video_adapter_list = adapter;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_setup (unsigned int width, unsigned int height,
|
|
unsigned int mode_type)
|
|
{
|
|
grub_video_adapter_t p;
|
|
|
|
/* De-activate last set video adapter. */
|
|
if (grub_video_adapter_active)
|
|
{
|
|
/* Finalize adapter. */
|
|
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)
|
|
{
|
|
/* Try to initialize adapter, if can't skip to next. */
|
|
p->init ();
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
{
|
|
grub_errno = GRUB_ERR_NONE;
|
|
continue;
|
|
}
|
|
|
|
/* Try to initialize video mode. */
|
|
p->setup (width, height, mode_type);
|
|
if (grub_errno == GRUB_ERR_NONE)
|
|
{
|
|
/* Valid mode found from adapter, and it has been activated.
|
|
Specify it as active adapter. */
|
|
grub_video_adapter_active = p;
|
|
return GRUB_ERR_NONE;
|
|
}
|
|
else
|
|
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");
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_restore (void)
|
|
{
|
|
if (grub_video_adapter_active)
|
|
{
|
|
grub_video_adapter_active->fini ();
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
return grub_errno;
|
|
|
|
grub_video_adapter_active = 0;
|
|
}
|
|
return GRUB_ERR_NONE;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_set_viewport (unsigned int x, unsigned int y,
|
|
unsigned int width, unsigned int height)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->set_viewport (x, y, width, height);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_get_viewport (unsigned int *x, unsigned int *y,
|
|
unsigned int *width, unsigned int *height)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->get_viewport (x, y, width, height);
|
|
}
|
|
|
|
grub_video_color_t
|
|
grub_video_map_color (grub_uint32_t color_name)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return 0;
|
|
|
|
return grub_video_adapter_active->map_color (color_name);
|
|
}
|
|
|
|
grub_video_color_t
|
|
grub_video_map_rgb (grub_uint8_t red, grub_uint8_t green, grub_uint8_t blue)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return 0;
|
|
|
|
return grub_video_adapter_active->map_rgb (red, green, 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)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return 0;
|
|
|
|
return grub_video_adapter_active->map_rgba (red, green, blue, alpha);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_fill_rect (grub_video_color_t color, int x, int y,
|
|
unsigned int width, unsigned int height)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->fill_rect (color, x, y, width, height);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_blit_glyph (struct grub_font_glyph *glyph,
|
|
grub_video_color_t color, int x, int y)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->blit_glyph (glyph, color, x, 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)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->blit_bitmap (bitmap, x, y,
|
|
offset_x, offset_y,
|
|
width, height);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_blit_render_target (struct grub_video_render_target *target,
|
|
int x, int y, int offset_x, int offset_y,
|
|
unsigned int width, unsigned int height)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->blit_render_target (target, x, y,
|
|
offset_x, offset_y,
|
|
width, height);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_scroll (grub_video_color_t color, int dx, int dy)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->scroll (color, dx, dy);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_swap_buffers (void)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->swap_buffers ();
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_create_render_target (struct grub_video_render_target **result,
|
|
unsigned int width, unsigned int height,
|
|
unsigned int mode_type)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->create_render_target (result,
|
|
width, height,
|
|
mode_type);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_delete_render_target (struct grub_video_render_target *target)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->delete_render_target (target);
|
|
}
|
|
|
|
grub_err_t
|
|
grub_video_set_active_render_target (struct grub_video_render_target *target)
|
|
{
|
|
if (! grub_video_adapter_active)
|
|
return grub_error (GRUB_ERR_BAD_DEVICE, "No video mode activated");
|
|
|
|
return grub_video_adapter_active->set_active_render_target (target);
|
|
}
|
|
|
|
GRUB_MOD_INIT(video_video)
|
|
{
|
|
grub_video_adapter_active = 0;
|
|
grub_video_adapter_list = 0;
|
|
}
|
|
|
|
GRUB_MOD_FINI(video_video)
|
|
{
|
|
}
|