summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Bornecrantz <wallbraker@gmail.com>2009-03-03 03:22:05 +0100
committerJakob Bornecrantz <wallbraker@gmail.com>2009-03-03 03:22:05 +0100
commit1d060e36f248b2c1d2575d1e2cbd362b8345ae55 (patch)
tree93ab507b1ecb643fcb3f3c8b42c401cade6df5b7
parentcc9fbb16a6787e03186926b7488bfcaaf41635d9 (diff)
st/dri2: Add DRI2 a state tracker
This was based of the unfinnished code that Keith Whitwell started on but never finnished. I moved the code from the glx directory because dri drivers can be used for more things then just glx.
-rw-r--r--src/gallium/state_trackers/dri2/Makefile28
-rw-r--r--src/gallium/state_trackers/dri2/dri_context.c (renamed from src/gallium/state_trackers/glx/dri/dri_context.c)60
-rw-r--r--src/gallium/state_trackers/dri2/dri_context.h (renamed from src/gallium/state_trackers/glx/dri/dri_context.h)41
-rw-r--r--src/gallium/state_trackers/dri2/dri_drawable.c315
-rw-r--r--src/gallium/state_trackers/dri2/dri_drawable.h (renamed from src/gallium/state_trackers/glx/dri/dri_drawable.h)29
-rw-r--r--src/gallium/state_trackers/dri2/dri_extensions.c (renamed from src/gallium/state_trackers/glx/dri/dri_extensions.c)25
-rw-r--r--src/gallium/state_trackers/dri2/dri_screen.c (renamed from src/gallium/state_trackers/glx/dri/dri_screen.c)218
-rw-r--r--src/gallium/state_trackers/dri2/dri_screen.h (renamed from src/gallium/state_trackers/glx/dri/dri_screen.h)53
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_drawable.c363
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_lock.c90
10 files changed, 572 insertions, 650 deletions
diff --git a/src/gallium/state_trackers/dri2/Makefile b/src/gallium/state_trackers/dri2/Makefile
new file mode 100644
index 00000000000..47750e997e9
--- /dev/null
+++ b/src/gallium/state_trackers/dri2/Makefile
@@ -0,0 +1,28 @@
1TOP = ../../../..
2include $(TOP)/configs/current
3
4LIBNAME = dri2drm
5
6LIBRARY_INCLUDES = \
7 -I$(TOP)/include \
8 -I$(TOP)/src/mesa \
9 -I$(TOP)/src/mesa/drivers/dri/common \
10 -I$(TOP)/src/mesa/main \
11 $(shell pkg-config --cflags-only-I libdrm)
12
13
14C_SOURCES = \
15 dri_context.c \
16 dri_screen.c \
17 dri_drawable.c \
18 dri_extensions.c
19
20# $(TOP)/src/mesa/drivers/dri/common/utils.c \
21 $(TOP)/src/mesa/drivers/dri/common/vblank.c \
22 $(TOP)/src/mesa/drivers/dri/common/dri_util.c \
23 $(TOP)/src/mesa/drivers/dri/common/xmlconfig.c \
24 $(TOP)/src/mesa/drivers/common/driverfuncs.c \
25 $(TOP)/src/mesa/drivers/dri/common/texmem.c \
26 $(TOP)/src/mesa/drivers/dri/common/drirenderbuffer.c
27
28include ../../Makefile.template
diff --git a/src/gallium/state_trackers/glx/dri/dri_context.c b/src/gallium/state_trackers/dri2/dri_context.c
index 9424e18bee3..a8a94be176c 100644
--- a/src/gallium/state_trackers/glx/dri/dri_context.c
+++ b/src/gallium/state_trackers/dri2/dri_context.c
@@ -18,22 +18,29 @@
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27 27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
28 31
29#include "dri_screen.h" 32#include "dri_screen.h"
30#include "dri_context.h"
31#include "dri_winsys.h"
32 33
34#include "dri_drawable.h"
35
36
37#include "state_tracker/drm_api.h"
33#include "state_tracker/st_public.h" 38#include "state_tracker/st_public.h"
34#include "state_tracker/st_context.h" 39#include "state_tracker/st_context.h"
35#include "pipe/p_context.h" 40#include "pipe/p_context.h"
36 41
42#include "dri_context.h"
43
37#include "util/u_memory.h" 44#include "util/u_memory.h"
38 45
39 46
@@ -59,14 +66,13 @@ dri_create_context(const __GLcontextModes *visual,
59 ctx->cPriv = cPriv; 66 ctx->cPriv = cPriv;
60 ctx->sPriv = sPriv; 67 ctx->sPriv = sPriv;
61 68
62 driParseConfigFiles(&ctx->optionCache, 69 driParseConfigFiles(&ctx->optionCache,
63 &screen->optionCache, 70 &screen->optionCache,
64 sPriv->myNum, 71 sPriv->myNum,
65 "dri"); 72 "dri");
66 73
67 ctx->pipe = screen->pipe_screen->create_context(screen->pipe_screen, 74 ctx->pipe = drm_api_hocks.create_context(screen->pipe_screen);
68 screen->pipe_winsys, 75
69 hw_winsys );
70 if (ctx->pipe == NULL) 76 if (ctx->pipe == NULL)
71 goto fail; 77 goto fail;
72 78
@@ -76,16 +82,16 @@ dri_create_context(const __GLcontextModes *visual,
76 if (ctx->st == NULL) 82 if (ctx->st == NULL)
77 goto fail; 83 goto fail;
78 84
79 dri_init_extensions( ctx ); 85 dri_init_extensions(ctx);
80 86
81 return GL_TRUE; 87 return GL_TRUE;
82 88
83fail: 89fail:
84 if (ctx && ctx->st) 90 if (ctx && ctx->st)
85 st_destroy_context( ctx->st ); 91 st_destroy_context(ctx->st);
86 92
87 if (ctx && ctx->pipe) 93 if (ctx && ctx->pipe)
88 ctx->pipe->destroy( ctx->pipe ); 94 ctx->pipe->destroy(ctx->pipe);
89 95
90 FREE(ctx); 96 FREE(ctx);
91 return FALSE; 97 return FALSE;
@@ -97,14 +103,13 @@ dri_destroy_context(__DRIcontextPrivate *cPriv)
97{ 103{
98 struct dri_context *ctx = dri_context(cPriv); 104 struct dri_context *ctx = dri_context(cPriv);
99 struct dri_screen *screen = dri_screen(cPriv->driScreenPriv); 105 struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
100 struct pipe_winsys *winsys = screen->winsys;
101 106
102 /* No particular reason to wait for command completion before 107 /* No particular reason to wait for command completion before
103 * destroying a context, but it is probably worthwhile flushing it 108 * destroying a context, but it is probably worthwhile flushing it
104 * to avoid having to add code elsewhere to cope with flushing a 109 * to avoid having to add code elsewhere to cope with flushing a
105 * partially destroyed context. 110 * partially destroyed context.
106 */ 111 */
107 st_flush(ctx->st); 112 st_flush(ctx->st, 0, NULL);
108 113
109 if (screen->dummyContext == ctx) 114 if (screen->dummyContext == ctx)
110 screen->dummyContext = NULL; 115 screen->dummyContext = NULL;
@@ -143,26 +148,21 @@ dri_make_current(__DRIcontextPrivate *cPriv,
143 */ 148 */
144 screen->dummyContext = ctx; 149 screen->dummyContext = ctx;
145 150
146 st_make_current( ctx->st, 151 st_make_current(ctx->st,
147 draw->stfb, 152 draw->stfb,
148 read->stfb ); 153 read->stfb);
149 154
150 ctx->dPriv = driDrawPriv; 155 ctx->dPriv = driDrawPriv;
151 156
152 /* Update window sizes if necessary: 157 if (driDrawPriv)
153 */ 158 dri_get_buffers(driDrawPriv);
154 if (draw->stamp != driDrawPriv->lastStamp) { 159 if (driDrawPriv != driReadPriv && driReadPriv)
155 dri_update_window_size( draw ); 160 dri_get_buffers(driReadPriv);
156 } 161 } else {
157
158 if (read->stamp != driReadPriv->lastStamp) {
159 dri_update_window_size( read );
160 }
161
162 }
163 else {
164 st_make_current(NULL, NULL, NULL); 162 st_make_current(NULL, NULL, NULL);
165 } 163 }
166 164
167 return GL_TRUE; 165 return GL_TRUE;
168} 166}
167
168/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_context.h b/src/gallium/state_trackers/dri2/dri_context.h
index 4e6a305abb0..e910472700c 100644
--- a/src/gallium/state_trackers/glx/dri/dri_context.h
+++ b/src/gallium/state_trackers/dri2/dri_context.h
@@ -1,6 +1,7 @@
1/************************************************************************** 1/**************************************************************************
2 * 2 *
3 * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 3 * Copyright (C) 2009 VMware, Inc.
4 * All Rights Reserved.
4 * 5 *
5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the 7 * copy of this software and associated documentation files (the
@@ -17,12 +18,16 @@
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * 25 *
25 **************************************************************************/ 26 **************************************************************************/
27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
26 31
27#ifndef DRI_CONTEXT_H 32#ifndef DRI_CONTEXT_H
28#define DRI_CONTEXT_H 33#define DRI_CONTEXT_H
@@ -35,22 +40,21 @@
35struct pipe_context; 40struct pipe_context;
36struct pipe_fence; 41struct pipe_fence;
37struct st_context; 42struct st_context;
43struct dri_drawable;
38 44
39 45
40struct dri_context 46struct dri_context
41{ 47{
48 /* dri */
49 __DRIscreenPrivate *sPriv;
42 __DRIcontextPrivate *cPriv; 50 __DRIcontextPrivate *cPriv;
43 __DRIdrawablePrivate *dPriv; 51 __DRIdrawablePrivate *dPriv;
44 52
53 driOptionCache optionCache;
54
55 /* gallium */
45 struct st_context *st; 56 struct st_context *st;
46 struct pipe_context *pipe; 57 struct pipe_context *pipe;
47
48 boolean locked;
49
50 /**
51 * Configuration cache
52 */
53 driOptionCache optionCache;
54}; 58};
55 59
56 60
@@ -60,13 +64,14 @@ dri_context(__DRIcontextPrivate *driContextPriv)
60 return (struct dri_context *) driContextPriv->driverPrivate; 64 return (struct dri_context *) driContextPriv->driverPrivate;
61} 65}
62 66
67
63/*********************************************************************** 68/***********************************************************************
64 * dri_context.c 69 * dri_context.c
65 */ 70 */
66void 71void
67dri_destroy_context(__DRIcontextPrivate * driContextPriv); 72dri_destroy_context(__DRIcontextPrivate * driContextPriv);
68 73
69boolean 74boolean
70dri_unbind_context(__DRIcontextPrivate * driContextPriv); 75dri_unbind_context(__DRIcontextPrivate * driContextPriv);
71 76
72boolean 77boolean
@@ -80,16 +85,12 @@ dri_create_context(const __GLcontextModes * visual,
80 void *sharedContextPrivate); 85 void *sharedContextPrivate);
81 86
82 87
83
84/*********************************************************************** 88/***********************************************************************
85 * dri_lock.c 89 * dri_extensions.c
86 */ 90 */
87void dri_lock_hardware( struct dri_context *context, 91void
88 struct dri_drawable *drawable ); 92dri_init_extensions(struct dri_context *ctx);
89
90void dri_unlock_hardware( struct dri_context *dri );
91boolean dri_is_locked( struct dri_context *dri );
92
93
94 93
95#endif 94#endif
95
96/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/dri2/dri_drawable.c b/src/gallium/state_trackers/dri2/dri_drawable.c
new file mode 100644
index 00000000000..120d45bc036
--- /dev/null
+++ b/src/gallium/state_trackers/dri2/dri_drawable.c
@@ -0,0 +1,315 @@
1/**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
31
32#include "dri_screen.h"
33#include "dri_context.h"
34#include "dri_drawable.h"
35
36#include "pipe/p_context.h"
37#include "pipe/p_screen.h"
38#include "pipe/p_inlines.h"
39#include "state_tracker/drm_api.h"
40#include "state_tracker/st_public.h"
41#include "state_tracker/st_context.h"
42#include "state_tracker/st_cb_fbo.h"
43
44#include "util/u_memory.h"
45
46
47static struct pipe_surface *
48dri_surface_from_handle(struct pipe_screen *screen,
49 unsigned handle,
50 enum pipe_format format,
51 unsigned width,
52 unsigned height,
53 unsigned pitch)
54{
55 struct pipe_surface *surface = NULL;
56 struct pipe_texture *texture = NULL;
57 struct pipe_texture templat;
58 struct pipe_buffer *buf = NULL;
59
60 buf = drm_api_hocks.buffer_from_handle(screen, "dri2 buffer", handle);
61 if (!buf)
62 return NULL;
63
64 memset(&templat, 0, sizeof(templat));
65 templat.tex_usage |= PIPE_TEXTURE_USAGE_RENDER_TARGET;
66 templat.target = PIPE_TEXTURE_2D;
67 templat.last_level = 0;
68 templat.depth[0] = 1;
69 templat.format = format;
70 templat.width[0] = width;
71 templat.height[0] = height;
72 pf_get_block(templat.format, &templat.block);
73
74 texture = screen->texture_blanket(screen,
75 &templat,
76 &pitch,
77 buf);
78
79 /* we don't need the buffer from this point on */
80 pipe_buffer_reference(screen, &buf, NULL);
81
82 if (!texture)
83 return NULL;
84
85 surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
86 PIPE_BUFFER_USAGE_GPU_READ |
87 PIPE_BUFFER_USAGE_GPU_WRITE);
88
89 /* we don't need the texture from this point on */
90 pipe_texture_reference(&texture, NULL);
91 return surface;
92}
93
94
95/**
96 * This will be called a drawable is known to have been resized.
97 */
98void
99dri_get_buffers(__DRIdrawablePrivate *dPriv)
100{
101 struct dri_drawable *drawable = dri_drawable(dPriv);
102 struct pipe_surface *surface = NULL;
103 struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
104 __DRIbuffer *buffers = NULL;
105 __DRIscreen *dri_screen = drawable->sPriv;
106 __DRIdrawable *dri_drawable = drawable->dPriv;
107 boolean have_depth = FALSE;
108 int i, count;
109
110 buffers = (*dri_screen->dri2.loader->getBuffers)(dri_drawable,
111 &dri_drawable->w,
112 &dri_drawable->h,
113 drawable->attachments,
114 drawable->num_attachments,
115 &count,
116 dri_drawable->loaderPrivate);
117
118 if (buffers == NULL) {
119 return;
120 }
121
122 /* set one cliprect to cover the whole dri_drawable */
123 dri_drawable->x = 0;
124 dri_drawable->y = 0;
125 dri_drawable->backX = 0;
126 dri_drawable->backY = 0;
127 dri_drawable->numClipRects = 1;
128 dri_drawable->pClipRects[0].x1 = 0;
129 dri_drawable->pClipRects[0].y1 = 0;
130 dri_drawable->pClipRects[0].x2 = dri_drawable->w;
131 dri_drawable->pClipRects[0].y2 = dri_drawable->h;
132 dri_drawable->numBackClipRects = 1;
133 dri_drawable->pBackClipRects[0].x1 = 0;
134 dri_drawable->pBackClipRects[0].y1 = 0;
135 dri_drawable->pBackClipRects[0].x2 = dri_drawable->w;
136 dri_drawable->pBackClipRects[0].y2 = dri_drawable->h;
137
138 for (i = 0; i < count; i++) {
139 enum pipe_format format = 0;
140 int index = 0;
141
142 switch (buffers[i].attachment) {
143 case __DRI_BUFFER_FRONT_LEFT:
144 index = ST_SURFACE_FRONT_LEFT;
145 format = PIPE_FORMAT_A8R8G8B8_UNORM;
146 break;
147 case __DRI_BUFFER_BACK_LEFT:
148 index = ST_SURFACE_BACK_LEFT;
149 format = PIPE_FORMAT_A8R8G8B8_UNORM;
150 break;
151 case __DRI_BUFFER_DEPTH:
152 index = ST_SURFACE_DEPTH;
153 format = PIPE_FORMAT_Z24S8_UNORM;
154 break;
155 case __DRI_BUFFER_STENCIL:
156 index = ST_SURFACE_DEPTH;
157 format = PIPE_FORMAT_Z24S8_UNORM;
158 break;
159 case __DRI_BUFFER_ACCUM:
160 default:
161 assert(0);
162 }
163 assert(buffers[i].cpp == 4);
164
165 if (index == ST_SURFACE_DEPTH) {
166 if (have_depth)
167 continue;
168 else
169 have_depth = TRUE;
170 }
171
172 surface = dri_surface_from_handle(screen,
173 buffers[i].name,
174 format,
175 dri_drawable->w,
176 dri_drawable->h,
177 buffers[i].pitch);
178
179 st_set_framebuffer_surface(drawable->stfb, index, surface);
180 pipe_surface_reference(&surface, NULL);
181 }
182 /* this needed, or else the state tracker fails to pick the new buffers */
183 st_resize_framebuffer(drawable->stfb, dri_drawable->w, dri_drawable->h);
184}
185
186
187void
188dri_swap_buffers(__DRIdrawablePrivate * dPriv)
189{
190 struct dri_drawable *drawable = dri_drawable(dPriv);
191 struct pipe_surface *back_surf;
192
193 assert(drawable);
194 assert(drawable->stfb);
195
196 st_get_framebuffer_surface(drawable->stfb,
197 ST_SURFACE_BACK_LEFT,
198 &back_surf);
199 if (back_surf) {
200 st_notify_swapbuffers(drawable->stfb);
201 /* TODO do stuff here */
202 st_notify_swapbuffers_complete(drawable->stfb);
203 }
204}
205
206
207/**
208 * Called via glXCopySubBufferMESA() to copy a subrect of the back
209 * buffer to the front buffer/screen.
210 */
211void
212dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h)
213{
214 struct dri_drawable *drawable = dri_drawable(dPriv);
215 struct pipe_surface *back_surf;
216
217 assert(drawable);
218 assert(drawable->stfb);
219
220 st_get_framebuffer_surface(drawable->stfb,
221 ST_SURFACE_BACK_LEFT,
222 &back_surf);
223 if (back_surf) {
224 drm_clip_rect_t rect;
225 rect.x1 = x;
226 rect.y1 = y;
227 rect.x2 = w;
228 rect.y2 = h;
229
230 /* do stuff here */
231 }
232}
233
234
235/**
236 * This is called when we need to set up GL rendering to a new X window.
237 */
238boolean
239dri_create_buffer(__DRIscreenPrivate *sPriv,
240 __DRIdrawablePrivate *dPriv,
241 const __GLcontextModes *visual,
242 boolean isPixmap)
243{
244 enum pipe_format colorFormat, depthFormat, stencilFormat;
245 struct dri_drawable *drawable = NULL;
246 int i;
247
248 if (isPixmap)
249 goto fail; /* not implemented */
250
251 drawable = CALLOC_STRUCT(dri_drawable);
252 if (drawable == NULL)
253 goto fail;
254
255 /* XXX: todo: use the pipe_screen queries to figure out which
256 * render targets are supportable.
257 */
258 assert(visual->redBits == 8);
259 assert(visual->depthBits == 24 || visual->depthBits == 0);
260 assert(visual->stencilBits == 8 || visual->stencilBits == 0);
261
262 colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;
263
264 if (visual->depthBits)
265 depthFormat = PIPE_FORMAT_S8Z24_UNORM;
266 else
267 depthFormat = PIPE_FORMAT_NONE;
268
269 if (visual->stencilBits)
270 stencilFormat = PIPE_FORMAT_S8Z24_UNORM;
271 else
272 stencilFormat = PIPE_FORMAT_NONE;
273
274 drawable->stfb = st_create_framebuffer(visual,
275 colorFormat,
276 depthFormat,
277 stencilFormat,
278 dPriv->w,
279 dPriv->h,
280 (void*) drawable);
281 if (drawable->stfb == NULL)
282 goto fail;
283
284 drawable->sPriv = sPriv;
285 drawable->dPriv = dPriv;
286 dPriv->driverPrivate = (void *) drawable;
287
288 /* setup dri2 buffers information */
289 i = 0;
290 drawable->attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
291 drawable->attachments[i++] = __DRI_BUFFER_BACK_LEFT;
292 if (visual->depthBits)
293 drawable->attachments[i++] = __DRI_BUFFER_DEPTH;
294 if (visual->stencilBits)
295 drawable->attachments[i++] = __DRI_BUFFER_STENCIL;
296 drawable->num_attachments = i;
297
298 return GL_TRUE;
299fail:
300 FREE(drawable);
301 return GL_FALSE;
302}
303
304
305void
306dri_destroy_buffer(__DRIdrawablePrivate *dPriv)
307{
308 struct dri_drawable *drawable = dri_drawable(dPriv);
309
310 st_unreference_framebuffer(drawable->stfb);
311
312 FREE(drawable);
313}
314
315/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_drawable.h b/src/gallium/state_trackers/dri2/dri_drawable.h
index 1001bb8c578..d40d09c9b5b 100644
--- a/src/gallium/state_trackers/glx/dri/dri_drawable.h
+++ b/src/gallium/state_trackers/dri2/dri_drawable.h
@@ -18,7 +18,7 @@
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -37,12 +37,14 @@ struct st_framebuffer;
37 37
38struct dri_drawable 38struct dri_drawable
39{ 39{
40 /* dri */
40 __DRIdrawablePrivate *dPriv; 41 __DRIdrawablePrivate *dPriv;
41 unsigned stamp; 42 __DRIscreenPrivate *sPriv;
42 43
43 struct pipe_fence *last_swap_fence; 44 unsigned attachments[8];
44 struct pipe_fence *first_swap_fence; 45 unsigned num_attachments;
45 46
47 /* gallium */
46 struct st_framebuffer *stfb; 48 struct st_framebuffer *stfb;
47}; 49};
48 50
@@ -57,17 +59,26 @@ dri_drawable(__DRIdrawablePrivate * driDrawPriv)
57/*********************************************************************** 59/***********************************************************************
58 * dri_drawable.c 60 * dri_drawable.c
59 */ 61 */
62boolean
63dri_create_buffer(__DRIscreenPrivate *sPriv,
64 __DRIdrawablePrivate *dPriv,
65 const __GLcontextModes *visual,
66 boolean isPixmap);
60 67
61void 68void
62dri_swap_buffers(__DRIdrawablePrivate * dPriv); 69dri_swap_buffers(__DRIdrawablePrivate * dPriv);
63 70
64void 71void
65dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, 72dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv,
66 int x, int y, 73 int x, int y,
67 int w, int h); 74 int w, int h);
68 75
69void 76void
70dri_update_window_size(__DRIdrawablePrivate *dPriv); 77dri_get_buffers(__DRIdrawablePrivate * dPriv);
71 78
79void
80dri_destroy_buffer(__DRIdrawablePrivate *dPriv);
72 81
73#endif 82#endif
83
84/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_extensions.c b/src/gallium/state_trackers/dri2/dri_extensions.c
index 126faf76014..9c7a27282b2 100644
--- a/src/gallium/state_trackers/glx/dri/dri_extensions.c
+++ b/src/gallium/state_trackers/dri2/dri_extensions.c
@@ -18,15 +18,20 @@
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
27 31
28 32#include "dri_screen.h"
29 33#include "dri_context.h"
34#include "state_tracker/st_context.h"
30 35
31#define need_GL_ARB_multisample 36#define need_GL_ARB_multisample
32#define need_GL_ARB_point_parameters 37#define need_GL_ARB_point_parameters
@@ -96,13 +101,17 @@ const struct dri_extension card_extensions[] = {
96}; 101};
97 102
98 103
99 104void
100void 105dri_init_extensions(struct dri_context *ctx)
101dri_init_extensions( void )
102{ 106{
103 /* The card_extensions list should be pruned according to the 107 /* The card_extensions list should be pruned according to the
104 * capabilities of the pipe_screen. This is actually something 108 * capabilities of the pipe_screen. This is actually something
105 * that can/should be done inside st_create_context(). 109 * that can/should be done inside st_create_context().
106 */ 110 */
107 driInitExtensions( ctx->st->ctx, card_extensions, GL_TRUE ); 111 if (ctx)
112 driInitExtensions(ctx->st->ctx, card_extensions, GL_TRUE);
113 else
114 driInitExtensions(NULL, card_extensions, GL_FALSE);
108} 115}
116
117/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_screen.c b/src/gallium/state_trackers/dri2/dri_screen.c
index f7119b949a3..1fef5382946 100644
--- a/src/gallium/state_trackers/glx/dri/dri_screen.c
+++ b/src/gallium/state_trackers/dri2/dri_screen.c
@@ -18,23 +18,29 @@
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
27 31
28#include "utils.h" 32#include "utils.h"
29#include "vblank.h" 33#include "vblank.h"
30#include "xmlpool.h" 34#include "xmlpool.h"
31 35
32#include "dri_context.h"
33#include "dri_screen.h" 36#include "dri_screen.h"
37#include "dri_context.h"
38#include "dri_drawable.h"
34 39
35#include "pipe/p_context.h" 40#include "pipe/p_context.h"
36#include "pipe/p_screen.h" 41#include "pipe/p_screen.h"
37#include "pipe/p_inlines.h" 42#include "pipe/p_inlines.h"
43#include "state_tracker/drm_api.h"
38#include "state_tracker/st_public.h" 44#include "state_tracker/st_public.h"
39#include "state_tracker/st_cb_fbo.h" 45#include "state_tracker/st_cb_fbo.h"
40 46
@@ -44,19 +50,15 @@ PUBLIC const char __driConfigOptions[] =
44 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS) 50 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
45 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0) 51 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
46 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY 52 DRI_CONF_SECTION_END DRI_CONF_SECTION_QUALITY
47// DRI_CONF_FORCE_S3TC_ENABLE(false) 53 /*DRI_CONF_FORCE_S3TC_ENABLE(false)*/
48 DRI_CONF_ALLOW_LARGE_TEXTURES(1) 54 DRI_CONF_ALLOW_LARGE_TEXTURES(1)
49 DRI_CONF_SECTION_END DRI_CONF_END; 55 DRI_CONF_SECTION_END DRI_CONF_END;
50 56
51const uint __driNConfigOptions = 3;
52
53static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
54
55extern const struct dri_extension card_extensions[];
56 57
58const uint __driNConfigOptions = 3;
57 59
58 60
59static const __DRIextension *driScreenExtensions[] = { 61static const __DRIextension *dri_screen_extensions[] = {
60 &driReadDrawableExtension, 62 &driReadDrawableExtension,
61 &driCopySubBufferExtension.base, 63 &driCopySubBufferExtension.base,
62 &driSwapControlExtension.base, 64 &driSwapControlExtension.base,
@@ -66,46 +68,40 @@ static const __DRIextension *driScreenExtensions[] = {
66}; 68};
67 69
68 70
69 71static void
70 72dri_get_drm_minor(struct dri_screen *screen)
71static const char *
72dri_get_name( struct pipe_winsys *winsys )
73{ 73{
74 return "dri"; 74 /* TODO get the real minor */
75 screen->minor = 0;
75} 76}
76 77
77 78
78
79static void 79static void
80dri_destroy_screen(__DRIscreenPrivate * sPriv) 80dri_get_device_id(struct dri_screen *screen)
81{ 81{
82 struct dri_screen *screen = dri_screen(sPriv); 82 char path[512];
83 83 FILE *file;
84 screen->pipe_screen->destroy( screen->pipe_screen );
85 screen->pipe_winsys->destroy( screen->pipe_winsys );
86 FREE(screen);
87 sPriv->private = NULL;
88}
89 84
85 /*
86 * There must be a better way to get the deviceID.
87 * XXX this only works on Linux.
88 */
89 snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", screen->minor);
90 file = fopen(path, "r");
91 if (!file) {
92 return;
93 }
90 94
91/** 95 fgets(path, sizeof(path), file);
92 * Get information about previous buffer swaps. 96 sscanf(path, "%x", &screen->deviceID);
93 */ 97 fclose(file);
94static int
95dri_get_swap_info(__DRIdrawablePrivate * dPriv,
96 __DRIswapInfo * sInfo)
97{
98 if (dPriv == NULL ||
99 dPriv->driverPrivate == NULL ||
100 sInfo == NULL)
101 return -1;
102 else
103 return 0;
104} 98}
105 99
100
106static const __DRIconfig ** 101static const __DRIconfig **
107dri_fill_in_modes(__DRIscreenPrivate *psp, 102dri_fill_in_modes(__DRIscreenPrivate *psp,
108 unsigned pixel_bits ) 103 unsigned pixel_bits, unsigned depth_bits,
104 unsigned stencil_bits, GLboolean have_back_buffer)
109{ 105{
110 __DRIconfig **configs; 106 __DRIconfig **configs;
111 __GLcontextModes *m; 107 __GLcontextModes *m;
@@ -115,17 +111,19 @@ dri_fill_in_modes(__DRIscreenPrivate *psp,
115 uint8_t msaa_samples_array[1]; 111 uint8_t msaa_samples_array[1];
116 unsigned depth_buffer_factor; 112 unsigned depth_buffer_factor;
117 unsigned back_buffer_factor; 113 unsigned back_buffer_factor;
114 unsigned msaa_samples_factor;
118 GLenum fb_format; 115 GLenum fb_format;
119 GLenum fb_type; 116 GLenum fb_type;
120 int i; 117 int i;
121 118
122 static const GLenum back_buffer_modes[] = { 119 static const GLenum back_buffer_modes[] = {
123 GLX_NONE, GLX_SWAP_UNDEFINED_OML 120 GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
124 }; 121 };
125 122
123 /* TODO probe the hardware of what is supports */
126 depth_bits_array[0] = 0; 124 depth_bits_array[0] = 0;
127 depth_bits_array[1] = depth_bits; 125 depth_bits_array[1] = 24;
128 depth_bits_array[2] = depth_bits; 126 depth_bits_array[2] = 24;
129 127
130 stencil_bits_array[0] = 0; /* no depth or stencil */ 128 stencil_bits_array[0] = 0; /* no depth or stencil */
131 stencil_bits_array[1] = 0; /* z24x8 */ 129 stencil_bits_array[1] = 0; /* z24x8 */
@@ -134,9 +132,10 @@ dri_fill_in_modes(__DRIscreenPrivate *psp,
134 msaa_samples_array[0] = 0; 132 msaa_samples_array[0] = 0;
135 133
136 depth_buffer_factor = 3; 134 depth_buffer_factor = 3;
137 back_buffer_factor = 1; 135 back_buffer_factor = 3;
136 msaa_samples_factor = 1;
138 137
139 num_modes = depth_buffer_factor * back_buffer_factor * 4; 138 num_modes = depth_buffer_factor * back_buffer_factor * msaa_samples_factor * 4;
140 139
141 if (pixel_bits == 16) { 140 if (pixel_bits == 16) {
142 fb_format = GL_RGB; 141 fb_format = GL_RGB;
@@ -148,85 +147,79 @@ dri_fill_in_modes(__DRIscreenPrivate *psp,
148 } 147 }
149 148
150 configs = driCreateConfigs(fb_format, fb_type, 149 configs = driCreateConfigs(fb_format, fb_type,
151 depth_bits_array, 150 depth_bits_array,
152 stencil_bits_array, depth_buffer_factor, 151 stencil_bits_array, depth_buffer_factor,
153 back_buffer_modes, back_buffer_factor, 152 back_buffer_modes, back_buffer_factor,
154 msaa_samples_array, 1); 153 msaa_samples_array, msaa_samples_factor);
155 if (configs == NULL) { 154 if (configs == NULL) {
156 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__); 155 debug_printf("%s: driCreateConfigs failed\n", __FUNCTION__);
157 return NULL; 156 return NULL;
158 } 157 }
159 158
160 return configs; 159 for (i = 0; configs[i]; i++) {
160 m = &configs[i]->modes;
161 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
162 m->visualRating = GLX_SLOW_CONFIG;
163 }
164 }
165
166 return (const const __DRIconfig **) configs;
161} 167}
162 168
163 169
170/**
171 * Get information about previous buffer swaps.
172 */
173int
174dri_get_swap_info(__DRIdrawablePrivate * dPriv,
175 __DRIswapInfo * sInfo)
176{
177 if (dPriv == NULL ||
178 dPriv->driverPrivate == NULL ||
179 sInfo == NULL)
180 return -1;
181 else
182 return 0;
183}
184
164 185
165/* This is the driver specific part of the createNewScreen entry point. 186/**
166 * 187 * This is the driver specific part of the createNewScreen entry point.
188 *
167 * Returns the __GLcontextModes supported by this driver. 189 * Returns the __GLcontextModes supported by this driver.
168 */ 190 */
169static const __DRIconfig **dri_init_screen(__DRIscreenPrivate *sPriv) 191const __DRIconfig **
192dri_init_screen2(__DRIscreenPrivate *sPriv)
170{ 193{
171 static const __DRIversion ddx_expected = { 1, 6, 0 }; /* hw query */
172 static const __DRIversion dri_expected = { 4, 0, 0 };
173 static const __DRIversion drm_expected = { 1, 5, 0 }; /* hw query */
174 struct dri_screen *screen; 194 struct dri_screen *screen;
175 195
176 if (!driCheckDriDdxDrmVersions2("dri", 196 /* Set up dispatch table to cope with all known extensions */
177 &sPriv->dri_version, &dri_expected, 197 dri_init_extensions(NULL);
178 &sPriv->ddx_version, &ddx_expected,
179 &sPriv->drm_version, &drm_expected)) {
180 return NULL;
181 }
182
183 /* Set up dispatch table to cope with all known extensions:
184 */
185 driInitExtensions( NULL, card_extensions, GL_FALSE );
186
187 198
188 screen = CALLOC_STRUCT(dri_screen); 199 screen = CALLOC_STRUCT(dri_screen);
189 if (!screen) 200 if (!screen)
190 goto fail; 201 goto fail;
191 202
192 screen->sPriv = sPriv; 203 screen->sPriv = sPriv;
204 screen->fd = sPriv->fd;
205 dri_get_drm_minor(screen);
206 dri_get_device_id(screen);
193 sPriv->private = (void *) screen; 207 sPriv->private = (void *) screen;
208 sPriv->extensions = dri_screen_extensions;
194 209
195 210
196 /* Search the registered winsys' for one that likes this sPriv. 211 screen->pipe_screen = drm_api_hocks.create_screen(screen->fd, screen->deviceID);
197 * This is required in situations where multiple devices speak to 212 if (!screen->pipe_screen) {
198 * the same DDX and are built into the same binary. 213 debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
199 * 214 goto fail;
200 * Note that cases like Intel i915 vs i965 doesn't fall into this
201 * category because they are built into separate binaries.
202 *
203 * Nonetheless, it's healthy to keep that level of detail out of
204 * this state_tracker.
205 */
206 for (i = 0;
207 i < dri1_winsys_count &&
208 screen->st_winsys == NULL;
209 i++)
210 {
211 screen->dri_winsys =
212 dri_winsys[i]->check_dri_privates( sPriv->pDevPriv,
213 sPriv->pSAREA
214 /* versions, etc?? */));
215 } 215 }
216
217 216
218 driParseOptionInfo(&screen->optionCache, 217 driParseOptionInfo(&screen->optionCache,
219 __driConfigOptions, 218 __driConfigOptions,
220 __driNConfigOptions); 219 __driNConfigOptions);
221 220
222 221 return dri_fill_in_modes(sPriv,
223 /* Plug our info back into the __DRIscreenPrivate: 222 4 * 8,
224 */
225 sPriv->private = (void *) screen;
226 sPriv->extensions = driScreenExtensions;
227
228 return dri_fill_in_modes(sPriv,
229 dri_priv->cpp * 8,
230 24, 223 24,
231 8, 224 8,
232 1); 225 1);
@@ -235,21 +228,32 @@ fail:
235} 228}
236 229
237 230
231void
232dri_destroy_screen(__DRIscreenPrivate * sPriv)
233{
234 struct dri_screen *screen = dri_screen(sPriv);
235
236 screen->pipe_screen->destroy(screen->pipe_screen);
237 FREE(screen);
238 sPriv->private = NULL;
239}
238 240
239const struct __DriverAPIRec driDriverAPI = {
240 .InitScreen = dri_init_screen,
241 .DestroyScreen = dri_destroy_screen,
242 .CreateContext = dri_create_context,
243 .DestroyContext = dri_destroy_context,
244 .CreateBuffer = dri_create_buffer,
245 .DestroyBuffer = dri_destroy_buffer,
246 .SwapBuffers = dri_swap_buffers,
247 .MakeCurrent = dri_make_current,
248 .UnbindContext = dri_unbind_context,
249 .GetSwapInfo = dri_get_swap_info,
250 .GetDrawableMSC = driDrawableGetMSC32,
251 .WaitForMSC = driWaitForMSC32,
252 .CopySubBuffer = dri_copy_sub_buffer,
253 241
254 //.InitScreen2 = dri_init_screen2, 242PUBLIC const struct __DriverAPIRec driDriverAPI = {
243 .InitScreen = NULL,
244 .DestroyScreen = dri_destroy_screen,
245 .CreateContext = dri_create_context,
246 .DestroyContext = dri_destroy_context,
247 .CreateBuffer = dri_create_buffer,
248 .DestroyBuffer = dri_destroy_buffer,
249 .SwapBuffers = dri_swap_buffers,
250 .MakeCurrent = dri_make_current,
251 .UnbindContext = dri_unbind_context,
252 .GetSwapInfo = dri_get_swap_info,
253 .GetDrawableMSC = driDrawableGetMSC32,
254 .WaitForMSC = driWaitForMSC32,
255 .CopySubBuffer = dri_copy_sub_buffer,
256 .InitScreen2 = dri_init_screen2,
255}; 257};
258
259/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_screen.h b/src/gallium/state_trackers/dri2/dri_screen.h
index 12ed86d22a9..fe2676d0be3 100644
--- a/src/gallium/state_trackers/glx/dri/dri_screen.h
+++ b/src/gallium/state_trackers/dri2/dri_screen.h
@@ -18,12 +18,16 @@
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27/*
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
30 */
27 31
28#ifndef DRI_SCREEN_H 32#ifndef DRI_SCREEN_H
29#define DRI_SCREEN_H 33#define DRI_SCREEN_H
@@ -35,27 +39,8 @@
35 39
36struct dri_screen 40struct dri_screen
37{ 41{
38 __DRIScreenPrivate *sPriv; 42 /* dri */
39 struct pipe_winsys *pipe_winsys; 43 __DRIscreenPrivate *sPriv;
40 struct pipe_screen *pipe_screen;
41
42 struct {
43 /* Need a pipe_surface pointer to do client-side swapbuffers:
44 */
45 unsigned long buffer_handle;
46 struct pipe_surface *surface;
47 struct pipe_texture *texture;
48
49 int pitch; /* row stride, in bytes */
50 int width;
51 int height;
52 int size;
53 int cpp; /* for front and back buffers */
54 } front;
55
56 int deviceID;
57 int drmMinor;
58
59 44
60 /** 45 /**
61 * Configuration cache with default values for all contexts 46 * Configuration cache with default values for all contexts
@@ -67,8 +52,16 @@ struct dri_screen
67 * which we need a rendering context, but none is currently bound. 52 * which we need a rendering context, but none is currently bound.
68 */ 53 */
69 struct dri_context *dummyContext; 54 struct dri_context *dummyContext;
70};
71 55
56 /* drm */
57 int deviceID;
58 int fd;
59 int minor;
60
61 /* gallium */
62 struct pipe_winsys *pipe_winsys;
63 struct pipe_screen *pipe_screen;
64};
72 65
73 66
74/** cast wrapper */ 67/** cast wrapper */
@@ -79,5 +72,19 @@ dri_screen(__DRIscreenPrivate *sPriv)
79} 72}
80 73
81 74
75/***********************************************************************
76 * dri_screen.c
77 */
78const __DRIconfig **
79dri_init_screen2(__DRIscreenPrivate *sPriv);
80
81void
82dri_destroy_screen(__DRIscreenPrivate * sPriv);
83
84int
85dri_get_swap_info(__DRIdrawablePrivate * dPriv,
86 __DRIswapInfo * sInfo);
82 87
83#endif 88#endif
89
90/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/glx/dri/dri_drawable.c b/src/gallium/state_trackers/glx/dri/dri_drawable.c
deleted file mode 100644
index b712acda88e..00000000000
--- a/src/gallium/state_trackers/glx/dri/dri_drawable.c
+++ /dev/null
@@ -1,363 +0,0 @@
1/**************************************************************************
2 *
3 * Copyright 2009, VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#include "dri_screen.h"
29#include "dri_context.h"
30#include "dri_swapbuffers.h"
31
32#include "pipe/p_context.h"
33#include "state_tracker/st_public.h"
34#include "state_tracker/st_context.h"
35#include "state_tracker/st_cb_fbo.h"
36
37
38static void
39blit_swapbuffers(__DRIdrawablePrivate *dPriv,
40 __DRIcontextPrivate *cPriv,
41 struct pipe_surface *src,
42 const drm_clip_rect_t *rect)
43{
44 struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
45 struct dri_drawable *fb = dri_drawable(dPriv);
46 struct dri_context *context = dri_context(cPriv);
47
48 const int nbox = dPriv->numClipRects;
49 const drm_clip_rect_t *pbox = dPriv->pClipRects;
50
51 struct pipe_surface *dest = fb->front_surface;
52 const int backWidth = fb->stfb->Base.Width;
53 const int backHeight = fb->stfb->Base.Height;
54 int i;
55
56 for (i = 0; i < nbox; i++, pbox++) {
57 drm_clip_rect_t box;
58 drm_clip_rect_t sbox;
59
60 if (pbox->x1 > pbox->x2 ||
61 pbox->y1 > pbox->y2 ||
62 (pbox->x2 - pbox->x1) > dest->width ||
63 (pbox->y2 - pbox->y1) > dest->height)
64 continue;
65
66 box = *pbox;
67
68 if (rect) {
69 drm_clip_rect_t rrect;
70
71 rrect.x1 = dPriv->x + rect->x1;
72 rrect.y1 = (dPriv->h - rect->y1 - rect->y2) + dPriv->y;
73 rrect.x2 = rect->x2 + rrect.x1;
74 rrect.y2 = rect->y2 + rrect.y1;
75 if (rrect.x1 > box.x1)
76 box.x1 = rrect.x1;
77 if (rrect.y1 > box.y1)
78 box.y1 = rrect.y1;
79 if (rrect.x2 < box.x2)
80 box.x2 = rrect.x2;
81 if (rrect.y2 < box.y2)
82 box.y2 = rrect.y2;
83
84 if (box.x1 > box.x2 || box.y1 > box.y2)
85 continue;
86 }
87
88 /* restrict blit to size of actually rendered area */
89 if (box.x2 - box.x1 > backWidth)
90 box.x2 = backWidth + box.x1;
91 if (box.y2 - box.y1 > backHeight)
92 box.y2 = backHeight + box.y1;
93
94 debug_printf("%s: box %d,%d-%d,%d\n", __FUNCTION__,
95 box.x1, box.y1, box.x2, box.y2);
96
97 sbox.x1 = box.x1 - dPriv->x;
98 sbox.y1 = box.y1 - dPriv->y;
99
100 ctx->st->pipe->surface_copy( ctx->st->pipe,
101 FALSE,
102 dest,
103 box.x1, box.y1,
104 src,
105 sbox.x1, sbox.y1,
106 box.x2 - box.x1,
107 box.y2 - box.y1 );
108 }
109}
110
111/**
112 * Display a colorbuffer surface in an X window.
113 * Used for SwapBuffers and flushing front buffer rendering.
114 *
115 * \param dPriv the window/drawable to display into
116 * \param surf the surface to display
117 * \param rect optional subrect of surface to display (may be NULL).
118 */
119static void
120dri_display_surface(__DRIdrawablePrivate *dPriv,
121 struct pipe_surface *source,
122 const drm_clip_rect_t *rect)
123{
124 struct dri_drawable *drawable = dri_drawable(dPriv);
125 struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
126 struct dri_context *context = screen->dummy_context;
127 struct pipe_winsys *winsys = screen->winsys;
128
129 if (!context)
130 return;
131
132 if (drawable->last_swap_fence) {
133 winsys->fence_finish( winsys,
134 drawable->last_swap_fence,
135 0 );
136
137 winsys->fence_reference( winsys,
138 &drawable->last_swap_fence,
139 NULL );
140 }
141
142 drawable->last_swap_fence = drawable->first_swap_fence;
143 drawable->first_swap_fence = NULL;
144
145 /* Call lock_hardware to update dPriv cliprects.
146 */
147 dri_lock_hardware(context, drawable);
148 {
149 if (dPriv->numClipRects) {
150 blit_swapbuffers( context, dPriv, source, rect );
151 }
152 }
153 dri_unlock_hardware(context);
154
155 if (drawble->stamp != drawable->dPriv->lastStamp) {
156 dri_update_window_size( dpriv );
157 }
158}
159
160
161
162/**
163 * This will be called a drawable is known to have moved/resized.
164 */
165void
166dri_update_window_size(__DRIdrawablePrivate *dPriv)
167{
168 struct dri_drawable *drawable = dri_drawable(dPriv);
169 st_resize_framebuffer(drawable->stfb, dPriv->w, dPriv->h);
170 drawable->stamp = dPriv->lastStamp;
171}
172
173
174
175void
176dri_swap_buffers(__DRIdrawablePrivate * dPriv)
177{
178 struct dri_drawable *drawable = dri_drawable(dPriv);
179 struct pipe_surface *back_surf;
180
181 assert(drawable);
182 assert(drawable->stfb);
183
184 back_surf = st_get_framebuffer_surface(drawable->stfb,
185 ST_SURFACE_BACK_LEFT);
186 if (back_surf) {
187 st_notify_swapbuffers(drawable->stfb);
188 dri_display_surface(dPriv, back_surf, NULL);
189 st_notify_swapbuffers_complete(drawable->stfb);
190 }
191}
192
193
194/**
195 * Called via glXCopySubBufferMESA() to copy a subrect of the back
196 * buffer to the front buffer/screen.
197 */
198void
199dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h)
200{
201 struct dri_drawable *drawable = dri_drawable(dPriv);
202 struct pipe_surface *back_surf;
203
204 assert(drawable);
205 assert(drawable->stfb);
206
207 back_surf = st_get_framebuffer_surface(drawable->stfb,
208 ST_SURFACE_BACK_LEFT);
209 if (back_surf) {
210 drm_clip_rect_t rect;
211 rect.x1 = x;
212 rect.y1 = y;
213 rect.x2 = w;
214 rect.y2 = h;
215
216 st_notify_swapbuffers(drawable->stfb);
217 dri_display_surface(dPriv, back_surf, &rect);
218 }
219}
220
221
222
223/*
224 * The state tracker keeps track of whether the fake frontbuffer has
225 * been touched by any rendering since the last time we copied its
226 * contents to the real frontbuffer. Our task is easy:
227 */
228static void
229dri_flush_frontbuffer( struct pipe_winsys *winsys,
230 struct pipe_surface *surf,
231 void *context_private)
232{
233 struct dri_context *dri = (struct dri_context *) context_private;
234 __DRIdrawablePrivate *dPriv = dri->driDrawable;
235
236 dri_display_surface(dPriv, surf, NULL);
237}
238
239
240
241/* Need to create a surface which wraps the front surface to support
242 * client-side swapbuffers.
243 */
244static void
245dri_create_front_surface(struct dri_screen *screen,
246 struct pipe_winsys *winsys,
247 unsigned handle)
248{
249 struct pipe_screen *pipe_screen = screen->pipe_screen;
250 struct pipe_texture *texture;
251 struct pipe_texture templat;
252 struct pipe_surface *surface;
253 struct pipe_buffer *buffer;
254 unsigned pitch;
255
256 assert(screen->front.cpp == 4);
257
258// buffer = dri_buffer_from_handle(screen->winsys,
259// "front", handle);
260
261 if (!buffer)
262 return;
263
264 screen->front.buffer = dri_bo(buffer);
265
266 memset(&templat, 0, sizeof(templat));
267 templat.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
268 templat.target = PIPE_TEXTURE_2D;
269 templat.last_level = 0;
270 templat.depth[0] = 1;
271 templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
272 templat.width[0] = screen->front.width;
273 templat.height[0] = screen->front.height;
274 pf_get_block(templat.format, &templat.block);
275 pitch = screen->front.pitch;
276
277 texture = pipe_screen->texture_blanket(pipe_screen,
278 &templat,
279 &pitch,
280 buffer);
281
282 /* Unref the buffer we don't need it anyways */
283 pipe_buffer_reference(screen, &buffer, NULL);
284
285 surface = pipe_screen->get_tex_surface(pipe_screen,
286 texture,
287 0,
288 0,
289 0,
290 PIPE_BUFFER_USAGE_GPU_WRITE);
291
292 screen->front.texture = texture;
293 screen->front.surface = surface;
294}
295
296/**
297 * This is called when we need to set up GL rendering to a new X window.
298 */
299static boolean
300dri_create_buffer(__DRIscreenPrivate *sPriv,
301 __DRIdrawablePrivate *dPriv,
302 const __GLcontextModes *visual,
303 boolean isPixmap)
304{
305 enum pipe_format colorFormat, depthFormat, stencilFormat;
306 struct dri_drawable *drawable;
307
308 if (isPixmap)
309 goto fail; /* not implemented */
310
311 drawable = CALLOC_STRUCT(dri_drawable);
312 if (drawable == NULL)
313 goto fail;
314
315 /* XXX: todo: use the pipe_screen queries to figure out which
316 * render targets are supportable.
317 */
318 if (visual->redBits == 5)
319 colorFormat = PIPE_FORMAT_R5G6B5_UNORM;
320 else
321 colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM;
322
323 if (visual->depthBits == 16)
324 depthFormat = PIPE_FORMAT_Z16_UNORM;
325 else if (visual->depthBits == 24) {
326 if (visual->stencilBits == 8)
327 depthFormat = PIPE_FORMAT_S8Z24_UNORM;
328 else
329 depthFormat = PIPE_FORMAT_X8Z24_UNORM;
330 }
331
332 drawable->stfb = st_create_framebuffer(visual,
333 colorFormat,
334 depthFormat,
335 dPriv->w,
336 dPriv->h,
337 (void*) drawable);
338 if (drawable->stfb == NULL)
339 goto fail;
340
341 dPriv->driverPrivate = (void *) drawable;
342 return GL_TRUE;
343
344fail:
345 FREE(drawable);
346 return GL_FALSE;
347}
348
349static void
350dri_destroy_buffer(__DRIdrawablePrivate *dPriv)
351{
352 struct dri_drawable *drawable = dri_drawable(dPriv);
353
354 /* No particular need to wait on fences before dereferencing them:
355 */
356 winsys->fence_reference( winsys, &ctx->last_swap_fence, NULL );
357 winsys->fence_reference( winsys, &ctx->first_swap_fence, NULL );
358
359 st_unreference_framebuffer(drawable->stfb);
360
361 FREE(drawable);
362}
363
diff --git a/src/gallium/state_trackers/glx/dri/dri_lock.c b/src/gallium/state_trackers/glx/dri/dri_lock.c
deleted file mode 100644
index b272ab55f34..00000000000
--- a/src/gallium/state_trackers/glx/dri/dri_lock.c
+++ /dev/null
@@ -1,90 +0,0 @@
1/**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29#include "pipe/p_thread.h"
30#include "dri_context.h"
31#include "xf86drm.h"
32
33pipe_static_mutex( lockMutex );
34
35static void
36dri_contended_lock(struct dri_context *ctx)
37{
38 __DRIdrawablePrivate *dPriv = ctx->dPriv;
39 __DRIcontextPrivate *cPriv = ctx->cPriv;
40 __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
41
42 drmGetLock(sPriv->fd, cPriv->hHWContext, 0);
43
44 /* Perform round trip communication with server (including dropping
45 * and retaking the above lock) to update window dimensions:
46 */
47 if (dPriv)
48 DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv);
49}
50
51
52/* Lock the hardware and validate our state.
53 */
54void dri_lock_hardware( struct dri_context *ctx )
55{
56 __DRIcontextPrivate *cPriv = ctx->cPriv;
57 __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
58 char __ret = 0;
59
60 pipe_mutex_lock(lockMutex);
61 assert(!ctx->locked);
62
63 DRM_CAS((drmLock *) &sPriv->pSAREA->lock,
64 cPriv->hHWContext,
65 (DRM_LOCK_HELD | cPriv->hHWContext),
66 __ret);
67
68 if (__ret)
69 dri_contended_lock( ctx );
70
71 ctx->locked = TRUE;
72}
73
74
75/* Unlock the hardware using the global current context
76 */
77void dri_unlock_hardware( struct dri_context *ctx )
78{
79 __DRIcontextPrivate *cPriv = ctx->cPriv;
80 __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
81
82 assert(ctx->locked);
83 ctx->locked = FALSE;
84
85 DRM_UNLOCK(sPriv->fd,
86 (drmLock *) &sPriv->pSAREA->lock,
87 cPriv->hHWContext);
88
89 pipe_mutex_unlock(lockMutex);
90}