void RenderPass(Common.Region dc, Common.Size ReqSize) { renderTime.Start(); // FIXME so much object spam and disposal in this very high frequency function (also inside Resize called belw). My poor megabytes! // Resize the form and backbuffer to noForm.Size, and fire the noForms sizechanged Resize(ReqSize); // make size... Win32Util.Size w32Size = new Win32Util.Size((int)ReqSize.width, (int)ReqSize.height); Win32Util.SetWindowSize(w32Size, hWnd); // Allow noform size to change as requested..like a layout hook (truncating layout passes with the render passes for performance) RenderSizeChanged(ReqSize); lock (noForm) { // Do Drawing stuff DrawingSize rtSize = new DrawingSize((int)d2dRenderTarget.Size.Width, (int)d2dRenderTarget.Size.Height); using (Texture2D t2d = new Texture2D(backBuffer.Device, backBuffer.Description)) { using (Surface1 srf = t2d.QueryInterface <Surface1>()) { using (RenderTarget trt = new RenderTarget(d2dFactory, srf, new RenderTargetProperties(d2dRenderTarget.PixelFormat))) { _backRenderer.renderTarget = trt; trt.BeginDraw(); noForm.DrawBase(this, dc); // Fill with transparency the edgeBuffer! trt.FillRectangle(new RectangleF(0, noForm.Size.height, noForm.Size.width + edgeBufferSize, noForm.Size.height + edgeBufferSize), scbTrans); trt.FillRectangle(new RectangleF(noForm.Size.width, 0, noForm.Size.width + edgeBufferSize, noForm.Size.height + edgeBufferSize), scbTrans); trt.EndDraw(); foreach (var rc in dc.AsRectangles()) { t2d.Device.CopySubresourceRegion(t2d, 0, new ResourceRegion() { Left = (int)rc.left, Right = (int)rc.right, Top = (int)rc.top, Bottom = (int)rc.bottom, Back = 1, Front = 0 }, backBuffer, 0, (int)rc.left, (int)rc.top, 0); } } } } // Present DC to windows (ugh layered windows sad times) IntPtr dxHdc = surface.GetDC(false); System.Drawing.Graphics dxdc = System.Drawing.Graphics.FromHdc(dxHdc); Win32Util.Point dstPoint = new Win32Util.Point((int)(noForm.Location.X), (int)(noForm.Location.Y)); Win32Util.Point srcPoint = new Win32Util.Point(0, 0); Win32Util.Size pSize = new Win32Util.Size(rtSize.Width, rtSize.Height); Win32Util.BLENDFUNCTION bf = new Win32Util.BLENDFUNCTION() { SourceConstantAlpha = 255, AlphaFormat = Win32Util.AC_SRC_ALPHA, BlendFlags = 0, BlendOp = 0 }; bool suc = Win32Util.UpdateLayeredWindow(hWnd, someDC, ref dstPoint, ref pSize, dxHdc, ref srcPoint, 1, ref bf, 2); surface.ReleaseDC(); dxdc.Dispose(); } lastFrameRenderDuration = 1f / (float)renderTime.Elapsed.TotalSeconds; renderTime.Reset(); }