st/dri: Make st_manager the base for dri_screen

This commit is contained in:
Jakob Bornecrantz 2010-04-24 11:08:58 +01:00
parent ea6a52a1f8
commit a66b391edf
8 changed files with 35 additions and 85 deletions

View file

@ -53,9 +53,9 @@ GLboolean
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;
@ -77,7 +77,7 @@ dri_create_context(const __GLcontextModes * visual,
&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;
@ -119,7 +119,8 @@ dri_destroy_context(__DRIcontext * cPriv)
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);
@ -140,7 +141,8 @@ dri_make_current(__DRIcontext * 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);
@ -173,9 +175,10 @@ dri_make_current(__DRIcontext * 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);

View file

@ -80,7 +80,7 @@ dri_make_current(__DRIcontext * driContextPriv,
__DRIdrawable * driReadPriv);
struct dri_context *
dri_get_current(void);
dri_get_current(__DRIscreen * driScreenPriv);
boolean
dri_create_context(const __GLcontextModes * visual,

View file

@ -304,9 +304,6 @@ dri_destroy_screen_helper(struct dri_screen * screen)
{
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);
@ -336,8 +333,7 @@ dri_init_screen_helper(struct dri_screen *screen,
return NULL;
}
screen->smapi = dri_create_st_manager(screen);
if (!screen->smapi)
if (!dri_init_st_manager(screen))
return NULL;
driParseOptionInfo(&screen->optionCache,

View file

@ -46,6 +46,10 @@ struct dri_drawable;
struct dri_screen
{
/* st_api */
struct st_manager base;
struct st_api *st_api;
/* dri */
__DRIscreen *sPriv;
@ -75,8 +79,6 @@ struct dri_screen
boolean sd_depth_bits_last;
boolean auto_fake_front;
struct st_manager *smapi;
/* used only by DRI1 */
struct pipe_context *dri1_pipe;
};

View file

@ -170,39 +170,6 @@ dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi,
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)
@ -231,37 +198,22 @@ dri_st_manager_get_egl_image(struct st_manager *smapi,
/**
* 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_close_st_manager(struct dri_screen *screen)
{
_dri_put_st_api();
FREE(smapi);
}
/**
* Return the st_api of OpenGL state tracker.
*/
struct st_api *
dri_get_st_api(void)
{
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);
}

View file

@ -43,14 +43,11 @@ struct __DRIimageRec {
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);

View file

@ -257,7 +257,7 @@ static void
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;
@ -280,8 +280,8 @@ dri1_flush_frontbuffer(struct dri_drawable *draw,
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;
@ -309,7 +309,7 @@ dri1_swap_buffers(__DRIdrawable * dPriv)
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;

View file

@ -105,7 +105,7 @@ drisw_present_texture(__DRIdrawable *dPriv,
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;
@ -131,7 +131,7 @@ drisw_copy_to_front(__DRIdrawable * dPriv,
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;
@ -151,7 +151,7 @@ static void
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)