+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 dri_swrast_renderbuffer *xrb = dri_swrast_renderbuffer(rb);
+ GLubyte *map = xrb->Base.Buffer;
+ int cpp = _mesa_get_format_bytes(rb->Format);
+ int stride = rb->Width * 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;
+ xrb->Base.Buffer = malloc(h * stride);
+
+ sPriv->swrast_loader->getImage(dPriv, x, y, w, h,
+ (char *) xrb->Base.Buffer,
+ dPriv->loaderPrivate);
+
+ *out_map = xrb->Base.Buffer;
+ *out_stride = stride;
+ return;
+ }
+
+ ASSERT(xrb->Base.Buffer);
+
+ if (rb->AllocStorage == swrast_alloc_back_storage) {
+ map += (rb->Height - 1) * stride;
+ stride = -stride;
+ }
+
+ map += (GLsizei)y * stride;
+ map += (GLsizei)x * cpp;
+
+ *out_map = map;
+ *out_stride = stride;
+}
+
+static void
+swrast_unmap_renderbuffer(struct gl_context *ctx,
+ struct gl_renderbuffer *rb)
+{
+ struct dri_swrast_renderbuffer *xrb = dri_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,
+ (char *) xrb->Base.Buffer,
+ dPriv->loaderPrivate);
+ }
+
+ free(xrb->Base.Buffer);
+ xrb->Base.Buffer = NULL;
+ }
+}
+