- int xy1;
- int xy2;
-
- xy1 = ((int)src->x1 > (int)bbox->x1 + dst_x) ? src->x1 :
- (int)bbox->x1 + dst_x;
- xy2 = ((int)src->x2 < (int)bbox->x2 + dst_x) ? src->x2 :
- (int)bbox->x2 + dst_x;
- if (xy1 >= xy2 || xy1 < 0)
- return FALSE;
-
- dst->x1 = xy1;
- dst->x2 = xy2;
-
- xy1 = ((int)src->y1 > (int)bbox->y1 + dst_y) ? src->y1 :
- (int)bbox->y1 + dst_y;
- xy2 = ((int)src->y2 < (int)bbox->y2 + dst_y) ? src->y2 :
- (int)bbox->y2 + dst_y;
- if (xy1 >= xy2 || xy1 < 0)
- return FALSE;
-
- dst->y1 = xy1;
- dst->y2 = xy2;
- return TRUE;
+ struct vmw_svga_winsys_surface *vsrf;
+ struct svga_winsys_surface *ssrf;
+ struct vmw_winsys_screen *vws = vmw_winsys_screen(sws);
+ SVGA3dSurfaceAllFlags flags;
+ uint32_t mip_levels;
+ struct vmw_buffer_desc desc;
+ struct pb_manager *provider = vws->pools.gmr;
+ struct pb_buffer *pb_buf;
+ uint32_t handle;
+ int ret;
+
+ if (whandle->offset != 0) {
+ fprintf(stderr, "Attempt to import unsupported winsys offset %u\n",
+ whandle->offset);
+ return NULL;
+ }
+
+ ret = vmw_ioctl_gb_surface_ref(vws, whandle, &flags, format,
+ &mip_levels, &handle, &desc.region);
+
+ if (ret) {
+ fprintf(stderr, "Failed referencing shared surface. SID %d.\n"
+ "Error %d (%s).\n",
+ whandle->handle, ret, strerror(-ret));
+ return NULL;
+ }
+
+ if (mip_levels != 1) {
+ fprintf(stderr, "Incorrect number of mipmap levels on shared surface."
+ " SID %d, levels %d\n",
+ whandle->handle, mip_levels);
+ goto out_mip;
+ }
+
+ vsrf = CALLOC_STRUCT(vmw_svga_winsys_surface);
+ if (!vsrf)
+ goto out_mip;
+
+ pipe_reference_init(&vsrf->refcnt, 1);
+ p_atomic_set(&vsrf->validated, 0);
+ vsrf->screen = vws;
+ vsrf->sid = handle;
+ vsrf->size = vmw_region_size(desc.region);
+
+ /*
+ * Synchronize backing buffers of shared surfaces using the
+ * kernel, since we don't pass fence objects around between
+ * processes.
+ */
+ desc.pb_desc.alignment = 4096;
+ desc.pb_desc.usage = VMW_BUFFER_USAGE_SHARED | VMW_BUFFER_USAGE_SYNC;
+ pb_buf = provider->create_buffer(provider, vsrf->size, &desc.pb_desc);
+ vsrf->buf = vmw_svga_winsys_buffer_wrap(pb_buf);
+ if (!vsrf->buf)
+ goto out_no_buf;
+ ssrf = svga_winsys_surface(vsrf);
+
+ return ssrf;
+
+out_no_buf:
+ FREE(vsrf);
+out_mip:
+ vmw_ioctl_region_destroy(desc.region);
+ vmw_ioctl_surface_destroy(vws, whandle->handle);
+ return NULL;