dri_create_context(const __GLcontextModes * visual,
__DRIcontext * cPriv, void *sharedContextPrivate)
{
- struct st_api *stapi = dri_get_st_api();
__DRIscreen *sPriv = cPriv->driScreenPriv;
struct dri_screen *screen = dri_screen(sPriv);
+ struct st_api *stapi = screen->st_api;
struct dri_context *ctx = NULL;
struct st_context_iface *st_share = NULL;
struct st_visual stvis;
&screen->optionCache, sPriv->myNum, "dri");
dri_fill_st_visual(&stvis, screen, visual);
- ctx->st = stapi->create_context(stapi, screen->smapi, &stvis, st_share);
+ ctx->st = stapi->create_context(stapi, &screen->base, &stvis, st_share);
if (ctx->st == NULL)
goto fail;
ctx->st->st_manager_private = (void *) ctx;
GLboolean
dri_unbind_context(__DRIcontext * cPriv)
{
- struct st_api *stapi = dri_get_st_api();
+ struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
+ struct st_api *stapi = screen->st_api;
if (cPriv) {
struct dri_context *ctx = dri_context(cPriv);
__DRIdrawable * driDrawPriv,
__DRIdrawable * driReadPriv)
{
- struct st_api *stapi = dri_get_st_api();
+ struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
+ struct st_api *stapi = screen->st_api;
if (cPriv) {
struct dri_context *ctx = dri_context(cPriv);
}
struct dri_context *
-dri_get_current(void)
+dri_get_current(__DRIscreen *sPriv)
{
- struct st_api *stapi = dri_get_st_api();
+ struct dri_screen *screen = dri_screen(sPriv);
+ struct st_api *stapi = screen->st_api;
struct st_context_iface *st;
st = stapi->get_current(stapi);
__DRIdrawable * driReadPriv);
struct dri_context *
-dri_get_current(void);
+dri_get_current(__DRIscreen * driScreenPriv);
boolean
dri_create_context(const __GLcontextModes * visual,
{
dri1_destroy_pipe_context(screen);
- if (screen->smapi)
- dri_destroy_st_manager(screen->smapi);
-
if (screen->pipe_screen)
screen->pipe_screen->destroy(screen->pipe_screen);
return NULL;
}
- screen->smapi = dri_create_st_manager(screen);
- if (!screen->smapi)
+ if (!dri_init_st_manager(screen))
return NULL;
driParseOptionInfo(&screen->optionCache,
struct dri_screen
{
+ /* st_api */
+ struct st_manager base;
+ struct st_api *st_api;
+
/* dri */
__DRIscreen *sPriv;
boolean sd_depth_bits_last;
boolean auto_fake_front;
- struct st_manager *smapi;
-
/* used only by DRI1 */
struct pipe_context *dri1_pipe;
};
stfbi->validate(stfbi, statts, count, NULL);
}
-/**
- * Reference counted st_api.
- */
-static struct {
- int32_t refcnt;
- struct st_api *stapi;
-} dri_st_api;
-
-/**
- * Add a reference to the st_api of the state tracker.
- */
-static void
-_dri_get_st_api(void)
-{
- p_atomic_inc(&dri_st_api.refcnt);
- if (p_atomic_read(&dri_st_api.refcnt) == 1)
- dri_st_api.stapi = st_gl_api_create();
-}
-
-/**
- * Remove a reference to the st_api of the state tracker.
- */
-static void
-_dri_put_st_api(void)
-{
- struct st_api *stapi = dri_st_api.stapi;
-
- if (p_atomic_dec_zero(&dri_st_api.refcnt)) {
- stapi->destroy(dri_st_api.stapi);
- dri_st_api.stapi = NULL;
- }
-}
-
static boolean
dri_st_manager_get_egl_image(struct st_manager *smapi,
struct st_egl_image *stimg)
/**
* Create a state tracker manager from the given screen.
*/
-struct st_manager *
-dri_create_st_manager(struct dri_screen *screen)
+boolean
+dri_init_st_manager(struct dri_screen *screen)
{
- struct st_manager *smapi;
+ screen->base.screen = screen->pipe_screen;
+ screen->base.get_egl_image = dri_st_manager_get_egl_image;
+ screen->st_api = st_gl_api_create();
- smapi = CALLOC_STRUCT(st_manager);
- if (smapi) {
- smapi->screen = screen->pipe_screen;
- smapi->get_egl_image = dri_st_manager_get_egl_image;
- _dri_get_st_api();
- }
+ if (!screen->st_api)
+ return FALSE;
- return smapi;
+ return TRUE;
}
-/**
- * Destroy a state tracker manager.
- */
void
-dri_destroy_st_manager(struct st_manager *smapi)
-{
- _dri_put_st_api();
- FREE(smapi);
-}
-
-/**
- * Return the st_api of OpenGL state tracker.
- */
-struct st_api *
-dri_get_st_api(void)
+dri_close_st_manager(struct dri_screen *screen)
{
- assert(dri_st_api.stapi);
- return dri_st_api.stapi;
+ if (screen->st_api && screen->st_api->destroy)
+ screen->st_api->destroy(screen->st_api);
}
void *loader_private;
};
-struct st_api *
-dri_get_st_api(void);
-
-struct st_manager *
-dri_create_st_manager(struct dri_screen *screen);
+boolean
+dri_init_st_manager(struct dri_screen *screen);
void
-dri_destroy_st_manager(struct st_manager *smapi);
+dri_close_st_manager(struct dri_screen *screen);
struct st_framebuffer_iface *
dri_create_st_framebuffer(struct dri_drawable *drawable);
dri1_flush_frontbuffer(struct dri_drawable *draw,
enum st_attachment_type statt)
{
- struct dri_context *ctx = dri_get_current();
+ struct dri_context *ctx = dri_get_current(draw->sPriv);
struct dri_screen *screen = dri_screen(draw->sPriv);
struct pipe_screen *pipe_screen = screen->pipe_screen;
struct pipe_fence_handle *dummy_fence;
void
dri1_swap_buffers(__DRIdrawable * dPriv)
{
- struct dri_context *ctx = dri_get_current();
struct dri_drawable *draw = dri_drawable(dPriv);
+ struct dri_context *ctx = dri_get_current(draw->sPriv);
struct dri_screen *screen = dri_screen(draw->sPriv);
struct pipe_screen *pipe_screen = screen->pipe_screen;
struct pipe_fence_handle *fence;
void
dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h)
{
- struct dri_context *ctx = dri_get_current();
+ struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
struct pipe_screen *pipe_screen = screen->pipe_screen;
struct drm_clip_rect sub_bbox;
static INLINE void
drisw_invalidate_drawable(__DRIdrawable *dPriv)
{
- struct dri_context *ctx = dri_get_current();
+ struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
struct dri_drawable *drawable = dri_drawable(dPriv);
drawable->texture_stamp = dPriv->lastStamp - 1;
void
drisw_swap_buffers(__DRIdrawable *dPriv)
{
- struct dri_context *ctx = dri_get_current();
+ struct dri_context *ctx = dri_get_current(dPriv->driScreenPriv);
struct dri_drawable *drawable = dri_drawable(dPriv);
struct pipe_resource *ptex;
drisw_flush_frontbuffer(struct dri_drawable *drawable,
enum st_attachment_type statt)
{
- struct dri_context *ctx = dri_get_current();
+ struct dri_context *ctx = dri_get_current(drawable->sPriv);
struct pipe_resource *ptex;
if (!ctx)