1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-10 17:09:45 +00:00

Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2250 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
atmos4 2001-10-18 02:42:20 +00:00
parent 50f2513fc8
commit 14fe0175c0
7 changed files with 113 additions and 75 deletions

View File

@ -1,5 +1,7 @@
/* Stuff for correct aspect scaling. */ /* Stuff for correct aspect scaling. */
//#define ASPECT_DEBUG #include "aspect.h"
#define ASPECT_DEBUG
#ifdef ASPECT_DEBUG #ifdef ASPECT_DEBUG
#include <stdio.h> #include <stdio.h>
@ -7,39 +9,69 @@
float monitor_aspect=4.0/3.0; float monitor_aspect=4.0/3.0;
static struct {
int orgw; // real width
int orgh; // real height
int prew; // prescaled width
int preh; // prescaled height
int scrw; // horizontal resolution
int scrh; // vertical resolution
} aspdat;
void aspect_save_orig(int orgw, int orgh){
aspdat.orgw = orgw;
aspdat.orgh = orgh;
}
void aspect_save_prescale(int prew, int preh){
aspdat.prew = prew;
aspdat.preh = preh;
}
void aspect_save_screenres(int scrw, int scrh){
aspdat.scrw = scrw;
aspdat.scrh = scrh;
}
/* aspect is called with the source resolution and the /* aspect is called with the source resolution and the
* resolution, that the scaled image should fit into * resolution, that the scaled image should fit into
*/ */
void aspect(int *srcw, int *srch, int fitinw, int fitinh){ void aspect(int *srcw, int *srch, int zoom){
int srcwcp, srchcp, tmp; int tmpw;
srcwcp=*srcw; srchcp=*srch;
srcwcp=fitinw;
#ifdef ASPECT_DEBUG #ifdef ASPECT_DEBUG
printf("aspect(0) fitin: %dx%d \n",fitinw,fitinh); printf("aspect(0) fitin: %dx%d zoom: %d \n",aspdat.scrw,aspdat.scrh,zoom);
printf("aspect(1) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch); printf("aspect(1) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
#endif #endif
srchcp=(int)(((float)fitinw / (float)*srcw * (float)*srch) if(zoom){
* ((float)fitinh / ((float)fitinw / monitor_aspect))); *srcw = aspdat.scrw;
srchcp+=srchcp%2; // round *srch = (int)(((float)aspdat.scrw / (float)aspdat.prew * (float)aspdat.preh)
* ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
}else{
*srcw = aspdat.prew;
*srch = (int)((float)aspdat.preh
* ((float)aspdat.scrh / ((float)aspdat.scrw / monitor_aspect)));
}
*srch+= *srch%2; // round
#ifdef ASPECT_DEBUG #ifdef ASPECT_DEBUG
printf("aspect(2) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch); printf("aspect(2) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
#endif #endif
if(srchcp>fitinh || srchcp<*srch){ if(*srch>aspdat.scrh || *srch<aspdat.orgh){
tmp=(int)(((float)fitinh / (float)*srch * (float)*srcw) if(zoom)
* ((float)fitinw / ((float)fitinh / (1/monitor_aspect)))); tmpw = (int)(((float)aspdat.scrh / (float)aspdat.preh * (float)aspdat.prew)
if(srcwcp>fitinw){ * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
srchcp=fitinh; else
srcwcp=tmp; tmpw = (int)((float)aspdat.prew
srcwcp+=srcwcp%2; // round * ((float)aspdat.scrw / ((float)aspdat.scrh / (1.0/monitor_aspect))));
if(tmpw<=aspdat.scrw && tmpw>=aspdat.orgw){
*srch = zoom?aspdat.scrh:aspdat.preh;
*srcw = tmpw;
*srcw+= *srcw%2; // round
} }
} }
#ifdef ASPECT_DEBUG #ifdef ASPECT_DEBUG
printf("aspect(3) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch); printf("aspect(3) wh: %dx%d (org: %dx%d)\n",*srcw,*srch,aspdat.prew,aspdat.preh);
#endif
*srcw=srcwcp; *srch=srchcp;
#ifdef ASPECT_DEBUG
printf("aspect(4) wh: %dx%d (org: %dx%d)\n",srcwcp,srchcp,*srcw,*srch);
#endif #endif
} }

View File

@ -2,7 +2,16 @@
#define __ASPECT_H #define __ASPECT_H
/* Stuff for correct aspect scaling. */ /* Stuff for correct aspect scaling. */
void aspect(int *srcw, int *srch, int fitinw, int fitinh); void aspect_save_orig(int orgw, int orgh);
void aspect_save_prescale(int prew, int preh);
void aspect_save_screenres(int scrw, int scrh);
#define A_ZOOM 1
#define A_NOZOOM 0
void aspect(int *srcw, int *srch, int zoom);
#endif #endif

View File

@ -99,7 +99,6 @@ static uint32_t
init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) init(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 screen;
int dwidth,dheight;
unsigned int fg, bg; unsigned int fg, bg;
char *hello = (title == NULL) ? "OpenGL rulez" : title; char *hello = (title == NULL) ? "OpenGL rulez" : title;
// char *name = ":0.0"; // char *name = ":0.0";
@ -118,13 +117,16 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
if (X_already_started) return -1; if (X_already_started) return -1;
if(!vo_init()) return -1; if(!vo_init()) return -1;
aspect_save_orig(width,height);
aspect_save_prescale(d_width,d_height);
aspect_save_screenres(vo_screenwidth,vo_screenheight);
X_already_started++; X_already_started++;
dwidth=d_width; dheight=d_height; aspect(&d_width,&d_height,A_NOZOOM);
#ifdef X11_FULLSCREEN #ifdef X11_FULLSCREEN
if( flags&0x01 ){ // (-fs) if( flags&0x01 ){ // (-fs)
aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight); aspect(&d_width,&d_height,A_ZOOM);
dwidth=d_width; dheight=d_height;
} }
#endif #endif
hint.x = 0; hint.x = 0;

View File

@ -395,7 +395,6 @@ static uint32_t
init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) init(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 screen;
int dwidth,dheight;
unsigned int fg, bg; unsigned int fg, bg;
char *hello = (title == NULL) ? "OpenGL rulez" : title; char *hello = (title == NULL) ? "OpenGL rulez" : title;
// char *name = ":0.0"; // char *name = ":0.0";
@ -414,13 +413,16 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
if (X_already_started) return -1; if (X_already_started) return -1;
if(!vo_init()) return -1; if(!vo_init()) return -1;
aspect_save_orig(width,height);
aspect_save_prescale(d_width,d_height);
aspect_save_screenres(vo_screenwidth,vo_screenheight);
X_already_started++; X_already_started++;
dwidth=d_width; dheight=d_height; aspect(&d_width,&d_height,A_NOZOOM);
#ifdef X11_FULLSCREEN #ifdef X11_FULLSCREEN
if( flags&0x01 ){ // (-fs) if( flags&0x01 ){ // (-fs)
aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight); aspect(&d_width,&d_height,A_ZOOM);
dwidth=d_width; dheight=d_height;
} }
#endif #endif
hint.x = 0; hint.x = 0;

View File

@ -555,35 +555,26 @@ static void set_fullmode (int mode)
static void set_fullmode (int mode) { static void set_fullmode (int mode) {
struct sdl_priv_s *priv = &sdl_priv; struct sdl_priv_s *priv = &sdl_priv;
SDL_Surface *newsurface = NULL; SDL_Surface *newsurface = NULL;
int newwidth = priv->dstwidth,
newheight= priv->dstheight;
/* if we haven't set a fullmode yet, default to the lowest res fullmode first */ /* if we haven't set a fullmode yet, default to the lowest res fullmode first */
if(mode < 0) if(mode < 0)
mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1; mode = priv->fullmode = findArrayEnd(priv->fullmodes) - 1;
aspect_save_screenres(priv->fullmodes[mode]->w, priv->fullmodes[mode]->h);
/* calculate new video size/aspect */ /* calculate new video size/aspect */
if(!priv->mode) { if(!priv->mode) {
if(priv->fulltype&FS) { if(priv->fulltype&FS) {
#ifdef HAVE_X11 #ifdef HAVE_X11
aspect(&newwidth, &newheight, priv->XWidth ? priv->XWidth : priv->dstwidth, priv->XHeight ? priv->XHeight : priv->dstheight); aspect_save_screenres(priv->XWidth, priv->XHeight);
#else
aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
#endif #endif
} else
if(priv->fulltype&VM) {
#ifdef HAVE_X11
aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth)));
#else
aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
#endif
} else {
aspect(&newwidth, &newheight, priv->fullmodes[mode]->w, priv->fullmodes[mode]->h);
} }
aspect(&priv->dstwidth, &priv->dstheight, A_ZOOM);
} }
/* try to change to given fullscreenmode */ /* try to change to given fullscreenmode */
newsurface = SDL_SetVideoMode(newwidth, newheight, priv->bpp, priv->sdlfullflags); newsurface = SDL_SetVideoMode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlfullflags);
/* if creation of new surface was successfull, save it and hide mouse cursor */ /* if creation of new surface was successfull, save it and hide mouse cursor */
if(newsurface) { if(newsurface) {
@ -615,7 +606,8 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
static Display *XDisplay; static Display *XDisplay;
static int XScreen; static int XScreen;
#endif #endif
int newwidth, newheight; aspect_save_orig(width,height);
aspect_save_prescale(d_width,d_height);
sdl_format = format; sdl_format = format;
switch(format){ switch(format){
@ -701,17 +693,16 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
priv->height = height; priv->height = height;
priv->dstwidth = d_width ? d_width : width; priv->dstwidth = d_width ? d_width : width;
priv->dstheight = d_height ? d_height : height; priv->dstheight = d_height ? d_height : height;
newwidth = priv->dstwidth;
newheight = priv->dstheight;
/*priv->width = res.w; /*priv->width = res.w;
priv->height = res.h;*/ priv->height = res.h;*/
priv->format = format; priv->format = format;
#ifdef HAVE_X11 #ifdef HAVE_X11
aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth))); aspect_save_screenres(priv->XWidth,priv->XHeight);
aspect(&priv->dstwidth,&priv->dstheight,A_NOZOOM);
#endif #endif
priv->windowsize.w = newwidth; priv->windowsize.w = priv->dstwidth;
priv->windowsize.h = newheight; priv->windowsize.h = priv->dstheight;
/* bit 0 (0x01) means fullscreen (-fs) /* bit 0 (0x01) means fullscreen (-fs)
* bit 1 (0x02) means mode switching (-vm) * bit 1 (0x02) means mode switching (-vm)
@ -726,15 +717,14 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
} }
if(flags&FS) { if(flags&FS) {
if(verbose) printf("SDL: setting zoomed fullscreen without modeswitching\n"); if(verbose) printf("SDL: setting zoomed fullscreen without modeswitching\n");
printf("SDL: Info - please use -vm (unscaled) or -zoom (scaled) for best fullscreen experience\n"); printf("SDL: Info - please use -vm or -zoom to switch to best resolution.\n");
priv->fulltype = FS; priv->fulltype = FS;
set_fullmode(priv->fullmode); set_fullmode(priv->fullmode);
/*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags))) /*if((priv->surface = SDL_SetVideoMode (d_width, d_height, priv->bpp, priv->sdlfullflags)))
SDL_ShowCursor(0);*/ SDL_ShowCursor(0);*/
} else } else
if(flags&VM) { if(flags&VM) {
if(verbose) printf("SDL: setting nonzoomed fullscreen with modeswitching\n"); if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
printf("SDL: Info - please use -zoom switch to scale video\n");
priv->fulltype = VM; priv->fulltype = VM;
set_fullmode(priv->fullmode); set_fullmode(priv->fullmode);
/*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags))) /*if((priv->surface = SDL_SetVideoMode (d_width ? d_width : width, d_height ? d_height : height, priv->bpp, priv->sdlfullflags)))
@ -742,18 +732,16 @@ init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint3
} else } else
if(flags&ZOOM) { if(flags&ZOOM) {
if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n"); if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
printf("SDL: Info - please use -vm switch instead if you don't want scaled video\n");
priv->fulltype = ZOOM; priv->fulltype = ZOOM;
set_fullmode(priv->fullmode); set_fullmode(priv->fullmode);
} }
else { else {
if((strcmp(priv->driver, "x11") == 0) || ((strcmp(priv->driver, "aalib") == 0) && priv->X)) { if((strcmp(priv->driver, "x11") == 0) || ((strcmp(priv->driver, "aalib") == 0) && priv->X)) {
if(verbose) printf("SDL: setting windowed mode\n"); if(verbose) printf("SDL: setting windowed mode\n");
priv->surface = SDL_SetVideoMode (newwidth, newheight, priv->bpp, priv->sdlflags); priv->surface = SDL_SetVideoMode (priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags);
} }
else { else {
if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n"); if(verbose) printf("SDL: setting zoomed fullscreen with modeswitching\n");
printf("SDL: Info - please use -vm switch instead if you don't want scaled video\n");
priv->fulltype = ZOOM; priv->fulltype = ZOOM;
set_fullmode(priv->fullmode); set_fullmode(priv->fullmode);
} }
@ -1092,20 +1080,17 @@ static void check_events (void)
} }
else if ( keypressed == SDLK_n ) { else if ( keypressed == SDLK_n ) {
int newwidth = priv->dstwidth, newheight = priv->dstheight;
#ifdef HAVE_X11 #ifdef HAVE_X11
aspect(&newwidth, &newheight, priv->dstwidth, (int)((float)priv->dstwidth*((float)priv->XHeight / (float)priv->XWidth))); aspect(&priv->dstwidth, &priv->dstheight,A_NOZOOM);
#else
aspect(&newwidth, &newheight, priv->dstwidth, priv->dstheight);
#endif #endif
if (priv->surface->w != newwidth || priv->surface->h != newheight) { if (priv->surface->w != priv->dstwidth || priv->surface->h != priv->dstheight) {
priv->surface = SDL_SetVideoMode(newwidth, newheight, priv->bpp, priv->sdlflags); priv->surface = SDL_SetVideoMode(priv->dstwidth, priv->dstheight, priv->bpp, priv->sdlflags);
priv->windowsize.w = priv->surface->w; priv->windowsize.w = priv->surface->w;
priv->windowsize.h = priv->surface->h; priv->windowsize.h = priv->surface->h;
if(verbose > 1) printf("SDL: Normal size\n"); if(verbose > 1) printf("SDL: Normal size\n");
} else } else
if (priv->surface->w != newwidth * 2 || priv->surface->h != newheight * 2) { if (priv->surface->w != priv->dstwidth * 2 || priv->surface->h != priv->dstheight * 2) {
priv->surface = SDL_SetVideoMode(newwidth * 2, newheight * 2, priv->bpp, priv->sdlflags); priv->surface = SDL_SetVideoMode(priv->dstwidth * 2, priv->dstheight * 2, priv->bpp, priv->sdlflags);
priv->windowsize.w = priv->surface->w; priv->windowsize.w = priv->surface->w;
priv->windowsize.h = priv->surface->h; priv->windowsize.h = priv->surface->h;
if(verbose > 1) printf("SDL: Double size\n"); if(verbose > 1) printf("SDL: Double size\n");

View File

@ -230,11 +230,14 @@ static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_
if (!vo_init()) return -1; if (!vo_init()) return -1;
aspect_save_orig(width,height);
aspect_save_prescale(d_width,d_height);
aspect_save_screenres(vo_screenwidth,vo_screenheight);
mvWidth=width; mvHeight=height; mvWidth=width; mvHeight=height;
wndX=0; wndY=0; wndX=0; wndY=0;
wndWidth=d_width; wndHeight=d_height; wndWidth=d_width; wndHeight=d_height;
dwidth=d_width; dheight=d_height;
#ifdef HAVE_NEW_GUI #ifdef HAVE_NEW_GUI
// mdwidth=d_width; mdheight=d_height; // mdwidth=d_width; mdheight=d_height;
mdwidth=width; mdheight=height; mdwidth=width; mdheight=height;
@ -250,6 +253,7 @@ static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_
default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
} }
aspect(&d_width,&d_height,A_NOZOOM);
#ifdef HAVE_NEW_GUI #ifdef HAVE_NEW_GUI
if ( vo_window == None ) if ( vo_window == None )
{ {
@ -259,10 +263,10 @@ static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_
wndWidth=vo_screenwidth; wndWidth=vo_screenwidth;
wndHeight=vo_screenheight; wndHeight=vo_screenheight;
#ifdef X11_FULLSCREEN #ifdef X11_FULLSCREEN
aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight); aspect(&d_width,&d_height,A_ZOOM);
dwidth=d_width; dheight=d_height;
#endif #endif
} }
dwidth=d_width; dheight=d_height;
XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
mDepth=attribs.depth; mDepth=attribs.depth;

View File

@ -132,6 +132,9 @@ static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t
XSetWindowAttributes xswa; XSetWindowAttributes xswa;
unsigned long xswamask; unsigned long xswamask;
aspect_save_orig(width,height);
aspect_save_prescale(d_width,d_height);
image_height = height; image_height = height;
image_width = width; image_width = width;
image_format=format; image_format=format;
@ -142,11 +145,12 @@ static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t
#endif #endif
mFullscreen=flags&1; mFullscreen=flags&1;
dwidth=d_width; dheight=d_height;
num_buffers=vo_doublebuffering?NUM_BUFFERS:1; num_buffers=vo_doublebuffering?NUM_BUFFERS:1;
if (!vo_init()) return -1; if (!vo_init()) return -1;
aspect_save_screenres(vo_screenwidth,vo_screenheight);
#ifdef HAVE_NEW_GUI #ifdef HAVE_NEW_GUI
if ( vo_window == None ) if ( vo_window == None )
{ {
@ -155,6 +159,8 @@ static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t
hint.y = 0; hint.y = 0;
hint.width = d_width; hint.width = d_width;
hint.height = d_height; hint.height = d_height;
aspect(&d_width,&d_height,A_NOZOOM);
if ( mFullscreen ) if ( mFullscreen )
{ {
hint.width=vo_screenwidth; hint.width=vo_screenwidth;
@ -167,13 +173,11 @@ static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t
* irritated for now (and send lots o' mails ;) ::atmos * irritated for now (and send lots o' mails ;) ::atmos
*/ */
{ aspect(&d_width,&d_height,A_ZOOM);
aspect(&d_width,&d_height,vo_screenwidth,vo_screenheight);
dwidth=d_width; dheight=d_height;
}
#endif #endif
} }
dwidth=d_width; dheight=d_height; //XXX: what are the copy vars used for?
hint.flags = PPosition | PSize; hint.flags = PPosition | PSize;
XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs); XGetWindowAttributes(mDisplay, DefaultRootWindow(mDisplay), &attribs);
depth=attribs.depth; depth=attribs.depth;