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"
37 #include "state_tracker/drm_api.h"
38 #include "state_tracker/st_public.h"
39 #include "state_tracker/st_context.h"
40 #include "pipe/p_context.h"
42 #include "dri_context.h"
44 #include "util/u_memory.h"
48 dri_create_context(const __GLcontextModes
*visual
,
49 __DRIcontextPrivate
*cPriv
,
50 void *sharedContextPrivate
)
52 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
53 struct dri_screen
*screen
= dri_screen(sPriv
);
54 struct dri_context
*ctx
= NULL
;
55 struct st_context
*st_share
= NULL
;
57 if (sharedContextPrivate
) {
58 st_share
= ((struct dri_context
*) sharedContextPrivate
)->st
;
61 ctx
= CALLOC_STRUCT(dri_context
);
65 cPriv
->driverPrivate
= ctx
;
69 driParseConfigFiles(&ctx
->optionCache
,
74 ctx
->pipe
= drm_api_hooks
.create_context(screen
->pipe_screen
);
76 if (ctx
->pipe
== NULL
)
79 /* used in dri_flush_frontbuffer */
80 ctx
->pipe
->priv
= ctx
;
82 ctx
->st
= st_create_context(ctx
->pipe
, visual
, st_share
);
86 dri_init_extensions(ctx
);
92 st_destroy_context(ctx
->st
);
95 ctx
->pipe
->destroy(ctx
->pipe
);
103 dri_destroy_context(__DRIcontextPrivate
*cPriv
)
105 struct dri_context
*ctx
= dri_context(cPriv
);
106 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
108 /* No particular reason to wait for command completion before
109 * destroying a context, but it is probably worthwhile flushing it
110 * to avoid having to add code elsewhere to cope with flushing a
111 * partially destroyed context.
113 st_flush(ctx
->st
, 0, NULL
);
115 if (screen
->dummyContext
== ctx
)
116 screen
->dummyContext
= NULL
;
118 /* Also frees ctx->pipe?
120 st_destroy_context(ctx
->st
);
127 dri_unbind_context(__DRIcontextPrivate
*cPriv
)
129 struct dri_context
*ctx
= dri_context(cPriv
);
130 st_flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
131 /* XXX make_current(NULL)? */
137 dri_make_current(__DRIcontextPrivate
*cPriv
,
138 __DRIdrawablePrivate
*driDrawPriv
,
139 __DRIdrawablePrivate
*driReadPriv
)
142 struct dri_context
*ctx
= dri_context(cPriv
);
143 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
144 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
145 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
147 /* This is for situations in which we need a rendering context but
148 * there may not be any currently bound.
150 screen
->dummyContext
= ctx
;
152 st_make_current(ctx
->st
,
156 /* used in dri_flush_frontbuffer */
157 ctx
->dPriv
= driDrawPriv
;
160 dri_get_buffers(driDrawPriv
);
161 if (driDrawPriv
!= driReadPriv
&& driReadPriv
)
162 dri_get_buffers(driReadPriv
);
164 st_make_current(NULL
, NULL
, NULL
);
170 /* vim: set sw=3 ts=8 sts=3 expandtab: */