GSopen2: Current status...

* Software mode seems to work fine.  Suspend and resume emulation work nicely, without flaws.
 * Hardware DX9 mode suspends but displays only black after resuming.
 * Hardware DX10 status is unknown.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/GSopen2@1842 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
Jake.Stine 2009-09-17 07:40:38 +00:00
parent e6149c7c13
commit 8de579954f
21 changed files with 177 additions and 88 deletions

View File

@ -78,14 +78,21 @@ EXPORT_C_(INT32) GSinit()
return -1;
}
#ifdef _WINDOWS
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(!GSUtil::CheckDirectX())
{
return -1;
}
#endif
return 0;
}
EXPORT_C GSshutdown()
{
}
EXPORT_C GSclose()
{
delete s_gs;
@ -103,61 +110,103 @@ EXPORT_C GSclose()
#endif
}
EXPORT_C GSclose()
{
if( !s_gs ) return;
s_gs->ResetDevice();
if( s_gs->m_dev )
s_gs->m_dev->Reset(1, 1, GSDevice::Windowed);
delete s_gs->m_dev;
s_gs->m_dev = NULL;
s_gs->m_wnd.Detach();
}
static INT32 GSopen(void* dsp, char* title, int mt, int renderer)
{
GSclose();
#ifdef _WINDOWS
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
if(!GSUtil::CheckDirectX())
{
return -1;
}
#endif
GSDevice* dev = NULL;
switch(renderer)
{
default:
case 0: s_gs = new GSRendererDX9(s_basemem, !!mt, s_irq); break;
case 1: s_gs = new GSRendererSW(s_basemem, !!mt, s_irq, new GSDevice9()); break;
case 2: s_gs = new GSRendererNull(s_basemem, !!mt, s_irq, new GSDevice9()); break;
case 3: s_gs = new GSRendererDX10(s_basemem, !!mt, s_irq); break;
case 4: s_gs = new GSRendererSW(s_basemem, !!mt, s_irq, new GSDevice10()); break;
case 5: s_gs = new GSRendererNull(s_basemem, !!mt, s_irq, new GSDevice10()); break;
case 6: s_gs = new GSRendererDX11(s_basemem, !!mt, s_irq); break;
case 7: s_gs = new GSRendererSW(s_basemem, !!mt, s_irq, new GSDevice11()); break;
case 8: s_gs = new GSRendererNull(s_basemem, !!mt, s_irq, new GSDevice11()); break;
#if 0
case 9: s_gs = new GSRendererOGL(s_basemem, !!mt, s_irq); break;
case 10: s_gs = new GSRendererSW(s_basemem, !!mt, s_irq, new GSDeviceOGL()); break;
case 11: s_gs = new GSRendererNull(s_basemem, !!mt, s_irq, new GSDeviceOGL()); break;
#endif
case 12: s_gs = new GSRendererSW(s_basemem, !!mt, s_irq, new GSDeviceNull()); break;
case 13: s_gs = new GSRendererNull(s_basemem, !!mt, s_irq, new GSDeviceNull()); break;
case 0: case 1: case 2: dev = new GSDevice9(); break;
case 3: case 4: case 5: dev = new GSDevice10(); break;
case 6: case 7: case 8: dev = new GSDevice11(); break;
#if 0
case 9: case 10: case 11: dev = new GSDeviceOGL(); break;
#endif
case 12: case 13: new GSDeviceNull(); break;
}
if( !dev ) return -1;
if( !s_gs )
{
switch(renderer)
{
default:
case 0: s_gs = new GSRendererDX9(s_basemem, !!mt, s_irq); break;
case 3: s_gs = new GSRendererDX10(s_basemem, !!mt, s_irq); break;
case 6: s_gs = new GSRendererDX11(s_basemem, !!mt, s_irq); break;
#if 0
case 9: s_gs = new GSRendererOGL(s_basemem, !!mt, s_irq); break;
#endif
case 2: case 5: case 8: case 11: case 13:
s_gs = new GSRendererNull(s_basemem, !!mt, s_irq); break;
case 1: case 4: case 7: case 10: case 12:
s_gs = new GSRendererSW(s_basemem, !!mt, s_irq); break;
}
}
if( *(HWND*)dsp == NULL )
{
// old-style API expects us to create and manage our own window:
int w = theApp.GetConfig("ModeWidth", 0);
int h = theApp.GetConfig("ModeHeight", 0);
if(!s_gs->Create(title, w, h))
if(!s_gs->CreateWnd(title, w, h))
{
GSclose();
return -1;
}
s_gs->m_wnd.Show();
*(HWND*)dsp = (HWND)s_gs->m_wnd.GetHandle();
}
else
{
s_gs->m_wnd.Attach( *(HWND*)dsp, false );
}
if( !s_gs->CreateDevice(dev) )
{
GSclose();
return -1;
}
// if(mt) _mm_setcsr(MXCSR);
return 0;
}
EXPORT_C_(INT32) GSopen2(void* dsp, INT32 forceSoftware )
{
int renderer = theApp.GetConfig("renderer", 0);
if( forceSoftware )
{
renderer = 1;
}
return GSopen( dsp, NULL, true, renderer );
}
EXPORT_C_(INT32) GSopen(void* dsp, char* title, int mt)
{
int renderer;
@ -174,6 +223,7 @@ EXPORT_C_(INT32) GSopen(void* dsp, char* title, int mt)
renderer = theApp.GetConfig("renderer", 0);
}
*(HWND*)dsp = NULL;
return GSopen(dsp, title, mt, renderer);
}

