Remove Driver.ResizeBuffers = _mesa_resize_framebuffer lines.
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_context.c
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /**
31 * \file radeon_context.c
32 * Common context initialization.
33 *
34 * \author Keith Whitwell <keith@tungstengraphics.com>
35 */
36
37 #include <dlfcn.h>
38
39 #include "glheader.h"
40 #include "imports.h"
41 #include "context.h"
42 #include "state.h"
43 #include "matrix.h"
44 #include "framebuffer.h"
45
46 #include "drivers/common/driverfuncs.h"
47 #include "swrast/swrast.h"
48
49 #include "radeon_screen.h"
50 #include "radeon_ioctl.h"
51 #include "radeon_macros.h"
52 #include "radeon_reg.h"
53
54 #include "r300_state.h"
55
56 #include "utils.h"
57 #include "vblank.h"
58 #include "xmlpool.h" /* for symbolic values of enum-type options */
59
60 #define DRIVER_DATE "20060815"
61
62
63 /* Return various strings for glGetString().
64 */
65 static const GLubyte *radeonGetString(GLcontext * ctx, GLenum name)
66 {
67 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
68 static char buffer[128];
69
70 switch (name) {
71 case GL_VENDOR:
72 return (GLubyte *) "Tungsten Graphics, Inc.";
73
74 case GL_RENDERER:
75 {
76 unsigned offset;
77 GLuint agp_mode = (radeon->radeonScreen->card_type==RADEON_CARD_PCI) ? 0 :
78 radeon->radeonScreen->AGPMode;
79 const char* chipname;
80
81 if (IS_R300_CLASS(radeon->radeonScreen))
82 chipname = "R300";
83 else
84 chipname = "R200";
85
86 offset = driGetRendererString(buffer, chipname, DRIVER_DATE,
87 agp_mode);
88
89 sprintf(&buffer[offset], " %sTCL",
90 !(radeon->TclFallback & RADEON_TCL_FALLBACK_TCL_DISABLE)
91 ? "" : "NO-");
92
93 return (GLubyte *) buffer;
94 }
95
96 default:
97 return NULL;
98 }
99 }
100
101
102 /* Return the width and height of the given buffer.
103 */
104 static void radeonGetBufferSize(GLframebuffer * buffer,
105 GLuint * width, GLuint * height)
106 {
107 GET_CURRENT_CONTEXT(ctx);
108 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
109
110 LOCK_HARDWARE(radeon);
111 *width = radeon->dri.drawable->w;
112 *height = radeon->dri.drawable->h;
113 UNLOCK_HARDWARE(radeon);
114 }
115
116
117 /* Initialize the driver's misc functions.
118 */
119 static void radeonInitDriverFuncs(struct dd_function_table *functions)
120 {
121 functions->GetBufferSize = radeonGetBufferSize;
122 functions->GetString = radeonGetString;
123 }
124
125
126 /**
127 * Create and initialize all common fields of the context,
128 * including the Mesa context itself.
129 */
130 GLboolean radeonInitContext(radeonContextPtr radeon,
131 struct dd_function_table* functions,
132 const __GLcontextModes * glVisual,
133 __DRIcontextPrivate * driContextPriv,
134 void *sharedContextPrivate)
135 {
136 __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
137 radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
138 GLcontext* ctx;
139 GLcontext* shareCtx;
140 int fthrottle_mode;
141
142 /* Fill in additional standard functions. */
143 radeonInitDriverFuncs(functions);
144
145 /* Allocate and initialize the Mesa context */
146 if (sharedContextPrivate)
147 shareCtx = ((radeonContextPtr)sharedContextPrivate)->glCtx;
148 else
149 shareCtx = NULL;
150 radeon->glCtx = _mesa_create_context(glVisual, shareCtx,
151 functions, (void *)radeon);
152 if (!radeon->glCtx)
153 return GL_FALSE;
154
155 ctx = radeon->glCtx;
156 driContextPriv->driverPrivate = radeon;
157
158 /* DRI fields */
159 radeon->dri.context = driContextPriv;
160 radeon->dri.screen = sPriv;
161 radeon->dri.drawable = NULL; /* Set by XMesaMakeCurrent */
162 radeon->dri.hwContext = driContextPriv->hHWContext;
163 radeon->dri.hwLock = &sPriv->pSAREA->lock;
164 radeon->dri.fd = sPriv->fd;
165 radeon->dri.drmMinor = sPriv->drmMinor;
166
167 radeon->radeonScreen = screen;
168 radeon->sarea = (drm_radeon_sarea_t *) ((GLubyte *) sPriv->pSAREA +
169 screen->sarea_priv_offset);
170
171 /* Setup IRQs */
172 fthrottle_mode = driQueryOptioni(&radeon->optionCache, "fthrottle_mode");
173 radeon->iw.irq_seq = -1;
174 radeon->irqsEmitted = 0;
175 radeon->do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
176 radeon->radeonScreen->irq);
177
178 radeon->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
179
180 if (!radeon->do_irqs)
181 fprintf(stderr,
182 "IRQ's not enabled, falling back to %s: %d %d\n",
183 radeon->do_usleeps ? "usleeps" : "busy waits",
184 fthrottle_mode, radeon->radeonScreen->irq);
185
186 radeon->vblank_flags = (radeon->radeonScreen->irq != 0)
187 ? driGetDefaultVBlankFlags(&radeon->optionCache) : VBLANK_FLAG_NO_IRQ;
188
189 (*dri_interface->getUST) (&radeon->swap_ust);
190
191 return GL_TRUE;
192 }
193
194
195 /**
196 * Cleanup common context fields.
197 * Called by r200DestroyContext/r300DestroyContext
198 */
199 void radeonCleanupContext(radeonContextPtr radeon)
200 {
201 /* _mesa_destroy_context() might result in calls to functions that
202 * depend on the DriverCtx, so don't set it to NULL before.
203 *
204 * radeon->glCtx->DriverCtx = NULL;
205 */
206
207 /* free the Mesa context */
208 _mesa_destroy_context(radeon->glCtx);
209
210 if (radeon->state.scissor.pClipRects) {
211 FREE(radeon->state.scissor.pClipRects);
212 radeon->state.scissor.pClipRects = 0;
213 }
214 }
215
216
217 /**
218 * Swap front and back buffer.
219 */
220 void radeonSwapBuffers(__DRIdrawablePrivate * dPriv)
221 {
222 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
223 radeonContextPtr radeon;
224 GLcontext *ctx;
225
226 radeon = (radeonContextPtr) dPriv->driContextPriv->driverPrivate;
227 ctx = radeon->glCtx;
228
229 if (ctx->Visual.doubleBufferMode) {
230 _mesa_notifySwapBuffers(ctx); /* flush pending rendering comands */
231 if (radeon->doPageFlip) {
232 radeonPageFlip(dPriv);
233 } else {
234 radeonCopyBuffer(dPriv, NULL);
235 }
236 }
237 } else {
238 /* XXX this shouldn't be an error but we can't handle it for now */
239 _mesa_problem(NULL, "%s: drawable has no context!",
240 __FUNCTION__);
241 }
242 }
243
244 void radeonCopySubBuffer(__DRIdrawablePrivate * dPriv,
245 int x, int y, int w, int h )
246 {
247 if (dPriv->driContextPriv && dPriv->driContextPriv->driverPrivate) {
248 radeonContextPtr radeon;
249 GLcontext *ctx;
250
251 radeon = (radeonContextPtr) dPriv->driContextPriv->driverPrivate;
252 ctx = radeon->glCtx;
253
254 if (ctx->Visual.doubleBufferMode) {
255 drm_clip_rect_t rect;
256 rect.x1 = x + dPriv->x;
257 rect.y1 = (dPriv->h - y - h) + dPriv->y;
258 rect.x2 = rect.x1 + w;
259 rect.y2 = rect.y1 + h;
260 _mesa_notifySwapBuffers(ctx); /* flush pending rendering comands */
261 radeonCopyBuffer(dPriv, &rect);
262 }
263 } else {
264 /* XXX this shouldn't be an error but we can't handle it for now */
265 _mesa_problem(NULL, "%s: drawable has no context!",
266 __FUNCTION__);
267 }
268 }
269
270 /* Force the context `c' to be the current context and associate with it
271 * buffer `b'.
272 */
273 GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
274 __DRIdrawablePrivate * driDrawPriv,
275 __DRIdrawablePrivate * driReadPriv)
276 {
277 if (driContextPriv) {
278 radeonContextPtr radeon =
279 (radeonContextPtr) driContextPriv->driverPrivate;
280
281 if (RADEON_DEBUG & DEBUG_DRI)
282 fprintf(stderr, "%s ctx %p\n", __FUNCTION__,
283 radeon->glCtx);
284
285 if (radeon->dri.drawable != driDrawPriv) {
286 driDrawableInitVBlank(driDrawPriv,
287 radeon->vblank_flags,
288 &radeon->vbl_seq);
289 radeon->dri.drawable = driDrawPriv;
290
291 r300UpdateWindow(radeon->glCtx);
292 r300UpdateViewportOffset(radeon->glCtx);
293 }
294
295 _mesa_make_current(radeon->glCtx,
296 (GLframebuffer *) driDrawPriv->
297 driverPrivate,
298 (GLframebuffer *) driReadPriv->
299 driverPrivate);
300
301 if (!radeon->glCtx->Viewport.Width) {
302 _mesa_set_viewport(radeon->glCtx, 0, 0,
303 driDrawPriv->w, driDrawPriv->h);
304 }
305
306 _mesa_update_state(radeon->glCtx);
307 } else {
308 if (RADEON_DEBUG & DEBUG_DRI)
309 fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
310 _mesa_make_current(0, 0, 0);
311 }
312
313 if (RADEON_DEBUG & DEBUG_DRI)
314 fprintf(stderr, "End %s\n", __FUNCTION__);
315 return GL_TRUE;
316 }
317
318 /* Force the context `c' to be unbound from its buffer.
319 */
320 GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv)
321 {
322 radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
323
324 if (RADEON_DEBUG & DEBUG_DRI)
325 fprintf(stderr, "%s ctx %p\n", __FUNCTION__,
326 radeon->glCtx);
327
328 return GL_TRUE;
329 }
330