OSDN Git Service

Merge branch 'feature/37178_プロジェクトとソリューションファイルの英語化' into develop
[dtxmania/dtxmania.git] / FDK17プロジェクト / コード / 01.フレームワーク / Rendering / GraphicsDeviceManager.cs
diff --git a/FDK17プロジェクト/コード/01.フレームワーク/Rendering/GraphicsDeviceManager.cs b/FDK17プロジェクト/コード/01.フレームワーク/Rendering/GraphicsDeviceManager.cs
deleted file mode 100644 (file)
index f47c62d..0000000
+++ /dev/null
@@ -1,721 +0,0 @@
-/*\r
-* Copyright (c) 2007-2009 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-using System;\r
-using System.ComponentModel;\r
-using System.Drawing;\r
-using System.Runtime.InteropServices;\r
-using System.Text;\r
-using System.Threading;\r
-using System.Windows.Forms;\r
-using SharpDX;\r
-using SharpDX.Direct3D9;\r
-using SharpDX.DXGI;\r
-using System.Diagnostics;\r
-\r
-using Rectangle = System.Drawing.Rectangle;\r
-\r
-namespace SampleFramework\r
-{\r
-    /// <summary>\r
-    /// Handles the configuration and management of the graphics device.\r
-    /// </summary>\r
-    public class GraphicsDeviceManager : IDisposable\r
-    {\r
-        Game game;\r
-        bool ignoreSizeChanges;\r
-        bool deviceLost;\r
-//        bool doNotStoreBufferSize;\r
-//        bool renderingOccluded;\r
-\r
-        int fullscreenWindowWidth;\r
-        int fullscreenWindowHeight;\r
-        int windowedWindowWidth;\r
-        int windowedWindowHeight;\r
-        WINDOWPLACEMENT windowedPlacement;\r
-        long windowedStyle;\r
-        bool savedTopmost;\r
-\r
-#if TEST_Direct3D9Ex\r
-               internal static Direct3DEx Direct3D9Object                      // yyagi\r
-#else\r
-               internal static Direct3D Direct3D9Object\r
-#endif\r
-               {\r
-            get;\r
-            private set;\r
-        }\r
-\r
-        public DeviceSettings CurrentSettings\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-        public bool IsWindowed\r
-        {\r
-            get { return CurrentSettings.Windowed; }\r
-        }\r
-        public int ScreenWidth\r
-        {\r
-            get { return CurrentSettings.BackBufferWidth; }\r
-        }\r
-        public int ScreenHeight\r
-        {\r
-            get { return CurrentSettings.BackBufferHeight; }\r
-        }\r
-        public Size ScreenSize\r
-        {\r
-            get { return new Size(CurrentSettings.BackBufferWidth, CurrentSettings.BackBufferHeight); }\r
-        }\r
-        public Direct3D9Manager Direct3D9\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-        public string DeviceStatistics\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-        public string DeviceInformation\r
-        {\r
-            get;\r
-            private set;\r
-        }\r
-\r
-               public GraphicsDeviceManager( Game game )\r
-               {\r
-                       if( game == null )\r
-                               throw new ArgumentNullException( "game" );\r
-\r
-                       this.game = game;\r
-\r
-                       game.Window.ScreenChanged += Window_ScreenChanged;\r
-                       game.Window.UserResized += Window_UserResized;\r
-\r
-                       game.FrameStart += game_FrameStart;\r
-                       game.FrameEnd += game_FrameEnd;\r
-\r
-                       Direct3D9 = new Direct3D9Manager( this );\r
-               }\r
-\r
-        public void Dispose()\r
-        {\r
-            Dispose(true);\r
-            GC.SuppressFinalize(this);\r
-        }\r
-\r
-               public void ChangeDevice( DeviceSettings settings, DeviceSettings minimumSettings )\r
-               {\r
-                       if( settings == null )\r
-                               throw new ArgumentNullException( "settings" );\r
-\r
-                       Enumeration9.MinimumSettings = minimumSettings;\r
-\r
-                       DeviceSettings validSettings = DeviceSettings.FindValidSettings( settings );\r
-\r
-                       var pp = validSettings.Direct3D9.PresentParameters;\r
-                       pp.DeviceWindowHandle = game.Window.Handle;\r
-                       validSettings.Direct3D9.PresentParameters = pp;\r
-\r
-                       CreateDevice( validSettings );\r
-               }\r
-        public void ChangeDevice(bool windowed, int desiredWidth, int desiredHeight)\r
-        {\r
-            DeviceSettings desiredSettings = new DeviceSettings();\r
-            desiredSettings.Windowed = windowed;\r
-            desiredSettings.BackBufferWidth = desiredWidth;\r
-            desiredSettings.BackBufferHeight = desiredHeight;\r
-\r
-            ChangeDevice(desiredSettings, null);\r
-        }\r
-        public void ChangeDevice(DeviceSettings settings)\r
-        {\r
-            ChangeDevice(settings, null);\r
-        }\r
-\r
-        public void ToggleFullScreen()\r
-        {\r
-            if (!EnsureDevice())\r
-                throw new InvalidOperationException("No valid device.");\r
-\r
-            DeviceSettings newSettings = CurrentSettings.Clone();\r
-\r
-            newSettings.Windowed = !newSettings.Windowed;\r
-\r
-            int width = newSettings.Windowed ? windowedWindowWidth : fullscreenWindowWidth;\r
-            int height = newSettings.Windowed ? windowedWindowHeight : fullscreenWindowHeight;\r
-\r
-            newSettings.BackBufferWidth = width;\r
-            newSettings.BackBufferHeight = height;\r
-\r
-            ChangeDevice(newSettings);\r
-        }\r
-        public bool EnsureDevice()\r
-        {\r
-            if (Direct3D9.Device != null && !deviceLost)\r
-                return true;\r
-\r
-            return false;\r
-        }\r
-\r
-               protected virtual void Dispose( bool disposing )\r
-               {\r
-                       if( this.bDisposed )\r
-                               return;\r
-                       this.bDisposed = true;\r
-\r
-                       if( disposing )\r
-                               ReleaseDevice();\r
-\r
-               }\r
-               private bool bDisposed = false;\r
-\r
-        void CreateDevice(DeviceSettings settings)\r
-        {\r
-            DeviceSettings oldSettings = CurrentSettings;\r
-            CurrentSettings = settings;\r
-\r
-            ignoreSizeChanges = true;\r
-\r
-            bool keepCurrentWindowSize = false;\r
-            if (settings.BackBufferWidth == 0 && settings.BackBufferHeight == 0)\r
-                keepCurrentWindowSize = true;\r
-\r
-            // handle the window state in Direct3D9 (it will be handled for us in DXGI)\r
-                // check if we are going to windowed or fullscreen mode\r
-                       if( settings.Windowed )\r
-                       {\r
-                               if( oldSettings != null && !oldSettings.Windowed )\r
-                                       NativeMethods.SetWindowLong( game.Window.Handle, WindowConstants.GWL_STYLE, (uint) windowedStyle );\r
-                       }\r
-                       else\r
-                       {\r
-                               if( oldSettings == null || oldSettings.Windowed )\r
-                               {\r
-                                       savedTopmost = game.Window.TopMost;\r
-                                       long style = NativeMethods.GetWindowLong( game.Window.Handle, WindowConstants.GWL_STYLE );\r
-                                       style &= ~WindowConstants.WS_MAXIMIZE & ~WindowConstants.WS_MINIMIZE;\r
-                                       windowedStyle = style;\r
-\r
-                                       windowedPlacement = new WINDOWPLACEMENT();\r
-                                       windowedPlacement.length = WINDOWPLACEMENT.Length;\r
-                                       NativeMethods.GetWindowPlacement( game.Window.Handle, ref windowedPlacement );\r
-                               }\r
-\r
-                               // hide the window until we are done messing with it\r
-                               game.Window.Hide();\r
-                               NativeMethods.SetWindowLong( game.Window.Handle, WindowConstants.GWL_STYLE, (uint) ( WindowConstants.WS_POPUP | WindowConstants.WS_SYSMENU ) );\r
-\r
-                               WINDOWPLACEMENT placement = new WINDOWPLACEMENT();\r
-                               placement.length = WINDOWPLACEMENT.Length;\r
-                               NativeMethods.GetWindowPlacement( game.Window.Handle, ref placement );\r
-\r
-                               // check if we are in the middle of a restore\r
-                               if( ( placement.flags & WindowConstants.WPF_RESTORETOMAXIMIZED ) != 0 )\r
-                               {\r
-                                       // update the flags to avoid sizing issues\r
-                                       placement.flags &= ~WindowConstants.WPF_RESTORETOMAXIMIZED;\r
-                                       placement.showCmd = WindowConstants.SW_RESTORE;\r
-                                       NativeMethods.SetWindowPlacement( game.Window.Handle, ref placement );\r
-                               }\r
-                       }\r
-\r
-            if (settings.Windowed)\r
-            {\r
-                if (oldSettings != null && !oldSettings.Windowed)\r
-                {\r
-                    fullscreenWindowWidth = oldSettings.BackBufferWidth;\r
-                    fullscreenWindowHeight = oldSettings.BackBufferHeight;\r
-                }\r
-            }\r
-            else\r
-            {\r
-                if (oldSettings != null && oldSettings.Windowed)\r
-                {\r
-                    windowedWindowWidth = oldSettings.BackBufferWidth;\r
-                    windowedWindowHeight = oldSettings.BackBufferHeight;\r
-                }\r
-            }\r
-\r
-            // check if the device can be reset, or if we need to completely recreate it\r
-            Result result = SharpDX.Direct3D9.ResultCode.Success;\r
-            bool canReset = CanDeviceBeReset(oldSettings, settings);\r
-            if (canReset)\r
-                result = ResetDevice();\r
-\r
-            if (result == SharpDX.Direct3D9.ResultCode.DeviceLost)\r
-                deviceLost = true;\r
-            else if (!canReset || result.Failure)\r
-            {\r
-                if (oldSettings != null)\r
-                    ReleaseDevice();\r
-\r
-                InitializeDevice();\r
-            }\r
-\r
-            UpdateDeviceInformation();\r
-\r
-            // check if we changed from fullscreen to windowed mode\r
-            if (oldSettings != null && !oldSettings.Windowed && settings.Windowed)\r
-            {\r
-                NativeMethods.SetWindowPlacement(game.Window.Handle, ref windowedPlacement);\r
-                game.Window.TopMost = savedTopmost;\r
-            }\r
-\r
-            // check if we need to resize\r
-            if (settings.Windowed && !keepCurrentWindowSize)\r
-            {\r
-                int width;\r
-                int height;\r
-                if (NativeMethods.IsIconic(game.Window.Handle))\r
-                {\r
-                    WINDOWPLACEMENT placement = new WINDOWPLACEMENT();\r
-                    placement.length = WINDOWPLACEMENT.Length;\r
-                    NativeMethods.GetWindowPlacement(game.Window.Handle, ref placement);\r
-\r
-                    // check if we are being restored\r
-                    if ((placement.flags & WindowConstants.WPF_RESTORETOMAXIMIZED) != 0 && placement.showCmd == WindowConstants.SW_SHOWMINIMIZED)\r
-                    {\r
-                        NativeMethods.ShowWindow(game.Window.Handle, WindowConstants.SW_RESTORE);\r
-\r
-                        Rectangle rect = NativeMethods.GetClientRectangle(game.Window.Handle);\r
-\r
-                        width = rect.Width;\r
-                        height = rect.Height;\r
-                        NativeMethods.ShowWindow(game.Window.Handle, WindowConstants.SW_MINIMIZE);\r
-                    }\r
-                    else\r
-                    {\r
-                        NativeRectangle frame = new NativeRectangle();\r
-                        NativeMethods.AdjustWindowRect(ref frame, (uint)windowedStyle, false);\r
-                        int frameWidth = frame.right - frame.left;\r
-                        int frameHeight = frame.bottom - frame.top;\r
-\r
-                        width = placement.rcNormalPosition.right - placement.rcNormalPosition.left - frameWidth;\r
-                        height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top - frameHeight;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    Rectangle rect = NativeMethods.GetClientRectangle(game.Window.Handle);\r
-                    width = rect.Width;\r
-                    height = rect.Height;\r
-                }\r
-\r
-                // check if we have a different desired size\r
-                if (width != settings.BackBufferWidth ||\r
-                    height != settings.BackBufferHeight)\r
-                {\r
-                    if (NativeMethods.IsIconic(game.Window.Handle))\r
-                        NativeMethods.ShowWindow(game.Window.Handle, WindowConstants.SW_RESTORE);\r
-                    if (NativeMethods.IsZoomed(game.Window.Handle))\r
-                        NativeMethods.ShowWindow(game.Window.Handle, WindowConstants.SW_RESTORE);\r
-\r
-                    NativeRectangle rect = new NativeRectangle();\r
-                    rect.right = settings.BackBufferWidth;\r
-                    rect.bottom = settings.BackBufferHeight;\r
-                    NativeMethods.AdjustWindowRect(ref rect,\r
-                        NativeMethods.GetWindowLong(game.Window.Handle, WindowConstants.GWL_STYLE), false);\r
-\r
-                    NativeMethods.SetWindowPos(game.Window.Handle, IntPtr.Zero, 0, 0, rect.right - rect.left,\r
-                        rect.bottom - rect.top, WindowConstants.SWP_NOZORDER | WindowConstants.SWP_NOMOVE);\r
-\r
-                    Rectangle r = NativeMethods.GetClientRectangle(game.Window.Handle);\r
-                    int clientWidth = r.Width;\r
-                    int clientHeight = r.Height;\r
-\r
-                    // check if the size was modified by Windows\r
-                    if (clientWidth != settings.BackBufferWidth ||\r
-                        clientHeight != settings.BackBufferHeight)\r
-                    {\r
-                        DeviceSettings newSettings = CurrentSettings.Clone();\r
-                        newSettings.BackBufferWidth = 0;\r
-                        newSettings.BackBufferHeight = 0;\r
-                        if (newSettings.Direct3D9 != null)\r
-                        {\r
-                                                       var pp = newSettings.Direct3D9.PresentParameters;\r
-                                                       pp.BackBufferWidth = GameWindowSize.Width;      // #23510 2010.10.31 add yyagi: to avoid setting BackBufferSize=ClientSize\r
-                                                       pp.BackBufferHeight = GameWindowSize.Height;   // #23510 2010.10.31 add yyagi: to avoid setting BackBufferSize=ClientSize\r
-                                                       newSettings.Direct3D9.PresentParameters = pp;\r
-                        }\r
-\r
-                        CreateDevice(newSettings);\r
-                    }\r
-                }\r
-            }\r
-\r
-            // if the window is still hidden, make sure it is shown\r
-            if (!game.Window.Visible)\r
-                NativeMethods.ShowWindow(game.Window.Handle, WindowConstants.SW_SHOW);\r
-\r
-            // set the execution state of the thread\r
-            if (!IsWindowed)\r
-                NativeMethods.SetThreadExecutionState(WindowConstants.ES_DISPLAY_REQUIRED | WindowConstants.ES_CONTINUOUS);\r
-            else\r
-                NativeMethods.SetThreadExecutionState(WindowConstants.ES_CONTINUOUS);\r
-\r
-            ignoreSizeChanges = false;\r
-        }\r
-\r
-               void Window_UserResized( object sender, EventArgs e )\r
-               {\r
-                       if( ignoreSizeChanges || !EnsureDevice() || ( !IsWindowed ) )\r
-                               return;\r
-\r
-                       DeviceSettings newSettings = CurrentSettings.Clone();\r
-\r
-                       Rectangle rect = NativeMethods.GetClientRectangle( game.Window.Handle );\r
-                       if( rect.Width != newSettings.BackBufferWidth || rect.Height != newSettings.BackBufferHeight )\r
-                       {\r
-                               newSettings.BackBufferWidth = 0;\r
-                               newSettings.BackBufferHeight = 0;\r
-                               var pp = newSettings.Direct3D9.PresentParameters;\r
-                               pp.BackBufferWidth = GameWindowSize.Width;              // #23510 2010.10.31 add yyagi: to avoid setting BackBufferSize=ClientSize\r
-                               pp.BackBufferHeight = GameWindowSize.Height;   // \r
-                               newSettings.Direct3D9.PresentParameters = pp;\r
-                               CreateDevice( newSettings );\r
-                       }\r
-               }\r
-               void Window_ScreenChanged( object sender, EventArgs e )\r
-               {\r
-                       if( !EnsureDevice() || !CurrentSettings.Windowed || ignoreSizeChanges )\r
-                               return;\r
-\r
-                       IntPtr windowMonitor = NativeMethods.MonitorFromWindow( game.Window.Handle, WindowConstants.MONITOR_DEFAULTTOPRIMARY );\r
-\r
-                       DeviceSettings newSettings = CurrentSettings.Clone();\r
-                       int adapterOrdinal = GetAdapterOrdinal( windowMonitor );\r
-                       if( adapterOrdinal == -1 )\r
-                               return;\r
-                       newSettings.Direct3D9.AdapterOrdinal = adapterOrdinal;\r
-\r
-                       newSettings.BackBufferWidth = 0;                                                                // #23510 2010.11.1 add yyagi to avoid to reset to 640x480 for the first time in XP.\r
-                       newSettings.BackBufferHeight = 0;                               //\r
-                       var pp = newSettings.Direct3D9.PresentParameters;\r
-                       pp.BackBufferWidth = GameWindowSize.Width;              //\r
-                       pp.BackBufferHeight = GameWindowSize.Height;   //\r
-                       newSettings.Direct3D9.PresentParameters = pp;\r
-\r
-                       CreateDevice( newSettings);\r
-               }\r
-\r
-               void game_FrameEnd( object sender, EventArgs e )\r
-               {\r
-                       Result result = SharpDX.Direct3D9.ResultCode.Success;\r
-\r
-                       try\r
-                       {\r
-                               //result = Direct3D9.Device.TestCooperativeLevel();\r
-                               Direct3D9.Device.Present();\r
-                       }\r
-                       catch                   // #23842 2011.1.6 yyagi: catch D3D9Exception to avoid unexpected termination by changing VSyncWait in fullscreen.\r
-                       {\r
-                               deviceLost = true;\r
-                       }\r
-\r
-                       if( result == SharpDX.Direct3D9.ResultCode.DeviceLost )\r
-                               deviceLost = true;\r
-               }\r
-        void game_FrameStart(object sender, CancelEventArgs e)\r
-        {\r
-            if (Direct3D9.Device == null )\r
-            {\r
-                e.Cancel = true;\r
-                return;\r
-            }\r
-\r
-                       //if (!game.IsActive || deviceLost)             // #23568 2010.11.3 yyagi: separate conditions to support valiable sleep value when !IsActive.\r
-                       if( deviceLost )\r
-                               Thread.Sleep( 50 );\r
-                       else if( !game.IsActive && !this.CurrentSettings.EnableVSync )  // #23568 2010.11.4 yyagi: Don't add sleep() while VSync is enabled.\r
-                               Thread.Sleep( this.game.InactiveSleepTime.Milliseconds );\r
-\r
-            if (deviceLost)\r
-            {\r
-                Result result = Direct3D9.Device.TestCooperativeLevel();\r
-                if (result == SharpDX.Direct3D9.ResultCode.DeviceLost)\r
-                {\r
-                    e.Cancel = true;\r
-                    return;\r
-                }\r
-\r
-                // if we are windowed, check the adapter format to see if the user\r
-                // changed the desktop format, causing a lost device\r
-                if (IsWindowed)\r
-                {\r
-                    DisplayMode displayMode = GraphicsDeviceManager.Direct3D9Object.GetAdapterDisplayMode(CurrentSettings.Direct3D9.AdapterOrdinal);\r
-                    if (CurrentSettings.Direct3D9.AdapterFormat != displayMode.Format)\r
-                    {\r
-                        DeviceSettings newSettings = CurrentSettings.Clone();\r
-                        ChangeDevice(newSettings);\r
-                        e.Cancel = true;\r
-                        return;\r
-                    }\r
-                }\r
-\r
-                result = ResetDevice();\r
-                if (result.Failure)\r
-                {\r
-                    e.Cancel = true;\r
-                    return;\r
-                }\r
-            }\r
-\r
-            deviceLost = false;\r
-        }\r
-\r
-               bool CanDeviceBeReset( DeviceSettings oldSettings, DeviceSettings newSettings )\r
-               {\r
-                       if( oldSettings == null )\r
-                               return false;\r
-\r
-                       return Direct3D9.Device != null &&\r
-                               oldSettings.Direct3D9.AdapterOrdinal == newSettings.Direct3D9.AdapterOrdinal &&\r
-                               oldSettings.Direct3D9.DeviceType == newSettings.Direct3D9.DeviceType &&\r
-                               oldSettings.Direct3D9.CreationFlags == newSettings.Direct3D9.CreationFlags;\r
-               }\r
-\r
-        void InitializeDevice()\r
-        {\r
-                       try\r
-                       {\r
-                               EnsureD3D9();\r
-\r
-#if TEST_Direct3D9Ex\r
-                               // 2011.4.26 yyagi\r
-                               // Direct3D9.DeviceExを呼ぶ際(IDirect3D9Ex::CreateDeviceExを呼ぶ際)、\r
-                               // フルスクリーンモードで初期化する場合はDisplayModeEx(D3DDISPLAYMODEEX *pFullscreenDisplayMode)に\r
-                               // 適切な値を設定する必要あり。\r
-                               // 一方、ウインドウモードで初期化する場合は、D3DDISPLAYMODEEXをNULLにする必要があるが、\r
-                               // DisplayModeExがNULL不可と定義されているため、DeviceExのoverloadの中でDisplayModeExを引数に取らないものを\r
-                               // 使う。(DeviceEx側でD3DDISPLAYMODEEXをNULLにしてくれる)\r
-                               // 結局、DeviceExの呼び出しの際に、フルスクリーンかどうかで場合分けが必要となる。\r
-                               if ( CurrentSettings.Direct3D9.PresentParameters.Windowed == false )\r
-                               {\r
-                                       DisplayModeEx fullScreenDisplayMode = new DisplayModeEx();\r
-                                       fullScreenDisplayMode.Width = CurrentSettings.Direct3D9.PresentParameters.BackBufferWidth;\r
-                                       fullScreenDisplayMode.Height = CurrentSettings.Direct3D9.PresentParameters.BackBufferHeight;\r
-                                       fullScreenDisplayMode.RefreshRate = CurrentSettings.Direct3D9.PresentParameters.FullScreenRefreshRateInHertz;\r
-                                       fullScreenDisplayMode.Format = CurrentSettings.Direct3D9.PresentParameters.BackBufferFormat;\r
-\r
-                                       Direct3D9.Device = new SlimDX.Direct3D9.DeviceEx( Direct3D9Object, CurrentSettings.Direct3D9.AdapterOrdinal,\r
-                                               CurrentSettings.Direct3D9.DeviceType, game.Window.Handle,\r
-                                               CurrentSettings.Direct3D9.CreationFlags, CurrentSettings.Direct3D9.PresentParameters, fullScreenDisplayMode );\r
-                               }\r
-                               else\r
-                               {\r
-                                       Direct3D9.Device = new SlimDX.Direct3D9.DeviceEx( Direct3D9Object, CurrentSettings.Direct3D9.AdapterOrdinal,\r
-                                               CurrentSettings.Direct3D9.DeviceType, game.Window.Handle,\r
-                                               CurrentSettings.Direct3D9.CreationFlags, CurrentSettings.Direct3D9.PresentParameters );\r
-                               }\r
-                               Direct3D9.Device.MaximumFrameLatency = 1;\r
-#else\r
-                               Direct3D9.Device = new SharpDX.Direct3D9.Device(\r
-                                       Direct3D9Object,\r
-                                       CurrentSettings.Direct3D9.AdapterOrdinal,\r
-                                       CurrentSettings.Direct3D9.DeviceType,\r
-                                       game.Window.Handle,\r
-                                       CurrentSettings.Direct3D9.CreationFlags,\r
-                                       CurrentSettings.Direct3D9.PresentParameters );\r
-#endif\r
-                               if ( Result.GetResultFromWin32Error( Marshal.GetLastWin32Error() ) == SharpDX.Direct3D9.ResultCode.DeviceLost )\r
-                               {\r
-                                       deviceLost = true;\r
-                                       return;\r
-                               }\r
-#if TEST_Direct3D9Ex\r
-                               Direct3D9.Device.MaximumFrameLatency = 1;                       // yyagi\r
-#endif\r
-                       }\r
-                       catch( Exception e )\r
-                       {\r
-                               throw new DeviceCreationException( "Could not create graphics device.", e );\r
-                       }\r
-\r
-            PropogateSettings();\r
-\r
-            UpdateDeviceStats();\r
-\r
-            game.Initialize();\r
-            game.LoadContent();\r
-        }\r
-\r
-               Result ResetDevice()\r
-               {\r
-                       game.UnloadContent();\r
-\r
-                       Direct3D9.Device.Reset( CurrentSettings.Direct3D9.PresentParameters );\r
-\r
-                       var result = Result.GetResultFromWin32Error( Marshal.GetLastWin32Error() );\r
-\r
-                       if( result == SharpDX.Direct3D9.ResultCode.DeviceLost )\r
-                               return result;\r
-\r
-                       PropogateSettings();\r
-                       UpdateDeviceStats();\r
-                       game.LoadContent();\r
-\r
-                       return result;\r
-               }\r
-\r
-               void ReleaseDevice()\r
-        {\r
-            ReleaseDevice9();\r
-        }\r
-\r
-               void ReleaseDevice9()\r
-        {\r
-            if (Direct3D9.Device == null)\r
-                return;\r
-\r
-            if (game != null)\r
-            {\r
-                game.UnloadContent();\r
-                game.Dispose(true);\r
-            }\r
-\r
-                       try\r
-                       {\r
-                               Direct3D9.Device.Dispose();\r
-                       }\r
-                       catch( ObjectDisposedException )\r
-                       {\r
-                               // 時々発生するのでキャッチしておく。\r
-                       }\r
-            Direct3D9Object.Dispose();\r
-\r
-            Direct3D9Object = null;\r
-            Direct3D9.Device = null;\r
-        }\r
-               void PropogateSettings()\r
-               {\r
-                       CurrentSettings.BackBufferCount = CurrentSettings.Direct3D9.PresentParameters.BackBufferCount;\r
-                       CurrentSettings.BackBufferWidth = CurrentSettings.Direct3D9.PresentParameters.BackBufferWidth;\r
-                       CurrentSettings.BackBufferHeight = CurrentSettings.Direct3D9.PresentParameters.BackBufferHeight;\r
-                       CurrentSettings.BackBufferFormat = CurrentSettings.Direct3D9.PresentParameters.BackBufferFormat;\r
-                       CurrentSettings.DepthStencilFormat = CurrentSettings.Direct3D9.PresentParameters.AutoDepthStencilFormat;\r
-                       CurrentSettings.DeviceType = CurrentSettings.Direct3D9.DeviceType;\r
-                       CurrentSettings.MultisampleQuality = CurrentSettings.Direct3D9.PresentParameters.MultiSampleQuality;\r
-                       CurrentSettings.MultisampleType = CurrentSettings.Direct3D9.PresentParameters.MultiSampleType;\r
-                       CurrentSettings.RefreshRate = CurrentSettings.Direct3D9.PresentParameters.FullScreenRefreshRateInHz;\r
-                       CurrentSettings.Windowed = CurrentSettings.Direct3D9.PresentParameters.Windowed;\r
-               }\r
-\r
-               void UpdateDeviceInformation()\r
-               {\r
-                       StringBuilder builder = new StringBuilder();\r
-\r
-                       if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Hardware )\r
-                               builder.Append( "HAL" );\r
-                       else if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Reference )\r
-                               builder.Append( "REF" );\r
-                       else if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Software )\r
-                               builder.Append( "SW" );\r
-\r
-                       if( ( CurrentSettings.Direct3D9.CreationFlags & CreateFlags.HardwareVertexProcessing ) != 0 )\r
-                               if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Hardware )\r
-                                       builder.Append( " (hw vp)" );\r
-                               else\r
-                                       builder.Append( " (simulated hw vp)" );\r
-                       else if( ( CurrentSettings.Direct3D9.CreationFlags & CreateFlags.MixedVertexProcessing ) != 0 )\r
-                               if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Hardware )\r
-                                       builder.Append( " (mixed vp)" );\r
-                               else\r
-                                       builder.Append( " (simulated mixed vp)" );\r
-                       else\r
-                               builder.Append( " (sw vp)" );\r
-\r
-                       if( CurrentSettings.Direct3D9.DeviceType == DeviceType.Hardware )\r
-                       {\r
-                               // loop through each adapter until we find the right one\r
-                               foreach( AdapterInfo9 adapterInfo in Enumeration9.Adapters )\r
-                               {\r
-                                       if( adapterInfo.AdapterOrdinal == CurrentSettings.Direct3D9.AdapterOrdinal )\r
-                                       {\r
-                                               builder.AppendFormat( ": {0}", adapterInfo.Description );\r
-                                               break;\r
-                                       }\r
-                               }\r
-                       }\r
-\r
-                       DeviceInformation = builder.ToString();\r
-               }\r
-\r
-               void UpdateDeviceStats()\r
-               {\r
-                       StringBuilder builder = new StringBuilder();\r
-\r
-                       builder.Append( "D3D9 Vsync " );\r
-\r
-                       if( CurrentSettings.Direct3D9.PresentParameters.PresentationInterval == PresentInterval.Immediate )\r
-                               builder.Append( "off" );\r
-                       else\r
-                               builder.Append( "on" );\r
-\r
-                       builder.AppendFormat( " ({0}x{1}), ", CurrentSettings.Direct3D9.PresentParameters.BackBufferWidth, CurrentSettings.Direct3D9.PresentParameters.BackBufferHeight );\r
-\r
-                       if( CurrentSettings.Direct3D9.AdapterFormat == CurrentSettings.Direct3D9.PresentParameters.BackBufferFormat )\r
-                               builder.Append( Enum.GetName( typeof( SharpDX.Direct3D9.Format ), CurrentSettings.Direct3D9.AdapterFormat ) );\r
-                       else\r
-                               builder.AppendFormat( "backbuf {0}, adapter {1}",\r
-                                       Enum.GetName( typeof( SharpDX.Direct3D9.Format ), CurrentSettings.Direct3D9.AdapterFormat ),\r
-                                       Enum.GetName( typeof( SharpDX.Direct3D9.Format ), CurrentSettings.Direct3D9.PresentParameters.BackBufferFormat ) );\r
-\r
-                       builder.AppendFormat( " ({0})", Enum.GetName( typeof( SharpDX.Direct3D9.Format ), CurrentSettings.Direct3D9.PresentParameters.AutoDepthStencilFormat ) );\r
-\r
-                       if( CurrentSettings.Direct3D9.PresentParameters.MultiSampleType == MultisampleType.NonMaskable )\r
-                               builder.Append( " (Nonmaskable Multisample)" );\r
-                       else if( CurrentSettings.Direct3D9.PresentParameters.MultiSampleType != MultisampleType.None )\r
-                               builder.AppendFormat( " ({0}x Multisample)", (int) CurrentSettings.Direct3D9.PresentParameters.MultiSampleQuality );\r
-\r
-                       DeviceStatistics = builder.ToString();\r
-               }\r
-\r
-               int GetAdapterOrdinal( IntPtr screen )\r
-               {\r
-                       AdapterInfo9 adapter = null;\r
-                       foreach( AdapterInfo9 a in Enumeration9.Adapters )\r
-                       {\r
-                               if( Direct3D9Object.GetAdapterMonitor( a.AdapterOrdinal ) == screen )\r
-                               {\r
-                                       adapter = a;\r
-                                       break;\r
-                               }\r
-                       }\r
-\r
-                       if( adapter != null )\r
-                               return adapter.AdapterOrdinal;\r
-\r
-                       return -1;\r
-               }\r
-\r
-        internal static void EnsureD3D9()\r
-        {\r
-                       if ( Direct3D9Object == null )\r
-#if TEST_Direct3D9Ex\r
-                               Direct3D9Object = new Direct3DEx();             // yyagi\r
-#else\r
-                               Direct3D9Object = new Direct3D();\r
-#endif\r
-        }\r
-    }\r
-}\r