📄 xv.c
字号:
/***********************************************************
Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts,
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
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 permission notice appear in
supporting documentation, and that the names of Digital or MIT not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL 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.
******************************************************************/
/* $XFree86: xc/lib/Xv/Xv.c,v 1.15 2001/05/11 08:23:22 alanh Exp $ */
/*
** File:
**
** Xv.c --- Xv library extension module.
**
** Author:
**
** David Carver (Digital Workstation Engineering/Project Athena)
**
** Revisions:
**
** 26.06.91 Carver
** - changed XvFreeAdaptors to XvFreeAdaptorInfo
** - changed XvFreeEncodings to XvFreeEncodingInfo
**
** 11.06.91 Carver
** - changed SetPortControl to SetPortAttribute
** - changed GetPortControl to GetPortAttribute
** - changed QueryBestSize
**
** 15.05.91 Carver
** - version 2.0 upgrade
**
** 240.01.91 Carver
** - version 1.4 upgrade
**
*/
#include <stdio.h>
#include "Xvlibint.h"
#include <X11/extensions/Xext.h>
#include <X11/extensions/XShm.h>
#include "extutil.h"
static XExtensionInfo _xv_info_data;
static XExtensionInfo *xv_info = &_xv_info_data;
static char *xv_extension_name = XvName;
#define XvCheckExtension(dpy, i, val) \
XextCheckExtension(dpy, i, xv_extension_name, val)
static char *xv_error_string();
static int xv_close_display();
static Bool xv_wire_to_event();
static XExtensionHooks xv_extension_hooks = {
NULL, /* create_gc */
NULL, /* copy_gc */
NULL, /* flush_gc */
NULL, /* free_gc */
NULL, /* create_font */
NULL, /* free_font */
xv_close_display, /* close_display */
xv_wire_to_event, /* wire_to_event */
NULL, /* event_to_wire */
NULL, /* error */
xv_error_string /* error_string */
};
static char *xv_error_list[] =
{
"BadPort", /* XvBadPort */
"BadEncoding", /* XvBadEncoding */
"BadControl" /* XvBadControl */
};
static XEXT_GENERATE_CLOSE_DISPLAY (xv_close_display, xv_info)
static XEXT_GENERATE_FIND_DISPLAY (xv_find_display, xv_info,
xv_extension_name,
&xv_extension_hooks,
XvNumEvents, NULL)
static XEXT_GENERATE_ERROR_STRING (xv_error_string, xv_extension_name,
XvNumErrors, xv_error_list)
int
SDL_NAME(XvQueryExtension)(
Display *dpy,
unsigned int *p_version,
unsigned int *p_revision,
unsigned int *p_requestBase,
unsigned int *p_eventBase,
unsigned int *p_errorBase
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvQueryExtensionReq *req;
xvQueryExtensionReply rep;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
XvGetReq(QueryExtension, req);
if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return XvBadExtension;
}
*p_version = rep.version;
*p_revision = rep.revision;
*p_requestBase = info->codes->major_opcode;
*p_eventBase = info->codes->first_event;
*p_errorBase = info->codes->first_error;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
int
SDL_NAME(XvQueryAdaptors)(
Display *dpy,
Window window,
unsigned int *p_nAdaptors,
SDL_NAME(XvAdaptorInfo) **p_pAdaptors
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvQueryAdaptorsReq *req;
xvQueryAdaptorsReply rep;
int size,ii,jj;
char *name;
SDL_NAME(XvAdaptorInfo) *pas, *pa;
SDL_NAME(XvFormat) *pfs, *pf;
char *buffer;
union
{
char *buffer;
char *string;
xvAdaptorInfo *pa;
xvFormat *pf;
} u;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
XvGetReq(QueryAdaptors, req);
req->window = window;
/* READ THE REPLY */
if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
}
size = rep.length << 2;
if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
_XRead (dpy, buffer, size);
u.buffer = buffer;
/* GET INPUT ADAPTORS */
if (rep.num_adaptors == 0) {
pas = NULL;
} else {
size = rep.num_adaptors*sizeof(SDL_NAME(XvAdaptorInfo));
if ((pas=(SDL_NAME(XvAdaptorInfo) *)Xmalloc(size))==NULL) {
Xfree(buffer);
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
}
/* INIT ADAPTOR FIELDS */
pa = pas;
for (ii=0; ii<rep.num_adaptors; ii++) {
pa->num_adaptors = 0;
pa->name = (char *)NULL;
pa->formats = (SDL_NAME(XvFormat) *)NULL;
pa++;
}
pa = pas;
for (ii=0; ii<rep.num_adaptors; ii++) {
pa->type = u.pa->type;
pa->base_id = u.pa->base_id;
pa->num_ports = u.pa->num_ports;
pa->num_formats = u.pa->num_formats;
pa->num_adaptors = rep.num_adaptors - ii;
/* GET ADAPTOR NAME */
size = u.pa->name_size;
u.buffer += (sz_xvAdaptorInfo + 3) & ~3;
if ( (name = (char *)Xmalloc(size+1)) == NULL)
{
SDL_NAME(XvFreeAdaptorInfo)(pas);
Xfree(buffer);
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
(void)strncpy(name, u.string, size);
name[size] = '\0';
pa->name = name;
u.buffer += (size + 3) & ~3;
/* GET FORMATS */
size = pa->num_formats*sizeof(SDL_NAME(XvFormat));
if ((pfs=(SDL_NAME(XvFormat) *)Xmalloc(size))==NULL) {
SDL_NAME(XvFreeAdaptorInfo)(pas);
Xfree(buffer);
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
pf = pfs;
for (jj=0; jj<pa->num_formats; jj++) {
pf->depth = u.pf->depth;
pf->visual_id = u.pf->visual;
pf++;
u.buffer += (sz_xvFormat + 3) & ~3;
}
pa->formats = pfs;
pa++;
}
*p_nAdaptors = rep.num_adaptors;
*p_pAdaptors = pas;
UnlockDisplay(dpy);
SyncHandle();
return (Success);
}
void
SDL_NAME(XvFreeAdaptorInfo)(SDL_NAME(XvAdaptorInfo) *pAdaptors)
{
SDL_NAME(XvAdaptorInfo) *pa;
int ii;
if (!pAdaptors) return;
pa = pAdaptors;
for (ii=0; ii<pAdaptors->num_adaptors; ii++, pa++)
{
if (pa->name)
{
Xfree(pa->name);
}
if (pa->formats)
{
Xfree(pa->formats);
}
}
Xfree(pAdaptors);
}
int
SDL_NAME(XvQueryEncodings)(
Display *dpy,
XvPortID port,
unsigned int *p_nEncodings,
SDL_NAME(XvEncodingInfo) **p_pEncodings
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvQueryEncodingsReq *req;
xvQueryEncodingsReply rep;
int size, jj;
char *name;
SDL_NAME(XvEncodingInfo) *pes, *pe;
char *buffer;
union
{
char *buffer;
char *string;
xvEncodingInfo *pe;
} u;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
XvGetReq(QueryEncodings, req);
req->port = port;
/* READ THE REPLY */
if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadReply);
}
size = rep.length << 2;
if ( (buffer = (char *)Xmalloc ((unsigned) size)) == NULL) {
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
_XRead (dpy, buffer, size);
u.buffer = buffer;
/* GET ENCODINGS */
size = rep.num_encodings*sizeof(SDL_NAME(XvEncodingInfo));
if ( (pes = (SDL_NAME(XvEncodingInfo) *)Xmalloc(size)) == NULL) {
Xfree(buffer);
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
/* INITIALIZE THE ENCODING POINTER */
pe = pes;
for (jj=0; jj<rep.num_encodings; jj++) {
pe->name = (char *)NULL;
pe->num_encodings = 0;
pe++;
}
pe = pes;
for (jj=0; jj<rep.num_encodings; jj++) {
pe->encoding_id = u.pe->encoding;
pe->width = u.pe->width;
pe->height = u.pe->height;
pe->rate.numerator = u.pe->rate.numerator;
pe->rate.denominator = u.pe->rate.denominator;
pe->num_encodings = rep.num_encodings - jj;
size = u.pe->name_size;
u.buffer += (sz_xvEncodingInfo + 3) & ~3;
if ( (name = (char *)Xmalloc(size+1)) == NULL) {
Xfree(buffer);
UnlockDisplay(dpy);
SyncHandle();
return(XvBadAlloc);
}
strncpy(name, u.string, size);
name[size] = '\0';
pe->name = name;
pe++;
u.buffer += (size + 3) & ~3;
}
*p_nEncodings = rep.num_encodings;
*p_pEncodings = pes;
UnlockDisplay(dpy);
SyncHandle();
return (Success);
}
void
SDL_NAME(XvFreeEncodingInfo)(SDL_NAME(XvEncodingInfo) *pEncodings)
{
SDL_NAME(XvEncodingInfo) *pe;
int ii;
if (!pEncodings) return;
pe = pEncodings;
for (ii=0; ii<pEncodings->num_encodings; ii++, pe++) {
if (pe->name) Xfree(pe->name);
}
Xfree(pEncodings);
}
int
SDL_NAME(XvPutVideo)(
Display *dpy,
XvPortID port,
Drawable d,
GC gc,
int vx, int vy,
unsigned int vw, unsigned int vh,
int dx, int dy,
unsigned int dw, unsigned int dh
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvPutVideoReq *req;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
FlushGC(dpy, gc);
XvGetReq(PutVideo, req);
req->port = port;
req->drawable = d;
req->gc = gc->gid;
req->vid_x = vx;
req->vid_y = vy;
req->vid_w = vw;
req->vid_h = vh;
req->drw_x = dx;
req->drw_y = dy;
req->drw_w = dw;
req->drw_h = dh;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
int
SDL_NAME(XvPutStill)(
Display *dpy,
XvPortID port,
Drawable d,
GC gc,
int vx, int vy,
unsigned int vw, unsigned int vh,
int dx, int dy,
unsigned int dw, unsigned int dh
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvPutStillReq *req;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
FlushGC(dpy, gc);
XvGetReq(PutStill, req);
req->port = port;
req->drawable = d;
req->gc = gc->gid;
req->vid_x = vx;
req->vid_y = vy;
req->vid_w = vw;
req->vid_h = vh;
req->drw_x = dx;
req->drw_y = dy;
req->drw_w = dw;
req->drw_h = dh;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
int
SDL_NAME(XvGetVideo)(
Display *dpy,
XvPortID port,
Drawable d,
GC gc,
int vx, int vy,
unsigned int vw, unsigned int vh,
int dx, int dy,
unsigned int dw, unsigned int dh
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvGetVideoReq *req;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
FlushGC(dpy, gc);
XvGetReq(GetVideo, req);
req->port = port;
req->drawable = d;
req->gc = gc->gid;
req->vid_x = vx;
req->vid_y = vy;
req->vid_w = vw;
req->vid_h = vh;
req->drw_x = dx;
req->drw_y = dy;
req->drw_w = dw;
req->drw_h = dh;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
int
SDL_NAME(XvGetStill)(
Display *dpy,
XvPortID port,
Drawable d,
GC gc,
int vx, int vy,
unsigned int vw, unsigned int vh,
int dx, int dy,
unsigned int dw, unsigned int dh
){
XExtDisplayInfo *info = xv_find_display(dpy);
xvGetStillReq *req;
XvCheckExtension(dpy, info, XvBadExtension);
LockDisplay(dpy);
FlushGC(dpy, gc);
XvGetReq(GetStill, req);
req->port = port;
req->drawable = d;
req->gc = gc->gid;
req->vid_x = vx;
req->vid_y = vy;
req->vid_w = vw;
req->vid_h = vh;
req->drw_x = dx;
req->drw_y = dy;
req->drw_w = dw;
req->drw_h = dh;
UnlockDisplay(dpy);
SyncHandle();
return Success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -