Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ protected override void OnElementChanged(ElementChangedEventArgs<TFormsView> e)
if (Control != null)
{
var control = Control;
#if __ANDROID__
control.SetRenderer(null);
#else
control.PaintSurface -= OnPaintSurface;
#endif
}

if (e.NewElement != null)
Expand All @@ -47,7 +51,11 @@ protected override void OnElementChanged(ElementChangedEventArgs<TFormsView> e)

// create the native view
var view = CreateNativeControl();
#if __ANDROID__
view.SetRenderer(new Renderer(newController));
#else
view.PaintSurface += OnPaintSurface;
#endif
SetNativeControl(view);

// subscribe to events from the user
Expand Down Expand Up @@ -96,7 +104,11 @@ protected override void Dispose(bool disposing)
var control = Control;
if (control != null)
{
#if __ANDROID__
control.SetRenderer(null);
#else
control.PaintSurface -= OnPaintSurface;
#endif
}

base.Dispose(disposing);
Expand Down Expand Up @@ -127,5 +139,22 @@ private void OnPaintSurface(object sender, SKNativePaintGLSurfaceEventArgs e)
// the control is being repainted, let the user know
controller?.OnPaintSurface(new SKPaintGLSurfaceEventArgs(e.Surface, e.RenderTarget));
}

#if __ANDROID__
private class Renderer : SKNativeView.ISKRenderer
{
private readonly ISKGLViewController controller;

public Renderer(ISKGLViewController controller)
{
this.controller = controller;
}

public void OnDrawFrame(SKSurface surface, GRBackendRenderTargetDesc renderTarget)
{
controller.OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));
}
}
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you need this renderer construct? Is there a problem with the PaintSurface subscriptions? (just curious)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The types are different. The incoming event is a native type in the SkiaSharp.Views.PLATFORM assembly, and I am constructing a SkiaSharp.Views.Forms assembly type. It is the programmer within that couldn't think of different names :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh ok 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No wait. My bad.

The Android GL view does not use events. It is the surface-based system, which separates the view from the actual rendering via this render construct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

}
}