bool X11Grabber::Setup() { _x11Display = XOpenDisplay(NULL); if (_x11Display == nullptr) { std::cerr << "X11GRABBER ERROR: Unable to open display"; if (getenv("DISPLAY")) { std::cerr << " " << std::string(getenv("DISPLAY")) << std::endl; } else { std::cerr << ". DISPLAY environment variable not set" << std::endl; } return false; } _window = DefaultRootWindow(_x11Display); int dummy, pixmaps_supported; _XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy); _XShmAvailable = XShmQueryExtension(_x11Display); XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported); _XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_x11Display) == ZPixmap; return true; }
static int GGI_helper_x_shm_setup(struct ggi_helper *helper, const char *args, void *argptr) { ggi_x_priv *priv; int major, minor; Bool pixmaps; DPRINT_LIBS("GGI_helper_x_shm_setup(%p, %s, %p) called\n", helper, args, argptr); priv = GGIX_PRIV(helper->visual); if (XShmQueryExtension(priv->disp) != True) return GGI_ENOFUNC; if (XShmQueryVersion(priv->disp, &major, &minor, &pixmaps) != True) return GGI_ENOFUNC; DPRINT_LIBS("X: MIT-SHM: SHM version %i.%i %s pixmap support\n", major, minor, pixmaps ? "with" : "without"); priv->createfb = _ggi_xshm_create_ximage; priv->freefb = _ggi_xshm_free_ximage; return GGI_OK; }
bool X11Grabber::Setup() { _x11Display = XOpenDisplay(NULL); if (_x11Display == nullptr) { Error(_log, "Unable to open display"); if (getenv("DISPLAY")) { Error(_log, "%s",getenv("DISPLAY")); } else { Error(_log, "DISPLAY environment variable not set"); } return false; } _window = DefaultRootWindow(_x11Display); int dummy, pixmaps_supported; _XRenderAvailable = XRenderQueryExtension(_x11Display, &dummy, &dummy); _XShmAvailable = XShmQueryExtension(_x11Display); XShmQueryVersion(_x11Display, &dummy, &dummy, &pixmaps_supported); _XShmPixmapAvailable = pixmaps_supported && XShmPixmapFormat(_x11Display) == ZPixmap; // Image scaling is performed by XRender when available, otherwise by ImageResampler _imageResampler.setHorizontalPixelDecimation(_XRenderAvailable ? 1 : _horizontalDecimation); _imageResampler.setVerticalPixelDecimation(_XRenderAvailable ? 1 : _verticalDecimation); return true; }
/** * Create the capture */ static void *xshm_create(obs_data_t settings, obs_source_t source) { UNUSED_PARAMETER(source); struct xshm_data *data = bzalloc(sizeof(struct xshm_data)); data->dpy = XOpenDisplay(NULL); if (!data->dpy) { blog(LOG_ERROR, "xshm-input: Unable to open X display !"); goto fail; } if (!XShmQueryExtension(data->dpy)) { blog(LOG_ERROR, "xshm-input: XShm extension not found !"); goto fail; } data->use_xinerama = xinerama_is_active(data->dpy) ? true : false; obs_enter_graphics(); data->cursor = xcursor_init(data->dpy); obs_leave_graphics(); xshm_update(data, settings); return data; fail: xshm_destroy(data); return NULL; }
int evas_software_16_x11_x_can_do_shm(Display *d) { static Display *cached_d = NULL; static int cached_result = 0; if (d == cached_d) return cached_result; cached_d = d; if (XShmQueryExtension(d)) { X_Output_Buffer *xob; xob = evas_software_16_x11_x_output_buffer_new (d, DefaultVisual(d, DefaultScreen(d)), DefaultDepth(d, DefaultScreen(d)), 16, 16, 2, NULL); if (!xob) { cached_result = 0; return 0; } evas_software_16_x11_x_output_buffer_free(xob, 1); cached_result = 1; return 1; } cached_result = 0; return 0; }
void BC_Resources::init_shm(BC_WindowBase *window) { use_shm = 0; int (*old_handler)(Display *, XErrorEvent *) = XSetErrorHandler(BC_Resources::x_error_handler); if(XShmQueryExtension(window->display)) { XShmSegmentInfo test_shm; memset(&test_shm,0,sizeof(test_shm)); XImage *test_image = XShmCreateImage(window->display, window->vis, window->default_depth, ZPixmap, (char*)NULL, &test_shm, 5, 5); BC_Resources::error = 0; test_shm.shmid = shmget(IPC_PRIVATE, 5 * test_image->bytes_per_line, (IPC_CREAT | 0600)); if(test_shm.shmid != -1) { char *data = (char *)shmat(test_shm.shmid, NULL, 0); if(data != (void *)-1) { shmctl(test_shm.shmid, IPC_RMID, 0); test_shm.shmaddr = data; test_shm.readOnly = 0; if(XShmAttach(window->display, &test_shm)) { XSync(window->display, False); use_shm = 1; } shmdt(data); } } XDestroyImage(test_image); if(BC_Resources::error) use_shm = 0; } XSetErrorHandler(old_handler); }
static Bool NestedClientTryXShm(NestedClientPrivatePtr pPriv, int scrnIndex, int width, int height, int depth) { int shmMajor, shmMinor; Bool hasSharedPixmaps; if (!XShmQueryExtension(pPriv->display)) { xf86DrvMsg(scrnIndex, X_INFO, "XShmQueryExtension failed. Dropping XShm support.\n"); return FALSE; } if (XShmQueryVersion(pPriv->display, &shmMajor, &shmMinor, &hasSharedPixmaps)) { xf86DrvMsg(scrnIndex, X_INFO, "XShm extension version %d.%d %s shared pixmaps\n", shmMajor, shmMinor, (hasSharedPixmaps) ? "with" : "without"); } pPriv->img = XShmCreateImage(pPriv->display, DefaultVisualOfScreen(pPriv->screen), depth, ZPixmap, NULL, /* data */ &pPriv->shminfo, width, height); if (!pPriv->img) { xf86DrvMsg(scrnIndex, X_ERROR, "XShmCreateImage failed. Dropping XShm support.\n"); return FALSE; } /* XXX: change the 0777 mask? */ pPriv->shminfo.shmid = shmget(IPC_PRIVATE, pPriv->img->bytes_per_line * pPriv->img->height, IPC_CREAT | 0777); if (pPriv->shminfo.shmid == -1) { xf86DrvMsg(scrnIndex, X_ERROR, "shmget failed. Dropping XShm support.\n"); XDestroyImage(pPriv->img); return FALSE; } pPriv->shminfo.shmaddr = (char *)shmat(pPriv->shminfo.shmid, NULL, 0); if (pPriv->shminfo.shmaddr == (char *) -1) { xf86DrvMsg(scrnIndex, X_ERROR, "shmaddr failed. Dropping XShm support.\n"); XDestroyImage(pPriv->img); return FALSE; } pPriv->img->data = pPriv->shminfo.shmaddr; pPriv->shminfo.readOnly = FALSE; XShmAttach(pPriv->display, &pPriv->shminfo); pPriv->usingShm = TRUE; return TRUE; }
static int shm_available (void) { #if SHM_SUPPORT_LINKS == 1 if (XShmQueryExtension (display)) return 1; #endif return 0; }
// ###################################################################### AutomateXWin::AutomateXWin(const char* win_name) : itsDisplay(NULL), itsScreen(0), itsImage(NULL), itsWidth(0), itsHeight(0), itsDepth(0) { char *dispName = XDisplayName(NULL); unsigned num_tries; int event_base, error_base; int major_version, minor_version; itsDisplay = XOpenDisplay(dispName); if(!itsDisplay) LFATAL("XOpenDisplay(%s) failed\n", dispName); if (!XTestQueryExtension (itsDisplay, &event_base, &error_base, &major_version, &minor_version)) { XCloseDisplay(itsDisplay); LFATAL("XTest extension not supported on server"); } LINFO("XTestQueryExtension passed."); LINFO("XTest information for server \"%s\":", DisplayString(itsDisplay)); LINFO(" Major version: %d", major_version); LINFO(" Minor version: %d", minor_version); LINFO(" First event number: %d", event_base); LINFO(" First error number: %d", error_base); itsScreen = DefaultScreen(itsDisplay); itsRootWin = RootWindow(itsDisplay, itsScreen); for(num_tries=0;;) { itsWindow = XWindowByName(itsDisplay, itsRootWin, win_name); if(itsWindow) break; if(++num_tries == 100) LFATAL("XWindowByName\n"); usleep(20000); } XFlush(itsDisplay); XSync(itsDisplay, False); #ifdef USE_SHM if(!XShmQueryExtension(itsDisplay)) LFATAL("XShmQueryExtension"); #endif GetWindowGeometry(); if(!XMatchVisualInfo(itsDisplay, itsScreen, itsDepth, DirectColor, &itsVInfo)) { return; } }
static bool allocate_xvimage(struct vo *vo, int foo) { struct xvctx *ctx = vo->priv; struct vo_x11_state *x11 = vo->x11; // align it for faster OSD rendering (draw_bmp.c swscale usage) int aligned_w = FFALIGN(ctx->image_width, 32); #if HAVE_SHM if (x11->display_is_local && XShmQueryExtension(x11->display)) { ctx->Shmem_Flag = 1; x11->ShmCompletionEvent = XShmGetEventBase(x11->display) + ShmCompletion; } else { ctx->Shmem_Flag = 0; MP_INFO(vo, "Shared memory not supported\nReverting to normal Xv.\n"); } if (ctx->Shmem_Flag) { ctx->xvimage[foo] = (XvImage *) XvShmCreateImage(x11->display, ctx->xv_port, ctx->xv_format, NULL, aligned_w, ctx->image_height, &ctx->Shminfo[foo]); if (!ctx->xvimage[foo]) return false; ctx->Shminfo[foo].shmid = shmget(IPC_PRIVATE, ctx->xvimage[foo]->data_size, IPC_CREAT | 0777); ctx->Shminfo[foo].shmaddr = (char *) shmat(ctx->Shminfo[foo].shmid, 0, 0); if (ctx->Shminfo[foo].shmaddr == (void *)-1) return false; ctx->Shminfo[foo].readOnly = False; ctx->xvimage[foo]->data = ctx->Shminfo[foo].shmaddr; XShmAttach(x11->display, &ctx->Shminfo[foo]); XSync(x11->display, False); shmctl(ctx->Shminfo[foo].shmid, IPC_RMID, 0); } else #endif { ctx->xvimage[foo] = (XvImage *) XvCreateImage(x11->display, ctx->xv_port, ctx->xv_format, NULL, aligned_w, ctx->image_height); if (!ctx->xvimage[foo]) return false; ctx->xvimage[foo]->data = av_malloc(ctx->xvimage[foo]->data_size); if (!ctx->xvimage[foo]->data) return false; XSync(x11->display, False); } struct mp_image img = get_xv_buffer(vo, foo); img.w = aligned_w; mp_image_clear(&img, 0, 0, img.w, img.h); return true; }
static int can_use_shm(Display *dpy) { int major, minor, has_pixmap; if (!XShmQueryExtension(dpy)) return 0; XShmQueryVersion(dpy, &major, &minor, &has_pixmap); return has_pixmap; }
uchar* attachscreen(Rectangle *r, ulong *chan, int *d, int *width, int *softscreen) { int depth; Xsize &= ~0x3; /* ensure multiple of 4 */ r->min.x = 0; r->min.y = 0; r->max.x = Xsize; r->max.y = Ysize; if(!triedscreen){ xinitscreen(Xsize, Ysize, displaychan, chan, d); /* * moved xproc from here to end since it could cause an expose event and * hence a flushmemscreen before xscreendata is initialized */ } else{ *chan = displaychan; *d = displaydepth; } *width = (Xsize/4)*(*d/8); *softscreen = 1; displaychan = *chan; displaydepth = *d; /* check for X Shared Memory Extension */ is_shm = XShmQueryExtension(xdisplay); if(!is_shm || !makesharedfb()){ is_shm = 0; depth = xscreendepth; if(depth == 24) depth = 32; /* allocate virtual screen */ gscreendata = malloc(Xsize * Ysize * (displaydepth >> 3)); xscreendata = malloc(Xsize * Ysize * (depth >> 3)); if(gscreendata == nil || xscreendata == nil) { fprint(2, "emu: can not allocate virtual screen buffer (%dx%dx%d[%d])\n", Xsize, Ysize, displaydepth, depth); return 0; } img = XCreateImage(xdisplay, xvis, xscreendepth, ZPixmap, 0, (char*)xscreendata, Xsize, Ysize, 8, Xsize * (depth >> 3)); if(img == nil) { fprint(2, "emu: can not allocate virtual screen buffer (%dx%dx%d)\n", Xsize, Ysize, depth); return 0; } }
// gcc -Wall x11shot2.c -o x11shot2 -lX11 -lX11ext -lpng;./x11shot2 <wid> >/tmp/screenshot.png int main(int argc,char* argv[]){ if(argc<2){ fprintf(stderr, "usage:x11shot2 <wid> >/tmp/screenshot.png\n"); exit(1); } int wid=(int)strtol(argv[1], NULL, 0); sscanf(argv[1], "%x", &wid); XShmSegmentInfo shminfo; int x_off=0,y_off=0; Display *dpy=XOpenDisplay(getenv("DISPLAY")); XImage *image; XWindowAttributes wattr; if (dpy == NULL) { fprintf(stderr, "Cannot open display\n"); exit(1); } XGetWindowAttributes(dpy,wid,&wattr); fprintf(stderr,"wid:0x%x wattr x:%d y:%d w:%d h:%d begin capture\n" ,wid ,wattr.x,wattr.y ,wattr.width,wattr.height); if(!XShmQueryExtension(dpy)){ fprintf(stderr, "can't not use shm!\n"); exit(1); } int scr = XDefaultScreen(dpy); image = XShmCreateImage(dpy, DefaultVisual(dpy, scr), DefaultDepth(dpy, scr), ZPixmap, NULL, &shminfo, wattr.width,wattr.height); shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777); shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0); shminfo.readOnly = False; if (!XShmAttach(dpy, &shminfo)) { fprintf(stderr, "Fatal: Failed to attach shared memory!\n"); exit(1); } if(!XShmGetImage(dpy,wid,image,x_off,y_off,AllPlanes)) { die("Can't get image"); } pngstdout(image); XDestroyImage(image); return 0; };
static void XInit(int *argc, char ***argv) { XtToolkitInitialize(); xi.context = XtCreateApplicationContext(); XtAppSetFallbackResources(xi.context, fallback_resources); xi.disp = XtOpenDisplay(xi.context, NULL, "NMovie", "NMovie", NULL, 0, argc, *argv); if (!xi.disp) ErrorExit(ERROR_BAD_PARM,"Unable to open display"); shmext = XShmQueryExtension(xi.disp); xi.screenno = DefaultScreen(xi.disp); }
bool ensureImage(int w, int h) { if (ximage && ximage->width == w && ximage->height == h) return true; warn_bad_pitch = true; destroyX11Image(); use_shm = XShmQueryExtension(display); qDebug("use x11 shm: %d", use_shm); if (!use_shm) goto no_shm; // data seems not aligned ximage = XShmCreateImage(display, vinfo.visual, depth, ZPixmap, NULL, &shm, w, h); if (!ximage) { qWarning("XShmCreateImage error"); goto no_shm; } shm.shmid = shmget(IPC_PRIVATE, ximage->bytes_per_line*ximage->height, IPC_CREAT | 0777); if (shm.shmid < 0) { qWarning("shmget error"); goto no_shm; } shm.shmaddr = (char *)shmat(shm.shmid, 0, 0); if (shm.shmaddr == (char*)-1) { if (!ximage_data.isEmpty()) ximage->data = NULL; XDestroyImage(ximage); ximage = NULL; ximage_data.clear(); qWarning("Shared memory error,disabling ( seg id error )"); goto no_shm; } ximage->data = shm.shmaddr; shm.readOnly = False; if (!XShmAttach(display, &shm)) { qWarning("Attach to shm failed! try to use none shm"); goto no_shm; } XSync(display, False); shmctl(shm.shmid, IPC_RMID, 0); pixfmt = pixelFormat(ximage); return true; no_shm: ximage = XCreateImage(display, vinfo.visual, depth, ZPixmap, 0, NULL, w, h, 8, 0); if (!ximage) return false; pixfmt = pixelFormat(ximage); ximage->data = NULL; XSync(display, False); // TODO: align 16 or? ximage_data.resize(ximage->bytes_per_line*ximage->height + 32); return true; }
static gboolean ccm_display_init_shm (CCMDisplay * self) { g_return_val_if_fail (self != NULL, FALSE); int major, minor; if (XShmQueryExtension (self->priv->xdisplay) && XShmQueryVersion (self->priv->xdisplay, &major, &minor, &self->priv->shm_shared_pixmap)) { self->priv->shm.available = TRUE; return TRUE; } return FALSE; }
void InitializeX11(uint16_t x_off, uint16_t y_off, uint16_t *w, uint16_t *h){ printf("Loading X11 Module\n"); dpy = XOpenDisplay(""); default_src = XDefaultScreen(dpy); CaptureWin = Select_Window(); XGetWindowAttributes(dpy, CaptureWin, &gwa); *w = gwa.width; *h = gwa.height; #ifdef X11_USE_XSHM_ use_shm = XShmQueryExtension(dpy); if(use_shm) { printf("XShmQueryExtension(dpy);\n"); image = XShmCreateImage(dpy, DefaultVisual(dpy, default_src), DefaultDepth(dpy, default_src), ZPixmap, NULL, &shminfo, gwa.width, gwa.height); shminfo.shmid = shmget( IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777); if(shminfo.shmid == -1) { printf("shminfo.shmid == -1\n"); return; } shminfo.shmaddr = image->data = (char*) shmat(shminfo.shmid, 0, 0); shminfo.readOnly = False; if (!XShmAttach(dpy, &shminfo)) { printf("!XShmAttach(dpy, &shminfo)\n"); return; } } else{ #endif /*X11_USE_XSHM_*/ image = XGetImage(dpy, CaptureWin, x_off,y_off, gwa.width,gwa.height, AllPlanes, ZPixmap); #ifdef X11_USE_XSHM_ } #endif /*X11_USE_XSHM_*/ printf("X11 Module Running\n"); }
void XWindow::CreateXImage(int width, int height) { #ifdef HAVE_SHM if (_useShm) { if (_isInitialized && _XShmInfo.shmaddr) { XShmDetach (_display, &_XShmInfo); shmdt (_XShmInfo.shmaddr); } } else #endif { if (_XImage) { _XImage->data = _imageDataOrig; } } if (_XImage) XDestroyImage(_XImage); _imageDataOrig = NULL; #ifdef HAVE_SHM if (XShmQueryExtension (_display)) { _useShm = true; PTRACE(1, "X11\tXQueryShmExtension success"); } else { _useShm = false; PTRACE(1, "X11\tXQueryShmExtension failed"); } if (_useShm) ShmAttach(width, height); if (_useShm) { PTRACE(4, "X11\tUsing shm extension"); } else #endif { _XImage = XCreateImage(_display, _XVInfo.visual, _depth, ZPixmap, 0, NULL, width, height, 8, 0); _imageDataOrig = (char*)malloc(width * height * 4 + 32); _XImage->data = _imageDataOrig + 16 - ((long)_imageDataOrig & 15); memset(_XImage->data, 0, width * 4 * height); } }
glDispyWidget::glDispyWidget(QWidget *parent) : QGLWidget(parent) { //initialise X display xDisplay = XOpenDisplay(":0"); screenNumber = DefaultScreen(xDisplay); rootWindow = RootWindow(xDisplay, screenNumber); xDisplayWidth = XDisplayWidth(xDisplay, screenNumber); xDisplayHeight = XDisplayHeight(xDisplay, screenNumber); useShm = XShmQueryExtension(xDisplay); if (useShm) { img = XShmCreateImage(xDisplay, DefaultVisual(xDisplay, screenNumber), DefaultDepth(xDisplay, screenNumber), ZPixmap, NULL, &shminfo, xDisplayWidth, xDisplayHeight ); if(img == NULL) { qDebug() << "can't get shm image"; return; } shminfo.shmid = shmget(IPC_PRIVATE, img->bytes_per_line*img->height, IPC_CREAT | 0777 ); shminfo.shmaddr = img->data = (char *)shmat(shminfo.shmid, 0,0); shminfo.readOnly = false; XShmAttach(xDisplay, &shminfo); } //make this widget current GL context makeCurrent(); //render_fbo = new QGLFramebufferObject(512, 512); //render_fbo->bind(); initializeGL(); //glColor3f(1,1,0); //glBegin(GL_POLYGON); //glVertex2f(0,0); //glVertex2f(100,500); //glVertex2f(500,100); //glEnd(); //render_fbo->release(); timer = new QTimer(); QObject::connect(timer,SIGNAL(timeout()),this,SLOT(redraw())); timer->start(100); }
int BC_Capture::init_window(char *display_path) { int bits_per_pixel; if(display_path && display_path[0] == 0) display_path = NULL; if((display = XOpenDisplay(display_path)) == NULL) { printf(_("cannot connect to X server.\n")); if(getenv("DISPLAY") == NULL) printf(_("'DISPLAY' environment variable not set.\n")); exit(-1); return 1; } screen = DefaultScreen(display); rootwin = RootWindow(display, screen); vis = DefaultVisual(display, screen); default_depth = DefaultDepth(display, screen); client_byte_order = (*(u_int32_t*)"a ") & 0x00000001; server_byte_order = (XImageByteOrder(display) == MSBFirst) ? 0 : 1; char *data = 0; XImage *ximage; ximage = XCreateImage(display, vis, default_depth, ZPixmap, 0, data, 16, 16, 8, 0); bits_per_pixel = ximage->bits_per_pixel; XDestroyImage(ximage); bitmap_color_model = BC_WindowBase::evaluate_color_model(client_byte_order, server_byte_order, bits_per_pixel); // test shared memory // This doesn't ensure the X Server is on the local host if(use_shm && !XShmQueryExtension(display)) { use_shm = 0; } return 0; }
/** * Start the capture */ static void xshm_capture_start(struct xshm_data *data) { const char *server = (data->advanced && *data->server) ? data->server : NULL; data->dpy = XOpenDisplay(server); if (!data->dpy) { blog(LOG_ERROR, "Unable to open X display !"); goto fail; } if (!XShmQueryExtension(data->dpy)) { blog(LOG_ERROR, "XShm extension not found !"); goto fail; } data->use_xinerama = xinerama_is_active(data->dpy) ? true : false; if (xshm_update_geometry(data) < 0) { blog(LOG_ERROR, "failed to update geometry !"); goto fail; } data->xshm = xshm_attach(data->dpy, data->screen, data->width, data->height); if (!data->xshm) { blog(LOG_ERROR, "failed to attach shm !"); goto fail; } obs_enter_graphics(); data->cursor = xcursor_init(data->dpy); xcursor_offset(data->cursor, data->x_org, data->y_org); xshm_resize_texture(data); obs_leave_graphics(); return; fail: xshm_capture_stop(data); }
QXlibScreen::QXlibScreen() : mFormat(QImage::Format_RGB32) #if !defined(QT_NO_OPENGL) && defined(QT_OPENGL_ES_2) , mEGLDisplay(0) #endif { char *display_name = getenv("DISPLAY"); Display *display = XOpenDisplay(display_name); mDisplay = new QXlibDisplay(display); #ifndef DONT_USE_MIT_SHM int MIT_SHM_extension_supported = XShmQueryExtension (mDisplay->nativeDisplay()); Q_ASSERT(MIT_SHM_extension_supported == True); #endif original_x_errhandler = XSetErrorHandler(qt_x_errhandler); if (qgetenv("DO_X_SYNCHRONIZE").toInt()) XSynchronize(mDisplay->nativeDisplay(), true); mScreen = DefaultScreen(mDisplay->nativeDisplay()); XSelectInput(mDisplay->nativeDisplay(),rootWindow(), KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask); int width = DisplayWidth(mDisplay->nativeDisplay(), mScreen); int height = DisplayHeight(mDisplay->nativeDisplay(), mScreen); mGeometry = QRect(0,0,width,height); int physicalWidth = DisplayWidthMM(mDisplay->nativeDisplay(), mScreen); int physicalHeight = DisplayHeightMM(mDisplay->nativeDisplay(), mScreen); mPhysicalSize = QSize(physicalWidth,physicalHeight); int xSocketNumber = XConnectionNumber(mDisplay->nativeDisplay()); mDepth = DefaultDepth(mDisplay->nativeDisplay(),mScreen); #ifdef MYX11_DEBUG qDebug() << "X socket:"<< xSocketNumber; #endif QSocketNotifier *sock = new QSocketNotifier(xSocketNumber, QSocketNotifier::Read, this); connect(sock, SIGNAL(activated(int)), this, SLOT(eventDispatcher())); mCursor = new QXlibCursor(this); mKeyboard = new QXlibKeyboard(this); }
static PyObject * tkwin_ShmCheckExtension(TkWinObject * self, PyObject * args) { PyObject * result; if (XShmQueryExtension(Tk_Display(self->tkwin))) { int (*orighandler)(Display *, XErrorEvent *); shmerror = 0; orighandler = XSetErrorHandler(shm_error_handler); result = try_shm_image(self); XSetErrorHandler(orighandler); } else { Py_INCREF(Py_None); result = Py_None; } return result; }
/** * Return true if the screen supports the extension. */ boolean x11_screen_support(struct x11_screen *xscr, enum x11_screen_extension ext) { boolean supported = FALSE; switch (ext) { case X11_SCREEN_EXTENSION_XSHM: supported = XShmQueryExtension(xscr->dpy); break; #ifdef GLX_DIRECT_RENDERING case X11_SCREEN_EXTENSION_GLX: supported = x11_screen_init_glx(xscr); break; case X11_SCREEN_EXTENSION_DRI2: supported = x11_screen_init_dri2(xscr); break; #endif default: break; } return supported; }
static int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem) { Bool pixmaps; int major, minor; XGCValues values; if (!XShmQueryExtension(subsystem->display)) return -1; if (!XShmQueryVersion(subsystem->display, &major, &minor, &pixmaps)) return -1; if (!pixmaps) return -1; subsystem->fb_shm_info.shmid = -1; subsystem->fb_shm_info.shmaddr = (char*) -1; subsystem->fb_shm_info.readOnly = False; subsystem->fb_image = XShmCreateImage(subsystem->display, subsystem->visual, subsystem->depth, ZPixmap, NULL, &(subsystem->fb_shm_info), subsystem->width, subsystem->height); if (!subsystem->fb_image) { WLog_ERR(TAG, "XShmCreateImage failed"); return -1; } subsystem->fb_shm_info.shmid = shmget(IPC_PRIVATE, subsystem->fb_image->bytes_per_line * subsystem->fb_image->height, IPC_CREAT | 0600); if (subsystem->fb_shm_info.shmid == -1) { WLog_ERR(TAG, "shmget failed"); return -1; } subsystem->fb_shm_info.shmaddr = shmat(subsystem->fb_shm_info.shmid, 0, 0); subsystem->fb_image->data = subsystem->fb_shm_info.shmaddr; if (subsystem->fb_shm_info.shmaddr == ((char*) -1)) { WLog_ERR(TAG, "shmat failed"); return -1; } if (!XShmAttach(subsystem->display, &(subsystem->fb_shm_info))) return -1; XSync(subsystem->display, False); shmctl(subsystem->fb_shm_info.shmid, IPC_RMID, 0); subsystem->fb_pixmap = XShmCreatePixmap(subsystem->display, subsystem->root_window, subsystem->fb_image->data, &(subsystem->fb_shm_info), subsystem->fb_image->width, subsystem->fb_image->height, subsystem->fb_image->depth); XSync(subsystem->display, False); if (!subsystem->fb_pixmap) return -1; values.subwindow_mode = IncludeInferiors; values.graphics_exposures = False; subsystem->xshm_gc = XCreateGC(subsystem->display, subsystem->root_window, GCSubwindowMode | GCGraphicsExposures, &values); XSetFunction(subsystem->display, subsystem->xshm_gc, GXcopy); XSync(subsystem->display, False); return 1; }
static DFBResult InitLocal( DFBX11 *x11, DFBX11Shared *shared, CoreDFB *core ) { int i, n, d; XInitThreads(); x11->shared = shared; x11->core = core; x11->display = XOpenDisplay(getenv("DISPLAY")); if (!x11->display) { D_ERROR("X11: Error in XOpenDisplay for '%s'\n", getenv("DISPLAY")); return DFB_INIT; } x11->screenptr = DefaultScreenOfDisplay(x11->display); x11->screennum = DefaultScreen(x11->display); d = DefaultDepthOfScreen(x11->screenptr); for (i=0; i<x11->screenptr->ndepths; i++) { const Depth *depth = &x11->screenptr->depths[i]; for (n=0; n<depth->nvisuals; n++) { Visual *visual = &depth->visuals[n]; D_DEBUG_AT( X11_Core, "[Visual %d] ID 0x%02lx, depth %d, RGB 0x%06lx/0x%06lx/0x%06lx, %d bpRGB, %d entr.\n", n, visual->visualid, depth->depth, visual->red_mask, visual->green_mask, visual->blue_mask, visual->bits_per_rgb, visual->map_entries ); if (depth->depth != d) continue; switch (depth->depth) { case 32: if (visual->red_mask == 0xff0000 && visual->green_mask == 0x00ff00 && visual->blue_mask == 0x0000ff && !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_ARGB)]) x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_ARGB)] = visual; break; case 24: if (visual->red_mask == 0xff0000 && visual->green_mask == 0x00ff00 && visual->blue_mask == 0x0000ff && !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB32)]) x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB32)] = visual; break; case 16: if (visual->red_mask == 0xf800 && visual->green_mask == 0x07e0 && visual->blue_mask == 0x001f && !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB16)]) x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB16)] = visual; break; case 15: if (visual->red_mask == 0x7c00 && visual->green_mask == 0x03e0 && visual->blue_mask == 0x001f && !x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB555)]) x11->visuals[DFB_PIXELFORMAT_INDEX(DSPF_RGB555)] = visual; break; } } } if (XShmQueryExtension( x11->display )) XShmQueryVersion( x11->display, &x11->xshm_major, &x11->xshm_minor, &x11->use_shm ); x11->screen = dfb_screens_register( NULL, x11, x11PrimaryScreenFuncs ); dfb_layers_register( x11->screen, x11, x11PrimaryLayerFuncs ); dfb_layers_register( x11->screen, x11, x11PrimaryLayerFuncs ); dfb_layers_register( x11->screen, x11, x11PrimaryLayerFuncs ); return DFB_OK; }
static void getMyXImage(void) { #ifdef HAVE_SHM if (mLocalDisplay && XShmQueryExtension(mDisplay)) Shmem_Flag = 1; else { Shmem_Flag = 0; mp_msg(MSGT_VO, MSGL_WARN, "Shared memory not supported\nReverting to normal Xlib\n"); } if (Shmem_Flag) CompletionType = XShmGetEventBase(mDisplay) + ShmCompletion; if (Shmem_Flag) { myximage = XShmCreateImage(mDisplay, vinfo.visual, depth, ZPixmap, NULL, &Shminfo[0], image_width, image_height); if (myximage == NULL) { mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( Ximage error )\n"); goto shmemerror; } Shminfo[0].shmid = shmget(IPC_PRIVATE, myximage->bytes_per_line * myximage->height, IPC_CREAT | 0777); if (Shminfo[0].shmid < 0) { XDestroyImage(myximage); mp_msg(MSGT_VO, MSGL_V, "%s\n", strerror(errno)); //perror( strerror( errno ) ); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( seg id error )\n"); goto shmemerror; } Shminfo[0].shmaddr = (char *) shmat(Shminfo[0].shmid, 0, 0); if (Shminfo[0].shmaddr == ((char *) -1)) { XDestroyImage(myximage); if (Shminfo[0].shmaddr != ((char *) -1)) shmdt(Shminfo[0].shmaddr); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( address error )\n"); goto shmemerror; } myximage->data = Shminfo[0].shmaddr; ImageData = (unsigned char *) myximage->data; Shminfo[0].readOnly = False; XShmAttach(mDisplay, &Shminfo[0]); XSync(mDisplay, False); if (gXErrorFlag) { XDestroyImage(myximage); shmdt(Shminfo[0].shmaddr); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling.\n"); gXErrorFlag = 0; goto shmemerror; } else shmctl(Shminfo[0].shmid, IPC_RMID, 0); { static int firstTime = 1; if (firstTime) { mp_msg(MSGT_VO, MSGL_V, "Sharing memory.\n"); firstTime = 0; } } } else { shmemerror: Shmem_Flag = 0; #endif myximage = XCreateImage(mDisplay, vinfo.visual, depth, ZPixmap, 0, NULL, image_width, image_height, 8, 0); ImageDataOrig = malloc(myximage->bytes_per_line * image_height + 32); myximage->data = ImageDataOrig + 16 - ((long)ImageDataOrig & 15); memset(myximage->data, 0, myximage->bytes_per_line * image_height); ImageData = myximage->data; #ifdef HAVE_SHM } #endif }
static void getMyXImage(struct priv *p) { struct vo *vo = p->vo; #ifdef HAVE_SHM if (vo->x11->display_is_local && XShmQueryExtension(vo->x11->display)) p->Shmem_Flag = 1; else { p->Shmem_Flag = 0; mp_msg(MSGT_VO, MSGL_WARN, "Shared memory not supported\nReverting to normal Xlib\n"); } if (p->Shmem_Flag) p->CompletionType = XShmGetEventBase(vo->x11->display) + ShmCompletion; if (p->Shmem_Flag) { p->myximage = XShmCreateImage(vo->x11->display, p->vinfo.visual, p->depth, ZPixmap, NULL, &p->Shminfo[0], p->image_width, p->image_height); if (p->myximage == NULL) { mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( Ximage error )\n"); goto shmemerror; } p->Shminfo[0].shmid = shmget(IPC_PRIVATE, p->myximage->bytes_per_line * p->myximage->height, IPC_CREAT | 0777); if (p->Shminfo[0].shmid < 0) { XDestroyImage(p->myximage); mp_msg(MSGT_VO, MSGL_V, "%s\n", strerror(errno)); //perror( strerror( errno ) ); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( seg id error )\n"); goto shmemerror; } p->Shminfo[0].shmaddr = (char *) shmat(p->Shminfo[0].shmid, 0, 0); if (p->Shminfo[0].shmaddr == ((char *) -1)) { XDestroyImage(p->myximage); if (p->Shminfo[0].shmaddr != ((char *) -1)) shmdt(p->Shminfo[0].shmaddr); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling ( address error )\n"); goto shmemerror; } p->myximage->data = p->Shminfo[0].shmaddr; p->ImageData = (unsigned char *) p->myximage->data; p->Shminfo[0].readOnly = False; XShmAttach(vo->x11->display, &p->Shminfo[0]); XSync(vo->x11->display, False); if (p->gXErrorFlag) { XDestroyImage(p->myximage); shmdt(p->Shminfo[0].shmaddr); mp_msg(MSGT_VO, MSGL_WARN, "Shared memory error,disabling.\n"); p->gXErrorFlag = 0; goto shmemerror; } else shmctl(p->Shminfo[0].shmid, IPC_RMID, 0); if (!p->firstTime) { mp_msg(MSGT_VO, MSGL_V, "Sharing memory.\n"); p->firstTime = 1; } } else { shmemerror: p->Shmem_Flag = 0; #endif p->myximage = XCreateImage(vo->x11->display, p->vinfo.visual, p->depth, ZPixmap, 0, NULL, p->image_width, p->image_height, 8, 0); p->ImageDataOrig = malloc(p->myximage->bytes_per_line * p->image_height + 32); p->myximage->data = p->ImageDataOrig + 16 - ((long)p->ImageDataOrig & 15); memset(p->myximage->data, 0, p->myximage->bytes_per_line * p->image_height); p->ImageData = p->myximage->data; #ifdef HAVE_SHM } #endif }
void I_InitGraphics(void) { const char* displayname = NULL; int n; int pnum; int x=0; int y=0; { static int firsttime=1; if (!firsttime) { return; } firsttime = 0; } { // Check for screen enlargement char str[3] = { '-', 0, 0 }; for (n=1; n<4; n++) { str[1] = n + '0'; if (M_CheckParm(str)) multiply = n; } } X_width = SCREENWIDTH * multiply; X_height = SCREENHEIGHT * multiply; // check for command-line geometry if ( (pnum=M_CheckParm("-geom")) ? 1 : (pnum=M_CheckParm("-geometry"))) if (pnum+1 < myargc) { // check parm given // warning: char format, different type arg char xsign=' '; char ysign=' '; const char* pg = myargv[pnum+1]; pg += strcspn(pg, "+-"); // warning: char format, different type arg 3,5 n = sscanf(pg, "%c%d%c%d", &xsign, &x, &ysign, &y); if (n==2) x = y = 0; else if (n==4) { if (xsign == '-') x = -x; if (ysign == '-') y = -y; } else fprintf(stderr, "I_InitGraphics: bad -geom offsets \"%s\"\n", pg); } // check for command-line display name if ( (pnum=M_CheckParm("-disp")) ) // suggest parentheses around assignment displayname = myargv[pnum+1]; // CPhipps - support more standard -display param if ( (pnum=M_CheckParm("-display")) ) // ditto displayname = myargv[pnum+1]; // CPhipps - and -displayname as for xterm if ( (pnum=M_CheckParm("-displayname")) ) // ditto displayname = myargv[pnum+1]; // open the display if (!(X_display = XOpenDisplay(displayname))) { if (displayname) I_Error("Could not open display [%s]", displayname); else I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY")); } // use the default visual X_screen = DefaultScreen(X_display); X_deletewin = XInternAtom(X_display, "WM_DELETE_WINDOW", False); // check for the MITSHM extension // even if it's available, make sure it's a local connection lprintf(LO_INFO,"I_InitGraphics:"); #ifdef HAVE_LIBXXF86DGA if ((doDga = (M_CheckParm("-dga") && XF86DGAQueryExtension(X_display, &n, &n)) )) { lprintf(LO_INFO,"I_InitGraphics: found DGA extension\n"); if (M_CheckParm("-noaccel") || (X_opt & 1)) doDga = false; else lprintf(LO_INFO, "(using DGA)"); } else #endif #ifdef HAVE_LIBXEXT if ((doShm = XShmQueryExtension(X_display))) { if (!displayname) displayname = getenv("DISPLAY"); if (displayname) { // CPhipps - don't modify the original string, please. // - oops my code here was totally wrong // I have no idea exactly what should go here. if (M_CheckParm("-noaccel") || (X_opt & 1)) doShm = false; else lprintf(LO_INFO, "(using MITShm)"); } } else #endif if (devparm) fprintf(stderr, "No MITShm extension in server"); if (devparm) fputc('\n', stderr); if ((X_visual = I_FindMode(X_screen)) == NULL) I_Error("Unsupported visual"); // create the colormap X_cmap = XCreateColormap(X_display, RootWindow(X_display, X_screen), X_visual, true_color ? AllocNone : AllocAll); #ifdef HAVE_LIBXXF86DGA /* setup for DGA */ if(doDga) { char *fb; X_mainWindow=RootWindow(X_display, X_screen); XF86DGAGetViewPortSize(X_display, X_screen, &DGA_width, &DGA_height); XF86DGAGetVideo(X_display, X_screen, &fb, &DGA_real_width, &DGA_pagelen, &DGA_memlen); fprintf(stderr, "I_InitGraphics: DGA reports %dx%d scan=%d page=%d mem=%d\n", DGA_width,DGA_height,DGA_real_width,DGA_pagelen,DGA_memlen); out_buffer=(void*)fb; XF86DGADirectVideo(X_display, X_screen, XF86DGADirectGraphics); XF86DGASetVidPage(X_display, X_screen, 0); XF86DGAForkApp(X_screen); XSelectInput(X_display, X_mainWindow, KeyPressMask | KeyReleaseMask); fprintf(stderr,"DGA framebuffer @%p\n",fb); memset(fb,0,102400); } #endif #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { // setup attributes for main window unsigned long attribmask; XSetWindowAttributes attribs; attribmask = CWEventMask | CWColormap | CWBorderPixel; attribs.event_mask = KeyPressMask | KeyReleaseMask #ifdef MONITOR_VISIBILITY | VisibilityChangeMask #endif | ExposureMask; attribs.colormap = X_cmap; attribs.border_pixel = 0; // create the main window X_mainWindow = XCreateWindow( X_display, RootWindow(X_display, X_screen), x, y, X_width, X_height, 0, // borderwidth X_bpp, // depth InputOutput, X_visual, attribmask, &attribs ); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { XClassHint c_hint; XTextProperty x_name; XSizeHints s_hint; XWMHints wm_hint; char lcase_buf[10], ucase_buf[10]; char* str; strcpy(str = lcase_buf, lcase_lxdoom); XStringListToTextProperty(&str, 1, &x_name); s_hint.flags = PSize | PMinSize | PMaxSize; s_hint.min_width = s_hint.max_width = s_hint.base_width = X_width; s_hint.min_height = s_hint.max_height = s_hint.base_height = X_height; wm_hint.input = True; wm_hint.window_group = X_mainWindow; wm_hint.flags = InputHint | WindowGroupHint; strcpy(c_hint.res_name = lcase_buf, lcase_lxdoom); strcpy(c_hint.res_class = ucase_buf, ucase_lxdoom); XSetWMProtocols(X_display, X_mainWindow, &X_deletewin, 1); XSetWMProperties(X_display, X_mainWindow, &x_name, &x_name, (char**)myargv, myargc, &s_hint, &wm_hint, &c_hint); XFlush(X_display); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif // Hide pointer while over this window XDefineCursor(X_display, X_mainWindow, I_XCreateNullCursor( X_display, X_mainWindow ) ); { // create the GC XGCValues xgcvalues; int valuemask; valuemask = GCGraphicsExposures; xgcvalues.graphics_exposures = False; X_gc = XCreateGC(X_display, X_mainWindow, valuemask, &xgcvalues); } #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif { // name the window XStoreName(X_display, X_mainWindow, "lxdoom"); // map the window XMapWindow(X_display, X_mainWindow); } // wait until it is OK to draw #ifdef HAVE_LIBXXF86DGA if(!doDga) #endif do { XNextEvent(X_display, &X_event); } while (!(X_event.type == Expose && !X_event.xexpose.count)); #ifdef HAVE_LIBXXF86DGA if(doDga) {} else #endif #ifdef HAVE_LIBXEXT if (doShm) { X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion; // create the image image = XShmCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, &X_shminfo, X_width, X_height ); I_XShmGrabSharedMemory(image->bytes_per_line * image->height); if (!(out_buffer = (pval*)image->data)) { perror(""); I_Error("shmat() failed in I_InitGraphics()"); } // get the X server to attach to it if (!XShmAttach(X_display, &X_shminfo)) I_Error("XShmAttach() failed in InitGraphics()"); if (!expand_buffer) { // Render directly into MitSHM memory Z_Free(screens[0]); screens[0] = (unsigned char *) (image->data); } } else #endif { if (!expand_buffer) { // Very efficient, render directly into image out_buffer = (pval*)screens[0]; } else { // Will have to enlarge from rendering buffer // into image buffer out_buffer = (pval*)malloc (X_width * X_height * BYTESPP); } { /* hack to enable 15 bpp usage */ int bpp=X_bpp; if(bpp==15)bpp=16; image=XCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, (char*)out_buffer, X_width, X_height, bpp, 0); #ifdef NOT_NOW image=XCreateImage( X_display, X_visual, X_bpp, ZPixmap, 0, (char*)out_buffer, X_width, X_height, X_bpp, 0); #endif } if (!image) I_Error("XCreateImage: failed to create image %dx%d %d bpp", X_width, X_height, X_bpp); } atexit(I_ShutdownGraphics); I_XInitInputs(); }
/** * Initialize the x11 grab device demuxer (public device demuxer API). * * @param s1 Context from avformat core * @return <ul> * <li>AVERROR(ENOMEM) no memory left</li> * <li>AVERROR(EIO) other failure case</li> * <li>0 success</li> * </ul> */ static int x11grab_read_header(AVFormatContext *s1) { struct x11_grab *x11grab = s1->priv_data; Display *dpy; AVStream *st = NULL; enum PixelFormat input_pixfmt; XImage *image; int x_off = 0; int y_off = 0; int screen; int use_shm; char *dpyname, *offset; int ret = 0; AVRational framerate; dpyname = av_strdup(s1->filename); offset = strchr(dpyname, '+'); if (offset) { sscanf(offset, "%d,%d", &x_off, &y_off); x11grab->draw_mouse = !strstr(offset, "nomouse"); *offset= 0; } if ((ret = av_parse_video_size(&x11grab->width, &x11grab->height, x11grab->video_size)) < 0) { av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); goto out; } if ((ret = av_parse_video_rate(&framerate, x11grab->framerate)) < 0) { av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate); goto out; } av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, dpyname, x_off, y_off, x11grab->width, x11grab->height); dpy = XOpenDisplay(dpyname); av_freep(&dpyname); if(!dpy) { av_log(s1, AV_LOG_ERROR, "Could not open X display.\n"); ret = AVERROR(EIO); goto out; } st = avformat_new_stream(s1, NULL); if (!st) { ret = AVERROR(ENOMEM); goto out; } avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ screen = DefaultScreen(dpy); if (x11grab->follow_mouse) { int screen_w, screen_h; Window w; screen_w = DisplayWidth(dpy, screen); screen_h = DisplayHeight(dpy, screen); XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off, &ret, &ret, &ret); x_off -= x11grab->width / 2; y_off -= x11grab->height / 2; x_off = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width); y_off = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height); av_log(s1, AV_LOG_INFO, "followmouse is enabled, resetting grabbing region to x: %d y: %d\n", x_off, y_off); } use_shm = XShmQueryExtension(dpy); av_log(s1, AV_LOG_INFO, "shared memory extension%s found\n", use_shm ? "" : " not"); if(use_shm) { int scr = XDefaultScreen(dpy); image = XShmCreateImage(dpy, DefaultVisual(dpy, scr), DefaultDepth(dpy, scr), ZPixmap, NULL, &x11grab->shminfo, x11grab->width, x11grab->height); x11grab->shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT|0777); if (x11grab->shminfo.shmid == -1) { av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n"); ret = AVERROR(ENOMEM); goto out; } x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0); x11grab->shminfo.readOnly = False; if (!XShmAttach(dpy, &x11grab->shminfo)) { av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n"); /* needs some better error subroutine :) */ ret = AVERROR(EIO); goto out; } } else { image = XGetImage(dpy, RootWindow(dpy, screen), x_off,y_off, x11grab->width, x11grab->height, AllPlanes, ZPixmap); } switch (image->bits_per_pixel) { case 8: av_log (s1, AV_LOG_DEBUG, "8 bit palette\n"); input_pixfmt = PIX_FMT_PAL8; break; case 16: if ( image->red_mask == 0xf800 && image->green_mask == 0x07e0 && image->blue_mask == 0x001f ) { av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n"); input_pixfmt = PIX_FMT_RGB565; } else if (image->red_mask == 0x7c00 && image->green_mask == 0x03e0 && image->blue_mask == 0x001f ) { av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n"); input_pixfmt = PIX_FMT_RGB555; } else { av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); ret = AVERROR(EIO); goto out; } break; case 24: if ( image->red_mask == 0xff0000 && image->green_mask == 0x00ff00 && image->blue_mask == 0x0000ff ) { input_pixfmt = PIX_FMT_BGR24; } else if ( image->red_mask == 0x0000ff && image->green_mask == 0x00ff00 && image->blue_mask == 0xff0000 ) { input_pixfmt = PIX_FMT_RGB24; } else { av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); ret = AVERROR(EIO); goto out; } break; case 32: input_pixfmt = PIX_FMT_0RGB32; break; default: av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel); ret = AVERROR(EINVAL); goto out; } x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8; x11grab->dpy = dpy; x11grab->time_base = (AVRational) { framerate.den, framerate.num }; x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base); x11grab->x_off = x_off; x11grab->y_off = y_off; x11grab->image = image; x11grab->use_shm = use_shm; st->codec->codec_type = AVMEDIA_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_RAWVIDEO; st->codec->width = x11grab->width; st->codec->height = x11grab->height; st->codec->pix_fmt = input_pixfmt; st->codec->time_base = x11grab->time_base; st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(x11grab->time_base) * 8; out: return ret; }