+
+ /* If we're in a renderonly setup, use the other device to perform our
+ * (linear) allocation and just import it to v3d. The other device
+ * may be using CMA, and V3D can import from CMA but doesn't do CMA
+ * allocations on its own.
+ *
+ * We always allocate this way for SHARED, because get_handle will
+ * need a resource on the display fd.
+ */
+ if (screen->ro && (tmpl->bind & (PIPE_BIND_SCANOUT |
+ PIPE_BIND_SHARED))) {
+ struct winsys_handle handle;
+ struct pipe_resource scanout_tmpl = *tmpl;
+ struct renderonly_scanout *scanout =
+ renderonly_scanout_for_resource(&scanout_tmpl,
+ screen->ro,
+ &handle);
+ if (!scanout) {
+ fprintf(stderr, "Failed to create scanout resource\n");
+ return NULL;
+ }
+ assert(handle.type == WINSYS_HANDLE_TYPE_FD);
+ /* The fd is all we need. Destroy the old scanout (and its
+ * GEM handle on kms_fd) before resource_from_handle()'s
+ * renderonly_create_gpu_import_for_resource() call which will
+ * also get a kms_fd GEM handle for the fd.
+ */
+ renderonly_scanout_destroy(scanout, screen->ro);
+ struct pipe_resource *prsc =
+ pscreen->resource_from_handle(pscreen, tmpl,
+ &handle,
+ PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE);
+ close(handle.handle);
+ return prsc;
+ }
+