static void Initialize( struct state *st ) { XGCValues gcValues; XWindowAttributes XWinAttribs; /*int iBitsPerPixel;*/ /* Create the Image for drawing */ XGetWindowAttributes( st->dpy, st->window, &XWinAttribs ); #if 0 /* Find the preferred bits-per-pixel. (jwz) */ { int i, pfvc = 0; XPixmapFormatValues *pfv = XListPixmapFormats( st->dpy, &pfvc ); for( i=0; i<pfvc; i++ ) if( pfv[ i ].depth == XWinAttribs.depth ) { iBitsPerPixel = pfv[ i ].bits_per_pixel; break; } if( pfv ) XFree (pfv); } #endif /* Create the GC. */ st->gc = XCreateGC( st->dpy, st->window, 0, &gcValues ); st->pImage = XCreateImage( st->dpy, XWinAttribs.visual, XWinAttribs.depth, ZPixmap, 0, NULL, XWinAttribs.width, XWinAttribs.height, 8 /*BitmapPad( st->dpy )*/, 0 ); st->pImage->data = calloc((st->pImage)->bytes_per_line, (st->pImage)->height); st->iWinWidth = XWinAttribs.width; st->iWinHeight = XWinAttribs.height; /* These are precalculations used in Execute(). */ st->iBobDiameter = ( ( st->iWinWidth < st->iWinHeight ) ? st->iWinWidth : st->iWinHeight ) / 25; st->iBobRadius = st->iBobDiameter / 2; #ifdef VERBOSE printf( "%s: Bob Diameter = %d\n", progname, st->iBobDiameter ); #endif st->iWinCenterX = ( XWinAttribs.width / 2 ) - st->iBobRadius; st->iWinCenterY = ( XWinAttribs.height / 2 ) - st->iBobRadius; st->iVelocity = ( ( st->iWinWidth < st->iWinHeight ) ? st->iWinWidth : st->iWinHeight ) / 150; /* Create the Sin and Cosine lookup tables. */ st->iDegreeCount = get_integer_resource(st->dpy, "degrees", "Integer" ); if( st->iDegreeCount == 0 ) st->iDegreeCount = ( XWinAttribs.width / 6 ) + 400; else if( st->iDegreeCount < 90 ) st->iDegreeCount = 90; else if( st->iDegreeCount > 5400 ) st->iDegreeCount = 5400; CreateTables( st, st->iDegreeCount ); #ifdef VERBOSE printf( "%s: Using a %d degree circle.\n", progname, st->iDegreeCount ); #endif /* VERBOSE */ /* Get the base color. */ st->sColor = get_string_resource(st->dpy, "color", "Color" ); }
static Visual* I_FindMode(int screen) { XVisualInfo X_visualinfo; int i; const int nice_depths[]={ 8, 16, 15, 32, 24, 0}; // 0 terminated XPixmapFormatValues *pfv; int npfv; fprintf(stderr, "I_FindMode: "); for (i=0; nice_depths[i]!=0; i++) { dest_bpp = nice_depths[i]; if (I_QueryImageTranslation()) { if (XMatchVisualInfo(X_display, screen, dest_bpp, true_color ? TrueColor : PseudoColor, &X_visualinfo)) break; if (devparm) I_PrintMode("no visual like:"); } else if (devparm) I_PrintMode("no translation to:"); } if (nice_depths[i] == 0) I_Error("Unable to find supported visual settings"); X_bpp = dest_bpp; if ((dest_bpp == 24) && (X_opt & 2)) dest_bpp = 32; // kludge for 24bpp /* find out whether depth 24 is sparse or packed */ pfv=XListPixmapFormats(X_display,&npfv); if(pfv) { for(i=0;i<npfv;i++) if(pfv[i].depth==dest_bpp) break; if(i<npfv) { dest_bpp=pfv[i].bits_per_pixel; fprintf(stderr,"(Depth %d / %d BPP) ",X_bpp,dest_bpp); } else fprintf(stderr,"(Depth %d: no pixfmt?) ",dest_bpp); XFree(pfv); } I_InitImageTranslation(); if (true_color) { // Set up colour shifts I_SetColourShift(X_visualinfo.red_mask, &redshift); I_SetColourShift(X_visualinfo.green_mask, &greenshift); I_SetColourShift(X_visualinfo.blue_mask, &blueshift); } I_PrintMode("using"); return X_visualinfo.visual; }
static int setup_display() { int depth, i, formatCount, convDepth = -1; XPixmapFormatValues* formats; if (s_setup_done) { return 1; } s_display = XOpenDisplay(0); if (!s_display) { printf("Unable to open X11 display\n"); return 0; } s_context = XUniqueContext(); s_screen = DefaultScreen(s_display); s_visual = DefaultVisual(s_display, s_screen); formats = XListPixmapFormats(s_display, &formatCount); depth = DefaultDepth(s_display, s_screen); for (i = 0; i < formatCount; ++i) { if (depth == formats[i].depth) { convDepth = formats[i].bits_per_pixel; break; } } XFree(formats); // We only support 32-bit right now if (convDepth != 32) { printf("Unable to find 32-bit format for X11 display\n"); XCloseDisplay(s_display); return 0; } s_depth = depth; s_gc = DefaultGC(s_display, s_screen); s_screen_width = DisplayWidth(s_display, s_screen); s_screen_height = DisplayHeight(s_display, s_screen); const char* wmDeleteWindowName = "WM_DELETE_WINDOW"; XInternAtoms(s_display, (char**)&wmDeleteWindowName, 1, False, &s_wm_delete_window); s_setup_done = 1; return 1; }
static int get_idepth( void) { int i, n; XPixmapFormatValues *format = XListPixmapFormats( DISP, &n); int idepth = guts.depth; if ( !format) return guts.depth; for ( i = 0; i < n; i++) if ( format[i]. depth == guts. depth) { idepth = format[i]. bits_per_pixel; break; } XFree( format); return idepth; }
int schro_opengl_connect (SchroOpenGL * display, const char *display_name) { int usable; XGCValues values; XPixmapFormatValues *px_formats; int n_formats; int i; display->display = XOpenDisplay (display_name); if (display->display == NULL) { return FALSE; } #ifdef HANDLE_X_ERRORS XSynchronize (display->display, True); XSetErrorHandler (x_error_handler); #endif usable = schro_opengl_check_features (display); if (!usable) { return FALSE; } display->screen = DefaultScreenOfDisplay (display->display); display->screen_num = DefaultScreen (display->display); display->visual = DefaultVisual (display->display, display->screen_num); display->root = DefaultRootWindow (display->display); display->white = XWhitePixel (display->display, display->screen_num); display->black = XBlackPixel (display->display, display->screen_num); display->depth = DefaultDepthOfScreen (display->screen); display->gc = XCreateGC (display->display, DefaultRootWindow (display->display), 0, &values); px_formats = XListPixmapFormats (display->display, &n_formats); for (i = 0; i < n_formats; i++) { SCHRO_ERROR ("%d: depth %d bpp %d pad %d", i, px_formats[i].depth, px_formats[i].bits_per_pixel, px_formats[i].scanline_pad); } schro_opengl_init_tmp_window (display); return TRUE; }
int _get_visinfo(Display *disp) { XVisualInfo *vi_in=NULL, vi_out; int nvis, i, j, n, ret=0; unsigned depth, tmp; if(!_rshft && !_gshft && !_bshft) { vi_out.screen = DefaultScreen(disp); vi_out.depth = DefaultDepth(disp, vi_out.screen); vi_in = XGetVisualInfo(disp, VisualScreenMask|VisualDepthMask, &vi_out, &nvis); if(vi_in) { for(i=0; i<nvis; i++) { XPixmapFormatValues *pf = XListPixmapFormats(disp, &n); if(!pf) continue; depth = vi_in[i].depth; _dbpp = 0; for(j=0; j<n; j++) { if(pf[j].depth == depth) { _dbpp = pf[j].bits_per_pixel; break; } } if(j==n) continue; _rmask = vi_in[i].red_mask; for(_rshft=0, tmp=_rmask; !(tmp&0x1); _rshft++, tmp>>=1); for(_rbits=0, tmp=_rmask; tmp; _rbits++) tmp &= tmp-1; _gmask = vi_in[i].green_mask; for(_gshft=0, tmp=_gmask; !(tmp&0x1); _gshft++, tmp>>=1); for(_gbits=0, tmp=_gmask; tmp; _gbits++) tmp &= tmp-1; _bmask = vi_in[i].blue_mask; for(_bshft=0, tmp=_bmask; !(tmp&0x1); _bshft++, tmp>>=1); for(_bbits=0, tmp=_bmask; tmp; _bbits++) tmp &= tmp-1; break; } } else
static int xwchkbpp(struct fb* fb, int depth) { int i; int count; XPixmapFormatValues *pixmap_formats; pixmap_formats = XListPixmapFormats(fb->hw->display, &count); for(i = 0; i < count; i++) { if(depth == pixmap_formats[i].depth) { if(pixmap_formats[i].bits_per_pixel == 32) { XFree(pixmap_formats); return 0; } } } XFree(pixmap_formats); printf("depths other than 32bpp are not supported\n"); return -1; }
void mainloop(StarfishRef tex) { char *buf; int bpl; int n_pmf; int i; XPixmapFormatValues * pmf; pmf = XListPixmapFormats (display, &n_pmf); if (pmf) { for (i = 0; i < n_pmf; i++) { if (pmf[i].depth == depth) { int pad, pad_bytes; bpp = pmf[i].bits_per_pixel; bpl = width * bpp / 8; pad = pmf[i].scanline_pad; pad_bytes = pad / 8; /* make bpl a whole multiple of pad/8 */ bpl = (bpl + pad_bytes - 1) & ~(pad_bytes - 1); buf=malloc(height*bpl); image=XCreateImage(display,DefaultVisual(display,screen), depth, ZPixmap,0,buf,width,height,pad,bpl); if(!image) { puts("starfish: XCreateImage failed"); return; } break; } } XFree ((char *) pmf); } if (! XInitImage(image)) return; fillimage(tex); XSetWindowBackgroundImage(display, rootwin, image); XDestroyImage(image); }
int x11_get_pixelsize(const GUI *gui) { Screen *screen = DefaultScreenOfDisplay(gui->xstuff->disp); int i, n; XPixmapFormatValues *pmf; int pixel_size = 0; pmf = XListPixmapFormats(DisplayOfScreen(screen), &n); if (pmf) { for (i = 0; i < n; i++) { if (pmf[i].depth == PlanesOfScreen(screen)) { pixel_size = pmf[i].bits_per_pixel/8; break; } } XFree((char *) pmf); } return pixel_size; }
static int get_visual_bit_unit (XVisualInfo *vi, int bitdepth) { int bit_unit = 0; XPixmapFormatValues *xpfvs; int i,j; /* We now have the bitdepth of the display, but that doesn't tell us yet * how many bits to use per pixel. The VGA16 server has a bitdepth of 4, * but uses 1 byte per pixel. */ xpfvs = XListPixmapFormats (display, &i); for (j = 0; j < i && xpfvs[j].depth != bitdepth; j++) ; if (j < i) bit_unit = xpfvs[j].bits_per_pixel; XFree (xpfvs); if (j == i) { write_log ("Your X server is feeling ill.\n"); } return bit_unit; }
static gboolean ensure_pix_fmts (GstVaapiDisplayX11 * display) { GstVaapiDisplayX11Private *const priv = GST_VAAPI_DISPLAY_X11_PRIVATE (display); XPixmapFormatValues *pix_fmts; int i, n, num_pix_fmts; if (priv->pixmap_formats) return TRUE; GST_VAAPI_DISPLAY_LOCK (display); pix_fmts = XListPixmapFormats (GST_VAAPI_DISPLAY_XDISPLAY (display), &num_pix_fmts); GST_VAAPI_DISPLAY_UNLOCK (display); if (!pix_fmts) return FALSE; priv->pixmap_formats = g_array_sized_new (FALSE, FALSE, sizeof (GstVaapiPixmapFormatX11), num_pix_fmts); if (!priv->pixmap_formats) { XFree (pix_fmts); return FALSE; } for (i = 0, n = 0; i < num_pix_fmts; i++) { GstVaapiPixmapFormatX11 *const pix_fmt = &g_array_index (priv->pixmap_formats, GstVaapiPixmapFormatX11, n); pix_fmt->depth = pix_fmts[i].depth; pix_fmt->bpp = pix_fmts[i].bits_per_pixel; pix_fmt->format = pix_fmt_to_video_format (pix_fmt->depth, pix_fmt->bpp); if (pix_fmt->format != GST_VIDEO_FORMAT_UNKNOWN) n++; } priv->pixmap_formats->len = n; return TRUE; }
nsresult nsSystemInfo::Init() { struct pci_access *pacc; struct pci_dev *p; pciaddr_t ram = 0; char buf[128]; int i, found, v, n; Display *dpy; char *display = NULL; Window root; XVisualInfo *info, templ; XWindowAttributes wts; XPixmapFormatValues *pf; XSetWindowAttributes attr; Window win; mWidth = 0; mHeight = 0; mDepth = 0; pacc = pci_alloc(); pci_init(pacc); pci_scan_bus(pacc); for (p = pacc->devices; p; p=p->next) { pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_CLASS | PCI_FILL_BASES | PCI_FILL_SIZES); if (p->device_class == PCI_CLASS_DISPLAY_VGA) { pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, p->vendor_id, p->device_id); mDeviceName.AssignLiteral(buf); sprintf(buf, "0x%04X", p->vendor_id); mVendorID.AssignLiteral(buf); sprintf(buf, "0x%04X", p->device_id); mDeviceID.AssignLiteral(buf); for (i=0; i<6; i++) { pciaddr_t len = (p->known_fields & PCI_FILL_SIZES) ? p->size[i] : 0; if (len > ram) ram = len; } vram = ram / 1024 / 1024; } else { Log("Grafx Bot: No PCI VGA device found"); } } pci_cleanup(pacc); if (NULL != (display = getenv("DISPLAY"))) { if (display[0] != ':') { display = strchr(display, ':'); if (NULL == display) { Log("Grafx Bot: unable to find display"); return NS_OK; } } if (NULL == (dpy = XOpenDisplay(display))) { Log("Grafx Bot: unable to find X display"); return NS_OK; } root = DefaultRootWindow(dpy); XGetWindowAttributes(dpy, root, &wts); mWidth = wts.width; mHeight = wts.height; templ.screen = XDefaultScreen(dpy); info = XGetVisualInfo(dpy, VisualScreenMask, &templ, &found); v = -1; for (i = 0; v == -1 && i < found; i++) { if (info[i].depth >= 15) v = i; } for (i = 0; v == -1 && i < found; i++) { if (info[i].depth == 8) v = i; } if (-1 == v) { Log("Grafx Bot: can't find visual"); return NS_OK; } pf = XListPixmapFormats(dpy, &n); for (i = 0; i < n; i++) { if (pf[i].depth == info[v].depth) { mDepth = pf[i].depth; } } if (gGLXWrap.OpenLibrary("libGL.so.1") && gGLXWrap.Init()) { attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap(dpy, root, info[v].visual, AllocNone); attr.event_mask = StructureNotifyMask | ExposureMask; win = XCreateWindow(dpy, root, 0, 0, 100, 100, 0, info[v].depth, InputOutput, info[v].visual, CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, &attr); GLXContext ctx = gGLXWrap.fCreateContext(dpy, info, NULL, true); if (ctx) { if (gGLXWrap.fMakeCurrent(dpy, win, ctx)) { mDriverVersion.AssignLiteral((char*)gGLXWrap.fGetString(LOCAL_GL_VERSION)); mDriver.AssignLiteral((char*)gGLXWrap.fGetString(LOCAL_GL_RENDERER)); mDriver.AppendLiteral(" ("); mDriver.AppendLiteral((char*)gGLXWrap.fGetString(LOCAL_GL_VENDOR)); mDriver.AppendLiteral(")"); } else { Log("Grafx Bot: unable to make current"); } gGLXWrap.fDestroyContext(dpy, ctx); } else { Log("Grafx Bot: unable to create context"); } XDestroyWindow(dpy, win); } else { Log("Grafx Bot: can't init libGL.so.1"); } } return NS_OK; }
/* initiate connection with X server */ static unsigned char * x_init_driver(unsigned char *param, unsigned char *display) { XGCValues gcv; XSetWindowAttributes win_attr; XVisualInfo vinfo; int misordered=-1; n_wins=0; #if defined(HAVE_SETLOCALE) && defined(LC_ALL) setlocale(LC_ALL,""); #endif #ifdef X_DEBUG { unsigned char txt[256]; sprintf(txt,"x_init_driver(%s, %s)\n",param, display); MESSAGE(txt); } #endif x_input_encoding=-1; #if defined(HAVE_NL_LANGINFO) && defined(HAVE_LANGINFO_H) && defined(CODESET) { unsigned char *cp; cp=nl_langinfo(CODESET); x_input_encoding=get_cp_index(cp); } #endif if (x_input_encoding<0)x_driver.flags|=GD_NEED_CODEPAGE; if (!display||!(*display))display=0; /* X documentation says on XOpenDisplay(display_name) : display_name Specifies the hardware display name, which determines the dis- play and communications domain to be used. On a POSIX-confor- mant system, if the display_name is NULL, it defaults to the value of the DISPLAY environment variable. But OS/2 has problems when display_name is NULL ... */ if (!display)display=getenv("DISPLAY"); #ifndef __linux__ /* on Linux, do not assume XWINDOW present if $DISPLAY is not set --- rather open links on svgalib or framebuffer console */ if (!display)display=":0.0"; /* needed for MacOS X */ #endif x_display=XOpenDisplay(display); if (!x_display) { unsigned char *err=init_str(); int l=0; add_to_str(&err,&l,"Can't open display \""); add_to_str(&err,&l,display?display:(unsigned char *)"(null)"); add_to_str(&err,&l,"\"\n"); return err; } x_hash_table_init(); x_bitmap_bit_order=BitmapBitOrder(x_display); x_fd=XConnectionNumber(x_display); x_screen=DefaultScreen(x_display); x_display_height=DisplayHeight(x_display,x_screen); x_display_width=DisplayWidth(x_display,x_screen); x_root_window=RootWindow(x_display,x_screen); x_default_window_width=x_display_width-50; x_default_window_height=x_display_height-50; x_driver_param=NULL; if (param) { char *p, *e, *f; int w,h; x_driver_param=stracpy(param); for (p=x_driver_param;(*p)&&(*p)!='x'&&(*p)!='X';p++); if (!(*p))goto done; *p=0; w=strtoul(x_driver_param,&e,10); h=strtoul(p+1,&f,10); if (!(*e)&&!(*f)&&w&&h){x_default_window_width=w;x_default_window_height=h;} *p='x'; done:; } /* find best visual */ { #define DEPTHS 5 #define CLASSES 2 int depths[DEPTHS]={24, 16, 15, 8, 4}; int classes[CLASSES]={TrueColor, PseudoColor}; /* FIXME: dodelat DirectColor */ int a,b; for (a=0;a<DEPTHS;a++) for (b=0;b<CLASSES;b++) { if (XMatchVisualInfo(x_display, x_screen,depths[a],classes[b], &vinfo)) { x_default_visual=vinfo.visual; x_depth=vinfo.depth; /* determine bytes per pixel */ { XPixmapFormatValues *pfm; int n,i; pfm=XListPixmapFormats(x_display,&n); for (i=0;i<n;i++) if (pfm[i].depth==x_depth) { x_bitmap_bpp=pfm[i].bits_per_pixel<8?1:((pfm[i].bits_per_pixel)>>3); x_bitmap_scanline_pad=(pfm[i].scanline_pad)>>3; XFree(pfm); goto bytes_per_pixel_found; } if(n) XFree(pfm); continue; } bytes_per_pixel_found: /* test misordered flag */ switch(x_depth) { case 4: case 8: if (x_bitmap_bpp!=1)break; if (vinfo.red_mask>=vinfo.green_mask&&vinfo.green_mask>=vinfo.blue_mask) { misordered=0; goto visual_found; } break; case 15: case 16: if (x_bitmap_bpp!=2)break; if (x_bitmap_bit_order==MSBFirst&&vinfo.red_mask>vinfo.green_mask&&vinfo.green_mask>vinfo.blue_mask) { misordered=256; goto visual_found; } if (x_bitmap_bit_order==MSBFirst)break; if (vinfo.red_mask>vinfo.green_mask&&vinfo.green_mask>vinfo.blue_mask) { misordered=0; goto visual_found; } break; case 24: if (x_bitmap_bpp!=3&&x_bitmap_bpp!=4) break; if (vinfo.red_mask<vinfo.green_mask&&vinfo.green_mask<vinfo.blue_mask) { misordered=256; goto visual_found; } if (x_bitmap_bit_order==MSBFirst&&vinfo.red_mask>vinfo.green_mask&&vinfo.green_mask>vinfo.blue_mask) { misordered=512; goto visual_found; } if (vinfo.red_mask>vinfo.green_mask&&vinfo.green_mask>vinfo.blue_mask) { misordered=0; goto visual_found; } break; } } }
(*rsh)--; } BOOL xf_get_pixmap_info(xfContext* xfc) { int i; int vi_count; int pf_count; XVisualInfo* vi; XVisualInfo* vis; XVisualInfo template; XPixmapFormatValues* pf; XPixmapFormatValues* pfs; XWindowAttributes window_attributes; assert(xfc->display); pfs = XListPixmapFormats(xfc->display, &pf_count); if (!pfs) { WLog_ERR(TAG, "XListPixmapFormats failed"); return 1; } for (i = 0; i < pf_count; i++) { pf = pfs + i; if (pf->depth == xfc->depth) { xfc->bpp = pf->bits_per_pixel; xfc->scanline_pad = pf->scanline_pad;
Memimage* _xattach(char *label, char *winsize) { char *argv[2], *disp; int i, havemin, height, mask, n, width, x, xrootid, y; Rectangle r; XClassHint classhint; XDrawable pmid; XPixmapFormatValues *pfmt; XScreen *xscreen; XSetWindowAttributes attr; XSizeHints normalhint; XTextProperty name; XVisualInfo xvi; XWindow xrootwin; XWindowAttributes wattr; XWMHints hint; Atom atoms[2]; /* if(XInitThreads() == 0){ fprint(2, "XInitThreads failed\n"); abort(); } */ /* * Connect to X server. */ _x.display = XOpenDisplay(NULL); if(_x.display == nil){ disp = getenv("DISPLAY"); werrstr("XOpenDisplay %s: %r", disp ? disp : ":0"); free(disp); return nil; } _x.fd = ConnectionNumber(_x.display); XSetErrorHandler(xerror); XSetIOErrorHandler(xioerror); xrootid = DefaultScreen(_x.display); xrootwin = DefaultRootWindow(_x.display); /* * Figure out underlying screen format. */ if(XMatchVisualInfo(_x.display, xrootid, 24, TrueColor, &xvi) || XMatchVisualInfo(_x.display, xrootid, 24, DirectColor, &xvi)){ _x.vis = xvi.visual; _x.depth = 24; } else if(XMatchVisualInfo(_x.display, xrootid, 16, TrueColor, &xvi) || XMatchVisualInfo(_x.display, xrootid, 16, DirectColor, &xvi)){ _x.vis = xvi.visual; _x.depth = 16; } else if(XMatchVisualInfo(_x.display, xrootid, 15, TrueColor, &xvi) || XMatchVisualInfo(_x.display, xrootid, 15, DirectColor, &xvi)){ _x.vis = xvi.visual; _x.depth = 15; } else if(XMatchVisualInfo(_x.display, xrootid, 8, PseudoColor, &xvi) || XMatchVisualInfo(_x.display, xrootid, 8, StaticColor, &xvi)){ if(_x.depth > 8){ werrstr("can't deal with colormapped depth %d screens", _x.depth); goto err0; } _x.vis = xvi.visual; _x.depth = 8; } else{ _x.depth = DefaultDepth(_x.display, xrootid); if(_x.depth != 8){ werrstr("can't understand depth %d screen", _x.depth); goto err0; } _x.vis = DefaultVisual(_x.display, xrootid); } if(DefaultDepth(_x.display, xrootid) == _x.depth) _x.usetable = 1; /* * _x.depth is only the number of significant pixel bits, * not the total number of pixel bits. We need to walk the * display list to find how many actual bits are used * per pixel. */ _x.chan = 0; pfmt = XListPixmapFormats(_x.display, &n); for(i=0; i<n; i++){ if(pfmt[i].depth == _x.depth){ switch(pfmt[i].bits_per_pixel){ case 1: /* untested */ _x.chan = GREY1; break; case 2: /* untested */ _x.chan = GREY2; break; case 4: /* untested */ _x.chan = GREY4; break; case 8: _x.chan = CMAP8; break; case 15: _x.chan = RGB15; break; case 16: /* how to tell RGB15? */ _x.chan = RGB16; break; case 24: /* untested (impossible?) */ _x.chan = RGB24; break; case 32: _x.chan = XRGB32; break; } } } if(_x.chan == 0){ werrstr("could not determine screen pixel format"); goto err0; } /* * Set up color map if necessary. */ xscreen = DefaultScreenOfDisplay(_x.display); _x.cmap = DefaultColormapOfScreen(xscreen); if(_x.vis->class != StaticColor){ plan9cmap(); setupcmap(xrootwin); } /* * We get to choose the initial rectangle size. * This is arbitrary. In theory we should read the * command line and allow the traditional X options. */ mask = 0; x = 0; y = 0; if(winsize && winsize[0]){ if(parsewinsize(winsize, &r, &havemin) < 0) sysfatal("%r"); }else{ /* * Parse the various X resources. Thanks to Peter Canning. */ char *screen_resources, *display_resources, *geom, *geomrestype, *home, *file; XrmDatabase database; XrmValue geomres; database = XrmGetDatabase(_x.display); screen_resources = XScreenResourceString(xscreen); if(screen_resources != nil){ XrmCombineDatabase(XrmGetStringDatabase(screen_resources), &database, False); XFree(screen_resources); } display_resources = XResourceManagerString(_x.display); if(display_resources == nil){ home = getenv("HOME"); if(home!=nil && (file=smprint("%s/.Xdefaults", home)) != nil){ XrmCombineFileDatabase(file, &database, False); free(file); } free(home); }else XrmCombineDatabase(XrmGetStringDatabase(display_resources), &database, False); geom = smprint("%s.geometry", label); if(geom && XrmGetResource(database, geom, nil, &geomrestype, &geomres)) mask = XParseGeometry(geomres.addr, &x, &y, (uint*)&width, (uint*)&height); free(geom); if((mask & WidthValue) && (mask & HeightValue)){ r = Rect(0, 0, width, height); }else{ r = Rect(0, 0, WidthOfScreen(xscreen)*3/4, HeightOfScreen(xscreen)*3/4); if(Dx(r) > Dy(r)*3/2) r.max.x = r.min.x + Dy(r)*3/2; if(Dy(r) > Dx(r)*3/2) r.max.y = r.min.y + Dx(r)*3/2; } if(mask & XNegative){ x += WidthOfScreen(xscreen); } if(mask & YNegative){ y += HeightOfScreen(xscreen); } havemin = 0; } screenrect = Rect(0, 0, WidthOfScreen(xscreen), HeightOfScreen(xscreen)); windowrect = r; memset(&attr, 0, sizeof attr); attr.colormap = _x.cmap; attr.background_pixel = ~0; attr.border_pixel = 0; _x.drawable = XCreateWindow( _x.display, /* display */ xrootwin, /* parent */ x, /* x */ y, /* y */ Dx(r), /* width */ Dy(r), /* height */ 0, /* border width */ _x.depth, /* depth */ InputOutput, /* class */ _x.vis, /* visual */ /* valuemask */ CWBackPixel|CWBorderPixel|CWColormap, &attr /* attributes (the above aren't?!) */ ); /* * Label and other properties required by ICCCCM. */ memset(&name, 0, sizeof name); if(label == nil) label = "pjw-face-here"; name.value = (uchar*)label; name.encoding = XA_STRING; name.format = 8; name.nitems = strlen((char*)name.value); memset(&normalhint, 0, sizeof normalhint); normalhint.flags = PSize|PMaxSize; if(winsize && winsize[0]){ normalhint.flags &= ~PSize; normalhint.flags |= USSize; normalhint.width = Dx(r); normalhint.height = Dy(r); }else{ if((mask & WidthValue) && (mask & HeightValue)){ normalhint.flags &= ~PSize; normalhint.flags |= USSize; normalhint.width = width; normalhint.height = height; } if((mask & WidthValue) && (mask & HeightValue)){ normalhint.flags |= USPosition; normalhint.x = x; normalhint.y = y; } } normalhint.max_width = WidthOfScreen(xscreen); normalhint.max_height = HeightOfScreen(xscreen); memset(&hint, 0, sizeof hint); hint.flags = InputHint|StateHint; hint.input = 1; hint.initial_state = NormalState; memset(&classhint, 0, sizeof classhint); classhint.res_name = label; classhint.res_class = label; argv[0] = label; argv[1] = nil; XSetWMProperties( _x.display, /* display */ _x.drawable, /* window */ &name, /* XA_WM_NAME property */ &name, /* XA_WM_ICON_NAME property */ argv, /* XA_WM_COMMAND */ 1, /* argc */ &normalhint, /* XA_WM_NORMAL_HINTS */ &hint, /* XA_WM_HINTS */ &classhint /* XA_WM_CLASSHINTS */ ); XFlush(_x.display); if(havemin){ XWindowChanges ch; memset(&ch, 0, sizeof ch); ch.x = r.min.x; ch.y = r.min.y; XConfigureWindow(_x.display, _x.drawable, CWX|CWY, &ch); /* * Must pretend origin is 0,0 for X. */ r = Rect(0,0,Dx(r),Dy(r)); } /* * Look up clipboard atom. */ _x.clipboard = XInternAtom(_x.display, "CLIPBOARD", False); _x.utf8string = XInternAtom(_x.display, "UTF8_STRING", False); _x.targets = XInternAtom(_x.display, "TARGETS", False); _x.text = XInternAtom(_x.display, "TEXT", False); _x.compoundtext = XInternAtom(_x.display, "COMPOUND_TEXT", False); _x.takefocus = XInternAtom(_x.display, "WM_TAKE_FOCUS", False); _x.losefocus = XInternAtom(_x.display, "_9WM_LOSE_FOCUS", False); _x.wmprotos = XInternAtom(_x.display, "WM_PROTOCOLS", False); atoms[0] = _x.takefocus; atoms[1] = _x.losefocus; XChangeProperty(_x.display, _x.drawable, _x.wmprotos, XA_ATOM, 32, PropModeReplace, (uchar*)atoms, 2); /* * Put the window on the screen, check to see what size we actually got. */ XMapWindow(_x.display, _x.drawable); XSync(_x.display, False); if(!XGetWindowAttributes(_x.display, _x.drawable, &wattr)) fprint(2, "XGetWindowAttributes failed\n"); else if(wattr.width && wattr.height){ if(wattr.width != Dx(r) || wattr.height != Dy(r)){ r.max.x = wattr.width; r.max.y = wattr.height; } }else fprint(2, "XGetWindowAttributes: bad attrs\n"); /* * Allocate our local backing store. */ _x.screenr = r; _x.screenpm = XCreatePixmap(_x.display, _x.drawable, Dx(r), Dy(r), _x.depth); _x.nextscreenpm = _x.screenpm; _x.screenimage = _xallocmemimage(r, _x.chan, _x.screenpm); /* * Allocate some useful graphics contexts for the future. */ _x.gcfill = xgc(_x.screenpm, FillSolid, -1); _x.gccopy = xgc(_x.screenpm, -1, -1); _x.gcsimplesrc = xgc(_x.screenpm, FillStippled, -1); _x.gczero = xgc(_x.screenpm, -1, -1); _x.gcreplsrc = xgc(_x.screenpm, FillTiled, -1); pmid = XCreatePixmap(_x.display, _x.drawable, 1, 1, 1); _x.gcfill0 = xgc(pmid, FillSolid, 0); _x.gccopy0 = xgc(pmid, -1, -1); _x.gcsimplesrc0 = xgc(pmid, FillStippled, -1); _x.gczero0 = xgc(pmid, -1, -1); _x.gcreplsrc0 = xgc(pmid, FillTiled, -1); XFreePixmap(_x.display, pmid); return _x.screenimage; err0: /* * Should do a better job of cleaning up here. */ XCloseDisplay(_x.display); return nil; }
/* This function gets the X Display and global info about it. Everything is stored in our object and will be cleaned when the object is disposed. Note here that caps for supported format are generated without any window or image creation */ GstXContext * ximageutil_xcontext_get (GstElement * parent, const gchar * display_name) { GstXContext *xcontext = NULL; XPixmapFormatValues *px_formats = NULL; gint nb_formats = 0, i; xcontext = g_new0 (GstXContext, 1); xcontext->disp = XOpenDisplay (display_name); GST_DEBUG_OBJECT (parent, "opened display %p", xcontext->disp); if (!xcontext->disp) { g_free (xcontext); return NULL; } xcontext->screen = DefaultScreenOfDisplay (xcontext->disp); xcontext->screen_num = DefaultScreen (xcontext->disp); xcontext->visual = DefaultVisual (xcontext->disp, xcontext->screen_num); xcontext->root = DefaultRootWindow (xcontext->disp); xcontext->white = XWhitePixel (xcontext->disp, xcontext->screen_num); xcontext->black = XBlackPixel (xcontext->disp, xcontext->screen_num); xcontext->depth = DefaultDepthOfScreen (xcontext->screen); xcontext->width = DisplayWidth (xcontext->disp, xcontext->screen_num); xcontext->height = DisplayHeight (xcontext->disp, xcontext->screen_num); xcontext->widthmm = DisplayWidthMM (xcontext->disp, xcontext->screen_num); xcontext->heightmm = DisplayHeightMM (xcontext->disp, xcontext->screen_num); xcontext->caps = NULL; GST_DEBUG_OBJECT (parent, "X reports %dx%d pixels and %d mm x %d mm", xcontext->width, xcontext->height, xcontext->widthmm, xcontext->heightmm); ximageutil_calculate_pixel_aspect_ratio (xcontext); /* We get supported pixmap formats at supported depth */ px_formats = XListPixmapFormats (xcontext->disp, &nb_formats); if (!px_formats) { XCloseDisplay (xcontext->disp); g_free (xcontext); return NULL; } /* We get bpp value corresponding to our running depth */ for (i = 0; i < nb_formats; i++) { if (px_formats[i].depth == xcontext->depth) xcontext->bpp = px_formats[i].bits_per_pixel; } XFree (px_formats); xcontext->endianness = (ImageByteOrder (xcontext->disp) == LSBFirst) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; #ifdef HAVE_XSHM /* Search for XShm extension support */ if (XShmQueryExtension (xcontext->disp) && ximageutil_check_xshm_calls (xcontext)) { xcontext->use_xshm = TRUE; GST_DEBUG ("ximageutil is using XShm extension"); } else { xcontext->use_xshm = FALSE; GST_DEBUG ("ximageutil is not using XShm extension"); } #endif /* HAVE_XSHM */ /* our caps system handles 24/32bpp RGB as big-endian. */ if ((xcontext->bpp == 24 || xcontext->bpp == 32) && xcontext->endianness == G_LITTLE_ENDIAN) { xcontext->endianness = G_BIG_ENDIAN; xcontext->r_mask_output = GUINT32_TO_BE (xcontext->visual->red_mask); xcontext->g_mask_output = GUINT32_TO_BE (xcontext->visual->green_mask); xcontext->b_mask_output = GUINT32_TO_BE (xcontext->visual->blue_mask); if (xcontext->bpp == 24) { xcontext->r_mask_output >>= 8; xcontext->g_mask_output >>= 8; xcontext->b_mask_output >>= 8; }
struct lowWindow *lowWindowInit( int w, int h ) { #ifdef _GLDEBUG printf("lowWindowInit\n"); #endif struct lowWindow *window = NULL; window = (struct lowWindow*)malloc(sizeof(struct lowWindow)); XInitThreads(); window->dpy = XOpenDisplay(NULL); window->screen = DefaultScreen(window->dpy); Window root; unsigned long valuemask; XWindowAttributes attr1; XSetWindowAttributes attr; attr.event_mask = ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask; root = RootWindow(window->dpy,window->screen); XGetWindowAttributes(window->dpy,root,&attr1); valuemask = CWEventMask; #ifdef _OVERRIDE_REDIRECT valuemask += CWOverrideRedirect; attr.override_redirect = True; #endif window->id = XCreateWindow( window->dpy, root, 0,0, w, h, 1, DefaultDepth(window->dpy,window->screen), CopyFromParent, DefaultVisual(window->dpy,window->screen), valuemask, &attr ); window->surface = (unsigned char*)malloc(w*h*4); int count = 0; XPixmapFormatValues *formats = NULL; XPixmapFormatValues *format = NULL; formats = XListPixmapFormats(window->dpy,&count); for(format = formats; count > 0; count--, format++) { if (format->depth == DefaultDepth(window->dpy,window->screen)) { window->ximage = XCreateImage( window->dpy, DefaultVisual(window->dpy,window->screen), DefaultDepth(window->dpy,window->screen), ZPixmap, 0, (char*)window->surface, w,h, format->scanline_pad, 0 ); } } XSetWindowBackground(window->dpy,window->id, BlackPixel(window->dpy,window->screen)); XSelectInput(window->dpy,window->id, ExposureMask|ButtonPressMask|ButtonReleaseMask|ButtonMotionMask); XMapWindow(window->dpy,window->id); return window; }
bool QVideo::findDisplayProperties(ImageFormat& fmt, int& depth, unsigned int& bitsperpixel, int& bytesperpixel) { XVisualInfo *vi_in, vi_out; long mask = VisualScreenMask; int nvis = 0; ImageFormat p = FORMAT_NONE; int bpp = 0; int d = 0; vi_out.screen = QPaintDevice::x11AppScreen(); vi_in = XGetVisualInfo(qt_xdisplay(), mask, &vi_out, &nvis); if (vi_in) { for (int i = 0; i < nvis; i++) { bpp = 0; int n; XPixmapFormatValues *pf = XListPixmapFormats(qt_xdisplay(),&n); d = vi_in[i].depth; for (int j = 0; j < n; j++) { if (pf[j].depth == d) { bpp = pf[j].bits_per_pixel; break; } } XFree(pf); // FIXME: Endianess detection p = FORMAT_NONE; switch (bpp) { case 32: if (vi_in[i].red_mask == 0xff0000 && vi_in[i].green_mask == 0x00ff00 && vi_in[i].blue_mask == 0x0000ff) { p = FORMAT_BGR32; kdDebug() << "QVideo: Found BGR32 display." << endl; } break; case 24: if (vi_in[i].red_mask == 0xff0000 && vi_in[i].green_mask == 0x00ff00 && vi_in[i].blue_mask == 0x0000ff) { p = FORMAT_BGR24; kdDebug() << "QVideo: Found BGR24 display." << endl; } break; case 16: if (vi_in[i].red_mask == 0x00f800 && vi_in[i].green_mask == 0x0007e0 && vi_in[i].blue_mask == 0x00001f) { p = FORMAT_RGB15_LE; kdDebug() << "QVideo: Found RGB16_LE display." << endl; } else if (vi_in[i].red_mask == 0x007c00 && vi_in[i].green_mask == 0x0003e0 && vi_in[i].blue_mask == 0x00001f) { p = FORMAT_RGB15_LE; kdDebug() << "QVideo: Found RGB15_LE display." << endl; } break; case 8: default: continue; } if (p != FORMAT_NONE) break; } XFree(vi_in); } if (p != FORMAT_NONE) { int bytespp = bytesppForFormat(p); kdDebug() << "QVideo: Display properties: depth: " << d << ", bits/pixel: " << bpp << ", bytes/pixel: " << bytespp << endl; fmt = p; bitsperpixel = bpp; bytesperpixel = bytespp; depth = d; return true; } else { kdWarning() << "QVideo: Unable to find out palette. What display do you have????" << endl; fmt = FORMAT_NONE; bitsperpixel = 0; bytesperpixel = 0; depth = 0; return false; } }
/** ** X11 initialize. */ global void CloneInitDisplay(void) { int i; Window window; XGCValues gcvalue; XSizeHints hints; XWMHints wmhints; XClassHint classhint; XSetWindowAttributes attributes; int shm_major,shm_minor; Bool pixmap_support; XShmSegmentInfo shminfo; XVisualInfo xvi; XPixmapFormatValues *xpfv; if( !(TheDisplay=XOpenDisplay(NULL)) ) { fprintf(stderr,"Cannot connect to X-Server.\n"); exit(-1); } TheScreen=DefaultScreen(TheDisplay); // I need shared memory pixmap extension. if( !XShmQueryVersion(TheDisplay,&shm_major,&shm_minor,&pixmap_support) ) { fprintf(stderr,"SHM-Extensions required.\n"); exit(-1); } if( !pixmap_support ) { fprintf(stderr,"SHM-Extensions with pixmap supported required.\n"); exit(-1); } // Look for a nice visual #ifdef USE_HICOLOR if(XMatchVisualInfo(TheDisplay, TheScreen, 16, TrueColor, &xvi)) goto foundvisual; if(XMatchVisualInfo(TheDisplay, TheScreen, 15, TrueColor, &xvi)) goto foundvisual; fprintf(stderr,"Sorry, this version is for 15/16-bit displays only.\n"); #else if(XMatchVisualInfo(TheDisplay, TheScreen, 8, PseudoColor, &xvi)) goto foundvisual; fprintf(stderr,"Sorry, this version is for 8-bit displays only.\n"); #endif #if 0 if(XMatchVisualInfo(TheDisplay, TheScreen, 24, TrueColor, &xvi)) goto foundvisual; #endif exit(-1); foundvisual: xpfv=XListPixmapFormats(TheDisplay, &i); for(i--;i>=0;i--) if(xpfv[i].depth==xvi.depth) break; if(i<0) { fprintf(stderr,"No Pixmap format for visual depth?\n"); exit(-1); } VideoDepth=xvi.depth; VideoWidth = 640; VideoHeight = 480; MapWidth = 14; // FIXME: Not the correct way MapHeight = 14; shminfo.shmid=shmget(IPC_PRIVATE, (VideoWidth*xpfv[i].bits_per_pixel+xpfv[i].scanline_pad-1) / xpfv[i].scanline_pad * xpfv[i].scanline_pad * VideoHeight / 8, IPC_CREAT|0777); XFree(xpfv); if( !shminfo.shmid==-1 ) { fprintf(stderr,"shmget failed.\n"); exit(-1); } VideoMemory=(VMemType*)shminfo.shmaddr=shmat(shminfo.shmid,0,0); if( shminfo.shmaddr==(void*)-1 ) { shmctl(shminfo.shmid,IPC_RMID,0); fprintf(stderr,"shmat failed.\n"); exit(-1); } shminfo.readOnly=False; if( !XShmAttach(TheDisplay,&shminfo) ) { shmctl(shminfo.shmid,IPC_RMID,0); fprintf(stderr,"XShmAttach failed.\n"); exit(-1); } // Mark segment as deleted as soon as both clone and the X server have // attached to it. The POSIX spec says that a segment marked as deleted // can no longer have addition processes attach to it, but Linux will let // them anyway. shmctl(shminfo.shmid,IPC_RMID,0); TheMainDrawable=attributes.background_pixmap= XShmCreatePixmap(TheDisplay,DefaultRootWindow(TheDisplay) ,shminfo.shmaddr,&shminfo ,VideoWidth,VideoHeight ,xvi.depth); attributes.cursor = XCreateFontCursor(TheDisplay,XC_tcross-1); attributes.backing_store = NotUseful; attributes.save_under = False; attributes.event_mask = KeyPressMask|KeyReleaseMask|/*ExposureMask|*/ FocusChangeMask|ButtonPressMask|PointerMotionMask|ButtonReleaseMask; i = CWBackPixmap|CWBackingStore|CWSaveUnder|CWEventMask|CWCursor; if(xvi.class==PseudoColor) { i|=CWColormap; attributes.colormap = XCreateColormap( TheDisplay, xvi.screen, xvi.visual, AllocNone); // FIXME: Really should fill in the colormap right now } window=XCreateWindow(TheDisplay,DefaultRootWindow(TheDisplay) ,0,0,VideoWidth,VideoHeight,3 ,xvi.depth,InputOutput,xvi.visual ,i,&attributes); TheMainWindow=window; gcvalue.graphics_exposures=False; GcLine=XCreateGC(TheDisplay,window,GCGraphicsExposures,&gcvalue); // // Clear initial window. // XSetForeground(TheDisplay,GcLine,BlackPixel(TheDisplay,TheScreen)); XFillRectangle(TheDisplay,TheMainDrawable,GcLine,0,0 ,VideoWidth,VideoHeight); WmDeleteWindowAtom=XInternAtom(TheDisplay,"WM_DELETE_WINDOW",False); // // Set some usefull min/max sizes as well as a 1.3 aspect // #if 0 if( geometry ) { hints.flags=0; f=XParseGeometry(geometry ,&hints.x,&hints.y,&hints.width,&hints.height); if( f&XValue ) { if( f&XNegative ) { hints.x+=DisplayWidth-hints.width; } hints.flags|=USPosition; // FIXME: win gravity } if( f&YValue ) { if( f&YNegative ) { hints.y+=DisplayHeight-hints.height; } hints.flags|=USPosition; // FIXME: win gravity } if( f&WidthValue ) { hints.flags|=USSize; } if( f&HeightValue ) { hints.flags|=USSize; } } else { #endif hints.width=VideoWidth; hints.height=VideoHeight; hints.flags=PSize; #if 0 } #endif hints.min_width=VideoWidth; hints.min_height=VideoHeight; hints.max_width=VideoWidth; hints.max_height=VideoHeight; hints.min_aspect.x=4; hints.min_aspect.y=3; hints.max_aspect.x=4; hints.max_aspect.y=3; hints.width_inc=4; hints.height_inc=3; hints.flags|=PMinSize|PMaxSize|PAspect|PResizeInc; wmhints.input=True; wmhints.initial_state=NormalState; wmhints.window_group=window; wmhints.flags=InputHint|StateHint|WindowGroupHint; classhint.res_name="aleclone"; classhint.res_class="AleClone"; XSetStandardProperties(TheDisplay,window ,"ALE Clone","ALE Clone",None,(char**)0,0,&hints); XSetClassHint(TheDisplay,window,&classhint); XSetWMHints(TheDisplay,window,&wmhints); XSetWMProtocols(TheDisplay,window,&WmDeleteWindowAtom,1); XMapWindow(TheDisplay,window); // // Input handling. // XAddConnectionWatch(TheDisplay,MyConnectionWatch,NULL); }
result CMuli3DPresentTargetLinuxX11::Create() { m3ddeviceparameters DeviceParameters = m_pParent->GetDeviceParameters(); if( !DeviceParameters.iBackbufferWidth || !DeviceParameters.iBackbufferHeight ) { FUNC_FAILING( "CMuli3DPresentTargetLinuxX11::Create: invalid backbuffer dimensions have been supplied.\n" ); return e_invalidparameters; } m_pDisplay = XOpenDisplay( 0 ); if( !m_pDisplay ) { FUNC_FAILING( "CMuli3DPresentTargetLinuxX11::Create: couldn't open X-display.\n" ); return e_unknown; } const int32 iScreen = DefaultScreen( m_pDisplay ); const int32 iDepth = DefaultDepth( m_pDisplay, iScreen ); m_iPixelBytes = 0; int32 iPixmapFormatCount = 0; XPixmapFormatValues *pPixmapFormats = XListPixmapFormats( m_pDisplay, &iPixmapFormatCount ); for( int32 iPixmapFormat = 0; iPixmapFormat < iPixmapFormatCount && !m_iPixelBytes; ++iPixmapFormat ) { if( pPixmapFormats[iPixmapFormat].depth == iDepth ) { switch( pPixmapFormats[iPixmapFormat].bits_per_pixel ) { case 12: m_iPixelBytes = 2; m_i16bitMaxVal[0] = 15; m_i16bitMaxVal[1] = 15; m_i16bitMaxVal[2] = 15; m_i16bitShift[0] = 8; m_i16bitShift[1] = 4; m_i16bitShift[2] = 0; break; case 15: m_iPixelBytes = 2; m_i16bitMaxVal[0] = 31; m_i16bitMaxVal[1] = 31; m_i16bitMaxVal[2] = 31; m_i16bitShift[0] = 10; m_i16bitShift[1] = 5; m_i16bitShift[2] = 0; break; case 16: m_iPixelBytes = 2; m_i16bitMaxVal[0] = 31; m_i16bitMaxVal[1] = 63; m_i16bitMaxVal[2] = 31; m_i16bitShift[0] = 11; m_i16bitShift[1] = 5; m_i16bitShift[2] = 0; break; case 24: m_iPixelBytes = 3; break; case 32: m_iPixelBytes = 4; break; default: break; } } } XFree( pPixmapFormats ); if( !m_iPixelBytes ) { XCloseDisplay( m_pDisplay ); m_pDisplay = 0; FUNC_FAILING( "CMuli3DPresentTargetLinuxX11::Create: invalid pixel-depth! Make sure you're running in 16-, 24- or 32bits color-mode.\n" ); return e_unknown; } m_WindowGC = DefaultGC( m_pDisplay, iScreen ); m_pXImage = XCreateImage( m_pDisplay, CopyFromParent, iDepth, ZPixmap, 0, 0, DeviceParameters.iBackbufferWidth, DeviceParameters.iBackbufferHeight, 32, DeviceParameters.iBackbufferWidth * m_iPixelBytes ); if( !m_pXImage ) { FUNC_FAILING( "CMuli3DPresentTargetLinuxX11::Create: couldn't create X-image.\n" ); XCloseDisplay( m_pDisplay ); m_pDisplay = 0; return e_unknown; } m_pXImage->data = new char[DeviceParameters.iBackbufferWidth * DeviceParameters.iBackbufferHeight * m_iPixelBytes]; if( !m_pXImage->data ) { XDestroyImage( m_pXImage ); m_pXImage = 0; XCloseDisplay( m_pDisplay ); m_pDisplay = 0; FUNC_FAILING( "CMuli3DPresentTargetLinuxX11::Create: couldn't allocate memory for backbuffer.\n" ); return e_outofmemory; } return s_ok; }
NS_METHOD compzillaRenderingContext::SetDimensions (PRInt32 width, PRInt32 height) { DEBUG ("SetDimensions (%d,%d)\n", width, height); Destroy(); #if false // Check that the dimensions are sane if (!CheckSaneImageSize(width, height)) return NS_ERROR_FAILURE; #endif mWidth = width; mHeight = height; #ifdef MOZ_CAIRO_GFX DEBUG ("thebes\n"); mThebesSurface = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize (width, height), gfxASurface::ImageFormatARGB32); mThebesContext = new gfxContext(mThebesSurface); mSurface = mThebesSurface->CairoSurface(); cairo_surface_reference(mSurface); mCairo = mThebesContext->GetCairo(); cairo_reference(mCairo); DEBUG ("/thebes\n"); #else // non-cairo gfx // On most current X servers, using the software-only surface // actually provides a much smoother and faster display. // However, we provide MOZ_CANVAS_USE_RENDER for whomever wants to // go that route. //if (getenv("MOZ_CANVAS_USE_RENDER")) { XRenderPictFormat *fmt = XRenderFindStandardFormat (GDK_DISPLAY(), PictStandardARGB32); if (fmt) { int npfmts = 0; XPixmapFormatValues *pfmts = XListPixmapFormats(GDK_DISPLAY(), &npfmts); for (int i = 0; i < npfmts; i++) { if (pfmts[i].depth == 32) { npfmts = -1; break; } } XFree(pfmts); if (npfmts == -1) { mSurfacePixmap = XCreatePixmap (GDK_DISPLAY(), DefaultRootWindow(GDK_DISPLAY()), width, height, 32); mSurface = cairo_xlib_surface_create_with_xrender_format (GDK_DISPLAY(), mSurfacePixmap, DefaultScreenOfDisplay(GDK_DISPLAY()), fmt, mWidth, mHeight); } } //} // fall back to image surface if (!mSurface) { mImageSurfaceData = (PRUint8*) PR_Malloc (mWidth * mHeight * 4); if (!mImageSurfaceData) return NS_ERROR_OUT_OF_MEMORY; mSurface = cairo_image_surface_create_for_data (mImageSurfaceData, CAIRO_FORMAT_ARGB32, mWidth, mHeight, mWidth * 4); } mCairo = cairo_create(mSurface); #endif cairo_set_operator(mCairo, CAIRO_OPERATOR_CLEAR); cairo_new_path(mCairo); cairo_rectangle(mCairo, 0, 0, mWidth, mHeight); cairo_fill(mCairo); cairo_set_line_width(mCairo, 1.0); cairo_set_operator(mCairo, CAIRO_OPERATOR_OVER); cairo_set_miter_limit(mCairo, 10.0); cairo_set_line_cap(mCairo, CAIRO_LINE_CAP_BUTT); cairo_set_line_join(mCairo, CAIRO_LINE_JOIN_MITER); cairo_new_path(mCairo); return NS_OK; }
ibool MGLAPI XWINDC_initDriver(void *data,MGLDC *dc,int driverId,int modeId,ulong hwnd, int virtualX,int virtualY,int numBuffers,ibool stereo,int refreshRate) /**************************************************************************** * * Function: XWINDC_initDriver * Parameters: dc - Device context. * Returns: True if the device was correctly initialised. * * Description: Initialises the device driver, and starts the specified * graphics mode. This is also where we fill in all of the * vectors in the device context to initialise our device * context properly. * ****************************************************************************/ { Screen *scr; XSetWindowAttributes xswa; Display *dpy = dc->wm.xwindc.dpy; XVisualInfo *visinfo, vis; int nvis, npfv; Window root; int x,y; unsigned int w,h, bw, d; XPixmapFormatValues *pfv; _MGL_initInternal(); dc->deviceType = MGL_WINDOWED_DEVICE; dc->xInch = dc->yInch = 0; g_state.d.hardwareCursor = false; dc->v = &g_state; dc->v->m.refCount++; dc->wm.xwindc.scr = scr = DefaultScreenOfDisplay(dpy); dc->wm.xwindc.gc = DefaultGCOfScreen(scr); xswa.background_pixel = BlackPixel(dpy,XScreenNumberOfScreen(scr)); xswa.backing_store = Always; dc->wm.xwindc.wnd = hwnd; XGetGeometry(dpy, hwnd, &root, &x, &y, &w, &h, &bw, &d); dc->mi.xRes = w; dc->mi.yRes = h; dc->mi.maxPage = 0; dc->mi.bytesPerLine = 0; dc->mi.pageSize = 0; dc->surface = NULL; dc->mi.bitsPerPixel = dc->wm.xwindc.depth = d; vis.visualid = XVisualIDFromVisual(DefaultVisual(dpy, XScreenNumberOfScreen(scr))); visinfo = XGetVisualInfo(dpy, VisualIDMask, &vis, &nvis); pfv = XListPixmapFormats(dpy, &npfv); switch (d) { case 8: dc->mi.maxColor = 0xFFUL; break; case 15: dc->mi.maxColor = 0x7FFFUL; dc->pf= _MGL_pixelFormats[pfRGB555]; break; case 16: dc->mi.maxColor = 0xFFFFUL; dc->pf= _MGL_pixelFormats[visinfo->green_mask==0x7e0 ? pfRGB565 : pfRGB555]; break; case 24: { int i; dc->mi.maxColor = 0xFFFFFFUL; for(i=0; i<npfv; i++) if(pfv[i].depth == 24) break; if(pfv[i].bits_per_pixel==32){ dc->mi.bitsPerPixel = 32; dc->pf= _MGL_pixelFormats[pfARGB32]; }else dc->pf= _MGL_pixelFormats[pfRGB24]; break; } case 32: dc->mi.maxColor = 0xFFFFFFFFUL; dc->pf= _MGL_pixelFormats[pfARGB32]; break; } XFree(visinfo); if(d == 8){ // Set up the private colormap if necesary dc->wm.xwindc.hpal = xswa.colormap = XCreateColormap(dpy, hwnd, DefaultVisualOfScreen(scr), AllocAll); XChangeWindowAttributes(dpy, hwnd, CWColormap, &xswa); } XMapRaised(dpy, hwnd); XClearWindow(dpy, hwnd); XWIN_initInternal(dc); dc->v->w.destroy = destroyDC; dc->r.realizePalette = XWIN_realizePalette; dc->r.getDefaultPalette = XWIN_getDefaultPalette; dc->r.putImage = XWIN_putImage; return true; }
int main(int argc, char** argv) { GC gc; int index; int depth; int x, y; int width; int height; BYTE* buffer; int scanline; int pf_count; XEvent event; XImage* image; Pixmap pixmap; Screen* screen; Visual* visual; int scanline_pad; int screen_number; Display* display; Window window; Window root_window; rdtkEngine* engine; rdtkSurface* surface; unsigned long border; unsigned long background; XPixmapFormatValues* pf; XPixmapFormatValues* pfs; display = XOpenDisplay(NULL); if (!display) { WLog_ERR(TAG, "Cannot open display"); return winpr_exit(1); } x = 10; y = 10; width = 640; height = 480; screen_number = DefaultScreen(display); screen = ScreenOfDisplay(display, screen_number); visual = DefaultVisual(display, screen_number); gc = DefaultGC(display, screen_number); depth = DefaultDepthOfScreen(screen); root_window = RootWindow(display, screen_number); border = BlackPixel(display, screen_number); background = WhitePixel(display, screen_number); scanline_pad = 0; pfs = XListPixmapFormats(display, &pf_count); for (index = 0; index < pf_count; index++) { pf = &pfs[index]; if (pf->depth == depth) { scanline_pad = pf->scanline_pad; break; } } XFree(pfs); engine = rdtk_engine_new(); if (!engine) return winpr_exit(1); scanline = width * 4; buffer = (BYTE*) calloc(height, scanline); if (!buffer) return winpr_exit(1); surface = rdtk_surface_new(engine, buffer, width, height, scanline); rdtk_surface_fill(surface, 0, 0, width, height, 0x3BB9FF); rdtk_label_draw(surface, 16, 16, 128, 32, NULL, "label", 0, 0); rdtk_button_draw(surface, 16, 64, 128, 32, NULL, "button"); rdtk_text_field_draw(surface, 16, 128, 128, 32, NULL, "text field"); window = XCreateSimpleWindow(display, root_window, x, y, width, height, 1, border, background); XSelectInput(display, window, ExposureMask | KeyPressMask); XMapWindow(display, window); XSetFunction(display, gc, GXcopy); XSetFillStyle(display, gc, FillSolid); pixmap = XCreatePixmap(display, window, width, height, depth); image = XCreateImage(display, visual, depth, ZPixmap, 0, (char*) buffer, width, height, scanline_pad, 0); while (1) { XNextEvent(display, &event); if (event.type == Expose) { XPutImage(display, pixmap, gc, image, 0, 0, 0, 0, width, height); XCopyArea(display, pixmap, window, gc, 0, 0, width, height, 0, 0); } if (event.type == KeyPress) break; if (event.type == ClientMessage) break; } XFlush(display); XDestroyImage(image); XCloseDisplay(display); rdtk_surface_free(surface); free(buffer); rdtk_engine_free(engine); return winpr_exit(0); }