示例#1
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            // Save the provided buffer (a bitmap image) as a PNG.
            var bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppRgb, buffer);

            bitmap.Save("LastOnPaint.png", ImageFormat.Png);
        }
示例#2
0
 public unsafe void OnPaint(cef_browser_t *browser, CefPaintElementType type, UIntPtr dirtyRectsCount, [Immutable] cef_rect_t *dirtyRects, [Immutable] void *buffer, int width, int height)
 {
     fixed(cef_render_handler_t *self = &this)
     {
         ((delegate * unmanaged[Stdcall] < cef_render_handler_t *, cef_browser_t *, CefPaintElementType, UIntPtr, cef_rect_t *, void *, int, int, void >)on_paint)(self, browser, type, dirtyRectsCount, dirtyRects, buffer, width, height);
     }
 }
示例#3
0
 public unsafe void OnAcceleratedPaint(cef_browser_t *browser, CefPaintElementType type, UIntPtr dirtyRectsCount, [Immutable] cef_rect_t *dirtyRects, void *shared_handle)
 {
     fixed(cef_render_handler_t *self = &this)
     {
         ((delegate * unmanaged[Stdcall] < cef_render_handler_t *, cef_browser_t *, CefPaintElementType, UIntPtr, cef_rect_t *, void *, void >)on_accelerated_paint)(self, browser, type, dirtyRectsCount, dirtyRects, shared_handle);
     }
 }
示例#4
0
        public void OnAcceleratedPaint(CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr sharedHandle)
        {
            try
            {
                if (sharedHandle == IntPtr.Zero)
                {
                    return;
                }

                var d3dDevice = SharpDXInterop.GetNativeDevice(GraphicsDevice) as Device;
                if (d3dDevice is null)
                {
                    return;
                }

                var d3dTexture = d3dDevice.OpenSharedResource <Texture2D>(sharedHandle);
                if (d3dTexture is null)
                {
                    return;
                }

                var strideTexture = SharpDXInterop.CreateTextureFromNative(GraphicsDevice, d3dTexture, takeOwnership: true);
                lock (syncRoot)
                {
                    surface?.Dispose();
                    surface = strideTexture;
                }
                needsConversion = true;
            }
            catch (Exception e)
            {
                RuntimeGraph.ReportException(e);
            }
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CefPaintEventArgs"/> class.
 /// </summary>
 /// <param name="browser">The <see cref="CefBrowser"/> that triggered the event.</param>
 /// <param name="type">A paint element type.</param>
 /// <param name="dirtyRects">Specifies areas of the bitmap that changed.</param>
 /// <param name="buffer">The pointer to an array of bytes that contains the BGRA pixel data.</param>
 /// <param name="width">The width, in pixels, of the bitmap.</param>
 /// <param name="height">The height, in pixels, of the bitmap.</param>
 public CefPaintEventArgs(CefBrowser browser, CefPaintElementType type, CefRect[] dirtyRects, IntPtr buffer, int width, int height)
 {
     Browser          = browser;
     PaintElementType = type;
     DirtyRects       = dirtyRects;
     Buffer           = buffer;
     Width            = width;
     Height           = height;
 }
示例#6
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects
                                        , System.IntPtr buffer, int width, int height)
        {
            System.Console.WriteLine("Entering OnPaint");

            // if (isPainting == true) return;

            isPainting = true;

            string savePath = "";

            // if (System.Environment.OSVersion.Platform == System.PlatformID.Unix) savePath = "/opt/pdfglue/";


            // Save the provided buffer (a bitmap image) as a PNG.
            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, width * 4, System.Drawing.Imaging.PixelFormat.Format32bppRgb, buffer))
            {
                System.Console.WriteLine("PixelFormat: " + bitmap.PixelFormat);
                System.Console.WriteLine("HorizontalResolution: " + bitmap.HorizontalResolution);
                System.Console.WriteLine("VerticalResolution: " + bitmap.VerticalResolution);

                bitmap.Save(savePath + "LastOnPaint.bmp");
                bitmap.Save(savePath + "LastOnPaint.png", System.Drawing.Imaging.ImageFormat.Png);
            } // End Using bitmap


            // CefPdfPrintSettings ps = new CefPdfPrintSettings();
            // ps.PageWidth = CmToMicrons(21);
            // ps.PageHeight = CmToMicrons(29.7);

            // A0
            // ps.PageWidth = CmToMicrons(84.1);
            // ps.PageHeight = CmToMicrons(118.9);

            // 5= zuviel
            // 2,3,4 = OK
            // ps.PageWidth = CmToMicrons(15*84.1);
            // ps.PageHeight = CmToMicrons(15*118.9);



            //ps.Landscape = false;
            //ps.MarginLeft = 0;
            //ps.MarginTop = 0;
            //ps.MarginRight = 0;
            //ps.MarginBottom = 0;
            //ps.BackgroundsEnabled = true;
            //ps.SelectionOnly = false;

            CefPdfPrintSettings ps = new PageSize(PageSize_t.A4).PrintSettings;

            browser.GetHost().PrintToPdf(savePath + "AAA.pdf", ps, new PdfPrintCallback());
            // browser.GetHost().CloseBrowser();
            // browser.Dispose(); // We have the image - stop re-rendering

            System.Console.WriteLine("Exiting OnPaint");
        } // End Sub OnPaint
