1 /**************************************************************************
3 * Copyright 2009, VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 * Author: Keith Whitwell <keithw@vmware.com>
29 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
32 #include "dri_screen.h"
34 #include "dri_drawable.h"
35 #include "state_tracker/drm_api.h"
36 #include "state_tracker/dri1_api.h"
37 #include "state_tracker/st_public.h"
38 #include "pipe/p_context.h"
40 #include "dri_context.h"
42 #include "util/u_memory.h"
45 dri_create_context(const __GLcontextModes
* visual
,
46 __DRIcontext
* cPriv
, void *sharedContextPrivate
)
48 __DRIscreen
*sPriv
= cPriv
->driScreenPriv
;
49 struct dri_screen
*screen
= dri_screen(sPriv
);
50 struct dri_context
*ctx
= NULL
;
51 struct st_context
*st_share
= NULL
;
53 if (sharedContextPrivate
) {
54 st_share
= ((struct dri_context
*)sharedContextPrivate
)->st
;
57 ctx
= CALLOC_STRUCT(dri_context
);
61 cPriv
->driverPrivate
= ctx
;
64 ctx
->lock
= screen
->drmLock
;
68 driParseConfigFiles(&ctx
->optionCache
,
69 &screen
->optionCache
, sPriv
->myNum
, "dri");
71 ctx
->pipe
= screen
->pipe_screen
->context_create( screen
->pipe_screen
,
74 if (ctx
->pipe
== NULL
)
77 ctx
->st
= st_create_context(ctx
->pipe
, visual
, st_share
);
81 dri_init_extensions(ctx
);
87 st_destroy_context(ctx
->st
);
90 ctx
->pipe
->destroy(ctx
->pipe
);
97 dri_destroy_context(__DRIcontext
* cPriv
)
99 struct dri_context
*ctx
= dri_context(cPriv
);
101 /* note: we are freeing values and nothing more because
102 * driParseConfigFiles allocated values only - the rest
103 * is owned by screen optionCache.
105 FREE(ctx
->optionCache
.values
);
107 /* No particular reason to wait for command completion before
108 * destroying a context, but it is probably worthwhile flushing it
109 * to avoid having to add code elsewhere to cope with flushing a
110 * partially destroyed context.
112 st_flush(ctx
->st
, 0, NULL
);
114 /* Also frees ctx->pipe?
116 st_destroy_context(ctx
->st
);
122 dri_unbind_context(__DRIcontext
* cPriv
)
125 struct dri_context
*ctx
= dri_context(cPriv
);
127 if (--ctx
->bind_count
== 0) {
128 if (ctx
->st
&& ctx
->st
== st_get_current()) {
129 st_flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
130 st_make_current(NULL
, NULL
, NULL
, NULL
);
139 dri_make_current(__DRIcontext
* cPriv
,
140 __DRIdrawable
* driDrawPriv
,
141 __DRIdrawable
* driReadPriv
)
144 struct dri_context
*ctx
= dri_context(cPriv
);
145 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
146 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
147 struct st_context
*old_st
= st_get_current();
149 if (old_st
&& old_st
!= ctx
->st
)
150 st_flush(old_st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
154 if (ctx
->dPriv
!= driDrawPriv
) {
155 ctx
->dPriv
= driDrawPriv
;
156 ctx
->d_stamp
= driDrawPriv
->lastStamp
- 1;
158 if (ctx
->rPriv
!= driReadPriv
) {
159 ctx
->rPriv
= driReadPriv
;
160 ctx
->r_stamp
= driReadPriv
->lastStamp
- 1;
163 /* DRI co-state tracker currently overrides flush_frontbuffer.
164 * When this is fixed, will need to pass the drawable in the
165 * fourth parameter here so that when Mesa calls
166 * flush_frontbuffer directly (in front-buffer rendering), it
167 * will have access to the drawable argument:
169 st_make_current(ctx
->st
, draw
->stfb
, read
->stfb
, ctx
);
171 if (__dri1_api_hooks
) {
172 dri1_update_drawables(ctx
, draw
, read
);
174 dri_update_buffer(ctx
->pipe
->screen
,
178 st_make_current(NULL
, NULL
, NULL
, NULL
);
185 st_dri_lock(struct pipe_context
*pipe
)
187 dri_lock((struct dri_context
*)pipe
->priv
);
191 st_dri_unlock(struct pipe_context
*pipe
)
193 dri_unlock((struct dri_context
*)pipe
->priv
);
197 st_dri_is_locked(struct pipe_context
*pipe
)
199 return ((struct dri_context
*)pipe
->priv
)->isLocked
;
203 st_dri_lost_lock(struct pipe_context
*pipe
)
205 return ((struct dri_context
*)pipe
->priv
)->wsLostLock
;
209 st_dri_clear_lost_lock(struct pipe_context
*pipe
)
211 ((struct dri_context
*)pipe
->priv
)->wsLostLock
= FALSE
;
214 struct dri1_api_lock_funcs dri1_lf
= {
216 .unlock
= st_dri_unlock
,
217 .is_locked
= st_dri_is_locked
,
218 .is_lock_lost
= st_dri_lost_lock
,
219 .clear_lost_lock
= st_dri_clear_lost_lock
222 /* vim: set sw=3 ts=8 sts=3 expandtab: */