Exemplo n.º 1
0
static void
swrastDestroyDrawable(struct dri2_egl_display * dri2_dpy,
                      struct dri2_egl_surface * dri2_surf)
{
   xcb_free_gc(dri2_dpy->conn, dri2_surf->gc);
   xcb_free_gc(dri2_dpy->conn, dri2_surf->swapgc);
}
Exemplo n.º 2
0
void X11WindowedBackend::createCursor(const QImage &img, const QPoint &hotspot)
{
    const xcb_pixmap_t pix = xcb_generate_id(m_connection);
    const xcb_gcontext_t gc = xcb_generate_id(m_connection);
    const xcb_cursor_t cid = xcb_generate_id(m_connection);

    xcb_create_pixmap(m_connection, 32, pix, m_screen->root, img.width(), img.height());
    xcb_create_gc(m_connection, gc, pix, 0, nullptr);

    xcb_put_image(m_connection, XCB_IMAGE_FORMAT_Z_PIXMAP, pix, gc, img.width(), img.height(), 0, 0, 0, 32, img.byteCount(), img.constBits());

    XRenderPicture pic(pix, 32);
    xcb_render_create_cursor(m_connection, cid, pic, hotspot.x(), hotspot.y());
    for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) {
        xcb_change_window_attributes(m_connection, (*it).window, XCB_CW_CURSOR, &cid);
    }

    xcb_free_pixmap(m_connection, pix);
    xcb_free_gc(m_connection, gc);
    if (m_cursor) {
        xcb_free_cursor(m_connection, m_cursor);
    }
    m_cursor = cid;
    xcb_flush(m_connection);
    markCursorAsRendered();
}
Exemplo n.º 3
0
void VlcWindowlessXCB::drawBackground(xcb_drawable_t drawable)
{
    /* Obtain the background color */
    xcb_colormap_t colormap = m_screen->default_colormap;
    unsigned r = 0, g = 0, b = 0;
    HTMLColor2RGB(get_options().get_bg_color().c_str(), &r, &g, &b);
    xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(m_conn,
            xcb_alloc_color(m_conn, colormap,
                            (uint16_t) r << 8,
                            (uint16_t) g << 8,
                            (uint16_t) b << 8), NULL);
    uint32_t colorpixel = reply->pixel;
    free(reply);

    /* Prepare to fill the background */
    xcb_gcontext_t background = xcb_generate_id(m_conn);
    uint32_t        mask       = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
    uint32_t        values[2]  = {colorpixel, 0};
    xcb_create_gc(m_conn, background, drawable, mask, values);
    xcb_rectangle_t rect;
    rect.x = 0;
    rect.y = 0;
    rect.width = npwindow.width;
    rect.height = npwindow.height;

    /* Fill the background */
    xcb_poly_fill_rectangle(m_conn, drawable, background, 1, &rect);
    xcb_free_gc(m_conn, background);
}
Exemplo n.º 4
0
void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source)
{
    Q_XCB_NOOP(connection());
    if (m_gc_window != window) {
        if (m_gc)
            Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));

        m_gc = xcb_generate_id(xcb_connection());
        Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0));

        m_gc_window = window;
    }

    Q_XCB_NOOP(connection());
    xcb_image_shm_put(xcb_connection(),
                      window,
                      m_gc,
                      m_xcb_image,
                      m_shm_info,
                      source.x(),
                      source.y(),
                      target.x(),
                      target.y(),
                      source.width(),
                      source.height(),
                      false);
    Q_XCB_NOOP(connection());

    m_dirty = m_dirty | source;

    xcb_flush(xcb_connection());
    Q_XCB_NOOP(connection());
}
Exemplo n.º 5
0
Arquivo: dri3.c Projeto: sarnex/wine
BOOL
PRESENTHelperCopyFront(Display *dpy, PRESENTPixmapPriv *present_pixmap_priv)
{
    PRESENTpriv *present_priv = present_pixmap_priv->present_priv;
    xcb_void_cookie_t cookie;
    xcb_generic_error_t *error;

    uint32_t v = 0;
    xcb_gcontext_t gc;

    pthread_mutex_lock(&present_priv->mutex_present);

    if (!present_priv->window) {
        pthread_mutex_unlock(&present_priv->mutex_present);
        return FALSE;
    }

    xcb_create_gc(present_priv->xcb_connection,
                  (gc = xcb_generate_id(present_priv->xcb_connection)),
                  present_priv->window,
                  XCB_GC_GRAPHICS_EXPOSURES,
                  &v);
    cookie = xcb_copy_area_checked(present_priv->xcb_connection,
                                   present_priv->window,
                                   present_pixmap_priv->pixmap,
                                   gc,
                                   0, 0, 0, 0,
                                   present_pixmap_priv->width,
                                   present_pixmap_priv->height);
    error = xcb_request_check(present_priv->xcb_connection, cookie);
    xcb_free_gc(present_priv->xcb_connection, gc);
    pthread_mutex_unlock(&present_priv->mutex_present);
    return (error != NULL);
}
Exemplo n.º 6
0
void
x_client_icon::update_default_icon(void)
{
  xcb_free_pixmap(m_c(), m_default_icon);
  m_default_icon = XCB_NONE;

  const uint32_t width = default_application_icon.width;
  const uint32_t height = default_application_icon.width;

  m_icon_geometry.first = width;
  m_icon_geometry.second = height;

  m_default_icon = xcb_generate_id(m_c());
  xcb_create_pixmap(
      m_c(), 32, m_default_icon, m_c.root_window(), width, height);

  xcb_image_t * image = xcb_image_create_native(
      m_c(), width, height, XCB_IMAGE_FORMAT_Z_PIXMAP, 32, NULL, 0, NULL);

  image->data = (uint8_t *)default_application_icon.pixel_data;;

  xcb_gcontext_t gc = xcb_generate_id(m_c());
  xcb_create_gc(m_c(), gc, m_default_icon, 0, NULL);

  xcb_image_put(m_c(), m_default_icon, gc, image, 0, 0, 0);

  xcb_image_destroy(image);
  xcb_free_gc(m_c(), gc);
}
void
_cairo_xcb_connection_free_gc (cairo_xcb_connection_t *connection,
			       xcb_gcontext_t gc)
{
    xcb_free_gc (connection->xcb_connection, gc);
    _cairo_xcb_connection_put_xid (connection, gc);
}
Exemplo n.º 8
0
static EGLBoolean
dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
		  EGLNativePixmapType native_target)
{
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
   struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
   xcb_gcontext_t gc;
   xcb_pixmap_t target = (uintptr_t )native_target;

   (void) drv;

   (*dri2_dpy->flush->flush)(dri2_surf->dri_drawable);

   gc = xcb_generate_id(dri2_dpy->conn);
   xcb_create_gc(dri2_dpy->conn, gc, target, 0, NULL);
   xcb_copy_area(dri2_dpy->conn,
		  dri2_surf->drawable,
		  target,
		  gc,
		  0, 0,
		  0, 0,
		  dri2_surf->base.Width,
		  dri2_surf->base.Height);
   xcb_free_gc(dri2_dpy->conn, gc);

   return EGL_TRUE;
}
Exemplo n.º 9
0
void xcbosd_destroy(xcbosd *osd)
{

  assert (osd);

  xcb_free_gc(osd->connection, osd->gc);
  xcb_free_pixmap(osd->connection, osd->bitmap);
  xcb_free_colormap(osd->connection, osd->cmap);
  if(osd->mode==XCBOSD_SHAPED) {
    xcb_free_gc(osd->connection, osd->u.shaped.mask_gc);
    xcb_free_gc(osd->connection, osd->u.shaped.mask_gc_back);
    xcb_free_pixmap(osd->connection, osd->u.shaped.mask_bitmap);
    xcb_destroy_window(osd->connection, osd->u.shaped.window);
  }

  free (osd);
}
Exemplo n.º 10
0
void
x_client_icon::update_net_wm_icon(void)
{
  xcb_free_pixmap(m_c(), m_net_wm_icon);
  m_net_wm_icon = XCB_NONE;

  xcb_generic_error_t * error;
  xcb_get_property_cookie_t c =
    xcb_ewmh_get_wm_icon(m_c.ewmh(), m_x_client.window());

  xcb_ewmh_get_wm_icon_reply_t wm_icon;
  std::memset(&wm_icon, 0, sizeof(xcb_ewmh_get_wm_icon_reply_t));
  xcb_ewmh_get_wm_icon_reply(m_c.ewmh(), c, &wm_icon, &error);

  if (error) {
    std::free(error);

  } else if (0 < xcb_ewmh_get_wm_icon_length(&wm_icon)) {

    uint32_t width = 0;
    uint32_t height = 0;
    uint32_t * data = NULL;

    xcb_ewmh_wm_icon_iterator_t iter = xcb_ewmh_get_wm_icon_iterator(&wm_icon);
    for (; iter.rem; xcb_ewmh_get_wm_icon_next(&iter)) {
      if (iter.width > width) {
        width = iter.width;
        height = iter.height;
        data = iter.data;
      }
    }

    m_icon_geometry.first = width;
    m_icon_geometry.second = height;

    m_net_wm_icon = xcb_generate_id(m_c());
    xcb_create_pixmap(
        m_c(), 32, m_net_wm_icon, m_c.root_window(), width, height);

    xcb_image_t * image = xcb_image_create_native(
        m_c(), width, height, XCB_IMAGE_FORMAT_Z_PIXMAP, 32, NULL, 0, NULL);

    image->data = (uint8_t *)data;

    alpha_transform(image->data, width, height);

    xcb_gcontext_t gc = xcb_generate_id(m_c());
    xcb_create_gc(m_c(), gc, m_net_wm_icon, 0, NULL);

    xcb_image_put(m_c(), m_net_wm_icon, gc, image, 0, 0, 0);

    xcb_image_destroy(image);
    xcb_free_gc(m_c(), gc);

    xcb_ewmh_get_wm_icon_reply_wipe(&wm_icon);
  }
}
Exemplo n.º 11
0
void QXcbShmImage::destroy()
{
    Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg));
    xcb_image_destroy(m_xcb_image);
    shmdt(m_shm_info.shmaddr);
    shmctl(m_shm_info.shmid, IPC_RMID, 0);
    if (m_gc)
        Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
}
Exemplo n.º 12
0
void 
evas_software_xcb_outbuf_free(Outbuf *buf) 
{
   while (buf->priv.pending_writes) 
     {
        RGBA_Image *im = NULL;
        Outbuf_Region *obr = NULL;

        im = buf->priv.pending_writes->data;
        buf->priv.pending_writes = 
          eina_list_remove_list(buf->priv.pending_writes, 
                                buf->priv.pending_writes);
        obr = im->extended_info;
#ifdef EVAS_CSERVE2
        if (evas_cserve2_use_get())
          evas_cache2_image_close(&im->cache_entry);
        else
#endif
          evas_cache_image_drop(&im->cache_entry);

        if (obr->xcbob) _unfind_xcbob(obr->xcbob, EINA_FALSE);
        if (obr->mask) _unfind_xcbob(obr->mask, EINA_FALSE);
        free(obr);
     }

   evas_software_xcb_outbuf_idle_flush(buf);
   evas_software_xcb_outbuf_flush(buf, NULL, MODE_FULL);

   if (buf->priv.x11.xcb.gc)
     xcb_free_gc(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.gc);
   if (buf->priv.x11.xcb.gcm)
     xcb_free_gc(buf->priv.x11.xcb.conn, buf->priv.x11.xcb.gcm);
   if (buf->priv.pal)
     evas_software_xcb_color_deallocate(buf->priv.x11.xcb.conn, 
                                        buf->priv.x11.xcb.cmap, 
                                        buf->priv.x11.xcb.visual, 
                                        buf->priv.pal);

   eina_array_flush(&buf->priv.onebuf_regions);

   free(buf);
   _clear_xcbob(EINA_FALSE);
}
Exemplo n.º 13
0
/*
 * Destroys the surface.
 *
 */