示例#7
0
        protected override unsafe void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects,
                                               IntPtr buffer, int width, int height)
        {
            var length = width * height * 4;

            if (_texture == IntPtr.Zero)
            {
                return;
            }
        }
示例#8
0
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     if (browser != null)
     {
         lock (sPixelLock)
         {
             Marshal.Copy(buffer, sPixelBuffer, 0, sPixelBuffer.Length);
         }
     }
 }
示例#9
0
        public void OnPaint(CefPaintElementType type, CefRectangle[] cefRects, IntPtr buffer, int width, int height)
        {
            var image = SKImage.FromPixelCopy(new SKImageInfo(width, height, SKColorType.Bgra8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb()), buffer, width * 4);

            lock (syncRoot)
            {
                rasterImage?.Dispose();
                rasterImage = image;
            }
        }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (type != CefPaintElementType.View)
            {
                // Only want to paint the view
                return;
            }

            this.core.OnPaint(buffer);
        }
 /*Called when an element should be painted. |type| indicates whether the element is the view or the popup widget. |buffer| contains the pixel data for the whole image.
  * |dirtyRects| contains the set of rectangles that need to be repainted.
  * On Windows |buffer| will be width*height*4 bytes in size and represents a BGRA image with an upper-left origin.
  *  The CefBrowserSettings.animation_frame_rate value controls the rate at which this method is called.*/
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     _copysize     = width * height * 4;
     CurrentWidth  = width;
     CurrentHeight = height;
     if (_memServer != null)
     {
         _memServer.PushTexture(buffer, _copysize);
     }
 }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (type != CefPaintElementType.View)
            {
                // Only want to paint the view
                return;
            }

            this.core.OnPaint(buffer);
        }
示例#13
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            //_logger.Debug("Type: {0} Buffer: {1:X8} Width: {2} Height: {3}", type, buffer, width, height);
            //foreach (var rect in dirtyRects)
            //{
            //    _logger.Debug("   DirtyRect: X={0} Y={1} W={2} H={3}", rect.X, rect.Y, rect.Width, rect.Height);
            //}

            owner.HandlePaint(browser, type, dirtyRects, buffer, width, height);
        }
示例#14
0
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     try
     {
         _imageElement?.SetBitmap(new Bitmap(width, height, width * 4, PixelFormat.Format32bppArgb, buffer));
     }
     catch (Exception ex)
     {
         LogManager.CefLog(ex, "CEF PAINT");
     }
 }
