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, 60 uint32 space, 61 status_t *error, 62 bool debug_enable = false); 63 BWindowScreen(const char *title, 64 uint32 space, 65 uint32 attributes, 66 status_t *error); 67 virtual ~BWindowScreen(); 68 virtual void Quit(void); 69 virtual void ScreenConnected(bool active); 70 void Disconnect(); 71 virtual void WindowActivated(bool active); 72 virtual void WorkspaceActivated(int32 ws, bool state); 73 virtual void ScreenChanged(BRect screen_size, color_space depth); 74 virtual void Hide(); 75 virtual void Show(); 76 void SetColorList(rgb_color *list,int32 first_index = 0,int32 last_index = 255); 77 status_t SetSpace(uint32 space); 78 bool CanControlFrameBuffer(); 79 status_t SetFrameBuffer(int32 width, int32 height); 80 status_t MoveDisplayArea(int32 x, int32 y); 81 82 void *IOBase(); // Not supported anymore. It always returns NULL 83 84 rgb_color *ColorList(); 85 frame_buffer_info *FrameBufferInfo(); 86 graphics_card_hook CardHookAt(int32 index); 87 graphics_card_info *CardInfo(); 88 89 /******************************* Debugger API Notice ******************************** 90 Those three calls, and the debug_enable flag in the constructor, have been added to 91 help debugging a WindowScreen application without a cross-developement platform or 92 the use of serial debug output. 93 94 To use them, you need to : 95 - enable the debug mode by setting the debug_enable flag of the constructor to "true". 96 - register all threads that could be accessing the screen directly at any time. To do 97 that, call RegisterThread after spawning the new thread and before resuming 98 it (you should never draw from the Window thread itself, neither register it). 99 - launch your application from Terminal. The GameKit will first swicth to another 100 workspace before opening the WindowScreen. If you launch from workspace 0 [Alt-F1], 101 it will choose the workspace 1 [Alt-F2]. For any other workspace, it will choose 102 the previous one (for example, for workspace 3 (Alt-F4), it will choose workspace 2 103 [Alt-F3]). 104 105 Then : 106 - You can use printf(...) anywhere to display informations that will be logged in the 107 Terminal window. You can go back to the Terminal Window at any time (using the 108 correct Alt-F?? key). Switching workspace will automatically suspend all the thread 109 you registered and save the graphic context. Switching back to the WindowScreen 110 workspace will restore everything and resume your application. 111 - If you need to save and restore more states when your application is suspended and 112 resumed, you can overwrite the ForceSwitchForDebug() method. This function is called 113 with active == true just after suspending your app, and active == false just before 114 resuming it. 115 - You can suspend your application by calling the Debugger() method. This will also 116 switch to the Terminal workspace. Then you can resume by just switchng back to the 117 WindowScreen workspace (using the good Alt-F?? key). It's better not to call Debugger() 118 with the WindowScreen locked. 119 120 In case of crash : 121 - Use the safety short-cut : All the left modifiers (Ctrl, Shift, Option, Command, Alt 122 or equivalents) of your keyboard and F12. That should send you back to 640x480, and 123 the debugger terminal should be visible (and usable) if any. 124 - Then, you can also switch to your Terminal workspace to check the last printf infos. 125 - After you got (we hope) more information about your (or our :-) bug, quit the debugger 126 window. Then you should be able to change your code and run your application again. 127 In any case, check the Error() function immediately after the WindowScreen constructor. 128 A bad error code will mean that the GameKit is in a inconsistent state, and then you 129 have better to reboot your machine. If you don't wnat to reboot, you can also try to 130 run your application in a different workspace. 131 132 It's far to be perfect, but we hope it will still help. 133 134 The Debug API will not be support after the Preview Release (replaced by the debug 135 API in the new WindowScreen class). 136 ***************************************************************************************/ 137 void RegisterThread(thread_id id); 138 virtual void SuspensionHook(bool active); 139 void Suspend(char *label); 140 141 142 virtual status_t Perform(perform_code d, void *arg); 143 144 private: 145 146 typedef BWindow inherited; 147 148 virtual void _ReservedWindowScreen1(); 149 virtual void _ReservedWindowScreen2(); 150 virtual void _ReservedWindowScreen3(); 151 virtual void _ReservedWindowScreen4(); 152 153 BWindowScreen(); 154 BWindowScreen(BWindowScreen &); 155 BWindowScreen &operator=(BWindowScreen &); 156 157 char addon_state; 158 char space_mode; 159 void *io_buffer; 160 bool direct_enable; 161 bool work_state; 162 bool window_state; 163 bool activate_state; 164 int32 lock_state; 165 int32 screen_index; 166 int32 memory_area, io_area; 167 display_mode *old_space; 168 display_mode *new_space; 169 uint32 space0; 170 sem_id activate_sem; 171 sem_id debug_sem; 172 image_id addon_image; 173 rgb_color colorList[256]; 174 GetAccelerantHook m_gah; 175 graphics_card_info card_info; 176 graphics_card_hook hooks[B_HOOK_COUNT]; 177 _direct_screen_info_ info; 178 frame_buffer_info format_info; 179 180 char *debug_buffer; 181 bool debug_state; 182 bool debug_first; 183 int32 debug_list_count; 184 int32 debug_workspace; 185 thread_id *debug_list; 186 187 uint32 _attributes; 188 uint32 mode_count; 189 display_mode *mode_list; 190 engine_token *et; 191 wait_engine_idle m_wei; 192 acquire_engine m_ae; 193 release_engine m_re; 194 fill_rectangle fill_rect; 195 screen_to_screen_blit blit_rect; 196 screen_to_screen_transparent_blit trans_blit_rect; 197 screen_to_screen_scaled_filtered_blit scaled_filtered_blit_rect; 198 199 uint32 _reserved_[21]; 200 201 static BRect CalcFrame(int32 index, int32 space, display_mode *dmode); 202 int32 SetFullscreen(int32 enable); 203 status_t InitData(uint32 space, uint32 attributes); 204 status_t SetActiveState(int32 state); 205 status_t SetLockState(int32 state); 206 void GetCardInfo(); 207 void Suspend(); 208 void Resume(); 209 status_t GetModeFromSpace(uint32 space, display_mode *dmode); 210 status_t InitClone(); 211 status_t AssertDisplayMode(display_mode *dmode); 212 }; 213 214 #endif 215 216 217 218 219 220 221 222 223 224 225 226