View File

@ -79,7 +79,7 @@ bool GSDevice::Reset(int w, int h, int mode)
m_current = NULL; // current is special, points to other textures, no need to delete
return true;
return m_wnd != NULL;
}
void GSDevice::Present(const GSVector4i& r, int shader, bool limit)

View File

@ -22,9 +22,9 @@
#include "StdAfx.h"
#include "GSRenderer.h"
GSRenderer::GSRenderer(uint8* base, bool mt, void (*irq)(), GSDevice* dev)
GSRenderer::GSRenderer(uint8* base, bool mt, void (*irq)())
: GSState(base, mt, irq)
, m_dev(dev)
, m_dev(NULL)
, m_shader(0)
, m_vt(this)
{
@ -55,21 +55,26 @@ GSRenderer::~GSRenderer()
delete m_dev;
}
bool GSRenderer::Create(const string& title, int w, int h)
bool GSRenderer::CreateWnd(const string& title, int w, int h)
{
if(!m_wnd.Create(title.c_str(), w, h))
{
return false;
}
return true;
}
ASSERT(m_dev);
bool GSRenderer::CreateDevice(GSDevice* dev)
{
ASSERT(dev);
ASSERT(!m_dev);
if(!m_dev->Create(&m_wnd, m_vsync))
if(!dev->Create(&m_wnd, m_vsync))
{
return false;
}
Reset();
m_dev = dev;
return true;
}
@ -316,7 +321,11 @@ void GSRenderer::VSync(int field)
s += " | Recording...";
}
m_wnd.SetWindowText(s.c_str());
if( !m_wnd.SetWindowText(s.c_str()) )
{
// We don't have window title rights, or the window has no title,
// so let's use actual OSD!
}
}
if(m_frameskip)

View File

@ -46,7 +46,6 @@ protected:
bool m_aa1;
bool m_blur;
virtual void ResetDevice() {}
virtual GSTexture* GetOutput(int i) = 0;
GSVertexTrace m_vt;
@ -70,10 +69,12 @@ public:
int s_saven;
public:
GSRenderer(uint8* base, bool mt, void (*irq)(), GSDevice* dev);
GSRenderer(uint8* base, bool mt, void (*irq)());
virtual ~GSRenderer();
virtual bool Create(const string& title, int w, int h);
virtual bool CreateWnd(const string& title, int w, int h);
virtual bool CreateDevice(GSDevice* dev);
virtual void ResetDevice() {}
virtual void VSync(int field);
virtual bool MakeSnapshot(const string& path);
virtual void KeyEvent(GSKeyEventData* e, int param = 0);
@ -212,8 +213,8 @@ protected:
virtual void Draw() = 0;
public:
GSRendererT(uint8* base, bool mt, void (*irq)(), GSDevice* dev)
: GSRenderer(base, mt, irq, dev)
GSRendererT(uint8* base, bool mt, void (*irq)())
: GSRenderer(base, mt, irq)
, m_vertices(NULL)
, m_count(0)
, m_maxcount(0)

View File

