summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/glx
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2009-01-12 19:33:44 +0000
committerKeith Whitwell <keith@tungstengraphics.com>2009-01-12 19:33:44 +0000
commit3e492acc579ba0a98d0388aa73605aba5bf9840c (patch)
tree07a50917cc3e9b156251adcc1b155d1053bfcf66 /src/gallium/state_trackers/glx
parent3425257e14e3f4b1f663649856f73b520726db9b (diff)
dri: pull dri_swapbuffers.c into dri_drawable.c
Diffstat (limited to 'src/gallium/state_trackers/glx')
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_context.h48
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_drawable.c303
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_drawable.h (renamed from src/gallium/state_trackers/glx/dri/dri_swapbuffers.h)49
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_lock.c6
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_screen.h15
-rw-r--r--src/gallium/state_trackers/glx/dri/dri_swapbuffers.c295
6 files changed, 370 insertions, 346 deletions
diff --git a/src/gallium/state_trackers/glx/dri/dri_context.h b/src/gallium/state_trackers/glx/dri/dri_context.h
index 06b86d69a8..4e6a305abb 100644
--- a/src/gallium/state_trackers/glx/dri/dri_context.h
+++ b/src/gallium/state_trackers/glx/dri/dri_context.h
@@ -27,12 +27,10 @@
#ifndef DRI_CONTEXT_H
#define DRI_CONTEXT_H
-#include <stdint.h>
+#include "pipe/p_compiler.h"
#include "drm.h"
+#include "dri_util.h"
-#include "pipe/p_debug.h"
-
-#include "dri_screen.h"
struct pipe_context;
struct pipe_fence;
@@ -56,35 +54,39 @@ struct dri_context
};
-
-struct dri_drawable
-{
- __DRIdrawablePrivate *dPriv;
- unsigned stamp;
-
- struct pipe_fence *last_swap_fence;
- struct pipe_fence *first_swap_fence;
-
- struct st_framebuffer *stfb;
-};
-
-
static INLINE struct dri_context *
dri_context(__DRIcontextPrivate *driContextPriv)
{
return (struct dri_context *) driContextPriv->driverPrivate;
}
-static INLINE struct dri_drawable *
-dri_drawable(__DRIdrawablePrivate * driDrawPriv)
-{
- return (struct dri_drawable *) driDrawPriv->driverPrivate;
-}
+/***********************************************************************
+ * dri_context.c
+ */
+void
+dri_destroy_context(__DRIcontextPrivate * driContextPriv);
+
+boolean
+dri_unbind_context(__DRIcontextPrivate * driContextPriv);
+
+boolean
+dri_make_current(__DRIcontextPrivate * driContextPriv,
+ __DRIdrawablePrivate * driDrawPriv,
+ __DRIdrawablePrivate * driReadPriv);
+
+boolean
+dri_create_context(const __GLcontextModes * visual,
+ __DRIcontextPrivate * driContextPriv,
+ void *sharedContextPrivate);
+
+
/***********************************************************************
* dri_lock.c
*/
-void dri_lock_hardware( struct dri_context *dri, struct dri_drawable *drawable );
+void dri_lock_hardware( struct dri_context *context,
+ struct dri_drawable *drawable );
+
void dri_unlock_hardware( struct dri_context *dri );
boolean dri_is_locked( struct dri_context *dri );
diff --git a/src/gallium/state_trackers/glx/dri/dri_drawable.c b/src/gallium/state_trackers/glx/dri/dri_drawable.c
index 7503c40194..53ac3dbb8c 100644
--- a/src/gallium/state_trackers/glx/dri/dri_drawable.c
+++ b/src/gallium/state_trackers/glx/dri/dri_drawable.c
@@ -1,3 +1,298 @@
+/**************************************************************************
+ *
+ * Copyright 2009, VMware, Inc.
+ * All Rights Reserved.
+ *
+ * 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, sub license, 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#include "dri_screen.h"
+#include "dri_context.h"
+#include "dri_swapbuffers.h"
+
+#include "pipe/p_context.h"
+#include "state_tracker/st_public.h"
+#include "state_tracker/st_context.h"
+#include "state_tracker/st_cb_fbo.h"
+
+
+static void
+blit_swapbuffers(__DRIdrawablePrivate *dPriv,
+ __DRIcontextPrivate *cPriv,
+ struct pipe_surface *src,
+ const drm_clip_rect_t *rect)
+{
+ struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
+ struct dri_drawable *fb = dri_drawable(dPriv);
+ struct dri_context *context = dri_context(cPriv);
+
+ const int nbox = dPriv->numClipRects;
+ const drm_clip_rect_t *pbox = dPriv->pClipRects;
+
+ struct pipe_surface *dest = fb->front_surface;
+ const int backWidth = fb->stfb->Base.Width;
+ const int backHeight = fb->stfb->Base.Height;
+ int i;
+
+ for (i = 0; i < nbox; i++, pbox++) {
+ drm_clip_rect_t box;
+ drm_clip_rect_t sbox;
+
+ if (pbox->x1 > pbox->x2 ||
+ pbox->y1 > pbox->y2 ||
+ (pbox->x2 - pbox->x1) > dest->width ||
+ (pbox->y2 - pbox->y1) > dest->height)
+ continue;
+
+ box = *pbox;
+
+ if (rect) {
+ drm_clip_rect_t rrect;
+
+ rrect.x1 = dPriv->x + rect->x1;
+ rrect.y1 = (dPriv->h - rect->y1 - rect->y2) + dPriv->y;
+ rrect.x2 = rect->x2 + rrect.x1;
+ rrect.y2 = rect->y2 + rrect.y1;
+ if (rrect.x1 > box.x1)
+ box.x1 = rrect.x1;
+ if (rrect.y1 > box.y1)
+ box.y1 = rrect.y1;
+ if (rrect.x2 < box.x2)
+ box.x2 = rrect.x2;
+ if (rrect.y2 < box.y2)
+ box.y2 = rrect.y2;
+
+ if (box.x1 > box.x2 || box.y1 > box.y2)
+ continue;
+ }
+
+ /* restrict blit to size of actually rendered area */
+ if (box.x2 - box.x1 > backWidth)
+ box.x2 = backWidth + box.x1;
+ if (box.y2 - box.y1 > backHeight)
+ box.y2 = backHeight + box.y1;
+
+ debug_printf("%s: box %d,%d-%d,%d\n", __FUNCTION__,
+ box.x1, box.y1, box.x2, box.y2);
+
+ sbox.x1 = box.x1 - dPriv->x;
+ sbox.y1 = box.y1 - dPriv->y;
+
+ ctx->st->pipe->surface_copy( ctx->st->pipe,
+ FALSE,
+ dest,
+ box.x1, box.y1,
+ src,
+ sbox.x1, sbox.y1,
+ box.x2 - box.x1,
+ box.y2 - box.y1 );
+ }
+}
+
+/**
+ * Display a colorbuffer surface in an X window.
+ * Used for SwapBuffers and flushing front buffer rendering.
+ *
+ * \param dPriv the window/drawable to display into
+ * \param surf the surface to display
+ * \param rect optional subrect of surface to display (may be NULL).
+ */
+void
+dri_display_surface(__DRIdrawablePrivate *dPriv,
+ struct pipe_surface *source,
+ const drm_clip_rect_t *rect)
+{
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
+ struct dri_context *context = screen->dummy_context;
+ struct pipe_winsys *winsys = screen->winsys;
+
+ if (!context)
+ return;
+
+ if (drawable->last_swap_fence) {
+ winsys->fence_finish( winsys,
+ drawable->last_swap_fence,
+ 0 );
+
+ winsys->fence_reference( winsys,
+ &drawable->last_swap_fence,
+ NULL );
+ }
+
+ drawable->last_swap_fence = drawable->first_swap_fence;
+ drawable->first_swap_fence = NULL;
+
+ /* The lock_hardware is required for the cliprects. Buffer offsets
+ * should work regardless.
+ */
+ dri_lock_hardware(context, drawable);
+ {
+ if (dPriv->numClipRects) {
+ blit_swapbuffers( context, dPriv, source, rect );
+ }
+ }
+ dri_unlock_hardware(context);
+
+ if (drawble->stamp != drawable->dPriv->lastStamp) {
+ dri_update_window_size( dpriv );
+ }
+}
+
+
+
+/**
+ * This will be called a drawable is known to have moved/resized.
+ */
+void
+dri_update_window_size(__DRIdrawablePrivate *dPriv)
+{
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ st_resize_framebuffer(drawable->stfb, dPriv->w, dPriv->h);
+ drawable->stamp = dPriv->lastStamp;
+}
+
+
+
+void
+dri_swap_buffers(__DRIdrawablePrivate * dPriv)
+{
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ struct pipe_surface *back_surf;
+
+ assert(drawable);
+ assert(drawable->stfb);
+
+ back_surf = st_get_framebuffer_surface(drawable->stfb,
+ ST_SURFACE_BACK_LEFT);
+ if (back_surf) {
+ st_notify_swapbuffers(drawable->stfb);
+ dri_display_surface(dPriv, back_surf, NULL);
+ st_notify_swapbuffers_complete(drawable->stfb);
+ }
+}
+
+
+/**
+ * Called via glXCopySubBufferMESA() to copy a subrect of the back
+ * buffer to the front buffer/screen.
+ */
+void
+dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h)
+{
+ struct dri_drawable *drawable = dri_drawable(dPriv);
+ struct pipe_surface *back_surf;
+
+ assert(drawable);
+ assert(drawable->stfb);
+
+ back_surf = st_get_framebuffer_surface(drawable->stfb,
+ ST_SURFACE_BACK_LEFT);
+ if (back_surf) {
+ drm_clip_rect_t rect;
+ rect.x1 = x;
+ rect.y1 = y;
+ rect.x2 = w;
+ rect.y2 = h;
+
+ st_notify_swapbuffers(drawable->stfb);
+ dri_display_surface(dPriv, back_surf, &rect);
+ }
+}
+
+
+
+/*
+ * The state tracker keeps track of whether the fake frontbuffer has
+ * been touched by any rendering since the last time we copied its
+ * contents to the real frontbuffer. Our task is easy:
+ */
+static void
+dri_flush_frontbuffer( struct pipe_winsys *winsys,
+ struct pipe_surface *surf,
+ void *context_private)
+{
+ struct dri_context *dri = (struct dri_context *) context_private;
+ __DRIdrawablePrivate *dPriv = dri->driDrawable;
+
+ dri_display_surface(dPriv, surf, NULL);
+}
+
+
+
+/* Need to create a surface which wraps the front surface to support
+ * client-side swapbuffers.
+ */
+static void
+dri_create_front_surface(struct dri_screen *screen,
+ struct pipe_winsys *winsys,
+ unsigned handle)
+{
+ struct pipe_screen *pipe_screen = screen->pipe_screen;
+ struct pipe_texture *texture;
+ struct pipe_texture templat;
+ struct pipe_surface *surface;
+ struct pipe_buffer *buffer;
+ unsigned pitch;
+
+ assert(screen->front.cpp == 4);
+
+// buffer = dri_buffer_from_handle(screen->winsys,
+// "front", handle);
+
+ if (!buffer)
+ return;
+
+ screen->front.buffer = dri_bo(buffer);
+
+ memset(&templat, 0, sizeof(templat));
+ templat.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+ templat.target = PIPE_TEXTURE_2D;
+ templat.last_level = 0;
+ templat.depth[0] = 1;
+ templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
+ templat.width[0] = screen->front.width;
+ templat.height[0] = screen->front.height;
+ pf_get_block(templat.format, &templat.block);
+ pitch = screen->front.pitch;
+
+ texture = pipe_screen->texture_blanket(pipe_screen,
+ &templat,
+ &pitch,
+ buffer);
+
+ /* Unref the buffer we don't need it anyways */
+ pipe_buffer_reference(screen, &buffer, NULL);
+
+ surface = pipe_screen->get_tex_surface(pipe_screen,
+ texture,
+ 0,
+ 0,
+ 0,
+ PIPE_BUFFER_USAGE_GPU_WRITE);
+
+ screen->front.texture = texture;
+ screen->front.surface = surface;
+}
/**
* This is called when we need to set up GL rendering to a new X window.
@@ -56,8 +351,14 @@ static void
dri_destroy_buffer(__DRIdrawablePrivate *dPriv)
{
struct dri_drawable *drawable = dri_drawable(dPriv);
- assert(drawable->stfb);
+
+ /* No particular need to wait on fences before dereferencing them:
+ */
+ winsys->fence_reference( winsys, &ctx->last_swap_fence, NULL );
+ winsys->fence_reference( winsys, &ctx->first_swap_fence, NULL );
+
st_unreference_framebuffer(drawable->stfb);
+
FREE(drawable);
}
diff --git a/src/gallium/state_trackers/glx/dri/dri_swapbuffers.h b/src/gallium/state_trackers/glx/dri/dri_drawable.h
index 1b8cd85704..cf6b3c8964 100644
--- a/src/gallium/state_trackers/glx/dri/dri_swapbuffers.h
+++ b/src/gallium/state_trackers/glx/dri/dri_drawable.h
@@ -25,23 +25,54 @@
*
**************************************************************************/
-#ifndef DRI_SWAPBUFFERS_H
-#define DRI_SWAPBUFFERS_H
+#ifndef DRI_DRAWABLE_H
+#define DRI_DRAWABLE_H
+#include "pipe/p_compiler.h"
struct pipe_surface;
+struct pipe_fence;
+struct st_framebuffer;
-extern void dri_display_surface(__DRIdrawablePrivate * dPriv,
- struct pipe_surface *surf,
- const drm_clip_rect_t * rect);
+struct dri_drawable
+{
+ __DRIdrawablePrivate *dPriv;
+ unsigned stamp;
-extern void dri_swap_buffers(__DRIdrawablePrivate * dPriv);
+ struct pipe_fence *last_swap_fence;
+ struct pipe_fence *first_swap_fence;
-extern void dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv,
- int x, int y, int w, int h);
+ struct st_framebuffer *stfb;
+};
-extern void dri_update_window_size(__DRIdrawablePrivate *dPriv);
+
+static INLINE struct dri_drawable *
+dri_drawable(__DRIdrawablePrivate * driDrawPriv)
+{
+ return (struct dri_drawable *) driDrawPriv->driverPrivate;
+}
+
+
+/***********************************************************************
+ * dri_drawable.c
+ */
+
+void
+dri_display_surface(__DRIdrawablePrivate * dPriv,
+ struct pipe_surface *surf,
+ const drm_clip_rect_t * rect);
+
+void
+dri_swap_buffers(__DRIdrawablePrivate * dPriv);
+
+void
+dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv,
+ int x, int y,
+ int w, int h);
+
+void
+dri_update_window_size(__DRIdrawablePrivate *dPriv);
#endif
diff --git a/src/gallium/state_trackers/glx/dri/dri_lock.c b/src/gallium/state_trackers/glx/dri/dri_lock.c
index 9d7bd61e28..b272ab55f3 100644
--- a/src/gallium/state_trackers/glx/dri/dri_lock.c
+++ b/src/gallium/state_trackers/glx/dri/dri_lock.c
@@ -37,7 +37,7 @@ dri_contended_lock(struct dri_context *ctx)
{
__DRIdrawablePrivate *dPriv = ctx->dPriv;
__DRIcontextPrivate *cPriv = ctx->cPriv;
- __DRIscreenPrivate *sPriv = ctx->sPriv;
+ __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
drmGetLock(sPriv->fd, cPriv->hHWContext, 0);
@@ -53,8 +53,8 @@ dri_contended_lock(struct dri_context *ctx)
*/
void dri_lock_hardware( struct dri_context *ctx )
{
- __DRIscreenPrivate *sPriv = ctx->sPriv;
__DRIcontextPrivate *cPriv = ctx->cPriv;
+ __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
char __ret = 0;
pipe_mutex_lock(lockMutex);
@@ -76,8 +76,8 @@ void dri_lock_hardware( struct dri_context *ctx )
*/
void dri_unlock_hardware( struct dri_context *ctx )
{
- __DRIscreenPrivate *sPriv = ctx->sPriv;
__DRIcontextPrivate *cPriv = ctx->cPriv;
+ __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
assert(ctx->locked);
ctx->locked = FALSE;
diff --git a/src/gallium/state_trackers/glx/dri/dri_screen.h b/src/gallium/state_trackers/glx/dri/dri_screen.h
index 8909c920e4..12ed86d22a 100644
--- a/src/gallium/state_trackers/glx/dri/dri_screen.h
+++ b/src/gallium/state_trackers/glx/dri/dri_screen.h
@@ -79,20 +79,5 @@ dri_screen(__DRIscreenPrivate *sPriv)
}
-extern void dri_destroy_context(__DRIcontextPrivate * driContextPriv);
-
-extern boolean dri_unbind_context(__DRIcontextPrivate * driContextPriv);
-
-extern boolean
-dri_make_current(__DRIcontextPrivate * driContextPriv,
- __DRIdrawablePrivate * driDrawPriv,
- __DRIdrawablePrivate * driReadPriv);
-
-
-extern boolean
-dri_create_context(const __GLcontextModes * visual,
- __DRIcontextPrivate * driContextPriv,
- void *sharedContextPrivate);
-
#endif
diff --git a/src/gallium/state_trackers/glx/dri/dri_swapbuffers.c b/src/gallium/state_trackers/glx/dri/dri_swapbuffers.c
deleted file mode 100644
index 6b2b930134..0000000000
--- a/src/gallium/state_trackers/glx/dri/dri_swapbuffers.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009, VMware, Inc.
- * All Rights Reserved.
- *
- * 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, sub license, 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 (including the
- * next paragraph) 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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.
- *
- **************************************************************************/
-
-#include "dri_screen.h"
-#include "dri_context.h"
-#include "dri_swapbuffers.h"
-
-#include "pipe/p_context.h"
-#include "state_tracker/st_public.h"
-#include "state_tracker/st_context.h"
-#include "state_tracker/st_cb_fbo.h"
-
-
-static void
-blit_swapbuffers(__DRIdrawablePrivate *dPriv,
- __DRIcontextPrivate *cPriv,
- struct pipe_surface *src,
- const drm_clip_rect_t *rect)
-{
- struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
- struct dri_drawable *fb = dri_drawable(dPriv);
- struct dri_context *context = dri_context(cPriv);
-
- const int nbox = dPriv->numClipRects;
- const drm_clip_rect_t *pbox = dPriv->pClipRects;
-
- struct pipe_surface *dest = fb->front_surface;
- const int backWidth = fb->stfb->Base.Width;
- const int backHeight = fb->stfb->Base.Height;
- int i;
-
- for (i = 0; i < nbox; i++, pbox++) {
- drm_clip_rect_t box;
- drm_clip_rect_t sbox;
-
- if (pbox->x1 > pbox->x2 ||
- pbox->y1 > pbox->y2 ||
- (pbox->x2 - pbox->x1) > dest->width ||
- (pbox->y2 - pbox->y1) > dest->height)
- continue;
-
- box = *pbox;
-
- if (rect) {
- drm_clip_rect_t rrect;
-
- rrect.x1 = dPriv->x + rect->x1;
- rrect.y1 = (dPriv->h - rect->y1 - rect->y2) + dPriv->y;
- rrect.x2 = rect->x2 + rrect.x1;
- rrect.y2 = rect->y2 + rrect.y1;
- if (rrect.x1 > box.x1)
- box.x1 = rrect.x1;
- if (rrect.y1 > box.y1)
- box.y1 = rrect.y1;
- if (rrect.x2 < box.x2)
- box.x2 = rrect.x2;
- if (rrect.y2 < box.y2)
- box.y2 = rrect.y2;
-
- if (box.x1 > box.x2 || box.y1 > box.y2)
- continue;
- }
-
- /* restrict blit to size of actually rendered area */
- if (box.x2 - box.x1 > backWidth)
- box.x2 = backWidth + box.x1;
- if (box.y2 - box.y1 > backHeight)
- box.y2 = backHeight + box.y1;
-
- debug_printf("%s: box %d,%d-%d,%d\n", __FUNCTION__,
- box.x1, box.y1, box.x2, box.y2);
-
- sbox.x1 = box.x1 - dPriv->x;
- sbox.y1 = box.y1 - dPriv->y;
-
- ctx->st->pipe->surface_copy( ctx->st->pipe,
- FALSE,
- dest,
- box.x1, box.y1,
- src,
- sbox.x1, sbox.y1,
- box.x2 - box.x1,
- box.y2 - box.y1 );
- }
-}
-
-/**
- * Display a colorbuffer surface in an X window.
- * Used for SwapBuffers and flushing front buffer rendering.
- *
- * \param dPriv the window/drawable to display into
- * \param surf the surface to display
- * \param rect optional subrect of surface to display (may be NULL).
- */
-void
-dri_display_surface(__DRIdrawablePrivate *dPriv,
- struct pipe_surface *source,
- const drm_clip_rect_t *rect)
-{
- struct dri_drawable *drawable = dri_drawable(dPriv);
- struct dri_screen *screen = dri_screen(dPriv->driScreenPriv);
- struct dri_context *context = screen->dummy_context;
- struct pipe_winsys *winsys = screen->winsys;
-
- if (!context)
- return;
-
- if (drawable->last_swap_fence) {
- winsys->fence_finish( winsys,
- drawable->last_swap_fence,
- 0 );
-
- winsys->fence_reference( winsys,
- &drawable->last_swap_fence,
- NULL );
- }
-
- drawable->last_swap_fence = drawable->first_swap_fence;
- drawable->first_swap_fence = NULL;
-
- /* The lock_hardware is required for the cliprects. Buffer offsets
- * should work regardless.
- */
- dri_lock_hardware(context, drawable);
- {
- if (dPriv->numClipRects) {
- blit_swapbuffers( context, dPriv, source, rect );
- }
- }
- dri_unlock_hardware(context);
-
- if (drawble->stamp != drawable->dPriv->lastStamp) {
- dri_update_window_size( dpriv );
- }
-}
-
-
-
-/**
- * This will be called a drawable is known to have moved/resized.
- */
-void
-dri_update_window_size(__DRIdrawablePrivate *dPriv)
-{
- struct dri_drawable *drawable = dri_drawable(dPriv);
- st_resize_framebuffer(drawable->stfb, dPriv->w, dPriv->h);
- drawable->stamp = dPriv->lastStamp;
-}
-
-
-
-void
-dri_swap_buffers(__DRIdrawablePrivate * dPriv)
-{
- struct dri_drawable *drawable = dri_drawable(dPriv);
- struct pipe_surface *back_surf;
-
- assert(drawable);
- assert(drawable->stfb);
-
- back_surf = st_get_framebuffer_surface(drawable->stfb,
- ST_SURFACE_BACK_LEFT);
- if (back_surf) {
- st_notify_swapbuffers(drawable->stfb);
- dri_display_surface(dPriv, back_surf, NULL);
- st_notify_swapbuffers_complete(drawable->stfb);
- }
-}
-
-
-/**
- * Called via glXCopySubBufferMESA() to copy a subrect of the back
- * buffer to the front buffer/screen.
- */
-void
-dri_copy_sub_buffer(__DRIdrawablePrivate * dPriv, int x, int y, int w, int h)
-{
- struct dri_drawable *drawable = dri_drawable(dPriv);
- struct pipe_surface *back_surf;
-
- assert(drawable);
- assert(drawable->stfb);
-
- back_surf = st_get_framebuffer_surface(drawable->stfb,
- ST_SURFACE_BACK_LEFT);
- if (back_surf) {
- drm_clip_rect_t rect;
- rect.x1 = x;
- rect.y1 = y;
- rect.x2 = w;
- rect.y2 = h;
-
- st_notify_swapbuffers(drawable->stfb);
- dri_display_surface(dPriv, back_surf, &rect);
- }
-}
-
-
-
-/*
- * The state tracker keeps track of whether the fake frontbuffer has
- * been touched by any rendering since the last time we copied its
- * contents to the real frontbuffer. Our task is easy:
- */
-static void
-dri_flush_frontbuffer( struct pipe_winsys *winsys,
- struct pipe_surface *surf,
- void *context_private)
-{
- struct dri_context *dri = (struct dri_context *) context_private;
- __DRIdrawablePrivate *dPriv = dri->driDrawable;
-
- dri_display_surface(dPriv, surf, NULL);
-}
-
-
-
-/* Need to create a surface which wraps the front surface to support
- * client-side swapbuffers.
- */
-static void
-dri_create_front_surface(struct dri_screen *screen,
- struct pipe_winsys *winsys,
- unsigned handle)
-{
- struct pipe_screen *pipe_screen = screen->pipe_screen;
- struct pipe_texture *texture;
- struct pipe_texture templat;
- struct pipe_surface *surface;
- struct pipe_buffer *buffer;
- unsigned pitch;
-
- assert(screen->front.cpp == 4);
-
-// buffer = dri_buffer_from_handle(screen->winsys,
-// "front", handle);
-
- if (!buffer)
- return;
-
- screen->front.buffer = dri_bo(buffer);
-
- memset(&templat, 0, sizeof(templat));
- templat.tex_usage |= PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
- templat.target = PIPE_TEXTURE_2D;
- templat.last_level = 0;
- templat.depth[0] = 1;
- templat.format = PIPE_FORMAT_A8R8G8B8_UNORM;
- templat.width[0] = screen->front.width;
- templat.height[0] = screen->front.height;
- pf_get_block(templat.format, &templat.block);
- pitch = screen->front.pitch;
-
- texture = pipe_screen->texture_blanket(pipe_screen,
- &templat,
- &pitch,
- buffer);
-
- /* Unref the buffer we don't need it anyways */
- pipe_buffer_reference(screen, &buffer, NULL);
-
- surface = pipe_screen->get_tex_surface(pipe_screen,
- texture,
- 0,
- 0,
- 0,
- PIPE_BUFFER_USAGE_GPU_WRITE);
-
- screen->front.texture = texture;
- screen->front.surface = surface;
-}