dslinux/user/pixil/packages/flash/flash/Player Makefile main_nx.c main_x11.c stub.cc vroot.h
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:26:13 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/packages/flash/flash/Player
In directory antilope:/tmp/cvs-serv11916/packages/flash/flash/Player
Added Files:
Makefile main_nx.c main_x11.c stub.cc vroot.h
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: main_nx.c ---
/*///////////////////////////////////////////////////////////
// Flash Plugin and Player
// Copyright (C) 1998 Olivier Debon
//
// Ported to Nano-X by Greg Haerr <greg at censoft.com>
// Copyright (c) 2002, 2003 by Greg Haerr
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////
// Author : Olivier Debon <odebon at club-internet.fr>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
//#include <sys/ipc.h>
//#include <sys/shm.h>
#include "flash.h"
#define MWINCLUDECOLORS
#include <nano-X.h>
extern int nxSocket;
static char *rcsid = "$Id: main_nx.c,v 1.1 2006-10-03 11:26:10 dslinux_amadeus Exp $";
typedef struct {
FlashDisplay fd;
GR_WINDOW_ID target; /* Target window*/
GR_GC_ID gc; /* NX Graphic context*/
int pixtype;
long xOffset, yOffset;
} NXContext;
NXContext xc1, *xc=&xc1;
GR_GC_ID gc;
GR_WINDOW_ID frame,movie,control;
struct FlashInfo fi;
char *filename;
/* memory function for the plugin */
void *flash_malloc(unsigned long size)
{
return malloc(size);
}
void flash_free(void *p)
{
free(p);
}
void *flash_realloc(void *p, unsigned long size)
{
return realloc(p, size);
}
#define FLASH_NXEVENT_MASK (GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_BUTTON_DOWN|GR_EVENT_MASK_BUTTON_UP|GR_EVENT_MASK_MOUSE_POSITION|GR_EVENT_MASK_KEY_DOWN)
long FlashExecNX(FlashHandle fh, long flag, GR_EVENT *event, struct timeval *wakeDate)
{
FlashEvent fe;
if (flag & FLASH_EVENT) {
/* NX to Flash event structure conversion*/
switch (event->type) {
case GR_EVENT_TYPE_BUTTON_DOWN:
fe.type = FeButtonPress;
break;
case GR_EVENT_TYPE_BUTTON_UP:
fe.type = FeButtonRelease;
break;
case GR_EVENT_TYPE_MOUSE_POSITION:
fe.type = FeMouseMove;
fe.x = event->mouse.x;
fe.y = event->mouse.y;
break;
case GR_EVENT_TYPE_EXPOSURE:
fe.type = FeRefresh;
break;
default:
fe.type = FeNone;
break;
}
}
return FlashExec(fh,flag,&fe,wakeDate);
}
long FlashGraphicInitNX(FlashHandle fh, GR_WINDOW_ID w, int onRoot)
{
GR_WINDOW_INFO wattr;
GR_SCREEN_INFO sinfo;
int nItems;
int n;
int targetWidth;
int targetHeight;
long bpl; /* Bytes per line*/
long bpp; /* Bytes per pixel*/
long pad; /* Scanline pad in byte*/
/* Platform dependent members*/
GR_WINDOW_ID target; /* Target window*/
GR_GC_ID gc; /* NX Graphic context*/
//GR_WINDOW_ID canvas; /* Graphic buffer
//struct shmid_ds buf;
//Cursor buttonCursor; /* Window cursor (a hand if over a button)*/
//XShmSegmentInfo segInfo; /* Shared memory information*/
target = w;
/* Get Window dimension*/
GrGetWindowInfo(target, &wattr);
/* Get screen info*/
GrGetScreenInfo(&sinfo);
bpp = sinfo.bpp/8; /* bytes per pixel*/
/* no padding for GrArea (=1)*/
pad = 1; /* # bytes pad*/
gc = GrNewGC();
if (onRoot) {
targetWidth = fi.frameWidth/20;
targetHeight = fi.frameHeight/20;
xc->xOffset = (wattr.width-targetWidth)/2;
xc->yOffset = (wattr.height-targetHeight)/2;
} else {
targetWidth = wattr.width;
targetHeight = wattr.height;
xc->xOffset = 0;
xc->yOffset = 0;
}
if (bpp) {
bpl = (targetWidth*bpp + pad-1)/pad*pad;
} else {
bpl = (targetWidth/8 + pad-1)/pad*pad;
}
if (!onRoot) {
GrSelectEvents(target, FLASH_NXEVENT_MASK);
}
#if 0
/* Prepare data for Direct Graphics*/
segInfo.readOnly = False;
segInfo.shmid = shmget (IPC_PRIVATE,targetHeight*bpl,IPC_CREAT|0777);
if (segInfo.shmid <0) {
perror("shmget");
fprintf(stderr,"Size = %d x %d\n", targetWidth, targetHeight);
}
segInfo.shmaddr = (char*)shmat (segInfo.shmid, 0, 0);
if ((long)segInfo.shmaddr == -1) {
perror("shmat");
}
XShmAttach(dpy, &segInfo);
/* When number of attached clients falls down to zero */
/* the shm is removed. This is convenient when it crashes. */
if (shmctl(segInfo.shmid, IPC_RMID, &buf) < 0) {
perror("shmctl");
}
//canvas = XShmCreatePixmap(dpy,target,segInfo.shmaddr,&segInfo,targetWidth,targetHeight,DefaultDepth(dpy, DefaultScreen(dpy)));
//buttonCursor = XCreateFontCursor(dpy, XC_hand2);
#endif
xc->fd.pixels = (char*)malloc(targetHeight*bpl);
xc->fd.width = targetWidth;
xc->fd.height = targetHeight;
xc->fd.bpl = bpl;
xc->fd.depth = sinfo.bpp;
xc->fd.bpp = bpp;
xc->target = target;
xc->gc = gc;
xc->pixtype = sinfo.pixtype;
GrFlush();
return FlashGraphicInit(fh, &xc->fd);
}
void FlashCopyNX(int all)
{
//GrSetMode(xc->gc, GR_MODE_COPY);
//if (all) {
GrArea(xc->target, xc->gc,
xc->xOffset, xc->yOffset, xc->fd.width, xc->fd.height,
xc->fd.pixels, xc->pixtype);
//XCopyArea(xc->dpy,xc->canvas,xc->target,xc->gc,
//0,0,
//xc->fd.width,xc->fd.height,
//xc->xOffset, xc->yOffset
//);
//} else {
//XCopyArea(xc->dpy,xc->canvas,xc->target,xc->gc,
//xc->fd.clip_x,xc->fd.clip_y,
//xc->fd.clip_width,xc->fd.clip_height,
//xc->fd.clip_x + xc->xOffset, xc->fd.clip_y + xc->yOffset
//);
//}
GrFlush();
}
/*
* This file is the entry of a very simple Flash Player
*/
int
readFile(char *filename, char **buffer, long *size)
{
FILE *in;
char *buf;
long length;
in = fopen(filename,"r");
if (in == 0) {
perror(filename);
return -1;
}
fseek(in,0,SEEK_END);
length = ftell(in);
rewind(in);
buf = malloc(length);
fread(buf,length,1,in);
fclose(in);
*size = length;
*buffer = buf;
return length;
}
void drawInfo()
{
char msg[256];
sprintf(msg,"%s (Flash %d) - Frames = %d - Rate = %d fps",
filename,fi.version,fi.frameCount,fi.frameRate);
GrSetGCForeground(gc, WHITE);
GrText(control,gc,10,15,msg, strlen(msg), GR_TFASCII|GR_TFBASELINE);
sprintf(msg, " (Q)uit (R)eplay (P)ause (C)ontinue (+) ZoomIn (-) ZoomOut");
GrText(control,gc,10,35,msg, strlen(msg), GR_TFASCII|GR_TFBASELINE);
GrFlush();
}
void playMovie(FlashHandle flashHandle, GR_WINDOW_ID movie, int onRoot)
{
struct timeval wd,de,now;
GR_EVENT event;
long evMask, cmd;
fd_set fdset;
int status;
long delay = 0;
long wakeUp;
long z = 1;
long x = 0;
long y = 0;
FlashEvent fe;
cmd = FLASH_WAKEUP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
if (!onRoot) {
GrSelectEvents(movie, FLASH_NXEVENT_MASK);
}
while(1) {
FD_ZERO(&fdset);
FD_SET(nxSocket,&fdset);
if (GrPeekEvent(&event))
goto have_event;
/*printf("WakeUp = %d Delay = %d\n", wakeUp, delay);*/
if (delay < 0) {
delay = 20;
}
if (xc->fd.flash_refresh) {
FlashCopyNX(0);
xc->fd.flash_refresh = 0;
}
if (wakeUp) {
de.tv_sec = delay/1000;
de.tv_usec = (delay%1000)*1000;
status = select(nxSocket+1, &fdset, 0, 0, &de);
} else {
de.tv_sec = 0;
de.tv_usec = 0;
status = select(nxSocket+1, &fdset, 0, 0, &de);
}
if (status == 0) {
cmd = FLASH_WAKEUP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
} else {
have_event:
GrGetNextEvent(&event);
if (event.type == GR_EVENT_TYPE_CLOSE_REQ) {
GrClose();
exit(0);
}
if (event.exposure.wid == movie) {
switch (event.type) {
case GR_EVENT_TYPE_KEY_DOWN:
fe.type = FeKeyPress;
fe.key = 0;
switch (event.keystroke.ch) {
case MWKEY_UP:
fe.key = FeKeyUp;
break;
case MWKEY_DOWN:
fe.key = FeKeyDown;
break;
case MWKEY_LEFT:
fe.key = FeKeyLeft;
break;
case MWKEY_RIGHT:
fe.key = FeKeyRight;
break;
case MWKEY_ENTER:
fe.key = FeKeyEnter;
break;
case MWKEY_TAB:
fe.key = FeKeyNext;
break;
}
if (fe.key != 0) {
cmd = FLASH_EVENT;
if (FlashExec(flashHandle, cmd, &fe, &wd)) {
wakeUp = 1;
}
} else {
switch (event.keystroke.ch) {
#if 1
case MWKEY_UP:
y -= 10;
FlashOffset(flashHandle,x,y);
break;
case MWKEY_DOWN:
y += 10;
FlashOffset(flashHandle,x,y);
break;
case MWKEY_LEFT:
x -= 10;
FlashOffset(flashHandle,x,y);
break;
case MWKEY_RIGHT:
x += 10;
FlashOffset(flashHandle,x,y);
break;
#endif
case MWKEY_KP_PLUS:
case '+':
case '=':
FlashZoom(flashHandle,++z);
break;
case MWKEY_KP_MINUS:
case '-':
FlashZoom(flashHandle,--z);
break;
case 'q':
return;
break;
case 'c':
cmd = FLASH_CONT;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
case 'p':
cmd = FLASH_STOP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
case 'r':
cmd = FLASH_REWIND;
FlashExec(flashHandle, cmd, 0, &wd);
cmd = FLASH_CONT;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
}
}
break;
case GR_EVENT_TYPE_EXPOSURE:
FlashCopyNX(1);
break;
default:
cmd = FLASH_EVENT;
if (FlashExecNX(flashHandle, cmd, &event, &wd)) {
wakeUp = 1;
}
break;
}
}
if (!onRoot && event.exposure.wid == control) {
if (event.type == GR_EVENT_TYPE_EXPOSURE) {
drawInfo();
}
}
}
/* Recompute delay */
gettimeofday(&now,0);
delay = (wd.tv_sec-now.tv_sec)*1000 + (wd.tv_usec-now.tv_usec)/1000;
}
}
void
showUrl(char *url, char *target, void *client_data)
{
printf("GetURL : %s\n", url);
}
void
getSwf(char *url, int level, void *client_data)
{
FlashHandle flashHandle;
char *buffer;
long size;
flashHandle = (FlashHandle) client_data;
printf("LoadMovie: %s @ %d\n", url, level);
if (readFile(url, &buffer, &size) > 0) {
FlashParse(flashHandle, level, buffer, size);
}
}
main(int argc, char **argv)
{
char *buffer;
long size;
char *audiodev;
FlashHandle flashHandle;
int status;
int onRoot = 0;
if (argc < 2) {
fprintf(stderr,"Usage : %s [ -root ] <file.swf>\n", argv[0]);
exit(1);
}
if (argc == 3) {
if (!strcmp(argv[1],"-root") || !strcmp(argv[1],"-inroot")) {
onRoot = 1;
}
argc--;
argv++;
}
if (GrOpen() < 0) {
fprintf(stderr,"Can't open graphics\n");
exit(1);
}
gc = GrNewGC();
GrSetGCUseBackground(gc, GR_FALSE);
filename = argv[1];
if (readFile(filename, &buffer, &size) < 0) {
exit(2);
}
flashHandle = FlashNew();
if (flashHandle == 0) {
exit(1);
}
/* Load level 0 movie*/
do {
status = FlashParse(flashHandle, 0, buffer, size);
} while (status & FLASH_PARSE_NEED_DATA);
if (status == FLASH_PARSE_ERROR) {
fprintf(stderr, "Error - Unable to parse the flash file\n");
exit(-1);
}
free(buffer);
FlashGetInfo(flashHandle, &fi);
if (onRoot == 0) {
frame = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "Microwindows Flash Player",
GR_ROOT_WINDOW_ID,
0, 0, fi.frameWidth/20, fi.frameHeight/20+40,
BLACK);
GrSelectEvents(frame, GR_EVENT_MASK_CLOSE_REQ);
GrMapWindow(frame);
movie = GrNewWindow(frame,
0, 0, fi.frameWidth/20,fi.frameHeight/20,
0, BLACK, BLACK);
GrMapWindow(movie);
control = GrNewWindow(frame,
0, fi.frameHeight/20, fi.frameWidth/20, 40,
0, GREEN, BLACK);
GrMapWindow(control);
GrSelectEvents(control, GR_EVENT_MASK_EXPOSURE);
drawInfo();
} else {
movie = GR_ROOT_WINDOW_ID;
control = GR_ROOT_WINDOW_ID;
/* Auto loop when onRoot*/
FlashSettings(flashHandle, PLAYER_LOOP);
}
GrFlush();
FlashGraphicInitNX(flashHandle, movie, onRoot);
audiodev = getenv("AUDIODEV");
if (audiodev == NULL) {
#if SUN_SOUND
audiodev = "/dev/audio";
#else
audiodev = "/dev/dsp";
#endif
}
FlashSoundInit(flashHandle, audiodev);
FlashSetGetUrlMethod(flashHandle, showUrl, 0);
FlashSetGetSwfMethod(flashHandle, getSwf, (void*)flashHandle);
playMovie(flashHandle, movie, onRoot);
FlashClose(flashHandle);
exit(0);
}
--- NEW FILE: stub.cc ---
#include <stdlib.h>
#include <stddef.h>
#include <new>
const nothrow_t nothrow = {};
void * operator new(size_t size, const nothrow_t&)
{
return malloc(size);
}
void operator delete(void *p)
{
return free(p);
}
--- NEW FILE: Makefile ---
FLASH=../Lib
CPPFLAGS=-I$(FLASH) -I$(GUIINC)
CFLAGS=$(OPTIMIZE) $(CPPFLAGS) $(ALLCFLAGS)
LIBS = $(FLASH)/libflash.a $(Z_LIB) $(JPEG_LIB) $(GUILIBS) -lm
LDFLAGS=
swfplayer: $(GUIAPP) $(FLASH)/libflash.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(GUIAPP) $(LIBS)
cp ./swfplayer ../nxflashplay
clean:
rm -f *~ *.o swfplayer core gmon.out ../nxflashplay
--- NEW FILE: main_x11.c ---
/*////////////////////////////////////////////////////////////
// Flash Plugin and Player
// Copyright (C) 1998 Olivier Debon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
///////////////////////////////////////////////////////////////
// Author : Olivier Debon <odebon at club-internet.fr>
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include "flash.h"
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/cursorfont.h>
#include <X11/Xutil.h>
#include <X11/extensions/XShm.h>
#include "vroot.h"
static char *rcsid = "$Id: main_x11.c,v 1.1 2006-10-03 11:26:10 dslinux_amadeus Exp $";
typedef struct {
FlashDisplay fd;
Display *dpy; /* X11 Display */
Window target; /* Target window */
GC gc; /* X11 Graphic context */
Pixmap canvas; /* Graphic buffer */
long xOffset, yOffset;
} X11Context;
X11Context xc1, *xc=&xc1;
int shape_size,shape_nb,shaperecord_size,shaperecord_nb,style_size,style_nb;
Display *dpy;
GC gc;
Window frame,movie,control;
struct FlashInfo fi;
char *filename;
/* memory function for the plugin */
void *flash_malloc(unsigned long size)
{
return malloc(size);
}
void flash_free(void *p)
{
free(p);
}
void *flash_realloc(void *p, unsigned long size)
{
return realloc(p, size);
}
#define FLASH_XEVENT_MASK (ExposureMask|ButtonReleaseMask|ButtonPressMask|PointerMotionMask)
long FlashExecX11(FlashHandle fh, long flag, XEvent *event, struct timeval *wakeDate)
{
FlashEvent fe;
if (flag & FLASH_EVENT) {
/* X to Flash event structure conversion */
switch (event->type) {
case ButtonPress:
fe.type = FeButtonPress;
break;
case ButtonRelease:
fe.type = FeButtonRelease;
break;
case MotionNotify:
fe.type = FeMouseMove;
fe.x = event->xmotion.x;
fe.y = event->xmotion.y;
break;
case Expose:
fe.type = FeRefresh;
break;
default:
fe.type = FeNone;
break;
}
}
return FlashExec(fh,flag,&fe,wakeDate);
}
long FlashGraphicInitX11(FlashHandle fh, Display *d, Window w, int onRoot)
{
XWindowAttributes wattr;
XPixmapFormatValues *pf;
Visual *visual;
int nItems;
int n;
struct shmid_ds buf;
int targetWidth;
int targetHeight;
long bpl; /* Bytes per line */
long bpp; /* Bytes per pixel */
long pad; /* Scanline pad in byte */
/* Platform dependent members */
Window target; /* Target window */
Cursor buttonCursor; /* Window cursor (a hand if over a button) */
Display *dpy; /* X11 Display */
GC gc; /* X11 Graphic context */
Pixmap canvas; /* Graphic buffer */
XShmSegmentInfo segInfo; /* Shared memory information */
dpy = d;
target = w;
/* Get Window dimension */
XGetWindowAttributes(dpy, target, &wattr);
/* Get first visual, don't care about others, really ! */
visual = wattr.visual;
#define PRINT 0
#if PRINT
fprintf(stderr,"Id: %x\n", target);
fprintf(stderr,"VisualId: %x\n", visual->visualid);
fprintf(stderr,"BitmapPad = %d\n", BitmapPad(dpy));
fprintf(stderr,"BitmapUnit = %d\n", BitmapUnit(dpy));
fprintf(stderr,"Depth = %d\n", DefaultDepth(dpy,DefaultScreen(dpy)));
fprintf(stderr,"RedMask = %x\n", visual->red_mask);
fprintf(stderr,"GreenMask = %x\n", visual->green_mask);
fprintf(stderr,"BlueMask = %x\n", visual->blue_mask);
fprintf(stderr,"Bits/RGB = %d\n", visual->bits_per_rgb);
#endif
bpp = 0;
/* Get screen info */
for(pf=XListPixmapFormats(dpy, &n); n--; pf++) {
if (pf->depth == DefaultDepth(dpy, DefaultScreen(dpy))) {
bpp = pf->bits_per_pixel/8;
pad = pf->scanline_pad/8;
}
#if PRINT
fprintf(stderr,"----------------\n");
fprintf(stderr,"Depth = %d\n", pf->depth);
fprintf(stderr,"Bits Per Pixel = %d\n", pf->bits_per_pixel);
fprintf(stderr,"Scanline Pad = %d\n", pf->scanline_pad);
#endif
}
gc = DefaultGC(dpy, DefaultScreen(dpy));
if (onRoot) {
targetWidth = fi.frameWidth/20;
targetHeight = fi.frameHeight/20;
xc->xOffset = (wattr.width-targetWidth)/2;
xc->yOffset = (wattr.height-targetHeight)/2;
} else {
targetWidth = wattr.width;
targetHeight = wattr.height;
xc->xOffset = 0;
xc->yOffset = 0;
}
#if PRINT
fprintf(stderr,"Target Width = %d\n", wattr.width);
fprintf(stderr,"Target Height = %d\n", wattr.height);
#endif
if (bpp) {
bpl = (targetWidth*bpp + pad-1)/pad*pad;
} else {
bpl = (targetWidth/8 + pad-1)/pad*pad;
}
if (!onRoot) {
XSelectInput(dpy, target, ExposureMask|ButtonReleaseMask|ButtonPressMask|PointerMotionMask);
}
/* Prepare data for Direct Graphics */
segInfo.readOnly = False;
segInfo.shmid = shmget (IPC_PRIVATE,targetHeight*bpl,IPC_CREAT|0777);
if (segInfo.shmid <0) {
perror("shmget");
fprintf(stderr,"Size = %d x %d\n", targetWidth, targetHeight);
}
segInfo.shmaddr = (char*)shmat (segInfo.shmid, 0, 0);
if ((long)segInfo.shmaddr == -1) {
perror("shmat");
}
XShmAttach(dpy, &segInfo);
XSync(dpy, False);
/* When number of attached clients falls down to zero */
/* the shm is removed. This is convenient when it crashes. */
if (shmctl(segInfo.shmid, IPC_RMID, &buf) < 0) {
perror("shmctl");
}
xc->fd.pixels = (char*)segInfo.shmaddr;
xc->fd.width = targetWidth;
xc->fd.height = targetHeight;
xc->fd.bpl = bpl;
xc->fd.depth = DefaultDepth(dpy, DefaultScreen(dpy));
xc->fd.bpp = bpp;
canvas = XShmCreatePixmap(dpy,target,segInfo.shmaddr,&segInfo,targetWidth,targetHeight,DefaultDepth(dpy, DefaultScreen(dpy)));
XSync(dpy, False);
buttonCursor = XCreateFontCursor(dpy, XC_hand2);
XFlush(dpy);
xc->dpy = dpy;
xc->target = target;
xc->canvas = canvas;
xc->gc = gc;
return FlashGraphicInit(fh, &xc->fd);
}
void FlashCopyX11(int all)
{
XSetFunction(xc->dpy,xc->gc,GXcopy);
if (all) {
XCopyArea(xc->dpy,xc->canvas,xc->target,xc->gc,
0,0,
xc->fd.width,xc->fd.height,
xc->xOffset, xc->yOffset
);
} else {
XCopyArea(xc->dpy,xc->canvas,xc->target,xc->gc,
xc->fd.clip_x,xc->fd.clip_y,
xc->fd.clip_width,xc->fd.clip_height,
xc->fd.clip_x + xc->xOffset, xc->fd.clip_y + xc->yOffset
);
}
XFlush(xc->dpy);
}
/*
* This file is the entry of a very simple Flash Player
*/
int
readFile(char *filename, char **buffer, long *size)
{
FILE *in;
char *buf;
long length;
in = fopen(filename,"r");
if (in == 0) {
perror(filename);
return -1;
}
fseek(in,0,SEEK_END);
length = ftell(in);
rewind(in);
buf = malloc(length);
fread(buf,length,1,in);
fclose(in);
*size = length;
*buffer = buf;
return length;
}
void drawInfo()
{
char msg[1024];
sprintf(msg,"%s (Flash %d) - Frames = %d - Rate = %d fps",
filename,fi.version,fi.frameCount,fi.frameRate);
XSetForeground(dpy,gc,WhitePixel(dpy, DefaultScreen(dpy)));
XDrawString(dpy,control,gc,10,15,msg, strlen(msg));
sprintf(msg, " (Q)uit (R)eplay (P)ause (C)ontinue");
XDrawString(dpy,control,gc,10,35,msg, strlen(msg));
XFlush(dpy);
}
void playMovie(FlashHandle flashHandle, Display *dpy, Window movie, int onRoot)
{
struct timeval wd,de,now;
XEvent event;
long evMask, cmd;
fd_set fdset;
int status;
long delay = 0;
long wakeUp;
long z = 1;
long x = 0;
long y = 0;
FlashEvent fe;
cmd = FLASH_WAKEUP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
if (!onRoot) {
XSelectInput(dpy, movie, FLASH_XEVENT_MASK|KeyPressMask);
}
XSync(dpy,False);
while(1) {
FD_ZERO(&fdset);
FD_SET(ConnectionNumber(dpy),&fdset);
/*printf("WakeUp = %d Delay = %d\n", wakeUp, delay); */
if (delay < 0) {
delay = 20;
}
if (xc->fd.flash_refresh) {
FlashCopyX11(0);
xc->fd.flash_refresh = 0;
}
if (wakeUp) {
de.tv_sec = delay/1000;
de.tv_usec = (delay%1000)*1000;
status = select(ConnectionNumber(dpy)+1, &fdset, 0, 0, &de);
} else {
status = select(ConnectionNumber(dpy)+1, &fdset, 0, 0, 0);
}
if (status == 0) {
cmd = FLASH_WAKEUP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
} else {
XNextEvent(dpy, &event);
/*printf("Event %d (%d)\n",event.type,event.xany.serial); */
if (event.xany.window == movie) {
int keycode;
KeySym keysym;
switch (event.type) {
case KeyPress:
keycode = event.xkey.keycode;
keysym = XLookupKeysym((XKeyEvent*)&event, 0);
fe.type = FeKeyPress;
fe.key = 0;
switch (keysym) {
case XK_Up:
fe.key = FeKeyUp;
break;
case XK_Down:
fe.key = FeKeyDown;
break;
case XK_Left:
fe.key = FeKeyLeft;
break;
case XK_Right:
fe.key = FeKeyRight;
break;
case XK_Return:
fe.key = FeKeyEnter;
break;
case XK_Tab:
fe.key = FeKeyNext;
break;
}
if (fe.key != 0) {
cmd = FLASH_EVENT;
if (FlashExec(flashHandle, cmd, &fe, &wd)) {
wakeUp = 1;
}
} else {
switch (keysym) {
#if 0
case XK_Up:
y -= 10;
FlashOffset(flashHandle,x,y);
break;
case XK_Down:
y += 10;
FlashOffset(flashHandle,x,y);
break;
case XK_Left:
x -= 10;
FlashOffset(flashHandle,x,y);
break;
case XK_Right:
x += 10;
FlashOffset(flashHandle,x,y);
break;
#endif
case XK_KP_Add:
FlashZoom(flashHandle,++z);
break;
case XK_KP_Subtract:
FlashZoom(flashHandle,--z);
break;
case XK_q:
return;
break;
case XK_c:
cmd = FLASH_CONT;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
case XK_p:
cmd = FLASH_STOP;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
case XK_r:
cmd = FLASH_REWIND;
FlashExec(flashHandle, cmd, 0, &wd);
cmd = FLASH_CONT;
wakeUp = FlashExec(flashHandle, cmd, 0, &wd);
break;
}
}
break;
case Expose:
FlashCopyX11(1);
break;
case NoExpose:
break;
default:
cmd = FLASH_EVENT;
if (FlashExecX11(flashHandle, cmd, &event, &wd)) {
wakeUp = 1;
}
break;
}
}
if (!onRoot && event.xany.window == control) {
if (event.type == Expose) {
drawInfo();
}
}
}
/* Recompute delay */
gettimeofday(&now,0);
delay = (wd.tv_sec-now.tv_sec)*1000 + (wd.tv_usec-now.tv_usec)/1000;
}
}
void
showUrl(char *url, char *target, void *client_data)
{
printf("GetURL : %s\n", url);
}
void
getSwf(char *url, int level, void *client_data)
{
FlashHandle flashHandle;
char *buffer;
long size;
flashHandle = (FlashHandle) client_data;
printf("LoadMovie: %s @ %d\n", url, level);
if (readFile(url, &buffer, &size) > 0) {
FlashParse(flashHandle, level, buffer, size);
}
}
main(int argc, char **argv)
{
char *buffer;
long size;
char *audiodev;
FlashHandle flashHandle;
int status;
int onRoot = 0;
Screen *screen;
if (argc < 2) {
fprintf(stderr,"Usage : %s [ -root ] <file.swf>\n", argv[0]);
exit(1);
}
if (argc == 3) {
if (!strcmp(argv[1],"-root") || !strcmp(argv[1],"-inroot")) {
onRoot = 1;
}
argc--;
argv++;
}
dpy = XOpenDisplay(getenv("DISPLAY"));
if (dpy == 0) {
fprintf(stderr,"Can't open X display\n");
exit(1);
}
screen = DefaultScreenOfDisplay(dpy);
gc = DefaultGC(dpy, DefaultScreen(dpy));
filename = argv[1];
if (readFile(filename, &buffer, &size) < 0) {
exit(2);
}
flashHandle = FlashNew();
if (flashHandle == 0) {
exit(1);
}
/* Load level 0 movie */
do {
status = FlashParse(flashHandle, 0, buffer, size);
} while (status & FLASH_PARSE_NEED_DATA);
free(buffer);
FlashGetInfo(flashHandle, &fi);
if (onRoot == 0) {
frame = XCreateSimpleWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)),
0, 0,
fi.frameWidth/20, fi.frameHeight/20+40,
0, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy))
);
XMapWindow(dpy, frame);
movie = XCreateSimpleWindow(dpy, frame, 0, 0, fi.frameWidth/20,fi.frameHeight/20,
0, WhitePixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy))
);
XMapWindow(dpy, movie);
control = XCreateSimpleWindow(dpy, frame, 0, fi.frameHeight/20, fi.frameWidth/20,40,
0, BlackPixel(dpy, DefaultScreen(dpy)), BlackPixel(dpy, DefaultScreen(dpy))
);
XMapWindow(dpy, control);
XSelectInput(dpy, control, ExposureMask);
drawInfo();
} else {
movie = VirtualRootWindowOfScreen(screen);
/* Auto loop when onRoot */
FlashSettings(flashHandle, PLAYER_LOOP);
}
XFlush(dpy);
FlashGraphicInitX11(flashHandle, dpy, movie, onRoot);
audiodev = getenv("AUDIODEV");
if (audiodev == NULL) {
#if SUN_SOUND
audiodev = "/dev/audio";
#else
audiodev = "/dev/dsp";
#endif
}
FlashSoundInit(flashHandle, audiodev);
FlashSetGetUrlMethod(flashHandle, showUrl, 0);
FlashSetGetSwfMethod(flashHandle, getSwf, (void*)flashHandle);
playMovie(flashHandle, dpy, movie, onRoot);
FlashClose(flashHandle);
exit(0);
}
--- NEW FILE: vroot.h ---
/*****************************************************************************/
/** Copyright 1991 by Andreas Stolcke **/
/** Copyright 1990 by Solbourne Computer Inc. **/
/** Longmont, Colorado **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** name of Solbourne not be used in advertising **/
/** in publicity pertaining to distribution of the software without **/
/** specific, written prior permission. **/
/** **/
/** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
/** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/
/** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/
/** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/
/** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
/** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
/** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
/** OR PERFORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/*
* vroot.h -- Virtual Root Window handling header file
*
* This header file redefines the X11 macros RootWindow and DefaultRootWindow,
* making them look for a virtual root window as provided by certain `virtual'
* window managers like swm and tvtwm. If none is found, the ordinary root
* window is returned, thus retaining backward compatibility with standard
* window managers.
* The function implementing the virtual root lookup remembers the result of
* its last invocation to avoid overhead in the case of repeated calls
* on the same display and screen arguments.
* The lookup code itself is taken from Tom LaStrange's ssetroot program.
*
* Most simple root window changing X programs can be converted to using
* virtual roots by just including
*
* #include <X11/vroot.h>
*
* after all the X11 header files. It has been tested on such popular
* X clients as xphoon, xfroot, xloadimage, and xaqua.
* It also works with the core clients xprop, xwininfo, xwd, and editres
* (and is necessary to get those clients working under tvtwm).
* It does NOT work with xsetroot; get the xsetroot replacement included in
* the tvtwm distribution instead.
*
* Andreas Stolcke <stolcke at ICSI.Berkeley.EDU>, 9/7/90
* - replaced all NULL's with properly cast 0's, 5/6/91
* - free children list (suggested by Mark Martin <mmm at cetia.fr>), 5/16/91
* - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
*/
#ifndef _VROOT_H_
#define _VROOT_H_
#if !defined(lint) && !defined(SABER)
static const char vroot_rcsid[] = "#Id: vroot.h,v 1.4 1991/09/30 19:23:16 stolcke Exp stolcke #";
#endif
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
static Window
#ifdef __STDC__ /* ANSIfication added by jwz, to avoid superfluous warnings. */
VirtualRootWindowOfScreen(Screen *screen)
#else /* !__STDC__ */
VirtualRootWindowOfScreen(screen) Screen *screen;
#endif /* !__STDC__ */
{
static Screen *save_screen = (Screen *)0;
static Window root = (Window)0;
if (screen != save_screen) {
Display *dpy = DisplayOfScreen(screen);
Atom __SWM_VROOT = None;
int i;
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
root = RootWindowOfScreen(screen);
/* go look for a virtual root */
__SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
&children, &numChildren)) {
for (i = 0; i < numChildren; i++) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
Window *newRoot = (Window *)0;
if (XGetWindowProperty(dpy, children[i],
__SWM_VROOT, 0, 1, False, XA_WINDOW,
&actual_type, &actual_format,
&nitems, &bytesafter,
(unsigned char **) &newRoot) == Success
&& newRoot) {
root = *newRoot;
break;
}
}
if (children)
XFree((char *)children);
}
save_screen = screen;
}
return root;
}
#endif
More information about the dslinux-commit
mailing list