BadMatch X_CreateWindow无法用visual通道创建窗口画图

来源:互联网 发布:php前景分析 编辑:程序博客网 时间:2024/06/10 23:43

上周花了两天时间,一直搞不懂为什么,今天接着弄,终于了解了点原因。先上我的测试例子:

 

 #include <stdio.h>
 #include <stdlib.h>
 #include <X11/Xlib.h>
 
 #include <X11/extensions/Xrender.h> //licl2012-06-05

 #define WINDOW_SIZE 200
 int main (int argc, char *argv[])
 {
  Display              *dpy;
  XSetWindowAttributes attributes;
  Window               win;
  GC                   gc;
  XKeyEvent event;
  int   i;
 
  int   nvi;//licl2012-06-05
  int   j;//licl2012-06-05
  XRenderPictFormat *format;//licl2012-06-05
  Visual  *visual = NULL;//licl2012-06-05
  XVisualInfo  *xvi;//licl2012-05-30
  XVisualInfo  temp;//licl2012-05-30

  // ... X Server.... X Server ......
  dpy = XOpenDisplay(NULL);

  // .. 200X200 .......
  attributes.background_pixel = XWhitePixel(dpy, 0); 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  temp.screen = DefaultScreen(dpy);
  temp.depth  = 32;
  temp.class  = TrueColor; 
 
  if ((xvi = XGetVisualInfo (dpy,
        VisualScreenMask |
        VisualDepthMask |
        VisualClassMask,
        &temp,
        &nvi)) == NULL)
        {
         printf(" failed geting VisualInfo\n");
         }
         else{
         printf(" succeeded geting VisualInfo\n");
          }
 
  for (j = 0; j < nvi; j++)
    {
     
     printf("  %3d: visual 0x%lx class %d (%s) depth %d\n",
             j,
             xvi[j].visualid,
             xvi[j].class,
             xvi[j].class == TrueColor ? "TrueColor" : "unknown",
             xvi[j].depth);
     
     
      format = XRenderFindVisualFormat (dpy, xvi[j].visual);
      if (format->type == PictTypeDirect && format->direct.alphaMask)
    {
      visual = xvi[j].visual;
      printf(" succeeded geting rgba visual\n");
      break;
    }
    }
 
 
 
 
 
 
 
 
 
  win = XCreateWindow(dpy, XRootWindow(dpy, 0),
      0, 0, WINDOW_SIZE, WINDOW_SIZE, 0,
      32,//DefaultDepth(dpy, 0),
      InputOutput,
      //DefaultVisual(dpy, 0),
      visual,
      CWBackPixel,&attributes);
  // .......
  XSelectInput(dpy, win, ExposureMask | KeyPressMask );
  // .......
  gc = XCreateGC(dpy, win, 0, NULL);
  //Map ..
  XMapWindow(dpy, win);
  // .......... Expose ... KeyPress ..
  while(1)
  {
    XNextEvent(dpy,(XEvent *)&event);
    switch(event.type)
    {
      // .. Expose ..
      case Expose:
        {
          // .. 100 ..
          for (i=0;i<WINDOW_SIZE/2;i++)
            XDrawPoint(dpy, win, gc, WINDOW_SIZE/4+i, WINDOW_SIZE/2);
        }break;
      // ......
      case KeyPress:
        {
          XFreeGC(dpy, gc);
          XCloseDisplay(dpy);
          exit(0);
        }break;
      default:
        {
        }break;
    }
  }
  return(0);
 }

 gcc -o hello1 hello1.c -I/usr/X11R6/include   -L/usr/X11R6/lib   -lX11 -lXcomposite -lXdamage -lXfixes -lXrender编译没有问题

运行报错

succeeded geting VisualInfo
    0: visual 0x41 class 4 (TrueColor) depth 32
 succeeded geting rgba visual
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  1 (X_CreateWindow)
  Serial number of failed request:  10
  Current serial number in output stream:  13

 

 在http://linux.die.net/man/3/xcreatewindow看到了这个

The border_width for an InputOnly window must be zero, or a BadMatch error results. For classInputOutput, the visual type and depth must be a combination supported for the screen, or aBadMatch error results. The depth need not be the same as the parent, but the parent must not be a window of classInputOnly, or aBadMatch error results. For anInputOnly window, the depth must be zero, and the visual must be one supported by the screen. If either condition is not met, aBadMatch error results. The parent window, however, may have any depth and class. If you specify any invalid window attribute for a window, aBadMatch error results.

如果我设置的属性没错,那么很可能是the visual type and depth must be a combination supported for the screen, or aBadMatch error results.这条不满足。参考了很多例子,由于对xlib变成不是很了解,刚学几天,实在无法完全确定我的属性、上下文完全没问题,但是由于主要代码都是参考现成例子,估计问题不大,预示先放一放,看看sreen的支持有没有问题。

