static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ int bpp = pixel_stride(image_format); vo_draw_alpha_func draw = vo_get_draw_alpha(image_format); if (!draw) return; draw(w,h,src,srca,stride,ImageData+bpp*(y0*image_width+x0),bpp*image_width); }
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) { struct fb_cmap *cmap; int fs = flags & VOFLAG_FULLSCREEN; int x_offset = vo_dx + (d_width - width ) / 2; int y_offset = vo_dy + (d_height - height) / 2; x_offset = av_clip(x_offset, 0, fb_vinfo.xres - width); y_offset = av_clip(y_offset, 0, fb_vinfo.yres - height); in_width = width; in_height = height; if (fb_vinfo.xres < in_width || fb_vinfo.yres < in_height) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Screensize is smaller than video size (%dx%d < %dx%d)\n", fb_vinfo.xres, fb_vinfo.yres, in_width, in_height); return 1; } draw_alpha_p = vo_get_draw_alpha(format); fb_pixel_size = pixel_stride(format); if (vo_config_count == 0) { if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't get FSCREENINFO: %s\n", strerror(errno)); return 1; } if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] type %d not supported\n", fb_finfo.type); return 1; } switch (fb_finfo.visual) { case FB_VISUAL_TRUECOLOR: break; case FB_VISUAL_DIRECTCOLOR: mp_msg(MSGT_VO, MSGL_V, "[fbdev2] creating cmap for directcolor\n"); if (ioctl(fb_dev_fd, FBIOGETCMAP, &fb_oldcmap)) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] can't get cmap: %s\n", strerror(errno)); return 1; } if (!(cmap = make_directcolor_cmap(&fb_vinfo))) return 1; if (ioctl(fb_dev_fd, FBIOPUTCMAP, cmap)) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] can't put cmap: %s\n", strerror(errno)); free(cmap->red); free(cmap); return 1; } fb_cmap_changed = 1; free(cmap->red); free(cmap); break; default: mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] visual: %d not yet supported\n", fb_finfo.visual); break; } fb_size = fb_finfo.smem_len; fb_line_len = fb_finfo.line_length; if ((frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE, MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) -1) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't mmap %s: %s\n", fb_dev_name, strerror(errno)); return 1; } } center = frame_buffer + x_offset * fb_pixel_size + y_offset * fb_line_len; #ifndef USE_CONVERT2FB if (!(next_frame = realloc(next_frame, in_width * in_height * fb_pixel_size))) { mp_msg(MSGT_VO, MSGL_ERR, "[fbdev2] Can't malloc next_frame: %s\n", strerror(errno)); return 1; } #endif if (fs) { int len = fb_line_len * fb_vinfo.yres; int i; switch (format) { case IMGFMT_YUY2: for (i = 0; i < len - 3;) { frame_buffer[i++] = 0; frame_buffer[i++] = 0x80; frame_buffer[i++] = 0; frame_buffer[i++] = 0x80; } break; case IMGFMT_UYVY: for (i = 0; i < len - 3;) { frame_buffer[i++] = 0x80; frame_buffer[i++] = 0; frame_buffer[i++] = 0x80; frame_buffer[i++] = 0; } break; default: memset(frame_buffer, 0, len); } } 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; Colormap theCmap; 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_XF86VM if (vm) { vo_vm_switch(); } #endif theCmap = vo_x11_create_colormap(&vinfo); 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; draw_alpha_func = vo_get_draw_alpha(out_format); bpp = myximage->bits_per_pixel; out_offset = 0; // We can easily "emulate" non-native RGB32 and BGR32 if (out_format == (IMGFMT_BGR32 | 128) || out_format == (IMGFMT_RGB32 | 128)) { out_format &= ~128; #if HAVE_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; }
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) { struct fb_cmap *cmap; int vm = flags & VOFLAG_MODESWITCHING; int zoom = flags & VOFLAG_SWSCALE; fs = flags & VOFLAG_FULLSCREEN; if (pre_init_err == -2) { mp_msg(MSGT_VO, MSGL_ERR, "Internal fatal error: config() was called before preinit()\n"); return -1; } if (pre_init_err) return 1; if (fb_mode_name && !vm) { mp_msg(MSGT_VO, MSGL_ERR, "-fbmode can only be used with -vm\n"); return 1; } if (vm && parse_fbmode_cfg(fb_mode_cfgfile) < 0) return 1; if (d_width && (fs || vm)) { out_width = d_width; out_height = d_height; } else { out_width = width; out_height = height; } in_width = width; in_height = height; pixel_format = format; if (fb_mode_name) { if (!(fb_mode = find_mode_by_name(fb_mode_name))) { mp_msg(MSGT_VO, MSGL_ERR, "can't find requested video mode\n"); return 1; } fb_mode2fb_vinfo(fb_mode, &fb_vinfo, fb_rgb); } else if (vm) { monitor_hfreq = str2range(monitor_hfreq_str); monitor_vfreq = str2range(monitor_vfreq_str); monitor_dotclock = str2range(monitor_dotclock_str); if (!monitor_hfreq || !monitor_vfreq || !monitor_dotclock) { mp_msg(MSGT_VO, MSGL_ERR, "you have to specify the capabilities of" " the monitor.\n"); return 1; } if (!(fb_mode = find_best_mode(out_width, out_height, monitor_hfreq, monitor_vfreq, monitor_dotclock))) { mp_msg(MSGT_VO, MSGL_ERR, "can't find best video mode\n"); return 1; } mp_msg(MSGT_VO, MSGL_V, "using mode %dx%d @ %.1fHz\n", fb_mode->xres, fb_mode->yres, vsf(fb_mode)); fb_mode2fb_vinfo(fb_mode, &fb_vinfo, fb_rgb); } fb_bpp_we_want = fb_bpp; set_bpp(&fb_vinfo, fb_bpp, fb_rgb); fb_vinfo.xres_virtual = fb_vinfo.xres; fb_vinfo.yres_virtual = fb_vinfo.yres; fb_page = 0; if (vo_doublebuffering) { fb_vinfo.yres_virtual <<= 1; fb_vinfo.yoffset = 0; fb_page = 1; // start writing into the page we don't display } if (fb_tty_fd >= 0 && ioctl(fb_tty_fd, KDSETMODE, KD_GRAPHICS) < 0) { mp_msg(MSGT_VO, MSGL_V, "Can't set graphics mode: %s\n", strerror(errno)); close(fb_tty_fd); fb_tty_fd = -1; } if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo)) // Intel drivers fail if we request a transparency channel fb_vinfo.transp.length = fb_vinfo.transp.offset = 0; if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo)) { mp_msg(MSGT_VO, MSGL_ERR, "Can't put VSCREENINFO: %s\n", strerror(errno)); if (fb_tty_fd >= 0 && ioctl(fb_tty_fd, KDSETMODE, KD_TEXT) < 0) { mp_msg(MSGT_VO, MSGL_ERR, "Can't restore text mode: %s\n", strerror(errno)); } return 1; } fb_pixel_size = fb_vinfo.bits_per_pixel / 8; fb_bpp = fb_vinfo.bits_per_pixel; if (fb_bpp == 16) fb_bpp = fb_vinfo.red.length + fb_vinfo.green.length + fb_vinfo.blue.length; if (fb_bpp_we_want != fb_bpp) mp_msg(MSGT_VO, MSGL_WARN, "requested %d bpp, got %d bpp!!!\n", fb_bpp_we_want, fb_bpp); draw_alpha_p = vo_get_draw_alpha(format); fb_xres = fb_vinfo.xres; fb_yres = fb_vinfo.yres; if (vm || fs) { out_width = fb_xres; out_height = fb_yres; } if (out_width < in_width || out_height < in_height) { mp_msg(MSGT_VO, MSGL_ERR, "screensize %ix%i is smaller than video size %ix%i\n", out_width, out_height, in_width, in_height); return 1; } first_row = (out_height - in_height) / 2; last_row = (out_height + in_height) / 2; if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) { mp_msg(MSGT_VO, MSGL_ERR, "Can't get FSCREENINFO: %s\n", strerror(errno)); return 1; } if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) { mp_msg(MSGT_VO, MSGL_ERR, "type %d not supported\n", fb_finfo.type); return 1; } switch (fb_finfo.visual) { case FB_VISUAL_TRUECOLOR: break; case FB_VISUAL_DIRECTCOLOR: mp_msg(MSGT_VO, MSGL_V, "creating cmap for directcolor\n"); if (ioctl(fb_dev_fd, FBIOGETCMAP, &fb_oldcmap)) { mp_msg(MSGT_VO, MSGL_ERR, "can't get cmap: %s\n", strerror(errno)); return 1; } if (!(cmap = make_directcolor_cmap(&fb_vinfo))) return 1; if (ioctl(fb_dev_fd, FBIOPUTCMAP, cmap)) { mp_msg(MSGT_VO, MSGL_ERR, "can't put cmap: %s\n", strerror(errno)); free(cmap->red); free(cmap->green); free(cmap->blue); free(cmap); return 1; } fb_cmap_changed = 1; free(cmap->red); free(cmap->green); free(cmap->blue); free(cmap); break; default: mp_msg(MSGT_VO, MSGL_ERR, "visual: %d not yet supported\n", fb_finfo.visual); break; } fb_line_len = fb_finfo.line_length; fb_size = fb_finfo.smem_len; if (vo_doublebuffering && fb_size < 2 * fb_yres * fb_line_len) { mp_msg(MSGT_VO, MSGL_WARN, "framebuffer too small for double-buffering, disabling\n"); vo_doublebuffering = 0; fb_page = 0; } #ifdef CONFIG_VIDIX if (vidix_name) { unsigned image_width, image_height, x_offset, y_offset; if (zoom || fs) { aspect_save_orig(width, height); aspect_save_prescale(d_width, d_height); aspect_save_screenres(fb_xres, fb_yres); aspect(&image_width, &image_height, fs ? A_ZOOM : A_NOZOOM); } else { image_width = width; image_height = height; } if (fb_xres > image_width) x_offset = (fb_xres - image_width) / 2; else x_offset = 0; if (fb_yres > image_height) y_offset = (fb_yres - image_height) / 2; else y_offset = 0; if (vidix_init(width, height, x_offset, y_offset, image_width, image_height, format, fb_bpp, fb_xres, fb_yres) != 0) { mp_msg(MSGT_VO, MSGL_ERR, "Can't initialize VIDIX driver\n"); vidix_name = NULL; vidix_term(); return -1; } else mp_msg(MSGT_VO, MSGL_V, "Using VIDIX\n"); vidix_start(); if (vidix_grkey_support()) { vidix_grkey_get(&gr_key); gr_key.key_op = KEYS_PUT; if (!(vo_colorkey & 0xff000000)) { gr_key.ckey.op = CKEY_TRUE; gr_key.ckey.red = (vo_colorkey & 0x00ff0000) >> 16; gr_key.ckey.green = (vo_colorkey & 0x0000ff00) >> 8; gr_key.ckey.blue = vo_colorkey & 0x000000ff; } else gr_key.ckey.op = CKEY_FALSE; vidix_grkey_set(&gr_key); }