SVN revision: 22470
This commit is contained in:
doursse 2006-05-06 06:23:53 +00:00 committed by doursse
parent 581b0aa703
commit 772a1de220
2 changed files with 204 additions and 151 deletions

View File

@ -1,13 +1,18 @@
#include <X11/XCB/xcb.h>
#include <X11/XCB/xcb_icccm.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <math.h> #include <math.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#define X_H /* make sure we aren't using symbols from X.h */
#include <X11/XCB/xcb.h>
#include <X11/XCB/xcb_icccm.h>
#include <X11/XCB/xcb_aux.h>
#include "Evas.h" #include "Evas.h"
#include "Evas_Engine_Software_Xcb.h" #include "Evas_Engine_Software_Xcb.h"
@ -19,60 +24,86 @@ Evas *evas = NULL;
int win_w = 240; int win_w = 240;
int win_h = 240; int win_h = 240;
XCBSCREEN *
get_screen (XCBConnection *c, static void
int screen) title_set (XCBConnection *c, XCBWINDOW win, const char *title)
{ {
XCBSCREENIter i; XCBInternAtomCookie cookie_encoding;
XCBInternAtomCookie cookie_property;
XCBInternAtomRep *rep;
XCBATOM encoding;
char *atom_name;
i = XCBConnSetupSuccessRepRootsIter(XCBGetSetup(c)); atom_name = "UTF8_STRING";
for (; i.rem; --screen, XCBSCREENNext(&i)) cookie_encoding = XCBInternAtom (c,
if (screen == 0) 0,
return i.data; strlen (atom_name),
atom_name);
atom_name = "_NET_WM_NAME";
cookie_property = XCBInternAtom (c,
0,
strlen (atom_name),
atom_name);
return NULL; rep = XCBInternAtomReply (c, cookie_encoding, NULL);
encoding = rep->atom;
free (rep);
rep = XCBInternAtomReply (c, cookie_property, NULL);
XCBChangeProperty(c, XCBPropModeReplace,
win,
rep->atom, encoding, 8, strlen (title), title);
free (rep);
} }
XCBVISUALTYPE * static void
get_visual(XCBConnection *conn, class_set (XCBConnection *c, XCBWINDOW win, const char *name, const char *class)
XCBSCREEN *root)
{ {
XCBDEPTH *d; XCBInternAtomCookie cookie_encoding;
XCBVISUALTYPEIter iter; XCBInternAtomCookie cookie_property;
int cur; XCBInternAtomRep *rep;
XCBATOM encoding;
char *atom_name;
char *class_str;
char *s;
int length_name;
int length_class;
d = XCBSCREENAllowedDepthsIter(root).data; length_name = strlen (name);
if (!d) return NULL; length_class = strlen (class);
class_str = (char *)malloc (sizeof (char) * (length_name + length_class + 2));
if (!class_str) return;
s = class_str;
memcpy (s, name, length_name);
s += length_name;
*s = '\0';
s++;
memcpy (s, class, length_class);
s += length_class;
*s = '\0';
iter = XCBDEPTHVisualsIter(d); atom_name = "UTF8_STRING";
for (cur = 0 ; cur < iter.rem ; XCBVISUALTYPENext(&iter), ++cur) cookie_encoding = XCBInternAtom (c,
if (root->root_visual.id == iter.data->visual_id.id) 0,
return iter.data; strlen (atom_name),
atom_name);
atom_name = "_WM_CLASS";
cookie_property = XCBInternAtom (c,
0,
strlen (atom_name),
atom_name);
return NULL; rep = XCBInternAtomReply (c, cookie_encoding, NULL);
} encoding = rep->atom;
free (rep);
int rep = XCBInternAtomReply (c, cookie_property, NULL);
get_depth(XCBConnection *conn,
XCBSCREEN *root)
{
XCBDRAWABLE drawable;
XCBGetGeometryRep *geom;
int depth;
drawable.window = root->root; XCBChangeProperty(c, XCBPropModeReplace,
geom = XCBGetGeometryReply (conn, XCBGetGeometry(conn, drawable), 0); win,
rep->atom, encoding, 8, strlen (class_str), class_str);
if(!geom) free (rep);
{
perror ("GetGeometry(root) failed");
exit (0);
}
depth = geom->depth;
free (geom);
return depth;
} }
int int
@ -84,7 +115,6 @@ main(int argc, char **argv)
XCBGenericEvent *e; XCBGenericEvent *e;
CARD32 mask = 0; CARD32 mask = 0;
CARD32 value[6]; CARD32 value[6];
/* XClassHint chint; */
SizeHints *szhints; SizeHints *szhints;
int screen_nbr; int screen_nbr;
@ -95,34 +125,33 @@ main(int argc, char **argv)
exit(-1); exit(-1);
} }
screen = get_screen (c, screen_nbr); screen = XCBAuxGetScreen (c, screen_nbr);
mask = CWBackingStore | CWColormap | mask =
CWBackPixmap | CWBorderPixel | XCBCWBackPixmap | XCBCWBorderPixel |
CWBitGravity | CWEventMask; XCBCWBitGravity | XCBCWBackingStore |
XCBCWEventMask | XCBCWColormap;
value[0] = None; value[0] = XCBBackPixmapNone;
value[1] = 0; value[1] = 0;
value[2] = ForgetGravity; value[2] = XCBGravityBitForget;
value[3] = NotUseful; value[3] = XCBBackingStoreNotUseful;
value[4] = ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; value[4] = XCBEventMaskExposure | XCBEventMaskButtonPress | XCBEventMaskButtonRelease | XCBEventMaskPointerMotion;
value[5] = screen->default_colormap.xid; value[5] = screen->default_colormap.xid;
win.window = XCBWINDOWNew(c); win.window = XCBWINDOWNew(c);
XCBCreateWindow (c, XCBCreateWindow (c,
get_depth(c, screen), XCBAuxGetDepth(c, screen),
win.window, screen->root, win.window, screen->root,
0, 0, 0, 0,
win_w, win_h, win_w, win_h,
0, 0,
InputOutput, XCBWindowClassInputOutput,
screen->root_visual, screen->root_visual,
mask, value); mask, value);
/* XStoreName(disp, win, "Evas Performance Test"); */ title_set (c, win.window, "Evas XCB Performance Test");
/* chint.res_name = "Evas_Test"; */ class_set (c, win.window, "Evas_XCB_Perf_Test", "Main");
/* chint.res_class = "Main"; */
/* XSetClassHint(disp, win, &chint); */
szhints = AllocSizeHints(); szhints = AllocSizeHints();
SizeHintsSetMinSize(szhints, win_w, win_h); SizeHintsSetMinSize(szhints, win_w, win_h);
@ -145,10 +174,10 @@ main(int argc, char **argv)
/* the following is specific to the engine */ /* the following is specific to the engine */
einfo->info.conn = c; einfo->info.conn = c;
einfo->info.visual = get_visual (c, screen); einfo->info.visual = XCBAuxGetVisualtype(c, screen_nbr, screen->root_visual);
einfo->info.colormap = screen->default_colormap; einfo->info.colormap = screen->default_colormap;
einfo->info.drawable = win; einfo->info.drawable = win;
einfo->info.depth = get_depth(c, screen); einfo->info.depth = XCBAuxGetDepth(c, screen);
einfo->info.rotation = 0; einfo->info.rotation = 0;
evas_engine_info_set(evas, (Evas_Engine_Info *) einfo); evas_engine_info_set(evas, (Evas_Engine_Info *) einfo);
@ -162,25 +191,25 @@ main(int argc, char **argv)
{ {
switch (e->response_type) switch (e->response_type)
{ {
case ButtonPress: { case XCBButtonPress: {
XCBButtonPressEvent *ev = (XCBButtonPressEvent *)e; XCBButtonPressEvent *ev = (XCBButtonPressEvent *)e;
/* evas_event_button_down(evas, ev->event_x, ev->event_y, ev->detail.id);*/ /* evas_event_button_down(evas, ev->event_x, ev->event_y, ev->detail.id);*/
break; break;
} }
case ButtonRelease: { case XCBButtonRelease: {
XCBButtonReleaseEvent *ev = (XCBButtonReleaseEvent *)e; XCBButtonReleaseEvent *ev = (XCBButtonReleaseEvent *)e;
/* evas_event_button_up(evas, ev->event_x, ev->event_y, ev->detail.id);*/ /* evas_event_button_up(evas, ev->event_x, ev->event_y, ev->detail.id);*/
break; break;
} }
case MotionNotify: { case XCBMotionNotify: {
XCBMotionNotifyEvent *ev = (XCBMotionNotifyEvent *)e; XCBMotionNotifyEvent *ev = (XCBMotionNotifyEvent *)e;
/* evas_event_move(evas, ev->event_x, ev->event_y);*/ /* evas_event_move(evas, ev->event_x, ev->event_y);*/
break; break;
} }
case Expose: { case XCBExpose: {
XCBExposeEvent *ev = (XCBExposeEvent *)e; XCBExposeEvent *ev = (XCBExposeEvent *)e;
exposed = 1; exposed = 1;
@ -214,10 +243,10 @@ main(int argc, char **argv)
(Evas_Engine_Info_Software_Xcb *) evas_engine_info_get(evas); (Evas_Engine_Info_Software_Xcb *) evas_engine_info_get(evas);
perf = perf =
einfo->func.performance_new(evas, c, einfo->func.performance_new(evas, c,
get_visual (c, screen), XCBAuxGetVisualtype(c, screen_nbr, screen->root_visual),
screen->default_colormap, screen->default_colormap,
win, win,
get_depth(c, screen)); XCBAuxGetDepth(c, screen));
key = einfo->func.performance_key_get(perf); key = einfo->func.performance_key_get(perf);
snprintf(buf, sizeof(buf), "%s/.evas/%s", getenv("HOME"), key); snprintf(buf, sizeof(buf), "%s/.evas/%s", getenv("HOME"), key);
free(key); free(key);

View File

@ -1,94 +1,112 @@
#include "evas_test_main.h" #include "evas_test_main.h"
#include <unistd.h> #include <unistd.h>
#define X_H /* make sure we aren't using symbols from X.h */
#include <X11/XCB/xcb.h> #include <X11/XCB/xcb.h>
#include <X11/XCB/shm.h>
#include <X11/XCB/render.h>
#include <X11/XCB/xcb_aux.h>
#include "Evas.h" #include "Evas.h"
#include "Evas_Engine_XRender_Xcb.h" #include "Evas_Engine_XRender_Xcb.h"
XCBSCREEN * static void
get_screen (XCBConnection *c, title_set (XCBConnection *c, XCBWINDOW win, const char *title)
int screen)
{ {
XCBSCREENIter iter; XCBInternAtomCookie cookie_encoding;
XCBInternAtomCookie cookie_property;
XCBInternAtomRep *rep;
XCBATOM encoding;
char *atom_name;
iter = XCBConnSetupSuccessRepRootsIter (XCBGetSetup (c));
for (; iter.rem; --screen, XCBSCREENNext (&iter))
if (screen == 0)
return iter.data;
return NULL;
}
int
get_depth(XCBConnection *conn,
XCBSCREEN *root)
{
XCBDRAWABLE drawable;
XCBGetGeometryRep *geom;
int depth;
drawable.window = root->root;
geom = XCBGetGeometryReply (conn, XCBGetGeometry(conn, drawable), 0);
if(!geom)
{
perror ("GetGeometry(root) failed");
exit (0);
}
depth = geom->depth;
free (geom);
return depth;
}
static void title_set (XCBConnection *conn, XCBWINDOW window, const char *title)
{
XCBInternAtomRep *rep;
XCBATOM encoding;
char *atom_name;
/* encoding */
atom_name = "UTF8_STRING"; atom_name = "UTF8_STRING";
rep = XCBInternAtomReply (conn, cookie_encoding = XCBInternAtom (c,
XCBInternAtom (conn, 0,
0, strlen (atom_name),
strlen (atom_name), atom_name);
atom_name), atom_name = "_NET_WM_NAME";
NULL); cookie_property = XCBInternAtom (c,
0,
strlen (atom_name),
atom_name);
rep = XCBInternAtomReply (c, cookie_encoding, NULL);
encoding = rep->atom; encoding = rep->atom;
free (rep); free (rep);
/* ICCCM */ rep = XCBInternAtomReply (c, cookie_property, NULL);
/* SetWMName (f->xcb.c, f->xcb.draw.window, encoding, strlen (title), title); */
/* NETWM */ XCBChangeProperty(c, XCBPropModeReplace,
atom_name = "_NET_WM_NAME"; win,
rep = XCBInternAtomReply (conn,
XCBInternAtom (conn,
0,
strlen (atom_name),
atom_name),
NULL);
XCBChangeProperty(conn, PropModeReplace,
window,
rep->atom, encoding, 8, strlen (title), title); rep->atom, encoding, 8, strlen (title), title);
free (rep); free (rep);
} }
static void
class_set (XCBConnection *c, XCBWINDOW win, const char *name, const char *class)
{
XCBInternAtomCookie cookie_encoding;
XCBInternAtomCookie cookie_property;
XCBInternAtomRep *rep;
XCBATOM encoding;
char *atom_name;
char *class_str;
char *s;
int length_name;
int length_class;
length_name = strlen (name);
length_class = strlen (class);
class_str = (char *)malloc (sizeof (char) * (length_name + length_class + 2));
if (!class_str) return;
s = class_str;
memcpy (s, name, length_name);
s += length_name;
*s = '\0';
s++;
memcpy (s, class, length_class);
s += length_class;
*s = '\0';
atom_name = "UTF8_STRING";
cookie_encoding = XCBInternAtom (c,
0,
strlen (atom_name),
atom_name);
atom_name = "_WM_CLASS";
cookie_property = XCBInternAtom (c,
0,
strlen (atom_name),
atom_name);
rep = XCBInternAtomReply (c, cookie_encoding, NULL);
encoding = rep->atom;
free (rep);
rep = XCBInternAtomReply (c, cookie_property, NULL);
XCBChangeProperty(c, XCBPropModeReplace,
win,
rep->atom, encoding, 8, strlen (class_str), class_str);
free (rep);
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int pause_me = 0; int pause_me = 0;
XCBConnection *conn; XCBConnection *conn;
XCBSCREEN *screen; const XCBQueryExtensionRep *rep_shm;
XCBDRAWABLE win; const XCBQueryExtensionRep *rep_xrender;
XCBGenericEvent *e; XCBSCREEN *screen;
CARD32 mask; XCBDRAWABLE win;
CARD32 value[6]; XCBGenericEvent *e;
int screen_nbr; CARD32 mask;
CARD32 value[6];
int screen_nbr;
conn = XCBConnect (NULL, &screen_nbr); conn = XCBConnect (NULL, &screen_nbr);
if (!conn) if (!conn)
@ -97,31 +115,37 @@ main(int argc, char **argv)
exit(-1); exit(-1);
} }
screen = get_screen (conn, screen_nbr); XCBPrefetchExtensionData (conn, &XCBShmId);
XCBPrefetchExtensionData (conn, &XCBRenderId);
rep_shm = XCBGetExtensionData(conn, &XCBShmId);
rep_xrender = XCBGetExtensionData(conn, &XCBRenderId);
screen = XCBAuxGetScreen (conn, screen_nbr);
mask = mask =
XCBCWBackingStore | XCBCWColormap | XCBCWBackPixmap | XCBCWBorderPixel |
XCBCWBackPixmap | XCBCWBorderPixel | XCBCWBitGravity | XCBCWBackingStore |
XCBCWBitGravity | XCBCWEventMask; XCBCWEventMask | XCBCWColormap;
value[0] = None; value[0] = XCBBackPixmapNone;
value[1] = 0; value[1] = 0;
value[2] = ForgetGravity; value[2] = XCBGravityBitForget;
value[3] = NotUseful; value[3] = XCBBackingStoreNotUseful;
value[4] = ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask; value[4] = XCBEventMaskExposure | XCBEventMaskButtonPress | XCBEventMaskButtonRelease | XCBEventMaskPointerMotion | XCBEventMaskStructureNotify;
value[5] = screen->default_colormap.xid; value[5] = screen->default_colormap.xid;
win.window = XCBWINDOWNew(conn); win.window = XCBWINDOWNew(conn);
XCBCreateWindow (conn, XCBCreateWindow (conn,
get_depth(conn, screen), XCBAuxGetDepth(conn, screen),
win.window, screen->root, win.window, screen->root,
0, 0, 0, 0,
win_w, win_h, win_w, win_h,
0, 0,
InputOutput, XCBWindowClassInputOutput,
screen->root_visual, screen->root_visual,
mask, value); mask, value);
title_set (conn, win.window, "Evas XRender Xcb Test"); title_set (conn, win.window, "Evas XRender Xcb Test");
class_set (conn, win.window, "Evas_XRender_XCB_Test", "Main");
#if 0 #if 0
szhints.flags = PMinSize | PMaxSize | PSize | USSize; szhints.flags = PMinSize | PMaxSize | PSize | USSize;
szhints.min_width = szhints.max_width = win_w; szhints.min_width = szhints.max_width = win_w;
@ -196,7 +220,7 @@ main(int argc, char **argv)
evas_event_feed_mouse_move(evas, ev->event_x, ev->event_y, 0, NULL); evas_event_feed_mouse_move(evas, ev->event_x, ev->event_y, 0, NULL);
break; break;
} }
case Expose: { case XCBExpose: {
XCBExposeEvent *ev = (XCBExposeEvent *)e; XCBExposeEvent *ev = (XCBExposeEvent *)e;
evas_damage_rectangle_add(evas, evas_damage_rectangle_add(evas,
@ -206,7 +230,7 @@ main(int argc, char **argv)
ev->height); ev->height);
break; break;
} }
case ConfigureNotify: { case XCBConfigureNotify: {
XCBConfigureNotifyEvent *ev = (XCBConfigureNotifyEvent *)e; XCBConfigureNotifyEvent *ev = (XCBConfigureNotifyEvent *)e;
evas_output_size_set(evas, evas_output_size_set(evas,