Exemplo n.º 1
0
        private void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (!initialized)
            {
                logger.Warn("CompositionTarget_Rendering(...) " + initialized);
                return;
            }

            try
            {
                RenderingEventArgs args = (RenderingEventArgs)e;

                //if (VideoSource.IsFrontBufferAvailable && lastRender != args.RenderingTime)//
                if (lastRender != args.RenderingTime)
                { //VideoSource.IsFrontBufferAvailable - не работает через RDP
                    if (needRedraw)
                    {
                        var pSurface = d3dProvider.GetSurfacePointer();

                        if (pSurface != IntPtr.Zero)
                        {
                            VideoSource.Lock();
                            // Repeatedly calling SetBackBuffer with the same IntPtr is
                            // a no-op. There is no performance penalty.
                            VideoSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, pSurface, EnableSoftwareFallback);

                            var rect = new Int32Rect(0, 0, VideoSource.PixelWidth, VideoSource.PixelHeight);
                            VideoSource.AddDirtyRect(rect);

                            VideoSource.Unlock();
                        }

                        needRedraw = false;
                    }
                    else
                    {
                        // logger.Debug("needRedraw == false");
                    }

                    lastRender = args.RenderingTime;
                }
                else
                {
                    logger.Debug("lastRender != args.RenderingTime");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);

                Shutdown();

                errorCode = ErrorCode.Unexpected;
            }
        }
Exemplo n.º 2
0
        public void Run(ID3DImageProvider provider)
        {
            logger.Debug("D3DImageRendererEx::Run(...)");

            if (initialized)
            {
                logger.Warn("D3DImageRendererEx::Run(...) invalid state");
                return;
            }

            try
            {
                d3dProvider = provider;
                d3dProvider.NewDataAvailable += D3dProvider_NewDataAvailable;
                VideoSource = new D3DImage();

                var pSurface = d3dProvider.GetSurfacePointer();

                if (pSurface != IntPtr.Zero)
                {
                    VideoSource.Lock();
                    VideoSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, pSurface);
                    VideoSource.Unlock();
                }

                // VideoSource.IsFrontBufferAvailableChanged += VideoSource_IsFrontBufferAvailableChanged;
                System.Windows.Media.CompositionTarget.Rendering += CompositionTarget_Rendering;

                initialized = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Shutdown();

                // throw;
            }
        }