Fix intel drmbuf sandbox/akiofukubayashi/als2019_8.0
authorAkio Fukubayashi <fukubayashi.akio@genetec.co.jp>
Wed, 4 Sep 2019 05:21:10 +0000 (14:21 +0900)
committerAkio Fukubayashi <fukubayashi.akio@genetec.co.jp>
Wed, 4 Sep 2019 05:21:10 +0000 (14:21 +0900)
Signed-off-by: Akio Fukubayashi <fukubayashi.akio@genetec.co.jp>
waltham-transmitter/waltham-renderer/waltham-renderer.c

index 967e419..1259e0f 100644 (file)
@@ -236,7 +236,53 @@ static void waltham_renderer_repaint_output(struct weston_transmitter_output *ou
        allocator = gst_dmabuf_allocator_new();
        mem = gst_dmabuf_allocator_alloc(allocator, output->renderer->dmafd,
                                         stride * output->renderer->surface_height);
+
+#if defined(__x86_64__)
+       /* per-texture constants (Intel X-major tile layout) */
+       uint tileW = 512;       /* 32 * 16B OWord colomns */
+       uint tileH = 8;         /* 8 Rows */
+       uint tilePitch = 8;     /* Pitch = 8tiles */
+       uint tileSize = tileW * tileH;
+       uint widthInTiles = (stride + tileW-1) / tileW;
+
+       /* convert linear format to tile format */
+       GstMapInfo infosrc, infodst;
+       GstMemory *memsrc = gst_memory_copy(mem, 0, stride * output->renderer->surface_height);
+       if (gst_memory_map(memsrc, &infosrc, GST_MAP_READ) == FALSE)
+               return;
+
+       GstMemory *memdst = gst_allocator_alloc(NULL, stride * output->renderer->surface_height, NULL);
+       if (gst_memory_map(memdst, &infodst, GST_MAP_WRITE) == FALSE) {
+               gst_memory_unmap(memsrc, &infosrc);
+               return;
+       }
+
+       int y = 0, x = 0;
+       uint tileX, tileY, inTileX, inTileY, idx;
+       for (y = 0; y < output->renderer->surface_height; y++) {
+               for (x = 0; x < stride; x++) {
+                       // actual addressing
+                       tileX = x / tileW;
+                       tileY = y / tileH;
+                       inTileX = x % tileW;
+                       inTileY = y % tileH;
+                       idx = (tileY * widthInTiles + tileX) * (tileSize)
+                         + (inTileY * tileW) + (inTileX);
+
+                       if (idx >= stride * output->renderer->surface_height) {
+                               fprintf(stderr, "index not in scope: idx=%d x=%d y=%d \n",idx, x, y);
+                               break;
+                       }
+                       infodst.data[y * stride + x] = infosrc.data[idx];
+               }
+       }
+
+       gst_memory_unmap(memsrc, &infosrc);
+       gst_memory_unmap(memdst, &infodst);
+       gst_buffer_append_memory(gstbuffer, memdst);
+#else
        gst_buffer_append_memory(gstbuffer, mem);
+#endif
        gst_buffer_add_video_meta_full(gstbuffer,
                                       GST_VIDEO_FRAME_FLAG_NONE,
                                       GST_VIDEO_FORMAT_BGRx,
@@ -248,6 +294,11 @@ static void waltham_renderer_repaint_output(struct weston_transmitter_output *ou
 
        gst_app_src_push_buffer(output->renderer->ctx->appsrc, gstbuffer);
        gst_object_unref(allocator);
+
+#if defined(__x86_64__)
+        gst_memory_unref(memsrc);
+        gst_memory_unref(mem);
+#endif
 }
 
 static int