private void Draw() { dispatcher.Invoke(() => { // if (_D3DImage.IsFrontBufferAvailable) if (state == RendererState.Rendering) { if (surface == null) { return; } var pSurface = surface.NativePointer; 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, surface.NativePointer, true); VideoSource.AddDirtyRect(new System.Windows.Int32Rect(0, 0, VideoSource.PixelWidth, VideoSource.PixelHeight)); VideoSource.Unlock(); //totalFramesCount++; //framePerSec++; } } }, DispatcherPriority.Render); }
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; } }