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 TUNGSTEN GRAPHICS 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 **************************************************************************/
29 #include "dri_screen.h"
30 #include "dri_context.h"
31 #include "dri_winsys.h"
33 #include "state_tracker/st_public.h"
34 #include "state_tracker/st_context.h"
35 #include "pipe/p_context.h"
37 #include "util/u_memory.h"
41 dri_create_context(const __GLcontextModes
*visual
,
42 __DRIcontextPrivate
*cPriv
,
43 void *sharedContextPrivate
)
45 __DRIscreenPrivate
*sPriv
= cPriv
->driScreenPriv
;
46 struct dri_screen
*screen
= dri_screen(sPriv
);
47 struct dri_context
*ctx
= NULL
;
48 struct st_context
*st_share
= NULL
;
50 if (sharedContextPrivate
) {
51 st_share
= ((struct dri_context
*) sharedContextPrivate
)->st
;
54 ctx
= CALLOC_STRUCT(dri_context
);
58 cPriv
->driverPrivate
= ctx
;
62 driParseConfigFiles(&ctx
->optionCache
,
67 ctx
->pipe
= screen
->pipe_screen
->create_context(screen
->pipe_screen
,
70 if (ctx
->pipe
== NULL
)
73 ctx
->pipe
->priv
= ctx
; /* I guess */
75 ctx
->st
= st_create_context(ctx
->pipe
, visual
, st_share
);
79 dri_init_extensions( ctx
);
85 st_destroy_context( ctx
->st
);
88 ctx
->pipe
->destroy( ctx
->pipe
);
96 dri_destroy_context(__DRIcontextPrivate
*cPriv
)
98 struct dri_context
*ctx
= dri_context(cPriv
);
99 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
100 struct pipe_winsys
*winsys
= screen
->winsys
;
102 /* No particular reason to wait for command completion before
103 * destroying a context, but it is probably worthwhile flushing it
104 * to avoid having to add code elsewhere to cope with flushing a
105 * partially destroyed context.
109 if (screen
->dummyContext
== ctx
)
110 screen
->dummyContext
= NULL
;
112 /* Also frees ctx->pipe?
114 st_destroy_context(ctx
->st
);
121 dri_unbind_context(__DRIcontextPrivate
*cPriv
)
123 struct dri_context
*ctx
= dri_context(cPriv
);
124 st_flush(ctx
->st
, PIPE_FLUSH_RENDER_CACHE
, NULL
);
125 /* XXX make_current(NULL)? */
131 dri_make_current(__DRIcontextPrivate
*cPriv
,
132 __DRIdrawablePrivate
*driDrawPriv
,
133 __DRIdrawablePrivate
*driReadPriv
)
136 struct dri_context
*ctx
= dri_context(cPriv
);
137 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
138 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
139 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
141 /* This is for situations in which we need a rendering context but
142 * there may not be any currently bound.
144 screen
->dummyContext
= ctx
;
146 st_make_current( ctx
->st
,
150 ctx
->dPriv
= driDrawPriv
;
152 /* Update window sizes if necessary:
154 if (draw
->stamp
!= driDrawPriv
->lastStamp
) {
155 dri_update_window_size( draw
);
158 if (read
->stamp
!= driReadPriv
->lastStamp
) {
159 dri_update_window_size( read
);
164 st_make_current(NULL
, NULL
, NULL
);