@ -41,8 +41,8 @@ protected:
virtual void UpdateFBA(GSTexture* rt) {}
public:
GSRendererDX(uint8* base, bool mt, void (*irq)(), GSDevice* dev, GSTextureCache* tc, GSTextureFX* tfx, const GSVector2& pixelcenter = GSVector2(0, 0))
: GSRendererHW<Vertex>(base, mt, irq, dev, tc)
GSRendererDX(uint8* base, bool mt, void (*irq)(), GSTextureCache* tc, GSTextureFX* tfx, const GSVector2& pixelcenter = GSVector2(0, 0))
: GSRendererHW<Vertex>(base, mt, irq, tc)
, m_tfx(tfx)
, m_pixelcenter(pixelcenter)
, m_topology(-1)
@ -58,9 +58,9 @@ public:
delete m_tfx;
}
bool Create(const string& title, int w, int h)
bool CreateDevice(GSDevice* dev)
{
if(!__super::Create(title, w, h))
if(!__super::CreateDevice(dev))
return false;
if(!m_tfx->Create(m_dev))

View File

@ -25,14 +25,14 @@
#include "resource.h"
GSRendererDX10::GSRendererDX10(uint8* base, bool mt, void (*irq)())
: GSRendererDX<GSVertexHW10>(base, mt, irq, new GSDevice10(), new GSTextureCache10(this), new GSTextureFX10(), GSVector2(-0.5f, -0.5f))
: GSRendererDX<GSVertexHW10>(base, mt, irq, new GSTextureCache10(this), new GSTextureFX10(), GSVector2(-0.5f, -0.5f))
{
InitVertexKick<GSRendererDX10>();
}
bool GSRendererDX10::Create(const string& title, int w, int h)
bool GSRendererDX10::CreateDevice(GSDevice* dev)
{
if(!__super::Create(title, w, h))
if(!__super::CreateDevice(dev))
return false;
//

View File

@ -41,7 +41,7 @@ protected:
public:
GSRendererDX10(uint8* base, bool mt, void (*irq)());
bool Create(const string& title, int w, int h);
bool CreateDevice(GSDevice* dev);
template<uint32 prim, uint32 tme, uint32 fst> void VertexKick(bool skip);
};

View File

@ -25,14 +25,14 @@
#include "resource.h"
GSRendererDX11::GSRendererDX11(uint8* base, bool mt, void (*irq)())
: GSRendererDX<GSVertexHW11>(base, mt, irq, new GSDevice11(), new GSTextureCache11(this), new GSTextureFX11(), GSVector2(-0.5f, -0.5f))
: GSRendererDX<GSVertexHW11>(base, mt, irq, new GSTextureCache11(this), new GSTextureFX11(), GSVector2(-0.5f, -0.5f))
{
InitVertexKick<GSRendererDX11>();
}
bool GSRendererDX11::Create(const string& title, int w, int h)
bool GSRendererDX11::CreateDevice(GSDevice* dev)
{
if(!__super::Create(title, w, h))
if(!__super::CreateDevice(dev))
return false;
//

View File

@ -42,7 +42,7 @@ protected:
public:
GSRendererDX11(uint8* base, bool mt, void (*irq)());
bool Create(const string& title, int w, int h);
bool CreateDevice(GSDevice* dev);
template<uint32 prim, uint32 tme, uint32 fst> void VertexKick(bool skip);
};

View File

@ -25,14 +25,14 @@
#include "resource.h"
GSRendererDX9::GSRendererDX9(uint8* base, bool mt, void (*irq)())
: GSRendererDX<GSVertexHW9>(base, mt, irq, new GSDevice9(), new GSTextureCache9(this), new GSTextureFX9())
: GSRendererDX<GSVertexHW9>(base, mt, irq, new GSTextureCache9(this), new GSTextureFX9())
{
InitVertexKick<GSRendererDX9>();
}
bool GSRendererDX9::Create(const string& title, int w, int h)
bool GSRendererDX9::CreateDevice(GSDevice* dev)
{
if(!__super::Create(title, w, h))
if(!__super::CreateDevice(dev))
return false;
//

View File

@ -48,7 +48,7 @@ protected:
public:
GSRendererDX9(uint8* base, bool mt, void (*irq)());
bool Create(const string& title, int w, int h);
bool CreateDevice(GSDevice* dev);
template<uint32 prim, uint32 tme, uint32 fst> void VertexKick(bool skip);
};

View File

@ -703,8 +703,8 @@ protected:
}
public:
GSRendererHW(uint8* base, bool mt, void (*irq)(), GSDevice* dev, GSTextureCache* tc)
: GSRendererT<Vertex>(base, mt, irq, dev)
GSRendererHW(uint8* base, bool mt, void (*irq)(), GSTextureCache* tc)
: GSRendererT<Vertex>(base, mt, irq)
, m_tc(tc)
, m_width(1024)
, m_height(1024)

View File

@ -37,8 +37,8 @@ protected:
}
public:
GSRendererNull(uint8* base, bool mt, void (*irq)(), GSDevice* dev)
: GSRendererT<GSVertexNull>(base, mt, irq, dev)
GSRendererNull(uint8* base, bool mt, void (*irq)())
: GSRendererT<GSVertexNull>(base, mt, irq)
{
InitVertexKick<GSRendererNull>();
}

View File

