|
7 | 7 | using Microsoft.UI.Xaml;
|
8 | 8 | using Microsoft.UI.Xaml.Controls;
|
9 | 9 | using SkiaSharp;
|
| 10 | +using Uno.UI.Xaml.Core; |
10 | 11 |
|
11 | 12 | namespace Uno.UI.Helpers;
|
12 | 13 |
|
13 | 14 | internal static class SkiaRenderHelper
|
14 | 15 | {
|
| 16 | + internal static (SKPicture, SKPath) RecordPictureAndReturnPath(int width, int height, ContainerVisual rootVisual, bool invertPath) |
| 17 | + { |
| 18 | + using var recorder = new SKPictureRecorder(); |
| 19 | + using var canvas = recorder.BeginRecording(new SKRect(-999999, -999999, 999999, 999999)); |
| 20 | + using var _ = new SKAutoCanvasRestore(canvas, true); |
| 21 | + canvas.Clear(SKColors.Transparent); |
| 22 | + var path = RenderRootVisualAndReturnPath(width, height, rootVisual, canvas, invertPath); |
| 23 | + var picture = recorder.EndRecording(); |
| 24 | + |
| 25 | + return (picture, path); |
| 26 | + } |
| 27 | + |
15 | 28 | /// <summary>
|
16 | 29 | /// Does a rendering cycle and returns a path that represents the visible area of the native views.
|
17 | 30 | /// Takes the current TotalMatrix of the surface's canvas into account
|
18 | 31 | /// </summary>
|
19 |
| - public static SKPath RenderRootVisualAndReturnNegativePath(int width, int height, ContainerVisual rootVisual, SKCanvas canvas) |
| 32 | + public static SKPath RenderRootVisualAndReturnPath(int width, int height, ContainerVisual rootVisual, SKCanvas canvas, bool invertPath) |
20 | 33 | {
|
21 | 34 | rootVisual.Compositor.RenderRootVisual(canvas, rootVisual);
|
22 |
| - if (!ContentPresenter.HasNativeElements()) |
| 35 | + SKPath outPath = new SKPath(); |
| 36 | + if (ContentPresenter.HasNativeElements()) |
23 | 37 | {
|
24 |
| - return new SKPath(); |
| 38 | + var parentClipPath = new SKPath(); |
| 39 | + parentClipPath.AddRect(new SKRect(0, 0, width, height)); |
| 40 | + rootVisual.GetNativeViewPath(parentClipPath, outPath); |
| 41 | + outPath.Transform(canvas.TotalMatrix, outPath); // canvas.TotalMatrix should be the same before and after RenderRootVisual because of the Save and Restore calls inside |
25 | 42 | }
|
26 |
| - var parentClipPath = new SKPath(); |
27 |
| - parentClipPath.AddRect(new SKRect(0, 0, width, height)); |
28 |
| - var outPath = new SKPath(); |
29 |
| - rootVisual.GetNativeViewPath(parentClipPath, outPath); |
30 |
| - outPath.Transform(canvas.TotalMatrix, outPath); // canvas.TotalMatrix should be the same before and after RenderRootVisual because of the Save and Restore calls inside |
31 |
| - return outPath; |
32 |
| - } |
33 | 43 |
|
34 |
| - /// <summary> |
35 |
| - /// Does a rendering cycle and returns a path that represents the total area that was drawn |
36 |
| - /// minus the native view areas. |
37 |
| - /// </summary> |
38 |
| - public static SKPath RenderRootVisualAndReturnPath(int width, int height, ContainerVisual rootVisual, SKCanvas canvas) |
39 |
| - { |
40 |
| - var outPath = new SKPath(); |
41 |
| - outPath.AddRect(new SKRect(0, 0, width, height)); |
42 |
| - outPath.Transform(canvas.TotalMatrix, outPath); |
43 |
| - outPath.Op(RenderRootVisualAndReturnNegativePath(width, height, rootVisual, canvas), SKPathOp.Difference, outPath); |
44 |
| - return outPath; |
| 44 | + if (invertPath) |
| 45 | + { |
| 46 | + var invertedPath = new SKPath(); |
| 47 | + invertedPath.AddRect(new SKRect(0, 0, width, height)); |
| 48 | + invertedPath.Transform(canvas.TotalMatrix, invertedPath); |
| 49 | + invertedPath.Op(outPath, SKPathOp.Difference, invertedPath); |
| 50 | + return invertedPath; |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + return outPath; |
| 55 | + } |
45 | 56 | }
|
46 | 57 |
|
47 | 58 | public class FpsHelper
|
|
0 commit comments