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 "state_tracker/st_context.h"
39 #include "pipe/p_context.h"
41 #include "dri_context.h"
43 #include "util/u_memory.h"
46 dri_create_context(const __GLcontextModes
* visual
,
47 __DRIcontextPrivate
* cPriv
, void *sharedContextPrivate
)
49 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
50 struct dri_screen
*screen
= dri_screen(sPriv
);
51 struct dri_context
*ctx
= NULL
;
52 struct st_context
*st_share
= NULL
;
54 if (sharedContextPrivate
) {
55 st_share
= ((struct dri_context
*)sharedContextPrivate
)->st
;
58 ctx
= CALLOC_STRUCT(dri_context
);
62 cPriv
->driverPrivate
= ctx
;
65 ctx
->lock
= screen
->drmLock
;
69 driParseConfigFiles(&ctx
->optionCache
,
70 &screen
->optionCache
, sPriv
->myNum
, "dri");
72 ctx
->pipe
= screen
->api
->create_context(screen
->api
, screen
->pipe_screen
);
74 if (ctx
->pipe
== NULL
)
77 /* used in dri_flush_frontbuffer */
78 ctx
->pipe
->priv
= ctx
;
80 ctx
->st
= st_create_context(ctx
->pipe
, visual
, st_share
);
84 dri_init_extensions(ctx
);
90 st_destroy_context(ctx
->st
);
93 ctx
->pipe
->destroy(ctx
->pipe
);
100 dri_destroy_context(__DRIcontextPrivate
* cPriv
)
102 struct dri_context
*ctx
= dri_context(cPriv
);
103 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
105 /* No particular reason to wait for command completion before
106 * destroying a context, but it is probably worthwhile flushing it
107 * to avoid having to add code elsewhere to cope with flushing a
108 * partially destroyed context.
110 st_flush(ctx
->st
, 0, NULL
);
112 if (screen
->dummyContext
== ctx
)
113 screen
->dummyContext
= NULL
;
115 /* Also frees ctx->pipe?
117 st_destroy_context(ctx
->st
);
123 dri_unbind_context(__DRIcontextPrivate
* cPriv
)
126 struct dri_context
*ctx
= dri_context(cPriv
);
128 if (--ctx
->bind_count
== 0) {
129 if (ctx
->st
&& ctx
->st
== st_get_current()) {
130 st_flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
131 st_make_current(NULL
, NULL
, NULL
);
140 dri_make_current(__DRIcontextPrivate
* cPriv
,
141 __DRIdrawablePrivate
* driDrawPriv
,
142 __DRIdrawablePrivate
* driReadPriv
)
145 struct dri_context
*ctx
= dri_context(cPriv
);
146 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
147 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
148 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
149 struct st_context
*old_st
= st_get_current();
151 if (old_st
&& old_st
!= ctx
->st
)
152 st_flush(old_st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
156 /* This is for situations in which we need a rendering context but
157 * there may not be any currently bound.
159 screen
->dummyContext
= ctx
;
161 if (ctx
->dPriv
!= driDrawPriv
) {
162 ctx
->dPriv
= driDrawPriv
;
163 ctx
->d_stamp
= driDrawPriv
->lastStamp
- 1;
165 if (ctx
->rPriv
!= driReadPriv
) {
166 ctx
->rPriv
= driReadPriv
;
167 ctx
->r_stamp
= driReadPriv
->lastStamp
- 1;
170 st_make_current(ctx
->st
, draw
->stfb
, read
->stfb
);
172 if (__dri1_api_hooks
) {
173 dri1_update_drawables(ctx
, draw
, read
);
176 dri_get_buffers(driDrawPriv
);
177 if (driDrawPriv
!= driReadPriv
&& driReadPriv
)
178 dri_get_buffers(driReadPriv
);
181 st_make_current(NULL
, NULL
, NULL
);
188 st_dri_lock(struct pipe_context
*pipe
)
190 dri_lock((struct dri_context
*)pipe
->priv
);
194 st_dri_unlock(struct pipe_context
*pipe
)
196 dri_unlock((struct dri_context
*)pipe
->priv
);
200 st_dri_is_locked(struct pipe_context
*pipe
)
202 return ((struct dri_context
*)pipe
->priv
)->isLocked
;
206 st_dri_lost_lock(struct pipe_context
*pipe
)
208 return ((struct dri_context
*)pipe
->priv
)->wsLostLock
;
212 st_dri_clear_lost_lock(struct pipe_context
*pipe
)
214 ((struct dri_context
*)pipe
->priv
)->wsLostLock
= FALSE
;
217 struct dri1_api_lock_funcs dri1_lf
= {
219 .unlock
= st_dri_unlock
,
220 .is_locked
= st_dri_is_locked
,
221 .is_lock_lost
= st_dri_lost_lock
,
222 .clear_lost_lock
= st_dri_clear_lost_lock
225 /* vim: set sw=3 ts=8 sts=3 expandtab: */