Exemple #1
0
        /// <summary>
        /// Creates or re-creates the DirectX device and the backbuffer. This is necessary in the initialization phase
        /// of the SkinEngine and after a parameter was changed which affects the DX device creation.
        /// </summary>
        internal static void DoReCreateDevice_MainThread()
        {
            try
            {
                // Note that only the thread which handles window messages is allowed to call CreateDevice and Reset
                // (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb147224%28v=vs.85%29.aspx )
                ServiceRegistration.Get <ILogger>().Debug("GraphicsDevice: Initializing DirectX");
                MPDirect3D.Load();

                // Cleanup-part: Only necessary during re-initialization
                UIResourcesHelper.ReleaseUIResources();
                if (_backBuffer != null)
                {
                    _backBuffer.Dispose();
                }
                if (_device != null)
                {
                    _device.Dispose();
                }
                _device = _setup.SetupDirectX();
                // End cleanup part

                SetupRenderStrategies();
                SetupRenderPipelines();

                Capabilities deviceCapabilities = _device.Capabilities;
                _backBuffer = _device.GetRenderTarget(0);
                _device.MaximumFrameLatency = _setup.PresentParameters.BackBufferCount; // Enables the device to queue as many frames as we have backbuffers defined
                int ordinal = deviceCapabilities.AdapterOrdinal;
                AdapterInformation adapterInfo = MPDirect3D.Direct3D.Adapters[ordinal];
                DisplayMode        currentMode = adapterInfo.CurrentDisplayMode;
                AdaptTargetFrameRateToDisplayMode(currentMode);
                LogScreenMode(currentMode);
                bool firstTimeInitialization = _dxCapabilities == null;
                _dxCapabilities = DxCapabilities.RequestCapabilities(deviceCapabilities, currentMode);
                if (firstTimeInitialization)
                {
                    if (!_dxCapabilities.SupportsShaders)
                    {
                        string text = String.Format("MediaPortal 2 needs a graphics card wich supports shader model 2.0\nYour card does NOT support this.\nMediaportal 2 will continue but migh run slow");
                        MessageBox.Show(text, "GraphicAdapter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                SetRenderState();
                UIResourcesHelper.ReallocUIResources();
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Critical("GraphicsDevice: Failed to setup DirectX", ex);
                Environment.Exit(0);
            }
        }
Exemple #2
0
        /// <summary>
        /// Resets the DirectX device. This will release all screens, other UI resources and our back buffer, reset the DX device and realloc
        /// all resources.
        /// </summary>
        public static bool Reset()
        {
            ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: Resetting DX device...");
            _screenManager.ExecuteWithTempReleasedResources(() => ExecuteInMainThread(() =>
            {
                // Note that the thread which created the device must call this (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb174344%28v=vs.85%29.aspx ).
                // Note also that only the thread which handles window messages is allowed to call CreateDevice and Reset
                // (see http://msdn.microsoft.com/en-us/library/windows/desktop/bb147224%28v=vs.85%29.aspx )
                ServiceRegistration.Get <ILogger>().Debug("GraphicsDevice: Reset DirectX");
                UIResourcesHelper.ReleaseUIResources();

                if (ContentManager.Instance.TotalAllocationSize != 0)
                {
                    ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: ContentManager.TotalAllocationSize = {0}, should be 0!", ContentManager.Instance.TotalAllocationSize / (1024 * 1024));
                }

                if (_backBuffer != null)
                {
                    _backBuffer.Dispose();
                }
                _backBuffer = null;

                _setup.BuildPresentParamsFromSettings();
                PresentParameters parameters = _setup.PresentParameters;
                _device.ResetEx(ref parameters);
                _setup.PresentParameters = parameters;

                SetupRenderStrategies();
                SetupRenderPipelines();

                Capabilities deviceCapabilities = _device.Capabilities;
                int ordinal = deviceCapabilities.AdapterOrdinal;
                AdapterInformation adapterInfo = MPDirect3D.Direct3D.Adapters[ordinal];
                DisplayMode currentMode        = adapterInfo.CurrentDisplayMode;
                AdaptTargetFrameRateToDisplayMode(currentMode);
                ServiceRegistration.Get <ILogger>().Debug("GraphicsDevice: DirectX reset {0}x{1} format: {2} {3} Hz", Width, Height,
                                                          currentMode.Format, TargetFrameRate);
                _backBuffer = _device.GetRenderTarget(0);
                _device.MaximumFrameLatency = _setup.PresentParameters.BackBufferCount; // Enables the device to queue as many frames as we have backbuffers defined
                _dxCapabilities             = DxCapabilities.RequestCapabilities(deviceCapabilities, currentMode);

                ScreenRefreshWorkaround();

                UIResourcesHelper.ReallocUIResources();
            }));
            ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: Device successfully reset");
            return(true);
        }
Exemple #3
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ILogger logger = ServiceRegistration.Get <ILogger>();

            try
            {
                logger.Debug("SkinEngine MainForm: Stopping");
                StopUI();
                UIResourcesHelper.ReleaseUIResources();
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("SkinEngine MainForm: Error occured in FormClosing handler", ex);
            }
            logger.Debug("SkinEngine MainForm: Closing");
            // We have to call ExitThread() explicitly because the application was started without
            // setting the MainWindow, which would have added an event handler which calls
            // Application.ExitThread() for us
            Application.ExitThread();
        }