Create X11 Pixmap without window

2

To the function

cairo_surface_t * cairo_xlib_surface_create 
(Display *dpy, Drawable drawable, Visual *visual, 
int width, int height);

I need to provide you a Drawtable . I have no interest in the Drawtable being displayed, so I understand that I need the Drawtable to be a Pixmap instead of a Window

The problem is that to create a Pixmap I also need a Drawtable , so it seems that the only way to get a Drawtable is to create a window:

Pixmap XCreatePixmap(display, drawable, width, height, depth)

Is there a way to call the first function ( cairo_xlib_surface_create ) without having created a window?

    
asked by oierlauzi 10.05.2018 в 22:20
source

1 answer

2

According to the Image Surfaces documentation you can render to memory buffers with the functions:

  • cairo_surface_t*    cairo_image_surface_create          (cairo_format_t format,
                                                             int width,
                                                             int height);
    
         

    Create a surface image with the specified format and dimensions. The initial content of the surface is not defined; you should explicitly clean the buffer using, for example, cairo_rectangle() and cairo_fill() if you want to clean it up.

         
    • format : format of the pixels of the surface to be created.
    •   
    • width : width of the surface, in pixels.
    •   
    • height : height of the surface, in pixels.
    •   
    • Return : a pointer to the newly created surface. The caller is the owner of the surface and should call cairo_surface_destroy when he does not need it anymore. This function always returns a valid pointer, but will return a pointer to a null surface ( "nil" ) if an error such as insufficient memory occurs. You can use cairo_surface_status() .
    •   
  • cairo_surface_t*    cairo_image_surface_create_for_data (unsigned char *data,
                                                             cairo_format_t format,
                                                             int width,
                                                             int height,
                                                             int stride);
    
         

    Create a surface image with the pixel data provided. The resulting buffer must be kept until cairo_surface_t be destroyed or be called cairo_surface_finish() on the surface. The initial contents of the buffer will be used as the initial content of the image; you should explicitly clean the buffer using, for example, cairo_rectangle() and cairo_fill() if you want to clean it up.

         
    • data : a pointer to a surface provided by the application in which to write data.
    •   
    • format : format of the pixels in the buffer.
    •   
    • width : width of the surface, in pixels.
    •   
    • height : height of the surface, in pixels.
    •   
    • stride : number of bytes between the start of the rows in the buffer. Having this data separated from the width allows you to add a padding to the end of the rows, or to write a sub-portion of a larger image.
    •   
    • Return : a pointer to the newly created surface. The caller is the owner of the surface and should call cairo_surface_destroy when he does not need it anymore. This function always returns a valid pointer, but will return a pointer to a null surface ( "nil" ) if an error such as insufficient memory occurs. You can use cairo_surface_status() .
    •   
  • Both options allow rendering in memory instead of in a window and do not have dependency on Drawable , the second option even allows to provide a buffer on which to write.

        
    answered by 11.05.2018 в 08:05