⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbe.c

📁 grub 1.95 linux 的bootloader 源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
          return;        }      *red = framebuffer.palette[color].r;      *green = framebuffer.palette[color].g;      *blue = framebuffer.palette[color].b;      *alpha = framebuffer.palette[color].a;      return;    }  else    {      grub_uint32_t tmp;      /* Get red component.  */      tmp = color >> mode_info->red_field_pos;      tmp &= (1 << mode_info->red_mask_size) - 1;      tmp <<= 8 - mode_info->red_mask_size;      tmp |= (1 << (8 - mode_info->red_mask_size)) - 1;      *red = tmp & 0xFF;      /* Get green component.  */      tmp = color >> mode_info->green_field_pos;      tmp &= (1 << mode_info->green_mask_size) - 1;      tmp <<= 8 - mode_info->green_mask_size;      tmp |= (1 << (8 - mode_info->green_mask_size)) - 1;      *green = tmp & 0xFF;      /* Get blue component.  */      tmp = color >> mode_info->blue_field_pos;      tmp &= (1 << mode_info->blue_mask_size) - 1;      tmp <<= 8 - mode_info->blue_mask_size;      tmp |= (1 << (8 - mode_info->blue_mask_size)) - 1;      *blue = tmp & 0xFF;      /* Get alpha component.  */      if (source->mode_info->reserved_mask_size > 0)        {          tmp = color >> mode_info->reserved_field_pos;          tmp &= (1 << mode_info->reserved_mask_size) - 1;          tmp <<= 8 - mode_info->reserved_mask_size;          tmp |= (1 << (8 - mode_info->reserved_mask_size)) - 1;        }      else        /* If there is no alpha component, assume it opaque.  */        tmp = 255;      *alpha = tmp & 0xFF;    }}static grub_err_tgrub_video_vbe_fill_rect (grub_video_color_t color, int x, int y,                          unsigned int width, unsigned int height){  struct grub_video_i386_vbeblit_info target;  /* Make sure there is something to do.  */  if ((x >= (int)render_target->viewport.width) || (x + (int)width < 0))    return GRUB_ERR_NONE;  if ((y >= (int)render_target->viewport.height) || (y + (int)height < 0))    return GRUB_ERR_NONE;  /* Do not allow drawing out of viewport.  */  if (x < 0)    {      width += x;      x = 0;    }  if (y < 0)    {      height += y;      y = 0;    }  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;  /* Add viewport offset.  */  x += render_target->viewport.x;  y += render_target->viewport.y;  /* Use vbeblit_info to encapsulate rendering.  */  target.mode_info = &render_target->mode_info;  target.data = render_target->data;  /* Try to figure out more optimized version.  */  if (target.mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)    {      grub_video_i386_vbefill_R8G8B8A8 (&target, color, x, y,                                         width, height);      return GRUB_ERR_NONE;    }  if (target.mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)    {      grub_video_i386_vbefill_R8G8B8 (&target, color, x, y,                                      width, height);      return GRUB_ERR_NONE;    }  if (target.mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)    {      grub_video_i386_vbefill_index (&target, color, x, y,                                     width, height);      return GRUB_ERR_NONE;    }  /* No optimized version found, use default (slow) filler.  */  grub_video_i386_vbefill (&target, color, x, y, width, height);  return GRUB_ERR_NONE;}// TODO: Remove this method and replace with bitmap based glyphsstatic grub_err_tgrub_video_vbe_blit_glyph (struct grub_font_glyph * glyph,                           grub_video_color_t color, int x, int y){  struct grub_video_i386_vbeblit_info target;  unsigned int width;  unsigned int charwidth;  unsigned int height;  unsigned int i;  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;  /* Calculate glyph dimensions.  */  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;  /* Do not allow drawing out of viewport.  */  if (x < 0)    {      width += x;      x_offset = (unsigned int)-x;      x = 0;    }  if (y < 0)    {      height += y;      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)    height = render_target->viewport.height - y;  /* Add viewport offset.  */  x += render_target->viewport.x;  y += render_target->viewport.y;  /* Use vbeblit_info to encapsulate rendering.  */  target.mode_info = &render_target->mode_info;  target.data = render_target->data;  /* Draw glyph.  */  for (j = 0; j < height; j++)    for (i = 0; i < width; i++)      if ((glyph->bitmap[((i + x_offset) / 8)                          + (j + y_offset) * (charwidth / 8)]            & (1 << ((charwidth - (i + x_offset) - 1) % 8))))        set_pixel (&target, x+i, y+j, color);  return GRUB_ERR_NONE;}/* NOTE: This function assumes that given coordiantes are within bounds of    handled data.  */static voidcommon_blitter (struct grub_video_i386_vbeblit_info *target,                struct grub_video_i386_vbeblit_info *source,                enum grub_video_blit_operators oper, int x, int y,                unsigned int width, unsigned int height,                int offset_x, int offset_y){  if (oper == GRUB_VIDEO_BLIT_REPLACE)    {      /* Try to figure out more optimized version for replace operator.  */      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)        {          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)            {              grub_video_i386_vbeblit_R8G8B8X8_R8G8B8X8 (target, source,                                                         x, y, width, height,                                                         offset_x, offset_y);              return;            }          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)            {              grub_video_i386_vbeblit_R8G8B8_R8G8B8X8 (target, source,                                                       x, y, width, height,                                                       offset_x, offset_y);              return;            }          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)            {              grub_video_i386_vbeblit_index_R8G8B8X8 (target, source,                                                      x, y, width, height,                                                      offset_x, offset_y);              return;            }        }      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)        {          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)            {              grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (target, source,                                                       x, y, width, height,                                                       offset_x, offset_y);              return;            }          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)            {              grub_video_i386_vbeblit_R8G8B8_R8G8B8 (target, source,                                                     x, y, width, height,                                                     offset_x, offset_y);              return;            }          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)            {              grub_video_i386_vbeblit_index_R8G8B8 (target, source,                                                    x, y, width, height,                                                    offset_x, offset_y);              return;            }        }      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)        {          if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)            {              grub_video_i386_vbeblit_index_index (target, source,                                                   x, y, width, height,                                                   offset_x, offset_y);              return;            }        }      /* No optimized replace operator found, use default (slow) blitter.  */      grub_video_i386_vbeblit_replace (target, source, x, y, width, height,                                       offset_x, offset_y);    }  else    {      /* Try to figure out more optimized blend operator.  */      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)      {        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)        {          grub_video_i386_vbeblit_R8G8B8A8_R8G8B8A8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)        {          grub_video_i386_vbeblit_R8G8B8_R8G8B8A8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)        {          grub_video_i386_vbeblit_index_R8G8B8A8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }      }      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)      {        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8A8)        {          grub_video_i386_vbeblit_R8G8B8A8_R8G8B8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_R8G8B8)        {          grub_video_i386_vbeblit_R8G8B8_R8G8B8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)        {          grub_video_i386_vbeblit_index_R8G8B8 (target, source,              x, y, width, height,              offset_x, offset_y);          return;        }      }      if (source->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)      {        if (target->mode_info->blit_format == GRUB_VIDEO_BLIT_FORMAT_INDEXCOLOR)        {          grub_video_i386_vbeblit_index_index (target, source,                                               x, y, width, height,                                               offset_x, offset_y);          return;        }      }      /* No optimized blend operation found, use default (slow) blitter.  */      grub_video_i386_vbeblit_blend (target, source, x, y, width, height,                                     offset_x, offset_y);    }}static grub_err_tgrub_video_vbe_blit_bitmap (struct grub_video_bitmap *bitmap,                            enum grub_video_blit_operators oper, int x, int y,                            int offset_x, int offset_y,                            unsigned int width, unsigned int height){  struct grub_video_i386_vbeblit_info source;  struct grub_video_i386_vbeblit_info target;  /* Make sure there is something to do.  */  if ((width == 0) || (height == 0))    return GRUB_ERR_NONE;  if ((x >= (int)render_target->viewport.width) || (x + (int)width < 0))    return GRUB_ERR_NONE;  if ((y >= (int)render_target->viewport.height) || (y + (int)height < 0))    return GRUB_ERR_NONE;  if ((x + (int)bitmap->mode_info.width) < 0)    return GRUB_ERR_NONE;  if ((y + (int)bitmap->mode_info.height) < 0)    return GRUB_ERR_NONE;  if ((offset_x >= (int)bitmap->mode_info.width)       || (offset_x + (int)width < 0))    return GRUB_ERR_NONE;  if ((offset_y >= (int)bitmap->mode_info.height)       || (offset_y + (int)height < 0))    return GRUB_ERR_NONE;  /* If we have negative coordinates, optimize drawing to minimum.  */  if (offset_x < 0)    {      width += offset_x;      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 -= x;      x = 0;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -