st/dri: Refactor dri_st_api into other files

This commit is contained in:
Jakob Bornecrantz
2010-04-24 14:28:55 +01:00
parent 27779ddad5
commit 1372a8f90d
17 changed files with 173 additions and 303 deletions
@@ -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;
}
@@ -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"
@@ -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.
*/
@@ -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: */
@@ -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,
@@ -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
@@ -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);
}
@@ -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_ */
@@ -16,7 +16,6 @@ C_SOURCES = \
dri_context.c \
dri_screen.c \
dri_drawable.c \
dri_st_api.c \
dri1_helper.c \
dri1.c \
dri2.c
@@ -20,7 +20,6 @@ if env['dri']:
source = [ 'dri_context.c',
'dri_drawable.c',
'dri_screen.c',
'dri_st_api.c',
'dri1_helper.c',
'dri1.c',
'dri2.c',
+4 -4
View File
@@ -259,7 +259,7 @@ dri1_flush_frontbuffer(struct dri_drawable *draw,
{
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_screen *pipe_screen = screen->base.screen;
struct pipe_fence_handle *dummy_fence;
struct pipe_resource *ptex;
@@ -283,7 +283,7 @@ dri1_swap_buffers(__DRIdrawable * dPriv)
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_screen *pipe_screen = screen->base.screen;
struct pipe_fence_handle *fence;
struct pipe_resource *ptex;
@@ -311,7 +311,7 @@ dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h)
{
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 pipe_screen *pipe_screen = screen->base.screen;
struct drm_clip_rect sub_bbox;
struct dri_drawable *draw = dri_drawable(dPriv);
struct pipe_fence_handle *dummy_fence;
@@ -389,7 +389,7 @@ dri1_allocate_textures(struct dri_drawable *drawable,
templ.bind = bind;
drawable->textures[statts[i]] =
screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
screen->base.screen->resource_create(screen->base.screen, &templ);
}
drawable->old_w = width;
+3 -4
View File
@@ -38,7 +38,6 @@
#include "dri_screen.h"
#include "dri_context.h"
#include "dri_drawable.h"
#include "dri_st_api.h"
#include "dri2.h"
#include "GL/internal/dri_interface.h"
@@ -81,7 +80,7 @@ dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
struct dri_drawable *drawable = dri_drawable(dPriv);
struct pipe_resource *pt;
dri_st_framebuffer_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
@@ -332,7 +331,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
whandle.stride = buf->pitch;
drawable->textures[statt] =
screen->pipe_screen->resource_from_handle(screen->pipe_screen,
screen->base.screen->resource_from_handle(screen->base.screen,
&templ, &whandle);
}
@@ -435,7 +434,7 @@ dri2_create_image_from_name(__DRIcontext *context,
whandle.handle = name;
whandle.stride = pitch * util_format_get_blocksize(pf);
img->texture = screen->pipe_screen->resource_from_handle(screen->pipe_screen,
img->texture = screen->base.screen->resource_from_handle(screen->base.screen,
&templ, &whandle);
if (!img->texture) {
FREE(img);
@@ -1 +0,0 @@
../common/dri_st_api.c
@@ -19,7 +19,6 @@ C_SOURCES = \
dri_context.c \
dri_screen.c \
dri_drawable.c \
dri_st_api.c \
dri1_helper.c \
drisw.c
@@ -20,7 +20,6 @@ if env['dri']:
source = [ 'dri_context.c',
'dri_drawable.c',
'dri_screen.c',
'dri_st_api.c',
'dri1_helper.c',
'drisw.c',
]
@@ -1 +0,0 @@
../common/dri_st_api.c
+2 -2
View File
@@ -99,7 +99,7 @@ drisw_present_texture(__DRIdrawable *dPriv,
if (!psurf)
return;
screen->pipe_screen->flush_frontbuffer(screen->pipe_screen, psurf, drawable);
screen->base.screen->flush_frontbuffer(screen->base.screen, psurf, drawable);
}
static INLINE void
@@ -225,7 +225,7 @@ drisw_allocate_textures(struct dri_drawable *drawable,
templ.bind = bind;
drawable->textures[statts[i]] =
screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
screen->base.screen->resource_create(screen->base.screen, &templ);
}
drawable->old_w = width;