aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/drivers/dri/swrast
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/drivers/dri/swrast')
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/swrast.c84
-rw-r--r--mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h295
2 files changed, 230 insertions, 149 deletions
diff --git a/mesalib/src/mesa/drivers/dri/swrast/swrast.c b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
index b1abc502f..75eb46ee6 100644
--- a/mesalib/src/mesa/drivers/dri/swrast/swrast.c
+++ b/mesalib/src/mesa/drivers/dri/swrast/swrast.c
@@ -296,7 +296,7 @@ swrast_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
rb->Data = NULL;
rb->Width = width;
rb->Height = height;
-
+ rb->RowStride = width;
xrb->pitch = bytes_per_line(width * xrb->bpp, 32);
return GL_TRUE;
@@ -320,7 +320,8 @@ swrast_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
}
static struct swrast_renderbuffer *
-swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front)
+swrast_new_renderbuffer(const struct gl_config *visual, __DRIdrawable *dPriv,
+ GLboolean front)
{
struct swrast_renderbuffer *xrb = calloc(1, sizeof *xrb);
GLuint pixel_format;
@@ -334,6 +335,7 @@ swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front)
pixel_format = choose_pixel_format(visual);
+ xrb->dPriv = dPriv;
xrb->Base.Delete = swrast_delete_renderbuffer;
if (front) {
xrb->Base.AllocStorage = swrast_alloc_front_storage;
@@ -380,6 +382,78 @@ swrast_new_renderbuffer(const struct gl_config *visual, GLboolean front)
return xrb;
}
+static void
+swrast_map_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb,
+ GLuint x, GLuint y, GLuint w, GLuint h,
+ GLbitfield mode,
+ GLubyte **out_map,
+ GLint *out_stride)
+{
+ struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+ GLubyte *map = rb->Data;
+ int cpp = _mesa_get_format_bytes(rb->Format);
+ int stride = rb->RowStride * cpp;
+
+ if (rb->AllocStorage == swrast_alloc_front_storage) {
+ __DRIdrawable *dPriv = xrb->dPriv;
+ __DRIscreen *sPriv = dPriv->driScreenPriv;
+
+ xrb->map_mode = mode;
+ xrb->map_x = x;
+ xrb->map_y = y;
+ xrb->map_w = w;
+ xrb->map_h = h;
+
+ stride = w * cpp;
+ rb->Data = malloc(h * stride);
+
+ sPriv->swrast_loader->getImage(dPriv, x, y, w, h,
+ (char *)rb->Data,
+ dPriv->loaderPrivate);
+
+ *out_map = rb->Data;
+ *out_stride = stride;
+ return;
+ }
+
+ ASSERT(rb->Data);
+
+ if (rb->AllocStorage == swrast_alloc_back_storage) {
+ map += (rb->Height - 1) * stride;
+ stride = -stride;
+ }
+
+ map += y * stride;
+ map += x * cpp;
+
+ *out_map = map;
+ *out_stride = stride;
+}
+
+static void
+swrast_unmap_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb)
+{
+ struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb);
+
+ if (rb->AllocStorage == swrast_alloc_front_storage) {
+ __DRIdrawable *dPriv = xrb->dPriv;
+ __DRIscreen *sPriv = dPriv->driScreenPriv;
+
+ if (xrb->map_mode & GL_MAP_WRITE_BIT) {
+ sPriv->swrast_loader->putImage(dPriv, __DRI_SWRAST_IMAGE_OP_DRAW,
+ xrb->map_x, xrb->map_y,
+ xrb->map_w, xrb->map_h,
+ rb->Data,
+ dPriv->loaderPrivate);
+ }
+
+ free(rb->Data);
+ rb->Data = NULL;
+ }
+}
+
static GLboolean
dri_create_buffer(__DRIscreen * sPriv,
__DRIdrawable * dPriv,
@@ -411,12 +485,12 @@ dri_create_buffer(__DRIscreen * sPriv,
_mesa_initialize_window_framebuffer(fb, visual);
/* add front renderbuffer */
- frontrb = swrast_new_renderbuffer(visual, GL_TRUE);
+ frontrb = swrast_new_renderbuffer(visual, dPriv, GL_TRUE);
_mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base);
/* add back renderbuffer */
if (visual->doubleBufferMode) {
- backrb = swrast_new_renderbuffer(visual, GL_FALSE);
+ backrb = swrast_new_renderbuffer(visual, dPriv, GL_FALSE);
_mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base);
}
@@ -581,6 +655,8 @@ swrast_init_driver_functions(struct dd_function_table *driver)
driver->GetBufferSize = NULL;
driver->Viewport = viewport;
driver->ChooseTextureFormat = swrastChooseTextureFormat;
+ driver->MapRenderbuffer = swrast_map_renderbuffer;
+ driver->UnmapRenderbuffer = swrast_unmap_renderbuffer;
}
static const char *es2_extensions[] = {
diff --git a/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h b/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
index e61965147..405bb0fd3 100644
--- a/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
+++ b/mesalib/src/mesa/drivers/dri/swrast/swrast_priv.h
@@ -1,145 +1,150 @@
-/*
- * Mesa 3-D graphics library
- * Version: 7.1
- *
- * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
- * Copyright 2008, 2010 George Sapountzis <gsapountzis@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
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL 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.
- */
-
-
-#ifndef _SWRAST_PRIV_H
-#define _SWRAST_PRIV_H
-
-#include <GL/gl.h>
-#include <GL/internal/dri_interface.h>
-#include "main/mtypes.h"
-#include "drisw_util.h"
-
-#ifdef _MSC_VER
-#ifdef PUBLIC
-#undef PUBLIC
-#endif
-#define PUBLIC __declspec(dllexport)
-#endif
-
-
-/**
- * Debugging
- */
-#define DEBUG_CORE 0
-#define DEBUG_SPAN 0
-
-#if DEBUG_CORE
-#define TRACE printf("--> %s\n", __FUNCTION__)
-#else
-#define TRACE
-#endif
-
-#if DEBUG_SPAN
-#define TRACE_SPAN printf("--> %s\n", __FUNCTION__)
-#else
-#define TRACE_SPAN
-#endif
-
-
-/**
- * Data types
- */
-struct dri_context
-{
- /* mesa, base class, must be first */
- struct gl_context Base;
-
- /* dri */
- __DRIcontext *cPriv;
-};
-
-static INLINE struct dri_context *
-dri_context(__DRIcontext * driContextPriv)
-{
- return (struct dri_context *)driContextPriv->driverPrivate;
-}
-
-static INLINE struct dri_context *
-swrast_context(struct gl_context *ctx)
-{
- return (struct dri_context *) ctx;
-}
-
-struct dri_drawable
-{
- /* mesa, base class, must be first */
- struct gl_framebuffer Base;
-
- /* dri */
- __DRIdrawable *dPriv;
-
- /* scratch row for optimized front-buffer rendering */
- char *row;
-};
-
-static INLINE struct dri_drawable *
-dri_drawable(__DRIdrawable * driDrawPriv)
-{
- return (struct dri_drawable *)driDrawPriv->driverPrivate;
-}
-
-static INLINE struct dri_drawable *
-swrast_drawable(struct gl_framebuffer *fb)
-{
- return (struct dri_drawable *) fb;
-}
-
-struct swrast_renderbuffer {
- struct gl_renderbuffer Base;
-
- /* renderbuffer pitch (in bytes) */
- GLuint pitch;
- /* bits per pixel of storage */
- GLuint bpp;
-};
-
-static INLINE struct swrast_renderbuffer *
-swrast_renderbuffer(struct gl_renderbuffer *rb)
-{
- return (struct swrast_renderbuffer *) rb;
-}
-
-
-/**
- * Pixel formats we support
- */
-#define PF_A8R8G8B8 1 /**< 32bpp TrueColor: 8-A, 8-R, 8-G, 8-B bits */
-#define PF_R5G6B5 2 /**< 16bpp TrueColor: 5-R, 6-G, 5-B bits */
-#define PF_R3G3B2 3 /**< 8bpp TrueColor: 3-R, 3-G, 2-B bits */
-#define PF_X8R8G8B8 4 /**< 32bpp TrueColor: 8-R, 8-G, 8-B bits */
-
-
-/* swrast_span.c */
-
-extern void
-swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
- GLuint pixel_format);
-
-extern void
-swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
- GLuint pixel_format);
-
-#endif /* _SWRAST_PRIV_H_ */
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.1
+ *
+ * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
+ * Copyright 2008, 2010 George Sapountzis <gsapountzis@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
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL 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.
+ */
+
+
+#ifndef _SWRAST_PRIV_H
+#define _SWRAST_PRIV_H
+
+#include <GL/gl.h>
+#include <GL/internal/dri_interface.h>
+#include "main/mtypes.h"
+#include "drisw_util.h"
+
+#ifdef _MSC_VER
+#ifdef PUBLIC
+#undef PUBLIC
+#endif
+#define PUBLIC __declspec(dllexport)
+#endif
+
+
+/**
+ * Debugging
+ */
+#define DEBUG_CORE 0
+#define DEBUG_SPAN 0
+
+#if DEBUG_CORE
+#define TRACE printf("--> %s\n", __FUNCTION__)
+#else
+#define TRACE
+#endif
+
+#if DEBUG_SPAN
+#define TRACE_SPAN printf("--> %s\n", __FUNCTION__)
+#else
+#define TRACE_SPAN
+#endif
+
+
+/**
+ * Data types
+ */
+struct dri_context
+{
+ /* mesa, base class, must be first */
+ struct gl_context Base;
+
+ /* dri */
+ __DRIcontext *cPriv;
+};
+
+static INLINE struct dri_context *
+dri_context(__DRIcontext * driContextPriv)
+{
+ return (struct dri_context *)driContextPriv->driverPrivate;
+}
+
+static INLINE struct dri_context *
+swrast_context(struct gl_context *ctx)
+{
+ return (struct dri_context *) ctx;
+}
+
+struct dri_drawable
+{
+ /* mesa, base class, must be first */
+ struct gl_framebuffer Base;
+
+ /* dri */
+ __DRIdrawable *dPriv;
+
+ /* scratch row for optimized front-buffer rendering */
+ char *row;
+};
+
+static INLINE struct dri_drawable *
+dri_drawable(__DRIdrawable * driDrawPriv)
+{
+ return (struct dri_drawable *)driDrawPriv->driverPrivate;
+}
+
+static INLINE struct dri_drawable *
+swrast_drawable(struct gl_framebuffer *fb)
+{
+ return (struct dri_drawable *) fb;
+}
+
+struct swrast_renderbuffer {
+ struct gl_renderbuffer Base;
+ __DRIdrawable *dPriv;
+
+ /* GL_MAP_*_BIT, used for mapping of front buffer. */
+ GLbitfield map_mode;
+ int map_x, map_y, map_w, map_h;
+
+ /* renderbuffer pitch (in bytes) */
+ GLuint pitch;
+ /* bits per pixel of storage */
+ GLuint bpp;
+};
+
+static INLINE struct swrast_renderbuffer *
+swrast_renderbuffer(struct gl_renderbuffer *rb)
+{
+ return (struct swrast_renderbuffer *) rb;
+}
+
+
+/**
+ * Pixel formats we support
+ */
+#define PF_A8R8G8B8 1 /**< 32bpp TrueColor: 8-A, 8-R, 8-G, 8-B bits */
+#define PF_R5G6B5 2 /**< 16bpp TrueColor: 5-R, 6-G, 5-B bits */
+#define PF_R3G3B2 3 /**< 8bpp TrueColor: 3-R, 3-G, 2-B bits */
+#define PF_X8R8G8B8 4 /**< 32bpp TrueColor: 8-R, 8-G, 8-B bits */
+
+
+/* swrast_span.c */
+
+extern void
+swrast_set_span_funcs_back(struct swrast_renderbuffer *xrb,
+ GLuint pixel_format);
+
+extern void
+swrast_set_span_funcs_front(struct swrast_renderbuffer *xrb,
+ GLuint pixel_format);
+
+#endif /* _SWRAST_PRIV_H_ */