[Freeciv-Dev] Re: (PR#7331) Speeding up the map view
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7331 >
On Sun, Feb 01, 2004 at 10:37:04AM -0800, Raimar Falke wrote:
> So I searched for an alternative way to get the performance. The
> XRender extension seems like a good candidate. It is server only AFAI
> tell. But there no f***ing docu on the net except a short presentation
> and undocumented header files. I have managed to produce a short
> example program for testing. It looks like it works. The next step is
> to implement in the FS client and measure its speed.
This this was hard to puzzle together I attach it.
gcc -Wall -L/usr/X11R6/lib -lX11 -lXrender render_test.c
Raimar
--
email: rf13@xxxxxxxxxxxxxxxxx
"Like the ad says, at 300 dpi you can tell she's wearing a
swimsuit. At 600 dpi you can tell it's wet. At 1200 dpi you
can tell it's painted on. I suppose at 2400 dpi you can tell
if the paint is giving her a rash."
-- Joshua R. Poulson
#include <X11/Xlib.h>
#include <X11/extensions/Xrender.h>
Pixmap color_pix,alpha_pix;
Picture pict_color1, pict_color2, pict_win, pict_alpha;
Window window;
Display *dpy;
int screen;
Visual *visual;
XRenderPictFormat *format_win, *format_pix, *format_alpha;
unsigned long color_green;
#define SIZE 200
int main(void)
{
XEvent ev;
dpy = XOpenDisplay(0);
if (!dpy) exit(1);
screen = DefaultScreen(dpy);
visual = DefaultVisual(dpy, screen);
window = XCreateSimpleWindow(dpy, RootWindow(dpy, screen),
0, 0, SIZE, SIZE, 1, BlackPixel(dpy,
screen),
WhitePixel(dpy, screen));
{
XColor mycolor;
mycolor.red = 0x0000;
mycolor.green = 0xffff;
mycolor.blue = 0x0000;
if (!XAllocColor
(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), &mycolor)) {
exit(1);
}
color_green = mycolor.pixel;
}
//XSynchronize(dpy, 1);
{
format_win = XRenderFindVisualFormat(dpy, visual);
if (!format_win)
exit(1);
}
{
XRenderPictFormat pf;
pf.depth = 32;
pf.type = PictTypeDirect;
pf.direct.alpha = 24;
pf.direct.alphaMask = 0xff;
pf.direct.red = 16;
pf.direct.redMask = 0xff;
pf.direct.green = 8;
pf.direct.greenMask = 0xff;
pf.direct.blue = 0;
pf.direct.blueMask = 0xff;
format_pix = XRenderFindFormat(dpy,
PictFormatType |
PictFormatDepth |
PictFormatRed |
PictFormatRedMask |
PictFormatGreen |
PictFormatGreenMask |
PictFormatBlue |
PictFormatBlueMask |
PictFormatAlpha |
PictFormatAlphaMask, &pf, 0);
if (!format_pix)
exit(1);
}
{
XRenderPictFormat pf;
pf.type = PictTypeDirect;
pf.depth = 8;
pf.direct.alphaMask = 0xff;
format_alpha = XRenderFindFormat(dpy,
PictFormatType |
PictFormatDepth |
PictFormatAlphaMask, &pf, 0);
if (!format_alpha)
exit(1);
}
pict_win = XRenderCreatePicture(dpy, window, format_win, 0, 0);
{
XRenderPictureAttributes pa;
color_pix = XCreatePixmap(dpy, window, 1, 1, 32);
pa.repeat = True;
pict_color1 =
XRenderCreatePicture(dpy, color_pix, format_pix, CPRepeat, &pa);
}
{
XRenderPictureAttributes pa;
alpha_pix = XCreatePixmap(dpy, window, 1, 1, 8);
pa.repeat = True;
pict_alpha =
XRenderCreatePicture(dpy, alpha_pix, format_alpha, CPRepeat, &pa);
}
XSelectInput(dpy, window, ExposureMask);
XMapWindow(dpy, window);
for (;;) {
XNextEvent(dpy, &ev);
if (ev.type == Expose && ev.xexpose.count == 0) {
XRenderColor rc;
rc.red = 0xffff;
rc.green = 0x0;
rc.blue = 0x0;
rc.alpha = 0xC000;
XClearArea(dpy, window, 0, 0, 0, 0, False);
{
XGCValues values;
GC gc;
values.graphics_exposures = False;
values.foreground = color_green;
gc = XCreateGC(dpy, window,
GCForeground | GCGraphicsExposures, &values);
XFillRectangle(dpy, window, gc, 10, 10, 150, 150);
XFreeGC(dpy, gc);
}
XRenderFillRectangle(dpy, PictOpSrc, pict_color1, &rc, 0, 0, 1, 1);
XRenderComposite(dpy,
PictOpOver,
pict_color1, pict_alpha, pict_win, /* src, mask, dest */
0, 0,
0, 0,
30, 20,
SIZE, SIZE);
}
}
}
|
|