xref: /haiku/headers/os/game/WindowScreen.h (revision a4f6a81235ca2522c01f532de13cad9b729d4029)
1 /*******************************************************************************
2 /
3 /	File:		WindowScreen.h
4 /
5 /	Description:	Client window class for direct screen access.
6 /
7 /	Copyright 1993-98, Be Incorporated, All Rights Reserved.
8 /
9 *******************************************************************************/
10 
11 
12 #ifndef	_WINDOW_SCREEN_H
13 #define	_WINDOW_SCREEN_H
14 
15 #include <BeBuild.h>
16 #include <Window.h>
17 #include <SupportDefs.h>
18 #include <OS.h>
19 #include <kernel/image.h>
20 #include <GraphicsCard.h>
21 #include <Accelerant.h>
22 
23 /* private struct */
24 typedef struct {
25     area_id               memory_area;
26     area_id               io_area;
27 	char                  addon_path[64+B_FILE_NAME_LENGTH];
28 } _direct_screen_info_;
29 
30 /* private typedef */
31 typedef int32 (*_add_on_control_)(uint32,void *);
32 
33 /* Global function, allowing to move the position of the mouse when the GameKit is in
34    control of the screen. */
35 _IMPEXP_GAME
36 void set_mouse_position(int32 x, int32 y);
37 
38 /**********************  WARNING - WARNING - WARNING ***********************************
39    This is the current version of WindowScreen. The main purpose of this object is to
40    establish a direct connexion between application and graphic driver, to increase
41    efficiency and abilities. The graphic driver architecture will overcome serious
42    changes in the next release, consequently this could only be a preview version of
43    the real WindowScreen API.
44 
45    Nevertheless, compatibility will be insure in future releases FOR MOST OF THE API,
46    through the use of a compatibility library (the new game library having a name
47    different from "libgame.so"), or a compatibility class (the new WindowScreen class
48    using a different name). Part of the API for which compatibility will not be insure
49    after the Preview Release are specifically pointed out in the following declarations.
50 ****************************************************************************************/
51 
52 enum {
53 	B_ENABLE_VIEW_DRAWING = 0x0001,
54 	B_ENABLE_DEBUGGER = 0x0002
55 };
56 
57 class BWindowScreen : public BWindow {
58 public:
59 	BWindowScreen(const char *title, uint32 space, status_t *error,
60 						bool debug_enable = false);
61         BWindowScreen(const char *title, uint32 space, uint32 attributes,
62 						status_t *error);
63 	virtual ~BWindowScreen();
64 
65 	virtual void Quit();
66 	virtual void ScreenConnected(bool active);
67         	void Disconnect();
68 
69 	virtual	void WindowActivated(bool active);
70 	virtual void WorkspaceActivated(int32 ws, bool state);
71 	virtual void ScreenChanged(BRect screen_size, color_space depth);
72 
73 	virtual void Hide();
74 	virtual void Show();
75 
76         void SetColorList(rgb_color *list,int32 first_index = 0,int32 last_index = 255);
77 	status_t SetSpace(uint32 space);
78 
79 	bool CanControlFrameBuffer();
80 	status_t SetFrameBuffer(int32 width, int32 height);
81 	status_t MoveDisplayArea(int32 x, int32 y);
82 
83 	void *IOBase(); // Not supported anymore. It always returns NULL
84 
85 	rgb_color           *ColorList();
86 	frame_buffer_info   *FrameBufferInfo();
87 	graphics_card_hook  CardHookAt(int32 index);
88 	graphics_card_info  *CardInfo();
89 
90 /******************************* Debugger API Notice ********************************
91   Those three calls, and the debug_enable flag in the constructor, have been added to
92   help debugging a WindowScreen application without a cross-developement platform or
93   the use of serial debug output.
94 
95   To use them, you need to :
96   - enable the debug mode by setting the debug_enable flag of the constructor to "true".
97   - register all threads that could be accessing the screen directly at any time. To do
98     that, call RegisterThread after spawning the new thread and before resuming
99 	it (you should never draw from the Window thread itself, neither register it).
100   - launch your application from Terminal. The GameKit will first swicth to another
101     workspace before opening the WindowScreen. If you launch from workspace 0 [Alt-F1],
102 	it will choose the workspace 1 [Alt-F2]. For any other workspace, it will choose
103 	the previous one (for example, for workspace 3 (Alt-F4), it will choose workspace 2
104 	[Alt-F3]).
105 
106   Then :
107   - You can use printf(...) anywhere to display informations that will be logged in the
108     Terminal window. You can go back to the Terminal Window at any time (using the
109 	correct Alt-F?? key). Switching workspace will automatically suspend all the thread
110 	you registered and save the graphic context. Switching back to the WindowScreen
111 	workspace will restore everything and resume your application.
112   - If you need to save and restore more states when your application is suspended and
113     resumed, you can overwrite the ForceSwitchForDebug() method. This function is called
114 	with active == true just after suspending your app, and active == false just before
115 	resuming it.
116   - You can suspend your application by calling the Debugger() method. This will also
117     switch to the Terminal workspace. Then you can resume by just switchng back to the
118 	WindowScreen workspace (using the good Alt-F?? key). It's better not to call Debugger()
119 	with the WindowScreen locked.
120 
121   In case of crash :
122   - Use the safety short-cut : All the left modifiers (Ctrl, Shift, Option, Command, Alt
123     or equivalents) of your keyboard and F12. That should send you back to 640x480, and
124 	the debugger terminal should be visible (and usable) if any.
125   - Then, you can also switch to your Terminal workspace to check the last printf infos.
126   - After you got (we hope) more information about your (or our :-) bug, quit the debugger
127     window. Then you should be able to change your code and run your application again.
128 	In any case, check the Error() function immediately after the WindowScreen constructor.
129 	A bad error code will mean that the GameKit is in a inconsistent state, and then you
130 	have better to reboot your machine. If you don't wnat to reboot, you can also try to
131 	run your application in a different workspace.
132 
133 	It's far to be perfect, but we hope it will still help.
134 
135 	The Debug API will not be support after the Preview Release (replaced by the debug
136 	API in the new WindowScreen class).
137 ***************************************************************************************/
138 	void        RegisterThread(thread_id id);
139 virtual	void        SuspensionHook(bool active);
140 	void        Suspend(char *label);
141 
142 
143 virtual status_t	Perform(perform_code d, void *arg);
144 
145 private:
146 
147 	typedef BWindow	inherited;
148 
149 virtual void        _ReservedWindowScreen1();
150 virtual void        _ReservedWindowScreen2();
151 virtual void        _ReservedWindowScreen3();
152 virtual void        _ReservedWindowScreen4();
153 
154 		BWindowScreen();
155 		BWindowScreen(BWindowScreen &);
156 		BWindowScreen &operator=(BWindowScreen &);
157 
158 		char                  _unused;
159 		char                  space_mode;
160 		bool                  direct_enable;
161 		bool                  fWorkState;
162 		bool                  fWindowState;
163 		bool                  fActivateState;
164         	int32                 fLockState;
165 		int32                 fScreenIndex;
166 
167 		display_mode          *fOldDisplayMode;
168 		display_mode          *fDisplayMode;
169 		uint32                space0;
170 		sem_id                fActivateSem;
171 		sem_id                fDebugSem;
172 		image_id              fAddonImage;
173 
174 		rgb_color             fColorList[256];
175 		GetAccelerantHook     fGetAccelerantHook;
176         	graphics_card_info    fCardInfo;
177 
178 		graphics_card_hook    hooks[B_HOOK_COUNT];
179 		_direct_screen_info_  info;
180 		frame_buffer_info     fFrameBufferInfo;
181 
182 		char                  *fDebugBuffer;
183 		bool                  fDebugState;
184 		bool                  fDebugFirst;
185 		int32                 fDebugListCount;
186 		int32                 fDebugWorkspace;
187 	    	thread_id             *fDebugList;
188 
189 		uint32		      fAttributes;
190 		uint32                fModeCount;
191 		display_mode          *fModeList;
192 
193 		engine_token          *fEngineToken;
194 		wait_engine_idle      m_wei;
195 		acquire_engine        m_ae;
196 		release_engine        m_re;
197 		fill_rectangle        fill_rect;
198 		screen_to_screen_blit blit_rect;
199 		screen_to_screen_transparent_blit trans_blit_rect;
200 		screen_to_screen_scaled_filtered_blit scaled_filtered_blit_rect;
201 
202 		uint32                _reserved_[24];
203 
204 	static	BRect		CalcFrame(int32 index, int32 space, display_mode *dmode);
205 		status_t	InitData(uint32 space, uint32 attributes);
206         	status_t    	SetActiveState(int32 state);
207 		status_t	SetupAccelerantHooks(bool enable);
208 		status_t    	GetCardInfo();
209 		void        	Suspend();
210 		void    	Resume();
211 		status_t	GetModeFromSpace(uint32 space, display_mode *dmode);
212 		status_t	InitClone();
213 		status_t	AssertDisplayMode(display_mode *dmode);
214 };
215 
216 #endif
217 
218 
219 
220 
221 
222 
223 
224 
225 
226 
227 
228