将/etc/X11/xorg.conf.d/hi3716-fb.conf中改为DefaultDepth 32          Depth   32

启动x server

X.Org X Server 1.10.1
Release Date: 2011-04-15
X Protocol Version 11, Revision 0
Build Operating System: Linux 2.6.37.6-0.9-default armv7l
Current Operating System: Linux localhost.localdomain 2.6.35.7_hi3716m #3 Thu Mar 29 15:08:31 CST 2012 armv7l
Kernel command line: mem=224M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 mtdparts=hinand:1M(fastboot),5
M(kernel),224M(rootfs),-(other) mmz=ddr,0,0x8E000000,32M
Build Date: 19 January 2012  03:33:43PM
Build ID: xorg-x11-server 1.10.1-1.14.Mer
Current version of pixman: 0.23.1
        Before reporting problems, check http://wiki.x.org
        to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
        (++) from command line, (!!) notice, (II) informational,
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Thu Jan  1 00:10:30 1970
(==) Using config directory: "/etc/X11/xorg.conf.d"
(EE) FBDEV(0): Weight given (000) is inconsistent with the depth (32)
(EE) Screen(s) found, but none have a usable configuration.

Fatal server error:
no screens found

Please consult the The X.Org Foundation support
         at http://wiki.x.org
 for help.
Please also check the log file at "/var/log/Xorg.0.log" for additional information.


[1]+  Exit 1                  Xorg -noreset

