internal static unsafe void DirectBlit(RenderBuffer buffer, ref Texture2D texture2d) { //TODO : Test if d3dt can be cached IDirect3DTexture9 d3dt = GetIUnknownObject <IDirect3DTexture9>(texture2d); //XE.Performance.Log("IDirect3DTexture9 Is "+(d3dt!=null ? d3dt.ToString():"null")); //D3DSURFACE_DESC desc=new D3DSURFACE_DESC(); //Marshal.ThrowExceptionForHR(d3dt.GetLevelDesc(0, out desc)); //XE.Performance.Log("LevelDesc Format "+desc.Format.ToString()); //XE.Performance.Log("LevelDesc MultiSampleQuality "+desc.MultiSampleQuality.ToString()); //XE.Performance.Log("LevelDesc MultiSampleType "+desc.MultiSampleType.ToString()); //XE.Performance.Log("LevelDesc Pool "+desc.Pool.ToString()); //XE.Performance.Log("LevelDesc Type "+desc.Type.ToString()); //XE.Performance.Log("LevelDesc Usage "+desc.Usage.ToString()); //XE.Performance.Log("LevelDesc Width "+desc.Width.ToString()); //XE.Performance.Log("LevelDesc Height "+desc.Height.ToString()); D3DLOCKED_RECT lockrect = new D3DLOCKED_RECT(); RECT rect = new RECT(); Marshal.ThrowExceptionForHR(d3dt.LockRect(0, out lockrect, rect, 0)); //XE.Performance.Log("LockRect Pitch "+lockrect.Pitch.ToString()); //XE.Performance.Log("LockRect pBits "+((uint)lockrect.pBits).ToString()); buffer.CopyTo((IntPtr)(uint)(lockrect.pBits), lockrect.Pitch, 4, false); d3dt.UnlockRect(0); //Meve onto Dispose() if d3dt will be cached d3dt Marshal.ReleaseComObject(d3dt); }
public static Bitmap ToBitmap(this RenderBuffer buffer) { const int depth = 4; const PixelFormat pf = PixelFormat.Format32bppArgb; // Create bitmap Bitmap bitmap = new Bitmap(buffer.GetWidth(), buffer.GetHeight(), pf); BitmapData data = bitmap.LockBits(new Rectangle(0, 0, buffer.GetWidth(), buffer.GetHeight()), ImageLockMode.WriteOnly, bitmap.PixelFormat); buffer.CopyTo(data.Scan0, buffer.GetWidth() * depth, depth, false); bitmap.UnlockBits(data); return(bitmap); }
void Render() { if ((webView == null) || !webView.IsLive) { return; } if (!webView.IsDirty) { return; } try { RenderBuffer rBuffer = webView.Render(); if (rBuffer != null) { lock (fbLockObject) { // Only recreate the bitmap if the size of the buffer has changed. if (frameBuffer == null || frameBuffer.Width != rBuffer.Width || frameBuffer.Height != rBuffer.Height) { if (frameBuffer != null) { frameBuffer.Dispose(); } frameBuffer = new Bitmap(rBuffer.Width, rBuffer.Height, PixelFormat.Format32bppPArgb); } BitmapData bits = frameBuffer.LockBits( new System.Drawing.Rectangle(0, 0, rBuffer.Width, rBuffer.Height), ImageLockMode.ReadWrite, frameBuffer.PixelFormat); // Copy to Bitmap specifying ConvertToRGBA = true. rBuffer.CopyTo(bits.Scan0, bits.Stride, 4, false); frameBuffer.UnlockBits(bits); //frameBuffer.Save(@"E:\Temp\test.jpg", ImageFormat.Jpeg); if (BrowserRenderEvent != null) { BrowserRenderEvent(Id, frameBuffer); } } } } catch { /* */ } finally { GC.Collect(); } }
private void Update() { if (!WebCore.IsRunning) { return; } if (webView.IsDirty) { RenderBuffer rBuffer = webView.Render(); if (rBuffer != null) { rBuffer.CopyTo(PixelsHandle.AddrOfPinnedObject(), rBuffer.Rowspan, 4, true, true); texture.SetPixels32(Pixels, 0); texture.Apply(false, false); } } }