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>
34 #include "dri_screen.h"
35 #include "dri_drawable.h"
36 #include "dri_context.h"
38 #include "pipe/p_context.h"
39 #include "state_tracker/st_context.h"
42 dri_init_extensions(struct dri_context
*ctx
)
44 struct st_context
*st
= (struct st_context
*) ctx
->st
;
46 /* New extensions should be added in mesa/state_tracker/st_extensions.c
47 * and not in this file. */
48 driInitExtensions(st
->ctx
, NULL
, GL_FALSE
);
52 dri_create_context(gl_api api
, const __GLcontextModes
* visual
,
53 __DRIcontext
* cPriv
, void *sharedContextPrivate
)
55 __DRIscreen
*sPriv
= cPriv
->driScreenPriv
;
56 struct dri_screen
*screen
= dri_screen(sPriv
);
57 struct st_api
*stapi
= screen
->st_api
;
58 struct dri_context
*ctx
= NULL
;
59 struct st_context_iface
*st_share
= NULL
;
60 struct st_visual stvis
;
62 if (sharedContextPrivate
) {
63 st_share
= ((struct dri_context
*)sharedContextPrivate
)->st
;
66 ctx
= CALLOC_STRUCT(dri_context
);
70 cPriv
->driverPrivate
= ctx
;
73 ctx
->lock
= screen
->drmLock
;
75 driParseConfigFiles(&ctx
->optionCache
,
76 &screen
->optionCache
, sPriv
->myNum
, "dri");
78 dri_fill_st_visual(&stvis
, screen
, visual
);
79 ctx
->st
= stapi
->create_context(stapi
, &screen
->base
, &stvis
, st_share
);
82 ctx
->st
->st_manager_private
= (void *) ctx
;
84 dri_init_extensions(ctx
);
90 ctx
->st
->destroy(ctx
->st
);
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 ctx
->st
->flush(ctx
->st
, 0, NULL
);
113 ctx
->st
->destroy(ctx
->st
);
119 dri_unbind_context(__DRIcontext
* cPriv
)
121 /* dri_util.c ensures cPriv is not null */
122 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
123 struct dri_context
*ctx
= dri_context(cPriv
);
124 struct st_api
*stapi
= screen
->st_api
;
126 if (--ctx
->bind_count
== 0) {
127 if (ctx
->st
== stapi
->get_current(stapi
)) {
128 ctx
->st
->flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
129 stapi
->make_current(stapi
, NULL
, NULL
, NULL
);
137 dri_make_current(__DRIcontext
* cPriv
,
138 __DRIdrawable
* driDrawPriv
,
139 __DRIdrawable
* driReadPriv
)
141 /* dri_util.c ensures cPriv is not null */
142 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
143 struct dri_context
*ctx
= dri_context(cPriv
);
144 struct st_api
*stapi
= screen
->st_api
;
145 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
146 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
147 struct st_context_iface
*old_st
= stapi
->get_current(stapi
);
149 if (old_st
&& old_st
!= ctx
->st
)
150 old_st
->flush(old_st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
154 if (ctx
->dPriv
!= driDrawPriv
) {
155 ctx
->dPriv
= driDrawPriv
;
156 draw
->texture_stamp
= driDrawPriv
->lastStamp
- 1;
158 if (ctx
->rPriv
!= driReadPriv
) {
159 ctx
->rPriv
= driReadPriv
;
160 read
->texture_stamp
= driReadPriv
->lastStamp
- 1;
163 stapi
->make_current(stapi
, ctx
->st
, &draw
->base
, &read
->base
);
169 dri_get_current(__DRIscreen
*sPriv
)
171 struct dri_screen
*screen
= dri_screen(sPriv
);
172 struct st_api
*stapi
= screen
->st_api
;
173 struct st_context_iface
*st
;
175 st
= stapi
->get_current(stapi
);
177 return (struct dri_context
*) (st
) ? st
->st_manager_private
: NULL
;
180 /* vim: set sw=3 ts=8 sts=3 expandtab: */