aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/g3dvl/nouveau
diff options
context:
space:
mode:
authorYounes Manton <[email protected]>2009-01-10 13:30:29 -0500
committerYounes Manton <[email protected]>2009-01-10 13:52:07 -0500
commit8ee238be7587a232beeb56b1dc3b75e1b8fb903e (patch)
treea0b25eda15eb123ff7742f18faa735ea9e10b288 /src/gallium/winsys/g3dvl/nouveau
parent734b3cb182b4b7d1075faf60c1a23ab0a55af356 (diff)
nouveau: Factor out common winsys bits into libnouveaudrm.a
Diffstat (limited to 'src/gallium/winsys/g3dvl/nouveau')
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/Makefile48
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_context.c370
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_context.h105
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.c172
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.h39
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.c (renamed from src/gallium/winsys/g3dvl/nouveau/nouveau_screen.c)45
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.h (renamed from src/gallium/winsys/g3dvl/nouveau/nouveau_screen.h)20
-rw-r--r--src/gallium/winsys/g3dvl/nouveau/nouveau_swapbuffers.c61
8 files changed, 308 insertions, 552 deletions
diff --git a/src/gallium/winsys/g3dvl/nouveau/Makefile b/src/gallium/winsys/g3dvl/nouveau/Makefile
index ff43327778a..22d925b6436 100644
--- a/src/gallium/winsys/g3dvl/nouveau/Makefile
+++ b/src/gallium/winsys/g3dvl/nouveau/Makefile
@@ -3,35 +3,33 @@ GALLIUMDIR = ../../..
DRMDIR ?= /usr
DRIDIR = ../../../../driclient
-OBJECTS = nouveau_bo.o nouveau_fence.o nouveau_swapbuffers.o nouveau_channel.o \
- nouveau_grobj.o nouveau_context.o nouveau_winsys.o nouveau_lock.o \
- nouveau_winsys_pipe.o nouveau_device.o nouveau_notifier.o nouveau_dma.o \
- nouveau_pushbuf.o nouveau_resource.o nouveau_screen.o nv04_surface.o \
- nv50_surface.o #nouveau_winsys_softpipe.o
-
-CFLAGS += -g -Wall -fPIC \
- -I${GALLIUMDIR}/include \
- -I${GALLIUMDIR}/winsys/g3dvl \
- -I${DRMDIR}/include \
- -I${DRMDIR}/include/drm \
- -I${GALLIUMDIR}/drivers \
- -I${GALLIUMDIR}/auxiliary \
+OBJECTS = nouveau_screen_vl.o nouveau_context_vl.o nouveau_swapbuffers.o
+
+CFLAGS += -g -Wall -Werror=implicit-function-declaration -fPIC \
+ -I${GALLIUMDIR}/include \
+ -I${GALLIUMDIR}/winsys/g3dvl \
+ -I${GALLIUMDIR}/winsys/drm/nouveau \
+ -I${DRMDIR}/include \
+ -I${DRMDIR}/include/drm \
+ -I${GALLIUMDIR}/drivers \
+ -I${GALLIUMDIR}/auxiliary \
-I${DRIDIR}/include
-LDFLAGS += -L${DRMDIR}/lib \
- -L${DRIDIR}/lib \
- -L${GALLIUMDIR}/auxiliary/draw \
- -L${GALLIUMDIR}/auxiliary/tgsi \
- -L${GALLIUMDIR}/auxiliary/translate \
- -L${GALLIUMDIR}/auxiliary/rtasm \
- -L${GALLIUMDIR}/auxiliary/cso_cache \
- -L${GALLIUMDIR}/drivers/nv10 \
- -L${GALLIUMDIR}/drivers/nv20 \
- -L${GALLIUMDIR}/drivers/nv30 \
- -L${GALLIUMDIR}/drivers/nv40 \
+LDFLAGS += -L${DRMDIR}/lib \
+ -L${DRIDIR}/lib \
+ -L${GALLIUMDIR}/winsys/drm/nouveau/common \
+ -L${GALLIUMDIR}/auxiliary/draw \
+ -L${GALLIUMDIR}/auxiliary/tgsi \
+ -L${GALLIUMDIR}/auxiliary/translate \
+ -L${GALLIUMDIR}/auxiliary/rtasm \
+ -L${GALLIUMDIR}/auxiliary/cso_cache \
+ -L${GALLIUMDIR}/drivers/nv10 \
+ -L${GALLIUMDIR}/drivers/nv20 \
+ -L${GALLIUMDIR}/drivers/nv30 \
+ -L${GALLIUMDIR}/drivers/nv40 \
-L${GALLIUMDIR}/drivers/nv50
-LIBS += -ldriclient -ldrm -lnv10 -lnv20 -lnv30 -lnv40 -lnv50 -ldraw -ltgsi -ltranslate -lrtasm -lcso_cache -lm
+LIBS += -lnouveaudrm -ldriclient -ldrm -lnv10 -lnv20 -lnv30 -lnv40 -lnv50 -ldraw -ltgsi -ltranslate -lrtasm -lcso_cache -lm
#############################################
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_context.c b/src/gallium/winsys/g3dvl/nouveau/nouveau_context.c
deleted file mode 100644
index 06a61fcda3e..00000000000
--- a/src/gallium/winsys/g3dvl/nouveau/nouveau_context.c
+++ /dev/null
@@ -1,370 +0,0 @@
-#include "pipe/p_defines.h"
-#include "pipe/p_context.h"
-#include "pipe/p_screen.h"
-#include "util/u_memory.h"
-
-#include "nouveau_context.h"
-#include "nouveau_dri.h"
-#include "nouveau_local.h"
-#include "nouveau_screen.h"
-#include "nouveau_winsys_pipe.h"
-
-/*
-#ifdef DEBUG
-static const struct dri_debug_control debug_control[] = {
- { "bo", DEBUG_BO },
- { NULL, 0 }
-};
-int __nouveau_debug = 0;
-#endif
-*/
-
-/*
- * TODO: Re-examine dri_screen, dri_context, nouveau_screen, nouveau_context
- * relationships, seems like there is a lot of room for simplification there.
- */
-
-static void
-nouveau_channel_context_destroy(struct nouveau_channel_context *nvc)
-{
- nouveau_grobj_free(&nvc->NvCtxSurf2D);
- nouveau_grobj_free(&nvc->NvImageBlit);
- nouveau_grobj_free(&nvc->NvGdiRect);
- nouveau_grobj_free(&nvc->NvM2MF);
- nouveau_grobj_free(&nvc->Nv2D);
- nouveau_grobj_free(&nvc->NvSwzSurf);
- nouveau_grobj_free(&nvc->NvSIFM);
-
- nouveau_notifier_free(&nvc->sync_notifier);
-
- nouveau_channel_free(&nvc->channel);
-
- FREE(nvc);
-}
-
-static struct nouveau_channel_context *
-nouveau_channel_context_create(struct nouveau_device *dev)
-{
- struct nouveau_channel_context *nvc;
- int ret;
-
- nvc = CALLOC_STRUCT(nouveau_channel_context);
- if (!nvc)
- return NULL;
-
- if ((ret = nouveau_channel_alloc(dev, 0x8003d001, 0x8003d002,
- &nvc->channel))) {
- NOUVEAU_ERR("Error creating GPU channel: %d\n", ret);
- nouveau_channel_context_destroy(nvc);
- return NULL;
- }
-
- nvc->next_handle = 0x80000000;
-
- if ((ret = nouveau_notifier_alloc(nvc->channel, nvc->next_handle++, 1,
- &nvc->sync_notifier))) {
- NOUVEAU_ERR("Error creating channel sync notifier: %d\n", ret);
- nouveau_channel_context_destroy(nvc);
- return NULL;
- }
-
- switch (dev->chipset & 0xf0) {
- case 0x50:
- case 0x80:
- case 0x90:
- ret = nouveau_surface_channel_create_nv50(nvc);
- break;
- default:
- ret = nouveau_surface_channel_create_nv04(nvc);
- break;
- }
-
- if (ret) {
- NOUVEAU_ERR("Error initialising surface objects: %d\n", ret);
- nouveau_channel_context_destroy(nvc);
- return NULL;
- }
-
- return nvc;
-}
-
-int
-nouveau_context_create(dri_context_t *dri_context)
-{
- dri_screen_t *dri_screen = dri_context->dri_screen;
- struct nouveau_screen *nv_screen = dri_screen->private;
- struct nouveau_context *nv = CALLOC_STRUCT(nouveau_context);
- struct pipe_context *pipe = NULL;
- struct nouveau_channel_context *nvc = NULL;
- struct nouveau_device *dev = nv_screen->device;
- int i;
-
- switch (dev->chipset & 0xf0) {
- case 0x10:
- case 0x20:
- /* NV10 */
- case 0x30:
- /* NV30 */
- case 0x40:
- case 0x60:
- /* NV40 */
- case 0x50:
- case 0x80:
- case 0x90:
- /* G80 */
- break;
- default:
- NOUVEAU_ERR("Unsupported chipset: NV%02x\n", dev->chipset);
- return 1;
- }
-
- dri_context->private = (void*)nv;
- nv->dri_context = dri_context;
- nv->nv_screen = nv_screen;
-
- {
- struct nouveau_device_priv *nvdev = nouveau_device(dev);
-
- nvdev->ctx = dri_context->drm_context;
- nvdev->lock = (drmLock*)&dri_screen->sarea->lock;
- }
-
- /*
- driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
- nv->dri_screen->myNum, "nouveau");
-#ifdef DEBUG
- __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
- debug_control);
-#endif
- */
-
- /*XXX: Hack up a fake region and buffer object for front buffer.
- * This will go away with TTM, replaced with a simple reference
- * of the front buffer handle passed to us by the DDX.
- */
- {
- struct pipe_surface *fb_surf;
- struct nouveau_pipe_buffer *fb_buf;
- struct nouveau_bo_priv *fb_bo;
-
- fb_bo = calloc(1, sizeof(struct nouveau_bo_priv));
- fb_bo->drm.offset = nv_screen->front_offset;
- fb_bo->drm.flags = NOUVEAU_MEM_FB;
- fb_bo->drm.size = nv_screen->front_pitch *
- nv_screen->front_height;
- fb_bo->refcount = 1;
- fb_bo->base.flags = NOUVEAU_BO_PIN | NOUVEAU_BO_VRAM;
- fb_bo->base.offset = fb_bo->drm.offset;
- fb_bo->base.handle = (unsigned long)fb_bo;
- fb_bo->base.size = fb_bo->drm.size;
- fb_bo->base.device = nv_screen->device;
-
- fb_buf = calloc(1, sizeof(struct nouveau_pipe_buffer));
- fb_buf->bo = &fb_bo->base;
-
- fb_surf = calloc(1, sizeof(struct pipe_surface));
- if (nv_screen->front_cpp == 2)
- fb_surf->format = PIPE_FORMAT_R5G6B5_UNORM;
- else
- fb_surf->format = PIPE_FORMAT_A8R8G8B8_UNORM;
- pf_get_block(fb_surf->format, &fb_surf->block);
- fb_surf->width = nv_screen->front_pitch / nv_screen->front_cpp;
- fb_surf->height = nv_screen->front_height;
- fb_surf->stride = fb_surf->width * fb_surf->block.size;
- fb_surf->refcount = 1;
- fb_surf->buffer = &fb_buf->base;
-
- nv->frontbuffer = fb_surf;
- }
-
- nvc = nv_screen->nvc;
-
- if (!nvc) {
- nvc = nouveau_channel_context_create(dev);
- if (!nvc) {
- NOUVEAU_ERR("Failed initialising GPU context\n");
- return 1;
- }
- nv_screen->nvc = nvc;
- }
-
- nvc->refcount++;
- nv->nvc = nvc;
-
- /* Find a free slot for a pipe context, allocate a new one if needed */
- nv->pctx_id = -1;
- for (i = 0; i < nvc->nr_pctx; i++) {
- if (nvc->pctx[i] == NULL) {
- nv->pctx_id = i;
- break;
- }
- }
-
- if (nv->pctx_id < 0) {
- nv->pctx_id = nvc->nr_pctx++;
- nvc->pctx =
- realloc(nvc->pctx,
- sizeof(struct pipe_context *) * nvc->nr_pctx);
- }
-
- /* Create pipe */
- switch (dev->chipset & 0xf0) {
- case 0x50:
- case 0x80:
- case 0x90:
- if (nouveau_surface_init_nv50(nv))
- return 1;
- break;
- default:
- if (nouveau_surface_init_nv04(nv))
- return 1;
- break;
- }
-
- if (!getenv("NOUVEAU_FORCE_SOFTPIPE")) {
- struct pipe_screen *pscreen;
-
- pipe = nouveau_pipe_create(nv);
- if (!pipe)
- NOUVEAU_ERR("Couldn't create hw pipe\n");
- pscreen = nvc->pscreen;
-
- nv->cap.hw_vertex_buffer =
- pscreen->get_param(pscreen, NOUVEAU_CAP_HW_VTXBUF);
- nv->cap.hw_index_buffer =
- pscreen->get_param(pscreen, NOUVEAU_CAP_HW_IDXBUF);
- }
-
- /* XXX: nouveau_winsys_softpipe needs a mesa header removed before we can compile it. */
- /*
- if (!pipe) {
- NOUVEAU_MSG("Using softpipe\n");
- pipe = nouveau_create_softpipe(nv);
- if (!pipe) {
- NOUVEAU_ERR("Error creating pipe, bailing\n");
- return 1;
- }
- }
- */
- if (!pipe) {
- NOUVEAU_ERR("Error creating pipe, bailing\n");
- return 1;
- }
-
- pipe->priv = nv;
-
- return 0;
-}
-
-void
-nouveau_context_destroy(dri_context_t *dri_context)
-{
- struct nouveau_context *nv = dri_context->private;
- struct nouveau_channel_context *nvc = nv->nvc;
-
- assert(nv);
-
- if (nv->pctx_id >= 0) {
- nvc->pctx[nv->pctx_id] = NULL;
- if (--nvc->refcount <= 0) {
- nouveau_channel_context_destroy(nvc);
- nv->nv_screen->nvc = NULL;
- }
- }
-
- free(nv);
-}
-
-int
-nouveau_context_bind(struct nouveau_context *nv, dri_drawable_t *dri_drawable)
-{
- assert(nv);
- assert(dri_drawable);
-
- if (nv->dri_drawable != dri_drawable)
- {
- nv->dri_drawable = dri_drawable;
- dri_drawable->private = nv;
- }
-
- return 0;
-}
-
-int
-nouveau_context_unbind(struct nouveau_context *nv)
-{
- assert(nv);
-
- nv->dri_drawable = NULL;
-
- return 0;
-}
-
-/* Show starts here */
-
-int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable)
-{
- struct nouveau_context *nv;
- dri_drawable_t *dri_drawable;
-
- nv = pipe->priv;
-
- driCreateDrawable(nv->nv_screen->dri_screen, drawable, &dri_drawable);
-
- nouveau_context_bind(nv, dri_drawable);
-
- return 0;
-}
-
-int unbind_pipe_drawable(struct pipe_context *pipe)
-{
- nouveau_context_unbind(pipe->priv);
-
- return 0;
-}
-
-struct pipe_context* create_pipe_context(Display *display, int screen)
-{
- dri_screen_t *dri_screen;
- dri_framebuffer_t dri_framebuf;
- dri_context_t *dri_context;
- struct nouveau_context *nv;
-
- driCreateScreen(display, screen, &dri_screen, &dri_framebuf);
- driCreateContext(dri_screen, XDefaultVisual(display, screen), &dri_context);
-
- nouveau_screen_create(dri_screen, &dri_framebuf);
- nouveau_context_create(dri_context);
-
- nv = dri_context->private;
-
- return nv->nvc->pctx[nv->pctx_id];
-}
-
-int destroy_pipe_context(struct pipe_context *pipe)
-{
- struct pipe_screen *screen;
- struct pipe_winsys *winsys;
- struct nouveau_context *nv;
- dri_screen_t *dri_screen;
- dri_context_t *dri_context;
-
- assert(pipe);
-
- screen = pipe->screen;
- winsys = pipe->winsys;
- nv = pipe->priv;
- dri_context = nv->dri_context;
- dri_screen = dri_context->dri_screen;
-
- pipe->destroy(pipe);
- screen->destroy(screen);
- free(winsys);
-
- nouveau_context_destroy(dri_context);
- nouveau_screen_destroy(dri_screen);
- driDestroyContext(dri_context);
- driDestroyScreen(dri_screen);
-
- return 0;
-}
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_context.h b/src/gallium/winsys/g3dvl/nouveau/nouveau_context.h
deleted file mode 100644
index 395a3ab7903..00000000000
--- a/src/gallium/winsys/g3dvl/nouveau/nouveau_context.h
+++ /dev/null
@@ -1,105 +0,0 @@
-#ifndef __NOUVEAU_CONTEXT_H__
-#define __NOUVEAU_CONTEXT_H__
-
-/*#include "xmlconfig.h"*/
-
-#include <driclient.h>
-#include "nouveau/nouveau_winsys.h"
-#include "nouveau_drmif.h"
-#include "nouveau_dma.h"
-
-struct nouveau_channel_context {
- struct pipe_screen *pscreen;
- int refcount;
-
- unsigned cur_pctx;
- unsigned nr_pctx;
- struct pipe_context **pctx;
-
- struct nouveau_channel *channel;
-
- struct nouveau_notifier *sync_notifier;
-
- /* Common */
- struct nouveau_grobj *NvM2MF;
- /* NV04-NV40 */
- struct nouveau_grobj *NvCtxSurf2D;
- struct nouveau_grobj *NvSwzSurf;
- struct nouveau_grobj *NvImageBlit;
- struct nouveau_grobj *NvGdiRect;
- struct nouveau_grobj *NvSIFM;
- /* G80 */
- struct nouveau_grobj *Nv2D;
-
- uint32_t next_handle;
- uint32_t next_subchannel;
- uint32_t next_sequence;
-};
-
-struct nouveau_context {
- /* DRI stuff */
- dri_context_t *dri_context;
- dri_drawable_t *dri_drawable;
- unsigned int last_stamp;
- /*driOptionCache dri_option_cache;*/
- drm_context_t drm_context;
- drmLock drm_lock;
- int locked;
- struct nouveau_screen *nv_screen;
- struct pipe_surface *frontbuffer;
-
- struct {
- int hw_vertex_buffer;
- int hw_index_buffer;
- } cap;
-
- /* Hardware context */
- struct nouveau_channel_context *nvc;
- int pctx_id;
-
- /* pipe_surface accel */
- struct pipe_surface *surf_src, *surf_dst;
- unsigned surf_src_offset, surf_dst_offset;
-
- int (*surface_copy_prep)(struct nouveau_context *,
- struct pipe_surface *dst,
- struct pipe_surface *src);
- void (*surface_copy)(struct nouveau_context *, unsigned dx, unsigned dy,
- unsigned sx, unsigned sy, unsigned w, unsigned h);
- void (*surface_copy_done)(struct nouveau_context *);
- int (*surface_fill)(struct nouveau_context *, struct pipe_surface *,
- unsigned, unsigned, unsigned, unsigned, unsigned);
-};
-
-extern int nouveau_context_create(dri_context_t *);
-extern void nouveau_context_destroy(dri_context_t *);
-extern int nouveau_context_bind(struct nouveau_context *, dri_drawable_t *);
-extern int nouveau_context_unbind(struct nouveau_context *);
-
-#ifdef DEBUG
-extern int __nouveau_debug;
-
-#define DEBUG_BO (1 << 0)
-
-#define DBG(flag, ...) do { \
- if (__nouveau_debug & (DEBUG_##flag)) \
- NOUVEAU_ERR(__VA_ARGS__); \
-} while(0)
-#else
-#define DBG(flag, ...)
-#endif
-
-extern void LOCK_HARDWARE(struct nouveau_context *);
-extern void UNLOCK_HARDWARE(struct nouveau_context *);
-
-extern int
-nouveau_surface_channel_create_nv04(struct nouveau_channel_context *);
-extern int
-nouveau_surface_channel_create_nv50(struct nouveau_channel_context *);
-extern int nouveau_surface_init_nv04(struct nouveau_context *);
-extern int nouveau_surface_init_nv50(struct nouveau_context *);
-
-extern uint32_t *nouveau_pipe_dma_beginp(struct nouveau_grobj *, int, int);
-extern void nouveau_pipe_dma_kickoff(struct nouveau_channel *);
-
-#endif
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.c b/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.c
new file mode 100644
index 00000000000..dfc4905bc03
--- /dev/null
+++ b/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.c
@@ -0,0 +1,172 @@
+#include "nouveau_context_vl.h"
+#include <pipe/p_defines.h>
+#include <pipe/p_context.h>
+#include <pipe/p_screen.h>
+#include <util/u_memory.h>
+#include <common/nouveau_dri.h>
+#include <common/nouveau_local.h>
+#include <common/nouveau_winsys_pipe.h>
+#include "nouveau_screen_vl.h"
+
+/*
+#ifdef DEBUG
+static const struct dri_debug_control debug_control[] = {
+ { "bo", DEBUG_BO },
+ { NULL, 0 }
+};
+int __nouveau_debug = 0;
+#endif
+*/
+
+int
+nouveau_context_create(dri_context_t *dri_context)
+{
+ dri_screen_t *dri_screen;
+ struct nouveau_screen_vl *nv_screen;
+ struct nouveau_context_vl *nv;
+
+ assert (dri_context);
+
+ dri_screen = dri_context->dri_screen;
+ nv_screen = dri_screen->private;
+ nv = CALLOC_STRUCT(nouveau_context_vl);
+
+ if (!nv)
+ return 1;
+
+ if (nouveau_context_init(&nv_screen->base, dri_context->drm_context,
+ (drmLock*)&dri_screen->sarea->lock, NULL, &nv->base))
+ {
+ FREE(nv);
+ return 1;
+ }
+
+ dri_context->private = (void*)nv;
+ nv->dri_context = dri_context;
+ nv->nv_screen = nv_screen;
+
+ /*
+ driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache,
+ nv->dri_screen->myNum, "nouveau");
+#ifdef DEBUG
+ __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"),
+ debug_control);
+#endif
+ */
+
+ nv->base.nvc->pctx[nv->base.pctx_id]->priv = nv;
+
+ return 0;
+}
+
+void
+nouveau_context_destroy(dri_context_t *dri_context)
+{
+ struct nouveau_context_vl *nv = dri_context->private;
+
+ assert(dri_context);
+
+ nouveau_context_cleanup(&nv->base);
+
+ FREE(nv);
+}
+
+int
+nouveau_context_bind(struct nouveau_context_vl *nv, dri_drawable_t *dri_drawable)
+{
+ assert(nv);
+ assert(dri_drawable);
+
+ if (nv->dri_drawable != dri_drawable)
+ {
+ nv->dri_drawable = dri_drawable;
+ dri_drawable->private = nv;
+ }
+
+ return 0;
+}
+
+int
+nouveau_context_unbind(struct nouveau_context_vl *nv)
+{
+ assert(nv);
+
+ nv->dri_drawable = NULL;
+
+ return 0;
+}
+
+/* Show starts here */
+
+int bind_pipe_drawable(struct pipe_context *pipe, Drawable drawable)
+{
+ struct nouveau_context_vl *nv;
+ dri_drawable_t *dri_drawable;
+
+ assert(pipe);
+
+ nv = pipe->priv;
+
+ driCreateDrawable(nv->nv_screen->dri_screen, drawable, &dri_drawable);
+
+ nouveau_context_bind(nv, dri_drawable);
+
+ return 0;
+}
+
+int unbind_pipe_drawable(struct pipe_context *pipe)
+{
+ assert (pipe);
+
+ nouveau_context_unbind(pipe->priv);
+
+ return 0;
+}
+
+struct pipe_context* create_pipe_context(Display *display, int screen)
+{
+ dri_screen_t *dri_screen;
+ dri_framebuffer_t dri_framebuf;
+ dri_context_t *dri_context;
+ struct nouveau_context_vl *nv;
+
+ assert(display);
+
+ driCreateScreen(display, screen, &dri_screen, &dri_framebuf);
+ driCreateContext(dri_screen, XDefaultVisual(display, screen), &dri_context);
+
+ nouveau_screen_create(dri_screen, &dri_framebuf);
+ nouveau_context_create(dri_context);
+
+ nv = dri_context->private;
+
+ return nv->base.nvc->pctx[nv->base.pctx_id];
+}
+
+int destroy_pipe_context(struct pipe_context *pipe)
+{
+ struct pipe_screen *screen;
+ struct pipe_winsys *winsys;
+ struct nouveau_context_vl *nv;
+ dri_screen_t *dri_screen;
+ dri_context_t *dri_context;
+
+ assert(pipe);
+
+ screen = pipe->screen;
+ winsys = pipe->winsys;
+ nv = pipe->priv;
+ dri_context = nv->dri_context;
+ dri_screen = dri_context->dri_screen;
+
+ pipe->destroy(pipe);
+ screen->destroy(screen);
+ FREE(winsys);
+
+ nouveau_context_destroy(dri_context);
+ nouveau_screen_destroy(dri_screen);
+ driDestroyContext(dri_context);
+ driDestroyScreen(dri_screen);
+
+ return 0;
+}
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.h b/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.h
new file mode 100644
index 00000000000..1115c3130cb
--- /dev/null
+++ b/src/gallium/winsys/g3dvl/nouveau/nouveau_context_vl.h
@@ -0,0 +1,39 @@
+#ifndef __NOUVEAU_CONTEXT_VL_H__
+#define __NOUVEAU_CONTEXT_VL_H__
+
+#include <driclient.h>
+#include <nouveau/nouveau_winsys.h>
+#include <common/nouveau_context.h>
+
+/*#include "xmlconfig.h"*/
+
+struct nouveau_context_vl {
+ struct nouveau_context base;
+ struct nouveau_screen_vl *nv_screen;
+ dri_context_t *dri_context;
+ dri_drawable_t *dri_drawable;
+ unsigned int last_stamp;
+ /*driOptionCache dri_option_cache;*/
+ drm_context_t drm_context;
+ drmLock drm_lock;
+};
+
+extern int nouveau_context_create(dri_context_t *);
+extern void nouveau_context_destroy(dri_context_t *);
+extern int nouveau_context_bind(struct nouveau_context_vl *, dri_drawable_t *);
+extern int nouveau_context_unbind(struct nouveau_context_vl *);
+
+#ifdef DEBUG
+extern int __nouveau_debug;
+
+#define DEBUG_BO (1 << 0)
+
+#define DBG(flag, ...) do { \
+ if (__nouveau_debug & (DEBUG_##flag)) \
+ NOUVEAU_ERR(__VA_ARGS__); \
+} while(0)
+#else
+#define DBG(flag, ...)
+#endif
+
+#endif
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_screen.c b/src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.c
index f80d00050c8..658dafd9105 100644
--- a/src/gallium/winsys/g3dvl/nouveau/nouveau_screen.c
+++ b/src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.c
@@ -1,11 +1,8 @@
-#include "pipe/p_context.h"
-#include "util/u_memory.h"
-#include "nouveau_context.h"
+#include "nouveau_screen_vl.h"
+#include <util/u_memory.h>
#include <nouveau_drm.h>
-#include "nouveau_dri.h"
-#include "nouveau_local.h"
-#include "nouveau_screen.h"
-#include "nouveau_swapbuffers.h"
+#include <common/nouveau_dri.h>
+#include <common/nouveau_local.h>
#if NOUVEAU_DRM_HEADER_PATCHLEVEL != 11
#error nouveau_drm.h version does not match expected version
@@ -50,34 +47,33 @@ int nouveau_check_dri_drm_ddx(dri_version_t *dri, dri_version_t *drm, dri_versio
int
nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf)
{
- struct nouveau_dri *nv_dri = dri_framebuf->private;
- struct nouveau_screen *nv_screen;
- int ret;
+ struct nouveau_dri *nv_dri = dri_framebuf->private;
+ struct nouveau_screen_vl *nv_screen;
+
+ assert(dri_screen);
+ assert(dri_framebuf);
if (nouveau_check_dri_drm_ddx(&dri_screen->dri, &dri_screen->drm, &dri_screen->ddx))
return 1;
- nv_screen = CALLOC_STRUCT(nouveau_screen);
+ nv_screen = CALLOC_STRUCT(nouveau_screen_vl);
+
if (!nv_screen)
return 1;
- nv_screen->dri_screen = dri_screen;
- dri_screen->private = (void*)nv_screen;
+
+ if (nouveau_screen_init(nv_dri, dri_screen->fd, &nv_screen->base))
+ {
+ FREE(nv_screen);
+ return 1;
+ }
/*
driParseOptionInfo(&nv_screen->option_cache,
__driConfigOptions, __driNConfigOptions);
*/
- if ((ret = nouveau_device_open_existing(&nv_screen->device, 0,
- dri_screen->fd, 0))) {
- NOUVEAU_ERR("Failed opening nouveau device: %d.\n", ret);
- return 1;
- }
-
- nv_screen->front_offset = nv_dri->front_offset;
- nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8);
- nv_screen->front_cpp = nv_dri->bpp / 8;
- nv_screen->front_height = nv_dri->height;
+ nv_screen->dri_screen = dri_screen;
+ dri_screen->private = (void*)nv_screen;
return 0;
}
@@ -85,7 +81,8 @@ nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_framebuf)
void
nouveau_screen_destroy(dri_screen_t *dri_screen)
{
- struct nouveau_screen *nv_screen = dri_screen->private;
+ struct nouveau_screen_vl *nv_screen = dri_screen->private;
+ nouveau_screen_cleanup(&nv_screen->base);
FREE(nv_screen);
}
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_screen.h b/src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.h
index 8a58bb75564..0c1ceca6dee 100644
--- a/src/gallium/winsys/g3dvl/nouveau/nouveau_screen.h
+++ b/src/gallium/winsys/g3dvl/nouveau/nouveau_screen_vl.h
@@ -1,19 +1,16 @@
-#ifndef __NOUVEAU_SCREEN_H__
-#define __NOUVEAU_SCREEN_H__
+#ifndef __NOUVEAU_SCREEN_VL_H__
+#define __NOUVEAU_SCREEN_VL_H__
+
+#include <driclient.h>
+#include <common/nouveau_screen.h>
/* TODO: Investigate using DRI options for interesting things */
/*#include "xmlconfig.h"*/
-struct nouveau_screen {
+struct nouveau_screen_vl
+{
+ struct nouveau_screen base;
dri_screen_t *dri_screen;
- struct nouveau_device *device;
- struct nouveau_channel_context *nvc;
-
- uint32_t front_offset;
- uint32_t front_pitch;
- uint32_t front_cpp;
- uint32_t front_height;
-
/*driOptionCache option_cache;*/
};
@@ -21,4 +18,3 @@ int nouveau_screen_create(dri_screen_t *dri_screen, dri_framebuffer_t *dri_frame
void nouveau_screen_destroy(dri_screen_t *dri_screen);
#endif
-
diff --git a/src/gallium/winsys/g3dvl/nouveau/nouveau_swapbuffers.c b/src/gallium/winsys/g3dvl/nouveau/nouveau_swapbuffers.c
index 7916c806151..16e6d5543cb 100644
--- a/src/gallium/winsys/g3dvl/nouveau/nouveau_swapbuffers.c
+++ b/src/gallium/winsys/g3dvl/nouveau/nouveau_swapbuffers.c
@@ -1,26 +1,26 @@
-#include "pipe/p_context.h"
-#include "nouveau_context.h"
-#include "nouveau_local.h"
-#include "nouveau_screen.h"
+#include <driclient.h>
+#include <common/nouveau_local.h>
+#include <common/nouveau_screen.h>
+#include "nouveau_context_vl.h"
#include "nouveau_swapbuffers.h"
void
nouveau_copy_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf,
const drm_clip_rect_t *rect)
{
- struct nouveau_context *nv = dri_drawable->private;
- drm_clip_rect_t *pbox;
- int nbox, i;
+ struct nouveau_context_vl *nv = dri_drawable->private;
+ drm_clip_rect_t *pbox;
+ int nbox, i;
- LOCK_HARDWARE(nv);
+ LOCK_HARDWARE(&nv->base);
if (!dri_drawable->num_cliprects) {
- UNLOCK_HARDWARE(nv);
+ UNLOCK_HARDWARE(&nv->base);
return;
}
pbox = dri_drawable->cliprects;
nbox = dri_drawable->num_cliprects;
- nv->surface_copy_prep(nv, nv->frontbuffer, surf);
+ nv->base.surface_copy_prep(&nv->base, nv->base.frontbuffer, surf);
for (i = 0; i < nbox; i++, pbox++) {
int sx, sy, dx, dy, w, h;
@@ -31,14 +31,11 @@ nouveau_copy_buffer(dri_drawable_t *dri_drawable, struct pipe_surface *surf,
w = pbox->x2 - pbox->x1;
h = pbox->y2 - pbox->y1;
- nv->surface_copy(nv, dx, dy, sx, sy, w, h);
+ nv->base.surface_copy(&nv->base, dx, dy, sx, sy, w, h);
}
- FIRE_RING(nv->nvc->channel);
- UNLOCK_HARDWARE(nv);
-
- //if (nv->last_stamp != dri_drawable->last_sarea_stamp)
- //nv->last_stamp = dri_drawable->last_sarea_stamp;
+ FIRE_RING(nv->base.nvc->channel);
+ UNLOCK_HARDWARE(&nv->base);
}
void
@@ -62,3 +59,35 @@ nouveau_swap_buffers(dri_drawable_t *dri_drawable, struct pipe_surface *surf)
nouveau_copy_buffer(dri_drawable, surf, NULL);
}
+void
+nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf,
+ void *context_private)
+{
+ struct nouveau_context_vl *nv;
+ dri_drawable_t *dri_drawable;
+
+ assert(pws);
+ assert(surf);
+ assert(context_private);
+
+ nv = context_private;
+ dri_drawable = nv->dri_drawable;
+
+ nouveau_copy_buffer(dri_drawable, surf, NULL);
+}
+
+void
+nouveau_contended_lock(struct nouveau_context *nv)
+{
+ struct nouveau_context_vl *nv_vl = (struct nouveau_context_vl*)nv;
+ dri_drawable_t *dri_drawable = nv_vl->dri_drawable;
+ dri_screen_t *dri_screen = nv_vl->dri_context->dri_screen;
+
+ /* If the window moved, may need to set a new cliprect now.
+ *
+ * NOTE: This releases and regains the hw lock, so all state
+ * checking must be done *after* this call:
+ */
+ if (dri_drawable)
+ DRI_VALIDATE_DRAWABLE_INFO(dri_screen, dri_drawable);
+}