4 * Copyright (C) 2001 Andreas Ackermann <acki@acki-netz.de>
5 * Sourceforge username: acki2
7 * This file is part of MPlayer.
9 * MPlayer is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * MPlayer is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "video_out.h"
31 #include "video_out_internal.h"
33 #include "x11_common.h"
34 #include "fastmemcpy.h"
38 #include <X11/extensions/xf86dga.h>
41 #include <X11/extensions/xf86vmode.h>
44 static const vo_info_t info
= {
46 "DGA ( Direct Graphic Access V2.0 )",
49 "DGA ( Direct Graphic Access V1.0+XF86VidModeExt. )",
51 "DGA ( Direct Graphic Access V1.0 )",
55 "Andreas Ackermann <acki@acki-netz.de>",
59 const LIBVO_EXTERN(dga
)
60 //------------------------------------------------------------------
61 //#define BITSPP (vo_dga_modes[vo_dga_active_mode].vdm_bitspp)
62 //#define BYTESPP (vo_dga_modes[vo_dga_active_mode].vdm_bytespp)
63 #define VO_DGA_INVALID_RES 100000
64 #define HW_MODE (vo_dga_modes[vo_dga_hw_mode])
65 #define SRC_MODE (vo_dga_modes[vo_dga_src_mode])
68 int vdm_mplayer_depth
;
79 //------------------------------------------------------------------
81 static struct vd_modes vo_dga_modes
[] = {
82 // these entries describe HW modes
83 // however, we use the same entries to tell mplayer what we support
84 // so the last two values describe, which HW mode to use and which conversion
85 // function to use for a mode that is not supported by HW
87 {0, 0, 0, 0, 0, 0, 0, 0, 0,},
88 {15, 0, 15, 16, 2, 0x7c00, 0x03e0, 0x001f, 2,},
89 {16, 0, 16, 16, 2, 0xf800, 0x07e0, 0x001f, 2,},
90 {24, 0, 24, 24, 3, 0xff0000, 0x00ff00, 0x0000ff, 4},
91 {32, 0, 24, 32, 4, 0x00ff0000, 0x0000ff00, 0x000000ff, 4}
94 static int vo_dga_mode_num
=
95 sizeof(vo_dga_modes
) / sizeof(struct vd_modes
);
97 // enable a HW mode (by description)
98 static int vd_EnableMode(int depth
, int bitspp
,
99 int rmask
, int gmask
, int bmask
)
103 for (i
= 1; i
< vo_dga_mode_num
; i
++)
105 if (vo_dga_modes
[i
].vdm_depth
== depth
&&
106 vo_dga_modes
[i
].vdm_bitspp
== bitspp
&&
107 vo_dga_modes
[i
].vdm_rmask
== rmask
&&
108 vo_dga_modes
[i
].vdm_gmask
== gmask
&&
109 vo_dga_modes
[i
].vdm_bmask
== bmask
)
111 vo_dga_modes
[i
].vdm_supported
= 1;
112 vo_dga_modes
[i
].vdm_hw_mode
= i
;
119 static int vd_ModeEqual(int depth
, int bitspp
,
120 int rmask
, int gmask
, int bmask
, int index
)
122 return (vo_dga_modes
[index
].vdm_depth
== depth
&&
123 vo_dga_modes
[index
].vdm_bitspp
== bitspp
&&
124 vo_dga_modes
[index
].vdm_rmask
== rmask
&&
125 vo_dga_modes
[index
].vdm_gmask
== gmask
&&
126 vo_dga_modes
[index
].vdm_bmask
== bmask
) ? 1 : 0;
130 // enable a HW mode (mplayer_depth decides which)
131 static int vd_ValidateMode(int mplayer_depth
)
135 if (mplayer_depth
== 0)
137 for (i
= 1; i
< vo_dga_mode_num
; i
++)
139 if (vo_dga_modes
[i
].vdm_mplayer_depth
== mplayer_depth
)
141 vo_dga_modes
[i
].vdm_supported
= 1;
142 vo_dga_modes
[i
].vdm_hw_mode
= i
;
149 // do we support this mode? (not important whether native or conversion)
150 static int vd_ModeValid(int mplayer_depth
)
154 if (mplayer_depth
== 0)
156 for (i
= 1; i
< vo_dga_mode_num
; i
++)
158 if (vo_dga_modes
[i
].vdm_mplayer_depth
== mplayer_depth
&&
159 vo_dga_modes
[i
].vdm_supported
!= 0)
167 static char *vd_GetModeString(int index
)
170 #define VO_DGA_MAX_STRING_LEN 100
171 static char stringbuf
[VO_DGA_MAX_STRING_LEN
];
173 stringbuf
[VO_DGA_MAX_STRING_LEN
- 1] = 0;
174 snprintf(stringbuf
, VO_DGA_MAX_STRING_LEN
- 2,
175 "depth=%d, bpp=%d, r=%06x, g=%06x, b=%06x, %s (-bpp %d)",
176 vo_dga_modes
[index
].vdm_depth
,
177 vo_dga_modes
[index
].vdm_bitspp
,
178 vo_dga_modes
[index
].vdm_rmask
,
179 vo_dga_modes
[index
].vdm_gmask
,
180 vo_dga_modes
[index
].vdm_bmask
,
182 vdm_supported
? "native" : "not supported",
183 vo_dga_modes
[index
].vdm_mplayer_depth
);
187 //-----------------------------------------------------------------
189 #if defined(CONFIG_XF86VM) && !defined(CONFIG_DGA2)
190 static XF86VidModeModeInfo
**vo_dga_vidmodes
= NULL
;
194 static int vo_dga_src_format
;
195 static int vo_dga_width
; // bytes per line in framebuffer
196 static int vo_dga_vp_width
; // visible pixels per line in
199 static int vo_dga_vp_height
; // visible lines in framebuffer
200 static int vo_dga_is_running
= 0;
201 static int vo_dga_src_width
; // width of video in pixels
202 static int vo_dga_src_height
; // height of video in pixels
203 static int vo_dga_src_offset
= 0; // offset in src
204 static int vo_dga_vp_offset
= 0; // offset in dest
205 static int vo_dga_bytes_per_line
; // bytes per line to copy
206 static int vo_dga_vp_skip
; // dto. for dest
207 static int vo_dga_lines
; // num of lines to copy
208 static int vo_dga_hw_mode
= 0; // index in mode list that is actually
210 // used by framebuffer
211 static int vo_dga_src_mode
= 0; // index in mode list that is used by
214 static int vo_dga_XServer_mode
= 0; // index in mode list for resolution
217 static XDGAMode
*vo_modelines
;
218 static int vo_modecount
;
221 #define MAX_NR_VIDEO_BUFFERS 3
223 #define CURRENT_VIDEO_BUFFER \
224 (vo_dga_video_buffer[vo_dga_current_video_buffer])
226 static int vo_dga_nr_video_buffers
; // Total number of frame buffers.
227 static int vo_dga_current_video_buffer
; // Buffer available for rendering.
229 static struct video_buffer
233 } vo_dga_video_buffer
[MAX_NR_VIDEO_BUFFERS
];
235 /* saved src and dst dimensions for SwScaler */
236 static unsigned int scale_srcW
= 0,
237 scale_dstW
= 0, scale_srcH
= 0, scale_dstH
= 0;
239 //---------------------------------------------------------
241 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
242 unsigned char *srca
, int stride
)
249 offset
= vo_dga_width
* y0
+ x0
;
250 buffer_stride
= vo_dga_width
;
251 d
= CURRENT_VIDEO_BUFFER
.data
+ vo_dga_vp_offset
;
253 switch (HW_MODE
.vdm_mplayer_depth
)
257 vo_draw_alpha_rgb32(w
, h
, src
, srca
, stride
, d
+ 4 * offset
,
261 vo_draw_alpha_rgb24(w
, h
, src
, srca
, stride
, d
+ 3 * offset
,
265 vo_draw_alpha_rgb15(w
, h
, src
, srca
, stride
, d
+ 2 * offset
,
269 vo_draw_alpha_rgb16(w
, h
, src
, srca
, stride
, d
+ 2 * offset
,
276 //---------------------------------------------------------
281 // quick & dirty - for debugging only
283 static void fillblock(char *strt
, int yoff
, int lines
, int val
)
287 for (i
= strt
+ yoff
* vo_dga_width
* HW_MODE
.vdm_bytespp
;
288 i
< strt
+ (lines
+ yoff
) * vo_dga_width
* HW_MODE
.vdm_bytespp
;)
295 //---------------------------------------------------------
297 static int draw_frame(uint8_t * src
[])
300 int numlines
= vo_dga_lines
;
305 d
= CURRENT_VIDEO_BUFFER
.data
+ vo_dga_vp_offset
;
308 vo_dga_bytes_per_line
,
310 vo_dga_bytes_per_line
+ vo_dga_vp_skip
,
311 vo_dga_bytes_per_line
);
316 d
= CURRENT_VIDEO_BUFFER
.data
+ vo_dga_vp_offset
;
317 fillblock(d
, 0, 10, 0x800000ff);
318 fillblock(d
, 10, 10, 0x8000ff00);
319 fillblock(d
, 20, 10, 0x80ff0000);
320 fillblock(d
, 30, 10, 0xff0000ff);
321 fillblock(d
, 40, 10, 0x800000ff);
322 fillblock(d
, 50, 10, 0x0f0000ff);
327 //---------------------------------------------------------
329 static void check_events(void)
331 vo_x11_check_events(mDisplay
);
334 //---------------------------------------------------------
338 static void draw_osd(void)
340 vo_draw_text(vo_dga_src_width
, vo_dga_src_height
, draw_alpha
);
343 static void switch_video_buffers(void)
345 vo_dga_current_video_buffer
=
346 (vo_dga_current_video_buffer
+ 1) % vo_dga_nr_video_buffers
;
349 static void flip_page(void)
351 if (1 < vo_dga_nr_video_buffers
)
354 XDGASetViewport(mDisplay
, mScreen
,
355 0, CURRENT_VIDEO_BUFFER
.y
, XDGAFlipRetrace
);
357 XF86DGASetViewPort(mDisplay
, mScreen
, 0, CURRENT_VIDEO_BUFFER
.y
);
359 switch_video_buffers();
363 //---------------------------------------------------------
365 static int draw_slice(uint8_t * src
[], int stride
[],
366 int w
, int h
, int x
, int y
)
371 //---------------------------------------------------------
373 static int query_format(uint32_t format
)
376 if ((format
& IMGFMT_BGR_MASK
) == IMGFMT_BGR
&&
377 vd_ModeValid(format
& 0xff))
379 return VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
| VFCAP_OSD
;
385 //---------------------------------------------------------
387 static void uninit(void)
391 XDGADevice
*dgadevice
;
394 if (!vo_config_count
)
397 if (vo_dga_is_running
)
399 vo_dga_is_running
= 0;
400 mp_msg(MSGT_VO
, MSGL_V
, "vo_dga: in uninit\n");
402 XUngrabPointer(mDisplay
, CurrentTime
);
403 XUngrabKeyboard(mDisplay
, CurrentTime
);
405 XDGACloseFramebuffer(mDisplay
, mScreen
);
406 dgadevice
= XDGASetMode(mDisplay
, mScreen
, 0);
407 if (dgadevice
!= NULL
)
412 XF86DGADirectVideo(mDisplay
, mScreen
, 0);
413 // first disable DirectVideo and then switch mode back!
415 if (vo_dga_vidmodes
!= NULL
)
419 screen
= XDefaultScreen(mDisplay
);
420 mp_msg(MSGT_VO
, MSGL_V
,
421 "vo_dga: VidModeExt: Switching back..\n");
422 // seems some graphics adaptors need this more than once ...
423 XF86VidModeSwitchToMode(mDisplay
, screen
, vo_dga_vidmodes
[0]);
424 XF86VidModeSwitchToMode(mDisplay
, screen
, vo_dga_vidmodes
[0]);
425 XF86VidModeSwitchToMode(mDisplay
, screen
, vo_dga_vidmodes
[0]);
426 XF86VidModeSwitchToMode(mDisplay
, screen
, vo_dga_vidmodes
[0]);
427 XFree(vo_dga_vidmodes
);
436 //----------------------------------------------------------
437 // TODO: check for larger maxy value
438 // (useful for double buffering!!!)
440 static int check_res(int num
, int x
, int y
, int bpp
,
441 int new_x
, int new_y
, int new_vbi
, int new_maxy
,
442 int *old_x
, int *old_y
, int *old_vbi
, int *old_maxy
)
445 mp_msg(MSGT_VO
, MSGL_V
,
446 "vo_dga: (%3d) Trying %4d x %4d @ %3d Hz @ depth %2d ..", num
,
447 new_x
, new_y
, new_vbi
, bpp
);
448 mp_msg(MSGT_VO
, MSGL_V
, "(old: %dx%d@%d).", *old_x
, *old_y
, *old_vbi
);
449 if ((new_x
>= x
) && (new_y
>= y
) && (
450 // prefer a better resolution either in X or in Y
451 // as long as the other dimension is at least the same
453 // hmm ... MAYBE it would be more clever to focus on the
454 // x-resolution; I had 712x400 and 640x480 and the movie
455 // was 640x360; 640x480 would be the 'right thing' here
456 // but since 712x400 was queried first I got this one.
457 // I think there should be a cmd-line switch to let the
458 // user choose the mode he likes ... (acki2)
459 (((new_x
< *old_x
) &&
460 !(new_y
> *old_y
)) ||
463 // but if we get an identical resolution choose
464 // the one with the lower refreshrate (saves bandwidth !!!)
465 // as long as it's above 50 Hz (acki2 on 30/3/2001)
467 (((new_x
== *old_x
) &&
469 ((new_vbi
>= *old_vbi
472 && new_vbi
< *old_vbi
473 && new_vbi
>= 50))) ||
474 // if everything is equal, then use the mode with the lower
476 ((new_x
== *old_x
) &&
478 (new_vbi
== *old_vbi
) &&
479 (new_maxy
> *old_maxy
)))))
483 *old_maxy
= new_maxy
;
485 mp_msg(MSGT_VO
, MSGL_V
, ".ok!!\n");
489 mp_msg(MSGT_VO
, MSGL_V
, ".no\n");
496 //---------------------------------------------------------
498 static void init_video_buffers(uint8_t * buffer_base
,
499 int view_port_height
,
500 int bytes_per_scanline
,
502 int use_multiple_buffers
)
504 int bytes_per_buffer
= view_port_height
* bytes_per_scanline
;
507 if (use_multiple_buffers
)
508 vo_dga_nr_video_buffers
= max_view_port_y
/ view_port_height
;
510 vo_dga_nr_video_buffers
= 1;
512 if (vo_dga_nr_video_buffers
> MAX_NR_VIDEO_BUFFERS
)
513 vo_dga_nr_video_buffers
= MAX_NR_VIDEO_BUFFERS
;
514 if (vo_dga_nr_video_buffers
<= 0)
515 vo_dga_nr_video_buffers
= 1;
517 vo_dga_current_video_buffer
= 0;
519 for (i
= 0; i
< vo_dga_nr_video_buffers
; i
++)
521 vo_dga_video_buffer
[i
].y
= i
* view_port_height
;
522 vo_dga_video_buffer
[i
].data
= buffer_base
+ i
* bytes_per_buffer
;
524 // Clear video buffer.
525 memset(vo_dga_video_buffer
[i
].data
, 0, bytes_per_buffer
);
529 static int config(uint32_t width
, uint32_t height
,
530 uint32_t d_width
, uint32_t d_height
,
531 uint32_t flags
, char *title
, uint32_t format
)
535 int wanted_width
, wanted_height
;
537 static unsigned char *vo_dga_base
;
538 static int prev_width
, prev_height
;
541 // needed to change DGA video mode
542 int mX
= VO_DGA_INVALID_RES
, mY
= VO_DGA_INVALID_RES
, mVBI
=
543 100000, mMaxY
= 0, i
, j
= 0;
546 XDGADevice
*dgadevice
;
549 unsigned int vm_event
, vm_error
;
550 unsigned int vm_ver
, vm_rev
;
551 int i
, j
= 0, have_vm
= 0;
552 int mX
= VO_DGA_INVALID_RES
, mY
= VO_DGA_INVALID_RES
, mVBI
=
553 100000, mMaxY
= 0, dga_modenum
;
558 vo_dga_src_format
= format
;
560 wanted_width
= d_width
;
561 wanted_height
= d_height
;
564 wanted_height
= height
;
566 wanted_width
= width
;
570 if ((format
& IMGFMT_BGR_MASK
) == IMGFMT_BGR
)
572 vo_dga_src_mode
= vd_ModeValid(format
& 0xff);
576 vo_dga_src_mode
= vd_ModeValid(vo_dbpp
);
578 vo_dga_hw_mode
= SRC_MODE
.vdm_hw_mode
;
580 if (!vo_dga_src_mode
)
582 mp_msg(MSGT_VO
, MSGL_ERR
, "vo_dga: unsupported video format!\n");
586 vo_dga_vp_width
= vo_screenwidth
;
587 vo_dga_vp_height
= vo_screenheight
;
589 mp_msg(MSGT_VO
, MSGL_V
, "vo_dga: XServer res: %dx%d\n",
590 vo_dga_vp_width
, vo_dga_vp_height
);
592 // choose a suitable mode ...
595 // Code to change the video mode added by Michael Graffam
598 mp_msg(MSGT_VO
, MSGL_V
, "vo_dga: vo_modelines=%p, vo_modecount=%d\n",
599 vo_modelines
, vo_modecount
);
601 if (vo_modelines
== NULL
)
603 mp_msg(MSGT_VO
, MSGL_ERR
, "vo_dga: can't get modelines\n");
607 mp_msg(MSGT_VO
, MSGL_INFO
,
608 "vo_dga: DGA 2.0 available :-) Can switch resolution AND depth!\n");
609 for (i
= 0; i
< vo_modecount
; i
++)
611 if (vd_ModeEqual(vo_modelines
[i
].depth
,
612 vo_modelines
[i
].bitsPerPixel
,
613 vo_modelines
[i
].redMask
,
614 vo_modelines
[i
].greenMask
,
615 vo_modelines
[i
].blueMask
, vo_dga_hw_mode
))
618 mp_msg(MSGT_VO
, MSGL_V
, "maxy: %4d, depth: %2d, %4dx%4d, ",
619 vo_modelines
[i
].maxViewportY
, vo_modelines
[i
].depth
,
620 vo_modelines
[i
].imageWidth
,
621 vo_modelines
[i
].imageHeight
);
623 (i
, wanted_width
, wanted_height
, vo_modelines
[i
].depth
,
624 vo_modelines
[i
].viewportWidth
,
625 vo_modelines
[i
].viewportHeight
,
626 (unsigned) vo_modelines
[i
].verticalRefresh
,
627 vo_modelines
[i
].maxViewportY
, &mX
, &mY
, &mVBI
, &mMaxY
))
631 mp_msg(MSGT_VO
, MSGL_INFO
,
632 "vo_dga: Selected hardware mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d.\n",
633 mX
, mY
, mVBI
, HW_MODE
.vdm_depth
, HW_MODE
.vdm_bitspp
);
634 mp_msg(MSGT_VO
, MSGL_INFO
,
635 "vo_dga: Video parameters by codec: %3d x %3d, depth %2d, bitspp %2d.\n",
636 width
, height
, SRC_MODE
.vdm_depth
, SRC_MODE
.vdm_bitspp
);
637 vo_dga_vp_width
= mX
;
638 vo_dga_vp_height
= mY
;
640 if ((flags
& VOFLAG_SWSCALE
) || (flags
& VOFLAG_FULLSCREEN
))
642 scale_dstW
= (d_width
+ 7) & ~7;
643 scale_dstH
= d_height
;
646 aspect_save_screenres(mX
, mY
);
647 aspect_save_orig(scale_srcW
, scale_srcH
);
648 aspect_save_prescale(scale_dstW
, scale_dstH
);
649 if (flags
& VOFLAG_FULLSCREEN
) /* -fs */
650 aspect(&scale_dstW
, &scale_dstH
, A_ZOOM
);
651 else if (flags
& VOFLAG_SWSCALE
) /* -fs */
652 aspect(&scale_dstW
, &scale_dstH
, A_NOZOOM
);
653 mp_msg(MSGT_VO
, MSGL_INFO
,
654 "vo_dga: Aspect corrected size for SwScaler: %4d x %4d.\n",
655 scale_dstW
, scale_dstH
);
656 /* XXX this is a hack, but I'm lazy ;-) :: atmos */
661 vo_dga_width
= vo_modelines
[j
].bytesPerScanline
/ HW_MODE
.vdm_bytespp
;
662 dga_modenum
= vo_modelines
[j
].num
;
663 modeline
= vo_modelines
+ j
;
669 mp_msg(MSGT_VO
, MSGL_INFO
,
670 "vo_dga: DGA 1.0 compatibility code: Using XF86VidMode for mode switching!\n");
672 if (XF86VidModeQueryExtension(mDisplay
, &vm_event
, &vm_error
))
674 XF86VidModeQueryVersion(mDisplay
, &vm_ver
, &vm_rev
);
675 mp_msg(MSGT_VO
, MSGL_INFO
,
676 "vo_dga: XF86VidMode Extension v%i.%i\n", vm_ver
, vm_rev
);
680 mp_msg(MSGT_VO
, MSGL_ERR
,
681 "vo_dga: XF86VidMode Extension not available.\n");
684 #define GET_VREFRESH(dotclk, x, y)( (((dotclk)/(x))*1000)/(y) )
690 XF86VidModeGetAllModeLines(mDisplay
, mScreen
, &modecount
,
693 if (vo_dga_vidmodes
!= NULL
)
695 for (i
= 0; i
< modecount
; i
++)
697 if (check_res(i
, wanted_width
, wanted_height
,
698 vo_dga_modes
[vo_dga_hw_mode
].vdm_depth
,
699 vo_dga_vidmodes
[i
]->hdisplay
,
700 vo_dga_vidmodes
[i
]->vdisplay
,
701 GET_VREFRESH(vo_dga_vidmodes
[i
]->dotclock
,
702 vo_dga_vidmodes
[i
]->htotal
,
703 vo_dga_vidmodes
[i
]->vtotal
),
704 0, &mX
, &mY
, &mVBI
, &mMaxY
))
708 mp_msg(MSGT_VO
, MSGL_INFO
,
709 "vo_dga: Selected video mode %4d x %4d @ %3d Hz @ depth %2d, bitspp %2d, video %3d x %3d.\n",
711 vo_dga_modes
[vo_dga_hw_mode
].vdm_depth
,
712 vo_dga_modes
[vo_dga_hw_mode
].vdm_bitspp
, width
, height
);
715 mp_msg(MSGT_VO
, MSGL_INFO
,
716 "vo_dga: XF86VidMode returned no screens - using current resolution.\n");
719 vo_dga_vp_width
= mX
;
720 vo_dga_vp_height
= mY
;
724 mp_msg(MSGT_VO
, MSGL_INFO
,
725 "vo_dga: Only have DGA 1.0 extension and no XF86VidMode :-(\n");
726 mp_msg(MSGT_VO
, MSGL_INFO
,
727 " Thus, resolution switching is NOT possible.\n");
732 vo_dga_src_width
= width
;
733 vo_dga_src_height
= height
;
735 if (vo_dga_src_width
> vo_dga_vp_width
||
736 vo_dga_src_height
> vo_dga_vp_height
)
738 mp_msg(MSGT_VO
, MSGL_ERR
,
739 "vo_dga: Sorry, video larger than viewport is not yet supported!\n");
740 // ugly, do something nicer in the future ...
745 XFree(vo_dga_vidmodes
);
746 vo_dga_vidmodes
= NULL
;
753 if (vo_dga_vp_width
== VO_DGA_INVALID_RES
)
755 mp_msg(MSGT_VO
, MSGL_ERR
,
756 "vo_dga: Something is wrong with your DGA. There doesn't seem to be a\n"
757 " single suitable mode!\n"
758 " Please file a bug report (see DOCS/HTML/en/bugreports.html)\n");
763 XFree(vo_dga_vidmodes
);
764 vo_dga_vidmodes
= NULL
;
770 // now let's start the DGA thing
772 if (!vo_config_count
|| width
!= prev_width
|| height
!= prev_height
)
776 if (!XDGAOpenFramebuffer(mDisplay
, mScreen
))
778 mp_msg(MSGT_VO
, MSGL_ERR
,
779 "vo_dga: Framebuffer mapping failed!!!\n");
783 dgadevice
= XDGASetMode(mDisplay
, mScreen
, dga_modenum
);
784 XDGASync(mDisplay
, mScreen
);
786 vo_dga_base
= dgadevice
->data
;
789 XDGASetViewport(mDisplay
, mScreen
, 0, 0, XDGAFlipRetrace
);
796 XF86VidModeLockModeSwitch(mDisplay
, mScreen
, 0);
797 // Two calls are needed to switch modes on my ATI Rage 128. Why?
798 // for riva128 one call is enough!
799 XF86VidModeSwitchToMode(mDisplay
, mScreen
,
800 vo_dga_vidmodes
[dga_modenum
]);
801 XF86VidModeSwitchToMode(mDisplay
, mScreen
,
802 vo_dga_vidmodes
[dga_modenum
]);
806 XF86DGAGetViewPortSize(mDisplay
, mScreen
,
807 &vo_dga_vp_width
, &vo_dga_vp_height
);
809 XF86DGAGetVideo(mDisplay
, mScreen
,
810 (char **) &vo_dga_base
, &vo_dga_width
, &bank
,
813 XF86DGADirectVideo(mDisplay
, mScreen
,
814 XF86DGADirectGraphics
| XF86DGADirectMouse
|
817 XF86DGASetViewPort(mDisplay
, mScreen
, 0, 0);
821 // do some more checkings here ...
823 mp_msg(MSGT_VO
, MSGL_V
,
824 "vo_dga: bytes/line: %d, screen res: %dx%d, depth: %d, base: %p, bpp: %d\n",
825 vo_dga_width
, vo_dga_vp_width
, vo_dga_vp_height
,
826 HW_MODE
.vdm_bytespp
, vo_dga_base
, HW_MODE
.vdm_bitspp
);
828 x_off
= (vo_dga_vp_width
- vo_dga_src_width
) >> 1;
829 y_off
= (vo_dga_vp_height
- vo_dga_src_height
) >> 1;
831 vo_dga_bytes_per_line
= vo_dga_src_width
* HW_MODE
.vdm_bytespp
;
832 vo_dga_lines
= vo_dga_src_height
;
834 vo_dga_src_offset
= 0;
836 (y_off
* vo_dga_width
+ x_off
) * HW_MODE
.vdm_bytespp
;
838 vo_dga_vp_skip
= (vo_dga_width
- vo_dga_src_width
) * HW_MODE
.vdm_bytespp
; // todo
840 mp_msg(MSGT_VO
, MSGL_V
, "vo_dga: vp_off=%d, vp_skip=%d, bpl=%d\n",
841 vo_dga_vp_offset
, vo_dga_vp_skip
, vo_dga_bytes_per_line
);
844 XGrabKeyboard(mDisplay
, DefaultRootWindow(mDisplay
), True
,
845 GrabModeAsync
, GrabModeAsync
, CurrentTime
);
847 XGrabPointer(mDisplay
, DefaultRootWindow(mDisplay
), True
,
848 ButtonPressMask
, GrabModeAsync
, GrabModeAsync
,
849 None
, None
, CurrentTime
);
851 if (!vo_config_count
|| width
!= prev_width
|| height
!= prev_height
)
853 init_video_buffers(vo_dga_base
,
855 vo_dga_width
* HW_MODE
.vdm_bytespp
,
857 modeline
->maxViewportY
,
863 prev_height
= height
;
866 mp_msg(MSGT_VO
, MSGL_V
, "vo_dga: Using %d frame buffer%s.\n",
867 vo_dga_nr_video_buffers
,
868 vo_dga_nr_video_buffers
== 1 ? "" : "s");
870 vo_dga_is_running
= 1;
874 static int dga_depths_init
= 0;
876 static int preinit(const char *arg
)
880 mp_msg(MSGT_VO
, MSGL_INFO
, "vo_dga: Unknown subdevice: %s\n", arg
);
885 return -1; // Can't open X11
887 if (dga_depths_init
== 0)
891 vo_dga_XServer_mode
= vd_ValidateMode(vo_depthonscreen
);
893 if (vo_dga_XServer_mode
== 0)
896 mp_msg(MSGT_VO
, MSGL_ERR
,
897 "vo_dga: Your X-Server is not running in a ");
898 mp_msg(MSGT_VO
, MSGL_ERR
,
899 "resolution supported by DGA driver!\n");
902 // mp_msg(MSGT_VO, MSGL_V, "vo_dga: X running at: %s\n",
903 // vd_GetModeString(vo_dga_XServer_mode));
907 vo_modelines
= XDGAQueryModes(mDisplay
, mScreen
, &vo_modecount
);
910 for (i
= 0; i
< vo_modecount
; i
++)
912 mp_msg(MSGT_VO
, MSGL_V
,
913 "vo_dga: (%03d) depth=%d, bpp=%d, r=%08lx, g=%08lx, b=%08lx, %d x %d\n",
914 i
, vo_modelines
[i
].depth
,
915 vo_modelines
[i
].bitsPerPixel
,
916 vo_modelines
[i
].redMask
, vo_modelines
[i
].greenMask
,
917 vo_modelines
[i
].blueMask
,
918 vo_modelines
[i
].viewportWidth
,
919 vo_modelines
[i
].viewportHeight
);
920 vd_EnableMode(vo_modelines
[i
].depth
,
921 vo_modelines
[i
].bitsPerPixel
,
922 vo_modelines
[i
].redMask
,
923 vo_modelines
[i
].greenMask
,
924 vo_modelines
[i
].blueMask
);
930 if (!vo_dga_modes
[1].vdm_supported
931 && vo_dga_modes
[2].vdm_supported
)
933 vo_dga_modes
[1].vdm_supported
= 1;
936 if (!vo_dga_modes
[3].vdm_supported
937 && vo_dga_modes
[4].vdm_supported
)
939 vo_dga_modes
[3].vdm_supported
= 1;
942 for (i
= 1; i
< vo_dga_mode_num
; i
++)
944 mp_msg(MSGT_VO
, MSGL_INFO
, "vo_dga: Mode: %s",
945 vd_GetModeString(i
));
946 if (vo_dbpp
&& vo_dbpp
!= vo_dga_modes
[i
].vdm_mplayer_depth
)
948 vo_dga_modes
[i
].vdm_supported
= 0;
949 mp_msg(MSGT_VO
, MSGL_INFO
, " ...disabled by -bpp %d",
952 mp_msg(MSGT_VO
, MSGL_INFO
, "\n");
959 static uint32_t get_image(mp_image_t
* mpi
)
961 if (!IMGFMT_IS_BGR(mpi
->imgfmt
) ||
962 (IMGFMT_BGR_DEPTH(mpi
->imgfmt
) !=
963 vo_dga_modes
[vo_dga_hw_mode
].vdm_mplayer_depth
)
964 || (mpi
->type
== MP_IMGTYPE_STATIC
&& vo_dga_nr_video_buffers
> 1)
965 || (mpi
->type
== MP_IMGTYPE_IP
&& vo_dga_nr_video_buffers
< 2)
966 || (mpi
->type
== MP_IMGTYPE_IPB
))
969 if ((mpi
->flags
& MP_IMGFLAG_ACCEPT_STRIDE
) ||
970 (mpi
->flags
& MP_IMGFLAG_ACCEPT_WIDTH
&&
971 ((vo_dga_bytes_per_line
+ vo_dga_vp_skip
) % (mpi
->bpp
/ 8)) == 0)
972 || (mpi
->width
* (mpi
->bpp
/ 8) ==
973 (vo_dga_bytes_per_line
+ vo_dga_vp_skip
)))
976 mpi
->planes
[0] = CURRENT_VIDEO_BUFFER
.data
+ vo_dga_vp_offset
;
977 mpi
->stride
[0] = vo_dga_bytes_per_line
+ vo_dga_vp_skip
;
979 (vo_dga_bytes_per_line
+ vo_dga_vp_skip
) / (mpi
->bpp
/ 8);
980 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
987 static int control(uint32_t request
, void *data
)
991 case VOCTRL_GET_IMAGE
:
992 return get_image(data
);
993 case VOCTRL_QUERY_FORMAT
:
994 return query_format(*((uint32_t *) data
));
999 //---------------------------------------------------------