示例#1
0
static void _render_copy(struct test_target *tt,
			 int x, int y, int w, int h,
			 uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
	XRenderColor color;
	Picture src;
	Pixmap tmp;

	tmp = XCreatePixmap(tt->dpy->dpy, DefaultRootWindow(tt->dpy->dpy),
			    10+w, 20+h, tt->format->depth);
	src = XRenderCreatePicture(tt->dpy->dpy, tmp, tt->format, 0, NULL);

	/* magenta border */
	color.red = 0xffff;
	color.green = 0;
	color.blue = 0xffff;
	color.alpha = 0xffff;
	XRenderFillRectangle(tt->dpy->dpy, PictOpSrc, src, &color, 0, 0, w+10, h+20);

	color.red = red * alpha;
	color.green = green * alpha;
	color.blue = blue * alpha;
	color.alpha = alpha << 8 | alpha;
	XRenderFillRectangle(tt->dpy->dpy, PictOpSrc, src, &color, 5, 10, w, h);

	XRenderComposite(tt->dpy->dpy, PictOpSrc,
			 src, 0, tt->picture,
			 5, 10,
			 0, 0,
			 x, y,
			 w, h);

	XRenderFreePicture(tt->dpy->dpy, src);
	XFreePixmap(tt->dpy->dpy, tmp);
}
static Picture source_pixmap(struct test_display *t, struct test_target *target, int format)
{
	XRenderColor render_color[2] = {
		{ 0x8000, 0x8000, 0x8000, 0x8000 },
		{ 0xffff, 0xffff, 0xffff, 0xffff },
	};
	Pixmap pixmap;
	Picture picture;

	pixmap = XCreatePixmap(t->dpy, t->root,
			       target->width, target->height,
			       PIXMAN_FORMAT_DEPTH(formats[format].pixman_format));

	picture = XRenderCreatePicture(t->dpy, pixmap,
				       XRenderFindStandardFormat(t->dpy, format),
				       0, NULL);
	XFreePixmap(t->dpy, pixmap);

	XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color[0],
			     0, 0, target->width, target->height/2);
	XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color[1],
			     0, target->height/2, target->width, target->height/2);

	return picture;
}
static double _bench_source(struct test_display *t, enum target target_type,
			    int op, int src, int loops)
{
	XRenderColor render_color = { 0x8000, 0x8000, 0x8000, 0x8000 };
	struct test_target target;
	Picture picture;
	struct timespec tv;
	double elapsed;

	test_target_create_render(t, target_type, &target);
	XRenderFillRectangle(t->dpy, PictOpClear, target.picture, &render_color,
			     0, 0, target.width, target.height);

	picture = source[src].create(t, &target);
	if (picture) {
		test_timer_start(t, &tv);
		while (loops--)
			XRenderComposite(t->dpy, op,
					 picture, 0, target.picture,
					 0, 0,
					 0, 0,
					 0, 0,
					 target.width, target.height);
		elapsed = test_timer_stop(t, &tv);
		XRenderFreePicture(t->dpy, picture);
	} else
		elapsed = -1;

	test_target_destroy_render(t, &target);

	return elapsed;
}
示例#4
0
static void clear(struct test_display *dpy,
		  struct test_target *tt,
		  const XRenderColor *c)
{
	XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, c,
			     0, 0, tt->width, tt->height);
}
示例#5
0
文件: area.c 项目: Dok-Sergey/tint2
void clear_pixmap(Pixmap p, int x, int y, int w, int h)
{
	Picture pict = XRenderCreatePicture(server.dsp, p, XRenderFindVisualFormat(server.dsp, server.visual), 0, 0);
	XRenderColor col = { .red=0, .green=0, .blue=0, .alpha=0 };
	XRenderFillRectangle(server.dsp, PictOpSrc, pict, &col, x, y, w, h);
	XRenderFreePicture(server.dsp, pict);
}
示例#6
0
static void
clientwin_repaint(ClientWin *cw, XRectangle *rect)
{
	XRenderColor *tint = cw->focused ? &cw->mainwin->highlightTint : &cw->mainwin->normalTint;
	int s_x = (double)rect->x * cw->factor,
	    s_y = (double)rect->y * cw->factor,
	    s_w = (double)rect->width * cw->factor,
	    s_h = (double)rect->height * cw->factor;
	
	if(cw->mainwin->lazy_trans)
	{
		XRenderComposite(cw->mainwin->dpy, PictOpSrc, cw->origin,
		                 cw->focused ? cw->mainwin->highlightPicture : cw->mainwin->normalPicture,
		                 cw->destination, s_x, s_y, 0, 0, s_x, s_y, s_w, s_h);
	}
	else
	{
		XRenderComposite(cw->mainwin->dpy, PictOpSrc, cw->mainwin->background, None, cw->destination, cw->mini.x + s_x, cw->mini.y + s_y, 0, 0, s_x, s_y, s_w, s_h);
		XRenderComposite(cw->mainwin->dpy, PictOpOver, cw->origin,
		                 cw->focused ? cw->mainwin->highlightPicture : cw->mainwin->normalPicture,
		                 cw->destination, s_x, s_y, 0, 0, s_x, s_y, s_w, s_h);
	}
	
	if(tint->alpha)
		XRenderFillRectangle(cw->mainwin->dpy, PictOpOver, cw->destination, tint, s_x, s_y, s_w, s_h);
	
	XClearArea(cw->mainwin->dpy, cw->mini.window, s_x, s_y, s_w, s_h, False);
}
static void fill_rect(struct test_display *t, Picture p,
		      int x, int y, int w, int h,
		      uint8_t red, uint8_t green, uint8_t blue)
{
	Drawable tmp;
	XRenderColor c;
	Picture src;
	XRenderPictFormat *format;

	format = XRenderFindStandardFormat(t->dpy, PictStandardRGB24);

	tmp = XCreatePixmap(t->dpy, DefaultRootWindow(t->dpy),
			    w, h, format->depth);

	src = XRenderCreatePicture(t->dpy, tmp, format, 0, NULL);
	c.red = (int)red << 8 | red;
	c.green = (int)green << 8 | green;
	c.blue = (int)blue << 8 | blue;
	c.alpha = 0xffff;
	XRenderFillRectangle(t->dpy, PictOpSrc, src, &c, 0, 0, w, h);
	XRenderComposite(t->dpy, PictOpOver, src, 0, p, 0, 0, 0, 0, x, y, w, h);

	XRenderFreePicture(t->dpy, src);
	XFreePixmap(t->dpy, tmp);
}
示例#8
0
static XPicture sGetSolidFill(Color c)
{
	int q = GetHashValue(c) % (int)XRSolidFillCount;
	XRSolidFill& f = sFill[q];
	if(f.color == c && f.picture)
		return f.picture;
	if(f.picture)
		XRenderFreePicture(Xdisplay, f.picture);
	if(f.pixmap)
		XFreePixmap(Xdisplay, f.pixmap);
	f.pixmap = XCreatePixmap(Xdisplay, Xroot, 1, 1, 32);
	XRenderPictureAttributes attr;
	attr.repeat = XTrue;
	f.picture = XRenderCreatePicture(Xdisplay, f.pixmap,
	                                 XRenderFindStandardFormat(Xdisplay, PictStandardARGB32),
	                                                           CPRepeat, &attr);
	f.color = c;
	XRenderColor xc;
	xc.red = s255d16(c.GetR());
	xc.green = s255d16(c.GetG());
	xc.blue = s255d16(c.GetB());
	xc.alpha = 65535;
	XRenderFillRectangle(Xdisplay, PictOpSrc, f.picture, &xc, 0, 0, 1, 1);
	return f.picture;
}
XRenderPicture xRenderBlendPicture(double opacity)
{
    _blendColor.alpha = ushort(opacity * 0xffff);
    if (_blendPicture == X::None)
        _blendPicture = xRenderFill(&_blendColor);
    else
        XRenderFillRectangle(display(), PictOpSrc, _blendPicture, &_blendColor, 0, 0, 1, 1);
    return _blendPicture;
}
XRenderPicture xRenderFill(const XRenderColor *xc)
{
    Pixmap pixmap = XCreatePixmap(display(), rootWindow(), 1, 1, 32);
    XRenderPictureAttributes pa; pa.repeat = True;
    XRenderPicture fill(pixmap, 32);
    XFreePixmap(display(), pixmap);
    XRenderChangePicture(display(), fill, CPRepeat, &pa);
    XRenderFillRectangle(display(), PictOpSrc, fill, xc, 0, 0, 1, 1);
    return fill;
}
示例#11
0
static void fill_rect(struct test_display *dpy, Picture p, uint8_t op,
		      int x, int y, int w, int h,
		      uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{
	XRenderColor render_color;

	render_color.red   = red * alpha;
	render_color.green = green * alpha;
	render_color.blue  = blue * alpha;
	render_color.alpha = alpha << 8;

	XRenderFillRectangle(dpy->dpy, op, p, &render_color, x, y, w,h);
}
示例#12
0
文件: gui.c 项目: mortehu/bra
void
gui_draw_quad(struct gui_instance *gi, int x, int y, unsigned int width,
              unsigned int height, unsigned int color)
{
  XRenderColor c;

  c.alpha = ((color & 0xff000000) >> 24) * 0x0101;
  c.red = ((color & 0xff0000) >> 16) * 0x0101;
  c.green = ((color & 0x00ff00) >> 8) * 0x0101;
  c.blue = (color & 0x0000ff) * 0x0101;

  XRenderFillRectangle(GUI_display, PictOpSrc, gi->back_buffer, &c, x, y, width, height);
}
示例#13
0
static bool check_op(struct test_display *dpy, int op, struct test_target *tt)
{
	XRenderColor render_color = {0};

	XSync(dpy->dpy, True);
	_x_error_occurred = 0;

	XRenderFillRectangle(dpy->dpy, op,
			     tt->picture, &render_color,
			     0, 0, 0, 0);

	XSync(dpy->dpy, True);
	return _x_error_occurred == 0;
}
示例#14
0
void ShowPaintEffect::paintXrender()
{
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
    XRenderColor col;
    float alpha = 0.2;
    const QColor& color = colors[ color_index ];
    col.alpha = int(alpha * 0xffff);
    col.red = int(alpha * 0xffff * color.red() / 255);
    col.green = int(alpha * 0xffff * color.green() / 255);
    col.blue = int(alpha * 0xffff * color.blue() / 255);
    foreach (const QRect & r, painted.rects())
    XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
                         &col, r.x(), r.y(), r.width(), r.height());
#endif
}
示例#15
0
文件: xftdraw.c 项目: aosm/X11
void
XftDrawRect (XftDraw	    *draw,
	     XftColor	    *color,
	     int	    x, 
	     int	    y,
	     unsigned int   width,
	     unsigned int   height)
{
    if (XftDrawRenderPrepare (draw, color, 0, XFT_DRAW_SRC_RECT))
    {
	XRenderFillRectangle (draw->dpy, PictOpOver, draw->render.pict,
			      &color->color, x, y, width, height);
    }
    else
    {
	XftDrawCorePrepare (draw, color, 0);
	XFillRectangle (draw->dpy, draw->drawable, draw->core.draw_gc,
			x, y, width, height);
    }
}
示例#16
0
static Picture source_1x1r(struct test_display *t, struct test_target *target)
{
	XRenderColor render_color = { 0x8000, 0x8000, 0x8000, 0x8000 };
	XRenderPictureAttributes pa;
	Pixmap pixmap;
	Picture picture;

	pa.repeat = RepeatNormal;

	pixmap = XCreatePixmap(t->dpy, t->root, 1, 1, 32);
	picture = XRenderCreatePicture(t->dpy, pixmap,
				       XRenderFindStandardFormat(t->dpy, 0),
				       CPRepeat, &pa);
	XFreePixmap(t->dpy, pixmap);

	XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color,
			     0, 0, 1, 1);

	return picture;
}
示例#17
0
void Workspace::createRootTile()
{
	Pixmap pixmap = None;

	Atom actual_type;
	int actual_format;
	ulong nitems, bytes_remaining;
	uchar *data = 0L;

	// Try to find a root window property with a pixmap ID for a background pixmap.
	Atom atoms[] = { ATOM(ESETROOT_PMAP_ID), ATOM(_XROOTPMAP_ID), ATOM(_XSETROOT_ID) };
	for (int i = 0; i < 3; i++ )
	{
		int result = XGetWindowProperty( dpy, rootId(), atoms[i], 0, 4, false, XA_PIXMAP,
						&actual_type, &actual_format, &nitems, &bytes_remaining, &data );

		if ( result == Success && actual_type == XA_PIXMAP
				   && actual_format == 32 && nitems == 1 )
		{
			pixmap = *reinterpret_cast<Pixmap*>( data );
			XFree( data );
			break;
		}
	}

	XRenderPictureAttributes pa;
	pa.repeat = true;

	// Create the root tile picture for the pixmap if one was found
	if ( pixmap != None ) {
		mRootTile = XRenderCreatePicture( dpy, pixmap, format(), CPRepeat, &pa );
	} else {
		// If no background pixmap is set, create a simply 1x1 tile
		pixmap    = XCreatePixmap( dpy, rootId(), 1, 1, depth() );
		mRootTile = XRenderCreatePicture( dpy, pixmap, format(), CPRepeat, &pa );

		// Fill it with a gray color
		XRenderColor col = { 0x8080, 0x8080, 0x8080, 0xffff };
		XRenderFillRectangle( dpy, PictOpSrc, mRootTile, &col, 0, 0, 1, 1 );
	}
}
示例#18
0
gboolean
myDisplayTestXrender (DisplayInfo *display, gdouble min_time)
{
#ifdef HAVE_RENDER
    GTimeVal t1, t2;
    gdouble dt;
    Display *dpy;
    Picture picture1, picture2, picture3;
    XRenderPictFormat *format_src, *format_dst;
    Pixmap fillPixmap, rootPixmap;
    XRenderPictureAttributes pa;
    XSetWindowAttributes attrs;
    XImage *ximage;
    Window output;
    XRenderColor c;
    Visual *visual;
    Screen *screen;
    int x, y, w, h;
    int screen_number;
    int depth;
    int iterations;

    g_return_val_if_fail (display != NULL, FALSE);
    TRACE ("entering myDisplayTesxrender");

    c.alpha = 0x7FFF;
    c.red   = 0xFFFF;
    c.green = 0xFFFF;
    c.blue  = 0xFFFF;

    dpy = display->dpy;
    screen_number = DefaultScreen (dpy);
    screen = DefaultScreenOfDisplay (dpy);
    visual = DefaultVisual (dpy, screen_number);
    depth = DefaultDepth (dpy, screen_number);

    w = WidthOfScreen(screen) / 16;
    h = HeightOfScreen(screen) / 16;
    x = (WidthOfScreen(screen) - w);
    y = (HeightOfScreen(screen) - h);

    format_dst = XRenderFindVisualFormat (dpy, visual);
    g_return_val_if_fail (format_dst != NULL , FALSE);

    format_src = XRenderFindStandardFormat (dpy, PictStandardA8);
    g_return_val_if_fail (format_src != NULL , FALSE);

    ximage = XGetImage (dpy,
                        DefaultRootWindow(dpy),
                        x, y, w, h,
                        AllPlanes, ZPixmap);
    g_return_val_if_fail (ximage != NULL , FALSE);

    rootPixmap = XCreatePixmap (dpy,
                                DefaultRootWindow(dpy),
                                w, h, depth);
    XPutImage (dpy, rootPixmap,
               DefaultGC (dpy, screen_number), ximage,
               0, 0, 0, 0, w, h);
    XDestroyImage (ximage);

    attrs.override_redirect = TRUE;
    output = XCreateWindow (dpy,
                            DefaultRootWindow(dpy),
                            x, y, w, h,
                            0, CopyFromParent, CopyFromParent,
                            (Visual *) CopyFromParent,
                            CWOverrideRedirect, &attrs);
    XMapRaised (dpy, output);

    fillPixmap = XCreatePixmap (dpy,
                                DefaultRootWindow(dpy),
                                1, 1, 8);

    g_get_current_time (&t1);

    pa.repeat = TRUE;
    picture1 = XRenderCreatePicture (dpy,
                                     rootPixmap,
                                     format_dst, 0, NULL);
    picture2 = XRenderCreatePicture (dpy,
                                     fillPixmap,
                                     format_src, CPRepeat, &pa);
    picture3 = XRenderCreatePicture (dpy,
                                     output,
                                     format_dst, 0, NULL);
    XRenderComposite (dpy, PictOpSrc,
                    picture1, None, picture3,
                    0, 0, 0, 0, 0, 0, w, h);
    XRenderFillRectangle (dpy, PictOpSrc,
                          picture2, &c, 0, 0,
                          1, 1);
    for (iterations = 0; iterations < 10; iterations++)
    {
        XRenderComposite (dpy, PictOpOver,
                        picture1, picture2, picture3,
                        0, 0, 0, 0, 0, 0, w, h);
        ximage = XGetImage (dpy, output,
                            0, 0, 1, 1,
                            AllPlanes, ZPixmap);
        if (ximage)
        {
                XDestroyImage (ximage);
        }
    }
    XRenderFreePicture (dpy, picture1);
    XRenderFreePicture (dpy, picture2);
    XRenderFreePicture (dpy, picture3);

    XFreePixmap (dpy, fillPixmap);
    XFreePixmap (dpy, rootPixmap);

    XDestroyWindow (dpy, output);

    g_get_current_time (&t2);

    dt = (gdouble) (t2.tv_sec - t1.tv_sec) * G_USEC_PER_SEC +
         (gdouble) (t2.tv_usec - t1.tv_usec) / 1000.0;

    if (dt < min_time)
    {
        TRACE ("XRender test passed (target %3.4f sec., measured %3.4f sec.).", min_time, dt);
        return TRUE;
    }
    g_print ("XRender test failed (target %3.4f sec., measured %3.4f sec.).\n", min_time, dt);
    return FALSE;
#else  /* HAVE_RENDER */
    return FALSE;
#endif /* HAVE_RENDER */
}
示例#19
0
文件: img.c 项目: NerrickT/skippy-xd
pictw_t *
simg_postprocess(session_t *ps, pictw_t *src, enum pict_posp_mode mode,
		int twidth, int theight, enum align alg, enum align valg,
		const XRenderColor *pc) {
	static const XRenderColor XRC_TRANS = {
		.red = 0, .green = 0, .blue = 0, .alpha = 0
	};
	if (!pc) pc = &XRC_TRANS;

	const int depth = 32;
	pictw_t *dest = NULL;
	bool transformed = false;

	if (!src) {
		if (twidth && theight) {
			if (!(dest = create_pictw(ps, twidth, theight, depth)))
				printfef("(): Failed to create Picture.");
			else
				XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, 0, 0,
						twidth, theight);
		}
		goto simg_postprocess_end;
	}

	if (!(twidth || theight)
			|| (twidth == src->width && theight == src->height))
		return src;

	// Determine composite paramaters. We have to do this before create
	// Picture because the width/height may need to be calculated.
	int width = src->width, height = src->height;
	if (!twidth) twidth = (double) theight / height * width;
	else if (!theight) theight = (double) twidth / width * height;
	double ratio_x = 1.0, ratio_y = 1.0;
	switch (mode) {
		case PICTPOSP_ORIG: break;
		case PICTPOSP_TILE: break;
		case PICTPOSP_SCALE:
		case PICTPOSP_SCALEK:
		case PICTPOSP_SCALEE:
		case PICTPOSP_SCALEEK:
							{
								if (twidth) ratio_x = (double) twidth / width;
								if (theight) ratio_y = (double) theight / height;
								if (PICTPOSP_SCALEK == mode || PICTPOSP_SCALEEK == mode)
									ratio_x = ratio_y = MIN(ratio_x, ratio_y);
								if (PICTPOSP_SCALEE == mode || PICTPOSP_SCALEEK == mode) {
									ratio_x = MAX(1.0f, ratio_x);
									ratio_y = MAX(1.0f, ratio_y);
								}
								width *= ratio_x;
								height *= ratio_y;
							}
							break;
		default:            assert(0); break;
	}

	if (!(dest = create_pictw(ps, twidth, theight, depth))) {
		printfef("(): Failed to create Picture.");
		goto simg_postprocess_end;
	}

	int x = 0, y = 0;
	int num_x = 1, num_y = 1;
	if (PICTPOSP_TILE == mode) {
	    // num_x = ceil((float) twidth / width);
	    // num_y = ceil((float) theight / height);
	    num_x = twidth / width;
	    num_y = theight / height;
	}
	switch (alg) {
		case ALIGN_LEFT:  break;
		case ALIGN_RIGHT: x = twidth - width * num_x; break;
		case ALIGN_MID:   x = (twidth - width * num_x) / 2; break;
	};
	switch (valg) {
		case ALIGN_LEFT:  break;
		case ALIGN_RIGHT: y = theight - height * num_y; break;
		case ALIGN_MID:   y = (theight - height * num_y) / 2; break;
	};
	x = MAX(x, 0);
	y = MAX(y, 0);
	int x2 = MIN(x + width * num_x, twidth),
			y2 = MIN(y + height * num_y, theight);
	/* if (pc->alpha) */ {
		if (src->depth >= 32)
			XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, 0, 0,
					twidth, theight);
		else {
			XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, 0, 0,
					twidth, y);
			XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, 0, y2,
					twidth, theight - y2);
			XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, 0, y,
					x, y2 - y);
			XRenderFillRectangle(ps->dpy, PictOpSrc, dest->pict, pc, x2, y,
					twidth - x2, y2 - y);
		}
	}
	if (src->pict) {
		if (1.0 != ratio_x || 1.0 != ratio_y) {
			XTransform transform = { .matrix = {
				{ XDoubleToFixed(1.0 / ratio_x), XDoubleToFixed(0.0), XDoubleToFixed(0.0) },
				{ XDoubleToFixed(0.0), XDoubleToFixed(1.0 / ratio_y), XDoubleToFixed(0.0) },
				{ XDoubleToFixed(0.0), XDoubleToFixed(0.0), XDoubleToFixed(1.0) },
			} };
			transformed = true;
			XRenderSetPictureTransform(ps->dpy, src->pict, &transform);
		}
示例#20
0
void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
    if (m_active && w == m_resizeWindow) {
        if (m_features & TextureScale) {
            data.xTranslate += m_currentGeometry.x() - m_originalGeometry.x();
            data.xScale *= m_currentGeometry.width();
            data.xScale /= m_originalGeometry.width();
            data.yTranslate += m_currentGeometry.y() - m_originalGeometry.y();
            data.yScale *= m_currentGeometry.height();
            data.yScale /= m_originalGeometry.height();
        }
        effects->paintWindow(w, mask, region, data);

        if (m_features & Outline) {
            QRegion intersection = m_originalGeometry.intersected(m_currentGeometry);
            QRegion paintRegion = QRegion(m_originalGeometry).united(m_currentGeometry).subtracted(intersection);
            float alpha = 0.8f;
            QColor color = KColorScheme(QPalette::Normal, KColorScheme::Selection).background().color();

#ifdef KWIN_HAVE_OPENGL
            if (effects->compositingType() == OpenGLCompositing) {
                GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
                vbo->reset();
                vbo->setUseColor(true);
                if (ShaderManager::instance()->isValid()) {
                    ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
                }
                glEnable(GL_BLEND);
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                color.setAlphaF(alpha);
                vbo->setColor(color);
                QVector<float> verts;
                verts.reserve(paintRegion.rects().count() * 12);
                foreach (const QRect & r, paintRegion.rects()) {
                    verts << r.x() + r.width() << r.y();
                    verts << r.x() << r.y();
                    verts << r.x() << r.y() + r.height();
                    verts << r.x() << r.y() + r.height();
                    verts << r.x() + r.width() << r.y() + r.height();
                    verts << r.x() + r.width() << r.y();
                }
                vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
                vbo->render(GL_TRIANGLES);
                if (ShaderManager::instance()->isValid()) {
                    ShaderManager::instance()->popShader();
                }
                glDisable(GL_BLEND);
            }
#endif

#ifdef KWIN_HAVE_XRENDER_COMPOSITING
            if (effects->compositingType() == XRenderCompositing) {
                XRenderColor col;
                col.alpha = int(alpha * 0xffff);
                col.red = int(alpha * 0xffff * color.red() / 255);
                col.green = int(alpha * 0xffff * color.green() / 255);
                col.blue = int(alpha * 0xffff * color.blue() / 255);
                foreach (const QRect & r, paintRegion.rects())
                XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
                                     &col, r.x(), r.y(), r.width(), r.height());
            }
示例#21
0
int
InitCompositePix(XParms xp, Parms p, int64_t reps)
{
    XRenderPictFormat	*format = NULL;
    int			depth;
    static XRenderColor c = { 0xffff, 0x0000, 0xffff, 0xffff };

    (void) InitCompositeWin (xp, p, reps);
    
    /* Create pixmap to write stuff into, and initialize it */
    switch (xp->planemask) {
    case PictStandardNative:
	depth = xp->vinfo.depth;
	format = XRenderFindVisualFormat (xp->d, xp->vinfo.visual);
	break;
    case PictStandardRGB24:
	depth = 24;
	break;
    case PictStandardARGB32:
	depth = 32;
	break;
    case PictStandardA8:
	depth = 8;
	break;
    case PictStandardA4:
	depth = 4;
	break;
    case PictStandardA1:
	depth = 1;
	break;
    default:
	depth = 0;
	break;
    }
    if (!format)
	format = XRenderFindStandardFormat (xp->d, xp->planemask);
    
    pix = XCreatePixmap(xp->d, xp->w, WIDTH, HEIGHT, depth);
    pixPict = XRenderCreatePicture (xp->d, pix, format, 0, NULL);
    
    XRenderComposite (xp->d, PictOpClear,
		      winPict, None, pixPict,
		      0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
    
    XRenderFillRectangle (xp->d, PictOpSrc,
			  pixPict, &c, 0, 0, WIDTH, HEIGHT);
#if 1
    XRenderComposite (xp->d, PictOpSrc,
		      winPict, None, pixPict,
		      0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
#endif
    if (p->fillStyle) {
	XTransform		transform;
	memset (&transform, '\0', sizeof (transform));
	transform.matrix[0][0] = ((long long) 0x10000 * 0x10000) / p->fillStyle;
	transform.matrix[1][1] = ((long long) 0x10000 * 0x10000) / p->fillStyle;
	transform.matrix[2][2] = 0x10000;
	XRenderSetPictureTransform (xp->d, pixPict, &transform);
	XRenderSetPictureFilter (xp->d, pixPict, FilterBilinear, NULL, 0);
    }
    return reps;
}
示例#22
0
文件: xftdraw.c 项目: aosm/X11
Bool
XftDrawRenderPrepare (XftDraw	*draw,
		      XftColor	*color,
		      XftFont	*font,
		      int	src)
{
    if (!draw->render_set)
    {
	XRenderPictFormat	    *format;
	XRenderPictFormat	    *pix_format;
	XRenderPictureAttributes    pa;
	int			    n;
	Pixmap			    pix;

	draw->render_set = True;
	draw->render_able = False;
	format = _XftDrawFormat (draw);
	pix_format = _XftDrawFgFormat (draw);
	if (format && pix_format)
	{
	    draw->render_able = True;

	    draw->render.pict = XRenderCreatePicture (draw->dpy, draw->drawable,
						      format, 0, 0);
	    for (n = 0; n < XFT_DRAW_N_SRC; n++)
	    {
		pix = XCreatePixmap (draw->dpy, draw->drawable,
				     1, 1, pix_format->depth);
		pa.repeat = True;
		draw->render.src[n].pict = XRenderCreatePicture (draw->dpy, 
								 pix,
								 pix_format,
								 CPRepeat, &pa);
		XFreePixmap (draw->dpy, pix);
		
		draw->render.src[n].color = color->color;
		XRenderFillRectangle (draw->dpy, PictOpSrc, 
				      draw->render.src[n].pict,
				      &color->color, 0, 0, 1, 1);
	    }
	    if (draw->clip)
		XRenderSetPictureClipRegion (draw->dpy, draw->render.pict,
					     draw->clip);
	}
    }
    if (!draw->render_able)
	return False;
    if (memcmp (&color->color, &draw->render.src[src].color, 
		sizeof (XRenderColor)))
    {
	if (_XftFontDebug () & XFT_DBG_DRAW)
	{
	    printf ("Switching to color %04x,%04x,%04x,%04x\n",
		    color->color.alpha,
		    color->color.red,
		    color->color.green,
		    color->color.blue);
	}
	XRenderFillRectangle (draw->dpy, PictOpSrc, 
			      draw->render.src[src].pict,
			      &color->color, 0, 0, 1, 1);
	draw->render.src[src].color = color->color;
    }
    return True;
}
示例#23
0
文件: decorator.c 项目: micove/compiz
/*
 * draw_border_shape
 * Returns: void
 * Description: Draws a slight border around the decoration
 */
static void
draw_border_shape (Display	   *xdisplay,
		   Pixmap	   pixmap,
		   Picture	   picture,
		   int		   width,
		   int		   height,
		   decor_context_t *c,
		   void		   *closure)
{
    static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
    decor_t		d;
    decor_shadow_info_t *info = (decor_shadow_info_t *) closure;
    double		save_decoration_alpha;
    GdkScreen           *screen;

    memset (&d, 0, sizeof (d));

    if (info)
    {
	gwd_decor_frame_ref (info->frame);

	d.frame = info->frame;
	d.state = info->state;
	d.actions = info->active;
    }
    else
    {
	d.frame = gwd_get_decor_frame ("normal");
	d.state = 0;
	d.active = TRUE;
    }

    screen = gdk_screen_get_default ();

    d.surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen),
                                           pixmap,
                                           GDK_VISUAL_XVISUAL (gdk_screen_get_rgba_visual (screen)),
                                           width,
                                           height);
    d.width   = width;
    d.height  = height;
    d.active  = TRUE;
    d.draw    = theme_draw_window_decoration;
    d.picture = picture;
    d.context = c;

    /* we use closure argument if maximized */
    if (info)
	d.state = info->state;
    else
	d.state = 0;

    decor_get_default_layout (c, 1, 1, &d.border_layout);

    /* create shadow from opaque decoration
     * FIXME: Should not modify settings value
     * like this */
    save_decoration_alpha = decoration_alpha;
    decoration_alpha = 1.0;

    (*d.draw) (&d);

    decoration_alpha = save_decoration_alpha;

    XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white,
			  c->left_space,
			  c->top_space,
			  width - c->left_space - c->right_space,
			  height - c->top_space - c->bottom_space);

    if (!info)
	gwd_decor_frame_unref (d.frame);

    cairo_surface_destroy (d.surface);
}
示例#24
0
static void clear(struct test_display *dpy, struct test_target *tt)
{
	XRenderColor render_color = {0};
	XRenderFillRectangle(dpy->dpy, PictOpClear, tt->picture, &render_color,
			     0, 0, tt->width, tt->height);
}
示例#25
0
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
{
    if (from.isNull() && to.isNull()) {
        return from;
    }

    if (qFuzzyCompare(amount + 1, qreal(1.0))) {
        return from;
    }

    QRect startRect(from.rect());
    QRect targetRect(to.rect());
    QSize pixmapSize = startRect.size().expandedTo(targetRect.size());
    QRect toRect = QRect(QPoint(0,0), pixmapSize);
    targetRect.moveCenter(toRect.center());
    startRect.moveCenter(toRect.center());

    //paint to in the center of from
    QColor color;
    color.setAlphaF(amount);

    // If the native paint engine supports Porter/Duff compositing and CompositionMode_Plus
    QPaintEngine *paintEngine = from.paintEngine();
    if (paintEngine && 
        paintEngine->hasFeature(QPaintEngine::PorterDuff) &&
        paintEngine->hasFeature(QPaintEngine::BlendModes)) {
        QPixmap startPixmap(pixmapSize);
        startPixmap.fill(Qt::transparent);

        QPixmap targetPixmap(pixmapSize);
        targetPixmap.fill(Qt::transparent);

        QPainter p;
        p.begin(&targetPixmap);
        p.drawPixmap(targetRect, to);
        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(targetRect, color);
        p.end();

        p.begin(&startPixmap);
        p.drawPixmap(startRect, from);
        p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
        p.fillRect(startRect, color);
        p.setCompositionMode(QPainter::CompositionMode_Plus);
        p.drawPixmap(targetRect, targetPixmap);
        p.end();

        return startPixmap;
    }
#if defined(Q_WS_X11) && defined(HAVE_XRENDER)
    // We have Xrender support
    else if (paintEngine && paintEngine->hasFeature(QPaintEngine::PorterDuff)) {
        // QX11PaintEngine doesn't implement CompositionMode_Plus in Qt 4.3,
        // which we need to be able to do a transition from one pixmap to
        // another.
        //
        // In order to avoid the overhead of converting the pixmaps to images
        // and doing the operation entirely in software, this function has a
        // specialized path for X11 that uses Xrender directly to do the
        // transition. This operation can be fully accelerated in HW.
        //
        // This specialization can be removed when QX11PaintEngine supports
        // CompositionMode_Plus.
        QPixmap source(targetPixmap), destination(startPixmap);

        source.detach();
        destination.detach();

        Display *dpy = QX11Info::display();

        XRenderPictFormat *format = XRenderFindStandardFormat(dpy, PictStandardA8);
        XRenderPictureAttributes pa;
        pa.repeat = 1; // RepeatNormal

        // Create a 1x1 8 bit repeating alpha picture
        Pixmap pixmap = XCreatePixmap(dpy, destination.handle(), 1, 1, 8);
        Picture alpha = XRenderCreatePicture(dpy, pixmap, format, CPRepeat, &pa);
        XFreePixmap(dpy, pixmap);

        // Fill the alpha picture with the opacity value
        XRenderColor xcolor;
        xcolor.alpha = quint16(0xffff * amount);
        XRenderFillRectangle(dpy, PictOpSrc, alpha, &xcolor, 0, 0, 1, 1);

        // Reduce the alpha of the destination with 1 - opacity
        XRenderComposite(dpy, PictOpOutReverse, alpha, None, destination.x11PictureHandle(),
                         0, 0, 0, 0, 0, 0, destination.width(), destination.height());

        // Add source * opacity to the destination
        XRenderComposite(dpy, PictOpAdd, source.x11PictureHandle(), alpha,
                         destination.x11PictureHandle(),
                         toRect.x(), toRect.y(), 0, 0, 0, 0, destination.width(), destination.height());

        XRenderFreePicture(dpy, alpha);
        return destination;
    }
#endif
    else {
        // Fall back to using QRasterPaintEngine to do the transition.
        QImage under(pixmapSize, QImage::Format_ARGB32_Premultiplied);
        under.fill(Qt::transparent);
        QImage over(pixmapSize, QImage::Format_ARGB32_Premultiplied);
        over.fill(Qt::transparent);

        QPainter p;
        p.begin(&over);
        p.drawPixmap(targetRect, to);
        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        p.fillRect(over.rect(), color);
        p.end();

        p.begin(&under);
        p.drawPixmap(startRect, from);
        p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
        p.fillRect(startRect, color);
        p.setCompositionMode(QPainter::CompositionMode_Plus);
        p.drawImage(toRect.topLeft(), over);
        p.end();

        return QPixmap::fromImage(under);
    }
}
gboolean expose_parent(GtkWidget * widget, GdkEventExpose * event) {

    OMWeather *plugin = OMWEATHER(widget);
    GdkDrawable *drawable;
    gint x_offset, y_offset;
    XRenderColor color;
    Picture picture;
    XserverRegion region;
    cairo_t *cr;
    gint radius = 0;
    gint width, height, x, y;

    if (GTK_WIDGET_DRAWABLE(widget) == FALSE) {
        return FALSE;
    }

    gtk_widget_set_size_request(GTK_WIDGET(widget), -1, -1);
    gdk_window_get_internal_paint_info(widget->window, &drawable,
                                       &x_offset, &y_offset);


    picture = hildon_desktop_picture_from_drawable(drawable);

    if (picture == None) {
        return FALSE;
    }

    plugin->clip.x = event->area.x - x_offset;
    plugin->clip.y = event->area.y - y_offset;
    plugin->clip.width = event->area.width + x_offset;
    plugin->clip.height = event->area.height + y_offset;

    region = XFixesCreateRegion(GDK_DISPLAY(), &plugin->clip, 1);

    XFixesSetPictureClipRegion(GDK_DISPLAY(), picture, 0, 0, region);


    color.red = color.blue = color.green = 0;
    color.alpha = 0;

    XRenderFillRectangle(GDK_DISPLAY(), PictOpSrc, picture, &color,
                             0, 0,
                             widget->allocation.width,
                             widget->allocation.height);

    if (app->config->icons_layout < PRESET_NOW){
        radius = app->config->corner_radius;
        cr = gdk_cairo_create(drawable);
        cairo_set_source_rgba(cr,
                              (double)app->config->background_color.red /
                              (MAXSHORT * 2 + 1),
                              (double)app->config->background_color.green /
                              (MAXSHORT * 2 + 1),
                              (double)app->config->background_color.blue /
                              (MAXSHORT * 2 + 1),
                              (double)app->config->alpha_comp / 100);

        width = plugin->clip.width;
        height = plugin->clip.height;
        x = plugin->clip.x;
        y = plugin->clip.y;

        if ((radius > height / 2) || (radius > width / 2)) {
            if (width < height) {
                radius = width / 2 - 1;
            } else {
                radius = height / 2 - 2;
            }
        }

        cairo_move_to(cr, x + radius, y);
        cairo_line_to(cr, x + width - radius, y);
        cairo_curve_to(cr, x + width - radius, y, x + width, y, x + width,
                       y + radius);
        cairo_line_to(cr, x + width, y + height - radius);
        cairo_curve_to(cr, x + width, y + height - radius, x + width,
                       y + height, x + width - radius, y + height);
        cairo_line_to(cr, x + radius, y + height);
        cairo_curve_to(cr, x + radius, y + height, x, y + height, x,
                       y + height - radius);
        cairo_line_to(cr, x, y + radius);
        cairo_curve_to(cr, x, y + radius, x, y, x + radius, y);

        cairo_fill(cr);
        cairo_destroy(cr);
    }
    
    XFixesDestroyRegion(GDK_DISPLAY(), region);
    XRenderFreePicture(GDK_DISPLAY(), picture);

    if (plugin->queueRefresh) {
        redraw_home_window(TRUE);
        plugin->queueRefresh = FALSE;
    }

     
        
    return
        GTK_WIDGET_CLASS(g_type_class_peek_parent
                         (GTK_FRAME_GET_CLASS(widget)))->expose_event
        (widget, event);
}
示例#27
0
int backing_reconfigure(backing_t *backing, int width, int height, int depth)
{
    XRenderColor color;
    XRenderPictureAttributes attr;
    backing_t old_backing = *backing;

    backing->total_width = width;
    backing->total_height = height;
    backing->depth = depth;

    backing->root_pixmap = XCreatePixmap(backing->dpy, backing->root,
					 backing->total_width,
					 backing->total_height,
					 depth);
    attr.subwindow_mode = IncludeInferiors;
    backing->root_pict = XRenderCreatePicture(backing->dpy,
					      backing->root,
					      backing->root_format,
					      CPSubwindowMode,
					      &attr);

    backing->brush_pixmap = XCreatePixmap(backing->dpy, backing->root,
					  backing->total_width,
					  backing->total_height,
					  32);
    backing->brush_pict = XRenderCreatePicture(backing->dpy,
					       backing->brush_pixmap,
					       backing->brush_format,
					       0, 0);

    color.red = 0;
    color.green = 0;
    color.blue = 0;
    color.alpha = 0;
    XRenderFillRectangle(backing->dpy,
			 PictOpSrc, backing->brush_pict, &color,
			 0, 0, backing->total_width, backing->total_height);

    if (old_backing.root_pixmap) {
	if (old_backing.depth == depth) {
	    XCopyArea(backing->dpy, old_backing.root_pixmap,
		      backing->root_pixmap, backing->gc,
		      old_backing.x, old_backing.y,
		      old_backing.width, old_backing.height,
		      old_backing.x, old_backing.y);
	}
	XFreePixmap(old_backing.dpy, old_backing.root_pixmap);
	old_backing.root_pixmap = 0;
	XRenderFreePicture(old_backing.dpy, old_backing.root_pict);
	old_backing.root_pict = 0;
    }
    if (old_backing.brush_pixmap) {
	XRenderComposite(backing->dpy,
			 PictOpSrc,
			 old_backing.brush_pict, None, backing->brush_pict,
			 0, 0, 0, 0, 0, 0,
			 old_backing.total_width, old_backing.total_height);
	XFreePixmap(old_backing.dpy, old_backing.brush_pixmap);
	old_backing.brush_pixmap = 0;
	XRenderFreePicture(old_backing.dpy, old_backing.brush_pict);
	old_backing.brush_pict = 0;
    }

    return 0;
}
示例#28
0
void Thumbnail::redraw()
{
    int borderWidth = Settings::instance()->borderWidth();
    int headerHeight = Resources::instance()->headerMiddle()->height();
    int headerLeftWidth = Resources::instance()->headerLeft()->width();
    int headerRightWidth = Resources::instance()->headerRight()->width();

    int w = _clientScaledWidth;
    int h = _clientScaledHeight;

    bool selected = (!Settings::instance()->disableSelection())
                    && this == _teleWindow->activeThumbnail();
    const XRenderColor *borderColor = selected ?
                                      Resources::instance()->borderActiveColor() :
                                      Resources::instance()->borderColor();

    Picture left = selected ?
                   Resources::instance()->headerLeftSelected()->picture() :
                   Resources::instance()->headerLeft()->picture();
    Picture right = selected ?
                    Resources::instance()->headerRightSelected()->picture() :
                    Resources::instance()->headerRight()->picture();
    Picture middle = selected ?
                     Resources::instance()->headerMiddleSelected()->picture() :
                     Resources::instance()->headerMiddle()->picture();

    XRenderComposite(_dpy, PictOpSrc,
                     left, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX - borderWidth,
                     _clientOffsetY - headerHeight,
                     headerLeftWidth, headerHeight
                    );

    XRenderComposite(_dpy, PictOpSrc,
                     right, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX + w + borderWidth - headerRightWidth,
                     _clientOffsetY - headerHeight,
                     headerRightWidth, headerHeight
                    );

    XRenderComposite(_dpy, PictOpSrc,
                     middle, None, _image->picture(),
                     0, 0,
                     0, 0,
                     _clientOffsetX - borderWidth + headerLeftWidth,
                     _clientOffsetY - headerHeight,
                     w + 2 * borderWidth - headerLeftWidth - headerRightWidth,
                     headerHeight
                    );

    // Left border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX - borderWidth,
                         _clientOffsetY,
                         borderWidth, h
                        );
    // Right border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX + w,
                         _clientOffsetY,
                         borderWidth, h
                        );
    // Bottom border
    XRenderFillRectangle(_dpy, PictOpSrc, _image->picture(), borderColor,
                         _clientOffsetX - borderWidth,
                         _clientOffsetY + h,
                         w + 2*borderWidth, borderWidth
                        );


    // Drawing title text

    XftColor fontColor;
    fontColor.pixel = 0;
    fontColor.color.red     = 0xffff;
    fontColor.color.green   = 0xffff;
    fontColor.color.blue    = 0xffff;
    fontColor.color.alpha   = 0xffff;

    XRectangle rect = {
        _clientOffsetX - borderWidth + Settings::instance()->textLeftMargin(),
        _clientOffsetY - headerHeight,
        _clientScaledWidth + 2*borderWidth - Settings::instance()->textLeftMargin() - Settings::instance()->textRightMargin(),
        headerHeight
    };
    Region clip = XCreateRegion();
    XUnionRectWithRegion(&rect, clip, clip);

    XftDrawSetClip(_xftDraw, clip);

    XftDrawStringUtf8(_xftDraw, &fontColor, _teleWindow->xftFont(),
                      _clientOffsetX - borderWidth + Settings::instance()->textLeftMargin(),
                      _clientOffsetY + Settings::instance()->textYOffset(),
                      (const FcChar8*)_title,
                      strlen(_title)
                     );

    XDestroyRegion(clip);


    drawPreview();
}
示例#29
0
/*
 * draw_border_shape
 * Returns: void
 * Description: Draws a slight border around the decoration
 */
