1
0

dxcontext.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005-2013 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef __NULLSOFT_DX9_PLUGIN_SHELL_DXCONTEXT_H__
  25. #define __NULLSOFT_DX9_PLUGIN_SHELL_DXCONTEXT_H__ 1
  26. #include <windows.h>
  27. #include "shell_defines.h"
  28. #ifdef _DEBUG
  29. #define D3D_DEBUG_INFO // declare this before including d3d9.h
  30. #endif
  31. #include <d3d9.h>
  32. #include <d3dx9.h>
  33. #define SNAP_WINDOWED_MODE_BLOCKSIZE 32 // or use 0 if you don't want snapping
  34. typedef struct
  35. {
  36. eScrMode screenmode; // WINDOWED, FULLSCREEN, or FAKE FULLSCREEN
  37. int nbackbuf;
  38. int allow_page_tearing;
  39. GUID adapter_guid;
  40. char adapter_devicename[256];
  41. D3DDISPLAYMODE display_mode; // ONLY VALID FOR FULLSCREEN MODE.
  42. D3DMULTISAMPLE_TYPE multisamp;
  43. HWND parent_window;
  44. int m_dualhead_horz; // 0 = span both, 1 = left only, 2 = right only
  45. int m_dualhead_vert; // 0 = span both, 1 = top only, 2 = bottom only
  46. int m_skin;
  47. }
  48. DXCONTEXT_PARAMS;
  49. #define MAX_DXC_ADAPTERS 32
  50. class DXContext
  51. {
  52. public:
  53. // PUBLIC FUNCTIONS
  54. DXContext(HWND hWndWinamp,HINSTANCE hInstance,LPCWSTR szClassName,LPCSTR szWindowCaption,WNDPROC pProc,LONG_PTR uWindowLong, int minimize_winamp, wchar_t* szIniFile);
  55. ~DXContext();
  56. BOOL StartOrRestartDevice(DXCONTEXT_PARAMS *pParams); // also serves as Init() function
  57. BOOL OnUserResizeWindow(RECT *new_window_rect, RECT *new_client_rect);
  58. inline HWND GetHwnd() { return m_hwnd; };
  59. inline int TempIgnoreDestroyMessages() { return m_ignore_wm_destroy; };
  60. void OnTrulyExiting() { m_truly_exiting = 1; }
  61. void UpdateMonitorWorkRect();
  62. int GetBitDepth() { return m_bpp; };
  63. inline D3DFORMAT GetZFormat() { return m_zFormat; };
  64. char* GetDriver() { return m_szDriver; };
  65. char* GetDesc() { return m_szDesc; };
  66. void SaveWindow();
  67. // PUBLIC DATA - DO NOT WRITE TO THESE FROM OUTSIDE THE CLASS
  68. int m_ready;
  69. HRESULT m_lastErr;
  70. int m_window_width;
  71. int m_window_height;
  72. int m_client_width; //in windowed mode, these are the SNAPPED (locked to nearest 32x32)
  73. int m_client_height; // width and height
  74. int m_REAL_client_width; //these are the ACTUAL (raw) width and height -
  75. int m_REAL_client_height; // only valid in windowed mode!
  76. int m_fake_fs_covers_all;
  77. int m_frame_delay;
  78. RECT m_all_monitors_rect; // rect that encompasses all monitors that make up the desktop. The primary monitor's upper-left corner is (0,0).
  79. RECT m_monitor_rect; // rect for monitor the plugin is running on; for pseudo-multimon modes like 2048x768, if user decides to only run on half the monitor, this rect reflects that as well.
  80. RECT m_monitor_rect_orig; // same, but it's the original rect; does not account for pseudo-multimon modes like 2048x768
  81. RECT m_monitor_work_rect; // same, but excludes the taskbar area.
  82. RECT m_monitor_work_rect_orig; // original work rect; does not account for pseudo-multimon modes like 2048x768
  83. DXCONTEXT_PARAMS m_current_mode;
  84. LPDIRECT3DDEVICE9 m_lpDevice;
  85. D3DPRESENT_PARAMETERS m_d3dpp;
  86. LPDIRECT3D9 m_lpD3D;
  87. D3DCAPS9 m_caps;
  88. protected:
  89. D3DMULTISAMPLE_TYPE m_multisamp;
  90. D3DFORMAT m_zFormat;
  91. D3DFORMAT m_orig_windowed_mode_format[MAX_DXC_ADAPTERS];
  92. HMODULE m_hmod_d3d9, m_hmod_d3dx9;
  93. int m_ordinal_adapter;
  94. HWND m_hwnd;
  95. HWND m_hwnd_winamp;
  96. LONG_PTR m_uWindowLong;
  97. ATOM m_classAtom;
  98. char m_szWindowCaption[512];
  99. wchar_t m_szIniFile[MAX_PATH];
  100. char m_szDriver[MAX_DEVICE_IDENTIFIER_STRING];
  101. char m_szDesc[MAX_DEVICE_IDENTIFIER_STRING];
  102. HINSTANCE m_hInstance;
  103. int m_ignore_wm_destroy;
  104. int m_minimize_winamp;
  105. int m_winamp_minimized;
  106. int m_truly_exiting;
  107. int m_bpp;
  108. embedWindowState myWindowState;
  109. void WriteSafeWindowPos();
  110. int GetWindowedModeAutoSize(int iteration);
  111. BOOL TestDepth(int ordinal_adapter, D3DFORMAT fmt);
  112. BOOL TestFormat(int ordinal_adapter, D3DFORMAT fmt);
  113. int CheckAndCorrectFullscreenDispMode(int ordinal_adapter, D3DDISPLAYMODE *pdm);
  114. void SetViewport();
  115. void MinimizeWinamp(HMONITOR hPluginMonitor);
  116. BOOL Internal_Init(DXCONTEXT_PARAMS *pParams, BOOL bFirstInit);
  117. void Internal_CleanUp();
  118. void RestoreWinamp();
  119. void GetSnappedClientSize(); //windowed mode only
  120. };
  121. #define DXC_ERR_REGWIN -2
  122. #define DXC_ERR_CREATEWIN -3
  123. #define DXC_ERR_CREATE3D -4
  124. #define DXC_ERR_GETFORMAT -5
  125. #define DXC_ERR_FORMAT -6
  126. #define DXC_ERR_CREATEDEV_PROBABLY_OUTOFVIDEOMEMORY -7
  127. #define DXC_ERR_RESIZEFAILED -8
  128. #define DXC_ERR_CAPSFAIL -9
  129. #define DXC_ERR_BAD_FS_DISPLAYMODE -10
  130. #define DXC_ERR_USER_CANCELED -11
  131. #define DXC_ERR_CREATEDEV_NOT_AVAIL -12
  132. #define DXC_ERR_CREATEDDRAW -13
  133. #endif