diff --git a/include/grub/fbfill.h b/include/grub/fbfill.h index 08cd7b8..11e22c6 100644 --- a/include/grub/fbfill.h +++ b/include/grub/fbfill.h @@ -24,29 +24,6 @@ struct grub_video_fbblit_info; -struct grub_video_fbrender_target -{ - /* Copy of the screen's mode info structure, except that width, height and - mode_type has been re-adjusted to requested render target settings. */ - struct grub_video_mode_info mode_info; - - struct - { - unsigned int x; - unsigned int y; - unsigned int width; - unsigned int height; - } viewport; - - /* Indicates whether 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; -}; - void grub_video_fbfill (struct grub_video_fbblit_info *dst, grub_video_color_t color, int x, int y, diff --git a/include/grub/fbutil.h b/include/grub/fbutil.h index 76e1e57..fc1e885 100644 --- a/include/grub/fbutil.h +++ b/include/grub/fbutil.h @@ -25,13 +25,36 @@ #include #include +struct grub_video_fbrender_target +{ + /* Copy of the screen's mode info structure, except that width, height and + mode_type has been re-adjusted to requested render target settings. */ + struct grub_video_mode_info mode_info; + + struct + { + unsigned int x; + unsigned int y; + unsigned int width; + unsigned int height; + } viewport; + + /* Indicates whether 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; +}; + struct grub_video_fbblit_info { struct grub_video_mode_info *mode_info; void *data; }; -grub_uint8_t *get_data_ptr (struct grub_video_fbblit_info *source, +grub_uint8_t *grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source, unsigned int x, unsigned int y); grub_video_color_t get_pixel (struct grub_video_fbblit_info *source, diff --git a/include/grub/video_fb.h b/include/grub/video_fb.h index 03ef385..17debd6 100644 --- a/include/grub/video_fb.h +++ b/include/grub/video_fb.h @@ -33,9 +33,6 @@ struct grub_video_fbrender_target; #define GRUB_VIDEO_FBSTD_NUMCOLORS 16 extern struct grub_video_palette_data grub_video_fbstd_colors[GRUB_VIDEO_FBSTD_NUMCOLORS]; -grub_uint8_t * grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source, - grub_uint32_t x, grub_uint32_t y); - grub_err_t grub_video_fb_init (void); diff --git a/video/fb/fbblit.c b/video/fb/fbblit.c index 138eba8..5b613bc 100644 --- a/video/fb/fbblit.c +++ b/video/fb/fbblit.c @@ -83,8 +83,8 @@ grub_video_fbblit_replace_directN (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (dst, x, y + j); grub_memmove (dstptr, srcptr, width * bpp); } @@ -110,8 +110,8 @@ grub_video_fbblit_replace_BGRX8888_RGBX8888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint8_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint8_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -153,8 +153,8 @@ grub_video_fbblit_replace_BGRX8888_RGB888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint8_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint8_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -197,8 +197,8 @@ grub_video_fbblit_replace_BGR888_RGBX8888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint32_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint8_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint32_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -245,8 +245,8 @@ grub_video_fbblit_replace_BGR888_RGB888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint8_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint8_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -285,8 +285,8 @@ grub_video_fbblit_replace_RGBX8888_RGB888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -321,8 +321,8 @@ grub_video_fbblit_replace_RGB888_RGBX8888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -358,8 +358,8 @@ grub_video_fbblit_replace_index_RGBX8888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -394,8 +394,8 @@ grub_video_fbblit_replace_index_RGB888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint8_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -491,8 +491,8 @@ grub_video_fbblit_blend_BGRA8888_RGBA8888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint32_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint32_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint32_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint32_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -572,8 +572,8 @@ grub_video_fbblit_blend_BGR888_RGBA8888 (struct grub_video_fbblit_info *dst, srcrowskip = src->mode_info->pitch - src->mode_info->bytes_per_pixel * width; dstrowskip = dst->mode_info->pitch - dst->mode_info->bytes_per_pixel * width; - srcptr = (grub_uint32_t *) get_data_ptr (src, offset_x, offset_y); - dstptr = (grub_uint8_t *) get_data_ptr (dst, x, y); + srcptr = (grub_uint32_t *) grub_video_fb_get_video_ptr (src, offset_x, offset_y); + dstptr = (grub_uint8_t *) grub_video_fb_get_video_ptr (dst, x, y); for (j = 0; j < height; j++) { @@ -656,8 +656,8 @@ grub_video_fbblit_blend_RGBA8888_RGBA8888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint32_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -721,8 +721,8 @@ grub_video_fbblit_blend_RGB888_RGBA8888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { @@ -788,8 +788,8 @@ grub_video_fbblit_blend_index_RGBA8888 (struct grub_video_fbblit_info *dst, for (j = 0; j < height; j++) { - srcptr = (grub_uint32_t *)get_data_ptr (src, offset_x, j + offset_y); - dstptr = (grub_uint8_t *)get_data_ptr (dst, x, y + j); + srcptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (src, offset_x, j + offset_y); + dstptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (dst, x, y + j); for (i = 0; i < width; i++) { diff --git a/video/fb/fbutil.c b/video/fb/fbutil.c index 09cbb12..1fa48ec 100644 --- a/video/fb/fbutil.c +++ b/video/fb/fbutil.c @@ -16,12 +16,23 @@ * along with GRUB. If not, see . */ +/* SPECIAL NOTES! + + Please note following when reading the code below: + + - In this driver we assume that every memory can be accessed by same memory + bus. If there are different address spaces do not use this code as a base + code for other archs. + + - Every function in this code assumes that bounds checking has been done in + previous phase and they are opted out in here. */ + #include #include #include grub_uint8_t * -get_data_ptr (struct grub_video_fbblit_info *source, +grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source, unsigned int x, unsigned int y) { grub_uint8_t *ptr = 0; @@ -72,24 +83,24 @@ get_pixel (struct grub_video_fbblit_info *source, switch (source->mode_info->bpp) { case 32: - color = *(grub_uint32_t *)get_data_ptr (source, x, y); + color = *(grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y); break; case 24: { grub_uint8_t *ptr; - ptr = get_data_ptr (source, x, y); + ptr = grub_video_fb_get_video_ptr (source, x, y); color = ptr[0] | (ptr[1] << 8) | (ptr[2] << 16); } break; case 16: case 15: - color = *(grub_uint16_t *)get_data_ptr (source, x, y); + color = *(grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y); break; case 8: - color = *(grub_uint8_t *)get_data_ptr (source, x, y); + color = *(grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y); break; case 1: @@ -120,7 +131,7 @@ set_pixel (struct grub_video_fbblit_info *source, { grub_uint32_t *ptr; - ptr = (grub_uint32_t *)get_data_ptr (source, x, y); + ptr = (grub_uint32_t *)grub_video_fb_get_video_ptr (source, x, y); *ptr = color; } @@ -131,7 +142,7 @@ set_pixel (struct grub_video_fbblit_info *source, grub_uint8_t *ptr; grub_uint8_t *colorptr = (grub_uint8_t *)&color; - ptr = get_data_ptr (source, x, y); + ptr = grub_video_fb_get_video_ptr (source, x, y); ptr[0] = colorptr[0]; ptr[1] = colorptr[1]; @@ -144,7 +155,7 @@ set_pixel (struct grub_video_fbblit_info *source, { grub_uint16_t *ptr; - ptr = (grub_uint16_t *)get_data_ptr (source, x, y); + ptr = (grub_uint16_t *)grub_video_fb_get_video_ptr (source, x, y); *ptr = (grub_uint16_t) (color & 0xFFFF); } @@ -154,7 +165,7 @@ set_pixel (struct grub_video_fbblit_info *source, { grub_uint8_t *ptr; - ptr = (grub_uint8_t *)get_data_ptr (source, x, y); + ptr = (grub_uint8_t *)grub_video_fb_get_video_ptr (source, x, y); *ptr = (grub_uint8_t) (color & 0xFF); } diff --git a/video/fb/video_fb.c b/video/fb/video_fb.c index a9cd76b..902e683 100644 --- a/video/fb/video_fb.c +++ b/video/fb/video_fb.c @@ -83,44 +83,6 @@ grub_video_fb_get_info (struct grub_video_mode_info *mode_info) return GRUB_ERR_NONE; } - -grub_uint8_t * -grub_video_fb_get_video_ptr (struct grub_video_fbblit_info *source, - grub_uint32_t x, grub_uint32_t y) -{ - grub_uint8_t *ptr = 0; - - switch (source->mode_info->bpp) - { - case 32: - ptr = (grub_uint8_t *)source->data - + y * source->mode_info->pitch - + x * 4; - break; - - case 24: - ptr = (grub_uint8_t *)source->data - + y * source->mode_info->pitch - + x * 3; - break; - - case 16: - case 15: - ptr = (grub_uint8_t *)source->data - + y * source->mode_info->pitch - + x * 2; - break; - - case 8: - ptr = (grub_uint8_t *)source->data - + y * source->mode_info->pitch - + x; - break; - } - - return ptr; -} - grub_err_t grub_video_fb_get_palette (unsigned int start, unsigned int count, struct grub_video_palette_data *palette_data) @@ -1105,12 +1067,9 @@ grub_video_fb_create_render_target_from_pointer (struct grub_video_fbrender_targ target->viewport.width = mode_info->width; target->viewport.height = mode_info->height; - /* Mark framebuffer memory as non allocated. */ - target->is_allocated = 0; - /* Clear render target with black and maximum transparency. */ for (y = 0; y < mode_info->height; y++) - grub_memset (target->data + mode_info->pitch * y, 0, + grub_memset ((char *) target->data + mode_info->pitch * y, 0, mode_info->bytes_per_pixel * mode_info->width); /* Save result to caller. */ diff --git a/video/i386/pc/vbe.c b/video/i386/pc/vbe.c index b3fe4d6..27ea08e 100644 --- a/video/i386/pc/vbe.c +++ b/video/i386/pc/vbe.c @@ -364,7 +364,7 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, unsigned int mode_type) { grub_uint16_t *p; - struct grub_vbe_mode_info_block mode_info; + struct grub_vbe_mode_info_block vbe_mode_info; struct grub_vbe_mode_info_block best_mode_info; grub_uint32_t best_mode = 0; int depth; @@ -378,7 +378,7 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, { grub_uint32_t mode = *p; - grub_vbe_get_video_mode_info (mode, &mode_info); + grub_vbe_get_video_mode_info (mode, &vbe_mode_info); if (grub_errno != GRUB_ERR_NONE) { /* Could not retrieve mode info, retreat. */ @@ -386,33 +386,33 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, break; } - if ((mode_info.mode_attributes & 0x001) == 0) + if ((vbe_mode_info.mode_attributes & 0x001) == 0) /* If not available, skip it. */ continue; - if ((mode_info.mode_attributes & 0x002) == 0) + if ((vbe_mode_info.mode_attributes & 0x002) == 0) /* Not enough information. */ continue; - if ((mode_info.mode_attributes & 0x008) == 0) + if ((vbe_mode_info.mode_attributes & 0x008) == 0) /* Monochrome is unusable. */ continue; - if ((mode_info.mode_attributes & 0x080) == 0) + if ((vbe_mode_info.mode_attributes & 0x080) == 0) /* We support only linear frame buffer modes. */ continue; - if ((mode_info.mode_attributes & 0x010) == 0) + if ((vbe_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)) + if ((vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL) + && (vbe_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)) + if ((vbe_mode_info.x_resolution != width) + || (vbe_mode_info.y_resolution != height)) /* Non matching resolution. */ continue; @@ -420,28 +420,28 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, if ((mode_type & GRUB_VIDEO_MODE_TYPE_COLOR_MASK) != 0) { if (((mode_type & GRUB_VIDEO_MODE_TYPE_INDEX_COLOR) != 0) - && (mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)) + && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_PACKED_PIXEL)) /* Requested only index color modes. */ continue; if (((mode_type & GRUB_VIDEO_MODE_TYPE_RGB) != 0) - && (mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)) + && (vbe_mode_info.memory_model != GRUB_VBE_MEMORY_MODEL_DIRECT_COLOR)) /* Requested only RGB modes. */ continue; } /* If there is a request for specific depth, ignore others. */ - if ((depth != 0) && (mode_info.bits_per_pixel != depth)) + if ((depth != 0) && (vbe_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) + if (vbe_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)); + grub_memcpy (&best_mode_info, &vbe_mode_info, sizeof (vbe_mode_info)); } /* Try to initialize best mode found. */ @@ -482,18 +482,18 @@ grub_video_vbe_setup (unsigned int width, unsigned int height, framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); - /* Copy default palette to initialize emulated palette. */ - err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, - grub_video_fbstd_colors); + 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_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr); - + err = grub_video_fb_set_active_render_target (framebuffer.render_target); if (err) return err; - return grub_video_fb_set_active_render_target (framebuffer.render_target); + /* Copy default palette to initialize emulated palette. */ + return grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS, + grub_video_fbstd_colors); } /* Couldn't found matching mode. */