示例#15
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, Int32 width, Int32 height)
        {
            Log.Trace("RenderHandler.OnPaint( browser: {0}, type: {1} )", browser.Identifier, Enum.GetName(typeof(CefPaintElementType), type));

            //this.LastPainted = DateTime.Now;

            lock (this.NextBitmap)
            {
                this.NextBitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, buffer);
            }
        }
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     if (type == CefPaintElementType.View)
     {
         _owner.HandleViewPaint(browser, type, dirtyRects, buffer, width, height);
     }
     else if (type == CefPaintElementType.Popup)
     {
         _owner.HandlePopupPaint(width, height, dirtyRects, buffer);
     }
 }
示例#17
0
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width,
                                 int height)
 {
     if (browser != null)
     {
         //Copy our pixel buffer to our pixels
         lock (pixelsLock)
         {
             Marshal.Copy(buffer, pixels, 0, pixels.Length);
         }
     }
 }
示例#18
0
            protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
            {
                switch (type)
                {
                case CefPaintElementType.View:
                    FRenderer.Paint(dirtyRects, buffer, width * 4);
                    break;

                case CefPaintElementType.Popup:
                    break;
                }
            }
示例#19
0
 public void OnAcceleratedPaint(CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr sharedHandle)
 {
     lock (syncRoot)
     {
         if (sharedHandle != this.sharedHandle)
         {
             this.sharedHandle = sharedHandle;
             sharedTexture?.Dispose();
             sharedTexture = device?.OpenSharedResource <Texture2D>(sharedHandle);
         }
     }
 }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            _logger.Debug("Type: {0} Buffer: {1:X8} Width: {2} Height: {3}", type, buffer, width, height);
            foreach (var rect in dirtyRects)
            {
                _logger.Debug("   DirtyRect: X={0} Y={1} W={2} H={3}", rect.X, rect.Y, rect.Width, rect.Height);
            }

            if (type == CefPaintElementType.View)
            {
                _owner.HandleViewPaint(browser, type, dirtyRects, buffer, width, height);
            }
            // 			else if (type == CefPaintElementType.Popup)
            // 				this.browser.HandleWidgetPaint(browser, type, dirtyRects, buffer, width, height);
        }
示例#21
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            _logger.Debug("Type: {0} Buffer: {1:X8} Width: {2} Height: {3}", type, buffer, width, height);
            foreach (var rect in dirtyRects)
            {
                _logger.Debug("   DirtyRect: X={0} Y={1} W={2} H={3}", rect.X, rect.Y, rect.Width, rect.Height);
            }

            if (type == CefPaintElementType.View)
            {
                _owner.HandleViewPaint(browser, type, dirtyRects, buffer, width, height);
            }
            //          else if (type == CefPaintElementType.Popup)
            //              this.browser.HandleWidgetPaint(browser, type, dirtyRects, buffer, width, height);
        }
示例#22
0
            protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRect[] dirtyRects, IntPtr buffer)
            {
                int width, height;

                switch (type)
                {
                case CefPaintElementType.View:
                    browser.GetSize(CefPaintElementType.View, out width, out height);
                    FRenderer.Paint(dirtyRects, buffer, width * 4);
                    break;

                case CefPaintElementType.Popup:
                    break;
                }
                base.OnPaint(browser, type, dirtyRects, buffer);
            }
示例#23
0
            protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
            {
                if (browser == null)
                {
                    return;
                }

                byte[] targetBuffer = client.sPixelBuffer;
                if (type == CefPaintElementType.Popup)
                {
                    client.AjustPopupBuffer(width, height);
                    targetBuffer = client.sPopupPixelBufer;
                }

                Marshal.Copy(buffer, targetBuffer, 0, targetBuffer.Length);
                client.UpdateTexture();
            }
