Rename winsys amd to radeon.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Fri, 6 Feb 2009 21:28:15 +0000 (13:28 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Fri, 6 Feb 2009 21:28:15 +0000 (13:28 -0800)
24 files changed:
src/gallium/winsys/drm/amd/Makefile [deleted file]
src/gallium/winsys/drm/amd/SConscript [deleted file]
src/gallium/winsys/drm/amd/amd_buffer.c [deleted file]
src/gallium/winsys/drm/amd/amd_buffer.h [deleted file]
src/gallium/winsys/drm/amd/amd_context.c [deleted file]
src/gallium/winsys/drm/amd/amd_context.h [deleted file]
src/gallium/winsys/drm/amd/amd_r300.c [deleted file]
src/gallium/winsys/drm/amd/amd_r300.h [deleted file]
src/gallium/winsys/drm/amd/amd_screen.c [deleted file]
src/gallium/winsys/drm/amd/amd_screen.h [deleted file]
src/gallium/winsys/drm/amd/amd_winsys_softpipe.c [deleted file]
src/gallium/winsys/drm/amd/amd_winsys_softpipe.h [deleted file]
src/gallium/winsys/drm/radeon/Makefile [new file with mode: 0644]
src/gallium/winsys/drm/radeon/SConscript [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_buffer.c [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_buffer.h [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_context.c [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_context.h [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_r300.c [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_r300.h [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_screen.c [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_screen.h [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c [new file with mode: 0644]
src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h [new file with mode: 0644]

diff --git a/src/gallium/winsys/drm/amd/Makefile b/src/gallium/winsys/drm/amd/Makefile
deleted file mode 100644 (file)
index fb77873..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-
-TOP = ../../../../..
-include $(TOP)/configs/current
-
-LIBNAME = amd_dri.so
-
-MINIGLX_SOURCES =
-
-PIPE_DRIVERS = \
-       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
-       $(TOP)/src/gallium/drivers/r300/libr300.a
-
-DRIVER_SOURCES = \
-       amd_buffer.c \
-       amd_context.c \
-       amd_r300.c \
-       amd_screen.c \
-       amd_winsys_softpipe.c
-
-C_SOURCES = \
-       $(COMMON_GALLIUM_SOURCES) \
-       $(DRIVER_SOURCES)
-
-ASM_SOURCES = 
-
-DRIVER_DEFINES = -I../../../drivers/r300
-
-include ../Makefile.template
-
-DRI_LIB_DEPS += -ldrm_radeon
-
-symlinks:
diff --git a/src/gallium/winsys/drm/amd/SConscript b/src/gallium/winsys/drm/amd/SConscript
deleted file mode 100644 (file)
index a4856da..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-Import('*')
-
-if 'mesa' in env['statetrackers']:
-
-       env = drienv.Clone()
-
-       DRIVER_SOURCES = [
-               'amd_buffer.c',
-               'amd_context.c',
-               'amd_screen.c',
-               'amd_winsys_softpipe.c',
-       ]
-
-       sources = \
-               COMMON_GALLIUM_SOURCES + \
-               DRIVER_SOURCES
-
-       drivers = [
-               softpipe,
-               r300
-       ]
-
-       # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions
-       env.SharedLibrary(
-               target ='amd_dri.so',
-               source = sources,
-               LIBS = drivers + mesa + auxiliaries + env['LIBS'],
-       )
-
diff --git a/src/gallium/winsys/drm/amd/amd_buffer.c b/src/gallium/winsys/drm/amd/amd_buffer.c
deleted file mode 100644 (file)
index 4b831c7..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#include <stdio.h>
-#include "dri_util.h"
-#include "state_tracker/st_public.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "amd_buffer.h"
-#include "amd_screen.h"
-#include "amd_context.h"
-#include "radeon_bo.h"
-#include "radeon_drm.h"
-
-static const char *amd_get_name(struct pipe_winsys *ws)
-{
-    return "AMD/DRI2";
-}
-
-static struct pipe_buffer *amd_buffer_create(struct pipe_winsys *ws,
-                                             unsigned alignment,
-                                             unsigned usage,
-                                             unsigned size)
-{
-    struct amd_pipe_winsys *amd_ws = (struct amd_pipe_winsys *)ws;
-    struct amd_pipe_buffer *amd_buffer;
-    uint32_t domain;
-
-    amd_buffer = calloc(1, sizeof(*amd_buffer));
-    if (amd_buffer == NULL) {
-        return NULL;
-    }
-    amd_buffer->base.refcount = 1;
-    amd_buffer->base.alignment = alignment;
-    amd_buffer->base.usage = usage;
-    amd_buffer->base.size = size;
-
-    domain = 0;
-
-    if (usage & PIPE_BUFFER_USAGE_PIXEL) {
-        domain |= RADEON_GEM_DOMAIN_VRAM;
-    }
-    if (usage & PIPE_BUFFER_USAGE_VERTEX) {
-        domain |= RADEON_GEM_DOMAIN_GTT;
-    }
-
-    if (usage & PIPE_BUFFER_USAGE_INDEX) {
-        domain |= RADEON_GEM_DOMAIN_GTT;
-    }
-    amd_buffer->bo = radeon_bo_open(amd_ws->amd_screen->bom, 0,
-                                    size, alignment, domain, 0);
-    if (amd_buffer->bo == NULL) {
-        free(amd_buffer);
-    }
-    return &amd_buffer->base;
-}
-
-static struct pipe_buffer *amd_buffer_user_create(struct pipe_winsys *ws,
-                                                  void *ptr,
-                                                  unsigned bytes)
-{
-    struct amd_pipe_buffer *amd_buffer;
-
-    amd_buffer = (struct amd_pipe_buffer*)amd_buffer_create(ws, 0, 0, bytes);
-    if (amd_buffer == NULL) {
-        return NULL;
-    }
-    radeon_bo_map(amd_buffer->bo, 1);
-    memcpy(amd_buffer->bo->ptr, ptr, bytes);
-    radeon_bo_unmap(amd_buffer->bo);
-    return &amd_buffer->base;
-}
-
-static void amd_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer)
-{
-    struct amd_pipe_buffer *amd_buffer = (struct amd_pipe_buffer*)buffer;
-
-    radeon_bo_unref(amd_buffer->bo);
-    free(amd_buffer);
-}
-
-static void *amd_buffer_map(struct pipe_winsys *ws,
-                            struct pipe_buffer *buffer,
-                            unsigned flags)
-{
-    struct amd_pipe_buffer *amd_buffer = (struct amd_pipe_buffer*)buffer;
-    int write = 0;
-
-    if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
-        write = 1;
-    }
-    if (radeon_bo_map(amd_buffer->bo, write))
-        return NULL;
-    return amd_buffer->bo->ptr;
-}
-
-static void amd_buffer_unmap(struct pipe_winsys *ws, struct pipe_buffer *buffer)
-{
-    struct amd_pipe_buffer *amd_buffer = (struct amd_pipe_buffer*)buffer;
-
-    radeon_bo_unmap(amd_buffer->bo);
-}
-
-static void amd_fence_reference(struct pipe_winsys *ws,
-                                struct pipe_fence_handle **ptr,
-                                struct pipe_fence_handle *pfence)
-{
-}
-
-static int amd_fence_signalled(struct pipe_winsys *ws,
-                               struct pipe_fence_handle *pfence,
-                               unsigned flag)
-{
-    return 1;
-}
-
-static int amd_fence_finish(struct pipe_winsys *ws,
-                            struct pipe_fence_handle *pfence,
-                            unsigned flag)
-{
-    return 0;
-}
-
-static void amd_flush_frontbuffer(struct pipe_winsys *pipe_winsys,
-                                  struct pipe_surface *pipe_surface,
-                                  void *context_private)
-{
-    /* TODO: call dri2CopyRegion */
-}
-
-struct pipe_winsys *amd_pipe_winsys(struct amd_screen *amd_screen)
-{
-    struct amd_pipe_winsys *amd_ws;
-
-    amd_ws = calloc(1, sizeof(struct amd_pipe_winsys));
-    if (amd_ws == NULL) {
-        return NULL;
-    }
-    amd_ws->amd_screen = amd_screen;
-
-    amd_ws->winsys.flush_frontbuffer = amd_flush_frontbuffer;
-
-    amd_ws->winsys.buffer_create = amd_buffer_create;
-    amd_ws->winsys.buffer_destroy = amd_buffer_del;
-    amd_ws->winsys.user_buffer_create = amd_buffer_user_create;
-    amd_ws->winsys.buffer_map = amd_buffer_map;
-    amd_ws->winsys.buffer_unmap = amd_buffer_unmap;
-
-    amd_ws->winsys.fence_reference = amd_fence_reference;
-    amd_ws->winsys.fence_signalled = amd_fence_signalled;
-    amd_ws->winsys.fence_finish = amd_fence_finish;
-
-    amd_ws->winsys.get_name = amd_get_name;
-
-    return &amd_ws->winsys;
-}
-
-static struct pipe_buffer *amd_buffer_from_handle(struct amd_screen *amd_screen,
-                                                  uint32_t handle)
-{
-    struct amd_pipe_buffer *amd_buffer;
-    struct radeon_bo *bo = NULL;
-
-    bo = radeon_bo_open(amd_screen->bom, handle, 0, 0, 0, 0);
-    if (bo == NULL) {
-        return NULL;
-    }
-    amd_buffer = calloc(1, sizeof(struct amd_pipe_buffer));
-    if (amd_buffer == NULL) {
-        radeon_bo_unref(bo);
-        return NULL;
-    }
-    amd_buffer->base.refcount = 1;
-    amd_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
-    amd_buffer->bo = bo;
-    return &amd_buffer->base;
-}
-
-struct pipe_surface *amd_surface_from_handle(struct amd_context *amd_context,
-                                             uint32_t handle,
-                                             enum pipe_format format,
-                                             int w, int h, int pitch)
-{
-    struct pipe_screen *pipe_screen = amd_context->pipe_screen;
-    struct pipe_winsys *pipe_winsys = amd_context->pipe_winsys;
-    struct pipe_texture tmpl;
-    struct pipe_surface *ps;
-    struct pipe_texture *pt;
-    struct pipe_buffer *pb;
-
-    pb = amd_buffer_from_handle(amd_context->amd_screen, handle);
-    if (pb == NULL) {
-        return NULL;
-    }
-    memset(&tmpl, 0, sizeof(tmpl));
-    tmpl.tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
-    tmpl.target = PIPE_TEXTURE_2D;
-    tmpl.width[0] = w;
-    tmpl.height[0] = h;
-    tmpl.depth[0] = 1;
-    tmpl.format = format;
-    pf_get_block(tmpl.format, &tmpl.block);
-    tmpl.nblocksx[0] = pf_get_nblocksx(&tmpl.block, w);
-    tmpl.nblocksy[0] = pf_get_nblocksy(&tmpl.block, h);
-
-    pt = pipe_screen->texture_blanket(pipe_screen, &tmpl, &pitch, pb);
-    if (pt == NULL) {
-        pipe_buffer_reference(pipe_screen, &pb, NULL);
-    }
-    ps = pipe_screen->get_tex_surface(pipe_screen, pt, 0, 0, 0,
-                                      PIPE_BUFFER_USAGE_GPU_WRITE);
-    return ps;
-}
diff --git a/src/gallium/winsys/drm/amd/amd_buffer.h b/src/gallium/winsys/drm/amd/amd_buffer.h
deleted file mode 100644 (file)
index 238ca57..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#ifndef AMD_BUFFER_H
-#define AMD_BUFFER_H
-
-#include "pipe/internal/p_winsys_screen.h"
-#include "amd_screen.h"
-#include "amd_context.h"
-#include "radeon_bo.h"
-
-struct amd_pipe_buffer {
-    struct pipe_buffer  base;
-    struct radeon_bo    *bo;
-};
-
-struct amd_pipe_winsys {
-    struct pipe_winsys      winsys;
-    struct amd_screen       *amd_screen;
-};
-
-struct pipe_winsys *amd_pipe_winsys(struct amd_screen *amd_screen);
-struct pipe_surface *amd_surface_from_handle(struct amd_context *amd_context,
-                                             uint32_t handle,
-                                             enum pipe_format format,
-                                             int w, int h, int pitch);
-
-#endif
diff --git a/src/gallium/winsys/drm/amd/amd_context.c b/src/gallium/winsys/drm/amd/amd_context.c
deleted file mode 100644 (file)
index e089cf6..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#include <stdio.h>
-#include "dri_util.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "state_tracker/st_public.h"
-#include "state_tracker/st_context.h"
-#include "amd_screen.h"
-#include "amd_context.h"
-#include "amd_buffer.h"
-#include "amd_winsys_softpipe.h"
-
-#define need_GL_ARB_fragment_program
-#define need_GL_ARB_multisample
-#define need_GL_ARB_point_parameters
-#define need_GL_ARB_shader_objects
-#define need_GL_ARB_texture_compression
-#define need_GL_ARB_vertex_buffer_object
-#define need_GL_ARB_vertex_program
-#define need_GL_ARB_vertex_shader
-#define need_GL_EXT_blend_color
-#define need_GL_EXT_blend_equation_separate
-#define need_GL_EXT_blend_func_separate
-#define need_GL_EXT_blend_minmax
-#define need_GL_EXT_cull_vertex
-#define need_GL_EXT_compiled_vertex_array
-#define need_GL_EXT_fog_coord
-#define need_GL_EXT_framebuffer_object
-#define need_GL_EXT_multi_draw_arrays
-#define need_GL_EXT_secondary_color
-#define need_GL_VERSION_2_0
-#define need_GL_VERSION_2_1
-#include "extension_helper.h"
-
-/**
- * Extension strings exported by the amd driver.
- */
-const struct dri_extension amd_card_extensions[] = {
-   {"GL_ARB_multitexture", NULL},
-   {"GL_ARB_texture_border_clamp", NULL},
-   {"GL_ARB_texture_rectangle", NULL},
-   {"GL_ARB_pixel_buffer_object", NULL},
-   {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
-   {"GL_ARB_shader_objects", GL_ARB_shader_objects_functions},
-   {"GL_ARB_shading_language_100", GL_VERSION_2_0_functions},
-   {"GL_ARB_shading_language_120", GL_VERSION_2_1_functions},
-   {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
-   {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
-   {"GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions},
-   {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
-   {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions},
-   {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
-   {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
-   {"GL_EXT_blend_subtract", NULL},
-   {"GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions},
-   {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
-   {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
-   {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
-   {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
-   {"GL_EXT_packed_depth_stencil", NULL},
-   {"GL_EXT_pixel_buffer_object", NULL},
-   {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
-   {"GL_EXT_stencil_wrap", NULL},
-   {NULL, NULL}
-};
-
-static void amd_update_renderbuffers(__DRIcontext *dri_context,
-                                     __DRIdrawable *dri_drawable)
-{
-    struct amd_framebuffer *amd_fb;
-    struct amd_context *amd_context;
-    unsigned attachments[10];
-    __DRIbuffer *buffers;
-    __DRIscreen *screen;
-    int i, count;
-
-    amd_context = dri_context->driverPrivate;
-    screen = dri_drawable->driScreenPriv;
-    amd_fb = dri_drawable->driverPrivate;
-    for (count = 0, i = 0; count < 6; count++) {
-        if (amd_fb->attachments & (1 << count)) {
-            attachments[i++] = count;
-        }
-    }
-
-    buffers = (*screen->dri2.loader->getBuffers)(dri_drawable,
-                                                 &dri_drawable->w,
-                                                 &dri_drawable->h,
-                                                 attachments,
-                                                 i,
-                                                 &count,
-                                                 dri_drawable->loaderPrivate);
-    if (buffers == NULL) {
-        return;
-    }
-
-    /* set one cliprect to cover the whole dri_drawable */
-    dri_drawable->x = 0;
-    dri_drawable->y = 0;
-    dri_drawable->backX = 0;
-    dri_drawable->backY = 0;
-    dri_drawable->numClipRects = 1;
-    dri_drawable->pClipRects[0].x1 = 0;
-    dri_drawable->pClipRects[0].y1 = 0;
-    dri_drawable->pClipRects[0].x2 = dri_drawable->w;
-    dri_drawable->pClipRects[0].y2 = dri_drawable->h;
-    dri_drawable->numBackClipRects = 1;
-    dri_drawable->pBackClipRects[0].x1 = 0;
-    dri_drawable->pBackClipRects[0].y1 = 0;
-    dri_drawable->pBackClipRects[0].x2 = dri_drawable->w;
-    dri_drawable->pBackClipRects[0].y2 = dri_drawable->h;
-
-    for (i = 0; i < count; i++) {
-        struct pipe_surface *ps;
-        enum pipe_format format = 0;
-        int index = 0;
-
-        switch (buffers[i].attachment) {
-        case __DRI_BUFFER_FRONT_LEFT:
-            index = ST_SURFACE_FRONT_LEFT;
-            switch (buffers[i].cpp) {
-            case 4:
-                format = PIPE_FORMAT_A8R8G8B8_UNORM;
-                break;
-            case 2:
-                format = PIPE_FORMAT_R5G6B5_UNORM;
-                break;
-            default:
-                /* FIXME: error */
-                return;
-            }
-            break;
-        case __DRI_BUFFER_BACK_LEFT:
-            index = ST_SURFACE_BACK_LEFT;
-            switch (buffers[i].cpp) {
-            case 4:
-                format = PIPE_FORMAT_A8R8G8B8_UNORM;
-                break;
-            case 2:
-                format = PIPE_FORMAT_R5G6B5_UNORM;
-                break;
-            default:
-                /* FIXME: error */
-                return;
-            }
-            break;
-        case __DRI_BUFFER_STENCIL:
-        case __DRI_BUFFER_DEPTH:
-            index = ST_SURFACE_DEPTH;
-            switch (buffers[i].cpp) {
-            case 4:
-                format = PIPE_FORMAT_Z24S8_UNORM;
-                break;
-            case 2:
-                format = PIPE_FORMAT_Z16_UNORM;
-                break;
-            default:
-                /* FIXME: error */
-                return;
-            }
-            break;
-        case __DRI_BUFFER_ACCUM:
-        default:
-            fprintf(stderr,
-                    "unhandled buffer attach event, attacment type %d\n",
-                    buffers[i].attachment);
-            return;
-        }
-
-        ps = amd_surface_from_handle(amd_context,
-                                     buffers[i].name,
-                                     format,
-                                     dri_drawable->w,
-                                     dri_drawable->h,
-                                     buffers[i].pitch);
-        assert(ps);
-        st_set_framebuffer_surface(amd_fb->st_framebuffer, index, ps);
-    }
-    st_resize_framebuffer(amd_fb->st_framebuffer,
-                          dri_drawable->w,
-                          dri_drawable->h);
-}
-
-GLboolean amd_context_create(const __GLcontextModes *visual,
-                             __DRIcontextPrivate *dri_context,
-                             void *shared_context)
-{
-    __DRIscreenPrivate *dri_screen;
-    struct amd_context *amd_context;
-    struct amd_screen *amd_screen;
-    struct pipe_context *pipe;
-    struct st_context *shared_st_context = NULL;
-
-    dri_context->driverPrivate = NULL;
-    amd_context = calloc(1, sizeof(struct amd_context));
-    if (amd_context == NULL) {
-        return GL_FALSE;
-    }
-
-    if (shared_context) {
-        shared_st_context = ((struct amd_context*)shared_context)->st_context;
-    }
-
-    dri_screen = dri_context->driScreenPriv;
-    amd_screen = dri_screen->private;
-    amd_context->dri_screen = dri_screen;
-    amd_context->amd_screen = amd_screen;
-    amd_context->drm_fd = dri_screen->fd;
-
-    amd_context->pipe_winsys = amd_pipe_winsys(amd_screen);
-    if (amd_context->pipe_winsys == NULL) {
-        free(amd_context);
-        return GL_FALSE;
-    }
-
-    if (!getenv("AMD_SOFTPIPE")) {
-        fprintf(stderr, "Creating r300 context...\n");
-        pipe =
-            r300_create_context(NULL,
-                                amd_context->pipe_winsys,
-                                amd_create_r300_winsys(amd_context->drm_fd));
-        amd_context->pipe_screen = pipe->screen;
-    } else {
-        pipe = amd_create_softpipe(amd_context);
-    }
-    amd_context->st_context = st_create_context(pipe, visual,
-                                                shared_st_context);
-    driInitExtensions(amd_context->st_context->ctx,
-                      amd_card_extensions, GL_TRUE);
-    dri_context->driverPrivate = amd_context;
-    return GL_TRUE;
-}
-
-void amd_context_destroy(__DRIcontextPrivate *dri_context)
-{
-    struct amd_context *amd_context;
-
-    amd_context = dri_context->driverPrivate;
-    st_finish(amd_context->st_context);
-    st_destroy_context(amd_context->st_context);
-    free(amd_context);
-}
-
-GLboolean amd_context_bind(__DRIcontextPrivate *dri_context,
-                           __DRIdrawablePrivate *dri_drawable,
-                           __DRIdrawablePrivate *dri_readable)
-{
-    struct amd_framebuffer *drawable;
-    struct amd_framebuffer *readable;
-    struct amd_context *amd_context;
-
-    if (dri_context == NULL) {
-        st_make_current(NULL, NULL, NULL);
-        return GL_TRUE;
-    }
-
-    amd_context = dri_context->driverPrivate;
-    drawable = dri_drawable->driverPrivate;
-    readable = dri_readable->driverPrivate;
-    st_make_current(amd_context->st_context,
-                    drawable->st_framebuffer,
-                    readable->st_framebuffer);
-
-    amd_update_renderbuffers(dri_context, dri_drawable);
-    if (dri_drawable != dri_readable) {
-        amd_update_renderbuffers(dri_context, dri_readable);
-    }
-    return GL_TRUE;
-}
-
-GLboolean amd_context_unbind(__DRIcontextPrivate *dri_context)
-{
-    struct amd_context *amd_context;
-
-    amd_context = dri_context->driverPrivate;
-    st_flush(amd_context->st_context, PIPE_FLUSH_RENDER_CACHE, NULL);
-    return GL_TRUE;
-}
diff --git a/src/gallium/winsys/drm/amd/amd_context.h b/src/gallium/winsys/drm/amd/amd_context.h
deleted file mode 100644 (file)
index 12557c4..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#ifndef AMD_CONTEXT_H
-#define AMD_CONTEXT_H
-
-#include "dri_util.h"
-#include "state_tracker/st_public.h"
-#include "state_tracker/st_context.h"
-#include "amd_screen.h"
-
-#include "amd_r300.h"
-
-struct amd_framebuffer {
-    struct st_framebuffer   *st_framebuffer;
-    unsigned                attachments;
-};
-
-struct amd_context {
-    /* st */
-    struct st_context       *st_context;
-    /* pipe */
-    struct pipe_screen      *pipe_screen;
-    struct pipe_winsys      *pipe_winsys;
-    /* DRI */
-    __DRIscreenPrivate      *dri_screen;
-    __DRIdrawablePrivate    *dri_drawable;
-    __DRIdrawablePrivate    *dri_readable;
-    /* DRM */
-    int                     drm_fd;
-   /* AMD */
-    struct amd_screen       *amd_screen;
-};
-
-GLboolean amd_context_create(const __GLcontextModes*,
-                             __DRIcontextPrivate*,
-                             void*);
-void amd_context_destroy(__DRIcontextPrivate*);
-GLboolean amd_context_bind(__DRIcontextPrivate*,
-                           __DRIdrawablePrivate*,
-                           __DRIdrawablePrivate*);
-GLboolean amd_context_unbind(__DRIcontextPrivate*);
-
-#endif
diff --git a/src/gallium/winsys/drm/amd/amd_r300.c b/src/gallium/winsys/drm/amd/amd_r300.c
deleted file mode 100644 (file)
index 04295e8..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
- *
- * 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
- * on 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
- * THE AUTHOR(S) AND/OR THEIR 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 "amd_r300.h"
-
-static boolean amd_r300_check_cs(struct radeon_cs* cs, int size)
-{
-    /* XXX check size here, lazy ass! */
-    return TRUE;
-}
-
-static void amd_r300_write_cs_reloc(struct radeon_cs* cs,
-                                    struct pipe_buffer* pbuffer,
-                                    uint32_t rd,
-                                    uint32_t wd,
-                                    uint32_t flags)
-{
-    radeon_cs_write_reloc(cs, ((struct amd_pipe_buffer*)pbuffer)->bo, rd, wd, flags);
-}
-
-static void amd_r300_flush_cs(struct radeon_cs* cs)
-{
-    radeon_cs_emit(cs);
-    radeon_cs_erase(cs);
-}
-
-/* Helper function to do the ioctls needed for setup and init. */
-static void do_ioctls(struct r300_winsys* winsys, int fd)
-{
-    drm_radeon_getparam_t gp;
-    uint32_t target;
-    int retval;
-
-    /* XXX is this cast safe? */
-    gp.value = (int*)&target;
-
-    /* First, get PCI ID */
-    gp.param = RADEON_PARAM_DEVICE_ID;
-    retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
-    if (retval) {
-        fprintf(stderr, "%s: Failed to get PCI ID, error number %d",
-                __FUNCTION__, retval);
-        exit(1);
-    }
-    winsys->pci_id = target;
-
-    /* Then, get the number of pixel pipes */
-    gp.param = RADEON_PARAM_NUM_GB_PIPES;
-    retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
-    if (retval) {
-        fprintf(stderr, "%s: Failed to get GB pipe count, error number %d",
-                __FUNCTION__, retval);
-        exit(1);
-    }
-    winsys->gb_pipes = target;
-
-}
-
-struct r300_winsys* amd_create_r300_winsys(int fd)
-{
-    struct r300_winsys* winsys = calloc(1, sizeof(struct r300_winsys));
-
-    do_ioctls(winsys, fd);
-
-    struct radeon_cs_manager* csm = radeon_cs_manager_gem_ctor(fd);
-
-    winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4);
-
-    winsys->check_cs = amd_r300_check_cs;
-    winsys->begin_cs = radeon_cs_begin;
-    winsys->write_cs_dword = radeon_cs_write_dword;
-    winsys->write_cs_reloc = amd_r300_write_cs_reloc;
-    winsys->end_cs = radeon_cs_end;
-    winsys->flush_cs = amd_r300_flush_cs;
-
-    return winsys;
-}
diff --git a/src/gallium/winsys/drm/amd/amd_r300.h b/src/gallium/winsys/drm/amd/amd_r300.h
deleted file mode 100644 (file)
index d80c235..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
- *
- * 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
- * on 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
- * THE AUTHOR(S) AND/OR THEIR 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. */
-
-/* XXX WTF is this! I shouldn't have to include those first three! FUCK! */
-#include <stdint.h>
-#include <stdlib.h>
-#include "drm.h"
-#include "radeon_drm.h"
-#include "radeon_cs.h"
-
-#include "r300_winsys.h"
-
-#include "amd_buffer.h"
-
-struct r300_winsys* amd_create_r300_winsys(int fd);
diff --git a/src/gallium/winsys/drm/amd/amd_screen.c b/src/gallium/winsys/drm/amd/amd_screen.c
deleted file mode 100644 (file)
index d62b47f..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#include <stdio.h>
-#include "pipe/p_screen.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
-#include "pipe/p_context.h"
-#include "pipe/p_state.h"
-#include "state_tracker/st_public.h"
-#include "state_tracker/st_context.h"
-#include "utils.h"
-#include "xf86drm.h"
-#include "drm.h"
-#include "dri_util.h"
-#include "amd_screen.h"
-#include "amd_context.h"
-#include "amd_buffer.h"
-#include "radeon_bo.h"
-#include "radeon_bo_gem.h"
-#include "radeon_drm.h"
-
-extern const struct dri_extension amd_card_extensions[];
-
-static const __DRIextension *amd_screen_extensions[] = {
-    &driReadDrawableExtension,
-    &driCopySubBufferExtension.base,
-    &driSwapControlExtension.base,
-    &driFrameTrackingExtension.base,
-    &driMediaStreamCounterExtension.base,
-    NULL
-};
-
-static __DRIconfig **amd_fill_in_modes(unsigned pixel_bits,
-                                       unsigned depth_bits,
-                                       GLboolean have_back_buffer)
-{
-    __DRIconfig **configs;
-    unsigned depth_buffer_factor;
-    unsigned back_buffer_factor;
-    unsigned num_modes;
-    GLenum fb_format;
-    GLenum fb_type;
-    uint8_t depth_bits_array[3];
-    uint8_t stencil_bits_array[3];
-    uint8_t msaa_samples_array[1];
-    /* TODO: pageflipping ? */
-    static const GLenum back_buffer_modes[] = {
-        GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
-    };
-
-    stencil_bits_array[0] = 0;
-    stencil_bits_array[1] = 0;
-    if (depth_bits == 24) {
-        stencil_bits_array[2] = 8;
-        num_modes = 3;
-    }
-
-    depth_bits_array[0] = 0;
-    depth_bits_array[1] = depth_bits;
-    depth_bits_array[2] = depth_bits;
-    depth_buffer_factor = (depth_bits == 24) ? 3 : 2;
-
-    back_buffer_factor = (have_back_buffer) ? 3 : 1;
-
-    msaa_samples_array[0] = 0;
-
-    if (pixel_bits == 16) {
-        fb_format = GL_RGB;
-        fb_type = GL_UNSIGNED_SHORT_5_6_5;
-    } else {
-        fb_format = GL_BGRA;
-        fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
-    }
-
-    configs = (__DRIconfig **)driCreateConfigs(fb_format,
-                                               fb_type,
-                                               depth_bits_array,
-                                               stencil_bits_array,
-                                               depth_buffer_factor,
-                                               back_buffer_modes,
-                                               back_buffer_factor,
-                                               msaa_samples_array,
-                                               1);
-    if (configs == NULL) {
-        fprintf(stderr, "[%s:%u] Error creating FBConfig!\n",
-                __FILE__, __LINE__);
-        return NULL;
-    }
-    return configs;
-}
-
-static void amd_screen_destroy(__DRIscreenPrivate *dri_screen)
-{
-     struct amd_screen *amd_screen = (struct amd_screen*)dri_screen->private;
-
-     radeon_bo_manager_gem_dtor(amd_screen->bom); 
-     dri_screen = NULL;
-     free(amd_screen);
-}
-
-static const __DRIconfig **amd_screen_init(__DRIscreenPrivate *dri_screen)
-{
-    struct amd_screen *amd_screen;
-
-    /* Calling driInitExtensions here, with a NULL context pointer,
-     * does not actually enable the extensions.  It just makes sure
-     * that all the dispatch offsets for all the extensions that
-     * *might* be enables are known.  This is needed because the
-     * dispatch offsets need to be known when _mesa_context_create is
-     * called, but we can't enable the extensions until we have a
-     * context pointer.
-     *
-     * Hello chicken.  Hello egg.  How are you two today?
-     */
-    driInitExtensions(NULL, amd_card_extensions, GL_FALSE);
-
-    amd_screen = calloc(1, sizeof(struct amd_screen));
-    if (amd_screen == NULL) {
-        fprintf(stderr, "\nERROR!  Allocating private area failed\n");
-        return NULL;
-    }
-    dri_screen->private = (void*)amd_screen;
-    dri_screen->extensions = amd_screen_extensions;
-    amd_screen->dri_screen = dri_screen;
-
-    amd_screen->bom = radeon_bo_manager_gem_ctor(dri_screen->fd);
-    if (amd_screen->bom == NULL) {
-        amd_screen_destroy(dri_screen);
-        return NULL;
-    }
-
-    return driConcatConfigs(amd_fill_in_modes(16, 16, 1),
-                            amd_fill_in_modes(32, 24, 1));
-}
-
-static boolean amd_buffer_create(__DRIscreenPrivate *dri_screen,
-                                 __DRIdrawablePrivate *dri_drawable,
-                                 const __GLcontextModes *visual,
-                                 boolean is_pixmap)
-{
-    if (is_pixmap) {
-        /* TODO: implement ? */
-        return GL_FALSE;
-    } else {
-        enum pipe_format color_format, depth_format, stencil_format;
-        struct amd_framebuffer *amd_fb;
-
-        amd_fb = calloc(1, sizeof(struct amd_framebuffer));
-        if (amd_fb == NULL) {
-            return GL_FALSE;
-        }
-
-        switch (visual->redBits) {
-        case 5:
-            color_format = PIPE_FORMAT_R5G6B5_UNORM;
-            break;
-        default:
-            color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-            break;
-        }
-
-        switch (visual->depthBits) {
-        case 24:
-            depth_format = PIPE_FORMAT_S8Z24_UNORM;
-            break;
-        case 16:
-            depth_format = PIPE_FORMAT_Z16_UNORM;
-            break;
-        default:
-            depth_format = PIPE_FORMAT_NONE;
-            break;
-        }
-
-        switch (visual->stencilBits) {
-        case 8:
-            /* force depth format */
-            depth_format = PIPE_FORMAT_S8Z24_UNORM;
-            stencil_format = PIPE_FORMAT_S8Z24_UNORM;
-            break;
-        default:
-            stencil_format = PIPE_FORMAT_NONE;
-            break;
-        }
-
-        amd_fb->st_framebuffer = st_create_framebuffer(visual,
-                                                       color_format,
-                                                       depth_format,
-                                                       stencil_format,
-                                                       dri_drawable->w,
-                                                       dri_drawable->h,
-                                                       (void*)amd_fb);
-        if (amd_fb->st_framebuffer == NULL) {
-            free(amd_fb);
-            return GL_FALSE;
-        }
-        dri_drawable->driverPrivate = (void *) amd_fb;
-
-        amd_fb->attachments = (1 << __DRI_BUFFER_FRONT_LEFT);
-        if (visual->doubleBufferMode) {
-            amd_fb->attachments |= (1 << __DRI_BUFFER_BACK_LEFT);
-        }
-        if (visual->depthBits || visual->stencilBits) {
-            amd_fb->attachments |= (1 << __DRI_BUFFER_DEPTH);
-        }
-
-        return GL_TRUE;
-    }
-}
-
-static void amd_buffer_destroy(__DRIdrawablePrivate * dri_drawable)
-{
-   struct amd_framebuffer *amd_fb;
-   
-   amd_fb = dri_drawable->driverPrivate;
-   assert(amd_fb->st_framebuffer);
-   st_unreference_framebuffer(amd_fb->st_framebuffer);
-   free(amd_fb);
-}
-
-static void amd_swap_buffers(__DRIdrawablePrivate *dri_drawable)
-{
-    struct amd_framebuffer *amd_fb;
-    struct pipe_surface *back_surf = NULL;
-
-    amd_fb = dri_drawable->driverPrivate;
-    assert(amd_fb);
-    assert(amd_fb->st_framebuffer);
-
-    st_get_framebuffer_surface(amd_fb->st_framebuffer,
-                               ST_SURFACE_BACK_LEFT,
-                               &back_surf);
-    if (back_surf) {
-        st_notify_swapbuffers(amd_fb->st_framebuffer);
-        /* TODO: do we want to do anythings ? */
-        st_notify_swapbuffers_complete(amd_fb->st_framebuffer);
-    }
-}
-
-/**
- * Called via glXCopySubBufferMESA() to copy a subrect of the back
- * buffer to the front buffer/screen.
- */
-static void amd_copy_sub_buffer(__DRIdrawablePrivate *dri_drawable,
-                         int x, int y, int w, int h)
-{
-    /* TODO: ... */
-}
-
-const struct __DriverAPIRec driDriverAPI = {
-    .InitScreen           = NULL,
-    .DestroyScreen        = amd_screen_destroy,
-    .CreateContext        = amd_context_create,
-    .DestroyContext       = amd_context_destroy,
-    .CreateBuffer         = amd_buffer_create,
-    .DestroyBuffer        = amd_buffer_destroy,
-    .SwapBuffers          = amd_swap_buffers,
-    .MakeCurrent          = amd_context_bind,
-    .UnbindContext        = amd_context_unbind,
-    .CopySubBuffer        = amd_copy_sub_buffer,
-    .InitScreen2          = amd_screen_init,
-};
diff --git a/src/gallium/winsys/drm/amd/amd_screen.h b/src/gallium/winsys/drm/amd/amd_screen.h
deleted file mode 100644 (file)
index 2617393..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#ifndef AMD_SCREEN_H
-#define AMD_SCREEN_H
-
-#include "dri_util.h"
-#include "radeon_bo.h"
-
-struct amd_screen {
-    __DRIscreenPrivate          *dri_screen;
-    struct radeon_bo_manager    *bom;
-};
-
-#endif
diff --git a/src/gallium/winsys/drm/amd/amd_winsys_softpipe.c b/src/gallium/winsys/drm/amd/amd_winsys_softpipe.c
deleted file mode 100644 (file)
index b9b2a0e..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
- * 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 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
- * THE COPYRIGHT HOLDERS, AUTHORS 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- * 
- * 
- **************************************************************************/
-/*
- * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
- */
-#include <stdio.h>
-#include "imports.h"
-#include "pipe/p_defines.h"
-#include "pipe/p_format.h"
-#include "softpipe/sp_winsys.h"
-#include "amd_context.h"
-#include "amd_winsys_softpipe.h"
-
-struct amd_softpipe_winsys {
-    struct softpipe_winsys  sp_winsys;
-    struct amd_context      *amd_context;
-};
-
-/**
- * Return list of surface formats supported by this driver.
- */
-static boolean amd_is_format_supported(struct softpipe_winsys *sws, uint format)
-{
-    switch (format) {
-    case PIPE_FORMAT_A8R8G8B8_UNORM:
-    case PIPE_FORMAT_R5G6B5_UNORM:
-    case PIPE_FORMAT_Z24S8_UNORM:
-        return TRUE;
-    default:
-        break;
-    };
-    return FALSE;
-}
-
-struct pipe_context *amd_create_softpipe(struct amd_context *amd_context)
-{
-    struct amd_softpipe_winsys *amd_sp_ws;
-    struct pipe_screen *pipe_screen;
-
-    pipe_screen = softpipe_create_screen(amd_context->pipe_winsys);
-
-    amd_sp_ws = CALLOC_STRUCT(amd_softpipe_winsys);
-    if (amd_sp_ws == NULL) {
-        return NULL;
-    }
-    amd_context->pipe_screen = pipe_screen;
-    amd_sp_ws->amd_context = amd_context;
-    amd_sp_ws->sp_winsys.is_format_supported = amd_is_format_supported;
-    return softpipe_create(pipe_screen,
-                           amd_context->pipe_winsys,
-                           &amd_sp_ws->sp_winsys);
-}
diff --git a/src/gallium/winsys/drm/amd/amd_winsys_softpipe.h b/src/gallium/winsys/drm/amd/amd_winsys_softpipe.h
deleted file mode 100644 (file)
index e5b68cf..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/* 
- * Copyright © 2008 Jérôme Glisse
- * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
- * 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.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- */
-/*
- * Authors:
- *      Jérôme Glisse <glisse@freedesktop.org>
- */
-#ifndef AMD_WINSYS_SOFTPIPE_H
-#define AMD_WINSYS_SOFTPIPE_H
-
-#include "amd_context.h"
-
-struct pipe_context *amd_create_softpipe(struct amd_context *amd_context);
-
-#endif
diff --git a/src/gallium/winsys/drm/radeon/Makefile b/src/gallium/winsys/drm/radeon/Makefile
new file mode 100644 (file)
index 0000000..dca1e32
--- /dev/null
@@ -0,0 +1,32 @@
+
+TOP = ../../../../..
+include $(TOP)/configs/current
+
+LIBNAME = radeon_dri.so
+
+MINIGLX_SOURCES =
+
+PIPE_DRIVERS = \
+       $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+       $(TOP)/src/gallium/drivers/r300/libr300.a
+
+DRIVER_SOURCES = \
+       radeon_buffer.c \
+       radeon_context.c \
+       radeon_r300.c \
+       radeon_screen.c \
+       radeon_winsys_softpipe.c
+
+C_SOURCES = \
+       $(COMMON_GALLIUM_SOURCES) \
+       $(DRIVER_SOURCES)
+
+ASM_SOURCES = 
+
+DRIVER_DEFINES = -I../../../drivers/r300
+
+include ../Makefile.template
+
+DRI_LIB_DEPS += -ldrm_radeon
+
+symlinks:
diff --git a/src/gallium/winsys/drm/radeon/SConscript b/src/gallium/winsys/drm/radeon/SConscript
new file mode 100644 (file)
index 0000000..2435211
--- /dev/null
@@ -0,0 +1,29 @@
+Import('*')
+
+if 'mesa' in env['statetrackers']:
+
+       env = drienv.Clone()
+
+       DRIVER_SOURCES = [
+               'radeon_buffer.c',
+               'radeon_context.c',
+               'radeon_screen.c',
+               'radeon_winsys_softpipe.c',
+       ]
+
+       sources = \
+               COMMON_GALLIUM_SOURCES + \
+               DRIVER_SOURCES
+
+       drivers = [
+               softpipe,
+               r300
+       ]
+
+       # TODO: write a wrapper function http://www.scons.org/wiki/WrapperFunctions
+       env.SharedLibrary(
+               target ='radeon_dri.so',
+               source = sources,
+               LIBS = drivers + mesa + auxiliaries + env['LIBS'],
+       )
+
diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.c b/src/gallium/winsys/drm/radeon/radeon_buffer.c
new file mode 100644 (file)
index 0000000..259a505
--- /dev/null
@@ -0,0 +1,239 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#include <stdio.h>
+#include "dri_util.h"
+#include "state_tracker/st_public.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "radeon_buffer.h"
+#include "radeon_screen.h"
+#include "radeon_context.h"
+#include "radeon_bo.h"
+#include "radeon_drm.h"
+
+static const char *radeon_get_name(struct pipe_winsys *ws)
+{
+    return "RADEON/DRI2";
+}
+
+static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws,
+                                             unsigned alignment,
+                                             unsigned usage,
+                                             unsigned size)
+{
+    struct radeon_pipe_winsys *radeon_ws = (struct radeon_pipe_winsys *)ws;
+    struct radeon_pipe_buffer *radeon_buffer;
+    uint32_t domain;
+
+    radeon_buffer = calloc(1, sizeof(*radeon_buffer));
+    if (radeon_buffer == NULL) {
+        return NULL;
+    }
+    radeon_buffer->base.refcount = 1;
+    radeon_buffer->base.alignment = alignment;
+    radeon_buffer->base.usage = usage;
+    radeon_buffer->base.size = size;
+
+    domain = 0;
+
+    if (usage & PIPE_BUFFER_USAGE_PIXEL) {
+        domain |= RADEON_GEM_DOMAIN_VRAM;
+    }
+    if (usage & PIPE_BUFFER_USAGE_VERTEX) {
+        domain |= RADEON_GEM_DOMAIN_GTT;
+    }
+
+    if (usage & PIPE_BUFFER_USAGE_INDEX) {
+        domain |= RADEON_GEM_DOMAIN_GTT;
+    }
+    radeon_buffer->bo = radeon_bo_open(radeon_ws->radeon_screen->bom, 0,
+                                    size, alignment, domain, 0);
+    if (radeon_buffer->bo == NULL) {
+        free(radeon_buffer);
+    }
+    return &radeon_buffer->base;
+}
+
+static struct pipe_buffer *radeon_buffer_user_create(struct pipe_winsys *ws,
+                                                  void *ptr,
+                                                  unsigned bytes)
+{
+    struct radeon_pipe_buffer *radeon_buffer;
+
+    radeon_buffer = (struct radeon_pipe_buffer*)radeon_buffer_create(ws, 0, 0, bytes);
+    if (radeon_buffer == NULL) {
+        return NULL;
+    }
+    radeon_bo_map(radeon_buffer->bo, 1);
+    memcpy(radeon_buffer->bo->ptr, ptr, bytes);
+    radeon_bo_unmap(radeon_buffer->bo);
+    return &radeon_buffer->base;
+}
+
+static void radeon_buffer_del(struct pipe_winsys *ws, struct pipe_buffer *buffer)
+{
+    struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer;
+
+    radeon_bo_unref(radeon_buffer->bo);
+    free(radeon_buffer);
+}
+
+static void *radeon_buffer_map(struct pipe_winsys *ws,
+                            struct pipe_buffer *buffer,
+                            unsigned flags)
+{
+    struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer;
+    int write = 0;
+
+    if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
+        write = 1;
+    }
+    if (radeon_bo_map(radeon_buffer->bo, write))
+        return NULL;
+    return radeon_buffer->bo->ptr;
+}
+
+static void radeon_buffer_unmap(struct pipe_winsys *ws, struct pipe_buffer *buffer)
+{
+    struct radeon_pipe_buffer *radeon_buffer = (struct radeon_pipe_buffer*)buffer;
+
+    radeon_bo_unmap(radeon_buffer->bo);
+}
+
+static void radeon_fence_reference(struct pipe_winsys *ws,
+                                struct pipe_fence_handle **ptr,
+                                struct pipe_fence_handle *pfence)
+{
+}
+
+static int radeon_fence_signalled(struct pipe_winsys *ws,
+                               struct pipe_fence_handle *pfence,
+                               unsigned flag)
+{
+    return 1;
+}
+
+static int radeon_fence_finish(struct pipe_winsys *ws,
+                            struct pipe_fence_handle *pfence,
+                            unsigned flag)
+{
+    return 0;
+}
+
+static void radeon_flush_frontbuffer(struct pipe_winsys *pipe_winsys,
+                                  struct pipe_surface *pipe_surface,
+                                  void *context_private)
+{
+    /* TODO: call dri2CopyRegion */
+}
+
+struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen)
+{
+    struct radeon_pipe_winsys *radeon_ws;
+
+    radeon_ws = calloc(1, sizeof(struct radeon_pipe_winsys));
+    if (radeon_ws == NULL) {
+        return NULL;
+    }
+    radeon_ws->radeon_screen = radeon_screen;
+
+    radeon_ws->winsys.flush_frontbuffer = radeon_flush_frontbuffer;
+
+    radeon_ws->winsys.buffer_create = radeon_buffer_create;
+    radeon_ws->winsys.buffer_destroy = radeon_buffer_del;
+    radeon_ws->winsys.user_buffer_create = radeon_buffer_user_create;
+    radeon_ws->winsys.buffer_map = radeon_buffer_map;
+    radeon_ws->winsys.buffer_unmap = radeon_buffer_unmap;
+
+    radeon_ws->winsys.fence_reference = radeon_fence_reference;
+    radeon_ws->winsys.fence_signalled = radeon_fence_signalled;
+    radeon_ws->winsys.fence_finish = radeon_fence_finish;
+
+    radeon_ws->winsys.get_name = radeon_get_name;
+
+    return &radeon_ws->winsys;
+}
+
+static struct pipe_buffer *radeon_buffer_from_handle(struct radeon_screen *radeon_screen,
+                                                  uint32_t handle)
+{
+    struct radeon_pipe_buffer *radeon_buffer;
+    struct radeon_bo *bo = NULL;
+
+    bo = radeon_bo_open(radeon_screen->bom, handle, 0, 0, 0, 0);
+    if (bo == NULL) {
+        return NULL;
+    }
+    radeon_buffer = calloc(1, sizeof(struct radeon_pipe_buffer));
+    if (radeon_buffer == NULL) {
+        radeon_bo_unref(bo);
+        return NULL;
+    }
+    radeon_buffer->base.refcount = 1;
+    radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
+    radeon_buffer->bo = bo;
+    return &radeon_buffer->base;
+}
+
+struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_context,
+                                             uint32_t handle,
+                                             enum pipe_format format,
+                                             int w, int h, int pitch)
+{
+    struct pipe_screen *pipe_screen = radeon_context->pipe_screen;
+    struct pipe_winsys *pipe_winsys = radeon_context->pipe_winsys;
+    struct pipe_texture tmpl;
+    struct pipe_surface *ps;
+    struct pipe_texture *pt;
+    struct pipe_buffer *pb;
+
+    pb = radeon_buffer_from_handle(radeon_context->radeon_screen, handle);
+    if (pb == NULL) {
+        return NULL;
+    }
+    memset(&tmpl, 0, sizeof(tmpl));
+    tmpl.tex_usage = PIPE_TEXTURE_USAGE_DISPLAY_TARGET;
+    tmpl.target = PIPE_TEXTURE_2D;
+    tmpl.width[0] = w;
+    tmpl.height[0] = h;
+    tmpl.depth[0] = 1;
+    tmpl.format = format;
+    pf_get_block(tmpl.format, &tmpl.block);
+    tmpl.nblocksx[0] = pf_get_nblocksx(&tmpl.block, w);
+    tmpl.nblocksy[0] = pf_get_nblocksy(&tmpl.block, h);
+
+    pt = pipe_screen->texture_blanket(pipe_screen, &tmpl, &pitch, pb);
+    if (pt == NULL) {
+        pipe_buffer_reference(pipe_screen, &pb, NULL);
+    }
+    ps = pipe_screen->get_tex_surface(pipe_screen, pt, 0, 0, 0,
+                                      PIPE_BUFFER_USAGE_GPU_WRITE);
+    return ps;
+}
diff --git a/src/gallium/winsys/drm/radeon/radeon_buffer.h b/src/gallium/winsys/drm/radeon/radeon_buffer.h
new file mode 100644 (file)
index 0000000..c626c20
--- /dev/null
@@ -0,0 +1,54 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#ifndef RADEON_BUFFER_H
+#define RADEON_BUFFER_H
+
+#include "pipe/internal/p_winsys_screen.h"
+#include "radeon_screen.h"
+#include "radeon_context.h"
+#include "radeon_bo.h"
+
+struct radeon_pipe_buffer {
+    struct pipe_buffer  base;
+    struct radeon_bo    *bo;
+};
+
+struct radeon_pipe_winsys {
+    struct pipe_winsys      winsys;
+    struct radeon_screen       *radeon_screen;
+};
+
+struct pipe_winsys *radeon_pipe_winsys(struct radeon_screen *radeon_screen);
+struct pipe_surface *radeon_surface_from_handle(struct radeon_context *radeon_context,
+                                             uint32_t handle,
+                                             enum pipe_format format,
+                                             int w, int h, int pitch);
+
+#endif
diff --git a/src/gallium/winsys/drm/radeon/radeon_context.c b/src/gallium/winsys/drm/radeon/radeon_context.c
new file mode 100644 (file)
index 0000000..a9d1577
--- /dev/null
@@ -0,0 +1,306 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#include <stdio.h>
+#include "dri_util.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "state_tracker/st_public.h"
+#include "state_tracker/st_context.h"
+#include "radeon_screen.h"
+#include "radeon_context.h"
+#include "radeon_buffer.h"
+#include "radeon_winsys_softpipe.h"
+
+#define need_GL_ARB_fragment_program
+#define need_GL_ARB_multisample
+#define need_GL_ARB_point_parameters
+#define need_GL_ARB_shader_objects
+#define need_GL_ARB_texture_compression
+#define need_GL_ARB_vertex_buffer_object
+#define need_GL_ARB_vertex_program
+#define need_GL_ARB_vertex_shader
+#define need_GL_EXT_blend_color
+#define need_GL_EXT_blend_equation_separate
+#define need_GL_EXT_blend_func_separate
+#define need_GL_EXT_blend_minmax
+#define need_GL_EXT_cull_vertex
+#define need_GL_EXT_compiled_vertex_array
+#define need_GL_EXT_fog_coord
+#define need_GL_EXT_framebuffer_object
+#define need_GL_EXT_multi_draw_arrays
+#define need_GL_EXT_secondary_color
+#define need_GL_VERSION_2_0
+#define need_GL_VERSION_2_1
+#include "extension_helper.h"
+
+/**
+ * Extension strings exported by the radeon driver.
+ */
+const struct dri_extension radeon_card_extensions[] = {
+   {"GL_ARB_multitexture", NULL},
+   {"GL_ARB_texture_border_clamp", NULL},
+   {"GL_ARB_texture_rectangle", NULL},
+   {"GL_ARB_pixel_buffer_object", NULL},
+   {"GL_ARB_point_parameters", GL_ARB_point_parameters_functions},
+   {"GL_ARB_shader_objects", GL_ARB_shader_objects_functions},
+   {"GL_ARB_shading_language_100", GL_VERSION_2_0_functions},
+   {"GL_ARB_shading_language_120", GL_VERSION_2_1_functions},
+   {"GL_ARB_vertex_buffer_object", GL_ARB_vertex_buffer_object_functions},
+   {"GL_ARB_vertex_program", GL_ARB_vertex_program_functions},
+   {"GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions},
+   {"GL_EXT_blend_color", GL_EXT_blend_color_functions},
+   {"GL_EXT_blend_equation_separate", GL_EXT_blend_equation_separate_functions},
+   {"GL_EXT_blend_func_separate", GL_EXT_blend_func_separate_functions},
+   {"GL_EXT_blend_minmax", GL_EXT_blend_minmax_functions},
+   {"GL_EXT_blend_subtract", NULL},
+   {"GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions},
+   {"GL_EXT_cull_vertex", GL_EXT_cull_vertex_functions},
+   {"GL_EXT_fog_coord", GL_EXT_fog_coord_functions},
+   {"GL_EXT_framebuffer_object", GL_EXT_framebuffer_object_functions},
+   {"GL_EXT_multi_draw_arrays", GL_EXT_multi_draw_arrays_functions},
+   {"GL_EXT_packed_depth_stencil", NULL},
+   {"GL_EXT_pixel_buffer_object", NULL},
+   {"GL_EXT_secondary_color", GL_EXT_secondary_color_functions},
+   {"GL_EXT_stencil_wrap", NULL},
+   {NULL, NULL}
+};
+
+static void radeon_update_renderbuffers(__DRIcontext *dri_context,
+                                     __DRIdrawable *dri_drawable)
+{
+    struct radeon_framebuffer *radeon_fb;
+    struct radeon_context *radeon_context;
+    unsigned attachments[10];
+    __DRIbuffer *buffers;
+    __DRIscreen *screen;
+    int i, count;
+
+    radeon_context = dri_context->driverPrivate;
+    screen = dri_drawable->driScreenPriv;
+    radeon_fb = dri_drawable->driverPrivate;
+    for (count = 0, i = 0; count < 6; count++) {
+        if (radeon_fb->attachments & (1 << count)) {
+            attachments[i++] = count;
+        }
+    }
+
+    buffers = (*screen->dri2.loader->getBuffers)(dri_drawable,
+                                                 &dri_drawable->w,
+                                                 &dri_drawable->h,
+                                                 attachments,
+                                                 i,
+                                                 &count,
+                                                 dri_drawable->loaderPrivate);
+    if (buffers == NULL) {
+        return;
+    }
+
+    /* set one cliprect to cover the whole dri_drawable */
+    dri_drawable->x = 0;
+    dri_drawable->y = 0;
+    dri_drawable->backX = 0;
+    dri_drawable->backY = 0;
+    dri_drawable->numClipRects = 1;
+    dri_drawable->pClipRects[0].x1 = 0;
+    dri_drawable->pClipRects[0].y1 = 0;
+    dri_drawable->pClipRects[0].x2 = dri_drawable->w;
+    dri_drawable->pClipRects[0].y2 = dri_drawable->h;
+    dri_drawable->numBackClipRects = 1;
+    dri_drawable->pBackClipRects[0].x1 = 0;
+    dri_drawable->pBackClipRects[0].y1 = 0;
+    dri_drawable->pBackClipRects[0].x2 = dri_drawable->w;
+    dri_drawable->pBackClipRects[0].y2 = dri_drawable->h;
+
+    for (i = 0; i < count; i++) {
+        struct pipe_surface *ps;
+        enum pipe_format format = 0;
+        int index = 0;
+
+        switch (buffers[i].attachment) {
+        case __DRI_BUFFER_FRONT_LEFT:
+            index = ST_SURFACE_FRONT_LEFT;
+            switch (buffers[i].cpp) {
+            case 4:
+                format = PIPE_FORMAT_A8R8G8B8_UNORM;
+                break;
+            case 2:
+                format = PIPE_FORMAT_R5G6B5_UNORM;
+                break;
+            default:
+                /* FIXME: error */
+                return;
+            }
+            break;
+        case __DRI_BUFFER_BACK_LEFT:
+            index = ST_SURFACE_BACK_LEFT;
+            switch (buffers[i].cpp) {
+            case 4:
+                format = PIPE_FORMAT_A8R8G8B8_UNORM;
+                break;
+            case 2:
+                format = PIPE_FORMAT_R5G6B5_UNORM;
+                break;
+            default:
+                /* FIXME: error */
+                return;
+            }
+            break;
+        case __DRI_BUFFER_STENCIL:
+        case __DRI_BUFFER_DEPTH:
+            index = ST_SURFACE_DEPTH;
+            switch (buffers[i].cpp) {
+            case 4:
+                format = PIPE_FORMAT_Z24S8_UNORM;
+                break;
+            case 2:
+                format = PIPE_FORMAT_Z16_UNORM;
+                break;
+            default:
+                /* FIXME: error */
+                return;
+            }
+            break;
+        case __DRI_BUFFER_ACCUM:
+        default:
+            fprintf(stderr,
+                    "unhandled buffer attach event, attacment type %d\n",
+                    buffers[i].attachment);
+            return;
+        }
+
+        ps = radeon_surface_from_handle(radeon_context,
+                                     buffers[i].name,
+                                     format,
+                                     dri_drawable->w,
+                                     dri_drawable->h,
+                                     buffers[i].pitch);
+        assert(ps);
+        st_set_framebuffer_surface(radeon_fb->st_framebuffer, index, ps);
+    }
+    st_resize_framebuffer(radeon_fb->st_framebuffer,
+                          dri_drawable->w,
+                          dri_drawable->h);
+}
+
+GLboolean radeon_context_create(const __GLcontextModes *visual,
+                             __DRIcontextPrivate *dri_context,
+                             void *shared_context)
+{
+    __DRIscreenPrivate *dri_screen;
+    struct radeon_context *radeon_context;
+    struct radeon_screen *radeon_screen;
+    struct pipe_context *pipe;
+    struct st_context *shared_st_context = NULL;
+
+    dri_context->driverPrivate = NULL;
+    radeon_context = calloc(1, sizeof(struct radeon_context));
+    if (radeon_context == NULL) {
+        return GL_FALSE;
+    }
+
+    if (shared_context) {
+        shared_st_context = ((struct radeon_context*)shared_context)->st_context;
+    }
+
+    dri_screen = dri_context->driScreenPriv;
+    radeon_screen = dri_screen->private;
+    radeon_context->dri_screen = dri_screen;
+    radeon_context->radeon_screen = radeon_screen;
+    radeon_context->drm_fd = dri_screen->fd;
+
+    radeon_context->pipe_winsys = radeon_pipe_winsys(radeon_screen);
+    if (radeon_context->pipe_winsys == NULL) {
+        free(radeon_context);
+        return GL_FALSE;
+    }
+
+    if (!getenv("RADEON_SOFTPIPE")) {
+        fprintf(stderr, "Creating r300 context...\n");
+        pipe =
+            r300_create_context(NULL,
+                                radeon_context->pipe_winsys,
+                                radeon_create_r300_winsys(radeon_context->drm_fd));
+        radeon_context->pipe_screen = pipe->screen;
+    } else {
+        pipe = radeon_create_softpipe(radeon_context);
+    }
+    radeon_context->st_context = st_create_context(pipe, visual,
+                                                shared_st_context);
+    driInitExtensions(radeon_context->st_context->ctx,
+                      radeon_card_extensions, GL_TRUE);
+    dri_context->driverPrivate = radeon_context;
+    return GL_TRUE;
+}
+
+void radeon_context_destroy(__DRIcontextPrivate *dri_context)
+{
+    struct radeon_context *radeon_context;
+
+    radeon_context = dri_context->driverPrivate;
+    st_finish(radeon_context->st_context);
+    st_destroy_context(radeon_context->st_context);
+    free(radeon_context);
+}
+
+GLboolean radeon_context_bind(__DRIcontextPrivate *dri_context,
+                           __DRIdrawablePrivate *dri_drawable,
+                           __DRIdrawablePrivate *dri_readable)
+{
+    struct radeon_framebuffer *drawable;
+    struct radeon_framebuffer *readable;
+    struct radeon_context *radeon_context;
+
+    if (dri_context == NULL) {
+        st_make_current(NULL, NULL, NULL);
+        return GL_TRUE;
+    }
+
+    radeon_context = dri_context->driverPrivate;
+    drawable = dri_drawable->driverPrivate;
+    readable = dri_readable->driverPrivate;
+    st_make_current(radeon_context->st_context,
+                    drawable->st_framebuffer,
+                    readable->st_framebuffer);
+
+    radeon_update_renderbuffers(dri_context, dri_drawable);
+    if (dri_drawable != dri_readable) {
+        radeon_update_renderbuffers(dri_context, dri_readable);
+    }
+    return GL_TRUE;
+}
+
+GLboolean radeon_context_unbind(__DRIcontextPrivate *dri_context)
+{
+    struct radeon_context *radeon_context;
+
+    radeon_context = dri_context->driverPrivate;
+    st_flush(radeon_context->st_context, PIPE_FLUSH_RENDER_CACHE, NULL);
+    return GL_TRUE;
+}
diff --git a/src/gallium/winsys/drm/radeon/radeon_context.h b/src/gallium/winsys/drm/radeon/radeon_context.h
new file mode 100644 (file)
index 0000000..d7222b4
--- /dev/null
@@ -0,0 +1,70 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#ifndef RADEON_CONTEXT_H
+#define RADEON_CONTEXT_H
+
+#include "dri_util.h"
+#include "state_tracker/st_public.h"
+#include "state_tracker/st_context.h"
+#include "radeon_screen.h"
+
+#include "radeon_r300.h"
+
+struct radeon_framebuffer {
+    struct st_framebuffer   *st_framebuffer;
+    unsigned                attachments;
+};
+
+struct radeon_context {
+    /* st */
+    struct st_context       *st_context;
+    /* pipe */
+    struct pipe_screen      *pipe_screen;
+    struct pipe_winsys      *pipe_winsys;
+    /* DRI */
+    __DRIscreenPrivate      *dri_screen;
+    __DRIdrawablePrivate    *dri_drawable;
+    __DRIdrawablePrivate    *dri_readable;
+    /* DRM */
+    int                     drm_fd;
+   /* RADEON */
+    struct radeon_screen       *radeon_screen;
+};
+
+GLboolean radeon_context_create(const __GLcontextModes*,
+                             __DRIcontextPrivate*,
+                             void*);
+void radeon_context_destroy(__DRIcontextPrivate*);
+GLboolean radeon_context_bind(__DRIcontextPrivate*,
+                           __DRIdrawablePrivate*,
+                           __DRIdrawablePrivate*);
+GLboolean radeon_context_unbind(__DRIcontextPrivate*);
+
+#endif
diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.c b/src/gallium/winsys/drm/radeon/radeon_r300.c
new file mode 100644 (file)
index 0000000..8fe2375
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ *
+ * 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
+ * on 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
+ * THE AUTHOR(S) AND/OR THEIR 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 "radeon_r300.h"
+
+static boolean radeon_r300_check_cs(struct radeon_cs* cs, int size)
+{
+    /* XXX check size here, lazy ass! */
+    return TRUE;
+}
+
+static void radeon_r300_write_cs_reloc(struct radeon_cs* cs,
+                                    struct pipe_buffer* pbuffer,
+                                    uint32_t rd,
+                                    uint32_t wd,
+                                    uint32_t flags)
+{
+    radeon_cs_write_reloc(cs, ((struct radeon_pipe_buffer*)pbuffer)->bo, rd, wd, flags);
+}
+
+static void radeon_r300_flush_cs(struct radeon_cs* cs)
+{
+    radeon_cs_emit(cs);
+    radeon_cs_erase(cs);
+}
+
+/* Helper function to do the ioctls needed for setup and init. */
+static void do_ioctls(struct r300_winsys* winsys, int fd)
+{
+    drm_radeon_getparam_t gp;
+    uint32_t target;
+    int retval;
+
+    /* XXX is this cast safe? */
+    gp.value = (int*)&target;
+
+    /* First, get PCI ID */
+    gp.param = RADEON_PARAM_DEVICE_ID;
+    retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
+    if (retval) {
+        fprintf(stderr, "%s: Failed to get PCI ID, error number %d",
+                __FUNCTION__, retval);
+        exit(1);
+    }
+    winsys->pci_id = target;
+
+    /* Then, get the number of pixel pipes */
+    gp.param = RADEON_PARAM_NUM_GB_PIPES;
+    retval = drmCommandWriteRead(fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
+    if (retval) {
+        fprintf(stderr, "%s: Failed to get GB pipe count, error number %d",
+                __FUNCTION__, retval);
+        exit(1);
+    }
+    winsys->gb_pipes = target;
+
+}
+
+struct r300_winsys* radeon_create_r300_winsys(int fd)
+{
+    struct r300_winsys* winsys = calloc(1, sizeof(struct r300_winsys));
+
+    do_ioctls(winsys, fd);
+
+    struct radeon_cs_manager* csm = radeon_cs_manager_gem_ctor(fd);
+
+    winsys->cs = radeon_cs_create(csm, 1024 * 64 / 4);
+
+    winsys->check_cs = radeon_r300_check_cs;
+    winsys->begin_cs = radeon_cs_begin;
+    winsys->write_cs_dword = radeon_cs_write_dword;
+    winsys->write_cs_reloc = radeon_r300_write_cs_reloc;
+    winsys->end_cs = radeon_cs_end;
+    winsys->flush_cs = radeon_r300_flush_cs;
+
+    return winsys;
+}
diff --git a/src/gallium/winsys/drm/radeon/radeon_r300.h b/src/gallium/winsys/drm/radeon/radeon_r300.h
new file mode 100644 (file)
index 0000000..8ed95a3
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ *
+ * 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
+ * on 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
+ * THE AUTHOR(S) AND/OR THEIR 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. */
+
+/* XXX WTF is this! I shouldn't have to include those first three! FUCK! */
+#include <stdint.h>
+#include <stdlib.h>
+#include "drm.h"
+#include "radeon_drm.h"
+#include "radeon_cs.h"
+
+#include "r300_winsys.h"
+
+#include "radeon_buffer.h"
+
+struct r300_winsys* radeon_create_r300_winsys(int fd);
diff --git a/src/gallium/winsys/drm/radeon/radeon_screen.c b/src/gallium/winsys/drm/radeon/radeon_screen.c
new file mode 100644 (file)
index 0000000..e31caff
--- /dev/null
@@ -0,0 +1,288 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#include <stdio.h>
+#include "pipe/p_screen.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+#include "state_tracker/st_public.h"
+#include "state_tracker/st_context.h"
+#include "utils.h"
+#include "xf86drm.h"
+#include "drm.h"
+#include "dri_util.h"
+#include "radeon_screen.h"
+#include "radeon_context.h"
+#include "radeon_buffer.h"
+#include "radeon_bo.h"
+#include "radeon_bo_gem.h"
+#include "radeon_drm.h"
+
+extern const struct dri_extension radeon_card_extensions[];
+
+static const __DRIextension *radeon_screen_extensions[] = {
+    &driReadDrawableExtension,
+    &driCopySubBufferExtension.base,
+    &driSwapControlExtension.base,
+    &driFrameTrackingExtension.base,
+    &driMediaStreamCounterExtension.base,
+    NULL
+};
+
+static __DRIconfig **radeon_fill_in_modes(unsigned pixel_bits,
+                                       unsigned depth_bits,
+                                       GLboolean have_back_buffer)
+{
+    __DRIconfig **configs;
+    unsigned depth_buffer_factor;
+    unsigned back_buffer_factor;
+    unsigned num_modes;
+    GLenum fb_format;
+    GLenum fb_type;
+    uint8_t depth_bits_array[3];
+    uint8_t stencil_bits_array[3];
+    uint8_t msaa_samples_array[1];
+    /* TODO: pageflipping ? */
+    static const GLenum back_buffer_modes[] = {
+        GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
+    };
+
+    stencil_bits_array[0] = 0;
+    stencil_bits_array[1] = 0;
+    if (depth_bits == 24) {
+        stencil_bits_array[2] = 8;
+        num_modes = 3;
+    }
+
+    depth_bits_array[0] = 0;
+    depth_bits_array[1] = depth_bits;
+    depth_bits_array[2] = depth_bits;
+    depth_buffer_factor = (depth_bits == 24) ? 3 : 2;
+
+    back_buffer_factor = (have_back_buffer) ? 3 : 1;
+
+    msaa_samples_array[0] = 0;
+
+    if (pixel_bits == 16) {
+        fb_format = GL_RGB;
+        fb_type = GL_UNSIGNED_SHORT_5_6_5;
+    } else {
+        fb_format = GL_BGRA;
+        fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+    }
+
+    configs = (__DRIconfig **)driCreateConfigs(fb_format,
+                                               fb_type,
+                                               depth_bits_array,
+                                               stencil_bits_array,
+                                               depth_buffer_factor,
+                                               back_buffer_modes,
+                                               back_buffer_factor,
+                                               msaa_samples_array,
+                                               1);
+    if (configs == NULL) {
+        fprintf(stderr, "[%s:%u] Error creating FBConfig!\n",
+                __FILE__, __LINE__);
+        return NULL;
+    }
+    return configs;
+}
+
+static void radeon_screen_destroy(__DRIscreenPrivate *dri_screen)
+{
+     struct radeon_screen *radeon_screen = (struct radeon_screen*)dri_screen->private;
+
+     radeon_bo_manager_gem_dtor(radeon_screen->bom); 
+     dri_screen = NULL;
+     free(radeon_screen);
+}
+
+static const __DRIconfig **radeon_screen_init(__DRIscreenPrivate *dri_screen)
+{
+    struct radeon_screen *radeon_screen;
+
+    /* Calling driInitExtensions here, with a NULL context pointer,
+     * does not actually enable the extensions.  It just makes sure
+     * that all the dispatch offsets for all the extensions that
+     * *might* be enables are known.  This is needed because the
+     * dispatch offsets need to be known when _mesa_context_create is
+     * called, but we can't enable the extensions until we have a
+     * context pointer.
+     *
+     * Hello chicken.  Hello egg.  How are you two today?
+     */
+    driInitExtensions(NULL, radeon_card_extensions, GL_FALSE);
+
+    radeon_screen = calloc(1, sizeof(struct radeon_screen));
+    if (radeon_screen == NULL) {
+        fprintf(stderr, "\nERROR!  Allocating private area failed\n");
+        return NULL;
+    }
+    dri_screen->private = (void*)radeon_screen;
+    dri_screen->extensions = radeon_screen_extensions;
+    radeon_screen->dri_screen = dri_screen;
+
+    radeon_screen->bom = radeon_bo_manager_gem_ctor(dri_screen->fd);
+    if (radeon_screen->bom == NULL) {
+        radeon_screen_destroy(dri_screen);
+        return NULL;
+    }
+
+    return driConcatConfigs(radeon_fill_in_modes(16, 16, 1),
+                            radeon_fill_in_modes(32, 24, 1));
+}
+
+static boolean radeon_buffer_create(__DRIscreenPrivate *dri_screen,
+                                 __DRIdrawablePrivate *dri_drawable,
+                                 const __GLcontextModes *visual,
+                                 boolean is_pixmap)
+{
+    if (is_pixmap) {
+        /* TODO: implement ? */
+        return GL_FALSE;
+    } else {
+        enum pipe_format color_format, depth_format, stencil_format;
+        struct radeon_framebuffer *radeon_fb;
+
+        radeon_fb = calloc(1, sizeof(struct radeon_framebuffer));
+        if (radeon_fb == NULL) {
+            return GL_FALSE;
+        }
+
+        switch (visual->redBits) {
+        case 5:
+            color_format = PIPE_FORMAT_R5G6B5_UNORM;
+            break;
+        default:
+            color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+            break;
+        }
+
+        switch (visual->depthBits) {
+        case 24:
+            depth_format = PIPE_FORMAT_S8Z24_UNORM;
+            break;
+        case 16:
+            depth_format = PIPE_FORMAT_Z16_UNORM;
+            break;
+        default:
+            depth_format = PIPE_FORMAT_NONE;
+            break;
+        }
+
+        switch (visual->stencilBits) {
+        case 8:
+            /* force depth format */
+            depth_format = PIPE_FORMAT_S8Z24_UNORM;
+            stencil_format = PIPE_FORMAT_S8Z24_UNORM;
+            break;
+        default:
+            stencil_format = PIPE_FORMAT_NONE;
+            break;
+        }
+
+        radeon_fb->st_framebuffer = st_create_framebuffer(visual,
+                                                       color_format,
+                                                       depth_format,
+                                                       stencil_format,
+                                                       dri_drawable->w,
+                                                       dri_drawable->h,
+                                                       (void*)radeon_fb);
+        if (radeon_fb->st_framebuffer == NULL) {
+            free(radeon_fb);
+            return GL_FALSE;
+        }
+        dri_drawable->driverPrivate = (void *) radeon_fb;
+
+        radeon_fb->attachments = (1 << __DRI_BUFFER_FRONT_LEFT);
+        if (visual->doubleBufferMode) {
+            radeon_fb->attachments |= (1 << __DRI_BUFFER_BACK_LEFT);
+        }
+        if (visual->depthBits || visual->stencilBits) {
+            radeon_fb->attachments |= (1 << __DRI_BUFFER_DEPTH);
+        }
+
+        return GL_TRUE;
+    }
+}
+
+static void radeon_buffer_destroy(__DRIdrawablePrivate * dri_drawable)
+{
+   struct radeon_framebuffer *radeon_fb;
+   
+   radeon_fb = dri_drawable->driverPrivate;
+   assert(radeon_fb->st_framebuffer);
+   st_unreference_framebuffer(radeon_fb->st_framebuffer);
+   free(radeon_fb);
+}
+
+static void radeon_swap_buffers(__DRIdrawablePrivate *dri_drawable)
+{
+    struct radeon_framebuffer *radeon_fb;
+    struct pipe_surface *back_surf = NULL;
+
+    radeon_fb = dri_drawable->driverPrivate;
+    assert(radeon_fb);
+    assert(radeon_fb->st_framebuffer);
+
+    st_get_framebuffer_surface(radeon_fb->st_framebuffer,
+                               ST_SURFACE_BACK_LEFT,
+                               &back_surf);
+    if (back_surf) {
+        st_notify_swapbuffers(radeon_fb->st_framebuffer);
+        /* TODO: do we want to do anythings ? */
+        st_notify_swapbuffers_complete(radeon_fb->st_framebuffer);
+    }
+}
+
+/**
+ * Called via glXCopySubBufferMESA() to copy a subrect of the back
+ * buffer to the front buffer/screen.
+ */
+static void radeon_copy_sub_buffer(__DRIdrawablePrivate *dri_drawable,
+                         int x, int y, int w, int h)
+{
+    /* TODO: ... */
+}
+
+const struct __DriverAPIRec driDriverAPI = {
+    .InitScreen           = NULL,
+    .DestroyScreen        = radeon_screen_destroy,
+    .CreateContext        = radeon_context_create,
+    .DestroyContext       = radeon_context_destroy,
+    .CreateBuffer         = radeon_buffer_create,
+    .DestroyBuffer        = radeon_buffer_destroy,
+    .SwapBuffers          = radeon_swap_buffers,
+    .MakeCurrent          = radeon_context_bind,
+    .UnbindContext        = radeon_context_unbind,
+    .CopySubBuffer        = radeon_copy_sub_buffer,
+    .InitScreen2          = radeon_screen_init,
+};
diff --git a/src/gallium/winsys/drm/radeon/radeon_screen.h b/src/gallium/winsys/drm/radeon/radeon_screen.h
new file mode 100644 (file)
index 0000000..01b7fa6
--- /dev/null
@@ -0,0 +1,41 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#ifndef RADEON_SCREEN_H
+#define RADEON_SCREEN_H
+
+#include "dri_util.h"
+#include "radeon_bo.h"
+
+struct radeon_screen {
+    __DRIscreenPrivate          *dri_screen;
+    struct radeon_bo_manager    *bom;
+};
+
+#endif
diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.c
new file mode 100644 (file)
index 0000000..8402e1f
--- /dev/null
@@ -0,0 +1,77 @@
+/**************************************************************************
+ * 
+ * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA
+ * 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 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
+ * THE COPYRIGHT HOLDERS, AUTHORS 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * 
+ **************************************************************************/
+/*
+ * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com>
+ */
+#include <stdio.h>
+#include "imports.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_format.h"
+#include "softpipe/sp_winsys.h"
+#include "radeon_context.h"
+#include "radeon_winsys_softpipe.h"
+
+struct radeon_softpipe_winsys {
+    struct softpipe_winsys  sp_winsys;
+    struct radeon_context      *radeon_context;
+};
+
+/**
+ * Return list of surface formats supported by this driver.
+ */
+static boolean radeon_is_format_supported(struct softpipe_winsys *sws, uint format)
+{
+    switch (format) {
+    case PIPE_FORMAT_A8R8G8B8_UNORM:
+    case PIPE_FORMAT_R5G6B5_UNORM:
+    case PIPE_FORMAT_Z24S8_UNORM:
+        return TRUE;
+    default:
+        break;
+    };
+    return FALSE;
+}
+
+struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context)
+{
+    struct radeon_softpipe_winsys *radeon_sp_ws;
+    struct pipe_screen *pipe_screen;
+
+    pipe_screen = softpipe_create_screen(radeon_context->pipe_winsys);
+
+    radeon_sp_ws = CALLOC_STRUCT(radeon_softpipe_winsys);
+    if (radeon_sp_ws == NULL) {
+        return NULL;
+    }
+    radeon_context->pipe_screen = pipe_screen;
+    radeon_sp_ws->radeon_context = radeon_context;
+    radeon_sp_ws->sp_winsys.is_format_supported = radeon_is_format_supported;
+    return softpipe_create(pipe_screen,
+                           radeon_context->pipe_winsys,
+                           &radeon_sp_ws->sp_winsys);
+}
diff --git a/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h b/src/gallium/winsys/drm/radeon/radeon_winsys_softpipe.h
new file mode 100644 (file)
index 0000000..519eab7
--- /dev/null
@@ -0,0 +1,37 @@
+/* 
+ * Copyright © 2008 Jérôme Glisse
+ * 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 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 THE COPYRIGHT HOLDERS, AUTHORS
+ * 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ */
+/*
+ * Authors:
+ *      Jérôme Glisse <glisse@freedesktop.org>
+ */
+#ifndef RADEON_WINSYS_SOFTPIPE_H
+#define RADEON_WINSYS_SOFTPIPE_H
+
+#include "radeon_context.h"
+
+struct pipe_context *radeon_create_softpipe(struct radeon_context *radeon_context);
+
+#endif