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_pp_query(struct dri_context
*ctx
)
46 for (i
= 0; i
< PP_FILTERS
; i
++) {
47 ctx
->pp_enabled
[i
] = driQueryOptioni(&ctx
->optionCache
, pp_filters
[i
].name
);
52 dri_create_context(gl_api api
, const struct gl_config
* 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_context_attribs attribs
;
62 memset(&attribs
, 0, sizeof(attribs
));
65 attribs
.profile
= ST_PROFILE_OPENGL_ES1
;
68 attribs
.profile
= ST_PROFILE_OPENGL_ES2
;
71 attribs
.profile
= ST_PROFILE_DEFAULT
;
75 if (sharedContextPrivate
) {
76 st_share
= ((struct dri_context
*)sharedContextPrivate
)->st
;
79 ctx
= CALLOC_STRUCT(dri_context
);
83 cPriv
->driverPrivate
= ctx
;
86 ctx
->lock
= screen
->drmLock
;
88 driParseConfigFiles(&ctx
->optionCache
,
89 &screen
->optionCache
, sPriv
->myNum
, "dri");
91 dri_fill_st_visual(&attribs
.visual
, screen
, visual
);
92 ctx
->st
= stapi
->create_context(stapi
, &screen
->base
, &attribs
, st_share
);
95 ctx
->st
->st_manager_private
= (void *) ctx
;
98 // Context successfully created. See if post-processing is requested.
101 ctx
->pp
= pp_init(screen
->base
.screen
, ctx
->pp_enabled
);
107 ctx
->st
->destroy(ctx
->st
);
114 dri_destroy_context(__DRIcontext
* cPriv
)
116 struct dri_context
*ctx
= dri_context(cPriv
);
118 /* note: we are freeing values and nothing more because
119 * driParseConfigFiles allocated values only - the rest
120 * is owned by screen optionCache.
122 FREE(ctx
->optionCache
.values
);
124 /* No particular reason to wait for command completion before
125 * destroying a context, but it is probably worthwhile flushing it
126 * to avoid having to add code elsewhere to cope with flushing a
127 * partially destroyed context.
129 ctx
->st
->flush(ctx
->st
, 0, NULL
);
130 ctx
->st
->destroy(ctx
->st
);
132 if (ctx
->pp
) pp_free(ctx
->pp
);
138 dri_unbind_context(__DRIcontext
* cPriv
)
140 /* dri_util.c ensures cPriv is not null */
141 struct dri_screen
*screen
= dri_screen(cPriv
->driScreenPriv
);
142 struct dri_context
*ctx
= dri_context(cPriv
);
143 struct st_api
*stapi
= screen
->st_api
;
145 if (--ctx
->bind_count
== 0) {
146 if (ctx
->st
== ctx
->stapi
->get_current(ctx
->stapi
)) {
147 ctx
->st
->flush(ctx
->st
, ST_FLUSH_FRONT
, NULL
);
148 stapi
->make_current(stapi
, NULL
, NULL
, NULL
);
156 dri_make_current(__DRIcontext
* cPriv
,
157 __DRIdrawable
* driDrawPriv
,
158 __DRIdrawable
* driReadPriv
)
160 /* dri_util.c ensures cPriv is not null */
161 struct dri_context
*ctx
= dri_context(cPriv
);
162 struct dri_drawable
*draw
= dri_drawable(driDrawPriv
);
163 struct dri_drawable
*read
= dri_drawable(driReadPriv
);
164 struct st_context_iface
*old_st
= ctx
->stapi
->get_current(ctx
->stapi
);
166 if (old_st
&& old_st
!= ctx
->st
)
167 old_st
->flush(old_st
, ST_FLUSH_FRONT
, NULL
);
171 if (!driDrawPriv
&& !driReadPriv
)
172 return ctx
->stapi
->make_current(ctx
->stapi
, ctx
->st
, NULL
, NULL
);
173 else if (!driDrawPriv
|| !driReadPriv
)
176 if (ctx
->dPriv
!= driDrawPriv
) {
177 ctx
->dPriv
= driDrawPriv
;
178 draw
->texture_stamp
= driDrawPriv
->lastStamp
- 1;
180 if (ctx
->rPriv
!= driReadPriv
) {
181 ctx
->rPriv
= driReadPriv
;
182 read
->texture_stamp
= driReadPriv
->lastStamp
- 1;
185 ctx
->stapi
->make_current(ctx
->stapi
, ctx
->st
, &draw
->base
, &read
->base
);
187 // This is ok to call here. If they are already init, it's a no-op.
188 if (draw
->textures
[ST_ATTACHMENT_BACK_LEFT
] && draw
->textures
[ST_ATTACHMENT_DEPTH_STENCIL
]
190 pp_init_fbos(ctx
->pp
, draw
->textures
[ST_ATTACHMENT_BACK_LEFT
]->width0
,
191 draw
->textures
[ST_ATTACHMENT_BACK_LEFT
]->height0
,
192 draw
->textures
[ST_ATTACHMENT_DEPTH_STENCIL
]);
198 dri_get_current(__DRIscreen
*sPriv
)
200 struct dri_screen
*screen
= dri_screen(sPriv
);
201 struct st_api
*stapi
= screen
->st_api
;
202 struct st_context_iface
*st
;
204 st
= stapi
->get_current(stapi
);
206 return (struct dri_context
*) (st
) ? st
->st_manager_private
: NULL
;
209 /* vim: set sw=3 ts=8 sts=3 expandtab: */