vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / libvo / vo_cvidix.c
blobd0e6860c656a7d55e92c3e87570d64a862b5f7ab
1 /*
2 * VIDIX-accelerated overlay on (black) background
4 * should work on any OS
6 * copyright (C) 2003 Sascha Sommer
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <math.h>
29 #include <errno.h>
31 #include "config.h"
32 #include "video_out.h"
33 #include "video_out_internal.h"
34 #include "aspect.h"
35 #include "geometry.h"
37 #include "mp_msg.h"
39 #include "vosub_vidix.h"
40 #include "vidix/vidix.h"
43 static const vo_info_t info = {
44 "console VIDIX",
45 "cvidix",
46 "Sascha Sommer",
50 LIBVO_EXTERN(cvidix)
52 /* VIDIX related */
53 static char *vidix_name;
54 static uint32_t swidth,sheight,sformat;
55 /// center video only when screenw & height are set
56 static uint32_t center=0;
57 static vidix_grkey_t gr_key;
60 static uint32_t setup_vidix(void){
61 int x=vo_dx,y=vo_dy;
62 aspect(&vo_dwidth,&vo_dheight,vo_fs ? A_ZOOM : A_NOZOOM);
63 if(vo_fs || center){
64 if(vo_dwidth <= vo_screenwidth)x = (vo_screenwidth - vo_dwidth)/2;
65 else x=0;
66 if(vo_dheight <= vo_screenheight)y = (vo_screenheight - vo_dheight)/2;
67 else y=0;
69 if(vo_config_count)vidix_stop();
70 if(vidix_init(swidth, sheight, x, y, vo_dwidth, vo_dheight, sformat, 32, vo_screenwidth,vo_screenheight)){
71 mp_msg(MSGT_VO, MSGL_FATAL, "Can't setup VIDIX driver: %s\n", strerror(errno));
72 return 1;
74 vidix_start();
75 if(vidix_grkey_support()){
76 vidix_grkey_get(&gr_key);
77 gr_key.key_op = KEYS_PUT;
78 if (!vo_fs && !(vo_colorkey & 0xff000000)){
79 gr_key.ckey.op = CKEY_TRUE;
80 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
81 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
82 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
84 else gr_key.ckey.op = CKEY_FALSE;
85 vidix_grkey_set(&gr_key);
87 return 0;
90 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){
91 vo_fs = flags & VOFLAG_FULLSCREEN;
92 if(!vo_config_count){
93 if(vo_screenwidth && vo_screenheight){
94 if(!vo_geometry)center=1;
97 if(!vo_screenwidth){
98 mp_msg(MSGT_VO, MSGL_WARN, "vo_cvidix: Screen width not set (see -screenw), assuming 640 pixels.\n");
99 vo_screenwidth = 640;
101 if(!vo_screenheight){
102 mp_msg(MSGT_VO, MSGL_WARN, "vo_cvidix: Screen height not set (see -screenh), assuming 480 pixels.\n");
103 vo_screenheight = 480;
105 swidth = width;
106 sheight = height;
107 sformat = format;
108 vo_dwidth=d_width;
109 vo_dheight=d_height;
110 aspect_save_orig(width,height);
111 aspect_save_prescale(d_width,d_height);
112 aspect_save_screenres(vo_screenwidth,vo_screenheight);
113 if(!vo_geometry){
114 vo_dx=0;
115 vo_dy=0;
117 else geometry(&vo_dx, &vo_dy, &vo_dwidth, &vo_dheight,vo_screenwidth,vo_screenheight);
118 return setup_vidix();
121 static void check_events(void){
124 /* draw_osd, flip_page, draw_slice, draw_frame should be
125 overwritten with vidix functions (vosub_vidix.c) */
126 static void draw_osd(void){
127 mp_msg(MSGT_VO, MSGL_FATAL, "vo_cvidix: error: didn't use vidix draw_osd!\n");
128 return;
131 static void flip_page(void){
132 mp_msg(MSGT_VO, MSGL_FATAL, "vo_cvidix: error: didn't use vidix flip_page!\n");
133 return;
136 static int draw_slice(uint8_t *src[], int stride[],int w, int h, int x, int y){
137 mp_msg(MSGT_VO, MSGL_FATAL, "vo_cvidix: error: didn't use vidix draw_slice!\n");
138 return -1;
141 static int draw_frame(uint8_t *src[]){
142 mp_msg(MSGT_VO, MSGL_FATAL, "vo_cvidix: error: didn't use vidix draw_frame!\n");
143 return -1;
146 static int query_format(uint32_t format){
147 return vidix_query_fourcc(format);
150 static void uninit(void){
151 if(!vo_config_count) return;
152 vidix_term();
153 free(vidix_name);
154 vidix_name = NULL;
157 static int preinit(const char *arg){
158 if(arg)vidix_name = strdup(arg);
159 else {
160 mp_msg(MSGT_VO, MSGL_INFO, "vo_cvidix: No vidix driver name provided, probing available ones (-v option for details)!\n");
161 vidix_name = NULL;
163 if (vidix_preinit(vidix_name, video_out_cvidix.old_functions))return 1;
164 return 0;
167 static int control(uint32_t request, void *data){
168 switch (request) {
169 case VOCTRL_QUERY_FORMAT:
170 return query_format(*((uint32_t*)data));
171 case VOCTRL_FULLSCREEN:
172 if(vo_fs)vo_fs=0;
173 else vo_fs=1;
174 setup_vidix();
175 return VO_TRUE;
177 return vidix_control(request, data);