1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/*
* Copyright 2005 Eric Anholt
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors:
* Eric Anholt <anholt@FreeBSD.org>
*
*/
#include "sis_context.h"
#include "sis_state.h"
#include "sis_lock.h"
#include "sis_reg.h"
#include "swrast/swrast.h"
#include "macros.h"
static void sis_clear_front_buffer(GLcontext *ctx, GLenum mask, GLint x,
GLint y, GLint width, GLint height);
static void sis_clear_back_buffer(GLcontext *ctx, GLenum mask, GLint x,
GLint y, GLint width, GLint height);
static void sis_clear_z_buffer(GLcontext * ctx, GLbitfield mask, GLint x,
GLint y, GLint width, GLint height );
static void
set_color_pattern( sisContextPtr smesa, GLubyte red, GLubyte green,
GLubyte blue, GLubyte alpha )
{
/* XXX only RGB565 and ARGB8888 */
switch (smesa->colorFormat)
{
case DST_FORMAT_ARGB_8888:
smesa->clearColorPattern = (alpha << 24) +
(red << 16) + (green << 8) + (blue);
break;
case DST_FORMAT_RGB_565:
smesa->clearColorPattern = ((red >> 3) << 11) +
((green >> 2) << 5) + (blue >> 3);
smesa->clearColorPattern |= smesa->clearColorPattern << 16;
break;
default:
sis_fatal_error("Bad dst color format\n");
}
}
void
sis6326UpdateZPattern(sisContextPtr smesa, GLclampd z)
{
CLAMPED_FLOAT_TO_USHORT(smesa->clearZStencilPattern, z * 65535.0);
}
void
sis6326DDClear(GLcontext *ctx, GLbitfield mask)
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
GLint x1, y1, width1, height1;
/* get region after locking: */
x1 = ctx->DrawBuffer->_Xmin;
y1 = ctx->DrawBuffer->_Ymin;
width1 = ctx->DrawBuffer->_Xmax - x1;
height1 = ctx->DrawBuffer->_Ymax - y1;
y1 = Y_FLIP(y1 + height1 - 1);
/* XXX: Scissoring */
fprintf(stderr, "Clear\n");
/* Mask out any non-existent buffers */
if (smesa->depth.offset == 0 || !ctx->Depth.Mask)
mask &= ~BUFFER_BIT_DEPTH;
LOCK_HARDWARE();
if (mask & BUFFER_BIT_FRONT_LEFT) {
sis_clear_front_buffer(ctx, mask, x1, y1, width1, height1);
mask &= ~BUFFER_BIT_FRONT_LEFT;
}
if (mask & BUFFER_BIT_BACK_LEFT) {
sis_clear_back_buffer(ctx, mask, x1, y1, width1, height1);
mask &= ~BUFFER_BIT_BACK_LEFT;
}
if (mask & BUFFER_BIT_DEPTH) {
sis_clear_z_buffer(ctx, mask, x1, y1, width1, height1);
mask &= ~BUFFER_BIT_DEPTH;
}
UNLOCK_HARDWARE();
if (mask != 0)
_swrast_Clear(ctx, mask);
}
void
sis6326DDClearColor(GLcontext *ctx, const GLfloat color[4])
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
GLubyte c[4];
CLAMPED_FLOAT_TO_UBYTE(c[0], color[0]);
CLAMPED_FLOAT_TO_UBYTE(c[1], color[1]);
CLAMPED_FLOAT_TO_UBYTE(c[2], color[2]);
CLAMPED_FLOAT_TO_UBYTE(c[3], color[3]);
set_color_pattern( smesa, c[0], c[1], c[2], c[3] );
}
void
sis6326DDClearDepth(GLcontext *ctx, GLclampd d)
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
sis6326UpdateZPattern(smesa, d);
}
static void
sis_clear_back_buffer(GLcontext *ctx, GLenum mask, GLint x, GLint y,
GLint width, GLint height)
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
/* XXX: The order of writing these registers seems to matter, while
* it actually shouldn't.
*/
mWait3DCmdQueue(6);
MMIO(REG_6326_BitBlt_DstSrcPitch, smesa->back.pitch << 16);
MMIO(REG_6326_BitBlt_fgColor, SiS_ROP_PATCOPY |
smesa->clearColorPattern);
MMIO(REG_6326_BitBlt_bgColor, SiS_ROP_PATCOPY |
smesa->clearColorPattern);
MMIO(REG_6326_BitBlt_DstAddr, smesa->back.offset +
(y+height) * smesa->back.pitch +
(x+width) * smesa->bytesPerPixel);
MMIO(REG_6326_BitBlt_HeightWidth, ((height-1) << 16) |
(width * smesa->bytesPerPixel));
MMIO_WMB();
MMIO(REG_6326_BitBlt_Cmd, BLT_PAT_BG);
}
static void
sis_clear_front_buffer(GLcontext *ctx, GLenum mask, GLint x, GLint y,
GLint width, GLint height)
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
int count;
drm_clip_rect_t *pExtents = NULL;
pExtents = smesa->driDrawable->pClipRects;
count = smesa->driDrawable->numClipRects;
mWait3DCmdQueue(3);
MMIO(REG_6326_BitBlt_DstSrcPitch, smesa->front.pitch << 16);
MMIO(REG_6326_BitBlt_fgColor, SiS_ROP_PATCOPY |
smesa->clearColorPattern);
MMIO(REG_6326_BitBlt_bgColor, SiS_ROP_PATCOPY |
smesa->clearColorPattern);
while (count--) {
GLint x1 = pExtents->x1 - smesa->driDrawable->x;
GLint y1 = pExtents->y1 - smesa->driDrawable->y;
GLint x2 = pExtents->x2 - smesa->driDrawable->x;
GLint y2 = pExtents->y2 - smesa->driDrawable->y;
if (x > x1)
x1 = x;
if (y > y1)
y1 = y;
if (x + width < x2)
x2 = x + width;
if (y + height < y2)
y2 = y + height;
width = x2 - x1;
height = y2 - y1;
pExtents++;
if (width <= 0 || height <= 0)
continue;
mWait3DCmdQueue(3);
MMIO(REG_6326_BitBlt_DstAddr, smesa->front.offset +
(y2-1) * smesa->front.pitch + x2 * smesa->bytesPerPixel);
MMIO(REG_6326_BitBlt_HeightWidth, ((height-1) << 16) |
(width * smesa->bytesPerPixel));
MMIO_WMB();
MMIO(REG_6326_BitBlt_Cmd, BLT_PAT_BG);
}
}
static void
sis_clear_z_buffer(GLcontext * ctx, GLbitfield mask, GLint x, GLint y,
GLint width, GLint height)
{
sisContextPtr smesa = SIS_CONTEXT(ctx);
mWait3DCmdQueue(6);
MMIO(REG_6326_BitBlt_DstAddr,
smesa->depth.offset + y * smesa->depth.pitch + x * 2);
MMIO(REG_6326_BitBlt_DstSrcPitch, smesa->depth.pitch << 16);
MMIO(REG_6326_BitBlt_HeightWidth, ((height-1) << 16) | (width * 2));
MMIO(REG_6326_BitBlt_fgColor, SiS_ROP_PATCOPY | smesa->clearZStencilPattern);
MMIO(REG_6326_BitBlt_bgColor, SiS_ROP_PATCOPY | smesa->clearZStencilPattern);
MMIO_WMB();
MMIO(REG_6326_BitBlt_Cmd, BLT_PAT_BG | BLT_XINC | BLT_YINC);
}
|