From 1372a8f90dc64350e4ac29dbb8c5feb88bc83cd1 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz <wallbraker@gmail.com> Date: Sat, 24 Apr 2010 14:28:55 +0100 Subject: st/dri: Refactor dri_st_api into other files --- .../state_trackers/dri/common/dri1_helper.c | 10 +- .../state_trackers/dri/common/dri_context.c | 1 - .../state_trackers/dri/common/dri_drawable.c | 111 ++++++++++- .../state_trackers/dri/common/dri_drawable.h | 4 + src/gallium/state_trackers/dri/common/dri_screen.c | 45 ++++- src/gallium/state_trackers/dri/common/dri_screen.h | 11 +- src/gallium/state_trackers/dri/common/dri_st_api.c | 207 --------------------- src/gallium/state_trackers/dri/common/dri_st_api.h | 62 ------ 8 files changed, 164 insertions(+), 287 deletions(-) delete mode 100644 src/gallium/state_trackers/dri/common/dri_st_api.c delete mode 100644 src/gallium/state_trackers/dri/common/dri_st_api.h (limited to 'src/gallium/state_trackers/dri/common') diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.c b/src/gallium/state_trackers/dri/common/dri1_helper.c index b0dd974a964..f641b41ff8b 100644 --- a/src/gallium/state_trackers/dri/common/dri1_helper.c +++ b/src/gallium/state_trackers/dri/common/dri1_helper.c @@ -42,7 +42,7 @@ struct pipe_fence_handle * dri1_swap_fences_pop_front(struct dri_drawable *draw) { - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_screen *screen = dri_screen(draw->sPriv)->base.screen; struct pipe_fence_handle *fence = NULL; if (draw->cur_fences >= draw->desired_fences) { @@ -58,7 +58,7 @@ void dri1_swap_fences_push_back(struct dri_drawable *draw, struct pipe_fence_handle *fence) { - struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen; + struct pipe_screen *screen = dri_screen(draw->sPriv)->base.screen; if (!fence) return; @@ -74,7 +74,7 @@ dri1_swap_fences_push_back(struct dri_drawable *draw, void dri1_swap_fences_clear(struct dri_drawable *drawable) { - struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_screen *screen = dri_screen(drawable->sPriv)->base.screen; struct pipe_fence_handle *fence; while (drawable->cur_fences) { @@ -86,7 +86,7 @@ dri1_swap_fences_clear(struct dri_drawable *drawable) struct pipe_surface * dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_resource *ptex) { - struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen; + struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->base.screen; struct pipe_surface *psurf = drawable->dri1_surface; if (!psurf || psurf->texture != ptex) { @@ -114,7 +114,7 @@ dri1_get_pipe_context(struct dri_screen *screen) if (!pipe) { screen->dri1_pipe = - screen->pipe_screen->context_create(screen->pipe_screen, NULL); + screen->base.screen->context_create(screen->base.screen, NULL); pipe = screen->dri1_pipe; } diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c index ba9fe62125d..0e5ab5b5198 100644 --- a/src/gallium/state_trackers/dri/common/dri_context.c +++ b/src/gallium/state_trackers/dri/common/dri_context.c @@ -34,7 +34,6 @@ #include "dri_screen.h" #include "dri_drawable.h" #include "dri_context.h" -#include "dri_st_api.h" #include "pipe/p_context.h" #include "state_tracker/st_context.h" diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c index a61e7e1b1b4..25892fc7a76 100644 --- a/src/gallium/state_trackers/dri/common/dri_drawable.c +++ b/src/gallium/state_trackers/dri/common/dri_drawable.c @@ -32,13 +32,82 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" -#include "dri_st_api.h" #include "dri1_helper.h" #include "pipe/p_screen.h" #include "util/u_format.h" #include "util/u_memory.h" +#include "util/u_inlines.h" + +static boolean +dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, + const enum st_attachment_type *statts, + unsigned count, + struct pipe_resource **out) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + struct dri_screen *screen = dri_screen(drawable->sPriv); + unsigned statt_mask, new_mask; + boolean new_stamp; + int i; + + statt_mask = 0x0; + for (i = 0; i < count; i++) + statt_mask |= (1 << statts[i]); + + /* record newly allocated textures */ + new_mask = (statt_mask & ~drawable->texture_mask); + + /* + * dPriv->pStamp is the server stamp. It should be accessed with a lock, at + * least for DRI1. dPriv->lastStamp is the client stamp. It has the value + * of the server stamp when last checked. + */ + new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); + + if (new_stamp || new_mask) { + if (new_stamp && screen->update_drawable_info) + screen->update_drawable_info(drawable); + + screen->allocate_textures(drawable, statts, count); + + /* add existing textures */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->textures[i]) + statt_mask |= (1 << i); + } + + drawable->texture_stamp = drawable->dPriv->lastStamp; + drawable->texture_mask = statt_mask; + } + + if (!out) + return TRUE; + + for (i = 0; i < count; i++) { + out[i] = NULL; + pipe_resource_reference(&out[i], drawable->textures[statts[i]]); + } + + return TRUE; +} + +static boolean +dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, + enum st_attachment_type statt) +{ + struct dri_drawable *drawable = + (struct dri_drawable *) stfbi->st_manager_private; + struct dri_screen *screen = dri_screen(drawable->sPriv); + + /* XXX remove this and just set the correct one on the framebuffer */ + screen->flush_frontbuffer(drawable, statt); + + return TRUE; +} + /** * This is called when we need to set up GL rendering to a new X window. */ @@ -58,7 +127,12 @@ dri_create_buffer(__DRIscreen * sPriv, goto fail; dri_fill_st_visual(&drawable->stvis, screen, visual); - dri_init_st_framebuffer(drawable); + + /* setup the st_framebuffer_iface */ + drawable->base.visual = &drawable->stvis; + drawable->base.flush_front = dri_st_framebuffer_flush_front; + drawable->base.validate = dri_st_framebuffer_validate; + drawable->base.st_manager_private = (void *) drawable; drawable->sPriv = sPriv; drawable->dPriv = dPriv; @@ -76,18 +150,49 @@ void dri_destroy_buffer(__DRIdrawable * dPriv) { struct dri_drawable *drawable = dri_drawable(dPriv); + int i; dri1_swap_fences_clear(drawable); dri1_destroy_pipe_surface(drawable); - dri_close_st_framebuffer(drawable); + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) + pipe_resource_reference(&drawable->textures[i], NULL); drawable->desired_fences = 0; FREE(drawable); } +/** + * Validate the texture at an attachment. Allocate the texture if it does not + * exist. + */ +void +dri_drawable_validate_att(struct dri_drawable *drawable, + enum st_attachment_type statt) +{ + enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; + unsigned i, count = 0; + + /* check if buffer already exists */ + if (drawable->texture_mask & (1 << statt)) + return; + + /* make sure DRI2 does not destroy existing buffers */ + for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { + if (drawable->texture_mask & (1 << i)) { + statts[count++] = i; + } + } + statts[count++] = statt; + + drawable->texture_stamp = drawable->dPriv->lastStamp - 1; + + /* this calles into the manager */ + drawable->base.validate(&drawable->base, statts, count, NULL); +} + /** * Get the format and binding of an attachment. */ diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h index 6c54a6953b3..5fd650ac88e 100644 --- a/src/gallium/state_trackers/dri/common/dri_drawable.h +++ b/src/gallium/state_trackers/dri/common/dri_drawable.h @@ -89,6 +89,10 @@ dri_drawable_get_format(struct dri_drawable *drawable, enum pipe_format *format, unsigned *bind); +void +dri_drawable_validate_att(struct dri_drawable *drawable, + enum st_attachment_type statt); + #endif /* vim: set sw=3 ts=8 sts=3 expandtab: */ diff --git a/src/gallium/state_trackers/dri/common/dri_screen.c b/src/gallium/state_trackers/dri/common/dri_screen.c index 7060107e737..064c73f54c2 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.c +++ b/src/gallium/state_trackers/dri/common/dri_screen.c @@ -38,7 +38,6 @@ #include "dri_screen.h" #include "dri_context.h" #include "dri_drawable.h" -#include "dri_st_api.h" #include "dri1_helper.h" #ifndef __NOT_HAVE_DRM_H #include "dri1.h" @@ -50,6 +49,7 @@ #include "util/u_inlines.h" #include "pipe/p_screen.h" #include "pipe/p_format.h" +#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */ #include "util/u_debug.h" @@ -79,7 +79,7 @@ dri_fill_in_modes(struct dri_screen *screen, unsigned depth_buffer_factor; unsigned back_buffer_factor; unsigned msaa_samples_factor; - struct pipe_screen *p_screen = screen->pipe_screen; + struct pipe_screen *p_screen = screen->base.screen; boolean pf_r5g6b5, pf_a8r8g8b8, pf_x8r8g8b8; boolean pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32; @@ -283,6 +283,31 @@ dri_get_swap_info(__DRIdrawable * dPriv, __DRIswapInfo * sInfo) #endif +static boolean +dri_get_egl_image(struct st_manager *smapi, + struct st_egl_image *stimg) +{ + struct dri_context *ctx = + (struct dri_context *)stimg->stctxi->st_manager_private; + struct dri_screen *screen = dri_screen(ctx->sPriv); + __DRIimage *img = NULL; + + if (screen->lookup_egl_image) { + img = screen->lookup_egl_image(ctx, stimg->egl_image); + } + + if (!img) + return FALSE; + + stimg->texture = NULL; + pipe_resource_reference(&stimg->texture, img->texture); + stimg->face = img->face; + stimg->level = img->level; + stimg->zslice = img->zslice; + + return TRUE; +} + static void dri_destroy_option_cache(struct dri_screen * screen) { @@ -304,8 +329,11 @@ dri_destroy_screen_helper(struct dri_screen * screen) { dri1_destroy_pipe_context(screen); - if (screen->pipe_screen) - screen->pipe_screen->destroy(screen->pipe_screen); + if (screen->st_api && screen->st_api->destroy) + screen->st_api->destroy(screen->st_api); + + if (screen->base.screen) + screen->base.screen->destroy(screen->base.screen); dri_destroy_option_cache(screen); } @@ -327,13 +355,16 @@ dri_init_screen_helper(struct dri_screen *screen, struct pipe_screen *pscreen, unsigned pixel_bits) { - screen->pipe_screen = pscreen; - if (!screen->pipe_screen) { + screen->base.screen = pscreen; + if (!screen->base.screen) { debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__); return NULL; } - if (!dri_init_st_manager(screen)) + screen->base.get_egl_image = dri_get_egl_image; + screen->st_api = st_gl_api_create(); + + if (!screen->st_api) return NULL; driParseOptionInfo(&screen->optionCache, diff --git a/src/gallium/state_trackers/dri/common/dri_screen.h b/src/gallium/state_trackers/dri/common/dri_screen.h index 98cb9e75508..1740fa8f426 100644 --- a/src/gallium/state_trackers/dri/common/dri_screen.h +++ b/src/gallium/state_trackers/dri/common/dri_screen.h @@ -73,8 +73,6 @@ struct dri_screen /* gallium */ struct drm_api *api; - struct pipe_winsys *pipe_winsys; - struct pipe_screen *pipe_screen; boolean d_depth_bits_last; boolean sd_depth_bits_last; boolean auto_fake_front; @@ -90,6 +88,15 @@ dri_screen(__DRIscreen * sPriv) return (struct dri_screen *)sPriv->private; } +struct __DRIimageRec { + struct pipe_resource *texture; + unsigned face; + unsigned level; + unsigned zslice; + + void *loader_private; +}; + #ifndef __NOT_HAVE_DRM_H static INLINE boolean diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.c b/src/gallium/state_trackers/dri/common/dri_st_api.c deleted file mode 100644 index 42e0ba020ad..00000000000 --- a/src/gallium/state_trackers/dri/common/dri_st_api.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu <olv@lunarg.com> - */ - -#include "util/u_memory.h" -#include "util/u_inlines.h" -#include "util/u_format.h" -#include "util/u_debug.h" -#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */ - -#include "dri_screen.h" -#include "dri_context.h" -#include "dri_drawable.h" -#include "dri_st_api.h" - -static boolean -dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi, - const enum st_attachment_type *statts, - unsigned count, - struct pipe_resource **out) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - struct dri_screen *screen = dri_screen(drawable->sPriv); - unsigned statt_mask, new_mask; - boolean new_stamp; - int i; - - statt_mask = 0x0; - for (i = 0; i < count; i++) - statt_mask |= (1 << statts[i]); - - /* record newly allocated textures */ - new_mask = (statt_mask & ~drawable->texture_mask); - - /* - * dPriv->pStamp is the server stamp. It should be accessed with a lock, at - * least for DRI1. dPriv->lastStamp is the client stamp. It has the value - * of the server stamp when last checked. - */ - new_stamp = (drawable->texture_stamp != drawable->dPriv->lastStamp); - - if (new_stamp || new_mask) { - if (new_stamp && screen->update_drawable_info) - screen->update_drawable_info(drawable); - - screen->allocate_textures(drawable, statts, count); - - /* add existing textures */ - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - if (drawable->textures[i]) - statt_mask |= (1 << i); - } - - drawable->texture_stamp = drawable->dPriv->lastStamp; - drawable->texture_mask = statt_mask; - } - - if (!out) - return TRUE; - - for (i = 0; i < count; i++) { - out[i] = NULL; - pipe_resource_reference(&out[i], drawable->textures[statts[i]]); - } - - return TRUE; -} - -static boolean -dri_st_framebuffer_flush_front(struct st_framebuffer_iface *stfbi, - enum st_attachment_type statt) -{ - struct dri_drawable *drawable = - (struct dri_drawable *) stfbi->st_manager_private; - struct dri_screen *screen = dri_screen(drawable->sPriv); - - /* XXX remove this and just set the correct one on the framebuffer */ - screen->flush_frontbuffer(drawable, statt); - - return TRUE; -} - -/** - * Init a framebuffer from the given drawable. - */ -void -dri_init_st_framebuffer(struct dri_drawable *drawable) -{ - drawable->base.visual = &drawable->stvis; - drawable->base.flush_front = dri_st_framebuffer_flush_front; - drawable->base.validate = dri_st_framebuffer_validate; - drawable->base.st_manager_private = (void *) drawable; -} - -/** - * Destroy a framebuffer. - */ -void -dri_close_st_framebuffer(struct dri_drawable *drawable) -{ - int i; - - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) - pipe_resource_reference(&drawable->textures[i], NULL); -} - -/** - * Validate the texture at an attachment. Allocate the texture if it does not - * exist. - */ -void -dri_st_framebuffer_validate_att(struct dri_drawable *drawable, - enum st_attachment_type statt) -{ - enum st_attachment_type statts[ST_ATTACHMENT_COUNT]; - unsigned i, count = 0; - - /* check if buffer already exists */ - if (drawable->texture_mask & (1 << statt)) - return; - - /* make sure DRI2 does not destroy existing buffers */ - for (i = 0; i < ST_ATTACHMENT_COUNT; i++) { - if (drawable->texture_mask & (1 << i)) { - statts[count++] = i; - } - } - statts[count++] = statt; - - drawable->texture_stamp = drawable->dPriv->lastStamp - 1; - - /* this calles into the manager */ - drawable->base.validate(&drawable->base, statts, count, NULL); -} - -static boolean -dri_st_manager_get_egl_image(struct st_manager *smapi, - struct st_egl_image *stimg) -{ - struct dri_context *ctx = - (struct dri_context *)stimg->stctxi->st_manager_private; - struct dri_screen *screen = dri_screen(ctx->sPriv); - __DRIimage *img = NULL; - - if (screen->lookup_egl_image) { - img = screen->lookup_egl_image(ctx, stimg->egl_image); - } - - if (!img) - return FALSE; - - stimg->texture = NULL; - pipe_resource_reference(&stimg->texture, img->texture); - stimg->face = img->face; - stimg->level = img->level; - stimg->zslice = img->zslice; - - return TRUE; -} - -/** - * Create a state tracker manager from the given screen. - */ -boolean -dri_init_st_manager(struct dri_screen *screen) -{ - screen->base.screen = screen->pipe_screen; - screen->base.get_egl_image = dri_st_manager_get_egl_image; - screen->st_api = st_gl_api_create(); - - if (!screen->st_api) - return FALSE; - - return TRUE; -} - -void -dri_close_st_manager(struct dri_screen *screen) -{ - if (screen->st_api && screen->st_api->destroy) - screen->st_api->destroy(screen->st_api); -} diff --git a/src/gallium/state_trackers/dri/common/dri_st_api.h b/src/gallium/state_trackers/dri/common/dri_st_api.h deleted file mode 100644 index 8cb9fabd4e4..00000000000 --- a/src/gallium/state_trackers/dri/common/dri_st_api.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Mesa 3-D graphics library - * Version: 7.9 - * - * Copyright (C) 2010 LunarG Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Chia-I Wu <olv@lunarg.com> - */ - -#ifndef _DRI_ST_API_H_ -#define _DRI_ST_API_H_ - -#include "state_tracker/st_api.h" - -struct dri_screen; -struct dri_drawable; - -struct __DRIimageRec { - struct pipe_resource *texture; - unsigned face; - unsigned level; - unsigned zslice; - - void *loader_private; -}; - -boolean -dri_init_st_manager(struct dri_screen *screen); - -void -dri_close_st_manager(struct dri_screen *screen); - -void -dri_init_st_framebuffer(struct dri_drawable *drawable); - -void -dri_close_st_framebuffer(struct dri_drawable *drawable); - -void -dri_st_framebuffer_validate_att(struct dri_drawable *drawable, - enum st_attachment_type statt); - -#endif /* _DRI_ST_API_H_ */ -- cgit v1.2.3