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