Example #1
0
        /// <summary>
        /// Called when an element should be painted. (Invoked from CefRenderHandler.OnPaint)
        /// </summary>
        /// <param name="type">indicates whether the element is the view or the popup widget.</param>
        /// <param name="dirtyRect">contains the set of rectangles in pixel coordinates that need to be repainted</param>
        /// <param name="buffer">The bitmap will be will be  width * height *4 bytes in size and represents a BGRA image with an upper-left origin</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
        {
            var handled = false;

            var args = new OnPaintEventArgs(type == PaintElementType.Popup, dirtyRect, buffer, width, height);

            var handler = Paint;

            if (handler != null)
            {
                handler(this, args);
                handled = args.Handled;
            }

            if (!handled)
            {
                RenderHandler?.OnPaint(type, dirtyRect, buffer, width, height);
            }

            var afterHandler = AfterPaint;

            if (afterHandler != null)
            {
                afterHandler(this, args);
            }
        }
Example #2
0
        /// <summary>
        /// Invoked from CefRenderHandler.OnPaint
        /// A new <see cref="Bitmap" /> is only created when <see cref="BitmapInfo.CreateNewBitmap" />
        /// is true, otherwise the new buffer is simply copied into the backBuffer of the existing
        /// <see cref="Bitmap" /> for efficiency. Locking provided by OnPaint as this method is called
        /// in it's lock scope.
        /// </summary>
        /// <param name="bitmapInfo">information about the bitmap to be rendered</param>
        void IRenderWebBrowser.OnPaint(BitmapInfo bitmapInfo)
        {
            var handled = false;

            var handler = OnPaint;

            if (handler != null)
            {
                var args = new OnPaintEventArgs(bitmapInfo.IsPopup, bitmapInfo.DirtyRect, bitmapInfo.BackBufferHandle,
                                                bitmapInfo.Width, bitmapInfo.Height, bitmapInfo.BytesPerPixel, bitmapInfo.NumberOfBytes);
                handler(this, args);

                handled = args.Handled;
            }

            if (!handled)
            {
                var newScreenshotHandler = NewScreenshot;
                if (newScreenshotHandler != null)
                {
                    newScreenshotHandler(this, EventArgs.Empty);
                }

                InvokeRenderAsync(bitmapInfo);
            }
        }