[Mesa-dev] [PATCH 03/24] intel: Add an implementation of MapRenderbuffer.

Eric Anholt eric at anholt.net
Fri Oct 28 12:49:53 PDT 2011


---
 src/mesa/drivers/dri/intel/intel_fbo.c |   55 ++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_fbo.c b/src/mesa/drivers/dri/intel/intel_fbo.c
index 4537f1f..c9a1df5 100644
--- a/src/mesa/drivers/dri/intel/intel_fbo.c
+++ b/src/mesa/drivers/dri/intel/intel_fbo.c
@@ -83,6 +83,59 @@ intel_delete_renderbuffer(struct gl_renderbuffer *rb)
    free(irb);
 }
 
+static void
+intel_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 intel_context *intel = intel_context(ctx);
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+   GLubyte *map;
+   int stride;
+
+   /* We sometimes get called with this by our intel_span.c usage. */
+   if (!irb->region) {
+      *out_map = NULL;
+      *out_stride = 0;
+      return;
+   }
+
+   if (drm_intel_bo_references(intel->batch.bo, irb->region->bo)) {
+      intel_batchbuffer_flush(intel);
+   }
+
+   drm_intel_gem_bo_map_gtt(irb->region->bo);
+
+   map = irb->region->bo->virtual;
+   stride = irb->region->pitch * irb->region->cpp;
+
+   if (rb->Name == 0) {
+      map += stride * (irb->region->height - 1);
+      stride = -stride;
+   } else {
+      map += irb->draw_x * irb->region->cpp;
+      map += (int)irb->draw_y * stride;
+   }
+
+   map += x * irb->region->cpp;
+   map += (int)y * stride;
+
+   *out_map = map;
+   *out_stride = stride;
+}
+
+static void
+intel_unmap_renderbuffer(struct gl_context *ctx,
+			 struct gl_renderbuffer *rb)
+{
+   struct intel_renderbuffer *irb = intel_renderbuffer(rb);
+
+   if (irb->region)
+      drm_intel_gem_bo_unmap_gtt(irb->region->bo);
+}
 
 /**
  * Return a pointer to a specific pixel in a renderbuffer.
@@ -938,6 +991,8 @@ intel_fbo_init(struct intel_context *intel)
 {
    intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer;
    intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer;
+   intel->ctx.Driver.MapRenderbuffer = intel_map_renderbuffer;
+   intel->ctx.Driver.UnmapRenderbuffer = intel_unmap_renderbuffer;
    intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer;
    intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer;
    intel->ctx.Driver.RenderTexture = intel_render_texture;
-- 
1.7.7



More information about the mesa-dev mailing list