[Mesa-dev] [PATCH] i965: Naive implementation of gbm_bo_map

Ben Widawsky ben at bwidawsk.net
Fri Apr 21 17:17:51 UTC 2017


Could do smarter stuff with the mappings. I decided not to.

Tested with kmscube. No current clients seem to use non-zero x0, y0, so
that's untested.

Cc: Tapani Pälli <tapani.palli at intel.com> (AndroidIA?)
Cc: Emil Velikov <emil.velikov at collabora.com>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 src/mesa/drivers/dri/i965/intel_screen.c | 39 ++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 34a5f18af2..f89de3c9d4 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -926,6 +926,41 @@ intel_from_planar(__DRIimage *parent, int plane, void *loaderPrivate)
     return image;
 }
 
+static void *
+intel_map_image(__DRIcontext *context, __DRIimage *image,
+                 int x0, int y0, int width, int height,
+                 unsigned int flags, int *stride, void **data)
+{
+   if (!image || !data || *data)
+      return NULL;
+
+   /* FIXME: add width/height check */
+
+   brw_bo_reference(image->bo);
+
+   uintptr_t offset =
+      y0 * image->pitch + x0 * _mesa_get_format_bytes(image->format);
+   void *bo_map = brw_bo_map__wc(image->bo);
+
+   if (bo_map) {
+      *data = image->bo;
+      *stride = image->pitch;
+   } else {
+      *data = NULL;
+      *stride = 0;
+      brw_bo_unreference(image->bo);
+   }
+
+   return bo_map + offset;
+}
+
+
+static void
+intel_unmap_image(__DRIcontext *context, __DRIimage *image, void *data)
+{
+   brw_bo_unreference(data);
+}
+
 static const __DRIimageExtension intelImageExtension = {
     .base = { __DRI_IMAGE, 14 },
 
@@ -943,8 +978,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,
 };
 
-- 
2.12.2



More information about the mesa-dev mailing list