xref: /haiku/src/add-ons/accelerants/s3/savage_draw.cpp (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 /*
2 	Haiku S3 Savage driver adapted from the X.org Savage driver.
3 
4 	Copyright (C) 1994-2000 The XFree86 Project, Inc.  All Rights Reserved.
5 	Copyright (c) 2003-2006, X.Org Foundation
6 
7 	Copyright 2007-2008 Haiku, Inc.  All rights reserved.
8 	Distributed under the terms of the MIT license.
9 
10 	Authors:
11 	Gerald Zajac 2006-2008
12 */
13 
14 
15 #include "accel.h"
16 #include "savage.h"
17 
18 
19 
20 void
21 Savage_FillRectangle(engine_token *et, uint32 color, fill_rect_params *pList, uint32 count)
22 {
23 	int cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
24 			| BCI_CMD_DEST_PBD_NEW | BCI_CMD_SRC_SOLID | BCI_CMD_SEND_COLOR;
25 
26 	(void)et;		// avoid compiler warning for unused arg
27 
28 	BCI_CMD_SET_ROP(cmd, 0xF0);		// use GXcopy for rop
29 
30 	while (count--) {
31 		int x = pList->left;
32 		int y = pList->top;
33 		int w = pList->right - x + 1;
34 		int h = pList->bottom - y + 1;
35 
36 		BCI_GET_PTR;
37 
38 		gInfo.WaitQueue(7);
39 
40 		BCI_SEND(cmd);
41 		BCI_SEND(gInfo.sharedInfo->frameBufferOffset);
42 		BCI_SEND(gInfo.sharedInfo->globalBitmapDesc);
43 
44 		BCI_SEND(color);
45 		BCI_SEND(BCI_X_Y(x, y));
46 		BCI_SEND(BCI_W_H(w, h));
47 
48 		pList++;
49 	}
50 }
51 
52 
53 void
54 Savage_FillSpan(engine_token *et, uint32 color, uint16 *pList, uint32 count)
55 {
56 	int cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
57 			| BCI_CMD_DEST_PBD_NEW | BCI_CMD_SRC_SOLID | BCI_CMD_SEND_COLOR;
58 
59 	(void)et;		// avoid compiler warning for unused arg
60 
61 	BCI_CMD_SET_ROP(cmd, 0xF0);		// use GXcopy for rop
62 
63 	while (count--) {
64 		int y = *pList++;
65 		int x = *pList++;
66 		int w = *pList++ - x + 1;
67 
68 		BCI_GET_PTR;
69 
70 		// The MediaPlayer in Zeta 1.21 displays a window which has 2 zero width
71 		// spans which the Savage chips display as a line completely across the
72 		// screen;  thus, the following if statement discards any span with zero
73 		// or negative width.
74 
75 		if (w <= 0)
76 			continue;
77 
78 		gInfo.WaitQueue(7);
79 
80 		BCI_SEND(cmd);
81 		BCI_SEND(gInfo.sharedInfo->frameBufferOffset);
82 		BCI_SEND(gInfo.sharedInfo->globalBitmapDesc);
83 
84 		BCI_SEND(color);
85 		BCI_SEND(BCI_X_Y(x, y));
86 		BCI_SEND(BCI_W_H(w, 1));
87 	}
88 }
89 
90 
91 void
92 Savage_InvertRectangle(engine_token *et, fill_rect_params *pList, uint32 count)
93 {
94 	int cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP
95 			| BCI_CMD_DEST_PBD_NEW;
96 
97 	(void)et;		// avoid compiler warning for unused arg
98 
99 	BCI_CMD_SET_ROP(cmd, 0x55);		// use GXinvert for rop
100 
101 	while (count--) {
102 		int x = pList->left;
103 		int y = pList->top;
104 		int w = pList->right - x + 1;
105 		int h = pList->bottom - y + 1;
106 
107 		BCI_GET_PTR;
108 
109 		gInfo.WaitQueue(7);
110 
111 		BCI_SEND(cmd);
112 		BCI_SEND(gInfo.sharedInfo->frameBufferOffset);
113 		BCI_SEND(gInfo.sharedInfo->globalBitmapDesc);
114 
115 		BCI_SEND(BCI_X_Y(x, y));
116 		BCI_SEND(BCI_W_H(w, h));
117 
118 		pList++;
119 	}
120 }
121 
122 
123 void
124 Savage_ScreenToScreenBlit(engine_token *et, blit_params *pList, uint32 count)
125 {
126 	(void)et;		// avoid compiler warning for unused arg
127 
128 	while (count--) {
129 		int cmd;
130 		int src_x = pList->src_left;
131 		int src_y = pList->src_top;
132 		int dest_x = pList->dest_left;
133 		int dest_y = pList->dest_top;
134 		int width = pList->width;
135 		int height = pList->height;
136 
137 		BCI_GET_PTR;
138 
139 		cmd = BCI_CMD_RECT | BCI_CMD_DEST_PBD_NEW | BCI_CMD_SRC_SBD_COLOR_NEW;
140 		BCI_CMD_SET_ROP(cmd, 0xCC);		// use GXcopy for rop
141 
142 		if (dest_x <= src_x) {
143 			cmd |= BCI_CMD_RECT_XP;
144 		} else {
145 			src_x += width;
146 			dest_x += width;
147 		}
148 
149 		if (dest_y <= src_y) {
150 			cmd |= BCI_CMD_RECT_YP;
151 		} else {
152 			src_y += height;
153 			dest_y += height;
154 		}
155 
156 		gInfo.WaitQueue(9);
157 
158 		BCI_SEND(cmd);
159 
160 		BCI_SEND(gInfo.sharedInfo->frameBufferOffset);
161 		BCI_SEND(gInfo.sharedInfo->globalBitmapDesc);
162 
163 		BCI_SEND(gInfo.sharedInfo->frameBufferOffset);
164 		BCI_SEND(gInfo.sharedInfo->globalBitmapDesc);
165 
166 		BCI_SEND(BCI_X_Y(src_x, src_y));
167 		BCI_SEND(BCI_X_Y(dest_x, dest_y));
168 		BCI_SEND(BCI_W_H(width + 1, height + 1));
169 
170 		pList++;
171 	}
172 }
173 
174