コード例 #1
0
        private void DisplayAsTexture(DirectXResource res)
        {
            if (res.Texture2D == null)
            {
                Core.LogWarning("DisplayAsTexture failed as Texture2D == null");
                return;
            }

            res.GetDx().RunOnContext(ctx =>
            {
                ctx.CopyResource(res.Texture2D, _sharedResource);
                ctx.Flush();
            }, "CopyToUI");

            if (_d3dimage.TryLock(TimeSpan.FromMilliseconds(1500)))
            {
                _d3dimage.AddDirtyRect(new Int32Rect(0, 0, res.Texture2D.Description.Width, res.Texture2D.Description.Height));
                _d3dimage.Unlock();
            }
            else
            {
                Core.LogWarning("Failed to Lock DirectXPresenter/d3dimage");
            }

            if (Source != _d3dimage)
            {
                Core.LogInfo("Assigning new D3DImage");
                Source = _d3dimage;
            }
        }
コード例 #2
0
        /// <summary>
        /// Invalidates the entire Direct3D image, notifying WPF to redraw
        /// </summary>
        protected void InternalInvalidateVideoImage()
        {
            /* Ensure we run on the correct Dispatcher */
            if (!D3DImage.Dispatcher.CheckAccess())
            {
                D3DImage.Dispatcher.BeginInvoke((Action)(() => InternalInvalidateVideoImage()));
                return;
            }

            /* If there is a new Surface to set,
             * this method will do the trick */
            SetBackBufferInternal(m_pBackBuffer);

            // may save a few AddDirtyRect calls when the rendering thread is too busy
            // or RenderOnCompositionTargetRendering is set but the video is not playing
            bool invalid = GetSetVideoImageInvalid(false);

            if (!invalid)
            {
                return;
            }

            /* Only render the video image if possible, or if IsRenderingEnabled is true */
            if (IsRenderingEnabled && m_pBackBuffer != IntPtr.Zero)
            {
                try
                {
                    if (!D3DImage.TryLock(InvalidateVideoImageLockDuration))
                    {
                        return;
                    }
                    /* Invalidate the entire image */
                    D3DImage.AddDirtyRect(new Int32Rect(0,                   /* Left */
                                                        0,                   /* Top */
                                                        D3DImage.PixelWidth, /* Width */
                                                        D3DImage.PixelHeight /* Height */));
                }
                catch (Exception)
                { }
                finally
                {
                    D3DImage.Unlock();
                }
            }

            /* Invalidate all of our cloned D3DRenderers */
            InvalidateClonedVideoImages();
        }
コード例 #3
0
 public bool LockImage()
 {
     return(_image.TryLock(_timeOutDuration));
 }