示例#24
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (CreateTextureEvent != null)
            {
                lock (texturesLock)
                {
                    SharedTexture textureToRender;
                    if (textures.Count <= currentTextureIndex)
                    {
                        IntPtr sharedTextureHandle;
                        CreateTextureEvent((UInt32)width, (UInt32)height, out sharedTextureHandle);

                        if (sharedTextureHandle == IntPtr.Zero)
                        {
                            //texture has not been created yet, try again on the next paint
                            return;
                        }

                        // TODO : eventually switch to shared textures
                        //Texture texture = GraphicsSystem.Instance.CreateTextureFromSharedHandle((UInt32)width, (UInt32)height, sharedTextureHandle);

                        Texture texture = new Texture(sharedTextureHandle);

                        textureToRender = new SharedTexture
                        {
                            Texture = texture,
                            Handle  = sharedTextureHandle
                        };

                        textures.Add(textureToRender);
                    }
                    else
                    {
                        textureToRender = textures[currentTextureIndex];
                    }

                    textureToRender.Texture.SetImage(buffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(width * 4));

                    // loop the current texture index
                    currentTextureIndex = ++currentTextureIndex % textureCount;
                    PaintEvent(textureToRender.Handle);
                }
            }
        }
示例#25
0
        public static void invalidate(cef_browser_host_t *self, CefPaintElementType type)
        {
            invalidate_delegate d;
            var p = self->_invalidate;

            if (p == _p1a)
            {
                d = _d1a;
            }
            else
            {
                d = (invalidate_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(invalidate_delegate));
                if (_p1a == IntPtr.Zero)
                {
                    _d1a = d; _p1a = p;
                }
            }
            d(self, type);
        }
示例#26
0
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            synchronization.Post((_) =>
            {
                if (type == CefPaintElementType.View)
                {
                    if (this.Resize(width, height))
                    {
                        ((Device)this.GraphicsDevice).ImmediateContext.UpdateSubresource(this._offscreenBuffer, 0, null, buffer, this._width * 4, 0);
                    }
                    else
                    {
                        for (int i = 0; i < dirtyRects.Length; i++)
                        {
                            CefRectangle cefRectangle = dirtyRects[i];
                            ((Device)this.GraphicsDevice).ImmediateContext.UpdateSubresource(this._offscreenBuffer, 0, new ResourceRegion?(new ResourceRegion(cefRectangle.X, cefRectangle.Y, 0, cefRectangle.X + cefRectangle.Width, cefRectangle.Y + cefRectangle.Height, 1)), buffer + cefRectangle.X * 4 + cefRectangle.Y * width * 4, this._width * 4, 0);
                        }
                    }

                    ////try
                    ////{
                    ////    var Pointer = new DataPointer(buffer, this._windowWidth * this._windowHeight * 4);
                    ////    this._offscreenBuffer.SetData(Pointer);
                    ////}
                    ////catch (Exception)
                    ////{

                    ////}


                    //for (int i = 0; i < dirtyRects.Length; i++)
                    //{
                    //    CefRectangle cefRectangle = dirtyRects[i];

                    //    var region = new ResourceRegion(cefRectangle.X, cefRectangle.Y, 0, cefRectangle.X + cefRectangle.Width, cefRectangle.Y + cefRectangle.Height, 1);
                    //    var pointer = new DataPointer(buffer + cefRectangle.X * 4 + cefRectangle.Y * width * 4, cefRectangle.Width * cefRectangle.Height * 4);
                    //    this._offscreenBuffer.SetData(pointer, 0, 0, region);
                    //}
                }

                ((Device)this.GraphicsDevice).ImmediateContext.Flush();
            }, null);
        }
        /*Called when an element should be painted. |type| indicates whether the element is the view or the popup widget. |buffer| contains the pixel data for the whole image.
         * |dirtyRects| contains the set of rectangles that need to be repainted.
         * On Windows |buffer| will be width*height*4 bytes in size and represents a BGRA image with an upper-left origin.
         *  The CefBrowserSettings.animation_frame_rate value controls the rate at which this method is called.*/
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (MainBitmap == null)
            {
                _copysize = width * height * 4;

                MainBitmap = new byte[_copysize];
            }

            CurrentWidth  = width;
            CurrentHeight = height;
            Marshal.Copy(buffer, MainBitmap, 0, _copysize);


            if (_memServer != null)
            {
                _memServer.WriteBytes(MainBitmap);
            }
        }
