[r300] Add more struct names for r300_hw_state
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_state.c
1 /**************************************************************************
2
3 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
4
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.
8
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:
16
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.
20
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.
28
29 **************************************************************************/
30
31 /*
32 * Authors:
33 * Keith Whitwell <keith@tungstengraphics.com>
34 */
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "api_arrayelt.h"
39 #include "enums.h"
40 #include "colormac.h"
41 #include "light.h"
42
43 #include "swrast/swrast.h"
44 #include "vbo/vbo.h"
45 #include "tnl/tnl.h"
46 #include "tnl/t_pipeline.h"
47 #include "swrast_setup/swrast_setup.h"
48
49 #include "radeon_ioctl.h"
50 #include "radeon_state.h"
51 #include "r300_ioctl.h"
52 #include "framebuffer.h"
53
54 /* =============================================================
55 * Scissoring
56 */
57
58 static GLboolean intersect_rect(drm_clip_rect_t * out,
59 drm_clip_rect_t * a, drm_clip_rect_t * b)
60 {
61 *out = *a;
62 if (b->x1 > out->x1)
63 out->x1 = b->x1;
64 if (b->y1 > out->y1)
65 out->y1 = b->y1;
66 if (b->x2 < out->x2)
67 out->x2 = b->x2;
68 if (b->y2 < out->y2)
69 out->y2 = b->y2;
70 if (out->x1 >= out->x2)
71 return GL_FALSE;
72 if (out->y1 >= out->y2)
73 return GL_FALSE;
74 return GL_TRUE;
75 }
76
77 void radeonRecalcScissorRects(radeonContextPtr radeon)
78 {
79 drm_clip_rect_t *out;
80 int i;
81
82 /* Grow cliprect store?
83 */
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;
89 }
90
91 if (radeon->state.scissor.pClipRects)
92 FREE(radeon->state.scissor.pClipRects);
93
94 radeon->state.scissor.pClipRects =
95 MALLOC(radeon->state.scissor.numAllocedClipRects *
96 sizeof(drm_clip_rect_t));
97
98 if (radeon->state.scissor.pClipRects == NULL) {
99 radeon->state.scissor.numAllocedClipRects = 0;
100 return;
101 }
102 }
103
104 out = radeon->state.scissor.pClipRects;
105 radeon->state.scissor.numClipRects = 0;
106
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++;
112 out++;
113 }
114 }
115 }
116
117 void radeonUpdateScissor(GLcontext* ctx)
118 {
119 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
120
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);
125
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;
130
131 radeonRecalcScissorRects(radeon);
132 }
133 }
134
135 static void radeonScissor(GLcontext* ctx, GLint x, GLint y, GLsizei w, GLsizei h)
136 {
137 if (ctx->Scissor.Enabled) {
138 /* We don't pipeline cliprect changes */
139 r300Flush(ctx);
140 radeonUpdateScissor(ctx);
141 }
142 }
143
144
145 /**
146 * Update cliprects and scissors.
147 */
148 void radeonSetCliprects(radeonContextPtr radeon)
149 {
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;
154
155 if (draw_fb->_ColorDrawBufferIndexes[0] == BUFFER_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;
161 } else {
162 radeon->numClipRects = drawable->numBackClipRects;
163 radeon->pClipRects = drawable->pBackClipRects;
164 }
165 } else {
166 /* front buffer (or none, or multiple buffers */
167 radeon->numClipRects = drawable->numClipRects;
168 radeon->pClipRects = drawable->pClipRects;
169 }
170
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;
176 }
177
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;
184 }
185 }
186
187 if (radeon->state.scissor.enabled)
188 radeonRecalcScissorRects(radeon);
189
190 radeon->lastStamp = drawable->lastStamp;
191 }
192
193
194 /**
195 * Handle common enable bits.
196 * Called as a fallback by r200Enable/r300Enable.
197 */
198 void radeonEnable(GLcontext* ctx, GLenum cap, GLboolean state)
199 {
200 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
201
202 switch(cap) {
203 case GL_SCISSOR_TEST:
204 /* We don't pipeline cliprect & scissor changes */
205 r300Flush(ctx);
206
207 radeon->state.scissor.enabled = state;
208 radeonUpdateScissor(ctx);
209 break;
210
211 default:
212 return;
213 }
214 }
215
216
217 /**
218 * Initialize default state.
219 * This function is called once at context init time from
220 * r200InitState/r300InitState
221 */
222 void radeonInitState(radeonContextPtr radeon)
223 {
224 radeon->Fallback = 0;
225
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;
229 } else {
230 radeon->state.color.drawOffset = radeon->radeonScreen->frontOffset;
231 radeon->state.color.drawPitch = radeon->radeonScreen->frontPitch;
232 }
233 }
234
235
236 /**
237 * Initialize common state functions.
238 * Called by r200InitStateFuncs/r300InitStateFuncs
239 */
240 void radeonInitStateFuncs(struct dd_function_table *functions)
241 {
242 functions->Scissor = radeonScissor;
243 }