void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface) {
    xcb_free_gc(conn, surface->gc);
    cairo_surface_destroy(surface->surface);
    cairo_destroy(surface->cr);

    /* We need to explicitly set these to NULL to avoid assertion errors in
     * cairo when calling this multiple times. This can happen, for example,
     * when setting the border of a window to none and then closing it. */
    surface->surface = NULL;
    surface->cr = NULL;
}
Exemplo n.º 14
0
bool VlcWindowlessXCB::handle_event(void *event)
{
    XEvent *xevent = static_cast<XEvent *>(event);
    switch (xevent->type) {
    case GraphicsExpose:

        xcb_gcontext_t gc;
        xcb_void_cookie_t cookie;
        xcb_generic_error_t *err;
        XGraphicsExposeEvent *xgeevent = reinterpret_cast<XGraphicsExposeEvent *>(xevent);

        /* Something went wrong during initialization */
        if (!m_conn || !m_screen)
            break;

        drawBackground(xgeevent->drawable);

        /* Validate video size */
        if (m_media_width == 0 || m_media_height == 0)
            break;

        /* Compute the position of the video */
        int left = (npwindow.width  - m_media_width)  / 2;
        int top  = (npwindow.height - m_media_height) / 2;

        gc = xcb_generate_id(m_conn);
        xcb_create_gc(m_conn, gc, xgeevent->drawable, 0, NULL);

        /* Push the frame in X11 */
        cookie = xcb_put_image_checked(
                    m_conn,
                    XCB_IMAGE_FORMAT_Z_PIXMAP,
                    xgeevent->drawable,
                    gc,
                    m_media_width,
                    m_media_height,
                    left, top,
                    0, 24,
                    m_media_width * m_media_height * 4,
                    (const uint8_t *)&m_frame_buf[0]);

        if (err = xcb_request_check(m_conn, cookie))
        {
            fprintf(stderr, "Unable to put picture into drawable. Error %d\n",
                            err->error_code);
            free(err);
        }

        /* Flush the the connection */
        xcb_flush(m_conn);
        xcb_free_gc(m_conn, gc);
    }
    return VlcWindowlessBase::handle_event(event);
}
Exemplo n.º 15
0
void render_text(xcb_connection_t *dpy, xcb_window_t win, int16_t x, int16_t y)
{
	char id[10];
	xcb_void_cookie_t ck;
	snprintf(id, sizeof(id), "0x%X", win);
	xcb_gcontext_t gc = get_font_gc(dpy, win, "-*-fixed-medium-*-*-*-18-*-*-*-*-*-*-*");
	/* Doesn't work without _checked */
	ck = xcb_image_text_8_checked(dpy, strlen(id), win, gc, x, y, id);
	check_request(dpy, ck, "Can't draw text");
	xcb_free_gc(dpy, gc);
}
Exemplo n.º 16
0
X11BufferSurface::~X11BufferSurface()
{
	if(active_) warning("ny::~X11BufferSurface: there is still an active BufferGuard");
	if(gc_) xcb_free_gc(&xConnection(), gc_);

	if(shmseg_)
	{
		xcb_shm_detach(&xConnection(), shmseg_);
		shmdt(data_);
		shmctl(shmid_, IPC_RMID, 0);
	}
}
Exemplo n.º 17
0
void drawButton (xcb_connection_t *connection,
                 xcb_screen_t     *screen,
                 xcb_window_t      window,
                 int16_t           x1,
                 int16_t           y1,
                 const char       *label )
{
    uint8_t length = strlen (label);
    int16_t inset = 2;
    int16_t width = 7 * length + 2 * (inset + 1);
    int16_t height = 13 + 2 * (inset + 1);

    xcb_point_t points[5];
    points[0].x = x1;
    points[0].y = y1;
    points[1].x = x1 + width;
    points[1].y = y1;
    points[2].x = x1 + width;
    points[2].y = y1 - height;
    points[3].x = x1;
    points[3].y = y1 - height;
    points[4].x = x1;
    points[4].y = y1;



    xcb_colormap_t      colors[2];
    colors[0]=screen->black_pixel;
    colors[1]=screen->white_pixel;
    xcb_gcontext_t gc = getFontGC2 (connection, screen, window,colors, "7x13");
    uint32_t		gcv[1]= {screen->black_pixel};
    xcb_change_gc(connection,gc, XCB_GC_FOREGROUND, gcv);
    xcb_void_cookie_t lineCookie = xcb_poly_line_checked (connection,
                                   XCB_COORD_MODE_ORIGIN,
                                   window,
                                   gc,
                                   5,
                                   points );
    testCookie (lineCookie, connection, "can't draw lines");

    xcb_void_cookie_t textCookie = xcb_image_text_8_checked (connection,
                                   length,
                                   window,
                                   gc,
                                   x1 + inset + 1,
                                   y1 - inset - 1,
                                   label );
    testCookie (textCookie, connection, "can't paste text");

    xcb_void_cookie_t gcCookie = xcb_free_gc (connection, gc);
    testCookie (gcCookie, connection, "can't free gc");
};
Exemplo n.º 18
0
static void
_e_alert_shutdown(void)
{
   if (!xcb_connection_has_error(conn))
     {
        xcb_close_font(conn, font);
        xcb_destroy_window(conn, btn1);
        xcb_destroy_window(conn, btn2);
        xcb_destroy_window(conn, win);
        if (comp_win) xcb_destroy_window(conn, comp_win);
        xcb_free_gc(conn, gc);
        xcb_disconnect(conn);
     }
}
Exemplo n.º 19
0
Arquivo: xcb.c Projeto: eplanet/i3lock
xcb_pixmap_t create_bg_pixmap(xcb_connection_t *conn, xcb_screen_t *scr, u_int32_t *resolution, char *color) {
    xcb_pixmap_t bg_pixmap = xcb_generate_id(conn);
    xcb_create_pixmap(conn, scr->root_depth, bg_pixmap, scr->root,
                      resolution[0], resolution[1]);

    /* Generate a Graphics Context and fill the pixmap with background color
     * (for images that are smaller than your screen) */
    xcb_gcontext_t gc = xcb_generate_id(conn);
    uint32_t values[] = {get_colorpixel(color)};
    xcb_create_gc(conn, gc, bg_pixmap, XCB_GC_FOREGROUND, values);
    xcb_rectangle_t rect = {0, 0, resolution[0], resolution[1]};
    xcb_poly_fill_rectangle(conn, bg_pixmap, gc, 1, &rect);
    xcb_free_gc(conn, gc);

    return bg_pixmap;
}
static void drawButton(xcb_connection_t *connection,
                       xcb_screen_t *screen,
                       xcb_window_t window,
                       int16_t x1,
                       int16_t y1,
                       const char *label) {

  uint8_t length = strlen(label);
  int16_t inset = 2;
  int16_t width = 7 * length + 2 * (inset + 1);
  int16_t height =13 + 2 * (inset + 1);

  xcb_point_t points[5];
  points[0].x = x1;
  points[0].y = y1;
  points[1].x = x1 + width;
  points[1].y = y1;
  points[2].x = x1 + width;
  points[2].y = y1 - height;
  points[3].x = x1;
  points[3].y = y1 - height;
  points[4].x = x1;
  points[4].y = y1;

  xcb_gcontext_t gc = getFontGC(connection, screen, window, "fixed");
  xcb_void_cookie_t lineCookie = xcb_poly_line_checked(connection,
                                                       XCB_COORD_MODE_ORIGIN,
                                                       window,
                                                       gc,
                                                       5,
                                                       points);

  testCookie(lineCookie, connection, "can't draw lines");
  xcb_void_cookie_t textCookie = xcb_image_text_8_checked(connection,
                                                          length,
                                                          window,
                                                          gc,
                                                          x1 + inset +1,
                                                          y1 - inset -1,
                                                          label);

  testCookie(textCookie, connection, "can't paste text");
  xcb_void_cookie_t gcCookie = xcb_free_gc(connection, gc);
  testCookie(gcCookie, connection, "can't free gc");

}
Exemplo n.º 21
0
static void ya_cleanup_x() {
	ya_bar_t * curbar = ya.curbar;
	ya_block_t *curblk;
	for(;curbar; curbar = curbar->next_bar) {
		for (int align = 0; align < 3; align++) {
			for (curblk = curbar->curblk[align]; curblk; curblk = curblk->next_blk) {
				xcb_free_gc(ya.c, curblk->gc);
				xcb_free_pixmap(ya.c, curblk->pixmap);
			}
		}
		xcb_destroy_window(ya.c, curbar->win);
	}
#ifdef YA_INTERNAL_EWMH
	xcb_ewmh_connection_wipe(ya.ewmh);
#endif //YA_INTERNAL_EWMH
	xcb_flush(ya.c);
	xcb_disconnect(ya.c);
}
Exemplo n.º 22
0
void QXcbShmImage::destroy()
{
    const int segmentSize = m_xcb_image ? (m_xcb_image->stride * m_xcb_image->height) : 0;
    if (segmentSize && m_shm_info.shmaddr)
        Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg));

    xcb_image_destroy(m_xcb_image);

    if (segmentSize) {
        if (m_shm_info.shmaddr) {
            shmdt(m_shm_info.shmaddr);
            shmctl(m_shm_info.shmid, IPC_RMID, 0);
        } else {
            free(m_xcb_image->data);
        }
    }

    if (m_gc)
        Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
}
Exemplo n.º 23
0
/** Destroy all resources of a simple window.
 * \param sw The simple_window_t to wipe.
 */