示例#28
0
        public void OnPaint(CefPaintElementType type, CefRectangle[] cefRects, IntPtr buffer, int width, int height)
        {
            var data   = new DataBox(buffer, width * 4, width * height * 4);
            var format = PixelFormat.B8G8R8A8_UNorm;

            if (GraphicsDevice.ColorSpace == ColorSpace.Linear)
            {
                format = PixelFormat.B8G8R8A8_UNorm_SRgb;
            }

            var surface = Texture.New2D(GraphicsDevice, width, height, 1, format, new[] { data }, usage: GraphicsResourceUsage.Immutable);

            lock (syncRoot)
            {
                this.surface?.Dispose();
                this.surface = surface;
            }

            needsConversion = false;
        }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            var rect = new Rectangle(0, 0, offscreenBrowser.Width, offscreenBrowser.Height);

            try {
                var screenShot      = offscreenBrowser.WindowBitmap.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                var totalSize       = screenShot.Stride * screenShot.Height;
                var temporaryBuffer = new byte[totalSize];

                var screenShotPtr = screenShot.Scan0;

                Marshal.Copy(buffer, temporaryBuffer, 0, totalSize);
                Marshal.Copy(temporaryBuffer, 0, screenShotPtr, totalSize);

                offscreenBrowser.WindowBitmap.UnlockBits(screenShot);
            } catch (Exception e) {
                // TODO add loggging
                throw;
            }
        }
示例#30
0
        internal void HandleViewPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            // When browser size changed - we just skip frame updating.
            // This is dirty precheck to do not do Invoke whenever is possible.
            if (_browserSizeChanged && (width != _browserWidth || height != _browserHeight))
            {
                return;
            }

            _mainUiDispatcher.Invoke(DispatcherPriority.Render, new Action(delegate
            {
                // Actual browser size changed check.
                if (_browserSizeChanged && (width != _browserWidth || height != _browserHeight))
                {
                    return;
                }

                try
                {
                    if (_browserSizeChanged)
                    {
                        _browserPageBitmap       = new WriteableBitmap((int)_browserWidth, (int)_browserHeight, 96, 96, PixelFormats.Bgr32, null);
                        _browserPageImage.Source = _browserPageBitmap;

                        _browserSizeChanged = false;
                    }

                    if (_browserPageBitmap != null)
                    {
                        DoRenderBrowser(_browserPageBitmap, width, height, dirtyRects, buffer);
                    }
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("WpfCefBrowser: Caught exception in HandleViewPaint()", ex);
                }
            }));
        }
示例#31
0
 /// <summary>
 /// 处理重绘操作
 /// </summary>
 /// <param name="browser"></param>
 /// <param name="type"></param>
 /// <param name="dirtyRects"></param>
 /// <param name="buffer"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 //此方法是多线程进行的,因此-texture在多线程中被使用
 public void HandleOnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     if (_texture != null)
     {
         lock (BitmapLock)
         {
             //当前分辨率不一致
             if (width != _windowsWidth && height != _windowsHeight)
             {
                 return;
             }
             else
             {
                 _gd.UpdateTexture(_texture, buffer, (uint)(_windowsWidth * _windowsHeight * 4), 0, 0, 0, _windowsWidth, _windowsHeight, 1, 0, 0);
                 //_gd.WaitForIdle();
             }
             foreach (var item in dirtyRects)
             {
                 //_gd.UpdateTexture
             }
         }
     }
 }
