+ return new wxDisplayImplDirectDraw(n, *info, info->m_pDD2);
+}
+
+// ============================================================================
+// wxDisplayImplDirectDraw
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// video modes enumeration
+// ----------------------------------------------------------------------------
+
+// tiny helper class used to pass information from GetModes() to
+// wxDDEnumModesCallback
+class wxDDVideoModesAdder
+{
+public:
+ // our Add() method will add modes matching modeMatch to modes array
+ wxDDVideoModesAdder(wxArrayVideoModes& modes, const wxVideoMode& modeMatch)
+ : m_modes(modes),
+ m_modeMatch(modeMatch)
+ {
+ }
+
+ void Add(const wxVideoMode& mode)
+ {
+ if ( mode.Matches(m_modeMatch) )
+ m_modes.Add(mode);
+ }
+
+private:
+ wxArrayVideoModes& m_modes;
+ const wxVideoMode& m_modeMatch;
+
+ DECLARE_NO_COPY_CLASS(wxDDVideoModesAdder)
+};
+
+HRESULT WINAPI wxDDEnumModesCallback(LPDDSURFACEDESC lpDDSurfaceDesc,
+ LPVOID lpContext)
+{
+ // we need at least the mode size
+ static const DWORD FLAGS_REQUIRED = DDSD_HEIGHT | DDSD_WIDTH;
+ if ( (lpDDSurfaceDesc->dwFlags & FLAGS_REQUIRED) == FLAGS_REQUIRED )
+ {
+ wxDDVideoModesAdder * const vmodes =
+ wx_static_cast(wxDDVideoModesAdder *, lpContext);
+
+ vmodes->Add(wxVideoMode(lpDDSurfaceDesc->dwWidth,
+ lpDDSurfaceDesc->dwHeight,
+ lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount,
+ lpDDSurfaceDesc->dwRefreshRate));
+ }
+
+ // continue the enumeration
+ return DDENUMRET_OK;
+}
+
+wxArrayVideoModes
+wxDisplayImplDirectDraw::GetModes(const wxVideoMode& modeMatch) const
+{
+ wxArrayVideoModes modes;
+ wxDDVideoModesAdder modesAdder(modes, modeMatch);
+
+ HRESULT hr = m_pDD2->EnumDisplayModes
+ (
+ DDEDM_REFRESHRATES,
+ NULL, // all modes
+ &modesAdder, // callback parameter
+ wxDDEnumModesCallback
+ );
+
+ if ( FAILED(hr) )
+ {
+ wxLogApiError(_T("IDirectDraw::EnumDisplayModes"), hr);
+ }
+
+ return modes;
+}
+
+// ----------------------------------------------------------------------------
+// video mode switching
+// ----------------------------------------------------------------------------
+
+bool wxDisplayImplDirectDraw::ChangeMode(const wxVideoMode& mode)
+{
+ wxWindow *winTop = wxTheApp->GetTopWindow();
+ wxCHECK_MSG( winTop, false, _T("top level window required for DirectX") );
+
+ HRESULT hr = m_pDD2->SetCooperativeLevel
+ (
+ GetHwndOf(winTop),
+ DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN
+ );
+ if ( FAILED(hr) )
+ {
+ wxLogApiError(_T("IDirectDraw2::SetCooperativeLevel"), hr);
+
+ return false;
+ }
+
+ hr = m_pDD2->SetDisplayMode(mode.w, mode.h, mode.bpp, mode.refresh, 0);
+ if ( FAILED(hr) )
+ {
+ wxLogApiError(_T("IDirectDraw2::SetDisplayMode"), hr);
+
+ return false;
+ }
+
+ return true;
+}
+
+#endif // wxUSE_DIRECTDRAW
+
+#endif // wxUSE_DISPLAY