@ -25,14 +25,14 @@
#include "resource.h"
GSRendererOGL::GSRendererOGL(uint8* base, bool mt, void (*irq)())
: GSRendererHW<GSVertexOGL>(base, mt, irq, new GSDeviceOGL(), new GSTextureCacheOGL(this))
: GSRendererHW<GSVertexOGL>(base, mt, irq, new GSTextureCacheOGL(this))
{
InitVertexKick<GSRendererOGL>();
}
bool GSRendererOGL::Create(const string& title, int w, int h)
bool GSRendererOGL::CreateDevice(GSDevice* dev)
{
if(!__super::Create(title, w, h))
if(!__super::CreateDevice(dev))
return false;
// TODO

View File

@ -34,7 +34,7 @@ protected:
public:
GSRendererOGL(uint8* base, bool mt, void (*irq)());
bool Create(const string& title, int w, int h);
bool CreateDevice(GSDevice* dev);
template<uint32 prim, uint32 tme, uint32 fst> void VertexKick(bool skip);
};

View File

@ -24,8 +24,8 @@
const GSVector4 g_pos_scale(1.0f / 16, 1.0f / 16, 1.0f, 128.0f);
GSRendererSW::GSRendererSW(uint8* base, bool mt, void (*irq)(), GSDevice* dev)
: GSRendererT(base, mt, irq, dev)
GSRendererSW::GSRendererSW(uint8* base, bool mt, void (*irq)())
: GSRendererT(base, mt, irq)
{
m_tc = new GSTextureCacheSW(this);

View File

@ -44,7 +44,7 @@ protected:
void GetScanlineParam(GSScanlineParam& p, GS_PRIM_CLASS primclass);
public:
GSRendererSW(uint8* base, bool mt, void (*irq)(), GSDevice* dev);
GSRendererSW(uint8* base, bool mt, void (*irq)());
virtual ~GSRendererSW();
template<uint32 prim, uint32 tme, uint32 fst>

View File

@ -25,6 +25,8 @@
GSWnd::GSWnd()
: m_hWnd(NULL)
, m_IsManaged(true)
, m_HasFrame(true)
{
}
@ -77,6 +79,8 @@ LRESULT GSWnd::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
bool GSWnd::Create(const string& title, int w, int h)
{
if(m_hWnd) return true;
WNDCLASS wc;
memset(&wc, 0, sizeof(wc));
@ -134,15 +138,22 @@ bool GSWnd::Create(const string& title, int w, int h)
return true;
}
bool GSWnd::Attach(HWND hWnd)
bool GSWnd::Attach(HWND hWnd, bool isManaged)
{
// TODO: subclass
m_hWnd = hWnd;
m_IsManaged = isManaged;
return true;
}
void GSWnd::Detach()
{
m_hWnd = NULL;
m_IsManaged = true;
}
GSVector4i GSWnd::GetClientRect()
{
GSVector4i r;
@ -152,13 +163,21 @@ GSVector4i GSWnd::GetClientRect()
return r;
}
void GSWnd::SetWindowText(const char* title)
// Returns FALSE if the window has no title, or if th window title is under the strict
// management of the emulator.
bool GSWnd::SetWindowText(const char* title)
{
if( !m_IsManaged ) return false;
::SetWindowText(m_hWnd, title);
return m_HasFrame;
}
void GSWnd::Show()
{
if( !m_IsManaged ) return;
//SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
SetForegroundWindow(m_hWnd);
@ -170,14 +189,20 @@ void GSWnd::Show()
void GSWnd::Hide()
{
if( !m_IsManaged ) return;
ShowWindow(m_hWnd, SW_HIDE);
}
void GSWnd::HideFrame()
{
if( !m_IsManaged ) return;
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & ~(WS_CAPTION|WS_THICKFRAME));
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
SetMenu(m_hWnd, NULL);
m_HasFrame = false;
}

View File

@ -26,6 +26,8 @@
class GSWnd
{
HWND m_hWnd;
bool m_IsManaged; // set true when we're attached to a 3rdparty window that's amanged by the emulator
bool m_HasFrame;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
@ -35,13 +37,14 @@ public:
virtual ~GSWnd();
bool Create(const string& title, int w, int h);
bool Attach(HWND hWnd);
bool Attach(HWND hWnd, bool isManaged=true);
void Detach();
void* GetHandle() {return m_hWnd;}
GSVector4i GetClientRect();
void SetWindowText(const char* title);
bool SetWindowText(const char* title);
void Show();
void Hide();

View File

@ -12,6 +12,7 @@ EXPORTS
GSinit
GSshutdown
GSopen
GSopen2
GSclose
GSreset
GSwriteCSR

View File

@ -1197,10 +1197,6 @@
/>
</FileConfiguration>
</File>
<File
RelativePath=".\GSdx.def"
>
</File>
<File
RelativePath=".\GSFunctionMap.cpp"
>
@ -1977,6 +1973,10 @@
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File
RelativePath=".\GSdx.def"
>
</File>
<File
RelativePath=".\GSdx.rc"
>