public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwSurface) { lock (_lock) if (dwSurface != IntPtr.Zero && cx != 0 && cy != 0) { if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height) { _originalVideoSize = new Size(cx, cy); } _aspectRatio.Width = arx; _aspectRatio.Height = ary; // We need to Dispose the created instance because SharpDX tracks all created objects. When the surface is disposed, it will get released // on unmanaged side as well, that's why we set the dwSurface to IntPtr.Zero to avoid duplicated release (which leads to hard crashes). using (Surface surf = new Surface(dwSurface)) { SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description; SurfaceDescription surfDesc = surf.Description; if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height) { if (_surface != null) { _surface.Dispose(); } _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false); } _device.StretchRectangle(surf, _surface, TextureFilter.None); } // Clear pointer, surface was already released. dwSurface = IntPtr.Zero; } VideoSizePresentDlgt vsp = VideoSizePresent; if (vsp != null) { vsp(this); VideoSizePresent = null; } // Inform caller that we have changed the texture if (_onTextureInvalidated != null) { _onTextureInvalidated(); } if (_renderDlgt != null) { _renderDlgt(); } return(0); }
public int PresentSurface(short cx, short cy, short arx, short ary, uint dwSurface) { lock (_lock) if (dwSurface != 0 && cx != 0 && cy != 0) { if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height) { _originalVideoSize = new Size(cx, cy); } _aspectRatio.Width = arx; _aspectRatio.Height = ary; using (Surface surf = Surface.FromPointer(new IntPtr(dwSurface))) { SurfaceDescription surfaceDesc = _surface == null ? new SurfaceDescription() : _surface.Description; SurfaceDescription surfDesc = surf.Description; if (surfaceDesc.Width != surfDesc.Width || surfaceDesc.Height != surfDesc.Height) { if (_surface != null) { _surface.Dispose(); } _surface = Surface.CreateRenderTarget(_device, surfDesc.Width, surfDesc.Height, Format.A8R8G8B8, MultisampleType.None, 0, false); } _device.StretchRectangle(surf, _surface, TextureFilter.None); } } VideoSizePresentDlgt vsp = VideoSizePresent; if (vsp != null) { vsp(this); VideoSizePresent = null; } // Inform caller that we have changed the texture if (_onTextureInvalidated != null) { _onTextureInvalidated(); } if (_renderDlgt != null) { _renderDlgt(); } return(0); }
public int PresentSurface(short cx, short cy, short arx, short ary, ref IntPtr dwTexture) { lock (_lock) if (dwTexture != IntPtr.Zero && cx != 0 && cy != 0) { if (cx != _originalVideoSize.Width || cy != _originalVideoSize.Height) { _originalVideoSize = new Size(cx, cy); } _aspectRatio.Width = arx; _aspectRatio.Height = ary; FilterGraphTools.TryDispose(ref _texture); _texture = new Texture(dwTexture); } VideoSizePresentDlgt vsp = VideoSizePresent; if (vsp != null) { vsp(this); VideoSizePresent = null; } // Inform caller that we have changed the texture if (_onTextureInvalidated != null) { _onTextureInvalidated(); } if (_renderDlgt != null) { _renderDlgt(); } return(0); }