⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 一个GNU的开源软件,基于linux下X-Window的flash播放器,工作稳定,方便移植和修改
💻 C
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////// 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@club-internet.fr>//  #include <stdio.h>#include <string.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.c,v 1.1.1.1 2004/06/04 21:17:08 tgc 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;//a display means a connection to the X ServerGC 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){//the flash is already parsed and stored in the FlashHandle fh    XWindowAttributes wattr;    XPixmapFormatValues *pf;	//XPixmapFormatValues Structure provides an interface to the pixmap format information that is returned	//at the time of a connection setup.	//the content is:	//typedef struct{	//		int depth;	//		int bits_per_pixel;	//		int scanline_pad;	// }XPixmapFormatValues;   this structure descibes the types of Z format images supported by the 	//specified display    Visual *visual;//the Visual structure is the pointer to the screen's associated visual structure/*    int nItems;*/    int n;    struct shmid_ds buf;    int			 	 targetWidth;    int 			 targetHeight;    long			 bpl;	// Bytes per line    long			 bpp;	// Bytes per pixel    long			 pad=0;	// 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;//movie window    // Get Window dimension    XGetWindowAttributes(dpy, target, &wattr);    // Get first visual, don't care about others, really !    visual = wattr.visual;//visual type.......what is it?!!?#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++) {//pf points to an array of the XListPixmapFormatValues structure	//n is the length of this array		if (pf->depth == DefaultDepth(dpy, DefaultScreen(dpy))) {			bpp = pf->bits_per_pixel/8;			pad = pf->scanline_pad/8;		}//find the "pf" whose depth equal to DefaultDepth and set "bpp" and "pad" with the corresponding value of "pf"#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	}//for(pf=XListPixmapFormats(dpy, &n); n--; pf++)	gc = DefaultGC(dpy, DefaultScreen(dpy));//function DefaultSreen(display) return the default screen number of the display	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;	}//set bpl using the value of bpp and pad.......bpl means bytes per line	if (!onRoot) {		XSelectInput(dpy, target, ExposureMask|ButtonReleaseMask|ButtonPressMask|PointerMotionMask);	}//excludes the events it isn't interested in	// Prepare data for Direct Graphics	segInfo.readOnly = False;//readwrite shared ram	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);//attach the shared ram to the connection dpy(typed Display)#ifdef linux	// Warning : this does NOT work properly on Solaris	// Special Linux shm behaviour is used here	// 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");	}#endif	XSync(dpy, False);	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)//combine the buffer canvas to the window target{    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 */intreadFile(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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -