| 1 |
/******************************************************** |
| 2 |
* |
| 3 |
* Video renderers |
| 4 |
* Copyright 2000 Eugene Kuznetsov ([email protected]) |
| 5 |
* |
| 6 |
********************************************************/ |
| 7 |
|
| 8 |
#include "default.h" |
| 9 |
|
| 10 |
#if 0 |
| 11 |
|
| 12 |
// do not compile |
| 13 |
|
| 14 |
#include "fourcc.h" |
| 15 |
#include "Locker.h" |
| 16 |
#include "except.h" |
| 17 |
#include "renderer.h" |
| 18 |
#include "playerwidget.h" |
| 19 |
#include "cpuinfo.h" |
| 20 |
#include "utils.h" |
| 21 |
#include "mmx.h" |
| 22 |
|
| 23 |
#include <string.h> |
| 24 |
#include <unistd.h> |
| 25 |
#include <fcntl.h> |
| 26 |
#include <sys/ioctl.h> |
| 27 |
#include <sys/time.h> |
| 28 |
|
| 29 |
#ifndef X_DISPLAY_MISSING |
| 30 |
|
| 31 |
#if defined(__FreeBSD__) || defined(__NetBSD__) |
| 32 |
#include <machine/param.h> |
| 33 |
#include <sys/types.h> |
| 34 |
#endif |
| 35 |
#include <errno.h> |
| 36 |
|
| 37 |
#include <sys/ipc.h> |
| 38 |
#include <sys/shm.h> |
| 39 |
|
| 40 |
#include <X11/Xlib.h> |
| 41 |
#include <X11/Xlocale.h> |
| 42 |
#include <X11/Xutil.h> |
| 43 |
#include <X11/extensions/XInput.h> //XGetExtensionVersion |
| 44 |
#include <X11/extensions/XShm.h> |
| 45 |
|
| 46 |
#ifdef HAVE_LIBXV |
| 47 |
#include <X11/extensions/Xv.h> |
| 48 |
#include <X11/extensions/Xvlib.h> |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifdef HAVE_LIBXXF86DGA |
| 52 |
#include <X11/extensions/xf86dga.h> |
| 53 |
#endif |
| 54 |
|
| 55 |
#ifdef HAVE_LIBXXF86VM |
| 56 |
#include <X11/extensions/xf86vmode.h> |
| 57 |
#endif |
| 58 |
|
| 59 |
#ifdef HAVE_LIBXFT |
| 60 |
#include <X11/Xft/Xft.h> |
| 61 |
//#include <X11/extensions/Xrender.h> |
| 62 |
#endif |
| 63 |
|
| 64 |
#include <VideoDPMS.h> |
| 65 |
|
| 66 |
/* |
| 67 |
#ifdef USE_QT |
| 68 |
#include <qfont.h> |
| 69 |
#include <qfontmetrics.h> |
| 70 |
#endif |
| 71 |
*/ |
| 72 |
|
| 73 |
#ifdef USE_SDL |
| 74 |
/* |
| 75 |
#ifdef USE_OPENGL |
| 76 |
#include <GL/gl.h> |
| 77 |
#include <GL/glu.h> |
| 78 |
#include <GL/glx.h> |
| 79 |
#endif |
| 80 |
*/ |
| 81 |
#include <SDL.h> |
| 82 |
#include <SDL_video.h> |
| 83 |
#include <SDL_syswm.h> |
| 84 |
#include <SDL_mouse.h> |
| 85 |
|
| 86 |
#ifndef SDL_DISABLE |
| 87 |
#define SDL_DISABLE 0 |
| 88 |
#endif |
| 89 |
|
| 90 |
#ifndef SDL_ENABLE |
| 91 |
#define SDL_ENABLE 1 |
| 92 |
#endif |
| 93 |
|
| 94 |
#endif |
| 95 |
|
| 96 |
#include <cstdio> |
| 97 |
#include <cstdlib> |
| 98 |
#include <cmath> |
| 99 |
#include <iostream> |
| 100 |
#include <string> |
| 101 |
|
| 102 |
using namespace std; |
| 103 |
|
| 104 |
/*fold00*/ |
| 105 |
/* |
| 106 |
inline static void qSafeXDestroyImage( XImage *x ) |
| 107 |
{ |
| 108 |
if ( x->data ) { |
| 109 |
free( x->data ); |
| 110 |
x->data = 0; |
| 111 |
} |
| 112 |
XDestroyImage( x ); |
| 113 |
} |
| 114 |
|
| 115 |
class ShmRenderer : public VideoRenderer |
| 116 |
{ |
| 117 |
bool xshminit; |
| 118 |
XShmSegmentInfo xshminfo; |
| 119 |
XImage *xshmimg; |
| 120 |
Pixmap xshmpm; |
| 121 |
GC gc; |
| 122 |
pthread_mutex_t mutex; |
| 123 |
int xpos; |
| 124 |
int screen; |
| 125 |
|
| 126 |
public: |
| 127 |
ShmRenderer() : xshminit(0), xshmimg(0), xshmpm(0) |
| 128 |
{ |
| 129 |
pthread_mutex_init(&mutex, 0); |
| 130 |
} |
| 131 |
void Alloc() |
| 132 |
{ |
| 133 |
static int major, minor; |
| 134 |
static Bool pixmaps_ok; |
| 135 |
// int dd = dev->x11Depth(); |
| 136 |
// dpy = dev->x11Display(); |
| 137 |
// vis = (Visual*)dev->x11Visual(); |
| 138 |
printf("Creating SHM renderer, width %d, height %d\n", pic_w, pic_h); |
| 139 |
printf("Server vendor %s, release %d\n", ServerVendor(_dpy), VendorRelease(_dpy)); |
| 140 |
|
| 141 |
try |
| 142 |
{ |
| 143 |
XGCValues xcg; |
| 144 |
xcg.graphics_exposures=false; |
| 145 |
gc=XCreateGC(_dpy, _vis, GCGraphicsExposures, &xcg); |
| 146 |
if ( !XShmQueryVersion(_dpy, &major, &minor, &pixmaps_ok) ) |
| 147 |
throw FATAL("MIT SHM extension not supported"); |
| 148 |
|
| 149 |
bool ok; |
| 150 |
int _pic_w=((pic_w+m_w-1)/m_w)*m_w; |
| 151 |
int _pic_h=((pic_h+m_h-1)/m_h)*m_h; |
| 152 |
xshminfo.shmid = shmget( IPC_PRIVATE, |
| 153 |
_pic_w*_pic_h*4, |
| 154 |
IPC_CREAT | 0777 ); |
| 155 |
ok = xshminfo.shmid != -1; |
| 156 |
if(!ok) |
| 157 |
throw FATAL("Can't get shared memory segment"); |
| 158 |
|
| 159 |
xshminfo.shmaddr = (char*)shmat( xshminfo.shmid, 0, 0 ); |
| 160 |
ok = xshminfo.shmaddr != 0; |
| 161 |
xshminfo.readOnly = FALSE; |
| 162 |
|
| 163 |
if ( !ok ) |
| 164 |
throw FATAL("Can't attach shared memory segment"); |
| 165 |
|
| 166 |
ok = XShmAttach( _dpy, &xshminfo ); |
| 167 |
if ( !ok ) |
| 168 |
throw FATAL("XShmAttach failed"); |
| 169 |
|
| 170 |
int dd=DefaultDepth(_dpy, DefaultScreen(dpy)); |
| 171 |
xshmimg = XShmCreateImage( _dpy, _vis, dd, ZPixmap, xshminfo.shmaddr, &xshminfo, _pic_w, _pic_h ); |
| 172 |
|
| 173 |
if ( !xshmimg ) |
| 174 |
throw FATAL("Can't create shared image"); |
| 175 |
|
| 176 |
printf("Video device: %d bpp ( physical %d ), color masks %X,%X,%X\n", |
| 177 |
dd, GetPhysicalDepth(_dpy), _vis->red_mask, _vis->green_mask, _vis->blue_mask); |
| 178 |
} |
| 179 |
catch(...) |
| 180 |
{ |
| 181 |
xshmimg = 0; |
| 182 |
if ( xshminfo.shmaddr ) |
| 183 |
shmdt( xshminfo.shmaddr ); |
| 184 |
if ( xshminfo.shmid != -1 ) |
| 185 |
shmctl( xshminfo.shmid, IPC_RMID, 0 ); |
| 186 |
throw; |
| 187 |
} |
| 188 |
} |
| 189 |
int Create(Display *_dpy, Visual *_vis, int x, int y, int _xpos=0, int sub=0) |
| 190 |
{ |
| 191 |
dpy=_dpy; |
| 192 |
vis=_vis; |
| 193 |
m_w=x; |
| 194 |
m_h=y; |
| 195 |
pic_w=x; |
| 196 |
pic_h=y; |
| 197 |
width=x; |
| 198 |
height=y; |
| 199 |
xpos=_xpos; |
| 200 |
Alloc(); |
| 201 |
} |
| 202 |
int Free() |
| 203 |
{ |
| 204 |
cerr<<"Free()"<<endl; |
| 205 |
if ( xshmimg == 0 ) |
| 206 |
return 0; |
| 207 |
XSync(dpy, false); |
| 208 |
if ( xshmpm ) { |
| 209 |
XFreePixmap( dpy, xshmpm ); |
| 210 |
xshmpm = 0; |
| 211 |
} |
| 212 |
XShmDetach( dpy, &xshminfo ); xshmimg->data = 0; |
| 213 |
qSafeXDestroyImage( xshmimg ); xshmimg = 0; |
| 214 |
shmdt( xshminfo.shmaddr ); |
| 215 |
shmctl( xshminfo.shmid, IPC_RMID, 0 ); |
| 216 |
XFreeGC(_dpy, gc); |
| 217 |
|
| 218 |
xshminfo.shmaddr=0; |
| 219 |
xshminfo.shmid=0; |
| 220 |
} |
| 221 |
int Resize(int& new_w, int& new_h) |
| 222 |
{ |
| 223 |
if(new_w<0)return -1; |
| 224 |
if(new_h<0)return -1; |
| 225 |
new_w&=(~7); |
| 226 |
new_h&=(~7); |
| 227 |
int xratio=(new_w+m_w-1)/m_w; |
| 228 |
int yratio=(new_h+m_h-1)/m_h; |
| 229 |
int old_xratio=(pic_w+m_w-1)/m_w; |
| 230 |
int old_yratio=(pic_h+m_h-1)/m_h; |
| 231 |
cerr<<"New size: "<<new_w<<" "<<new_h<<endl; |
| 232 |
pic_w=new_w; |
| 233 |
pic_h=new_h; |
| 234 |
if((xratio!=old_xratio)||(yratio!=old_yratio)) |
| 235 |
{ |
| 236 |
pthread_mutex_lock(&mutex); |
| 237 |
Free(); |
| 238 |
Alloc(); |
| 239 |
pthread_mutex_unlock(&mutex); |
| 240 |
} |
| 241 |
} |
| 242 |
virtual int Draw(const CImage* data) |
| 243 |
{ |
| 244 |
char* outpic=xshmimg->data; |
| 245 |
if(outpic==0) |
| 246 |
return 0; |
| 247 |
if(data==0) |
| 248 |
return 0; |
| 249 |
|
| 250 |
int bit_depth=GetPhysicalDepth(_dpy); |
| 251 |
|
| 252 |
if(pthread_mutex_trylock(&mutex)==EBUSY) |
| 253 |
return -1; |
| 254 |
// pthread_mutex_lock(&mutex); |
| 255 |
|
| 256 |
sync(); |
| 257 |
const char* src; |
| 258 |
|
| 259 |
if((pic_h==m_h) && (pic_w==m_w)) |
| 260 |
memcpy(outpic, data->data(), data->bytes()); |
| 261 |
else |
| 262 |
zoom((short*)outpic, (short*)data->data(), pic_w, pic_h, m_w, m_h, bit_depth, m_w*((pic_w+m_w-1)/m_w)); |
| 263 |
|
| 264 |
XShmPutImage(_dpy, _vis, gc, |
| 265 |
xshmimg, 0, 0, xpos, 0, pic_w, pic_h, true); |
| 266 |
|
| 267 |
pthread_mutex_unlock(&mutex); |
| 268 |
|
| 269 |
return 0; |
| 270 |
} |
| 271 |
virtual int sync() |
| 272 |
{ |
| 273 |
XSync(_dpy, false); |
| 274 |
return 0; |
| 275 |
} |
| 276 |
virtual ~ShmRenderer() |
| 277 |
{ |
| 278 |
Free(); |
| 279 |
pthread_mutex_destroy(&mutex); |
| 280 |
} |
| 281 |
virtual int toggle_fullscreen(bool=false); |
| 282 |
virtual int drawSubtitles(const char*); |
| 283 |
|
| 284 |
}; |
| 285 |
int ShmRenderer::ToggleFullscreen(bool maximize=false) |
| 286 |
{ |
| 287 |
return 0; |
| 288 |
} |
| 289 |
|
| 290 |
int ShmRenderer::DrawSubtitles(const char* sub) |
| 291 |
{ |
| 292 |
return 0; |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
VideoRenderer* CreateRenderer() |
| 297 |
{ |
| 298 |
return new ShmRenderer; |
| 299 |
} |
| 300 |
*/ |
| 301 |
/*FOLD00*/ |
| 302 |
|
| 303 |
#if 0 |
| 304 |
/*FOLD00*/ |
| 305 |
#ifdef HAVE_LIBXV |
| 306 |
class XvYUVRenderer : public VideoRendererWithLock |
| 307 |
{ |
| 308 |
Display* dpy; |
| 309 |
Window win; |
| 310 |
#ifdef I18N |
| 311 |
XFontSet font; |
| 312 |
#else |
| 313 |
XFontStruct* font; |
| 314 |
#endif |
| 315 |
int screen; |
| 316 |
XShmSegmentInfo xshminfo[2]; |
| 317 |
XvImage* xvimage[2]; |
| 318 |
uint_t xv_format; |
| 319 |
uint_t xv_port; |
| 320 |
const char* title; |
| 321 |
GC gc; |
| 322 |
Pixmap xshmpm; |
| 323 |
XSizeHints hint; |
| 324 |
XVisualInfo vinfo; |
| 325 |
XEvent xev; |
| 326 |
XWindowAttributes attribs; |
| 327 |
|
| 328 |
public: |
| 329 |
XvYUVRenderer(PlayerWidget* pw, Display* _dpy, |
| 330 |
int width, int height, unsigned long format, bool subtitle = false) |
| 331 |
: VideoRendererWithLock(width, height, subtitle), |
| 332 |
dpy(_dpy), font(0), xv_format(0), xv_port(0), xshmpm(0) |
| 333 |
{ |
| 334 |
//g_pw=pw; |
| 335 |
|
| 336 |
cout << XInitThreads() << endl; |
| 337 |
|
| 338 |
title = "Xv rulez"; |
| 339 |
screen = DefaultScreen(dpy); |
| 340 |
|
| 341 |
hint.x = 0; |
| 342 |
hint.y = 0; |
| 343 |
hint.width = m_w; |
| 344 |
hint.height = m_h; |
| 345 |
hint.flags = /*PPosition | */PSize; |
| 346 |
|
| 347 |
XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attribs); |
| 348 |
int depth = GetPhysicalDepth(dpy); |
| 349 |
|
| 350 |
XMatchVisualInfo(dpy, screen, depth, TrueColor, &vinfo); |
| 351 |
Colormap cmap = XCreateColormap(dpy, RootWindow(dpy, screen), |
| 352 |
vinfo.visual, AllocNone); |
| 353 |
XSetWindowAttributes xswa; |
| 354 |
unsigned long xswamask; |
| 355 |
|
| 356 |
xswa.background_pixel = 0; |
| 357 |
xswa.border_pixel = 1; |
| 358 |
xswa.colormap = cmap; |
| 359 |
xswamask = CWBackPixel | CWBorderPixel |CWColormap; |
| 360 |
|
| 361 |
XLockDisplay(dpy); |
| 362 |
win = XCreateWindow(dpy, RootWindow(dpy, screen), |
| 363 |
hint.x, hint.y, hint.width, hint.height, 4, |
| 364 |
depth, CopyFromParent, vinfo.visual, xswamask, &xswa); |
| 365 |
|
| 366 |
XSelectInput(dpy, win, StructureNotifyMask); |
| 367 |
XSetStandardProperties(dpy, win, title, title, None, NULL, 0, &hint); |
| 368 |
|
| 369 |
//if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 ); |
| 370 |
|
| 371 |
/* Map window. */ |
| 372 |
XMapWindow(dpy, win); |
| 373 |
|
| 374 |
/* Wait for map. */ |
| 375 |
do |
| 376 |
{ |
| 377 |
XNextEvent(dpy, &xev); |
| 378 |
//cout << "T: " << xev.xany.type << " w: " << xev.xany.window << endl; |
| 379 |
|
| 380 |
} |
| 381 |
while (xev.type != MapNotify || xev.xmap.event != win); |
| 382 |
|
| 383 |
XSelectInput(dpy, win, NoEventMask); |
| 384 |
|
| 385 |
XFlush(dpy); |
| 386 |
XSync(dpy, False); |
| 387 |
|
| 388 |
|
| 389 |
uint_t ver,rel,req,ev,err; |
| 390 |
if (Success != XvQueryExtension(dpy, &ver,&rel,&req,&ev,&err)) |
| 391 |
throw FATAL("Xv: XvQueryExtension failed"); |
| 392 |
|
| 393 |
/* check for Xvideo support */ |
| 394 |
uint_t adaptors; |
| 395 |
XvAdaptorInfo *ai; |
| 396 |
if (Success != XvQueryAdaptors(dpy, DefaultRootWindow(dpy), &adaptors,&ai)) |
| 397 |
throw FATAL("Xv: XvQueryAdaptors failed"); |
| 398 |
|
| 399 |
/* check adaptors */ |
| 400 |
for (unsigned i = 0; i < adaptors; i++) |
| 401 |
{ |
| 402 |
if (!xv_port && (ai[i].type & XvInputMask) && (ai[i].type & XvImageMask)) |
| 403 |
xv_port = ai[i].base_id; |
| 404 |
} |
| 405 |
|
| 406 |
XvFreeAdaptorInfo(ai); |
| 407 |
|
| 408 |
/* check image formats */ |
| 409 |
if (!xv_port) |
| 410 |
throw FATAL("Xv: XvQueryAdaptors no port"); |
| 411 |
|
| 412 |
uint_t formats; |
| 413 |
XvImageFormatValues* fo = XvListImageFormats(dpy, xv_port, (int*)&formats); |
| 414 |
for(unsigned i = 0; i < formats; i++) |
| 415 |
{ |
| 416 |
fprintf(stderr, "Xvideo image format: 0x%x (%4.4s) %s\n", fo[i].id, |
| 417 |
(char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); |
| 418 |
|
| 419 |
if (fo[i].id == (signed) format) |
| 420 |
xv_format = fo[i].id; |
| 421 |
} |
| 422 |
if (!xv_format) /* no matching image format not */ |
| 423 |
throw FATAL("Xv: XvQueryAdaptors no port"); |
| 424 |
|
| 425 |
fprintf(stderr,"using Xvideo port %d for hw scaling\n", xv_port); |
| 426 |
|
| 427 |
//allocate_xvimage(0); |
| 428 |
/* catch window resizes */ |
| 429 |
XSelectInput(dpy, win, |
| 430 |
EnterWindowMask | LeaveWindowMask |
| 431 |
| PointerMotionMask |
| 432 |
| StructureNotifyMask | KeyPressMask); |
| 433 |
//XSelectInput(mydisplay, mywindow, StructureNotifyMask); |
| 434 |
|
| 435 |
// resize: |
| 436 |
XMoveResizeWindow(dpy, win, 0, 0, m_w, m_h); |
| 437 |
XUnlockDisplay(dpy); |
| 438 |
Alloc(); |
| 439 |
} |
| 440 |
|
| 441 |
virtual ~XvYUVRenderer() |
| 442 |
{ |
| 443 |
cout <<"XvYUV: Destroy" << endl; |
| 444 |
Lock(); |
| 445 |
Free(); |
| 446 |
} |
| 447 |
|
| 448 |
void Alloc() |
| 449 |
{ |
| 450 |
printf("Creating Xv renderer, width %d, height %d\n", pic_w, pic_h); |
| 451 |
printf("Server vendor %s, release %d\n", |
| 452 |
ServerVendor(dpy), VendorRelease(dpy)); |
| 453 |
try |
| 454 |
{ |
| 455 |
bool ok = true; |
| 456 |
int width=((pic_w+m_w-1)/m_w)*m_w; |
| 457 |
int height=((pic_h+m_h-1)/m_h)*m_h; |
| 458 |
if (! ok) |
| 459 |
throw FATAL("XShmAttach failed"); |
| 460 |
|
| 461 |
XGCValues xgcv; |
| 462 |
xgcv.graphics_exposures = false; |
| 463 |
XLockDisplay(dpy); |
| 464 |
gc = XCreateGC(dpy, win, 0L, &xgcv); |
| 465 |
//int dd = DefaultDepth(dpy, DefaultScreen(dpy)); |
| 466 |
xvimage[0] = XvShmCreateImage(dpy, xv_port, xv_format, 0, |
| 467 |
width, height, &xshminfo[0]); |
| 468 |
|
| 469 |
if (! xvimage[0]) |
| 470 |
throw FATAL("Can't create shared image"); |
| 471 |
|
| 472 |
xshminfo[0].shmid = shmget(IPC_PRIVATE, xvimage[0]->data_size, IPC_CREAT | 0777); |
| 473 |
xshminfo[0].shmaddr = (char *) shmat(xshminfo[0].shmid, 0, 0); |
| 474 |
xshminfo[0].readOnly = False; |
| 475 |
|
| 476 |
xvimage[0]->data = xshminfo[0].shmaddr; |
| 477 |
XShmAttach(dpy, &xshminfo[0]); |
| 478 |
XSync(dpy, False); |
| 479 |
XUnlockDisplay(dpy); |
| 480 |
shmctl(xshminfo[0].shmid, IPC_RMID, 0); |
| 481 |
|
| 482 |
/* so we can do grayscale while testing... */ |
| 483 |
memset(xvimage[0]->data, 128, xvimage[0]->data_size); |
| 484 |
|
| 485 |
//printf("Video device: %d bpp ( physical %d ), color masks %lX,%lX,%lX\n", |
| 486 |
// dd, GetPhysicalDepth(dpy), |
| 487 |
// vis->red_mask, vis->green_mask, vis->blue_mask); |
| 488 |
//Alloc(); |
| 489 |
} catch(...) |
| 490 |
{ |
| 491 |
throw; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
int Free() |
| 496 |
{ |
| 497 |
//cout <<"XvYUV: Free()" << endl; |
| 498 |
|
| 499 |
if (xvimage[0] == 0) |
| 500 |
return 0; |
| 501 |
XLockDisplay(dpy); |
| 502 |
XFreeGC(dpy, gc); |
| 503 |
XSync(dpy, False); |
| 504 |
XShmDetach(dpy, &xshminfo[0]); |
| 505 |
XUnlockDisplay(dpy); |
| 506 |
|
| 507 |
XFree(xvimage[0]); |
| 508 |
xvimage[0] = 0; |
| 509 |
shmdt( xshminfo[0].shmaddr ); |
| 510 |
shmctl( xshminfo[0].shmid, IPC_RMID, 0 ); |
| 511 |
return 0; |
| 512 |
} |
| 513 |
|
| 514 |
int Resize(int& new_w, int& new_h) |
| 515 |
{ |
| 516 |
if (new_w < 0 || new_h < 0) |
| 517 |
return -1; |
| 518 |
|
| 519 |
new_w&=(~7); |
| 520 |
new_h&=(~7); |
| 521 |
int xratio=(new_w+m_w-1)/m_w; |
| 522 |
int yratio=(new_h+m_h-1)/m_h; |
| 523 |
int old_xratio=(pic_w+m_w-1)/m_w; |
| 524 |
int old_yratio=(pic_h+m_h-1)/m_h; |
| 525 |
cerr<<"New size: "<<new_w<<" "<<new_h<<endl; |
| 526 |
pic_w=new_w; |
| 527 |
pic_h=new_h; |
| 528 |
if (xratio != old_xratio || yratio != old_yratio) |
| 529 |
{ |
| 530 |
Lock(); |
| 531 |
Free(); |
| 532 |
Alloc(); |
| 533 |
Unlock(); |
| 534 |
} |
| 535 |
return 0; |
| 536 |
} |
| 537 |
|
| 538 |
virtual int Draw(const CImage* data) |
| 539 |
{ |
| 540 |
char* outpic = xvimage[0]->data; |
| 541 |
|
| 542 |
if (outpic==0 || data==0) |
| 543 |
return 0; |
| 544 |
|
| 545 |
//int bit_depth=GetPhysicalDepth(dpy); |
| 546 |
if (TryLock()==EBUSY) |
| 547 |
return -1; |
| 548 |
|
| 549 |
memcpy(outpic, data->Data(), data->Bytes()); |
| 550 |
//cout << "b " << data->bytes(); |
| 551 |
XLockDisplay(dpy); |
| 552 |
XvShmPutImage(dpy, xv_port, win, gc, xvimage[0], |
| 553 |
0, 0, m_w, m_h, 0, 0, pic_w, pic_h, True); |
| 554 |
XFlush(dpy); |
| 555 |
XUnlockDisplay(dpy); |
| 556 |
|
| 557 |
Unlock(); |
| 558 |
return 0; |
| 559 |
|
| 560 |
int ret=0; |
| 561 |
XEvent xevent; |
| 562 |
char buf[100]; |
| 563 |
KeySym keySym; |
| 564 |
XComposeStatus cstat; |
| 565 |
|
| 566 |
///XNextEvent( dpy, &xevent ); |
| 567 |
cout << "T: " << xevent.xany.type << " w: " << xevent.xany.window << endl; |
| 568 |
//cout << XPending( dpy ) << endl; |
| 569 |
//while ( NonblockXPending( dpy ) ) |
| 570 |
while ( XPending( dpy ) ) |
| 571 |
{ |
| 572 |
cout << "event " << endl; |
| 573 |
XNextEvent( dpy, &xevent ); |
| 574 |
switch( xevent.type ) |
| 575 |
{ |
| 576 |
case EnterNotify: |
| 577 |
cout << "Enter" << endl; |
| 578 |
break; |
| 579 |
case LeaveNotify: |
| 580 |
cout << "Enter" << endl; |
| 581 |
break; |
| 582 |
case Expose: |
| 583 |
//ret|=VO_EVENT_EXPOSE; |
| 584 |
break; |
| 585 |
case ConfigureNotify: |
| 586 |
{ |
| 587 |
int width=xevent.xconfigure.width; |
| 588 |
int height=xevent.xconfigure.height; |
| 589 |
//ret|=VO_EVENT_RESIZE; |
| 590 |
cout << "Resize " << width << " " << height << endl; |
| 591 |
} |
| 592 |
break; |
| 593 |
case KeyPress: |
| 594 |
XLookupString( &xevent.xkey,buf,sizeof(buf),&keySym,&cstat ); |
| 595 |
//vo_x11_putkey( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) ); |
| 596 |
//ret|=VO_EVENT_KEYPRESS; |
| 597 |
break; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
return 0; |
| 602 |
} |
| 603 |
virtual int Sync() |
| 604 |
{ |
| 605 |
//XFlush(dpy); |
| 606 |
return 0; |
| 607 |
} |
| 608 |
virtual int ToggleFullscreen(bool=false) |
| 609 |
{ |
| 610 |
return 0; |
| 611 |
} |
| 612 |
virtual int DrawSubtitles(const char*) |
| 613 |
{ |
| 614 |
return 0; |
| 615 |
} |
| 616 |
int Refresh() |
| 617 |
{ |
| 618 |
return 0; |
| 619 |
} |
| 620 |
}; |
| 621 |
|
| 622 |
VideoRenderer* CreateXvYUVRenderer(PlayerWidget* pw, Display* dpy, |
| 623 |
int width, int height, |
| 624 |
fourcc_t yuv_fmt, bool sub) |
| 625 |
{ |
| 626 |
return new XvYUVRenderer(pw, dpy, width, height, yuv_fmt, sub); |
| 627 |
} |
| 628 |
|
| 629 |
#endif /* HAVE_LIBXV */ |
| 630 |
/*FOLD00*/ |
| 631 |
|
| 632 |
#endif |
| 633 |
/* |
| 634 |
#ifdef USE_OPENGL |
| 635 |
struct texts { |
| 636 |
int w; |
| 637 |
int h; |
| 638 |
int u_w; |
| 639 |
int u_h; |
| 640 |
GLuint *texture; |
| 641 |
int quad_1; |
| 642 |
int quad_2; |
| 643 |
int quad_3; |
| 644 |
int quad_4; |
| 645 |
}; |
| 646 |
|
| 647 |
class GLFullscreenRenderer: public VideoRenderer |
| 648 |
{ |
| 649 |
|
| 650 |
SDL_Surface *screen; |
| 651 |
int dim_w, dim_h; |
| 652 |
int fs; |
| 653 |
int m_sub; |
| 654 |
int zoom_divider; |
| 655 |
int dirty; |
| 656 |
Window wnd; |
| 657 |
pthread_mutex_t mutex; |
| 658 |
struct texts *textures; |
| 659 |
GLuint *textureids; |
| 660 |
GLubyte* pixels; |
| 661 |
int textcount_w; |
| 662 |
int textcount_h; |
| 663 |
int max_texture_size; |
| 664 |
public: |
| 665 |
GLFullscreenRenderer():screen(0){} |
| 666 |
|
| 667 |
|
| 668 |
virtual int Create(QWidget* w, int width, int height, int xpos=0, int subtitles=0) |
| 669 |
{ |
| 670 |
fs=SDL_RESIZABLE | SDL_OPENGL; |
| 671 |
|
| 672 |
char SDL_windowhack[256]; |
| 673 |
dev=w; |
| 674 |
Display *dpy = dev->x11Display(); |
| 675 |
::dpy=dpy; |
| 676 |
unsigned long mask; |
| 677 |
|
| 678 |
int glxMajorVersion, glxMinorVersion; |
| 679 |
|
| 680 |
|
| 681 |
if(SDL_Init(SDL_INIT_VIDEO ) <0) |
| 682 |
throw FATAL("Failed to init SDL"); |
| 683 |
m_w=width; |
| 684 |
|
| 685 |
m_h=height; |
| 686 |
width=1024; |
| 687 |
height=768; |
| 688 |
pic_w=width; |
| 689 |
pic_h=height; |
| 690 |
m_sub=subtitles; |
| 691 |
dirty=0; |
| 692 |
dim_w=pic_w; |
| 693 |
dim_h=pic_h+(subtitles?80:0); |
| 694 |
pthread_mutex_init(&mutex, 0); |
| 695 |
// screen = SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL); | SDL_INIT_EVENTTHREAD |
| 696 |
screen=SDL_SetVideoMode(dim_w, dim_h, GetPhysicalDepth(dev), fs); |
| 697 |
if(screen ) |
| 698 |
{ |
| 699 |
// SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); |
| 700 |
// SDL_SetEventFilter(EventFilter); |
| 701 |
valid_filter=1; |
| 702 |
SDL_WM_SetCaption("Movie window", 0); |
| 703 |
|
| 704 |
SDL_SysWMinfo info; |
| 705 |
|
| 706 |
SDL_VERSION(&info.version); |
| 707 |
SDL_GetWMInfo(&info); |
| 708 |
Display *dpy=dev->x11Display(); |
| 709 |
|
| 710 |
GLint maxsize=0; |
| 711 |
GLboolean b= false; |
| 712 |
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); |
| 713 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size); |
| 714 |
cerr<<"Texturemaxsize="<<max_texture_size<<endl; |
| 715 |
glGetIntegerv(GL_RED_BITS, &maxsize); |
| 716 |
cerr<<"RED BITS="<<maxsize<<endl; |
| 717 |
glGetIntegerv(GL_BLUE_BITS, &maxsize); |
| 718 |
cerr<<"BLUE BITS="<<maxsize<<endl; |
| 719 |
glGetIntegerv(GL_GREEN_BITS, &maxsize); |
| 720 |
cerr<<"GREEN BITS="<<maxsize<<endl; |
| 721 |
glGetIntegerv(GL_ALPHA_BITS, &maxsize); |
| 722 |
cerr<<"ALPHA BITS="<<maxsize<<endl; |
| 723 |
glGetIntegerv(GL_MAX_TEXTURE_STACK_DEPTH, &maxsize); |
| 724 |
cerr<<"MAX_TEXTURE_STACK_DEPTH="<<maxsize<<endl; |
| 725 |
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxsize); |
| 726 |
cerr<<"MAX_TEXTURE_UNITS="<<maxsize<<endl; |
| 727 |
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &maxsize); |
| 728 |
cerr<<"MAX_VIEWPORT_DIMS="<<maxsize<<endl; |
| 729 |
glGetBooleanv(GL_DOUBLEBUFFER, &b); |
| 730 |
if (b) |
| 731 |
cerr<<"DOUBLBUFFER IS OK"<<endl; |
| 732 |
else |
| 733 |
cerr<<"NO DOUBELBUFFER"<<endl; |
| 734 |
glGetBooleanv(GL_RGBA_MODE, &b); |
| 735 |
if (b) |
| 736 |
cerr<<"RGBA IS TRUE"<<endl; |
| 737 |
else |
| 738 |
cerr<<"RGBA IS FALSE"<<endl; |
| 739 |
glXQueryVersion(::dpy, &glxMajorVersion, &glxMinorVersion); |
| 740 |
cerr<<"glX-Version "<<glxMajorVersion<<"."<<glxMinorVersion<<endl; |
| 741 |
if (glXIsDirect(::dpy, glXGetCurrentContext())) |
| 742 |
cerr<<"Congrats, you have Direct Rendering!"<<endl; |
| 743 |
else { |
| 744 |
cerr<<"Sorry, no Direct Rendering possible!"<<endl; |
| 745 |
screen = false; |
| 746 |
} |
| 747 |
|
| 748 |
glEnable( GL_TEXTURE_2D ); |
| 749 |
glViewport(0,0,pic_w, pic_h); |
| 750 |
if (createTextures()>0) { |
| 751 |
cerr<<"Fatal Error : can't create Textures"<<endl; |
| 752 |
screen=false; |
| 753 |
} |
| 754 |
else { |
| 755 |
gluOrtho2D(0, m_w, m_h, 0); |
| 756 |
int error = glGetError( ); |
| 757 |
if (error) |
| 758 |
cerr<<"Initerror :"<<error<<endl; |
| 759 |
|
| 760 |
// glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading |
| 761 |
|
| 762 |
|
| 763 |
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); |
| 764 |
glEnable( GL_TEXTURE_2D ); |
| 765 |
if (error) |
| 766 |
cerr<<"Initerror :"<<error<<endl; |
| 767 |
} |
| 768 |
|
| 769 |
return 0; |
| 770 |
} |
| 771 |
if(!screen) |
| 772 |
throw FATAL("Failed to set up video mode"); |
| 773 |
throw FATAL("Failed to set up fullscreen mode"); |
| 774 |
|
| 775 |
} |
| 776 |
|
| 777 |
GLenum createTextures() |
| 778 |
{ |
| 779 |
|
| 780 |
int skip_w=0; |
| 781 |
int skip_h=0; |
| 782 |
textcount_w=0; |
| 783 |
textcount_h=0; |
| 784 |
// This look how many textures we need in width |
| 785 |
while(skip_w<(m_w-8)) { |
| 786 |
skip_w += getPowerOf2(m_w-skip_w); |
| 787 |
textcount_w++; |
| 788 |
} |
| 789 |
// This look how many textures we need in height |
| 790 |
while(skip_h<(m_h-8)) { |
| 791 |
skip_h += getPowerOf2(m_h-skip_h); |
| 792 |
textcount_h++; |
| 793 |
} |
| 794 |
// A Backround will be set, if not the texture will not shown later |
| 795 |
pixels = (GLubyte*) malloc( m_w * m_h * 4); |
| 796 |
memset( pixels, 128, m_w * m_h * 4 ); |
| 797 |
if (!pixels) { |
| 798 |
return GL_OUT_OF_MEMORY; |
| 799 |
} |
| 800 |
|
| 801 |
textures = new texts[textcount_w * textcount_h]; // Here we stores all informatio n |
| 802 |
of the textures |
| 803 |
textureids = new GLuint[textcount_w * textcount_h]; // The Textureids so we can |
| 804 |
create all textures at once |
| 805 |
glGenTextures( textcount_w * textcount_h, textureids); // And here their will created |
| 806 |
skip_h=0; // Stores the Rows to skip |
| 807 |
int i=0; // only needed for pointerarithmetic |
| 808 |
for(int h=0; h<textcount_h;h++) { |
| 809 |
skip_w=0; // the pixels in row to skip |
| 810 |
int text_size_h = getPowerOf2(m_h-skip_h); |
| 811 |
for(int w=0; w<textcount_w;w++) { |
| 812 |
int text_size_w = getPowerOf2(m_w-skip_w); |
| 813 |
(textures+i)->w = text_size_w; // width and height of texture |
| 814 |
(textures+i)->h = text_size_h; |
| 815 |
cerr<<"Texturesize("<<i<<") :"<<text_size_w<<"; "<<text_size_h<<endl; |
| 816 |
(textures+i)->u_w = skip_w; // Pixels zu skip in row |
| 817 |
(textures+i)->u_h = skip_h; // Rows to skip |
| 818 |
(textures+i)->texture = (textureids+i); |
| 819 |
(textures+i)->quad_1 = skip_w; // is the vortex of the texture, |
| 820 |
so we can |
| 821 |
(textures+i)->quad_2 = skip_h; // draw faster (later) |
| 822 |
(textures+i)->quad_3 = (textures+i)->quad_1 + (textures+i)->w; |
| 823 |
(textures+i)->quad_4 = (textures+i)->quad_2 + (textures+i)->h; |
| 824 |
skip_w +=text_size_w; |
| 825 |
|
| 826 |
glBindTexture( GL_TEXTURE_2D, (GLuint) (textures+i)->texture); |
| 827 |
|
| 828 |
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); |
| 829 |
//GL_DECAL |
| 830 |
|
| 831 |
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); |
| 832 |
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); |
| 833 |
|
| 834 |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); |
| 835 |
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); |
| 836 |
|
| 837 |
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, (textures+i)->w, (textures+i)->h, 0, |
| 838 |
GL_RGBA, GL_UNSIGNED_BYTE, pixels ); |
| 839 |
int error = glGetError( ); |
| 840 |
if (error) return error; |
| 841 |
i++; |
| 842 |
} |
| 843 |
skip_h +=text_size_h; |
| 844 |
} |
| 845 |
|
| 846 |
// Simple state setup at the end. |
| 847 |
glClearColor( 0.0, 0.0, 0.0, 0.0 ); |
| 848 |
|
| 849 |
return glGetError( ); |
| 850 |
} |
| 851 |
|
| 852 |
int getPowerOf2(int value) |
| 853 |
{ |
| 854 |
int i,e; |
| 855 |
for(i=1;((i<=value) && (i<=max_texture_size)) ; i*=2) |
| 856 |
e=i; |
| 857 |
return e; |
| 858 |
} |
| 859 |
|
| 860 |
int Resize(int& new_w, int& new_h) |
| 861 |
{ |
| 862 |
if(new_w<0)return -1; |
| 863 |
if(new_h<0)return -1; |
| 864 |
if(new_h<m_h/4) |
| 865 |
return -1; |
| 866 |
if(new_w<m_w/4) |
| 867 |
return -1; |
| 868 |
pic_w=new_w; |
| 869 |
pic_h=new_h; |
| 870 |
dim_w=pic_w; |
| 871 |
dim_h=pic_h+(m_sub?fm_height*4:0); |
| 872 |
pthread_mutex_lock(&mutex); |
| 873 |
|
| 874 |
if(screen){ SDL_FreeSurface(screen); screen=0;} |
| 875 |
screen=SDL_SetVideoMode(dim_w, dim_h, 0, fs); |
| 876 |
if (screen) |
| 877 |
glViewport(0,0,pic_w, pic_h); |
| 878 |
|
| 879 |
|
| 880 |
pthread_mutex_unlock(&mutex); |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
virtual int Draw(const CImage* data) |
| 889 |
{ |
| 890 |
if(!screen)return -1; |
| 891 |
if(pthread_mutex_trylock(&mutex)==EBUSY) return -1; |
| 892 |
// copy the picture and swap BGR to RGB |
| 893 |
memcpy(pixels, data->Data(), data->Bytes()); |
| 894 |
for (int i=0;i<data->Bytes();i+=3) |
| 895 |
{ |
| 896 |
GLubyte tmp; |
| 897 |
tmp = *(pixels+i); |
| 898 |
*(pixels+i)=* (pixels+i+2); |
| 899 |
*(pixels+i+2)=tmp; |
| 900 |
} |
| 901 |
// load picture in textures and draw them |
| 902 |
for(int i=0; i<(textcount_w*textcount_h); i++) { |
| 903 |
glBindTexture( GL_TEXTURE_2D, (GLuint)(textures+i)->texture); |
| 904 |
glPixelStorei( GL_UNPACK_SKIP_PIXELS, (textures+i)->u_w ); |
| 905 |
glPixelStorei( GL_UNPACK_SKIP_ROWS, (textures+i)->u_h ); |
| 906 |
glPixelStorei( GL_UNPACK_ROW_LENGTH, m_w ); |
| 907 |
|
| 908 |
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, (textures+i)->w, (textures+i)->h, GL_RGB, |
| 909 |
GL_UNSIGNED_BYTE, pixels ); |
| 910 |
|
| 911 |
glBegin( GL_QUADS ); |
| 912 |
glTexCoord2f( 0.0, 0.0 ); |
| 913 |
glVertex2i((textures+i)->quad_1, (textures+i)->quad_2); |
| 914 |
glTexCoord2f( 0.0, 1.0 ); |
| 915 |
glVertex2i( (textures+i)->quad_1, (textures+i)->quad_4); |
| 916 |
glTexCoord2f( 1.0, 1.0 ); |
| 917 |
glVertex2i( (textures+i)->quad_3, (textures+i)->quad_4 ); |
| 918 |
glTexCoord2f( 1.0, 0.0 ); |
| 919 |
glVertex2i((textures+i)->quad_3, (textures+i)->quad_2 ); |
| 920 |
glEnd( ); |
| 921 |
int error = glGetError( ); |
| 922 |
if (error) |
| 923 |
cerr<<"Drawerror :"<<error<<endl; |
| 924 |
} |
| 925 |
SDL_GL_SwapBuffers(); |
| 926 |
pthread_mutex_unlock(&mutex); |
| 927 |
SDL_Event event; |
| 928 |
while(SDL_PollEvent(&event)) |
| 929 |
EventFilter(&event); |
| 930 |
return 0; |
| 931 |
} |
| 932 |
|
| 933 |
virtual int sync() |
| 934 |
{ |
| 935 |
if(dirty) |
| 936 |
{ |
| 937 |
SDL_UpdateRect(screen, 0, 0, dim_w, dim_h-(m_sub?fm_height*4:0)); |
| 938 |
dirty=0; |
| 939 |
} |
| 940 |
return 0; |
| 941 |
} |
| 942 |
virtual ~GLFullscreenRenderer() |
| 943 |
{ |
| 944 |
pthread_mutex_lock(&mutex); |
| 945 |
|
| 946 |
free(pixels); |
| 947 |
SDL_SetEventFilter(0); |
| 948 |
SDL_QuitSubSystem(SDL_INIT_VIDEO); |
| 949 |
valid_filter=0; |
| 950 |
pthread_mutex_unlock(&mutex); |
| 951 |
pthread_mutex_destroy(&mutex); |
| 952 |
|
| 953 |
} |
| 954 |
virtual int toggle_fullscreen(bool maximize=false) |
| 955 |
{ |
| 956 |
pthread_mutex_lock(&mutex); |
| 957 |
fs=fs^SDL_FULLSCREEN; |
| 958 |
if(screen){ SDL_FreeSurface(screen); screen=0;} |
| 959 |
screen=SDL_SetVideoMode(dim_w, dim_h, GetPhysicalDepth(dev), SDL_OPENGL | fs); |
| 960 |
if(!screen) |
| 961 |
{ |
| 962 |
fs=fs^SDL_FULLSCREEN; |
| 963 |
screen=SDL_SetVideoMode(dim_w, dim_h, GetPhysicalDepth(dev), SDL_OPENGL |fs); |
| 964 |
} |
| 965 |
else |
| 966 |
glViewport(0, 0, pic_w, pic_h); |
| 967 |
|
| 968 |
if(fs&SDL_FULLSCREEN) |
| 969 |
{ |
| 970 |
SDL_ShowCursor(0); |
| 971 |
} |
| 972 |
else |
| 973 |
{ |
| 974 |
SDL_ShowCursor(1); |
| 975 |
} |
| 976 |
|
| 977 |
#ifdef HAVE_LIBXXF86VM |
| 978 |
if(maximize && (fs&SDL_FULLSCREEN)) |
| 979 |
{ |
| 980 |
XF86VidModeModeLine mode; |
| 981 |
int unused; |
| 982 |
int w, h; |
| 983 |
double ratio_x, ratio_y; |
| 984 |
if ( XF86VidModeGetModeLine(dev->x11Display(), dev->x11Screen(), &unused, &mode) ) |
| 985 |
{ |
| 986 |
w = mode.hdisplay; |
| 987 |
h = mode.vdisplay-(m_sub?fm_height*4:0); |
| 988 |
ratio_x=double(w)/pic_w; |
| 989 |
ratio_y=double(h)/pic_h; |
| 990 |
double ratio=(ratio_x<ratio_y)?ratio_x:ratio_y; |
| 991 |
w=int(ratio*pic_w); |
| 992 |
h=int(ratio*pic_h); |
| 993 |
cerr<<mode.hdisplay<<" "<<mode.vdisplay<<" "<<w<<" "<<h<<endl; |
| 994 |
pthread_mutex_unlock(&mutex); |
| 995 |
Resize(w, h); |
| 996 |
|
| 997 |
return ((fs&SDL_FULLSCREEN)==0)?0:1; |
| 998 |
} |
| 999 |
} |
| 1000 |
#endif |
| 1001 |
pthread_mutex_unlock(&mutex); |
| 1002 |
|
| 1003 |
|
| 1004 |
return ((fs&SDL_FULLSCREEN)==0)?0:1; |
| 1005 |
|
| 1006 |
} |
| 1007 |
virtual int drawSubtitles(const char* text) |
| 1008 |
{ |
| 1009 |
static char* old_text=0; |
| 1010 |
if(!m_sub)return 0; |
| 1011 |
if(!text)return 0; |
| 1012 |
if((!old_text) && (!text[0]))return 0; |
| 1013 |
|
| 1014 |
SDL_SysWMinfo info; |
| 1015 |
XGCValues gcv; |
| 1016 |
|
| 1017 |
SDL_VERSION(&info.version); |
| 1018 |
SDL_GetWMInfo(&info); |
| 1019 |
Window win; |
| 1020 |
if(fs & SDL_FULLSCREEN) |
| 1021 |
win=info.info.x11.fswindow; |
| 1022 |
else |
| 1023 |
win=info.info.x11.window; |
| 1024 |
Display *dpy=dev->x11Display(); |
| 1025 |
gcv.graphics_exposures = False; |
| 1026 |
win=info.info.x11.window; |
| 1027 |
|
| 1028 |
if(old_text && (!strcmp(text, old_text))) |
| 1029 |
return 0; |
| 1030 |
|
| 1031 |
QFont font=RegAccess::ReadFont(); |
| 1032 |
GC gc=XCreateGC(dpy, win, GCGraphicsExposures, &gcv); |
| 1033 |
#ifndef I18N |
| 1034 |
XSetFont(dpy, gc, font.handle()); |
| 1035 |
#endif |
| 1036 |
XSetForeground(dpy, gc, 0x0); |
| 1037 |
if(old_text && strcmp(text, old_text)) |
| 1038 |
XFillRectangle(dpy, win, gc, 0, dim_h-80, dim_w, 80); |
| 1039 |
XSetForeground(dpy, gc, 0xFFFFFFFF); |
| 1040 |
if(old_text)delete old_text; |
| 1041 |
old_text=new char[strlen(text)+1]; |
| 1042 |
strcpy(old_text, text); |
| 1043 |
char* sub=new char[strlen(text)+1]; |
| 1044 |
char* sub_orig=sub; |
| 1045 |
strcpy(sub, text); |
| 1046 |
char* run=sub; |
| 1047 |
int line=0; |
| 1048 |
while(*run!=0) |
| 1049 |
{ |
| 1050 |
run=strchr(run, '|'); |
| 1051 |
if(run)*run=0; |
| 1052 |
// XDrawString16(dpy, win, gc, |
| 1053 |
// dim_w/2-6*strlen(sub)/2, dim_h-65+20*line, |
| 1054 |
// (XChar2b*)(short*)QString::fromLocal8Bit(sub).unicode(), strlen(sub)); |
| 1055 |
XDrawString(dpy, win, gc, |
| 1056 |
dim_w/2-6*strlen(sub)/2, dim_h-65+20*line, |
| 1057 |
sub, strlen(sub)); |
| 1058 |
if(run==0)break; |
| 1059 |
line++; |
| 1060 |
run++; |
| 1061 |
sub=run; |
| 1062 |
} |
| 1063 |
delete sub_orig; |
| 1064 |
XFreeGC(dpy, gc); |
| 1065 |
return 0; |
| 1066 |
} |
| 1067 |
}; |
| 1068 |
|
| 1069 |
VideoRenderer* CreateGLFullscreenRenderer() |
| 1070 |
{ |
| 1071 |
return new GLFullscreenRenderer; |
| 1072 |
} |
| 1073 |
#endif //USE_OPENGL |
| 1074 |
*/ |
| 1075 |
#ifdef HAVE_LIBXXF86DGA |
| 1076 |
#ifdef HAVE_LIBXXF86VM |
| 1077 |
/******************************************************** |
| 1078 |
|
| 1079 |
DGA video renderer |
| 1080 |
Copyright 2000 Heinrich Langos |
| 1081 |
|
| 1082 |
*********************************************************/ |
| 1083 |
/* |
| 1084 |
#define INT32 __my_int32 |
| 1085 |
#define INT8 __my_int8 |
| 1086 |
// damn qglobal.h defines INT32 and INT8 without saying anything about signs |
| 1087 |
// thanx to roots__ from #c for helping me out with this. |
| 1088 |
|
| 1089 |
//#include "mmx_dga.cpp" |
| 1090 |
#include <X11/Xproto.h> |
| 1091 |
#include <X11/Xmd.h> |
| 1092 |
#include <X11/extensions/xf86dga.h> |
| 1093 |
#include <X11/extensions/xf86dgastr.h> |
| 1094 |
|
| 1095 |
#define VIDMODE_SWITCHING_DELAY 100 |
| 1096 |
|
| 1097 |
#include <X11/extensions/xf86vmode.h> |
| 1098 |
#include <X11/extensions/xf86vmstr.h> |
| 1099 |
|
| 1100 |
class DGARenderer: public VideoRenderer |
| 1101 |
// vm_* videomode variables |
| 1102 |
// vp_* vievport variables |
| 1103 |
{ |
| 1104 |
Display *dpy; |
| 1105 |
int ppl; //pixel per line (scan line, not frame line !! ) |
| 1106 |
char* base; //frame buffer base address |
| 1107 |
|
| 1108 |
int zoom_divider; |
| 1109 |
|
| 1110 |
|
| 1111 |
int vm_count; //number of available videomodes |
| 1112 |
XF86VidModeModeInfo **vm_modelines; // the modes themself |
| 1113 |
bool vm_switched; //only used to decide if we have to switch back on quit |
| 1114 |
|
| 1115 |
int vp_width,vp_height; // the viewport size |
| 1116 |
int vp_flip_offset; // memory offset to the next frame in framebuffer |
| 1117 |
int vp_current; // currently used viewport (0..vp_frames-1) |
| 1118 |
const static int vp_frames=2; // the number of viewports that we use. |
| 1119 |
int bit_depth,byte_depth; //self explaining ... |
| 1120 |
char *conversionbuf; // only used if we dont render directly into the framebuffer |
| 1121 |
|
| 1122 |
|
| 1123 |
void set_vidmode(int nr) |
| 1124 |
{ |
| 1125 |
printf("switching video mode to %dx%d/%d now\n", |
| 1126 |
vm_modelines[nr]->hdisplay, |
| 1127 |
vm_modelines[nr]->vdisplay, |
| 1128 |
vm_modelines[nr]->dotclock); |
| 1129 |
|
| 1130 |
// XF86VidModeSwitchToMode(dpy,XDefaultScreen(dpy),vm_modelines[nr]); |
| 1131 |
avm_usleep(VIDMODE_SWITCHING_DELAY*1000); |
| 1132 |
} |
| 1133 |
|
| 1134 |
public: |
| 1135 |
DGARenderer() |
| 1136 |
{} |
| 1137 |
int toggle_fullscreen() |
| 1138 |
{} |
| 1139 |
virtual int Create(QWidget* w, int x, int y, int zoom=1, int xpos=0, int sub=0) |
| 1140 |
{ |
| 1141 |
zoom_divider=zoom; |
| 1142 |
if(zoom!=1 && zoom!=2)throw FATAL("Unsupported zoom factor"); |
| 1143 |
vp_current=0; |
| 1144 |
dev=(QPaintDevice*)w; |
| 1145 |
dpy = dev->x11Display(); |
| 1146 |
m_w=x; |
| 1147 |
m_h=y; |
| 1148 |
width=x; |
| 1149 |
height=y; |
| 1150 |
Visual *vis = (Visual*)dev->x11Visual(); |
| 1151 |
bool have_dga=false; |
| 1152 |
int minor, major, bank, ram, flags; |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
int i,bestmatch, diff_x=99999, diff_y=99999; |
| 1157 |
XF86VidModeGetAllModeLines(dpy,XDefaultScreen(dpy), |
| 1158 |
&vm_count,&vm_modelines); |
| 1159 |
for (i = 0; i < vm_count; i++) { |
| 1160 |
if ((width/zoom_divider <= vm_modelines[i]->hdisplay) && |
| 1161 |
(height/zoom_divider <= vm_modelines[i]->vdisplay)) |
| 1162 |
if ( ( (vm_modelines[i]->hdisplay - width/zoom_divider) <= diff_x) && |
| 1163 |
( (vm_modelines[i]->vdisplay - height/zoom_divider) <= diff_y) ) { |
| 1164 |
bestmatch=i; |
| 1165 |
diff_x =vm_modelines[i]->hdisplay - width/zoom_divider ; |
| 1166 |
diff_y =vm_modelines[i]->vdisplay - height/zoom_divider ; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
i=bestmatch; |
| 1170 |
if (i != 0 && i != vm_count) { |
| 1171 |
set_vidmode(i); |
| 1172 |
vm_switched = 1; |
| 1173 |
vp_width = vm_modelines[i]->hdisplay; |
| 1174 |
vp_height = vm_modelines[i]->vdisplay; |
| 1175 |
} else { |
| 1176 |
vm_switched = 0; |
| 1177 |
vp_width = vm_modelines[0]->hdisplay; |
| 1178 |
vp_height = vm_modelines[0]->vdisplay; |
| 1179 |
} |
| 1180 |
// XWarpPointer(dpy, None, RootWindow(dpy, DefaultScreen(dpy)), |
| 1181 |
// 0, 0, 0, 0, 0,0); |
| 1182 |
XF86VidModeSetViewPort(dpy,XDefaultScreen(dpy),0,0); |
| 1183 |
if(XF86DGAQueryExtension(dpy, &major, &minor)) |
| 1184 |
{ |
| 1185 |
XF86DGAQueryDirectVideo(dpy, XDefaultScreen(dpy), &flags); |
| 1186 |
if(flags & XF86DGADirectPresent) |
| 1187 |
{ |
| 1188 |
have_dga=true; |
| 1189 |
XF86DGAGetVideo(dpy, DefaultScreen(dpy), &base, &ppl, &bank, &ram); |
| 1190 |
if(!base) |
| 1191 |
return -1; |
| 1192 |
|
| 1193 |
// This is quoted from xmms-1.0.1 dga.c |
| 1194 |
// The things we must go through to get a proper depth... |
| 1195 |
// If I find the idiot that thought making 32bit report 24bit |
| 1196 |
// was a good idea, there may be one less `programmer' in this |
| 1197 |
// world... |
| 1198 |
{ |
| 1199 |
XImage *img; |
| 1200 |
|
| 1201 |
img = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), |
| 1202 |
0, 0, 1, 1, AllPlanes, ZPixmap); |
| 1203 |
bit_depth = img->bits_per_pixel; |
| 1204 |
XDestroyImage(img); |
| 1205 |
} |
| 1206 |
byte_depth = (bit_depth+7)/8; |
| 1207 |
// end quote :-) |
| 1208 |
XF86DGAGetViewPortSize(dpy, DefaultScreen(dpy), &vp_width, &vp_height); |
| 1209 |
} |
| 1210 |
|
| 1211 |
} |
| 1212 |
|
| 1213 |
if(have_dga) { |
| 1214 |
|
| 1215 |
|
| 1216 |
// printf("DGA: base:%x , ppl:%d, bank:%d, ram:%d \n",base, ppl, bank, ram ); |
| 1217 |
// flip_offset=ppl*vp_height*byte_depth; |
| 1218 |
|
| 1219 |
vp_flip_offset=vp_height*ppl*byte_depth; |
| 1220 |
XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectGraphics); |
| 1221 |
|
| 1222 |
// XF86DGADirectMouse| |
| 1223 |
// XF86DGADirectKeyb); |
| 1224 |
|
| 1225 |
XF86DGASetViewPort(dpy, DefaultScreen(dpy), 0, 0); |
| 1226 |
|
| 1227 |
// |
| 1228 |
h}%@h}% zero=0; |
| 1229 |
for (int v=0;v<vp_flip_offset*vp_frames; v+=4) |
| 1230 |
memcpy((void*)(base+v), &zero, 4); |
| 1231 |
|
| 1232 |
return 0; |
| 1233 |
}else { |
| 1234 |
// conversionbuf=(char *)malloc(x*y*byte_depth); |
| 1235 |
// if (!conversionbuf) |
| 1236 |
// return -1; |
| 1237 |
} |
| 1238 |
} |
| 1239 |
|
| 1240 |
virtual int Draw(const CImage* data) |
| 1241 |
{ |
| 1242 |
// printf("Drawing %d lines to base %x ppl: %d width: %d \n",height,base,ppl, width); |
| 1243 |
bit_depth++; |
| 1244 |
bit_depth/=8; |
| 1245 |
int bpl=::width*bit_depth; |
| 1246 |
// conversionbuf+=bpl*(height-1); |
| 1247 |
sync(); |
| 1248 |
// for(int y=::height-1; y>0; y--) |
| 1249 |
// { |
| 1250 |
// memcpy(conversionbuf, data, bpl); |
| 1251 |
// data+=bpl; |
| 1252 |
// conversionbuf-=bpl; |
| 1253 |
// } |
| 1254 |
for(int i=0; i<height; i++) |
| 1255 |
memcpy((void*)(base+i*ppl*byte_depth), data->at(i), data->bpl()); |
| 1256 |
|
| 1257 |
return 0; |
| 1258 |
}; |
| 1259 |
virtual int sync() |
| 1260 |
{ |
| 1261 |
Display *dpy = dev->x11Display(); |
| 1262 |
XSync(dpy, false); |
| 1263 |
return 0; |
| 1264 |
}; |
| 1265 |
virtual ~DGARenderer(){ |
| 1266 |
Display *dpy = dev->x11Display(); |
| 1267 |
if (vm_switched) |
| 1268 |
set_vidmode(0); |
| 1269 |
XF86DGASetViewPort(dpy, DefaultScreen(dpy), 0, 0); |
| 1270 |
XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0); |
| 1271 |
// free(conversionbuf); |
| 1272 |
} |
| 1273 |
virtual int drawSubtitles(const char*) |
| 1274 |
{ |
| 1275 |
return 0; |
| 1276 |
} |
| 1277 |
}; |
| 1278 |
|
| 1279 |
VideoRenderer* CreateDGARenderer() |
| 1280 |
{ |
| 1281 |
h}%@h}%@rn new DGARenderer; |
| 1282 |
} |
| 1283 |
*/ |
| 1284 |
#endif /*HAVE_LIBXXF86VM*/ |
| 1285 |
#endif /*HAVE_LIBXXF86DGA*/ |
| 1286 |
#endif /*X_DISPLAY_MISSING*/ |
| 1287 |
/* |
| 1288 |
vim: tabstop=8 |
| 1289 |
*/ |
| 1290 |
|
| 1291 |
#endif // do not compile |