Пример #1
0
static void
swrastPutImage(__DRIdrawable * draw, int op,
               int x, int y, int w, int h,
               char *data, void *loaderPrivate)
{
   struct dri2_egl_surface *dri2_surf = loaderPrivate;
   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display);

   xcb_gcontext_t gc;

   switch (op) {
   case __DRI_SWRAST_IMAGE_OP_DRAW:
      gc = dri2_surf->gc;
      break;
   case __DRI_SWRAST_IMAGE_OP_SWAP:
      gc = dri2_surf->swapgc;
      break;
   default:
      return;
   }

   xcb_put_image(dri2_dpy->conn, XCB_IMAGE_FORMAT_Z_PIXMAP, dri2_surf->drawable,
                 gc, w, h, x, y, 0, dri2_surf->depth,
                 w*h*dri2_surf->bytes_per_pixel, (const uint8_t *)data);
}
Пример #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();
}
Пример #3
0
static void Prepare(vout_display_t *vd, picture_t *pic, subpicture_t *subpic,
                    vlc_tick_t date)
{
    const video_format_t *fmt = &vd->source;
    vout_display_sys_t *sys = vd->sys;
    xcb_connection_t *conn = sys->conn;

    size_t offset = PictureAttach(vd, pic);
    if (offset != (size_t)-1) {
        xcb_shm_put_image(conn, sys->drawable.source, sys->gc,
                          pic->p->i_pitch / pic->p->i_pixel_pitch,
                          pic->p->i_lines, 0, 0,
                          pic->p->i_pitch / pic->p->i_pixel_pitch,
                          pic->p->i_lines, 0, 0, 32, XCB_IMAGE_FORMAT_Z_PIXMAP,
                          0, sys->segment, offset);
    } else {
        xcb_put_image(conn, XCB_IMAGE_FORMAT_Z_PIXMAP, sys->drawable.source,
                      sys->gc, pic->p->i_pitch / pic->p->i_pixel_pitch,
                      pic->p->i_lines, 0, 0, 0, 32,
                      pic->p->i_pitch * pic->p->i_lines, pic->p->p_pixels);
    }

    /* Crop the picture with pixel accuracy */
    xcb_render_composite(conn, XCB_RENDER_PICT_OP_SRC,
                         sys->picture.source, XCB_RENDER_PICTURE_NONE,
                         sys->picture.crop,
                         fmt->i_x_offset, fmt->i_y_offset, 0, 0,
                         0, 0, fmt->i_visible_width, fmt->i_visible_height);

    /* Blank background */
    static const xcb_render_color_t black_color = { 0, 0, 0, 0xffff };
    xcb_rectangle_t rects[] = {
        { 0, 0, vd->cfg->display.width, vd->cfg->display.height },
    };

    xcb_render_fill_rectangles(conn, XCB_RENDER_PICT_OP_SRC,
                               sys->picture.scale, black_color,
                               ARRAY_SIZE(rects), rects);

    /* Scale and orient the picture */
    xcb_render_composite(conn, XCB_RENDER_PICT_OP_SRC,
                         sys->picture.crop, XCB_RENDER_PICTURE_NONE,
                         sys->picture.scale, sys->src_x, sys->src_y, 0, 0,
                         sys->place.x, sys->place.y,
                         sys->place.width, sys->place.height);
    if (offset != (size_t)-1)
        PictureDetach(vd);

    /* Blend subpictures */
    if (subpic != NULL)
        for (subpicture_region_t *r = subpic->p_region; r != NULL;
             r = r->p_next)
            RenderRegion(vd, subpic, r);

    xcb_flush(conn);
    (void) date;
}
void
_cairo_xcb_connection_put_image (cairo_xcb_connection_t *connection,
				 xcb_drawable_t dst,
				 xcb_gcontext_t gc,
				 uint16_t width,
				 uint16_t height,
				 int16_t dst_x,
				 int16_t dst_y,
				 uint8_t depth,
				 uint32_t stride,
				 void *data)
{
    const uint32_t req_size = 18;
    uint32_t length = height * stride;
    uint32_t len = (req_size + length) >> 2;

    if (len < connection->maximum_request_length) {
	xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP,
		       dst, gc, width, height, dst_x, dst_y, 0, depth,
		       length, data);
    } else {
	int rows = (connection->maximum_request_length - req_size - 4) / stride;
	if (rows > 0) {
	    do {
		if (rows > height)
		    rows = height;

		length = rows * stride;

		xcb_put_image (connection->xcb_connection, XCB_IMAGE_FORMAT_Z_PIXMAP,
			       dst, gc, width, rows, dst_x, dst_y, 0, depth, length, data);

		height -= rows;
		dst_y += rows;
		data = (char *) data + length;
	    } while (height);
	} else {
	    ASSERT_NOT_REACHED;
	}
    }
}
Пример #5
0
void X11WindowedQPainterBackend::present(int mask, const QRegion &damage)
{
    Q_UNUSED(mask)
    Q_UNUSED(damage)
    xcb_connection_t *c = m_backend->connection();
    const xcb_window_t window = m_backend->window();
    if (m_gc == XCB_NONE) {
        m_gc = xcb_generate_id(c);
        xcb_create_gc(c, m_gc, window, 0, nullptr);
    }
    // TODO: only update changes?
    xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, window, m_gc,
                    m_backBuffer.width(), m_backBuffer.height(), 0, 0, 0, 24,
                    m_backBuffer.byteCount(), m_backBuffer.constBits());
}
Пример #6
0
xcb_void_cookie_t
xcb_image_put (xcb_connection_t *  conn,
	       xcb_drawable_t      draw,
	       xcb_gcontext_t      gc,
	       xcb_image_t *       image,
	       int16_t             x,
	       int16_t             y,
	       uint8_t             left_pad)
{
  return xcb_put_image(conn, image->format, draw, gc,
		       image->width, image->height,
		       x, y, left_pad,
		       image->depth,
		       image->size,
		       image->data);
}
Пример #7
0
    //______________________________________________
    quint32 ShadowHelper::createPixmap( const QPixmap& source )
    {

        // do nothing for invalid pixmaps
        if( source.isNull() ) return 0;
        if( !Helper::isX11() ) return 0;

        /*
        in some cases, pixmap handle is invalid. This is the case notably
        when Qt uses to RasterEngine. In this case, we create an X11 Pixmap
        explicitly and draw the source pixmap on it.
        */

        #if MENDA_HAVE_X11

        const int width( source.width() );
        const int height( source.height() );

        // create X11 pixmap
        xcb_pixmap_t pixmap = xcb_generate_id( Helper::connection() );
        xcb_create_pixmap( Helper::connection(), 32, pixmap, QX11Info::appRootWindow(), width, height );

        // create gc
        if( !_gc )
        {
            _gc = xcb_generate_id( Helper::connection() );
            xcb_create_gc( Helper::connection(), _gc, pixmap, 0, 0x0 );
        }

        // create image from QPixmap and assign to pixmap
        QImage image( source.toImage() );
        xcb_put_image( Helper::connection(), XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap, _gc, image.width(), image.height(), 0, 0, 0, 32, image.byteCount(), image.constBits());

        return pixmap;

        #else
        return 0;
        #endif

    }
