protected void AssertVisual(string expectedHash, VisualElement root, int width = 1920, int height = 1080) { var testMethod = new StackTrace().GetFrame(1)?.GetMethod(); var testMethodName = $"{testMethod?.ReflectedType?.Name}_{testMethod?.Name}"; var surface = new IxenSurface(root); surface.ComputeLayout(width, height); SKBitmap bitmap = surface.RenderToBitmap(); byte[] md5hash = _md5.ComputeHash(bitmap.Bytes); string hash = Convert.ToHexString(md5hash).ToLower(); string fileExpectedPath = Path.Combine(_outputRendersDir, $"{testMethodName}_EXPECTED.png"); string fileErrorPath = Path.Combine(_outputRendersDir, $"{testMethodName}_NOK.png"); if (expectedHash == hash) { File.Delete(fileErrorPath); if (!File.Exists(fileExpectedPath)) { DumpBitmapToFile(fileExpectedPath, bitmap); } } else { DumpBitmapToFile(fileErrorPath, bitmap); Assert.Fail(); } }
private void OnPaint(int width, int height) { _pixelBuffer.EnsureAlloc(width, height); _ixenSurface.ComputeLayout(width, height); _skImageInfo = new SKImageInfo(width, height, SKColorType.Bgra8888, SKAlphaType.Premul); _painted = false; try { using (_skSurface = SKSurface.Create(_skImageInfo, _pixelBuffer.Ptr, _pixelBuffer.RowBytes)) { if (_skSurface != null) { _ixenSurface.Render(_skSurface.Canvas); _painted = true; } } } finally { if (_painted) { WindowApi.SetWindowPixelsBuffer(_windowPtr, _pixelBuffer.Ptr); } } }