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