Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

260 lines
8.3 KiB

  1. //================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
  2. //
  3. //
  4. //
  5. //==================================================================================================
  6. #ifndef ICOCOAMGR_H
  7. #define ICOCOAMGR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier0/threadtools.h"
  12. #include "appframework/IAppSystem.h"
  13. #include "glmgr/glmgr.h"
  14. // if you rev this version also update materialsystem/cmaterialsystem.cpp CMaterialSystem::Connect as it defines the string directly
  15. #define COCOAMGR_INTERFACE_VERSION "CocoaMgrInterface006"
  16. enum CocoaEventType_t
  17. {
  18. CocoaEvent_KeyDown,
  19. CocoaEvent_KeyUp,
  20. CocoaEvent_MouseButtonDown,
  21. CocoaEvent_MouseMove,
  22. CocoaEvent_MouseButtonUp,
  23. CocoaEvent_AppActivate,
  24. CocoaEvent_MouseScroll,
  25. CocoaEvent_AppQuit
  26. };
  27. // enum values need to match bit-shifting logic in CInputSystem::UpdateMouseButtonState and
  28. // the codes from NSEvent pressedMouseButtons, turns out the two are in agreement right now
  29. enum CocoaMouseButton_t
  30. {
  31. COCOABUTTON_LEFT = 1 << 0,
  32. COCOABUTTON_RIGHT = 1 << 1,
  33. COCOABUTTON_MIDDLE = 1 << 2,
  34. COCOABUTTON_4 = 1 << 3,
  35. COCOABUTTON_5 = 1 << 4,
  36. };
  37. enum ECocoaKeyModifier
  38. {
  39. eCapsLockKey,
  40. eShiftKey,
  41. eControlKey,
  42. eAltKey, // aka option
  43. eCommandKey
  44. };
  45. class CCocoaEvent
  46. {
  47. public:
  48. CocoaEventType_t m_EventType;
  49. int m_VirtualKeyCode;
  50. wchar_t m_UnicodeKey;
  51. wchar_t m_UnicodeKeyUnmodified;
  52. uint m_ModifierKeyMask; //
  53. int m_MousePos[2];
  54. int m_MouseButtonFlags; // Current state of the mouse buttons. See COCOABUTTON_xxxx.
  55. uint m_nMouseClickCount;
  56. int m_MouseButton; // which of the CocoaMouseButton_t buttons this is for from above
  57. };
  58. class CShowPixelsParams
  59. {
  60. public:
  61. GLuint m_srcTexName;
  62. int m_width,m_height;
  63. bool m_vsyncEnable;
  64. bool m_fsEnable; // want receiving view to be full screen. for now, just target the main screen. extend later.
  65. bool m_useBlit; // use FBO blit - sending context says it is available.
  66. bool m_noBlit; // the back buffer has already been populated by the caller (perhaps via direct MSAA resolve from multisampled RT tex)
  67. bool m_onlySyncView; // react to full/windowed state change only, do not present bits
  68. };
  69. #define kMaxCrawlFrames 100
  70. #define kMaxCrawlText (kMaxCrawlFrames * 256)
  71. class CStackCrawlParams
  72. {
  73. public:
  74. uint m_frameLimit; // input: max frames to retrieve
  75. uint m_frameCount; // output: frames found
  76. void *m_crawl[kMaxCrawlFrames]; // call site addresses
  77. char *m_crawlNames[kMaxCrawlFrames]; // pointers into text following, one per decoded name
  78. char m_crawlText[kMaxCrawlText];
  79. };
  80. struct GLMRendererInfoFields;
  81. class GLMDisplayDB;
  82. class ICocoaMgr : public IAppSystem
  83. {
  84. public:
  85. virtual bool Connect( CreateInterfaceFn factory ) = 0;
  86. virtual void Disconnect() = 0;
  87. virtual void *QueryInterface( const char *pInterfaceName ) = 0;
  88. // Init, shutdown
  89. virtual InitReturnVal_t Init() = 0;
  90. virtual void Shutdown() = 0;
  91. // Create the window.
  92. virtual bool CreateGameWindow( const char *pTitle, bool bWindowed, int width, int height ) = 0;
  93. // Get the NSWindow*.
  94. // virtual void* GetNSWindow() = 0;
  95. // Get the NSGLContext for a window's main view - note this is the carbon windowref as an argument
  96. virtual PseudoNSGLContextPtr GetNSGLContextForWindow( void* windowref ) = 0;
  97. // Get the next N events. The function returns the number of events that were filled into your array.
  98. virtual int GetEvents( CCocoaEvent *pEvents, int nMaxEventsToReturn, bool debugEvents = false ) = 0;
  99. // Set the mouse cursor position.
  100. virtual void SetCursorPosition( int x, int y ) = 0;
  101. virtual void *GetWindowRef() = 0;
  102. virtual void ShowPixels( CShowPixelsParams *params ) = 0;
  103. virtual void MoveWindow( int x, int y ) = 0;
  104. virtual void SizeWindow( int width, int tall ) = 0;
  105. virtual void PumpWindowsMessageLoop() = 0;
  106. virtual void GetStackCrawl( CStackCrawlParams *params ) = 0;
  107. virtual void DestroyGameWindow() = 0;
  108. virtual void SetApplicationIcon( const char *pchAppIconFile ) = 0;
  109. virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta = false ) = 0;
  110. virtual void RenderedSize( uint &width, uint &height, bool set ) = 0; // either set or retrieve rendered size value (from dxabstract)
  111. virtual void DisplayedSize( uint &width, uint &height ) = 0; // query backbuffer size (window size whether FS or windowed)
  112. virtual void GetDesiredPixelFormatAttribsAndRendererInfo( uint **ptrOut, uint *countOut, GLMRendererInfoFields *rendInfoOut ) = 0;
  113. virtual GLMDisplayDB *GetDisplayDB( void ) = 0;
  114. virtual void WaitUntilUserInput( int msSleepTime ) = 0;
  115. };
  116. //===============================================================================
  117. // modes, displays, and renderers
  118. // think of renderers as being at the top of a tree.
  119. // each renderer has displays hanging off of it.
  120. // each display has modes hanging off of it.
  121. // the tree is populated on demand and then queried as needed.
  122. //===============================================================================
  123. // GLMDisplayModeInfoFields is in glmdisplay.h
  124. class GLMDisplayMode
  125. {
  126. public:
  127. GLMDisplayModeInfoFields m_info;
  128. GLMDisplayMode( uint width, uint height, uint refreshHz );
  129. ~GLMDisplayMode( void );
  130. void Dump( int which );
  131. };
  132. //===============================================================================
  133. // GLMDisplayInfoFields is in glmdisplay.h
  134. class GLMDisplayInfo
  135. {
  136. public:
  137. GLMDisplayInfoFields m_info;
  138. CUtlVector< GLMDisplayMode* > *m_modes; // starts out NULL, set by PopulateModes
  139. GLMDisplayInfo( CGDirectDisplayID displayID, CGOpenGLDisplayMask displayMask );
  140. ~GLMDisplayInfo( void );
  141. void PopulateModes( void );
  142. void Dump( int which );
  143. };
  144. //===============================================================================
  145. // GLMRendererInfoFields is in glmdisplay.h
  146. class GLMRendererInfo
  147. {
  148. public:
  149. GLMRendererInfoFields m_info;
  150. CUtlVector< GLMDisplayInfo* > *m_displays; // starts out NULL, set by PopulateDisplays
  151. GLMRendererInfo ( GLMRendererInfoFields *info );
  152. ~GLMRendererInfo ( void );
  153. void PopulateDisplays( void );
  154. void Dump( int which );
  155. };
  156. //===============================================================================
  157. // this is just a tuple describing fake adapters which are really renderer/display pairings.
  158. // dxabstract bridges the gap between the d3d adapter-centric world and the GL renderer+display world.
  159. // this makes it straightforward to handle cases like two video cards with two displays on one, and one on the other -
  160. // you get three fake adapters which represent each useful screen.
  161. // the constraint that dxa will have to follow though, is that if the user wants to change their
  162. // display selection for full screen, they would only be able to pick on that has the same underlying renderer.
  163. // can't change fakeAdapter from one to another with different GL renderer under it. Screen hop but no card hop.
  164. struct GLMFakeAdapter
  165. {
  166. int m_rendererIndex;
  167. int m_displayIndex;
  168. };
  169. class GLMDisplayDB
  170. {
  171. public:
  172. CUtlVector< GLMRendererInfo* > *m_renderers; // starts out NULL, set by PopulateRenderers
  173. CUtlVector< GLMFakeAdapter > m_fakeAdapters;
  174. GLMDisplayDB ( void );
  175. ~GLMDisplayDB ( void );
  176. virtual void PopulateRenderers( void );
  177. virtual void PopulateFakeAdapters( uint realRendererIndex ); // fake adapters = one real adapter times however many displays are on it
  178. virtual void Populate( void );
  179. // The info-get functions return false on success.
  180. virtual int GetFakeAdapterCount( void );
  181. virtual bool GetFakeAdapterInfo( int fakeAdapterIndex, int *rendererOut, int *displayOut, GLMRendererInfoFields *rendererInfoOut, GLMDisplayInfoFields *displayInfoOut );
  182. virtual int GetRendererCount( void );
  183. virtual bool GetRendererInfo( int rendererIndex, GLMRendererInfoFields *infoOut );
  184. virtual int GetDisplayCount( int rendererIndex );
  185. virtual bool GetDisplayInfo( int rendererIndex, int displayIndex, GLMDisplayInfoFields *infoOut );
  186. virtual int GetModeCount( int rendererIndex, int displayIndex );
  187. virtual bool GetModeInfo( int rendererIndex, int displayIndex, int modeIndex, GLMDisplayModeInfoFields *infoOut );
  188. virtual void Dump( void );
  189. };
  190. #endif // ICOCOAMGR_H