Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a SkiaVisual that allows allows external use of SkiaSharp #15212

Closed
wants to merge 7 commits into from

Conversation

ramezgerges
Copy link
Contributor

GitHub Issue (If applicable): closes #15166

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@github-actions github-actions bot added area/skia ✏️ Categorizes an issue or PR as relevant to Skia area/automation Categorizes an issue or PR as relevant to project automation labels Jan 25, 2024
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15212/index.html

Invalidate(session.Surface.Canvas);
}

protected abstract void Invalidate(SKCanvas canvas);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramezgerges This method should be called Render. An Invalidate is also needed as a way for a visual to ask for a render, though there may be a Compositor way of doing so.

By default, the visual does not have any size specified, which means that we'll need to explain how to use it as well.

Multiple things:

  • Can you add runtime tests?
  • Can you add a new documentation page?

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15212/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-15212/index.html

@lindexi
Copy link
Contributor

lindexi commented Apr 1, 2024

@ramezgerges Thank you and can I ask any update ?

@jeromelaban
Copy link
Member

@lindexi we're still working on it at this time, there's a bit of work that's involving the reference API that we have not resolved yet.

{
internal override void Draw(in DrawingSession session)
{
Invalidate(session.Surface.Canvas);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Invalidate(session.Surface.Canvas);
Invalidate(session.Canvas);

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-15212/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-15212/index.html


# SkiaVisual

A `SkiaVisual` is a abstract Visual that provides Uno applications the ability to utilize SkiaSharp to draw directly on the Skia canvas that is used internally by Uno to draw the window. To use `SkiaVisual`, create a subclass of `SkiaVisual` and override the `RenderOverride` method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `SkiaVisual` is a abstract Visual that provides Uno applications the ability to utilize SkiaSharp to draw directly on the Skia canvas that is used internally by Uno to draw the window. To use `SkiaVisual`, create a subclass of `SkiaVisual` and override the `RenderOverride` method.
A `SkiaVisual` is an abstract `Visual` that provides Uno applications the ability to utilize SkiaSharp to draw directly on the Skia canvas that is used internally by Uno to draw the window. To use `SkiaVisual`, create a subclass of `SkiaVisual` and override the `RenderOverride` method.

private bool ApplyFlowDirection()
{
var oldMatrix = _skiaVisual.TransformMatrix;
if (FlowDirection == FlowDirection.RightToLeft && !MirroredWhenRightToLeft)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, mirroring happen when FlowDirection is the opposite of the parent, which is something we're supposed to already do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is supposed to disable this behaviour, since most likely, the user will want to keep the drawing the same regardless of RTL (like an image).

/// By default, SKCanvasElement will have the origin at the top-left of the drawing area with the normal directions increasing down and right.
/// If MirroredWhenRightToLeft is true, the drawing will be horizontally reflected when <see cref="SKCanvasElement.FlowDirection"/> is <see cref="FlowDirection.RightToLeft"/>.
/// </summary>
public bool MirroredWhenRightToLeft
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we really need this API. I tend to avoid adding public APIs without enough motivation. We could probably postpone it unless it's clear that we need it.

Copy link
Contributor Author

@ramezgerges ramezgerges May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this is something that the user can do by hand, but it might be common enough and annoying enough to get right that we should provide it ourselves. @jeromelaban thoughts?

@ramezgerges
Copy link
Contributor Author

closing in favor of #16621.

@ramezgerges ramezgerges closed this May 7, 2024
@ramezgerges ramezgerges deleted the skiavisual branch May 8, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/automation Categorizes an issue or PR as relevant to project automation area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for SkiaVisual
5 participants