1 /* Copyright (C)2004 Landmark Graphics Corporation
2  * Copyright (C)2005, 2006 Sun Microsystems, Inc.
3  * Copyright (C)2009, 2014, 2019 D. R. Commander
4  *
5  * This library is free software and may be redistributed and/or modified under
6  * the terms of the wxWindows Library License, Version 3.1 or (at your option)
7  * any later version.  The full license is in the LICENSE.txt file included
8  * with this distribution.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * wxWindows Library License for more details.
14  */
15 
16 /* FBXV -- An FBX-like API to abstract interaction with X Video */
17 
18 #ifndef __FBXV_H__
19 #define __FBXV_H__
20 
21 #define USESHM
22 
23 #include <stdio.h>
24 #include <X11/Xlib.h>
25 #ifdef USESHM
26 #include <sys/ipc.h>
27 #include <sys/shm.h>
28 #include <X11/extensions/XShm.h>
29 #endif
30 #include <X11/extensions/Xv.h>
31 #include <X11/extensions/Xvlib.h>
32 #include <X11/Xutil.h>
33 
34 
35 #define YUY2_PACKED  0x32595559
36 #define YV12_PLANAR  0x32315659
37 #define UYVY_PACKED  0x59565955
38 #define I420_PLANAR  0x30323449
39 
40 
41 typedef struct _fbxv_struct
42 {
43 	Display *dpy;  Window win;
44 	int shm, reqwidth, reqheight, port, doexpose;
45 	#ifdef USESHM
46 	XShmSegmentInfo shminfo;  int xattach;
47 	#endif
48 	GC xgc;
49 	XvImage *xvi;
50 } fbxv_struct;
51 
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /*
58    All of these methods return -1 on failure or 0 on success.
59 */
60 
61 
62 /*
63   fb = Address of fbxv_struct (must be pre-allocated by user)
64   Display *dpy = X11 display handle
65   Window win = X11 drawable into which the video should be drawn
66   width = Width of image (in pixels) that you wish to create.  0 = use width
67           of window
68   height = Height of image (in pixels) that you wish to create.  0 = use height
69            of window
70   format = GUID of desired X Video image format.  If the X Video extension does
71            not support this format, then fbxv_init() returns an error.
72   useShm = Use MIT-SHM extension, if available
73 
74   NOTES:
75   -- fbxv_init() is idempotent.  If you call it multiple times, it will
76      re-initialize the buffer only when it is necessary to do so (such as when
77      the window size has changed.)
78   -- If this function returns successfully, fb->xvi will point to a valid
79      XvImage structure that can be populated with image data.  Double-check
80      fb->xvi->width and fb->xvi->height, as these may differ from the requested
81      width and height.
82 */
83 int fbxv_init(fbxv_struct *fb, Display *dpy, Window win, int width, int height,
84 	int format, int useShm);
85 
86 
87 /*
88   This routine draws an X Video image stored in fb to the framebuffer
89 
90   fb = Address of fbxv_struct previously initialized by a call to fbxv_init()
91        fb->xvi->data should contain the image you wish to draw
92   srcX = left offset of the region you wish to draw (relative to the X Video
93          image)
94   srcY = top offset of the region you wish to draw (relative to the X Video
95          image)
96   srcWidth, srcHeight = width and height of the portion of the source image you
97                         wish to draw (0 = whole image)
98   dstX = left offset of the window region into which the image should be
99          drawn (relative to the window's client area)
100   dstY = top offset of the window region into which the image should be
101          drawn (relative to the window's client area)
102   dstWidth, dstHeight = width and height of the window region into which the
103                         image should be drawn
104 */
105 int fbxv_write(fbxv_struct *fb, int srcX, int srcY, int srcWidth,
106 	int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight);
107 
108 
109 /*
110   Frees the X Video image associated with fb (if any), then frees the memory
111   used by fb.
112 
113   NOTE: this routine is idempotent.  It only frees stuff that needs freeing.
114 */
115 int fbxv_term(fbxv_struct *fb);
116 
117 
118 /*
119   This returns a string containing the reason why the last command failed
120 */
121 char *fbxv_geterrmsg(void);
122 
123 
124 /*
125   This returns the line (within fbxv.c) of the last failure
126 */
127 int fbxv_geterrline(void);
128 
129 
130 /*
131   By default, FBXV will not print warning messages (such as messages related to
132   its automatic selection of a particular drawing method.)  These messages are
133   sometimes useful when diagnosing performance issues.  Passing a stream
134   pointer (such as stdout, stderr, or a pointer returned from a previous call
135   to fopen()) to this function will enable warning messages and will cause them
136   to be printed to the specified stream.  Passing an argument of NULL to this
137   function will disable warnings.
138 */
139 void fbxv_printwarnings(FILE *stream);
140 
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif  /* __FBXV_H__ */
147