summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r--src/gallium/state_trackers/dri/common/dri1_helper.c10
-rw-r--r--src/gallium/state_trackers/dri/common/dri_context.c68
-rw-r--r--src/gallium/state_trackers/dri/common/dri_context.h2
-rw-r--r--src/gallium/state_trackers/dri/common/dri_drawable.c141
-rw-r--r--src/gallium/state_trackers/dri/common/dri_drawable.h17
-rw-r--r--src/gallium/state_trackers/dri/common/dri_screen.c47
-rw-r--r--src/gallium/state_trackers/dri/common/dri_screen.h29
-rw-r--r--src/gallium/state_trackers/dri/common/dri_st_api.c289
-rw-r--r--src/gallium/state_trackers/dri/common/dri_st_api.h65
-rw-r--r--src/gallium/state_trackers/dri/drm/Makefile1
-rw-r--r--src/gallium/state_trackers/dri/drm/SConscript1
-rw-r--r--src/gallium/state_trackers/dri/drm/dri1.c65
-rw-r--r--src/gallium/state_trackers/dri/drm/dri1.h8
-rw-r--r--src/gallium/state_trackers/dri/drm/dri2.c50
-rw-r--r--src/gallium/state_trackers/dri/drm/dri2.h12
l---------src/gallium/state_trackers/dri/drm/dri_st_api.c1
-rw-r--r--src/gallium/state_trackers/dri/sw/Makefile1
-rw-r--r--src/gallium/state_trackers/dri/sw/SConscript1
l---------src/gallium/state_trackers/dri/sw/dri_st_api.c1
-rw-r--r--src/gallium/state_trackers/dri/sw/drisw.c67
-rw-r--r--src/gallium/state_trackers/dri/sw/drisw.h11
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d_st.c28
-rw-r--r--src/gallium/state_trackers/es/st_es1.c13
-rw-r--r--src/gallium/state_trackers/es/st_es2.c14
-rw-r--r--src/gallium/state_trackers/glx/xlib/xm_st.c13
-rw-r--r--src/gallium/state_trackers/vega/vg_manager.c33
-rw-r--r--src/gallium/state_trackers/wgl/stw_st.c4
27 files changed, 381 insertions, 611 deletions
diff --git a/src/gallium/state_trackers/dri/common/dri1_helper.c b/src/gallium/state_trackers/dri/common/dri1_helper.c
index b0dd974a96..f641b41ff8 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 f14f4130bf..a808d2d9dd 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"
@@ -53,9 +52,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 +76,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,16 +118,15 @@ dri_destroy_context(__DRIcontext * cPriv)
GLboolean
dri_unbind_context(__DRIcontext * cPriv)
{
- struct st_api *stapi = dri_get_st_api();
-
- if (cPriv) {
- struct dri_context *ctx = dri_context(cPriv);
+ /* dri_util.c ensures cPriv is not null */
+ struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
+ struct dri_context *ctx = dri_context(cPriv);
+ struct st_api *stapi = screen->st_api;
- if (--ctx->bind_count == 0) {
- if (ctx->st == stapi->get_current(stapi)) {
- ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
- stapi->make_current(stapi, NULL, NULL, NULL);
- }
+ if (--ctx->bind_count == 0) {
+ if (ctx->st == stapi->get_current(stapi)) {
+ ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
+ stapi->make_current(stapi, NULL, NULL, NULL);
}
}
@@ -140,42 +138,38 @@ dri_make_current(__DRIcontext * cPriv,
__DRIdrawable * driDrawPriv,
__DRIdrawable * driReadPriv)
{
- struct st_api *stapi = dri_get_st_api();
-
- if (cPriv) {
- struct dri_context *ctx = dri_context(cPriv);
- struct dri_drawable *draw = dri_drawable(driDrawPriv);
- struct dri_drawable *read = dri_drawable(driReadPriv);
- struct st_context_iface *old_st;
+ /* dri_util.c ensures cPriv is not null */
+ struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
+ struct dri_context *ctx = dri_context(cPriv);
+ struct st_api *stapi = screen->st_api;
+ struct dri_drawable *draw = dri_drawable(driDrawPriv);
+ struct dri_drawable *read = dri_drawable(driReadPriv);
+ struct st_context_iface *old_st = stapi->get_current(stapi);
- old_st = stapi->get_current(stapi);
- if (old_st && old_st != ctx->st)
- ctx->st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL);
+ if (old_st && old_st != ctx->st)
+ old_st->flush(old_st, PIPE_FLUSH_RENDER_CACHE, NULL);
- ++ctx->bind_count;
+ ++ctx->bind_count;
- if (ctx->dPriv != driDrawPriv) {
- ctx->dPriv = driDrawPriv;
- draw->texture_stamp = driDrawPriv->lastStamp - 1;
- }
- if (ctx->rPriv != driReadPriv) {
- ctx->rPriv = driReadPriv;
- read->texture_stamp = driReadPriv->lastStamp - 1;
- }
-
- stapi->make_current(stapi, ctx->st, draw->stfb, read->stfb);
+ if (ctx->dPriv != driDrawPriv) {
+ ctx->dPriv = driDrawPriv;
+ draw->texture_stamp = driDrawPriv->lastStamp - 1;
}
- else {
- stapi->make_current(stapi, NULL, NULL, NULL);
+ if (ctx->rPriv != driReadPriv) {
+ ctx->rPriv = driReadPriv;
+ read->texture_stamp = driReadPriv->lastStamp - 1;
}
+ stapi->make_current(stapi, ctx->st, &draw->base, &read->base);
+
return GL_TRUE;
}
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);
diff --git a/src/gallium/state_trackers/dri/common/dri_context.h b/src/gallium/state_trackers/dri/common/dri_context.h
index 594618874a..9fe6b58101 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.h
+++ b/src/gallium/state_trackers/dri/common/dri_context.h
@@ -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,
diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.c b/src/gallium/state_trackers/dri/common/dri_drawable.c
index 88c17e81bf..25892fc7a7 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,9 +127,12 @@ dri_create_buffer(__DRIscreen * sPriv,
goto fail;
dri_fill_st_visual(&drawable->stvis, screen, visual);
- drawable->stfb = dri_create_st_framebuffer(drawable);
- if (drawable->stfb == NULL)
- goto fail;
+
+ /* 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;
@@ -78,16 +150,75 @@ 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_destroy_st_framebuffer(drawable->stfb);
+ 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.
+ */
+void
+dri_drawable_get_format(struct dri_drawable *drawable,
+ enum st_attachment_type statt,
+ enum pipe_format *format,
+ unsigned *bind)
+{
+ switch (statt) {
+ case ST_ATTACHMENT_FRONT_LEFT:
+ case ST_ATTACHMENT_BACK_LEFT:
+ case ST_ATTACHMENT_FRONT_RIGHT:
+ case ST_ATTACHMENT_BACK_RIGHT:
+ *format = drawable->stvis.color_format;
+ *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
+ break;
+ case ST_ATTACHMENT_DEPTH_STENCIL:
+ *format = drawable->stvis.depth_stencil_format;
+ *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
+ break;
+ default:
+ *format = PIPE_FORMAT_NONE;
+ *bind = 0;
+ break;
+ }
+}
+
/* vim: set sw=3 ts=8 sts=3 expandtab: */
diff --git a/src/gallium/state_trackers/dri/common/dri_drawable.h b/src/gallium/state_trackers/dri/common/dri_drawable.h
index 315b778165..5fd650ac88 100644
--- a/src/gallium/state_trackers/dri/common/dri_drawable.h
+++ b/src/gallium/state_trackers/dri/common/dri_drawable.h
@@ -42,14 +42,13 @@ struct dri_context;
struct dri_drawable
{
+ struct st_framebuffer_iface base;
+ struct st_visual stvis;
+
/* dri */
__DRIdrawable *dPriv;
__DRIscreen *sPriv;
- /* gallium */
- struct st_framebuffer_iface *stfb;
- struct st_visual stvis;
-
__DRIbuffer old[8];
unsigned old_num;
unsigned old_w;
@@ -84,6 +83,16 @@ dri_create_buffer(__DRIscreen * sPriv,
void dri_destroy_buffer(__DRIdrawable * dPriv);
+void
+dri_drawable_get_format(struct dri_drawable *drawable,
+ enum st_attachment_type statt,
+ 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 4bfbc6e80b..064c73f54c 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,11 +329,11 @@ dri_destroy_screen_helper(struct dri_screen * screen)
{
dri1_destroy_pipe_context(screen);
- if (screen->smapi)
- dri_destroy_st_manager(screen->smapi);
+ if (screen->st_api && screen->st_api->destroy)
+ screen->st_api->destroy(screen->st_api);
- if (screen->pipe_screen)
- screen->pipe_screen->destroy(screen->pipe_screen);
+ if (screen->base.screen)
+ screen->base.screen->destroy(screen->base.screen);
dri_destroy_option_cache(screen);
}
@@ -330,14 +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;
}
- screen->smapi = dri_create_st_manager(screen);
- if (!screen->smapi)
+ 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 8ab7d43919..1740fa8f42 100644
--- a/src/gallium/state_trackers/dri/common/dri_screen.h
+++ b/src/gallium/state_trackers/dri/common/dri_screen.h
@@ -41,8 +41,15 @@
#include "state_tracker/st_api.h"
#include "state_tracker/drm_api.h"
+struct dri_context;
+struct dri_drawable;
+
struct dri_screen
{
+ /* st_api */
+ struct st_manager base;
+ struct st_api *st_api;
+
/* dri */
__DRIscreen *sPriv;
@@ -55,16 +62,21 @@ struct dri_screen
int fd;
drmLock *drmLock;
+ /* hooks filled in by dri1, dri2 & drisw */
+ __DRIimage * (*lookup_egl_image)(struct dri_context *ctx, void *handle);
+ void (*allocate_textures)(struct dri_drawable *drawable,
+ const enum st_attachment_type *statts,
+ unsigned count);
+ void (*update_drawable_info)(struct dri_drawable *drawable);
+ void (*flush_frontbuffer)(struct dri_drawable *drawable,
+ enum st_attachment_type statt);
+
/* 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;
- struct st_manager *smapi;
-
/* used only by DRI1 */
struct pipe_context *dri1_pipe;
};
@@ -76,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 261bae75a2..0000000000
--- a/src/gallium/state_trackers/dri/common/dri_st_api.c
+++ /dev/null
@@ -1,289 +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_manager.h" /* for st_manager_create_api */
-
-#include "dri_screen.h"
-#include "dri_context.h"
-#include "dri_drawable.h"
-#include "dri_st_api.h"
-#ifndef __NOT_HAVE_DRM_H
-#include "dri1.h"
-#include "dri2.h"
-#else
-#include "drisw.h"
-#endif
-
-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;
- 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) {
-
-#ifndef __NOT_HAVE_DRM_H
- if (__dri1_api_hooks) {
- dri1_allocate_textures(drawable, statt_mask);
- }
- else {
- dri2_allocate_textures(drawable, statts, count);
- }
-#else
- if (new_stamp)
- drisw_update_drawable_info(drawable);
-
- drisw_allocate_textures(drawable, statt_mask);
-#endif
-
- /* 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;
-
-#ifndef __NOT_HAVE_DRM_H
- if (__dri1_api_hooks) {
- dri1_flush_frontbuffer(drawable, statt);
- }
- else {
- dri2_flush_frontbuffer(drawable, statt);
- }
-#else
- drisw_flush_frontbuffer(drawable, statt);
-#endif
-
- return TRUE;
-}
-
-/**
- * Create a framebuffer from the given drawable.
- */
-struct st_framebuffer_iface *
-dri_create_st_framebuffer(struct dri_drawable *drawable)
-{
- struct st_framebuffer_iface *stfbi;
-
- stfbi = CALLOC_STRUCT(st_framebuffer_iface);
- if (stfbi) {
- stfbi->visual = &drawable->stvis;
- stfbi->flush_front = dri_st_framebuffer_flush_front;
- stfbi->validate = dri_st_framebuffer_validate;
- stfbi->st_manager_private = (void *) drawable;
- }
-
- return stfbi;
-}
-
-/**
- * Destroy a framebuffer.
- */
-void
-dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi)
-{
- struct dri_drawable *drawable =
- (struct dri_drawable *) stfbi->st_manager_private;
- int i;
-
- for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
- pipe_resource_reference(&drawable->textures[i], NULL);
-
- FREE(stfbi);
-}
-
-/**
- * Validate the texture at an attachment. Allocate the texture if it does not
- * exist.
- */
-void
-dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi,
- enum st_attachment_type statt)
-{
- struct dri_drawable *drawable =
- (struct dri_drawable *) stfbi->st_manager_private;
- 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;
-
- 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_manager_create_api();
-}
-
-/**
- * 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)
-{
- __DRIimage *img = NULL;
-
-#ifndef __NOT_HAVE_DRM_H
- if (!__dri1_api_hooks) {
- struct dri_context *ctx = (struct dri_context *)
- stimg->stctxi->st_manager_private;
- img = dri2_lookup_egl_image(ctx, stimg->egl_image);
- }
-#endif
- 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.
- */
-struct st_manager *
-dri_create_st_manager(struct dri_screen *screen)
-{
- struct st_manager *smapi;
-
- 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();
- }
-
- return smapi;
-}
-
-/**
- * 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)
-{
- assert(dri_st_api.stapi);
- return dri_st_api.stapi;
-}
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 11d86cfbdf..0000000000
--- a/src/gallium/state_trackers/dri/common/dri_st_api.h
+++ /dev/null
@@ -1,65 +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;
-};
-
-struct st_api *
-dri_get_st_api(void);
-
-struct st_manager *
-dri_create_st_manager(struct dri_screen *screen);
-
-void
-dri_destroy_st_manager(struct st_manager *smapi);
-
-struct st_framebuffer_iface *
-dri_create_st_framebuffer(struct dri_drawable *drawable);
-
-void
-dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi);
-
-void
-dri_st_framebuffer_validate_att(struct st_framebuffer_iface *stfbi,
- enum st_attachment_type statt);
-
-#endif /* _DRI_ST_API_H_ */
diff --git a/src/gallium/state_trackers/dri/drm/Makefile b/src/gallium/state_trackers/dri/drm/Makefile
index 7a236da0c0..d9a973e3c3 100644
--- a/src/gallium/state_trackers/dri/drm/Makefile
+++ b/src/gallium/state_trackers/dri/drm/Makefile
@@ -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
diff --git a/src/gallium/state_trackers/dri/drm/SConscript b/src/gallium/state_trackers/dri/drm/SConscript
index 1dfaa402f2..8800b65534 100644
--- a/src/gallium/state_trackers/dri/drm/SConscript
+++ b/src/gallium/state_trackers/dri/drm/SConscript
@@ -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',
diff --git a/src/gallium/state_trackers/dri/drm/dri1.c b/src/gallium/state_trackers/dri/drm/dri1.c
index e216e46a87..23c21ed839 100644
--- a/src/gallium/state_trackers/dri/drm/dri1.c
+++ b/src/gallium/state_trackers/dri/drm/dri1.c
@@ -104,13 +104,13 @@ dri1_propagate_drawable_change(struct dri_context *ctx)
if (dPriv && draw->texture_stamp != dPriv->lastStamp) {
ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
flushed = TRUE;
- ctx->st->notify_invalid_framebuffer(ctx->st, draw->stfb);
+ ctx->st->notify_invalid_framebuffer(ctx->st, &draw->base);
}
if (rPriv && dPriv != rPriv && read->texture_stamp != rPriv->lastStamp) {
if (!flushed)
ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
- ctx->st->notify_invalid_framebuffer(ctx->st, read->stfb);
+ ctx->st->notify_invalid_framebuffer(ctx->st, &read->base);
}
}
@@ -253,13 +253,13 @@ dri1_copy_to_front(struct dri_context *ctx,
* Backend functions for st_framebuffer interface and swap_buffers.
*/
-void
+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_screen *pipe_screen = screen->base.screen;
struct pipe_fence_handle *dummy_fence;
struct pipe_resource *ptex;
@@ -280,10 +280,10 @@ 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_screen *pipe_screen = screen->base.screen;
struct pipe_fence_handle *fence;
struct pipe_resource *ptex;
@@ -309,9 +309,9 @@ 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 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;
@@ -342,9 +342,10 @@ dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h)
* as they are requested. Unused attachments are not removed, not until the
* framebuffer is resized or destroyed.
*/
-void
+static void
dri1_allocate_textures(struct dri_drawable *drawable,
- unsigned mask)
+ const enum st_attachment_type *statts,
+ unsigned count)
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
struct pipe_resource templ;
@@ -371,40 +372,24 @@ dri1_allocate_textures(struct dri_drawable *drawable,
templ.depth0 = 1;
templ.last_level = 0;
- for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
+ for (i = 0; i < count; i++) {
enum pipe_format format;
- unsigned tex_usage;
+ unsigned bind;
- /* the texture already exists or not requested */
- if (drawable->textures[i] || !(mask & (1 << i))) {
+ /* the texture already exists */
+ if (drawable->textures[statts[i]])
continue;
- }
- switch (i) {
- case ST_ATTACHMENT_FRONT_LEFT:
- case ST_ATTACHMENT_BACK_LEFT:
- case ST_ATTACHMENT_FRONT_RIGHT:
- case ST_ATTACHMENT_BACK_RIGHT:
- format = drawable->stvis.color_format;
- tex_usage = PIPE_BIND_DISPLAY_TARGET |
- PIPE_BIND_RENDER_TARGET;
- break;
- case ST_ATTACHMENT_DEPTH_STENCIL:
- format = drawable->stvis.depth_stencil_format;
- tex_usage = PIPE_BIND_DEPTH_STENCIL;
- break;
- default:
- format = PIPE_FORMAT_NONE;
- break;
- }
+ dri_drawable_get_format(drawable, statts[i], &format, &bind);
+
+ if (format == PIPE_FORMAT_NONE)
+ continue;
- if (format != PIPE_FORMAT_NONE) {
- templ.format = format;
- templ.bind = tex_usage;
+ templ.format = format;
+ templ.bind = bind;
- drawable->textures[i] =
- screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
- }
+ drawable->textures[statts[i]] =
+ screen->base.screen->resource_create(screen->base.screen, &templ);
}
drawable->old_w = width;
@@ -489,6 +474,8 @@ dri1_init_screen(__DRIscreen * sPriv)
screen->sPriv = sPriv;
screen->fd = sPriv->fd;
screen->drmLock = (drmLock *) & sPriv->pSAREA->lock;
+ screen->allocate_textures = dri1_allocate_textures;
+ screen->flush_frontbuffer = dri1_flush_frontbuffer;
sPriv->private = (void *)screen;
sPriv->extensions = dri1_screen_extensions;
diff --git a/src/gallium/state_trackers/dri/drm/dri1.h b/src/gallium/state_trackers/dri/drm/dri1.h
index f7441f98ab..a50188b368 100644
--- a/src/gallium/state_trackers/dri/drm/dri1.h
+++ b/src/gallium/state_trackers/dri/drm/dri1.h
@@ -43,14 +43,6 @@ extern struct dri1_api *__dri1_api_hooks;
const __DRIconfig **
dri1_init_screen(__DRIscreen * sPriv);
-void
-dri1_flush_frontbuffer(struct dri_drawable *drawable,
- enum st_attachment_type statt);
-
-void
-dri1_allocate_textures(struct dri_drawable *drawable,
- unsigned mask);
-
void dri1_swap_buffers(__DRIdrawable * dPriv);
void
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index 0d15b5c9b8..e1216f14c0 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -38,9 +38,10 @@
#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"
+
/**
* DRI2 flush extension.
*/
@@ -59,7 +60,7 @@ dri2_invalidate_drawable(__DRIdrawable *dPriv)
drawable->dPriv->lastStamp = *drawable->dPriv->pStamp;
if (ctx)
- ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb);
+ ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
}
static const __DRI2flushExtension dri2FlushExtension = {
@@ -79,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->stfb, ST_ATTACHMENT_FRONT_LEFT);
+ dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
@@ -120,30 +121,31 @@ static const __DRItexBufferExtension dri2TexBufferExtension = {
};
/**
- * Get the format of an attachment.
+ * Get the format and binding of an attachment.
*/
-static INLINE enum pipe_format
+static INLINE void
dri2_drawable_get_format(struct dri_drawable *drawable,
- enum st_attachment_type statt)
+ enum st_attachment_type statt,
+ enum pipe_format *format,
+ unsigned *bind)
{
- enum pipe_format format;
-
switch (statt) {
case ST_ATTACHMENT_FRONT_LEFT:
case ST_ATTACHMENT_BACK_LEFT:
case ST_ATTACHMENT_FRONT_RIGHT:
case ST_ATTACHMENT_BACK_RIGHT:
- format = drawable->stvis.color_format;
+ *format = drawable->stvis.color_format;
+ *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
break;
case ST_ATTACHMENT_DEPTH_STENCIL:
- format = drawable->stvis.depth_stencil_format;
+ *format = drawable->stvis.depth_stencil_format;
+ *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
break;
default:
- format = PIPE_FORMAT_NONE;
+ *format = PIPE_FORMAT_NONE;
+ *bind = 0;
break;
}
-
- return format;
}
@@ -174,9 +176,10 @@ dri2_drawable_get_buffers(struct dri_drawable *drawable,
for (i = 0; i < *count; i++) {
enum pipe_format format;
+ unsigned bind;
int att, bpp;
- format = dri2_drawable_get_format(drawable, statts[i]);
+ dri2_drawable_get_format(drawable, statts[i], &format, &bind);
if (format == PIPE_FORMAT_NONE)
continue;
@@ -263,7 +266,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
struct pipe_resource templ;
struct winsys_handle whandle;
boolean have_depth = FALSE;
- unsigned i;
+ unsigned i, bind;
if (drawable->old_num == count &&
drawable->old_w == dri_drawable->w &&
@@ -275,7 +278,6 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
pipe_resource_reference(&drawable->textures[i], NULL);
memset(&templ, 0, sizeof(templ));
- templ.bind = PIPE_BIND_RENDER_TARGET;
templ.target = PIPE_TEXTURE_2D;
templ.last_level = 0;
templ.width0 = dri_drawable->w;
@@ -319,16 +321,17 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
break;
}
- format = dri2_drawable_get_format(drawable, statt);
+ dri2_drawable_get_format(drawable, statt, &format, &bind);
if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE)
continue;
templ.format = format;
+ templ.bind = bind;
whandle.handle = buf->name;
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);
}
@@ -342,7 +345,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
* Backend functions for st_framebuffer interface.
*/
-void
+static void
dri2_allocate_textures(struct dri_drawable *drawable,
const enum st_attachment_type *statts,
unsigned count)
@@ -354,7 +357,7 @@ dri2_allocate_textures(struct dri_drawable *drawable,
dri2_drawable_process_buffers(drawable, buffers, num_buffers);
}
-void
+static void
dri2_flush_frontbuffer(struct dri_drawable *drawable,
enum st_attachment_type statt)
{
@@ -369,7 +372,7 @@ dri2_flush_frontbuffer(struct dri_drawable *drawable,
}
}
-__DRIimage *
+static __DRIimage *
dri2_lookup_egl_image(struct dri_context *ctx, void *handle)
{
__DRIimageLookupExtension *loader = ctx->sPriv->dri2.image;
@@ -431,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);
@@ -508,6 +511,9 @@ dri2_init_screen(__DRIscreen * sPriv)
screen->api = drm_api_create();
screen->sPriv = sPriv;
screen->fd = sPriv->fd;
+ screen->lookup_egl_image = dri2_lookup_egl_image;
+ screen->allocate_textures = dri2_allocate_textures;
+ screen->flush_frontbuffer = dri2_flush_frontbuffer;
sPriv->private = (void *)screen;
sPriv->extensions = dri_screen_extensions;
diff --git a/src/gallium/state_trackers/dri/drm/dri2.h b/src/gallium/state_trackers/dri/drm/dri2.h
index 5b28850000..07adfe4f6c 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.h
+++ b/src/gallium/state_trackers/dri/drm/dri2.h
@@ -34,16 +34,4 @@
const __DRIconfig **
dri2_init_screen(__DRIscreen * sPriv);
-void
-dri2_flush_frontbuffer(struct dri_drawable *drawable,
- enum st_attachment_type statt);
-
-void
-dri2_allocate_textures(struct dri_drawable *drawable,
- const enum st_attachment_type *statts,
- unsigned count);
-
-__DRIimage *
-dri2_lookup_egl_image(struct dri_context *ctx, void *handle);
-
#endif /* DRI2_H */
diff --git a/src/gallium/state_trackers/dri/drm/dri_st_api.c b/src/gallium/state_trackers/dri/drm/dri_st_api.c
deleted file mode 120000
index a8f6bd06b0..0000000000
--- a/src/gallium/state_trackers/dri/drm/dri_st_api.c
+++ /dev/null
@@ -1 +0,0 @@
-../common/dri_st_api.c \ No newline at end of file
diff --git a/src/gallium/state_trackers/dri/sw/Makefile b/src/gallium/state_trackers/dri/sw/Makefile
index 18d7aabd9f..c0ae71451b 100644
--- a/src/gallium/state_trackers/dri/sw/Makefile
+++ b/src/gallium/state_trackers/dri/sw/Makefile
@@ -19,7 +19,6 @@ C_SOURCES = \
dri_context.c \
dri_screen.c \
dri_drawable.c \
- dri_st_api.c \
dri1_helper.c \
drisw.c
diff --git a/src/gallium/state_trackers/dri/sw/SConscript b/src/gallium/state_trackers/dri/sw/SConscript
index c97124c831..6bb282d1a4 100644
--- a/src/gallium/state_trackers/dri/sw/SConscript
+++ b/src/gallium/state_trackers/dri/sw/SConscript
@@ -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',
]
diff --git a/src/gallium/state_trackers/dri/sw/dri_st_api.c b/src/gallium/state_trackers/dri/sw/dri_st_api.c
deleted file mode 120000
index a8f6bd06b0..0000000000
--- a/src/gallium/state_trackers/dri/sw/dri_st_api.c
+++ /dev/null
@@ -1 +0,0 @@
-../common/dri_st_api.c \ No newline at end of file
diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c
index 9edddf01b5..dcf645593f 100644
--- a/src/gallium/state_trackers/dri/sw/drisw.c
+++ b/src/gallium/state_trackers/dri/sw/drisw.c
@@ -70,7 +70,7 @@ put_image(__DRIdrawable *dPriv, void *data, unsigned width, unsigned height)
data, dPriv->loaderPrivate);
}
-void
+static void
drisw_update_drawable_info(struct dri_drawable *drawable)
{
__DRIdrawable *dPriv = drawable->dPriv;
@@ -99,20 +99,20 @@ 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
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;
/* check if swapping currently bound buffer */
if (ctx && ctx->dPriv == dPriv)
- ctx->st->notify_invalid_framebuffer(ctx->st, drawable->stfb);
+ ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
}
static INLINE void
@@ -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;
@@ -147,11 +147,11 @@ drisw_swap_buffers(__DRIdrawable *dPriv)
}
}
-void
+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)
@@ -175,9 +175,10 @@ drisw_flush_frontbuffer(struct dri_drawable *drawable,
* seems a better seperation and safer for each DRI version to provide its own
* function.
*/
-void
+static void
drisw_allocate_textures(struct dri_drawable *drawable,
- unsigned mask)
+ const enum st_attachment_type *statts,
+ unsigned count)
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
struct pipe_resource templ;
@@ -206,38 +207,25 @@ drisw_allocate_textures(struct dri_drawable *drawable,
for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
enum pipe_format format;
- unsigned tex_usage;
+ unsigned bind;
/* the texture already exists or not requested */
- if (drawable->textures[i] || !(mask & (1 << i))) {
+ if (drawable->textures[statts[i]])
continue;
- }
-
- switch (i) {
- case ST_ATTACHMENT_FRONT_LEFT:
- case ST_ATTACHMENT_BACK_LEFT:
- case ST_ATTACHMENT_FRONT_RIGHT:
- case ST_ATTACHMENT_BACK_RIGHT:
- format = drawable->stvis.color_format;
- tex_usage = PIPE_BIND_DISPLAY_TARGET |
- PIPE_BIND_RENDER_TARGET;
- break;
- case ST_ATTACHMENT_DEPTH_STENCIL:
- format = drawable->stvis.depth_stencil_format;
- tex_usage = PIPE_BIND_DEPTH_STENCIL;
- break;
- default:
- format = PIPE_FORMAT_NONE;
- break;
- }
-
- if (format != PIPE_FORMAT_NONE) {
- templ.format = format;
- templ.bind = tex_usage;
-
- drawable->textures[i] =
- screen->pipe_screen->resource_create(screen->pipe_screen, &templ);
- }
+
+ dri_drawable_get_format(drawable, statts[i], &format, &bind);
+
+ if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL)
+ bind |= PIPE_BIND_DISPLAY_TARGET;
+
+ if (format == PIPE_FORMAT_NONE)
+ continue;
+
+ templ.format = format;
+ templ.bind = bind;
+
+ drawable->textures[statts[i]] =
+ screen->base.screen->resource_create(screen->base.screen, &templ);
}
drawable->old_w = width;
@@ -270,6 +258,9 @@ drisw_init_screen(__DRIscreen * sPriv)
screen->api = NULL; /* not needed */
screen->sPriv = sPriv;
screen->fd = -1;
+ screen->allocate_textures = drisw_allocate_textures;
+ screen->update_drawable_info = drisw_update_drawable_info;
+ screen->flush_frontbuffer = drisw_flush_frontbuffer;
sPriv->private = (void *)screen;
sPriv->extensions = drisw_screen_extensions;
diff --git a/src/gallium/state_trackers/dri/sw/drisw.h b/src/gallium/state_trackers/dri/sw/drisw.h
index c0c874f732..6c6c891f35 100644
--- a/src/gallium/state_trackers/dri/sw/drisw.h
+++ b/src/gallium/state_trackers/dri/sw/drisw.h
@@ -38,17 +38,6 @@
const __DRIconfig **
drisw_init_screen(__DRIscreen * sPriv);
-void
-drisw_update_drawable_info(struct dri_drawable *drawable);
-
-void
-drisw_flush_frontbuffer(struct dri_drawable *drawable,
- enum st_attachment_type statt);
-
-void
-drisw_allocate_textures(struct dri_drawable *drawable,
- unsigned mask);
-
void drisw_swap_buffers(__DRIdrawable * dPriv);
#endif /* DRISW_H */
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d_st.c b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
index 57a479f6bc..9744547868 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d_st.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d_st.c
@@ -49,41 +49,39 @@ egl_g3d_st_manager(struct st_manager *smapi)
struct st_api *
egl_g3d_create_st_api(enum st_api_type api)
{
- const char *stmod_name;
struct util_dl_library *lib;
- const struct st_module *mod;
+ const char *proc_name;
+ struct st_api * (*proc)(void) = NULL;
switch (api) {
case ST_API_OPENGL:
- stmod_name = ST_MODULE_OPENGL_SYMBOL;
+ proc_name = ST_CREATE_OPENGL_SYMBOL;
break;
case ST_API_OPENGL_ES1:
- stmod_name = ST_MODULE_OPENGL_ES1_SYMBOL;
+ proc_name = ST_CREATE_OPENGL_ES1_SYMBOL;
break;
case ST_API_OPENGL_ES2:
- stmod_name = ST_MODULE_OPENGL_ES2_SYMBOL;
+ proc_name = ST_CREATE_OPENGL_ES2_SYMBOL;
break;
case ST_API_OPENVG:
- stmod_name = ST_MODULE_OPENVG_SYMBOL;
+ proc_name = ST_CREATE_OPENVG_SYMBOL;
break;
default:
- stmod_name = NULL;
- break;
- }
- if (!stmod_name)
+ assert(!"Unknown API Type\n");
return NULL;
+ }
- mod = NULL;
lib = util_dl_open(NULL);
if (lib) {
- mod = (const struct st_module *)
- util_dl_get_proc_address(lib, stmod_name);
+ proc = util_dl_get_proc_address(lib, proc_name);
+ debug_printf("%s: %s %p\n", __func__, proc_name, proc);
util_dl_close(lib);
}
- if (!mod || mod->api != api)
+
+ if (!proc)
return NULL;
- return mod->create_api();
+ return proc();
}
static boolean
diff --git a/src/gallium/state_trackers/es/st_es1.c b/src/gallium/state_trackers/es/st_es1.c
index 4e89e06b34..825fdac215 100644
--- a/src/gallium/state_trackers/es/st_es1.c
+++ b/src/gallium/state_trackers/es/st_es1.c
@@ -1,8 +1,7 @@
-#include "state_tracker/st_manager.h"
+#include "state_tracker/st_gl_api.h"
-PUBLIC const int st_api_OpenGL_ES1 = 1;
-
-PUBLIC const struct st_module st_module_OpenGL_ES1 = {
- .api = ST_API_OPENGL_ES1,
- .create_api = st_manager_create_api
-};
+PUBLIC struct st_api *
+st_api_create_OpenGL_ES1()
+{
+ return st_gl_api_create();
+}
diff --git a/src/gallium/state_trackers/es/st_es2.c b/src/gallium/state_trackers/es/st_es2.c
index 82e88b176a..5c773aaf93 100644
--- a/src/gallium/state_trackers/es/st_es2.c
+++ b/src/gallium/state_trackers/es/st_es2.c
@@ -1,8 +1,8 @@
-#include "state_tracker/st_manager.h"
+#include "state_tracker/st_gl_api.h"
-PUBLIC const int st_api_OpenGL_ES2 = 1;
-
-PUBLIC const struct st_module st_module_OpenGL_ES2 = {
- .api = ST_API_OPENGL_ES2,
- .create_api = st_manager_create_api
-};
+PUBLIC struct st_api *
+st_api_create_OpenGL_ES2()
+{
+ /* linker magic creates different versions */
+ return st_gl_api_create();
+}
diff --git a/src/gallium/state_trackers/glx/xlib/xm_st.c b/src/gallium/state_trackers/glx/xlib/xm_st.c
index 294b593bf7..1c678b4f76 100644
--- a/src/gallium/state_trackers/glx/xlib/xm_st.c
+++ b/src/gallium/state_trackers/glx/xlib/xm_st.c
@@ -125,7 +125,7 @@ xmesa_st_framebuffer_copy_textures(struct st_framebuffer_iface *stfbi,
/**
* Remove outdated textures and create the requested ones.
*/
-static void
+static boolean
xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
unsigned width, unsigned height,
unsigned mask)
@@ -183,12 +183,16 @@ xmesa_st_framebuffer_validate_textures(struct st_framebuffer_iface *stfbi,
xstfb->textures[i] =
xstfb->screen->resource_create(xstfb->screen, &templ);
+ if (!xstfb->textures[i])
+ return FALSE;
}
}
xstfb->texture_width = width;
xstfb->texture_height = height;
xstfb->texture_mask = mask;
+
+ return TRUE;
}
static boolean
@@ -200,6 +204,7 @@ xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
struct xmesa_st_framebuffer *xstfb = xmesa_st_framebuffer(stfbi);
unsigned statt_mask, new_mask, i;
boolean resized;
+ boolean ret;
statt_mask = 0x0;
for (i = 0; i < count; i++)
@@ -212,8 +217,10 @@ xmesa_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
/* revalidate textures */
if (resized || new_mask) {
- xmesa_st_framebuffer_validate_textures(stfbi,
- xstfb->buffer->width, xstfb->buffer->height, statt_mask);
+ ret = xmesa_st_framebuffer_validate_textures(stfbi,
+ xstfb->buffer->width, xstfb->buffer->height, statt_mask);
+ if (!ret)
+ return ret;
if (!resized) {
enum st_attachment_type back, front;
diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c
index e4226754d1..aecac28e7e 100644
--- a/src/gallium/state_trackers/vega/vg_manager.c
+++ b/src/gallium/state_trackers/vega/vg_manager.c
@@ -546,26 +546,17 @@ vg_api_destroy(struct st_api *stapi)
free(stapi);
}
-static struct st_api *
-vg_module_create_api(void)
-{
- struct st_api *stapi;
-
- stapi = CALLOC_STRUCT(st_api);
- if (stapi) {
- stapi->destroy = vg_api_destroy;
- stapi->get_proc_address = vg_api_get_proc_address;
- stapi->is_visual_supported = vg_api_is_visual_supported;
-
- stapi->create_context = vg_api_create_context;
- stapi->make_current = vg_api_make_current;
- stapi->get_current = vg_api_get_current;
- }
+struct st_api st_vg_api = {
+ vg_api_destroy,
+ vg_api_get_proc_address,
+ vg_api_is_visual_supported,
+ vg_api_create_context,
+ vg_api_make_current,
+ vg_api_get_current,
+};
- return stapi;
+struct st_api *
+st_api_create_OpenVG(void)
+{
+ return &st_vg_api;
}
-
-PUBLIC const struct st_module st_module_OpenVG = {
- .api = ST_API_OPENVG,
- .create_api = vg_module_create_api,
-};
diff --git a/src/gallium/state_trackers/wgl/stw_st.c b/src/gallium/state_trackers/wgl/stw_st.c
index f4ea61ed2c..bcdd82e4f6 100644
--- a/src/gallium/state_trackers/wgl/stw_st.c
+++ b/src/gallium/state_trackers/wgl/stw_st.c
@@ -27,7 +27,7 @@
#include "util/u_memory.h"
#include "util/u_inlines.h"
-#include "state_tracker/st_manager.h" /* for st_manager_create_api */
+#include "state_tracker/st_gl_api.h" /* for st_gl_api_create */
#include "stw_st.h"
#include "stw_device.h"
@@ -308,5 +308,5 @@ stw_st_swap_framebuffer_locked(struct st_framebuffer_iface *stfb)
struct st_api *
stw_st_create_api(void)
{
- return st_manager_create_api();
+ return st_gl_api_create();
}