Beispiel #1
0
static xcb_cursor_t create_empty_cursor(xcb_connection_t *conn, xcb_screen_t *screen) {
    xcb_cursor_t cursor = xcb_generate_id(conn);
    xcb_pixmap_t pixmap = xcb_generate_id(conn);
    xcb_create_pixmap_checked(conn, 1, pixmap, screen->root, 1, 1);
    xcb_create_cursor(conn, cursor, pixmap, pixmap, 0, 0, 0, 0, 0, 0, 0, 0);
    return cursor;
}
Beispiel #2
0
/* Test each depth not explicitly advertised to see if pixmap creation
 * succeeds: if it does, that depth is usable. */
static int
pixmap_depths_usable (xcb_connection_t *c, uint32_t missing, xcb_pixmap_t pixmap, xcb_drawable_t root)
{
    xcb_void_cookie_t create_cookie[32] = { { 0 } };
    xcb_void_cookie_t free_cookie[32]   = { { 0 } };
    int d;
    int success = 1;
    for (d = 1; d <= 32; d++)
	if (missing & DEPTH_MASK(d))
	{
	    create_cookie[d - 1] = xcb_create_pixmap_checked (c, d, pixmap, root, 1, 1);
	    free_cookie[d - 1] = xcb_free_pixmap_checked (c, pixmap);
	    if (!create_cookie[d - 1].sequence || !free_cookie[d - 1].sequence)
	    {
		success = 0;
		break;
	    }
	}
    for (d = 0; d < 32; d++)
	if (create_cookie[d].sequence || free_cookie[d].sequence)
	{
	    xcb_generic_error_t *create_error = xcb_request_check (c, create_cookie[d]);
	    xcb_generic_error_t *free_error = xcb_request_check (c, free_cookie[d]);
	    success = success && !create_error;
	    free(create_error);
	    free(free_error);
	}
    return success;
}
Beispiel #3
0
static cairo_surface_t *
create_source_surface (int size)
{
#if CAIRO_HAS_XCB_SURFACE
    xcb_render_pictforminfo_t *render_format;
    struct closure *data;
    cairo_surface_t *surface;
    xcb_screen_t *root;
    xcb_void_cookie_t cookie;
    void *formats;

    data = xmalloc (sizeof (struct closure));

    data->connection = xcb_connect (NULL, NULL);
    render_format = find_depth (data->connection, 32, &formats);
    if (render_format == NULL) {
	xcb_disconnect (data->connection);
	free (data);
	return NULL;
    }

    root = xcb_setup_roots_iterator (xcb_get_setup (data->connection)).data;

    data->pixmap = xcb_generate_id (data->connection);
    cookie = xcb_create_pixmap_checked (data->connection, 32,
					data->pixmap, root->root, size, size);
    /* slow, but sure */
    if (xcb_request_check (data->connection, cookie) != NULL) {
	free (formats);
	xcb_disconnect (data->connection);
	free (data);
	return NULL;
    }

    surface = cairo_xcb_surface_create_with_xrender_format (data->connection,
							    root,
							    data->pixmap,
							    render_format,
							    size, size);
    free (formats);

    data->device = cairo_device_reference (cairo_surface_get_device (surface));
    cairo_surface_set_user_data (surface, &closure_key, data, cleanup);

    return surface;
#else
    return NULL;
#endif
}
static cairo_surface_t *
_cairo_boilerplate_xcb_create_surface (const char		 *name,
				       cairo_content_t		  content,
				       double			  width,
				       double			  height,
				       double			  max_width,
				       double			  max_height,
				       cairo_boilerplate_mode_t	  mode,
				       int                        id,
				       void			**closure)
{
    xcb_screen_t *root;
    xcb_target_closure_t *xtc;
    xcb_connection_t *c;
    xcb_render_pictforminfo_t *render_format;
    xcb_pict_standard_t format;
    xcb_void_cookie_t cookie;
    cairo_surface_t *surface;
    cairo_status_t status;

    *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));

    if (width == 0)
	width = 1;
    if (height == 0)
	height = 1;

    xtc->c = c = xcb_connect(NULL,NULL);
    if (xcb_connection_has_error(c)) {
	fprintf (stderr, "Failed to connect to X server through XCB\n");
	return NULL;
    }

    root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

    xtc->pixmap = xcb_generate_id (c);
    switch (content) {
    case CAIRO_CONTENT_COLOR:
	cookie = xcb_create_pixmap_checked (c, 24,
					    xtc->pixmap, root->root,
					    width, height);
	format = XCB_PICT_STANDARD_RGB_24;
	break;

    case CAIRO_CONTENT_COLOR_ALPHA:
	cookie = xcb_create_pixmap_checked (c, 32,
					    xtc->pixmap, root->root,
					    width, height);
	format = XCB_PICT_STANDARD_ARGB_32;
	break;

    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
    default:
	fprintf (stderr, "Invalid content for XCB test: %d\n", content);
	return NULL;
    }

    /* slow, but sure */
    if (xcb_request_check (c, cookie) != NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    render_format = xcb_render_util_find_standard_format (xcb_render_util_query_formats (c), format);
    if (render_format->id == 0)
	return NULL;

    surface = cairo_xcb_surface_create_with_xrender_format (c, xtc->pixmap, root,
							    render_format,
							    width, height);

    status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
    if (status == CAIRO_STATUS_SUCCESS)
	return surface;

    cairo_surface_destroy (surface);
    surface = cairo_boilerplate_surface_create_in_error (status);

    _cairo_boilerplate_xcb_cleanup (xtc);

    return surface;
}
Beispiel #5
0
static cairo_surface_t *
_cairo_boilerplate_xcb_create_render_0_0 (const char		    *name,
					  cairo_content_t	     content,
					  double		     width,
					  double		     height,
					  double		     max_width,
					  double		     max_height,
					  cairo_boilerplate_mode_t   mode,
					  int			     id,
					  void			   **closure)
{
    xcb_screen_t *root;
    xcb_target_closure_t *xtc;
    xcb_connection_t *c;
    xcb_render_pictforminfo_t *render_format;
    int depth;
    xcb_void_cookie_t cookie;
    cairo_surface_t *surface, *tmp;
    cairo_status_t status;
    void *formats;

    *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));

    if (width == 0)
	width = 1;
    if (height == 0)
	height = 1;

    xtc->c = c = xcb_connect(NULL,NULL);
    if (xcb_connection_has_error(c)) {
	free (xtc);
	return NULL;
    }

    root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

    xtc->surface = NULL;
    xtc->is_pixmap = TRUE;
    xtc->drawable = xcb_generate_id (c);
    switch (content) {
    case CAIRO_CONTENT_COLOR:
	depth = 24;
	cookie = xcb_create_pixmap_checked (c, depth,
					    xtc->drawable, root->root,
					    width, height);
	break;

    case CAIRO_CONTENT_COLOR_ALPHA:
	depth = 32;
	cookie = xcb_create_pixmap_checked (c, depth,
					    xtc->drawable, root->root,
					    width, height);
	break;

    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
    default:
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    /* slow, but sure */
    if (xcb_request_check (c, cookie) != NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    render_format = find_depth (c, depth, &formats);
    if (render_format == NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    tmp = cairo_xcb_surface_create_with_xrender_format (c, root,
							xtc->drawable,
							render_format,
							width, height);
    if (cairo_surface_status (tmp)) {
	free (formats);
	xcb_disconnect (c);
	free (xtc);
	return tmp;
    }

    xtc->device = cairo_device_reference (cairo_surface_get_device (tmp));
    cairo_xcb_device_debug_cap_xrender_version (xtc->device, 0, 0);

    /* recreate with impaired connection */
    surface = cairo_xcb_surface_create_with_xrender_format (c, root,
							    xtc->drawable,
							    render_format,
							    width, height);
    free (formats);
    cairo_surface_destroy (tmp);

    assert (cairo_surface_get_device (surface) == xtc->device);

    status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
    if (status == CAIRO_STATUS_SUCCESS)
	return surface;

    cairo_surface_destroy (surface);

    _cairo_boilerplate_xcb_cleanup (xtc);
    return cairo_boilerplate_surface_create_in_error (status);
}
Beispiel #6
0
xcbosd *xcbosd_create(xine_t *xine, xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window, enum xcbosd_mode mode)
{
  xcbosd *osd;

  xcb_get_geometry_cookie_t get_geometry_cookie;
  xcb_get_geometry_reply_t *get_geometry_reply;

  xcb_void_cookie_t generic_cookie;
  xcb_generic_error_t *generic_error;

  osd = calloc(1, sizeof(xcbosd));
  if (!osd)
    return NULL;

  osd->mode = mode;
  osd->xine = xine;
  osd->connection = connection;
  osd->screen = screen;
  osd->window = window;

  osd->visual = osd->screen->root_visual;

  get_geometry_cookie = xcb_get_geometry(osd->connection, osd->window);
  get_geometry_reply = xcb_get_geometry_reply(osd->connection, get_geometry_cookie, NULL);
  osd->depth = get_geometry_reply->depth;
  osd->width = get_geometry_reply->width;
  osd->height = get_geometry_reply->height;
  free(get_geometry_reply);

  assert(osd->width);
  assert(osd->height);

  switch (mode) {
    case XCBOSD_SHAPED: {
      const xcb_query_extension_reply_t *query_extension_reply = xcb_get_extension_data(osd->connection, &xcb_shape_id);

      if (!query_extension_reply || !query_extension_reply->present) {
	xprintf(osd->xine, XINE_VERBOSITY_LOG, _("x11osd: XShape extension not available. unscaled overlay disabled.\n"));
	goto error2;
      }

      unsigned int window_params[] = { osd->screen->black_pixel, 1, XCB_EVENT_MASK_EXPOSURE };
      osd->u.shaped.window = xcb_generate_id(osd->connection);
      generic_cookie = xcb_create_window_checked(osd->connection, XCB_COPY_FROM_PARENT, osd->u.shaped.window,
			osd->window, 0, 0, osd->width, osd->height, 0, XCB_COPY_FROM_PARENT,
			XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
			window_params);
      generic_error = xcb_request_check(osd->connection, generic_cookie);

      if (generic_error != NULL) {
	xprintf(osd->xine, XINE_VERBOSITY_LOG, _("x11osd: error creating window. unscaled overlay disabled.\n"));
	free(generic_error);
	goto error_window;
      }

      osd->u.shaped.mask_bitmap = xcb_generate_id(osd->connection);
      generic_cookie = xcb_create_pixmap_checked(osd->connection, 1, osd->u.shaped.mask_bitmap, osd->u.shaped.window, osd->width, osd->height);
      generic_error = xcb_request_check(osd->connection, generic_cookie);

      if (generic_error != NULL) {
	xprintf(osd->xine, XINE_VERBOSITY_LOG, _("x11osd: error creating pixmap. unscaled overlay disabled.\n"));
	free(generic_error);
	goto error_aftermaskbitmap;
      }

      osd->bitmap = xcb_generate_id(osd->connection);
      xcb_create_pixmap(osd->connection, osd->depth, osd->bitmap, osd->u.shaped.window, osd->width, osd->height);
      osd->gc = xcb_generate_id(osd->connection);
      xcb_create_gc(osd->connection, osd->gc, osd->u.shaped.window, 0, NULL);

      osd->u.shaped.mask_gc = xcb_generate_id(osd->connection);
      xcb_create_gc(osd->connection, osd->u.shaped.mask_gc, osd->u.shaped.mask_bitmap, XCB_GC_FOREGROUND, &osd->screen->white_pixel);

      osd->u.shaped.mask_gc_back = xcb_generate_id(osd->connection);
      xcb_create_gc(osd->connection, osd->u.shaped.mask_gc_back, osd->u.shaped.mask_bitmap, XCB_GC_FOREGROUND, &osd->screen->black_pixel);

      osd->u.shaped.mapped = 0;
      osd->cmap = xcb_generate_id(osd->connection);
      xcb_create_colormap(osd->connection, XCB_COLORMAP_ALLOC_NONE, osd->cmap, osd->u.shaped.window, osd->visual);
      break;
      }
    case XCBOSD_COLORKEY:
      osd->bitmap = xcb_generate_id(osd->connection);
      xcb_create_pixmap(osd->connection, osd->depth, osd->bitmap, osd->window, osd->width, osd->height);
      osd->gc = xcb_generate_id(osd->connection);
      xcb_create_gc(osd->connection, osd->gc, osd->window, 0, NULL);
      osd->cmap = xcb_generate_id(osd->connection);
      xcb_create_colormap(osd->connection, XCB_COLORMAP_ALLOC_NONE, osd->cmap, osd->window, osd->visual);
      /* FIXME: the expose event doesn't seem to happen? */
      /*XSelectInput (osd->display, osd->window, ExposureMask);*/
      break;
    default:
      goto error2;
  }

  osd->clean = UNDEFINED;
  xcbosd_expose(osd);

  xprintf(osd->xine, XINE_VERBOSITY_DEBUG,
    _("x11osd: unscaled overlay created (%s mode).\n"),
    (mode==XCBOSD_SHAPED) ? "XShape" : "Colorkey" );

  return osd;

/*
  XFreeGC (osd->display, osd->gc);
  XFreeGC (osd->display, osd->mask_gc);
  XFreeGC (osd->display, osd->mask_gc_back);
*/

error_aftermaskbitmap:
  if(mode==XCBOSD_SHAPED)
    xcb_free_pixmap(osd->connection, osd->u.shaped.mask_bitmap);
error_window:
  if(mode==XCBOSD_SHAPED)
    xcb_destroy_window(osd->connection, osd->u.shaped.window);
error2:
  free (osd);
  return NULL;
}
static cairo_surface_t *
_cairo_boilerplate_xcb_create_surface (const char		 *name,
				       cairo_content_t		  content,
				       double			  width,
				       double			  height,
				       double			  max_width,
				       double			  max_height,
				       cairo_boilerplate_mode_t   mode,
				       void			**closure)
{
    xcb_screen_t *root;
    xcb_target_closure_t *xtc;
    xcb_connection_t *c;
    xcb_render_query_pict_formats_cookie_t formats_cookie;
    xcb_render_pictforminfo_t *render_format;
    xcb_render_pictforminfo_iterator_t i;
    struct xcb_info *info;
    int depth;
    xcb_void_cookie_t cookie;
    cairo_surface_t *surface;
    cairo_status_t status;

    *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
    info = xcalloc (1, sizeof (struct xcb_info));

    if (width == 0)
	width = 1;
    if (height == 0)
	height = 1;

    xtc->c = c = xcb_connect(NULL,NULL);
    if (c == NULL || xcb_connection_has_error(c)) {
	free (xtc);
	return NULL;
    }

    root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
    formats_cookie = xcb_render_query_pict_formats (c);

    xtc->surface = NULL;
    xtc->is_pixmap = TRUE;
    xtc->drawable = xcb_generate_id (c);
    switch (content) {
    case CAIRO_CONTENT_COLOR:
	depth = 24;
	break;

    case CAIRO_CONTENT_COLOR_ALPHA:
	depth = 32;
	break;

    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
    default:
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    cookie = xcb_create_pixmap_checked (c, depth,
					xtc->drawable, root->root,
					width, height);

    /* slow, but sure */
    if (xcb_request_check (c, cookie) != NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    info->formats = xcb_render_query_pict_formats_reply (c, formats_cookie, 0);
    if (info->formats == NULL)
	return NULL;

    for (i = xcb_render_query_pict_formats_formats_iterator (info->formats);
	 i.rem;
	 xcb_render_pictforminfo_next (&i))
    {
	if (XCB_RENDER_PICT_TYPE_DIRECT != i.data->type)
	    continue;

	if (i.data->depth == 32) {
		if (info->render_format[0] == 0)
			info->render_format[0] = i.data;
	} else if (i.data->depth == 24) {
		if (info->render_format[1] == 0)
			info->render_format[1] = i.data;
	} else if (i.data->depth == 8) {
		if (info->render_format[2] == 0)
			info->render_format[2] = i.data;
	}
    }

    assert (info->render_format[0]);
    assert (info->render_format[1]);
    assert (info->render_format[2]);

    switch (content) {
    default:
    case CAIRO_CONTENT_COLOR_ALPHA:
	    render_format = info->render_format[0];
	    break;

    case CAIRO_CONTENT_COLOR:
	    render_format = info->render_format[1];
	    break;

    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
	    render_format = info->render_format[2];
	    break;
    }

    surface = cairo_xcb_surface_create_with_xrender_format (c, root,
							    xtc->drawable,
							    render_format,
							    width, height);
    cairo_device_set_user_data (cairo_surface_get_device (surface), &key, info, free);
    if (mode != CAIRO_BOILERPLATE_MODE_PERF)
	_cairo_boilerplate_xcb_setup_test_surface(surface);

    xtc->device = cairo_device_reference (cairo_surface_get_device (surface));
    status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
    if (status == CAIRO_STATUS_SUCCESS)
	return surface;

    cairo_surface_destroy (surface);

    _cairo_boilerplate_xcb_cleanup (xtc);
    return cairo_boilerplate_surface_create_in_error (status);
}