1 // Copyright (C)2004 Landmark Graphics Corporation
2 // Copyright (C)2005-2007 Sun Microsystems, Inc.
3 // Copyright (C)2009-2012, 2014, 2017-2018, 2020 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 #ifndef __FRAME_H__
16 #define __FRAME_H__
17 
18 #include "rr.h"
19 #include "fbx.h"
20 #include "turbojpeg.h"
21 #include "Mutex.h"
22 #ifdef USEXV
23 #include "fbxv.h"
24 #endif
25 #include "pf.h"
26 
27 
28 // Flags
29 #define FRAME_BOTTOMUP  1  // Bottom-up bitmap (as opposed to top-down)
30 
31 
32 // Uncompressed frame
33 
34 namespace vglcommon
35 {
36 	class Frame
37 	{
38 		public:
39 
40 			Frame(bool primary = true);
41 			virtual ~Frame(void);
42 			void init(rrframeheader &h, int pixelFormat, int flags,
43 				bool stereo = false);
44 			void init(unsigned char *bits, int width, int pitch, int height,
45 				int pixelFormat, int flags);
46 			void deInit(void);
47 			Frame *getTile(int x, int y, int width, int height);
48 			bool tileEquals(Frame *last, int x, int y, int width, int height);
49 			void makeAnaglyph(Frame &r, Frame &g, Frame &b);
50 			void makePassive(Frame &stf, int mode);
signalReady(void)51 			void signalReady(void) { ready.signal(); }
waitUntilReady(void)52 			void waitUntilReady(void) { ready.wait(); }
signalComplete(void)53 			void signalComplete(void) { complete.signal(); }
waitUntilComplete(void)54 			void waitUntilComplete(void) { complete.wait(); }
isComplete(void)55 			bool isComplete(void) { return !complete.isLocked(); }
56 			void decompressRGB(Frame &f, int width, int height, bool rightEye);
57 			void addLogo(void);
58 
59 			rrframeheader hdr;
60 			unsigned char *bits;
61 			unsigned char *rbits;
62 			int pitch, flags;
63 			PF *pf;
64 			bool isGL, isXV, stereo;
65 
66 		protected:
67 
68 			void dumpHeader(rrframeheader &);
69 			void checkHeader(rrframeheader &);
70 
71 			vglutil::Event ready;
72 			vglutil::Event complete;
73 			friend class CompressedFrame;
74 			bool primary;
75 	};
76 }
77 
78 
79 // Compressed frame
80 
81 namespace vglcommon
82 {
83 	class CompressedFrame : public Frame
84 	{
85 		public:
86 
87 			CompressedFrame(void);
88 			~CompressedFrame(void);
89 			CompressedFrame &operator= (Frame &f);
90 			void compressYUV(Frame &f);
91 			void compressJPEG(Frame &f);
92 			void compressRGB(Frame &f);
93 			void init(rrframeheader &h, int buffer);
94 
95 			rrframeheader rhdr;
96 
97 		private:
98 
99 			tjhandle tjhnd;
100 			friend class FBXFrame;
101 	};
102 }
103 
104 
105 // Frame created from shared graphics memory
106 
107 namespace vglcommon
108 {
109 	class FBXFrame : public Frame
110 	{
111 		public:
112 
113 			FBXFrame(Display *dpy, Drawable draw, Visual *vis = NULL,
114 				bool reuseConn = false);
115 			FBXFrame(char *dpystring, Window win);
116 			void init(char *dpystring, Drawable draw, Visual *vis = NULL);
117 			void init(Display *dpy, Drawable draw, Visual *vis);
118 			~FBXFrame(void);
119 			void init(rrframeheader &h);
120 			FBXFrame &operator= (CompressedFrame &cf);
121 			void redraw(void);
122 
123 		private:
124 
125 			fbx_wh wh;
126 			fbx_struct fb;
127 			tjhandle tjhnd;
128 			bool reuseConn;
129 			static vglutil::CriticalSection mutex;
130 	};
131 }
132 
133 
134 #ifdef USEXV
135 
136 // Frame created using X Video
137 
138 namespace vglcommon
139 {
140 	class XVFrame : public Frame
141 	{
142 		public:
143 
144 			XVFrame(Display *dpy, Window win);
145 			XVFrame(char *dpystring, Window win);
146 			void init(char *dpystring, Window win);
147 			~XVFrame(void);
148 			XVFrame &operator= (Frame &f);
149 			void init(rrframeheader &h);
150 			void redraw(void);
151 
152 		private:
153 
154 			fbxv_struct fb;
155 			Display *dpy;  Window win;
156 			tjhandle tjhnd;
157 			static vglutil::CriticalSection mutex;
158 	};
159 }
160 
161 #endif
162 
163 
164 #endif  // __FRAME_H__
165