[Mesa-dev] [PATCH] i965: implement (un)mapImage

Julien Isorce julien.isorce at gmail.com
Wed Nov 8 16:55:05 UTC 2017


v2: add early return if (flag & MAP_INTERNAL_MASK)

Already implemented for Gallium drivers.

Useful for gbm_bo_(un)map.

Tested by porting wayland/weston/clients/simple-dmabuf-drm.c to GBM.

Signed-off-by: Julien Isorce <jisorce at oblong.com>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 51 ++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index cdc36ad..b7b0e25 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -755,6 +755,53 @@ intel_create_image(__DRIscreen *dri_screen,
                                loaderPrivate);
 }
 
+static void *
+intel_map_image(__DRIcontext *context, __DRIimage *image,
+                int x0, int y0, int width, int height,
+                unsigned int flags, int *stride, void **map_info)
+{
+  struct brw_context *brw = NULL;
+  struct brw_bo *bo = NULL;
+  void *raw_data = NULL;
+
+  if (!context || !image || !stride || !map_info || *map_info)
+     return NULL;
+
+  if (flags & MAP_INTERNAL_MASK)
+     return NULL;
+
+  brw = context->driverPrivate;
+  bo = image->bo;
+
+  assert(brw);
+  assert(bo);
+
+  /* DRI flags and GL_MAP.*_BIT flags are the same, so just pass them on. */
+  raw_data = brw_bo_map(brw, bo, flags);
+
+  if (raw_data) {
+    *map_info = raw_data;
+    *stride = image->pitch;
+  }
+
+  return raw_data;
+}
+
+static void
+intel_unmap_image(__DRIcontext *context, __DRIimage *image, void *map_info)
+{
+   struct brw_bo *bo = NULL;
+
+   if (!context || !image || !map_info)
+      return;
+
+   bo = image->bo;
+
+   assert(bo);
+
+   brw_bo_unmap(bo);
+}
+
 static __DRIimage *
 intel_create_image_with_modifiers(__DRIscreen *dri_screen,
                                   int width, int height, int format,
@@ -1305,8 +1352,8 @@ static const __DRIimageExtension intelImageExtension = {
     .createImageFromDmaBufs             = intel_create_image_from_dma_bufs,
     .blitImage                          = NULL,
     .getCapabilities                    = NULL,
-    .mapImage                           = NULL,
-    .unmapImage                         = NULL,
+    .mapImage                           = intel_map_image,
+    .unmapImage                         = intel_unmap_image,
     .createImageWithModifiers           = intel_create_image_with_modifiers,
     .createImageFromDmaBufs2            = intel_create_image_from_dma_bufs2,
     .queryDmaBufFormats                 = intel_query_dma_buf_formats,
-- 
2.7.4



More information about the mesa-dev mailing list