protected override void OnPaint(bool isPopup, Structs.Rect dirtyRect, IntPtr buffer, int width, int height)
        {
            if (isTakingScreenshot)
            {
                //We ignore the first n number of frames
                if (ignoreFrames > 0)
                {
                    ignoreFrames--;
                    return;
                }

                //Wait until we have a frame that matches the updated size we requested
                if (screenshotSize.HasValue && screenshotSize.Value.Width == width && screenshotSize.Value.Height == height)
                {
                    var stride        = width * BytesPerPixel;
                    var numberOfBytes = stride * height;

                    //Create out own memory mapped view for the screenshot and copy the buffer into it.
                    //If we were going to create a lot of screenshots then it would be better to allocate a large buffer
                    //and reuse it.
                    var mappedFile   = MemoryMappedFile.CreateNew(null, numberOfBytes, MemoryMappedFileAccess.ReadWrite);
                    var viewAccessor = mappedFile.CreateViewAccessor();

                    CopyMemory(viewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), buffer, (uint)numberOfBytes);

                    //Bitmaps need to be created on the UI thread
                    Dispatcher.BeginInvoke((Action)(() =>
                    {
                        var backBuffer = mappedFile.SafeMemoryMappedFileHandle.DangerousGetHandle();
                        //NOTE: Interopbitmap is not capable of supporting DPI scaling
                        var bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(backBuffer,
                                                                                                width, height, PixelFormats.Bgra32, stride, 0);
                        //Using TaskExtensions.TrySetResultAsync extension method so continuation runs on Threadpool
                        screenshotTaskCompletionSource.TrySetResultAsync(bitmap);

                        isTakingScreenshot = false;
                        var browserHost = GetBrowser().GetHost();
                        //Return the framerate to the previous value
                        browserHost.WindowlessFrameRate = oldFrameRate;
                        //Let the browser know the size changes so normal rendering can continue
                        browserHost.WasResized();

                        if (viewAccessor != null)
                        {
                            viewAccessor.Dispose();
                        }

                        if (mappedFile != null)
                        {
                            mappedFile.Dispose();
                        }
                    }));
                }
            }
            else
            {
                base.OnPaint(isPopup, dirtyRect, buffer, width, height);
            }
        }
Пример #2
0
 internal static extern bool GetWindowRect(IntPtr hWnd, out Rect lpRect);
Пример #3
0
 public static extern bool GetWindowRect(IntPtr hWnd, out Structs.Rect RECT);
 public static extern bool GetWindowRect(IntPtr hwnd, out Structs.Rect lpRect);
Пример #5
0
 public static extern bool GetClientRect(IntPtr hWnd, out Structs.Rect RECT);