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"
46 #include "tnl/t_pipeline.h"
47 #include "swrast_setup/swrast_setup.h"
49 #include "radeon_ioctl.h"
50 #include "radeon_state.h"
51 #include "r300_ioctl.h"
52 #include "framebuffer.h"
54 /* =============================================================
58 static GLboolean
intersect_rect(drm_clip_rect_t
* out
,
59 drm_clip_rect_t
* a
, drm_clip_rect_t
* b
)
70 if (out
->x1
>= out
->x2
)
72 if (out
->y1
>= out
->y2
)
77 void radeonRecalcScissorRects(radeonContextPtr radeon
)
82 /* Grow cliprect store?
84 if (radeon
->state
.scissor
.numAllocedClipRects
< radeon
->numClipRects
) {
85 while (radeon
->state
.scissor
.numAllocedClipRects
<
86 radeon
->numClipRects
) {
87 radeon
->state
.scissor
.numAllocedClipRects
+= 1; /* zero case */
88 radeon
->state
.scissor
.numAllocedClipRects
*= 2;
91 if (radeon
->state
.scissor
.pClipRects
)
92 FREE(radeon
->state
.scissor
.pClipRects
);
94 radeon
->state
.scissor
.pClipRects
=
95 MALLOC(radeon
->state
.scissor
.numAllocedClipRects
*
96 sizeof(drm_clip_rect_t
));
98 if (radeon
->state
.scissor
.pClipRects
== NULL
) {
99 radeon
->state
.scissor
.numAllocedClipRects
= 0;
104 out
= radeon
->state
.scissor
.pClipRects
;
105 radeon
->state
.scissor
.numClipRects
= 0;
107 for (i
= 0; i
< radeon
->numClipRects
; i
++) {
108 if (intersect_rect(out
,
109 &radeon
->pClipRects
[i
],
110 &radeon
->state
.scissor
.rect
)) {
111 radeon
->state
.scissor
.numClipRects
++;
117 void radeonUpdateScissor(GLcontext
* ctx
)
119 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
121 if (radeon
->dri
.drawable
) {
122 __DRIdrawablePrivate
*dPriv
= radeon
->dri
.drawable
;
123 int x1
= dPriv
->x
+ ctx
->Scissor
.X
;
124 int y1
= dPriv
->y
+ dPriv
->h
- (ctx
->Scissor
.Y
+ ctx
->Scissor
.Height
);
126 radeon
->state
.scissor
.rect
.x1
= x1
;
127 radeon
->state
.scissor
.rect
.y1
= y1
;
128 radeon
->state
.scissor
.rect
.x2
= x1
+ ctx
->Scissor
.Width
- 1;
129 radeon
->state
.scissor
.rect
.y2
= y1
+ ctx
->Scissor
.Height
- 1;
131 radeonRecalcScissorRects(radeon
);
135 static void radeonScissor(GLcontext
* ctx
, GLint x
, GLint y
, GLsizei w
, GLsizei h
)
137 if (ctx
->Scissor
.Enabled
) {
138 /* We don't pipeline cliprect changes */
140 radeonUpdateScissor(ctx
);
146 * Update cliprects and scissors.
148 void radeonSetCliprects(radeonContextPtr radeon
)
150 __DRIdrawablePrivate
*const drawable
= radeon
->dri
.drawable
;
151 __DRIdrawablePrivate
*const readable
= radeon
->dri
.readable
;
152 GLframebuffer
*const draw_fb
= (GLframebuffer
*)drawable
->driverPrivate
;
153 GLframebuffer
*const read_fb
= (GLframebuffer
*)readable
->driverPrivate
;
155 if (draw_fb
->_ColorDrawBufferMask
[0] == BUFFER_BIT_BACK_LEFT
) {
156 /* Can't ignore 2d windows if we are page flipping. */
157 if (drawable
->numBackClipRects
== 0 || radeon
->doPageFlip
||
158 radeon
->sarea
->pfCurrentPage
== 1) {
159 radeon
->numClipRects
= drawable
->numClipRects
;
160 radeon
->pClipRects
= drawable
->pClipRects
;
162 radeon
->numClipRects
= drawable
->numBackClipRects
;
163 radeon
->pClipRects
= drawable
->pBackClipRects
;
166 /* front buffer (or none, or multiple buffers */
167 radeon
->numClipRects
= drawable
->numClipRects
;
168 radeon
->pClipRects
= drawable
->pClipRects
;
171 if ((draw_fb
->Width
!= drawable
->w
) ||
172 (draw_fb
->Height
!= drawable
->h
)) {
173 _mesa_resize_framebuffer(radeon
->glCtx
, draw_fb
,
174 drawable
->w
, drawable
->h
);
175 draw_fb
->Initialized
= GL_TRUE
;
178 if (drawable
!= readable
) {
179 if ((read_fb
->Width
!= readable
->w
) ||
180 (read_fb
->Height
!= readable
->h
)) {
181 _mesa_resize_framebuffer(radeon
->glCtx
, read_fb
,
182 readable
->w
, readable
->h
);
183 read_fb
->Initialized
= GL_TRUE
;
187 if (radeon
->state
.scissor
.enabled
)
188 radeonRecalcScissorRects(radeon
);
190 radeon
->lastStamp
= drawable
->lastStamp
;
195 * Handle common enable bits.
196 * Called as a fallback by r200Enable/r300Enable.
198 void radeonEnable(GLcontext
* ctx
, GLenum cap
, GLboolean state
)
200 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
203 case GL_SCISSOR_TEST
:
204 /* We don't pipeline cliprect & scissor changes */
207 radeon
->state
.scissor
.enabled
= state
;
208 radeonUpdateScissor(ctx
);
218 * Initialize default state.
219 * This function is called once at context init time from
220 * r200InitState/r300InitState
222 void radeonInitState(radeonContextPtr radeon
)
224 radeon
->Fallback
= 0;
226 if (radeon
->glCtx
->Visual
.doubleBufferMode
&& radeon
->sarea
->pfCurrentPage
== 0) {
227 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->backOffset
;
228 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->backPitch
;
230 radeon
->state
.color
.drawOffset
= radeon
->radeonScreen
->frontOffset
;
231 radeon
->state
.color
.drawPitch
= radeon
->radeonScreen
->frontPitch
;
237 * Initialize common state functions.
238 * Called by r200InitStateFuncs/r300InitStateFuncs
240 void radeonInitStateFuncs(struct dd_function_table
*functions
)
242 functions
->Scissor
= radeonScissor
;