示例#32
0
        internal void HandlePaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (type == CefPaintElementType.View)
            {
                if (texture != null && width != 0 && height != 0 && width == viewSize.X && height == viewSize.Y)
                {
                    //TO DO: dirtyRects

                    try
                    {
                        int stride           = width * 4;
                        int sourceBufferSize = stride * height;

                        lock ( renderBufferLock )
                        {
                            Vec2I newSize = new Vec2I(width, height);
                            if (renderBuffer == null || sourceBufferSize != renderBuffer.Length || renderBufferForSize != newSize)
                            {
                                renderBuffer        = new byte[sourceBufferSize];
                                renderBufferForSize = newSize;
                            }
                            Marshal.Copy(buffer, renderBuffer, 0, sourceBufferSize);
                        }

                        needUpdateTexture = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Error("WebBrowserControl: Caught exception in HandleViewPaint(): " + ex.Message);
                    }
                }
            }
            if (type == CefPaintElementType.Popup)
            {
                //TO DO?
            }
        }
示例#33
0
 /// <summary>
 /// Get the raw image data contained in the specified element without performing validation.
 /// The specified |width| and |height| dimensions must match the current element size.
 /// On Windows |buffer| must be width*height*4 bytes in size and represents a BGRA image with an upper-left origin.
 /// This method should only be called on the UI thread.
 /// </summary>
 public bool GetImage(CefPaintElementType type, int width, int height, IntPtr buffer)
 {
     return cef_browser_t.invoke_get_image(this.ptr, (cef_paint_element_type_t)type, width, height, (void*)buffer) != 0;
 }
示例#34
0
 /// <summary>
 /// Invalidate the |dirtyRect| region of the view. The browser will call
 /// CefRenderHandler::OnPaint asynchronously with the updated regions. This
 /// method is only used when window rendering is disabled.
 /// </summary>
 public void Invalidate(CefRectangle dirtyRect, CefPaintElementType type)
 {
     var n_dirtyRect = new cef_rect_t(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height);
     cef_browser_host_t.invalidate(_self, &n_dirtyRect, type);
 }
 public static void invalidate(cef_browser_host_t* self, CefPaintElementType type)
 {
     invalidate_delegate d;
     var p = self->_invalidate;
     if (p == _p1b) { d = _d1b; }
     else
     {
         d = (invalidate_delegate)Marshal.GetDelegateForFunctionPointer(p, typeof(invalidate_delegate));
         if (_p1b == IntPtr.Zero) { _d1b = d; _p1b = p; }
     }
     d(self, type);
 }
示例#36
0
 /// <summary>
 /// Invalidate the |dirtyRect| region of the view. The browser will call
 /// CefRenderHandler::OnPaint asynchronously with the updated regions. This
 /// method is only used when window rendering is disabled.
 /// </summary>
 public void Invalidate(CefPaintElementType type)
 {
     cef_browser_host_t.invalidate(_self, type);
 }
示例#37
0
 /// <summary>
 /// Set the size of the specified element.
 /// This method is only used when window rendering is disabled.
 /// </summary>
 public void SetSize(CefPaintElementType type, int width, int height)
 {
     cef_browser_t.invoke_set_size(this.ptr, (cef_paint_element_type_t)type, width, height);
 }
 /// <summary>
 /// Called when an element should be painted.
 /// |type| indicates whether the element is the view or the popup widget.
 /// |buffer| contains the pixel data for the whole image.
 /// |dirtyRects| indicates the portions of the image that have been repainted.
 /// On Windows |buffer| will be width*height*4 bytes in size and represents a BGRA image with an upper-left origin.
 /// </summary>
 protected virtual void OnPaint(CefBrowser browser, CefPaintElementType type, CefRect[] dirtyRect, IntPtr buffer)
 {
 }
        protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
        {
            if (CreateTextureEvent != null)
            {
                lock (texturesLock)
                {
                    SharedTexture textureToRender;
                    if (textures.Count <= currentTextureIndex)
                    {
                        IntPtr sharedTextureHandle;
                        CreateTextureEvent((UInt32)width, (UInt32)height, out sharedTextureHandle);

                        if (sharedTextureHandle == IntPtr.Zero)
                        {
                            API.Instance.Log("BrowserRenderHandler::OnPaint failed to create texture");
                            return;
                        }

                        // TODO : eventually switch to shared textures
                        //Texture texture = GraphicsSystem.Instance.CreateTextureFromSharedHandle((UInt32)width, (UInt32)height, sharedTextureHandle);

                        Texture texture = new Texture(sharedTextureHandle);

                        textureToRender = new SharedTexture
                        {
                            Texture = texture,
                            Handle = sharedTextureHandle
                        };

                        textures.Add(textureToRender);
                    }
                    else
                    {
                        textureToRender = textures[currentTextureIndex];
                    }

                    textureToRender.Texture.SetImage(buffer, GSImageFormat.GS_IMAGEFORMAT_BGRA, (UInt32)(width * 4));

                    // loop the current texture index
                    currentTextureIndex = ++currentTextureIndex % textureCount;
                    PaintEvent(textureToRender.Handle);
                }
            }
        }