void
simplewindow_wipe(simple_window_t *sw)
{
    if(sw->window)
    {
        xcb_destroy_window(globalconf.connection, sw->window);
        sw->window = XCB_NONE;
    }
    if(sw->pixmap)
    {
        xcb_free_pixmap(globalconf.connection, sw->pixmap);
        sw->pixmap = XCB_NONE;
    }
    if(sw->gc)
    {
        xcb_free_gc(globalconf.connection, sw->gc);
        sw->gc = XCB_NONE;
    }
    draw_context_wipe(&sw->ctx);
}
static void drawText(xcb_connection_t *connection,
                     xcb_screen_t *screen,
                     xcb_window_t window,
                     int16_t x1,
                     int16_t y1,
                     const char *label) {

  xcb_gcontext_t gc = getFontGC(connection, screen, window, "fixed");
  xcb_void_cookie_t textCookie = xcb_image_text_8_checked(connection,
                                                          strlen (label),
                                                          window,
                                                          gc,
                                                          x1,
                                                          y1,
                                                          label);

  testCookie(textCookie, connection, "can't paste text");

  xcb_void_cookie_t gcCookie = xcb_free_gc(connection, gc);
  testCookie(gcCookie, connection, "can't free gc");
}
Exemplo n.º 25
0
void draw_border(client_t *client)
{
    /* Clear root window to erase any old borders */
    xcb_aux_clear_window(wm_conf.connection, wm_conf.screen->root);

    xcb_gcontext_t orange = xcb_generate_id(wm_conf.connection);
    uint32_t mask = XCB_GC_FOREGROUND;
    uint32_t value[] = { 0xffffa500 };
    xcb_create_gc(wm_conf.connection, orange, wm_conf.screen->root, mask, value);
    xcb_rectangle_t rect[] = {{ client->rect.x - 2,
                                client->rect.y - 2,
                                client->rect.width + 4,
                                client->rect.height + 4 }};

    /* Draw the new border */
    xcb_poly_fill_rectangle(wm_conf.connection, wm_conf.screen->root, orange, 1, rect);

    xcb_free_gc(wm_conf.connection, orange);
    xcb_map_window(wm_conf.connection, wm_conf.screen->root);
    xcb_flush(wm_conf.connection);
}
Exemplo n.º 26
0
static void
text_draw (xcb_connection_t *c,
           xcb_screen_t     *screen,
           xcb_window_t      window,
           int16_t           x1,
           int16_t           y1,
           const char       *label)
{
  xcb_void_cookie_t    cookie_gc;
  xcb_void_cookie_t    cookie_text;
  xcb_generic_error_t *error;
  xcb_gcontext_t       gc;
  uint8_t              length;

  length = strlen (label);

  gc = gc_font_get(c, screen, window, "7x13");

  cookie_text = xcb_image_text_8_checked (c, length, window, gc,
                                          x1,
                                          y1, label);
  error = xcb_request_check (c, cookie_text);
  if (error) {
    fprintf (stderr, "ERROR: can't paste text : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }

  cookie_gc = xcb_free_gc (c, gc);
  error = xcb_request_check (c, cookie_gc);
  if (error) {
    fprintf (stderr, "ERROR: can't free gc : %d\n", error->error_code);
    xcb_disconnect (c);
    exit (-1);
  }
}
Exemplo n.º 27
0
internal void
hhxcb_resize_backbuffer(hhxcb_context *context, hhxcb_offscreen_buffer *buffer, int width, int height)
{
    // xcb_image owns the referenced data, so will clean it up without an explicit free()
    if (buffer->xcb_image)
    {
        xcb_image_destroy(buffer->xcb_image);
    }

    if (buffer->xcb_pixmap_id)
    {
        xcb_free_pixmap(context->connection, buffer->xcb_pixmap_id);
    }

    if (buffer->xcb_gcontext_id)
    {
        xcb_free_gc(context->connection, buffer->xcb_gcontext_id);
    }

    buffer->width = width;
    buffer->height = height;
    buffer->bytes_per_pixel = context->fmt->bits_per_pixel / 8;
    buffer->pitch = buffer->bytes_per_pixel * width;

    buffer->xcb_image = hhxcb_create_image(width, height, context->fmt,
            context->setup);
    buffer->memory = buffer->xcb_image->data;

    buffer->xcb_pixmap_id = xcb_generate_id(context->connection);
    xcb_create_pixmap(context->connection, context->fmt->depth,
            buffer->xcb_pixmap_id, context->window, width, height);

    buffer->xcb_gcontext_id = xcb_generate_id (context->connection);
    xcb_create_gc (context->connection, buffer->xcb_gcontext_id,
            buffer->xcb_pixmap_id, 0, 0);
}
Exemplo n.º 28
0
QPixmap QXcbScreen::grabWindow(WId window, int x, int y, int width, int height) const
{
    if (width == 0 || height == 0)
        return QPixmap();

    // TODO: handle multiple screens
    QXcbScreen *screen = const_cast<QXcbScreen *>(this);
    xcb_window_t root = screen->root();

    if (window == 0)
        window = root;

    xcb_get_geometry_cookie_t geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), window);

    xcb_get_geometry_reply_t *reply =
        xcb_get_geometry_reply(xcb_connection(), geometry_cookie, NULL);

    if (!reply) {
        return QPixmap();
    }

    if (width < 0)
        width = reply->width - x;
    if (height < 0)
        height = reply->height - y;

    geometry_cookie = xcb_get_geometry_unchecked(xcb_connection(), root);
    xcb_get_geometry_reply_t *root_reply =
        xcb_get_geometry_reply(xcb_connection(), geometry_cookie, NULL);

    if (!root_reply) {
        free(reply);
        return QPixmap();
    }

    if (reply->depth == root_reply->depth) {
        // if the depth of the specified window and the root window are the
        // same, grab pixels from the root window (so that we get the any
        // overlapping windows and window manager frames)

        // map x and y to the root window
        xcb_translate_coordinates_cookie_t translate_cookie =
            xcb_translate_coordinates_unchecked(xcb_connection(), window, root, x, y);

        xcb_translate_coordinates_reply_t *translate_reply =
            xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, NULL);

        if (!translate_reply) {
            free(reply);
            free(root_reply);
            return QPixmap();
        }

        x = translate_reply->dst_x;
        y = translate_reply->dst_y;

        window = root;

        free(translate_reply);
        free(reply);
        reply = root_reply;
    } else {
        free(root_reply);
        root_reply = 0;
    }

    xcb_get_window_attributes_reply_t *attributes_reply =
        xcb_get_window_attributes_reply(xcb_connection(), xcb_get_window_attributes_unchecked(xcb_connection(), window), NULL);

    if (!attributes_reply) {
        free(reply);
        return QPixmap();
    }

    const xcb_visualtype_t *visual = screen->visualForId(attributes_reply->visual);
    free(attributes_reply);

    xcb_pixmap_t pixmap = xcb_generate_id(xcb_connection());
    xcb_create_pixmap(xcb_connection(), reply->depth, pixmap, window, width, height);

    uint32_t gc_value_mask = XCB_GC_SUBWINDOW_MODE;
    uint32_t gc_value_list[] = { XCB_SUBWINDOW_MODE_INCLUDE_INFERIORS };

    xcb_gcontext_t gc = xcb_generate_id(xcb_connection());
    xcb_create_gc(xcb_connection(), gc, pixmap, gc_value_mask, gc_value_list);

    xcb_copy_area(xcb_connection(), window, pixmap, gc, x, y, 0, 0, width, height);

    QPixmap result = qt_xcb_pixmapFromXPixmap(connection(), pixmap, width, height, reply->depth, visual);

    free(reply);
    xcb_free_gc(xcb_connection(), gc);
    xcb_free_pixmap(xcb_connection(), pixmap);

    return result;
}
Exemplo n.º 29
0
void QXcbShmImage::put(xcb_window_t window, const QPoint &target, const QRect &source)
{
    Q_XCB_NOOP(connection());
    if (m_gc_window != window) {
        if (m_gc)
            Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));

        m_gc = xcb_generate_id(xcb_connection());
        Q_XCB_CALL(xcb_create_gc(xcb_connection(), m_gc, window, 0, 0));

        m_gc_window = window;
    }

    Q_XCB_NOOP(connection());
    if (m_shm_info.shmaddr) {
        xcb_image_shm_put(xcb_connection(),
                          window,
                          m_gc,
                          m_xcb_image,
                          m_shm_info,
                          source.x(),
                          source.y(),
                          target.x(),
                          target.y(),
                          source.width(),
                          source.height(),
                          false);
    } else {
        // If we upload the whole image in a single chunk, the result might be
        // larger than the server's maximum request size and stuff breaks.
        // To work around that, we upload the image in chunks where each chunk
        // is small enough for a single request.
        int src_x = source.x();
        int src_y = source.y();
        int target_x = target.x();
        int target_y = target.y();
        int width = source.width();
        int height = source.height();

        // We must make sure that each request is not larger than max_req_size.
        // Each request takes req_size + m_xcb_image->stride * height bytes.
        uint32_t max_req_size = xcb_get_maximum_request_length(xcb_connection());
        uint32_t req_size = sizeof(xcb_put_image_request_t);
        int rows_per_put = (max_req_size - req_size) / m_xcb_image->stride;

        // This assert could trigger if a single row has more pixels than fit in
        // a single PutImage request. However, max_req_size is guaranteed to be
        // at least 16384 bytes. That should be enough for quite large images.
        Q_ASSERT(rows_per_put > 0);

        while (height > 0) {
            int rows = std::min(height, rows_per_put);

            xcb_image_t *subimage = xcb_image_subimage(m_xcb_image, src_x, src_y, width, rows,
                                                       0, 0, 0);
            xcb_image_put(xcb_connection(),
                          window,
                          m_gc,
                          subimage,
                          target_x,
                          target_y,
                          0);

            xcb_image_destroy(subimage);

            src_y += rows;
            target_y += rows;
            height -= rows;
        }
    }
    Q_XCB_NOOP(connection());

    m_dirty = m_dirty | source;

    xcb_flush(xcb_connection());
    Q_XCB_NOOP(connection());
}
Exemplo n.º 30
0
void draw_gc(xcb_window_t win)
{
	// the only problem to draw bgr24 it  bps=4 but 3, if depth=24,
	/*
	fmt depth	 bps
	32	  32    4
	bgr24 24    4
	16    16    2
	8      8     1
	0      0      0
		 */
	//draw something in parent window for test
	//w = s->root;
	xcb_gcontext_t       g_solid;
	uint32_t             mask;
	uint32_t             values[2];
	xcb_rectangle_t      r = { 0, 0,  10,10 };
	xcb_rectangle_t      r2 = { 20, 20,  100,100 };
	xcb_connection_t    *c = G.conn;

	if(win==0) {
		win=G.root;
		// atach to root will cause  error=Resource temporary unavailable
	}
	xcb_map_window(c, win); xcb_flush(c);
	g_solid = xcb_generate_id(c);
	mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
	values[0] = G.s->white_pixel;
	values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
	xcb_create_gc(c, g_solid, win, 0,NULL);
	xcb_change_gc(c, g_solid,  mask, values);
	xcb_poly_fill_rectangle(c, win, g_solid,  1, &r2); xcb_flush(c);
	xcb_free_gc(c,g_solid);

	if(1){
		//getimage 
		xcb_get_image_cookie_t cookie;
		xcb_get_image_reply_t *reply;
		xcb_generic_error_t *error;
		int psize= r.width * r.height * G.s->root_depth/8;
		psize = r.width * r.height * 4; //correct
		static uint8_t *pbuf = NULL;
		xcb_void_cookie_t ck;

		if( pbuf == NULL){
			pbuf = malloc(psize);
			printf("malloc pbuf=0x%x size=%d\n",pbuf, psize);
			memset(pbuf, 0x18, psize);
		}

#if 0
		cookie = xcb_get_image (c, XCB_IMAGE_FORMAT_Z_PIXMAP,
				win, r.x, r.y, r.width, r.height, ~0);
		reply = xcb_get_image_reply (c, cookie, &error);
		if (reply == NULL){
			perror("get_image_replay");
			return;
		}

		if (error != NULL) {
			perror("error in xcb_get_image");
			free(error);
		} else {
			uint32_t bytes = xcb_get_image_data_length(reply);
			uint8_t *idata = xcb_get_image_data(reply);
			printf("get_image size=%d p=%p\n", bytes, idata);
			memcpy(pbuf, idata, bytes);
			printf("root_depth=%d\n", G.s->root_depth);
			psize=bytes;
		}
		free(reply);
#endif

		//draw image with xcb_put_image
		// creat gc and draw to parent window
		xcb_gcontext_t       g;
		g = xcb_generate_id(c);
		xcb_create_gc(c, g, win, 0,NULL);

		memset(pbuf, 0xf8, psize);
		int i=0;
		uint8_t *p2=pbuf;
		//fmt = bgr24
		for( i=0; i<psize; ){
			*(p2+i)= 0;		i++;  //blue
			*(p2+i)= 0xff;		i++; //green
			*(p2+i)= 0;		i++; //red
			*(p2+i)= 0x80;		i++; //??
		}
		ck = xcb_put_image_checked(c, XCB_IMAGE_FORMAT_Z_PIXMAP,
				win, g,
				r.width, r.height, r.x,r.y,
				0, G.s->root_depth,
				psize, pbuf);
		xcb_flush(c);

#if 0
		//BadMatch=8 BadLength=16
		xcb_generic_error_t *err;
		err = xcb_request_check (c, ck);
		if (err)
		{
			int code = err->error_code;
			free (err);
			printf("put image error %d\n", code);
			assert (code != 0);
		}   
		xcb_free_gc(c, g);
#endif
	}

}