Пример #1
0
            private bool init()
            {
                bool lresult = false;

                do
                {
                    // Free the old texture
                    if (this.surface != null)
                    {
                        this.surface.Dispose();
                        this.surface = null;
                    }

                    using (var device = CreateDevice(NativeMethods.GetDesktopWindow()))
                    {
                        surface = GetSharedSurface(device);

                        Lock();

                        this.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface.NativeInterface);

                        Unlock();

                        lresult = true;
                    }
                } while (false);

                return(lresult);
            }
        public VideoPanel()
        {
            var lTuple = D3D9Image.createD3D9Image();

            if (lTuple != null)
            {
                this.imageSource = lTuple.Item1;

                this.sharedResource = lTuple.Item2;

                this.sharedHandle = sharedResource.SharedHandle;
            }

            if (this.imageSource != null)
            {
                var image = new System.Windows.Controls.Image();
                image.Stretch = System.Windows.Media.Stretch.Uniform;
                image.Source  = this.imageSource;
                this.AddChild(image);

                // To greatly reduce flickering we're only going to AddDirtyRect
                // when WPF is rendering.
                System.Windows.Media.CompositionTarget.Rendering += this.CompositionTargetRendering;
            }
        }
Пример #3
0
 private void OnLost()
 {
     OnUnload();
     if (_renderTarget != null)
     {
         _renderTarget.Dispose();
         _renderTarget = null;
     }
     if (_swapChain != null)
     {
         _swapChain.Dispose();
         _swapChain = null;
     }
 }
Пример #4
0
        private void OnAcquireCheck()
        {
            if (_device == null ||
                _renderTarget != null ||
                _swapChain != null)
            {
                return;
            }
            var d3dpp = (D3DPRESENT_PARAMETERS)_d3dpp;//.Clone();

            _size = _window.Size;
            d3dpp.hDeviceWindow    = _window.Handle;
            d3dpp.BackBufferWidth  = _size.Width;
            d3dpp.BackBufferHeight = _size.Height;


            if (_size.Width <= 0 || _size.Height <= 0)
            {
                return;
            }
            var failed = false;

            try
            {
                _swapChain    = _device.CreateAdditionalSwapChain(ref d3dpp);
                _renderTarget = _swapChain.GetBackBuffer(0, D3DBACKBUFFER_TYPE.D3DBACKBUFFER_TYPE_MONO);
                //_renderTarget = _device.GetRenderTarget(0);
            }
            catch (Exception ex)
            {
                failed       = true;
                ErrorMessage = string.Format("{0}: {1}", ex.GetType().Name, ex.Message);
                throw;
            }
            finally
            {
                if (failed)
                {
                    OnLost();
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Assigns a <see cref="Microsoft.WindowsAPICodePack.DirectX.Direct3D10.Texture2D"/> as the source of the back buffer.
        /// </summary>
        /// <param name="texture">
        /// The <c>Texture2D</c> to assign as the back buffer. Value can be null.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// The D3D10Image has not been locked by a call to the
        /// <see cref="D3DImage.Lock" /> or <see cref="D3DImage.TryLock" /> methods.
        /// </exception>
        public void SetBackBuffer(Texture2D texture)
        {
            // Free the old surface
            if (this.surface != null)
            {
                this.surface.Dispose();
                this.surface = null;
            }

            if (texture == null)
            {
                this.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
            }
            else
            {
                using (var device = CreateDevice(NativeMethods.GetDesktopWindow()))
                    using (var texture9 = GetSharedSurface(device, texture))
                    {
                        this.surface = texture9.GetSurfaceLevel(0);
                    }

                this.SetBackBuffer(D3DResourceType.IDirect3DSurface9, this.surface.NativeInterface);
            }
        }