Ejemplo n.º 1
0
        private void WebBrowser_Paint(object sender, OnPaintEventArgs e)
        {
            // pixel data for the image: width * height * 4 bytes
            // BGRA image with upper-left origin

            int numberOfBytes = e.Height * e.Width * 4;

            if (paintBitmap == null || numberOfBytes != paintBitmap.Length)
            {
                paintBufferSize = numberOfBytes;
                paintBitmap     = new byte[paintBufferSize];

                Logr.Log("Paint buffer: Resizing to", paintBufferSize, "bytes");
            }

            try
            {
                Marshal.Copy(e.BufferHandle, paintBitmap, 0, paintBufferSize);
            }
            catch (AccessViolationException)
            {
                Logr.Log("WARN: Marshal copy failed: Access violation while reading frame buffer.");
            }

            this.runner.AddTask(new SendFrameTask(paintBitmap));
        }
Ejemplo n.º 2
0
        private void Browser_Paint(object sender, OnPaintEventArgs e)
        {
            var newbitmap = false;
            int pixels = e.Width * e.Height, numberOfBytes = pixels * BytesPerPixel;

            newbitmap = viewMemoryMappedFile == null || Height != e.Height || Width != e.Width;

            try
            {
                ReleaseMemoryMappedView(ref viewMemoryMappedFile, ref viewMemoryMappedViewAccessor);
                viewMemoryMappedFile         = MemoryMappedFile.CreateNew(null, numberOfBytes, MemoryMappedFileAccess.ReadWrite);
                viewMemoryMappedViewAccessor = viewMemoryMappedFile.CreateViewAccessor();

                CopyMemory(viewMemoryMappedViewAccessor.SafeMemoryMappedViewHandle.DangerousGetHandle(), e.BufferHandle, (uint)numberOfBytes);

                var backBufferHandle = viewMemoryMappedFile.SafeMemoryMappedFileHandle;
                if (backBufferHandle.IsClosed || backBufferHandle.IsInvalid)
                {
                    return;
                }

                var stride = e.Width * BytesPerPixel;

                var bs = Imaging.CreateBitmapSourceFromMemorySection(backBufferHandle.DangerousGetHandle(), e.Width, e.Height, PixelFormat, stride, 0);
                Screenshot = new Bitmap(e.Width, e.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                System.Drawing.Imaging.BitmapData data = Screenshot.LockBits(new Rectangle(Point.Empty, Screenshot.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);

                bs.CopyPixels(System.Windows.Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride);
                SetBitmap(Screenshot, this);
                GC.Collect(1);
            }
            catch { }
        }
Ejemplo n.º 3
0
 private void OnPaintEventHandler(object sender, OnPaintEventArgs e)
 {
     if (Debug)
     {
         DebugLog.Message("OnPaint");
     }
     OnPaintCount++;
     return;
 }
Ejemplo n.º 4
0
        private void WebBrowser_OnPaint(object sender, OnPaintEventArgs e)
        {
            if (paintBitmap == null || e.NumberOfBytes != paintBitmap.Length)
            {
                paintBufferSize = e.NumberOfBytes;// this.webBrowser.Size.Width * this.webBrowser.Size.Height * e.BytesPerPixel;
                paintBitmap     = new byte[paintBufferSize];

                Logr.Log("Paint buffer: Resizing to", paintBufferSize, "bytes");
            }

            try
            {
                Marshal.Copy(e.BufferHandle, paintBitmap, 0, paintBufferSize);
            }
            catch (AccessViolationException ex)
            {
                Logr.Log("WARN: Marshal copy failed: Access violation while reading frame buffer.");
            }

            this.runner.AddTask(new SendFrameTask(paintBitmap));
        }
Ejemplo n.º 5
0
        private void MonoCefBrowser_Paint(object sender, OnPaintEventArgs e)
        {
            if (e.DirtyRect.Width == 0 || e.DirtyRect.Height == 0)
            {
                return;
            }
            TotalTime.Start();
            var       bmp     = this.ScreenshotOrNull(PopupBlending.Main);
            Texture2D texture = null;

            if (bmp != null)
            {
                texture = GetTexture(bmp, e.DirtyRect);
                RenderCount++;
                //Console.WriteLine($"{TotalTime.ElapsedMilliseconds / (double)RenderCount}");
            }
            TotalTime.Stop();
            if (texture != null)
            {
                this.NewFrame?.Invoke(this, new NewFrameEventArgs(texture));
            }
        }
Ejemplo n.º 6
0
 private void Browser_Paint(object sender, OnPaintEventArgs e)
 {
     Paint?.Invoke(e.BufferHandle, e.Width, e.Height);
 }