savagefb_accel.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*-*- linux-c -*-
  2. * linux/drivers/video/savage/savage_accel.c -- Hardware Acceleration
  3. *
  4. * Copyright (C) 2004 Antonino Daplas<adaplas@pol.net>
  5. * All Rights Reserved
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/string.h>
  13. #include <linux/fb.h>
  14. #include "savagefb.h"
  15. static u32 savagefb_rop[] = {
  16. 0xCC, /* ROP_COPY */
  17. 0x5A /* ROP_XOR */
  18. };
  19. int savagefb_sync(struct fb_info *info)
  20. {
  21. struct savagefb_par *par = info->par;
  22. par->SavageWaitIdle(par);
  23. return 0;
  24. }
  25. void savagefb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  26. {
  27. struct savagefb_par *par = info->par;
  28. int sx = region->sx, dx = region->dx;
  29. int sy = region->sy, dy = region->dy;
  30. int cmd;
  31. if (!region->width || !region->height)
  32. return;
  33. par->bci_ptr = 0;
  34. cmd = BCI_CMD_RECT | BCI_CMD_DEST_GBD | BCI_CMD_SRC_GBD;
  35. BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
  36. if (dx <= sx) {
  37. cmd |= BCI_CMD_RECT_XP;
  38. } else {
  39. sx += region->width - 1;
  40. dx += region->width - 1;
  41. }
  42. if (dy <= sy) {
  43. cmd |= BCI_CMD_RECT_YP;
  44. } else {
  45. sy += region->height - 1;
  46. dy += region->height - 1;
  47. }
  48. par->SavageWaitFifo(par,4);
  49. BCI_SEND(cmd);
  50. BCI_SEND(BCI_X_Y(sx, sy));
  51. BCI_SEND(BCI_X_Y(dx, dy));
  52. BCI_SEND(BCI_W_H(region->width, region->height));
  53. }
  54. void savagefb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  55. {
  56. struct savagefb_par *par = info->par;
  57. int cmd, color;
  58. if (!rect->width || !rect->height)
  59. return;
  60. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
  61. color = rect->color;
  62. else
  63. color = ((u32 *)info->pseudo_palette)[rect->color];
  64. cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
  65. BCI_CMD_DEST_GBD | BCI_CMD_SRC_SOLID |
  66. BCI_CMD_SEND_COLOR;
  67. par->bci_ptr = 0;
  68. BCI_CMD_SET_ROP(cmd, savagefb_rop[rect->rop]);
  69. par->SavageWaitFifo(par,4);
  70. BCI_SEND(cmd);
  71. BCI_SEND(color);
  72. BCI_SEND( BCI_X_Y(rect->dx, rect->dy) );
  73. BCI_SEND( BCI_W_H(rect->width, rect->height) );
  74. }
  75. void savagefb_imageblit(struct fb_info *info, const struct fb_image *image)
  76. {
  77. struct savagefb_par *par = info->par;
  78. int fg, bg, size, i, width;
  79. int cmd;
  80. u32 *src = (u32 *) image->data;
  81. if (!image->width || !image->height)
  82. return;
  83. if (image->depth != 1) {
  84. cfb_imageblit(info, image);
  85. return;
  86. }
  87. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  88. fg = image->fg_color;
  89. bg = image->bg_color;
  90. } else {
  91. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  92. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  93. }
  94. cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
  95. BCI_CMD_CLIP_LR | BCI_CMD_DEST_GBD | BCI_CMD_SRC_MONO |
  96. BCI_CMD_SEND_COLOR;
  97. par->bci_ptr = 0;
  98. BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
  99. width = (image->width + 31) & ~31;
  100. size = (width * image->height)/8;
  101. size >>= 2;
  102. par->SavageWaitFifo(par, size + 5);
  103. BCI_SEND(cmd);
  104. BCI_SEND(BCI_CLIP_LR(image->dx, image->dx + image->width - 1));
  105. BCI_SEND(fg);
  106. BCI_SEND(bg);
  107. BCI_SEND(BCI_X_Y(image->dx, image->dy));
  108. BCI_SEND(BCI_W_H(width, image->height));
  109. for (i = 0; i < size; i++)
  110. BCI_SEND(src[i]);
  111. }
  112. MODULE_LICENSE("GPL");