static void
draw_border_shape (Display	   *xdisplay,
		   Pixmap	   pixmap,
		   Picture	   picture,
		   int		   width,
		   int		   height,
		   decor_context_t *c,
		   void		   *closure)
{
    static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
    GdkColormap		*colormap;
    decor_t		d;
    decor_shadow_info_t *info = (decor_shadow_info_t *) closure;
    double		save_decoration_alpha;

    memset (&d, 0, sizeof (d));

    if (info)
    {
	gwd_decor_frame_ref (info->frame);

	d.frame = info->frame;
	d.state = info->state;
	d.actions = info->active;
    }
    else
    {
	d.frame = gwd_get_decor_frame ("normal");
	d.state = 0;
	d.active = TRUE;
    }

    d.pixmap  = gdk_pixmap_foreign_new_for_display (gdk_display_get_default (),
						    pixmap);
    d.width   = width;
    d.height  = height;
    d.active  = TRUE;
    d.draw    = theme_draw_window_decoration;
    d.picture = picture;
    d.context = c;

    /* we use closure argument if maximized */
    if (info)
	d.state = info->state;
    else
	d.state = 0;

    decor_get_default_layout (c, 1, 1, &d.border_layout);

    colormap = get_colormap_for_drawable (GDK_DRAWABLE (d.pixmap));
    gdk_drawable_set_colormap (d.pixmap, colormap);

    /* create shadow from opaque decoration
     * FIXME: Should not modify settings value
     * like this */
    save_decoration_alpha = decoration_alpha;
    decoration_alpha = 1.0;

    (*d.draw) (&d);

    decoration_alpha = save_decoration_alpha;

    XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white,
			  c->left_space,
			  c->top_space,
			  width - c->left_space - c->right_space,
			  height - c->top_space - c->bottom_space);

    if (!info)
	gwd_decor_frame_unref (d.frame);

    g_object_unref (G_OBJECT (d.pixmap));
}