FBDEV报错,没有sreen,也就是说,默认色深32位时,是找不到满足条件的sreen的!再打开log("/var/log/Xorg.0.log)

 

[   630.152]
X.Org X Server 1.10.1
Release Date: 2011-04-15
[   630.152] X Protocol Version 11, Revision 0
[   630.153] Build Operating System: Linux 2.6.37.6-0.9-default armv7l
[   630.153] Current Operating System: Linux localhost.localdomain 2.6.35.7_hi3716m #3 Thu Mar 29 15:08:31 CST 2012 armv7l
[   630.154] Kernel command line: mem=224M console=ttyAMA0,115200 root=/dev/mtdblock2 rootfstype=jffs2 mtdparts=hinand:1M(fastboot),5M(kernel),224M(rootfs),-(other) mmz=ddr,0,0x8E000000,32M
[   630.155] Build Date: 19 January 2012  03:33:43PM
[   630.155] Build ID: xorg-x11-server 1.10.1-1.14.Mer
[   630.155] Current version of pixman: 0.23.1
[   630.156]  Before reporting problems, check http://wiki.x.org
 to make sure that you have the latest version.
[   630.156] Markers: (--) probed, (**) from config file, (==) default setting,
 (++) from command line, (!!) notice, (II) informational,
 (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[   630.158] (==) Log file: "/var/log/Xorg.0.log", Time: Thu Jan  1 00:10:30 1970
[   630.159] (==) Using config directory: "/etc/X11/xorg.conf.d"
[   630.160] (==) No Layout section.  Using the first Screen section.
[   630.160] (**) |-->Screen "Default Screen" (0)
[   630.161] (**) |   |-->Monitor "<default monitor>"
[   630.162] (**) |   |-->Device "Configured Video Device"
[   630.162] (==) No monitor specified for screen "Default Screen".
 Using a default monitor configuration.
[   630.162] (==) Automatically adding devices
[   630.163] (==) Automatically enabling devices
[   630.164] (==) FontPath set to:
 catalogue:/etc/X11/fontpath.d,
 built-ins
[   630.164] (==) ModulePath set to "/usr/lib/xorg/modules"
[   630.164] (II) The server relies on udev to provide the list of input devices.
 If no devices become available, reconfigure udev or disable AutoAddDevices.
[   630.165] (II) Loader magic: 0x19de20
[   630.165] (II) Module ABI versions:
[   630.165]  X.Org ANSI C Emulation: 0.4
[   630.165]  X.Org Video Driver: 10.0
[   630.166]  X.Org XInput driver : 12.2
[   630.166]  X.Org Server Extension : 5.0
[   630.167] (II) LoadModule: "extmod"
[   630.168] (II) Loading /usr/lib/xorg/modules/extensions/libextmod.so
[   630.169] (II) Module extmod: vendor="X.Org Foundation"
[   630.170]  compiled for 1.10.1, module version = 1.0.0
[   630.170]  Module class: X.Org Server Extension
[   630.170]  ABI class: X.Org Server Extension, version 5.0
[   630.171] (II) Loading extension MIT-SCREEN-SAVER
[   630.171] (II) Loading extension XFree86-VidModeExtension
[   630.171] (II) Loading extension XFree86-DGA
[   630.171] (II) Loading extension DPMS
[   630.172] (II) Loading extension XVideo
[   630.173] (II) Loading extension XVideo-MotionCompensation
[   630.173] (II) Loading extension X-Resource
[   630.173] (II) LoadModule: "dbe"
[   630.174] (II) Loading /usr/lib/xorg/modules/extensions/libdbe.so
[   630.174] (II) Module dbe: vendor="X.Org Foundation"
[   630.175]  compiled for 1.10.1, module version = 1.0.0
[   630.175]  Module class: X.Org Server Extension
[   630.175]  ABI class: X.Org Server Extension, version 5.0
[   630.176] (II) Loading extension DOUBLE-BUFFER
[   630.177] (II) LoadModule: "glx"
[   630.177] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so
[   630.178] (II) Module glx: vendor="X.Org Foundation"
[   630.179]  compiled for 1.10.1, module version = 1.0.0
[   630.179]  ABI class: X.Org Server Extension, version 5.0
[   630.179] (==) AIGLX enabled
[   630.180] (II) Loading extension GLX
[   630.180] (II) LoadModule: "record"
[   630.181] (II) Loading /usr/lib/xorg/modules/extensions/librecord.so
[   630.182] (II) Module record: vendor="X.Org Foundation"
[   630.182]  compiled for 1.10.1, module version = 1.13.0
[   630.183]  Module class: X.Org Server Extension
[   630.183]  ABI class: X.Org Server Extension, version 5.0
[   630.183] (II) Loading extension RECORD
[   630.183] (II) LoadModule: "dri"
[   630.184] (II) Loading /usr/lib/xorg/modules/extensions/libdri.so
[   630.185] (II) Module dri: vendor="X.Org Foundation"
[   630.186]  compiled for 1.10.1, module version = 1.0.0
[   630.188]  ABI class: X.Org Server Extension, version 5.0
[   630.188] (II) Loading extension XFree86-DRI
[   630.188] (II) LoadModule: "dri2"
[   630.189] (II) Loading /usr/lib/xorg/modules/extensions/libdri2.so
[   630.190] (II) Module dri2: vendor="X.Org Foundation"
[   630.191]  compiled for 1.10.1, module version = 1.2.0
[   630.191]  ABI class: X.Org Server Extension, version 5.0
[   630.191] (II) Loading extension DRI2
[   630.192] (II) LoadModule: "fbdev"
[   630.192] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so
[   630.193] (II) Module fbdev: vendor="X.Org Foundation"
[   630.193]  compiled for 1.10.1, module version = 0.4.2
[   630.194]  ABI class: X.Org Video Driver, version 10.0
[   630.194] (II) FBDEV: driver for framebuffer: fbdev
[   630.195] (--) using VT number 2

[   630.195] (WW) Falling back to old probe method for fbdev
[   630.196] (II) Loading sub module "fbdevhw"
[   630.196] (II) LoadModule: "fbdevhw"
[   630.196] (II) Loading /usr/lib/xorg/modules/libfbdevhw.so
[   630.197] (II) Module fbdevhw: vendor="X.Org Foundation"
[   630.198]  compiled for 1.10.1, module version = 0.0.2
[   630.199]  ABI class: X.Org Video Driver, version 10.0
[   630.236] (II) Loading /usr/lib/xorg/modules/drivers/fbdev_drv.so
[   630.237] (II) Loading /usr/lib/xorg/modules/libfbdevhw.so
[   630.237] (II) FBDEV(0): using /dev/fb2
[   630.238] (WW) VGA arbiter: cannot open kernel arbiter, no multi-card support
[   630.259] (**) FBDEV(0): Depth 32, (--) framebuffer bpp 32
[   630.259] (EE) FBDEV(0): Weight given (000) is inconsistent with the depth (32)
[   630.259] (II) UnloadModule: "fbdev"
[   630.260] (II) Unloading fbdev
[   630.261] (II) UnloadModule: "fbdevhw"
[   630.261] (II) Unloading fbdevhw
[   630.261] (EE) Screen(s) found, but none have a usable configuration.
[   630.261]
Fatal server error:
[   630.262] no screens found
[   630.262]
Please consult the The X.Org Foundation support
  at http://wiki.x.org
 for help.
[   630.262] Please also check the log file at "/var/log/Xorg.0.log" for additional information.
[   630.263]

到这里已经很清楚了,加载fbdev模块失败,原因在这里

[   630.259] (**) FBDEV(0): Depth 32, (--) framebuffer bpp 32
[   630.259] (EE) FBDEV(0): Weight given (000) is inconsistent with the depth (32)

原创粉丝点击