Пример #8
0
	bool IconImpl::Create(const Image& icon)
	{
		Image iconImage(icon); // Vive le COW
		if (!iconImage.Convert(Nz::PixelFormatType_BGRA8))
		{
			NazaraError("Failed to convert icon to BGRA8");
			return false;
		}

		auto width = iconImage.GetWidth();
		auto height = iconImage.GetHeight();

		ScopedXCBConnection connection;

		xcb_screen_t* screen = X11::XCBDefaultScreen(connection);

		if (!m_iconPixmap.Create(
			screen->root_depth,
			screen->root,
			width,
			height))
		{
			NazaraError("Failed to create icon pixmap");
			return false;
		}

		CallOnExit onExit([this](){
			Destroy();
		});

		XCBGContext iconGC(connection);

		if (!iconGC.Create(
			m_iconPixmap,
			0,
			nullptr))
		{
			NazaraError("Failed to create icon gc");
			return false;
		}

		if (!X11::CheckCookie(
			connection,
			xcb_put_image(
				connection,
				XCB_IMAGE_FORMAT_Z_PIXMAP,
				m_iconPixmap,
				iconGC,
				width,
				height,
				0,
				0,
				0,
				screen->root_depth,
				width * height * 4,
				iconImage.GetConstPixels()
			)))
		{
			NazaraError("Failed to put image for icon");
			return false;
		}

		// Create the mask pixmap (must have 1 bit depth)
		std::size_t pitch = (width + 7) / 8;
		static std::vector<UInt8> maskPixels(pitch * height, 0);
		for (std::size_t j = 0; j < height; ++j)
		{
			for (std::size_t i = 0; i < pitch; ++i)
			{
				for (std::size_t k = 0; k < 8; ++k)
				{
					if (i * 8 + k < width)
					{
						UInt8 opacity = (iconImage.GetConstPixels()[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0;
						maskPixels[i + j * pitch] |= (opacity << k);
					}
				}
			}
		}

		if (!m_maskPixmap.CreatePixmapFromBitmapData(
			X11::XCBDefaultRootWindow(connection),
			reinterpret_cast<uint8_t*>(&maskPixels[0]),
			width,
			height,
			1,
			0,
			1,
			nullptr))
		{
			NazaraError("Failed to create mask pixmap for icon");
			return false;
		}

		onExit.Reset();

		return true;
	}
Пример #9
0
static void RenderRegion(vout_display_t *vd, const subpicture_t *subpic,
                         const subpicture_region_t *reg)
{
    vout_display_sys_t *sys = vd->sys;
    xcb_connection_t *conn = sys->conn;
    const vout_display_place_t *place = &sys->place;
    picture_t *pic = reg->p_picture;
    unsigned sw = reg->fmt.i_width;
    unsigned sh = reg->fmt.i_height;
    xcb_rectangle_t rects[] = { { 0, 0, sw, sh }, };

    xcb_create_pixmap(conn, 32, sys->drawable.subpic, sys->root, sw, sh);
    xcb_create_pixmap(conn, 8, sys->drawable.alpha, sys->root, sw, sh);
    xcb_render_create_picture(conn, sys->picture.subpic, sys->drawable.subpic,
                              sys->format.argb, 0, NULL);
    xcb_render_create_picture(conn, sys->picture.alpha, sys->drawable.alpha,
                              sys->format.alpha, 0, NULL);

    /* Upload region (TODO: use FD passing for SPU?) */
    xcb_put_image(conn, XCB_IMAGE_FORMAT_Z_PIXMAP, sys->drawable.subpic,
                  sys->gc, pic->p->i_pitch / pic->p->i_pixel_pitch,
                  pic->p->i_lines, 0, 0, 0, 32,
                  pic->p->i_pitch * pic->p->i_lines, pic->p->p_pixels);

    /* Copy alpha channel */
    xcb_render_composite(conn, XCB_RENDER_PICT_OP_SRC,
                         sys->picture.subpic, XCB_RENDER_PICTURE_NONE,
                         sys->picture.alpha, 0, 0, 0, 0, 0, 0, sw, sh);

    /* Force alpha channel to maximum (add 100% and clip).
     * This is to compensate RENDER expecting pre-multiplied RGB
     * while VLC uses straight RGB.
     */
    static const xcb_render_color_t alpha_one_color = { 0, 0, 0, 0xffff };

    xcb_render_fill_rectangles(conn, XCB_RENDER_PICT_OP_ADD,
                               sys->picture.subpic, alpha_one_color,
                               ARRAY_SIZE(rects), rects);

    /* Multiply by region and subpicture alpha factors */
    static const float alpha_fixed = 0xffffp0f / (0xffp0f * 0xffp0f);
    xcb_render_color_t alpha_color = {
        0, 0, 0, lroundf(reg->i_alpha * subpic->i_alpha * alpha_fixed) };

    xcb_render_fill_rectangles(conn, XCB_RENDER_PICT_OP_IN_REVERSE,
                               sys->picture.subpic, alpha_color,
                               ARRAY_SIZE(rects), rects);

    /* Mask in the original alpha channel then renver over the scaled pixmap.
     * Mask (pre)multiplies RGB channels and restores the alpha channel.
     */
    int_fast16_t dx = place->x + reg->i_x * place->width
                      / subpic->i_original_picture_width;
    int_fast16_t dy = place->y + reg->i_y * place->height
                      / subpic->i_original_picture_height;
    uint_fast16_t dw = (reg->i_x + reg->fmt.i_visible_width) * place->width
                       / subpic->i_original_picture_width;
    uint_fast16_t dh = (reg->i_y + reg->fmt.i_visible_height) * place->height
                       / subpic->i_original_picture_height;

    xcb_render_composite(conn, XCB_RENDER_PICT_OP_OVER,
                         sys->picture.subpic, sys->picture.alpha,
                         sys->picture.scale, 0, 0, 0, 0, dx, dy, dw, dh);

    xcb_render_free_picture(conn, sys->picture.alpha);
    xcb_render_free_picture(conn, sys->picture.subpic);
    xcb_free_pixmap(conn, sys->drawable.alpha);
    xcb_free_pixmap(conn, sys->drawable.subpic);
}
Пример #10
0
Файл: x11.c Проект: meh/egill
static void
get_resources (el_backend_x11_t self)
{
	#define F(field) offsetof(struct el_backend_x11, field)
	static const struct {
		const char* name;
		int         offset;
	} atoms[] = {
		{ "WM_PROTOCOLS",     F(atom.wm_protocols) },
		{ "WM_NORMAL_HINTS",  F(atom.wm_normal_hints) },
		{ "WM_SIZE_HINTS",    F(atom.wm_size_hints) },
		{ "WM_DELETE_WINDOW", F(atom.wm_delete_window) },
		{ "WM_CLASS",         F(atom.wm_class) },

		{ "_NET_WM_NAME",             F(atom.net_wm_name) },
		{ "_NET_WM_ICON",             F(atom.net_wm_icon) },
		{ "_NET_WM_STATE",            F(atom.net_wm_state) },
		{ "_NET_WM_STATE_FULLSCREEN", F(atom.net_wm_state_fullscreen) },
		{ "_NET_SUPPORTING_WM_CHECK", F(atom.net_supporting_wm_check) },
		{ "_NET_SUPPORTED",           F(atom.net_supported) },

		{ "_XKB_RULES_NAMES", F(atom.xkb_names) },

		{ "STRING",      F(atom.string) },
		{ "UTF8_STRING", F(atom.utf8_string) },
		{ "CARDINAL",    F(atom.cardinal) },
	};
	#undef F

	uint8_t data[] = { 0, 0, 0, 0 };

	xcb_intern_atom_cookie_t cookies[lengthof(atoms)];

	for (size_t i = 0; i < lengthof(atoms); i++) {
		cookies[i] = xcb_intern_atom(self->connection, 0,
			strlen(atoms[i].name), atoms[i].name);
	}

	for (size_t i = 0; i < lengthof(atoms); i++) {
		xcb_intern_atom_reply_t* reply = xcb_intern_atom_reply(self->connection,
			cookies[i], NULL);

		*(xcb_atom_t*) ((char*) self + atoms[i].offset) = reply->atom;

		free(reply);
	}

	xcb_pixmap_t pixmap = xcb_generate_id(self->connection);
	xcb_gc_t     gc     = xcb_generate_id(self->connection);

	xcb_create_pixmap(self->connection, 1, pixmap, self->screen->root, 1, 1);
	xcb_create_gc(self->connection, gc, pixmap, 0, NULL);
	xcb_put_image(self->connection, XCB_IMAGE_FORMAT_XY_PIXMAP,
		pixmap, gc, 1, 1, 0, 0, 0, 32, sizeof(data), data);

	self->cursor = xcb_generate_id(self->connection);
	xcb_create_cursor(self->connection, self->cursor, pixmap, pixmap,
		0, 0, 0, 0, 0, 0, 1, 1);

	xcb_free_gc(self->connection, gc);
	xcb_free_pixmap(self->connection, pixmap);
}