1 /**************************************************************************
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
5 The Weather Channel (TM) funded Tungsten Graphics to develop the
6 initial release of the Radeon 8500 driver under the XFree86 license.
7 This notice must be preserved.
9 Permission is hereby granted, free of charge, to any person obtaining
10 a copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial
19 portions of the Software.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
25 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 **************************************************************************/
33 * Keith Whitwell <keith@tungstengraphics.com>
38 #include "api_arrayelt.h"
43 #include "swrast/swrast.h"
44 #include "array_cache/acache.h"
46 #include "tnl/t_pipeline.h"
47 #include "swrast_setup/swrast_setup.h"
49 #include "r200_context.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_state.h"
52 #include "r200_state.h"
53 #include "r300_ioctl.h"
56 /* =============================================================
60 static GLboolean
intersect_rect(drm_clip_rect_t
* out
,
61 drm_clip_rect_t
* a
, drm_clip_rect_t
* b
)
72 if (out
->x1
>= out
->x2
)
74 if (out
->y1
>= out
->y2
)
79 void radeonRecalcScissorRects(radeonContextPtr radeon
)
84 /* Grow cliprect store?
86 if (radeon
->state
.scissor
.numAllocedClipRects
< radeon
->numClipRects
) {
87 while (radeon
->state
.scissor
.numAllocedClipRects
<
88 radeon
->numClipRects
) {
89 radeon
->state
.scissor
.numAllocedClipRects
+= 1; /* zero case */
90 radeon
->state
.scissor
.numAllocedClipRects
*= 2;
93 if (radeon
->state
.scissor
.pClipRects
)
94 FREE(radeon
->state
.scissor
.pClipRects
);
96 radeon
->state
.scissor
.pClipRects
=
97 MALLOC(radeon
->state
.scissor
.numAllocedClipRects
*
98 sizeof(drm_clip_rect_t
));
100 if (radeon
->state
.scissor
.pClipRects
== NULL
) {
101 radeon
->state
.scissor
.numAllocedClipRects
= 0;
106 out
= radeon
->state
.scissor
.pClipRects
;
107 radeon
->state
.scissor
.numClipRects
= 0;
109 for (i
= 0; i
< radeon
->numClipRects
; i
++) {
110 if (intersect_rect(out
,
111 &radeon
->pClipRects
[i
],
112 &radeon
->state
.scissor
.rect
)) {
113 radeon
->state
.scissor
.numClipRects
++;
119 void radeonUpdateScissor(GLcontext
* ctx
)
121 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
123 assert(radeon
->state
.scissor
.enabled
== ctx
->Scissor
.Enabled
);
125 if (radeon
->dri
.drawable
) {
126 __DRIdrawablePrivate
*dPriv
= radeon
->dri
.drawable
;
127 int x1
= dPriv
->x
+ ctx
->Scissor
.X
;
128 int y1
= dPriv
->y
+ dPriv
->h
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
);
130 radeon
->state
.scissor
.rect
.x1
= x1
;
131 radeon
->state
.scissor
.rect
.y1
= y1
;
132 radeon
->state
.scissor
.rect
.x2
= x1
+ ctx
->Scissor
.Width
- 1;
133 radeon
->state
.scissor
.rect
.y2
= y1
+ ctx
->Scissor
.Height
- 1;
135 radeonRecalcScissorRects(radeon
);
139 static void radeonScissor(GLcontext
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
141 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
143 if (ctx
->Scissor
.Enabled
) {
144 /* We don't pipeline cliprect changes */
145 if (IS_FAMILY_R200(radeon
))
146 R200_FIREVERTICES((r200ContextPtr
)radeon
);
150 radeonUpdateScissor(ctx
);
156 * Update cliprects and scissors.
158 void radeonSetCliprects(radeonContextPtr radeon
, GLenum mode
)
160 __DRIdrawablePrivate
*dPriv
= radeon
->dri
.drawable
;
164 radeon
->numClipRects
= dPriv
->numClipRects
;
165 radeon
->pClipRects
= dPriv
->pClipRects
;
168 /* Can't ignore 2d windows if we are page flipping.
170 if (dPriv
->numBackClipRects
== 0 || radeon
->doPageFlip
) {
171 radeon
->numClipRects
= dPriv
->numClipRects
;
172 radeon
->pClipRects
= dPriv
->pClipRects
;
174 radeon
->numClipRects
= dPriv
->numBackClipRects
;
175 radeon
->pClipRects
= dPriv
->pBackClipRects
;
179 fprintf(stderr
, "bad mode in radeonSetCliprects\n");
180 radeon
->numClipRects
= 0;
181 radeon
->pClipRects
= 0;
185 if (radeon
->state
.scissor
.enabled
)
186 radeonRecalcScissorRects(radeon
);
191 * Handle common enable bits.
192 * Called as a fallback by r200Enable/r300Enable.
194 void radeonEnable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
196 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
199 case GL_SCISSOR_TEST
:
200 /* We don't pipeline cliprect & scissor changes */
201 if (IS_FAMILY_R200(radeon
))
202 R200_FIREVERTICES((r200ContextPtr
)radeon
);
206 radeon
->state
.scissor
.enabled
= state
;
207 radeonUpdateScissor(ctx
);
217 * Initialize default state.
218 * This function is called once at context init time from
219 * r200InitState/r300InitState
221 void radeonInitState(radeonContextPtr radeon
)
223 radeon
->Fallback
= 0;
225 if (radeon
->glCtx
->Visual
.doubleBufferMode
&& radeon
->sarea
->pfCurrentPage
== 0) {
226 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->backOffset
;
227 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->backPitch
;
229 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->frontOffset
;
230 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->frontPitch
;
233 radeon
->state
.pixel
.readOffset
= radeon
->state
.color
.drawOffset
;
234 radeon
->state
.pixel
.readPitch
= radeon
->state
.color
.drawPitch
;
239 * Initialize common state functions.
240 * Called by r200InitStateFuncs/r300InitStateFuncs
242 void radeonInitStateFuncs(struct dd_function_table
*functions
)
244 functions
->Scissor
= radeonScissor
;