34d9a932ead162de2e9dd5d0c99adc6c82c90022
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"
33 #include "dri_drawable.h"
34 #include "dri_context.h"
35 #include "dri_st_api.h"
37 #include "pipe/p_context.h"
38 #include "util/u_memory.h"
41 dri_create_context(const __GLcontextModes
* visual
,
42 __DRIcontext
* cPriv
, void *sharedContextPrivate
)
44 struct st_api
*stapi
= dri_get_st_api();
45 __DRIscreen
*sPriv
= cPriv
->driScreenPriv
;
46 struct dri_screen
*screen
= dri_screen(sPriv
);
47 struct dri_context
*ctx
= NULL
;
48 struct st_context_iface
*st_share
= NULL
;
49 struct st_visual stvis
;
51 if (sharedContextPrivate
) {
52 st_share
= ((struct dri_context
*)sharedContextPrivate
)->st
;
55 ctx
= CALLOC_STRUCT(dri_context
);
59 cPriv
->driverPrivate
= ctx
;
62 ctx
->lock
= screen
->drmLock
;
64 driParseConfigFiles(&ctx
->optionCache
,
65 &screen
->optionCache
, sPriv
->myNum
, "dri");
67 dri_fill_st_visual(&stvis
, screen
, visual
);
68 ctx
->st
= stapi
->create_context(stapi
, screen
->smapi
, &stvis
, st_share
);
71 ctx
->st
->st_manager_private
= (void *) ctx
;
73 dri_init_extensions(ctx
);
79 ctx
->st
->destroy(ctx
->st
);
86 dri_destroy_context(__DRIcontext
* cPriv
)
88 struct dri_context
*ctx
= dri_context(cPriv
);
90 /* note: we are freeing values and nothing more because
91 * driParseConfigFiles allocated values only - the rest
92 * is owned by screen optionCache.
94 FREE(ctx
->optionCache
.values
);
96 /* No particular reason to wait for command completion before
97 * destroying a context, but it is probably worthwhile flushing it
98 * to avoid having to add code elsewhere to cope with flushing a
99 * partially destroyed context.
101 ctx
->st
->flush(ctx
->st
, 0, NULL
);
102 ctx
->st
->destroy(ctx
->st
);
108 dri_unbind_context(__DRIcontext
* cPriv
)
110 struct st_api
*stapi
= dri_get_st_api();
113 struct dri_context
*ctx
= dri_context(cPriv
);
115 if (--ctx
->bind_count
== 0) {
116 if (ctx
->st
== stapi
->get_current(stapi
)) {
117 ctx
->st
->flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
118 stapi
->make_current(stapi
, NULL
, NULL
, NULL
);
127 dri_make_current(__DRIcontext
* cPriv
,
128 __DRIdrawable
* driDrawPriv
,
129 __DRIdrawable
* driReadPriv
)
131 struct st_api
*stapi
= dri_get_st_api();
134 struct dri_context
*ctx
= dri_context(cPriv
);
135 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
136 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
137 struct st_context_iface
*old_st
;
139 old_st
= stapi
->get_current(stapi
);
140 if (old_st
&& old_st
!= ctx
->st
)
141 ctx
->st
->flush(old_st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
145 if (ctx
->dPriv
!= driDrawPriv
) {
146 ctx
->dPriv
= driDrawPriv
;
147 draw
->texture_stamp
= driDrawPriv
->lastStamp
- 1;
149 if (ctx
->rPriv
!= driReadPriv
) {
150 ctx
->rPriv
= driReadPriv
;
151 read
->texture_stamp
= driReadPriv
->lastStamp
- 1;
154 stapi
->make_current(stapi
, ctx
->st
, draw
->stfb
, read
->stfb
);
157 stapi
->make_current(stapi
, NULL
, NULL
, NULL
);
164 dri_get_current(void)
166 struct st_api
*stapi
= dri_get_st_api();
167 struct st_context_iface
*st
;
169 st
= stapi
->get_current(stapi
);
171 return (struct dri_context
*) (st
) ? st
->st_manager_private
: NULL
;
174 /* vim: set sw=3 ts=8 sts=3 expandtab: */