savagefb_accel.c 3.2 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 <linux/module.h>
  15. #include "savagefb.h"
  16. static u32 savagefb_rop[] = {
  17. 0xCC, /* ROP_COPY */
  18. 0x5A /* ROP_XOR */
  19. };
  20. int savagefb_sync(struct fb_info *info)
  21. {
  22. struct savagefb_par *par = info->par;
  23. par->SavageWaitIdle(par);
  24. return 0;
  25. }
  26. void savagefb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
  27. {
  28. struct savagefb_par *par = info->par;
  29. int sx = region->sx, dx = region->dx;
  30. int sy = region->sy, dy = region->dy;
  31. int cmd;
  32. if (!region->width || !region->height)
  33. return;
  34. par->bci_ptr = 0;
  35. cmd = BCI_CMD_RECT | BCI_CMD_DEST_GBD | BCI_CMD_SRC_GBD;
  36. BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
  37. if (dx <= sx) {
  38. cmd |= BCI_CMD_RECT_XP;
  39. } else {
  40. sx += region->width - 1;
  41. dx += region->width - 1;
  42. }
  43. if (dy <= sy) {
  44. cmd |= BCI_CMD_RECT_YP;
  45. } else {
  46. sy += region->height - 1;
  47. dy += region->height - 1;
  48. }
  49. par->SavageWaitFifo(par,4);
  50. BCI_SEND(cmd);
  51. BCI_SEND(BCI_X_Y(sx, sy));
  52. BCI_SEND(BCI_X_Y(dx, dy));
  53. BCI_SEND(BCI_W_H(region->width, region->height));
  54. }
  55. void savagefb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
  56. {
  57. struct savagefb_par *par = info->par;
  58. int cmd, color;
  59. if (!rect->width || !rect->height)
  60. return;
  61. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
  62. color = rect->color;
  63. else
  64. color = ((u32 *)info->pseudo_palette)[rect->color];
  65. cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
  66. BCI_CMD_DEST_GBD | BCI_CMD_SRC_SOLID |
  67. BCI_CMD_SEND_COLOR;
  68. par->bci_ptr = 0;
  69. BCI_CMD_SET_ROP(cmd, savagefb_rop[rect->rop]);
  70. par->SavageWaitFifo(par,4);
  71. BCI_SEND(cmd);
  72. BCI_SEND(color);
  73. BCI_SEND( BCI_X_Y(rect->dx, rect->dy) );
  74. BCI_SEND( BCI_W_H(rect->width, rect->height) );
  75. }
  76. void savagefb_imageblit(struct fb_info *info, const struct fb_image *image)
  77. {
  78. struct savagefb_par *par = info->par;
  79. int fg, bg, size, i, width;
  80. int cmd;
  81. u32 *src = (u32 *) image->data;
  82. if (!image->width || !image->height)
  83. return;
  84. if (image->depth != 1) {
  85. cfb_imageblit(info, image);
  86. return;
  87. }
  88. if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
  89. fg = image->fg_color;
  90. bg = image->bg_color;
  91. } else {
  92. fg = ((u32 *)info->pseudo_palette)[image->fg_color];
  93. bg = ((u32 *)info->pseudo_palette)[image->bg_color];
  94. }
  95. cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP |
  96. BCI_CMD_CLIP_LR | BCI_CMD_DEST_GBD | BCI_CMD_SRC_MONO |
  97. BCI_CMD_SEND_COLOR;
  98. par->bci_ptr = 0;
  99. BCI_CMD_SET_ROP(cmd, savagefb_rop[0]);
  100. width = (image->width + 31) & ~31;
  101. size = (width * image->height)/8;
  102. size >>= 2;
  103. par->SavageWaitFifo(par, size + 5);
  104. BCI_SEND(cmd);
  105. BCI_SEND(BCI_CLIP_LR(image->dx, image->dx + image->width - 1));
  106. BCI_SEND(fg);
  107. BCI_SEND(bg);
  108. BCI_SEND(BCI_X_Y(image->dx, image->dy));
  109. BCI_SEND(BCI_W_H(width, image->height));
  110. for (i = 0; i < size; i++)
  111. BCI_SEND(src[i]);
  112. }
  113. MODULE_LICENSE("GPL");