Пример #1
0
 public bool IsDeviceStateOk()
 {
     if (device != null)
     {
         var state = device.CheckDeviceState(IntPtr.Zero);
         return(state == DeviceState.Ok);
     }
     return(false);
 }
Пример #2
0
 /// <summary>
 /// Calls <see cref="DeviceEx.CheckDeviceState"/> on the DX device and returns its result.
 /// </summary>
 internal static DeviceState CheckDeviceState()
 {
     return(_device.CheckDeviceState(_setup.RenderTarget.Handle));
 }
Пример #3
0
        public DeviceState CheckDeviceState()
        {
            DeviceEx ex = new DeviceEx(_device.NativePointer);

            return(ex.CheckDeviceState(_formHandle));
        }
        private void OpenSharedResourceIfNeeded(DirectXResource res)
        {
            try
            {
                bool reinit = false;
                _occludedCounter++;

                if (_occludedCounter % 1 == 0) // every 200 ms
                {
                    var  state         = _device?.CheckDeviceState(_windowHandle) ?? DeviceState.Ok;
                    bool occludedState = state == DeviceState.PresentOccluded; // happens when windows is locked; then we could get black screen in preview d3dImage

                    reinit = _occludedState && !occludedState;                 // reinit if change from bad -> good
                    if (reinit)
                    {
                        Core.LogInfo("occluded -> normal");

                        if (_windowStateManager.IsMinimized())
                        {
                            _windowStateManager.IsMinimizedChanged += OnwindowStateManagerIsMinimizedChanged;
                        }
                        else
                        {
                            _ = ReinitSurfacesWithDelay();
                        }
                    }

                    if (!_occludedState && occludedState)
                    {
                        Core.LogInfo("normal -> occluded");
                    }

                    _occludedState = occludedState;
                }

                if (_sharedResource == null ||
                    _sharedResource.Description.Width != res.Texture2D.Description.Width ||
                    _sharedResource.Description.Height != res.Texture2D.Description.Height ||
                    _sharedResourceOwner != res.GetDx() ||
                    _reinitSurfaces)
                {
                    Core.LogInfo("Initing DX Presenter surface");
                    Source          = null;
                    _reinitSurfaces = false;

                    _surfaceD9?.Dispose();
                    _sharedResource?.Dispose();

                    _surfaceD9           = null;
                    _sharedResource      = null;
                    _sharedResourceOwner = null;


                    IntPtr handle = IntPtr.Zero;
                    _surfaceD9 = Surface.CreateRenderTarget(_device, res.Texture2D.Description.Width, res.Texture2D.Description.Height, Format.A8R8G8B8, MultisampleType.None, 0, true, ref handle);
                    if (handle == IntPtr.Zero)
                    {
                        Core.LogWarning("DirectX 9 Device failed to create Surface. Reinit Devices");
                        _device?.Dispose();
                        _direct3d?.Dispose();
                        _device   = null;
                        _direct3d = null;
                        InitDx9();
                        _surfaceD9 = Surface.CreateRenderTarget(_device, res.Texture2D.Description.Width, res.Texture2D.Description.Height, Format.A8R8G8B8, MultisampleType.None, 0, true, ref handle);

                        if (handle == IntPtr.Zero)
                        {
                            Core.LogWarning("DirectX 9 Device failed to create Surface after recreation.");
                        }
                    }
                    _sharedResource      = res.GetDx().Device.OpenSharedResource <Texture2D>(handle);
                    _sharedResourceOwner = res.GetDx();

                    _d3dimage = new D3DImage();
                    _d3dimage.Lock();
                    _d3dimage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _surfaceD9.NativePointer);
                    _d3dimage.Unlock();

                    Core.LogInfo("Inited DX Presenter surface");
                }
            }
            catch (Exception e)
            {
                Core.LogError(e, "Failed to open shared resource");
            }
        }