static int glx_init(struct MPGLContext *ctx, int flags) { struct vo *vo = ctx->vo; struct glx_context *glx_ctx = ctx->priv; if (!vo_x11_init(ctx->vo)) goto uninit; int glx_major, glx_minor; if (!glXQueryVersion(vo->x11->display, &glx_major, &glx_minor)) { MP_ERR(vo, "GLX not found.\n"); goto uninit; } // FBConfigs were added in GLX version 1.3. if (MPGL_VER(glx_major, glx_minor) < MPGL_VER(1, 3)) { MP_ERR(vo, "GLX version older than 1.3.\n"); goto uninit; } int glx_attribs[] = { GLX_X_RENDERABLE, True, GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_ALPHA_SIZE, 0, GLX_DOUBLEBUFFER, True, None }; GLXFBConfig fbc = NULL; if (flags & VOFLAG_ALPHA) { set_glx_attrib(glx_attribs, GLX_ALPHA_SIZE, 1); fbc = select_fb_config(vo, glx_attribs, flags); if (!fbc) { set_glx_attrib(glx_attribs, GLX_ALPHA_SIZE, 0); flags &= ~VOFLAG_ALPHA; } } if (!fbc) fbc = select_fb_config(vo, glx_attribs, flags); if (!fbc) { MP_ERR(vo, "no GLX support present\n"); goto uninit; } MP_VERBOSE(vo, "GLX chose FB config with ID 0x%x\n", (int)(intptr_t)fbc); glx_ctx->fbc = fbc; glx_ctx->vinfo = glXGetVisualFromFBConfig(vo->x11->display, fbc); if (glx_ctx->vinfo) { MP_VERBOSE(vo, "GLX chose visual with ID 0x%x\n", (int)glx_ctx->vinfo->visualid); } else { MP_WARN(vo, "Selected GLX FB config has no associated X visual\n"); } if (!vo_x11_create_vo_window(vo, glx_ctx->vinfo, "gl")) goto uninit; bool success = false; if (!(flags & VOFLAG_GLES)) { success = create_context_x11_gl3(ctx, flags, 300, false); if (!success) success = create_context_x11_old(ctx); } if (!success) // try ES success = create_context_x11_gl3(ctx, flags, 200, true); if (success && !glXIsDirect(vo->x11->display, glx_ctx->context)) ctx->gl->mpgl_caps |= MPGL_CAP_SW; if (!success) goto uninit; glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_RED_SIZE, &ctx->gl->fb_r); glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_GREEN_SIZE, &ctx->gl->fb_g); glXGetFBConfigAttrib(vo->x11->display, fbc, GLX_BLUE_SIZE, &ctx->gl->fb_b); ctx->gl->fb_premultiplied = true; return 0; uninit: glx_uninit(ctx); return -1; }
static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { uint8_t *fbmem; int i; struct omapfb_color_key color_key; XVisualInfo vinfo; XSetWindowAttributes xswa; XWindowAttributes attribs; unsigned long xswamask; int depth; Window root, parent; Window *child; unsigned int n_children; fullscreen_flag = flags & VOFLAG_FULLSCREEN; if (!fb_overlay_only) { if (!title) title = "MPlayer OMAPFB (X11/FB) render"; XGetWindowAttributes(mDisplay, mRootWin, &attribs); depth = attribs.depth; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24; XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); xswa.border_pixel = 0; xswa.background_pixel = xv_colorkey = TRANSPARENT_COLOR_KEY; xswamask = CWBackPixel | CWBorderPixel; xv_ck_info.method = CK_METHOD_BACKGROUND; vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight, flags, CopyFromParent, "omapfb", title); XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xswa); /* Need to receive events on the parent window -- so when it is moved / resized / etc., we know. */ if(WinID > 0) { /* Query window tree information */ XQueryTree(mDisplay, vo_window, &root, &parent, &child, &n_children); if (n_children) XFree(child); XUnmapWindow(mDisplay, vo_window); if (parent) XSelectInput(mDisplay, parent, StructureNotifyMask); XMapWindow(mDisplay, vo_window); } vo_calc_drwXY(&drwX, &drwY); vo_xv_draw_colorkey(drwX, drwY, vo_dwidth - 1, vo_dheight - 1); } fbmem = mmap(NULL, minfo.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev_fd, 0); if (fbmem == MAP_FAILED) { mp_msg(MSGT_VO, MSGL_FATAL, "[omapfb] Error mmap\n"); return -1; } for (i = 0; i < minfo.size / 4; i++) ((uint32_t*)fbmem)[i] = 0x80008000; sinfo.xres = FFMIN(sinfo_p0.xres, width) & ~15; sinfo.yres = FFMIN(sinfo_p0.yres, height) & ~15; sinfo.xoffset = 0; sinfo.yoffset = 0; sinfo.nonstd = OMAPFB_COLOR_YUY422; fb_pages[0].x = 0; fb_pages[0].y = 0; fb_pages[0].buf = fbmem; if (dbl_buffer && minfo.size >= sinfo.xres * sinfo.yres * 2) { sinfo.xres_virtual = sinfo.xres; sinfo.yres_virtual = sinfo.yres * 2; fb_pages[1].x = 0; fb_pages[1].y = sinfo.yres; fb_pages[1].buf = fbmem + sinfo.xres * sinfo.yres * 2; fb_page_flip = 1; } else { sinfo.xres_virtual = sinfo.xres; sinfo.yres_virtual = sinfo.yres; fb_page_flip = 0; } ioctl(dev_fd, FBIOPUT_VSCREENINFO, &sinfo); if (WinID <= 0) { if (fullscreen_flag) { omapfb_update(0, 0, sinfo_p0.xres, sinfo_p0.yres, 1); } else { omapfb_update(sinfo_p0.xres / 2 - sinfo.xres / 2, sinfo_p0.yres / 2 - sinfo.yres / 2, sinfo.xres, sinfo.yres, 1); } } color_key.channel_out = OMAPFB_CHANNEL_OUT_LCD; color_key.background = 0x0; color_key.trans_key = TRANSPARENT_COLOR_KEY; if (fb_overlay_only) color_key.key_type = OMAPFB_COLOR_KEY_DISABLED; else color_key.key_type = OMAPFB_COLOR_KEY_GFX_DST; ioctl(dev_fd, OMAPFB_SET_COLOR_KEY, &color_key); plane_ready = 1; return 0; }
static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { // int screen; // int interval, prefer_blank, allow_exp, nothing; unsigned int fg, bg; Colormap theCmap; XSetWindowAttributes xswa; unsigned long xswamask; const struct fmt2Xfmtentry_s *fmte = fmt2Xfmt; #ifdef CONFIG_XF86VM int vm = flags & VOFLAG_MODESWITCHING; #endif Flip_Flag = flags & VOFLAG_FLIPPING; zoomFlag = flags & VOFLAG_SWSCALE; old_vo_dwidth = -1; old_vo_dheight = -1; int_pause = 0; if (!title) title = "MPlayer X11 (XImage/Shm) render"; in_format = format; srcW = width; srcH = height; XGetWindowAttributes(mDisplay, mRootWin, &attribs); depth = attribs.depth; if (depth != 15 && depth != 16 && depth != 24 && depth != 32) { Visual *visual; depth = vo_find_depth_from_visuals(mDisplay, mScreen, &visual); } if (!XMatchVisualInfo(mDisplay, mScreen, depth, DirectColor, &vinfo) || (WinID > 0 && vinfo.visualid != XVisualIDFromVisual(attribs.visual))) XMatchVisualInfo(mDisplay, mScreen, depth, TrueColor, &vinfo); /* set image size (which is indeed neither the input nor output size), if zoom is on it will be changed during draw_slice anyway so we don't duplicate the aspect code here */ image_width = (width + 7) & (~7); image_height = height; #ifdef CONFIG_GUI if (use_gui) guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize the window else #endif { #ifdef CONFIG_XF86VM if (vm) { vo_vm_switch(); } #endif bg = WhitePixel(mDisplay, mScreen); fg = BlackPixel(mDisplay, mScreen); theCmap = vo_x11_create_colormap(&vinfo); xswa.background_pixel = 0; xswa.border_pixel = 0; xswa.colormap = theCmap; xswamask = CWBackPixel | CWBorderPixel | CWColormap; #ifdef CONFIG_XF86VM if (vm) { xswa.override_redirect = True; xswamask |= CWOverrideRedirect; } #endif vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, vo_dwidth, vo_dheight, flags, theCmap, "x11", title); if (WinID > 0) depth = vo_x11_update_geometry(); #ifdef CONFIG_XF86VM if (vm) { /* Grab the mouse pointer in our window */ if (vo_grabpointer) XGrabPointer(mDisplay, vo_window, True, 0, GrabModeAsync, GrabModeAsync, vo_window, None, CurrentTime); XSetInputFocus(mDisplay, vo_window, RevertToNone, CurrentTime); } #endif } if (myximage) { freeMyXImage(); sws_freeContext(swsContext); } getMyXImage(); while (fmte->mpfmt) { int depth = IMGFMT_RGB_DEPTH(fmte->mpfmt); /* bits_per_pixel in X seems to be set to 16 for 15 bit formats => force depth to 16 so that only the color masks are used for the format check */ if (depth == 15) depth = 16; if (depth == myximage->bits_per_pixel && fmte->byte_order == myximage->byte_order && fmte->red_mask == myximage->red_mask && fmte->green_mask == myximage->green_mask && fmte->blue_mask == myximage->blue_mask) break; fmte++; } if (!fmte->mpfmt) { mp_msg(MSGT_VO, MSGL_ERR, "X server image format not supported, please contact the developers\n"); return -1; } out_format = fmte->mpfmt; switch ((bpp = myximage->bits_per_pixel)) { case 24: draw_alpha_fnc = draw_alpha_24; break; case 32: draw_alpha_fnc = draw_alpha_32; break; case 15: case 16: if (depth == 15) draw_alpha_fnc = draw_alpha_15; else draw_alpha_fnc = draw_alpha_16; break; default: draw_alpha_fnc = draw_alpha_null; } out_offset = 0; // for these formats conversion is currently not support and // we can easily "emulate" them. if (out_format & 64 && (IMGFMT_IS_RGB(out_format) || IMGFMT_IS_BGR(out_format))) { out_format &= ~64; #ifdef WORDS_BIGENDIAN out_offset = 1; #else out_offset = -1; #endif } /* always allocate swsContext as size could change between frames */ swsContext = sws_getContextFromCmdLine(width, height, in_format, width, height, out_format); if (!swsContext) return -1; dst_width = width; //printf( "X11 bpp: %d color mask: R:%lX G:%lX B:%lX\n",bpp,myximage->red_mask,myximage->green_mask,myximage->blue_mask ); return 0; }