public void RenderFrame(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (!this.terminated) { try { if (surfaceBuffer != null && (surfaceBuffer.Width != width || surfaceBuffer.Height != height)) { surfaceBuffer.Dispose(); surfaceBuffer = null; } if (surfaceBuffer == null) { surfaceBuffer = new DIBitmap(width, height); } // TODO: DirtyRect に対応 surfaceBuffer.SetSurfaceData(buffer, (uint)(width * height * 4)); UpdateLayeredWindowBitmap(); } catch { } } }
void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (screenshotSource != null) { try { var bmp = new Bitmap(width, height); var data = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); NativeMethods.CopyMemory(data.Scan0, buffer, (uint)(width * height * 4)); bmp.UnlockBits(data); screenshotSource.SetResult(bmp); screenshotSource = null; } catch (Exception ex) { screenshotSource.SetException(ex); screenshotSource = null; } } else { target.RenderFrame(type, dirtyRect, buffer, width, height); } }
/// <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); } }
void IRenderHandler.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (type == PaintElementType.View) { _paintBufferLock.EnterWriteLock(); try { if (_width != width || _height != height) { _width = width; _height = height; if (_paintBuffer.IsAllocated == true) { _paintBuffer.Free(); } _paintBuffer = GCHandle.Alloc( new byte[_width * _height * 4], GCHandleType.Pinned ); } WinApi.CopyMemory( _paintBuffer.AddrOfPinnedObject(), buffer, (uint)(width * height * 4) ); } finally { _paintBufferLock.ExitWriteLock(); } } }
public virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { var isPopup = type == PaintElementType.Popup; var bitmapBuffer = isPopup ? PopupBuffer : BitmapBuffer; bitmapBuffer.UpdateBuffer(width, height, buffer, dirtyRect); }
public void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { byte[] internalBuffer = new byte[width * height * 4]; Marshal.Copy(buffer, internalBuffer, 0, internalBuffer.Length); GfxMemory.WriteBytes(internalBuffer); }
public PaintEventArgs(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { this.Type = type; this.DirtyRect = dirtyRect; this.Buffer = buffer; this.Width = width; this.Height = height; }
public override void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { var length = bytesPerPixel * width * height; // If this is a popup render, copy it across to the buffer. if (type != PaintElementType.View) { Marshal.Copy(buffer, popupBuffer, 0, length); return; } // If the paint size does not match our buffer size, we're likely resizing and paint hasn't caught up. Noop. if (width != size.Width && height != size.Height) { return; } var frame = new BitmapFrame() { Length = length, Width = width, Height = height, DirtyX = dirtyRect.X, DirtyY = dirtyRect.Y, DirtyWidth = dirtyRect.Width, DirtyHeight = dirtyRect.Height, }; WriteToBuffers(frame, buffer, true); // Intersect with dirty? if (popupVisible) { var popupFrame = new BitmapFrame() { Length = length, Width = width, Height = height, DirtyX = popupRect.X, DirtyY = popupRect.Y, DirtyWidth = popupRect.Width, DirtyHeight = popupRect.Height, }; var handle = GCHandle.Alloc(popupBuffer, GCHandleType.Pinned); WriteToBuffers(popupFrame, handle.AddrOfPinnedObject(), false); handle.Free(); } // Render is complete, clean up obsolete buffers var obsoleteBuffers = this.obsoleteBuffers; this.obsoleteBuffers = new ConcurrentBag <SharedBuffer>(); foreach (var toDispose in obsoleteBuffers) { toDispose.Dispose(); } }
public void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (type == PaintElementType.View) { while (Interlocked.CompareExchange(ref this.dirtyState, 1, 0) == 0) { ; } this.BitmapBuffer.UpdateBuffer(width, height, buffer, dirtyRect); } }
public void RenderFrame(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (!this.terminated) { try { lock (surfaceLock) { Bitmap surface = type == PaintElementType.View ? surfaceBuffer : popupBuffer; if (surface != null && (surface.Width != width || surface.Height != height)) { surface.Dispose(); surface = null; } if (surface == null) { surface = new Bitmap(width, height); if (type == PaintElementType.View) { surfaceBuffer = surface; } else { popupBuffer = surface; } } var data = surface.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb); NativeMethods.CopyMemory(data.Scan0, buffer, (uint)(width * height * 4)); surface.UnlockBits(data); } var dnDirtyRect = new Rectangle(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height); if (type == PaintElementType.View) { Invalidate(new Region(dnDirtyRect), true); } else { Invalidate(true); } } catch (Exception ex) { Trace.WriteLine(ex.ToString()); } } }
public virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (Render && _browser.IsBrowserInitialized) { ResizeBuffer(width, height); Marshal.Copy(buffer, _buffer, 0, _buffer.Length); var bitmap = new Bitmap(width, height, PixelFormat.Format32bppPArgb); var bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppPArgb); Marshal.Copy(_buffer, 0, bitmapData.Scan0, _buffer.Length); bitmap.UnlockBits(bitmapData); OnBrowserPaint(bitmap); } }
public virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { if (type == PaintElementType.View) { m_Lock.EnterUpgradeableReadLock(); try { if (!Buffer.IsAllocated || width != Width || height != Height) { m_Lock.EnterWriteLock(); try { Width = width; Height = height; BufferSize = width * height * 4; if (Buffer.IsAllocated) { Buffer.Free(); } Buffer = GCHandle.Alloc(new byte[BufferSize], GCHandleType.Pinned); } finally { m_Lock.ExitWriteLock(); } } WinApi.CopyMemory(Buffer.AddrOfPinnedObject(), buffer, (uint)BufferSize); } finally { m_Lock.ExitUpgradeableReadLock(); } } }
public abstract void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height);
/// <summary> /// Called when an element has been rendered to the shared texture handle. /// This method is only called when <see cref="IWindowInfo.SharedTextureEnabled"/> is set to true /// </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="sharedHandle">is the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method.</param> void IRenderWebBrowser.OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle) { RenderHandler?.OnAcceleratedPaint(type, dirtyRect, sharedHandle); }
/// <summary> /// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously. /// </summary> /// <param name="type">indicates which surface to re-paint either View or Popup.</param> public void Invalidate(PaintElementType type) { managedCefBrowserAdapter.Invalidate(type); }
/// <summary> /// Called when an element has been rendered to the shared texture handle. /// This method is only called when <see cref="IWindowInfo.SharedTextureEnabled"/> is set to true /// </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="sharedHandle">is the handle for a D3D11 Texture2D that can be accessed via ID3D11Device using the OpenSharedResource method.</param> public virtual void OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle) { //NOT USED }
protected virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { RenderHandler?.OnPaint(type, dirtyRect, buffer, width, height); }
public void OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle) { // UNUSED // CEF has removed support for DX accelerated paint shared textures, pending re-implementation in // chromium's new compositor, Vis. Ref: https://bitbucket.org/chromiumembedded/cef/issues/2575/viz-implementation-for-osr }
public override void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { var targetTexture = type switch { PaintElementType.View => texture, PaintElementType.Popup => popupTexture, _ => throw new Exception($"Unknown paint type {type}"), }; // Nasty hack; we're keeping a ref to the view buffer for pixel lookups without going through DX if (type == PaintElementType.View) { bufferPtr = buffer; bufferWidth = width; bufferHeight = height; } // Calculate offset multipliers for the current buffer var rowPitch = width * bytesPerPixel; var depthPitch = rowPitch * height; // Build the destination region for the dirty rect that we'll draw to var texDesc = targetTexture.Description; var sourceRegionPtr = buffer + (dirtyRect.X * bytesPerPixel) + (dirtyRect.Y * rowPitch); var destinationRegion = new D3D11.ResourceRegion() { Top = Math.Min(dirtyRect.Y, texDesc.Height), Bottom = Math.Min(dirtyRect.Y + dirtyRect.Height, texDesc.Height), Left = Math.Min(dirtyRect.X, texDesc.Width), Right = Math.Min(dirtyRect.X + dirtyRect.Width, texDesc.Width), Front = 0, Back = 1, }; // Draw to the target var context = targetTexture.Device.ImmediateContext; context.UpdateSubresource(targetTexture, 0, destinationRegion, sourceRegionPtr, rowPitch, depthPitch); // Only need to do composition + flush on primary texture if (type != PaintElementType.View) { return; } // Intersect with dirty? if (popupVisible) { context.CopySubresourceRegion(popupTexture, 0, null, targetTexture, 0, popupRect.X, popupRect.Y); } context.Flush(); // Rendering is complete, clean up any obsolete textures var textures = obsoluteTextures; obsoluteTextures = new ConcurrentBag <D3D11.Texture2D>(); foreach (var texture in textures) { texture.Dispose(); } }
public void OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle) { }
public void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { Paint?.Invoke(this, new PaintEventArgs(type, dirtyRect, buffer, width, height)); }
void IRenderHandler.OnAcceleratedPaint(PaintElementType type, Rect dirtyRect, IntPtr sharedHandle) { // NOT USED }
void IRenderWebBrowser.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { form.RenderFrame(dirtyRect, buffer, width, height); }
/// <summary> /// Invalidate the view. The browser will call CefRenderHandler::OnPaint asynchronously. /// </summary> /// <param name="type">indicates which surface to re-paint either View or Popup.</param> public void Invalidate(PaintElementType type) { managedCefBrowserAdapter.Invalidate(type); }
public void RenderFrame(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height) { throw new NotImplementedException(); }