示例#40
0
        /// <summary>
        /// Get the size of the specified element.
        /// This method should only be called on the UI thread.
        /// </summary>
        public bool GetSize(CefPaintElementType type, out int width, out int height)
        {
            int m_width;
            int m_height;

            var result = cef_browser_t.invoke_get_size(this.ptr, (cef_paint_element_type_t)type, &m_width, &m_height);

            width = m_width;
            height = m_height;

            return result != 0;
        }
        private void on_paint(cef_render_handler_t* self, cef_browser_t* browser, CefPaintElementType type, UIntPtr dirtyRectsCount, cef_rect_t* dirtyRects, void* buffer, int width, int height)
        {
            CheckSelf(self);

            var m_browser = CefBrowser.FromNative(browser);

            // TODO: reuse arrays?
            var m_dirtyRects = new CefRectangle[(int)dirtyRectsCount];

            var count = (int)dirtyRectsCount;
            var rect = dirtyRects;
            for (var i = 0; i < count; i++)
            {
                m_dirtyRects[i].X = rect->x;
                m_dirtyRects[i].Y = rect->y;
                m_dirtyRects[i].Width = rect->width;
                m_dirtyRects[i].Height = rect->height;

                rect++;
            }

            OnPaint(m_browser, type, m_dirtyRects, (IntPtr)buffer, width, height);
        }
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     throw new NotImplementedException();
 }
示例#43
0
 protected override void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height)
 {
     renderer.OnPaint(browser, buffer, width, height, dirtyRects);
 }
 /// <summary>
 /// Called when an element should be painted. |type| indicates whether the
 /// element is the view or the popup widget. |buffer| contains the pixel data
 /// for the whole image. |dirtyRects| contains the set of rectangles that need
 /// to be repainted. On Windows |buffer| will be |width|*|height|*4 bytes
 /// in size and represents a BGRA image with an upper-left origin.
 /// </summary>
 protected abstract void OnPaint(CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height);
示例#45
0
        internal void HandleViewPaint( CefBrowser browser, CefPaintElementType type, CefRectangle[] dirtyRects, IntPtr buffer, int width, int height )
        {
            if( texture == null )
                return;

            if( width == 0 || height == 0 )
                return;

            if( width != viewSize.X || height != viewSize.Y )
                return;

            try
            {
                int stride = width * 4;
                int sourceBufferSize = stride * height;

                if( ( renderBuffer == null ) || ( sourceBufferSize > renderBuffer.Length ) )
                    renderBuffer = new byte[ sourceBufferSize ];

                Marshal.Copy( buffer, renderBuffer, 0, sourceBufferSize );

                forceUpdateTexture = true;
            }
            catch( Exception ex )
            {
                Log.Error( "WebBrowserControl: Caught exception in HandleViewPaint(): " + ex.Message );
            }
        }