grub/grub-core/video/capture.c
Vladimir Testov 4db2250000 * grub-core/gfxmenu/gui_box.c: Updated to work with area status.
* grub-core/gfxmenu/gui_canvas.c: Likewise.
        * grub-core/gfxmenu/view.c: Likewise.
        * grub-core/video/fb/video_fb.c: Introduce new functions:
        grub_video_set_area_status, grub_video_get_area_status,
        grub_video_set_region, grub_video_get_region.
        * grub-core/video/bochs.c: Likewise.
        * grub-core/video/capture.c: Likewise.
        * grub-core/video/video.c: Likewise.
        * grub-core/video/cirrus.c: Likewise.
        * grub-core/video/efi_gop.c: Likewise.
        * grub-core/video/efi_uga.c: Likewise.
        * grub-core/video/emu/sdl.c: Likewise.
        * grub-core/video/radeon_fuloong2e.c: Likewise.
        * grub-core/video/sis315pro.c: Likewise.
        * grub-core/video/sm712.c: Likewise.
        * grub-core/video/i386/pc/vbe.c: Likewise.
        * grub-core/video/i386/pc/vga.c: Likewise.
        * grub-core/video/ieee1275.c: Likewise.
        * grub-core/video/i386/coreboot/cbfb.c: Likewise.
        * include/grub/video.h: Likewise.
        * include/grub/video_fb.h: Likewise.
        * include/grub/fbfill.h: Updated render_target structure.
        grub_video_rect_t viewport, region, area
        int area_offset_x, area_offset_y, area_enabled
        * include/grub/gui.h: New helper function
        grub_video_bounds_inside_region.
        * docs/grub-dev.texi: Added information about new functions.
2013-11-08 15:42:38 +04:00

139 lines
3.7 KiB
C

#define grub_video_render_target grub_video_fbrender_target
#include <grub/video.h>
#include <grub/video_fb.h>
#include <grub/mm.h>
static struct
{
struct grub_video_mode_info mode_info;
struct grub_video_render_target *render_target;
grub_uint8_t *ptr;
} framebuffer;
void (*grub_video_capture_refresh_cb) (void);
static grub_err_t
grub_video_capture_swap_buffers (void)
{
if (grub_video_capture_refresh_cb)
grub_video_capture_refresh_cb ();
return GRUB_ERR_NONE;
}
static grub_err_t
grub_video_capture_set_active_render_target (struct grub_video_render_target *target)
{
if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
target = framebuffer.render_target;
return grub_video_fb_set_active_render_target (target);
}
static grub_err_t
grub_video_capture_fini (void)
{
return GRUB_ERR_NONE;
}
static struct grub_video_adapter grub_video_capture_adapter =
{
.name = "Render capture",
.prio = 0,
.id = GRUB_VIDEO_ADAPTER_CAPTURE,
.fini = grub_video_capture_fini,
.get_info = grub_video_fb_get_info,
.get_info_and_fini = 0,
.set_palette = grub_video_fb_set_palette,
.get_palette = grub_video_fb_get_palette,
.set_viewport = grub_video_fb_set_viewport,
.get_viewport = grub_video_fb_get_viewport,
.set_region = grub_video_fb_set_region,
.get_region = grub_video_fb_get_region,
.set_area_status = grub_video_fb_set_area_status,
.get_area_status = grub_video_fb_get_area_status,
.map_color = grub_video_fb_map_color,
.map_rgb = grub_video_fb_map_rgb,
.map_rgba = grub_video_fb_map_rgba,
.unmap_color = grub_video_fb_unmap_color,
.fill_rect = grub_video_fb_fill_rect,
.blit_bitmap = grub_video_fb_blit_bitmap,
.blit_render_target = grub_video_fb_blit_render_target,
.scroll = grub_video_fb_scroll,
.swap_buffers = grub_video_capture_swap_buffers,
.create_render_target = grub_video_fb_create_render_target,
.delete_render_target = grub_video_fb_delete_render_target,
.set_active_render_target = grub_video_capture_set_active_render_target,
.get_active_render_target = grub_video_fb_get_active_render_target,
.next = 0
};
static struct grub_video_adapter *saved;
static struct grub_video_mode_info saved_mode_info;
grub_err_t
grub_video_capture_start (const struct grub_video_mode_info *mode_info,
struct grub_video_palette_data *palette,
unsigned int palette_size)
{
grub_err_t err;
grub_memset (&framebuffer, 0, sizeof (framebuffer));
grub_video_fb_init ();
framebuffer.mode_info = *mode_info;
framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info);
framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch);
if (!framebuffer.ptr)
return grub_errno;
err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target,
&framebuffer.mode_info,
framebuffer.ptr);
if (err)
return err;
err = grub_video_fb_set_active_render_target (framebuffer.render_target);
if (err)
return err;
err = grub_video_fb_set_palette (0, palette_size, palette);
if (err)
return err;
saved = grub_video_adapter_active;
if (saved)
{
grub_video_get_info (&saved_mode_info);
if (saved->fini)
saved->fini ();
}
grub_video_adapter_active = &grub_video_capture_adapter;
return GRUB_ERR_NONE;
}
void *
grub_video_capture_get_framebuffer (void)
{
return framebuffer.ptr;
}
void
grub_video_capture_end (void)
{
grub_video_fb_delete_render_target (framebuffer.render_target);
grub_free (framebuffer.ptr);
grub_video_fb_fini ();
grub_video_adapter_active = saved;
if (saved)
{
if (saved->init)
saved->init ();
if (saved->setup)
saved->setup (saved_mode_info.width, saved_mode_info.height, 0, 0);
}
}