internal void OnBrowserRequestsPainting(CefSharp.Structs.Rect dirtyRect, IntPtr buffer, int width, int height) { if (_colorBuffer == null || _colorBuffer.Width != width || _colorBuffer.Height != height) { _colorBuffer?.Dispose(); _colorBuffer = new DeviceIndependentBitmap(width, height); } _colorBuffer.CopyFromBuffer(buffer, (uint)(width * height * 4 /*RGBA*/)); var blend = new NativeMethods.BlendFunction { BlendOp = NativeMethods.AC_SRC_OVER, BlendFlags = 0, SourceConstantAlpha = 255, AlphaFormat = NativeMethods.AC_SRC_ALPHA }; var windowPosition = new NativeMethods.Point { X = this.Left, Y = this.Top }; var surfaceSize = new NativeMethods.Size { Width = _colorBuffer.Width, Height = _colorBuffer.Height }; var surfacePosition = new NativeMethods.Point { X = 0, Y = 0 }; try { IntPtr handle = this.InvokeSyncOnUI((f) => f.Handle); //IntPtr.Zero; // this.InvokeSyncOnUIThread(() => handle = this.Handle); NativeMethods.UpdateLayeredWindow( handle, IntPtr.Zero, ref windowPosition, ref surfaceSize, _colorBuffer.DeviceContext, ref surfacePosition, 0, ref blend, NativeMethods.ULW_ALPHA); } catch (ObjectDisposedException ex) { //can happen, when the form gets killed by the ui thread while we try to render CEF stuff on it _colorBuffer?.Dispose(); } }
private void DisposeForm(bool disposing) { logger.Debug("Disposing cef overlay"); _formEnsureTopmost?.Dispose(); _formMover?.Dispose(); // Browser?.CloseBrowser(true); Browser?.Dispose(); Browser = null; _colorBuffer?.Dispose(); _colorBuffer = null; }