Exposing GRContext on the various GL views. Issue #358
This commit is contained in:
Родитель
2f706b08dd
Коммит
14a20e99ba
|
@ -165,9 +165,9 @@ namespace SkiaSharp.Views.Forms
|
|||
}
|
||||
|
||||
// the user asked for the size
|
||||
private void OnGetCanvasSize(object sender, GetCanvasSizeEventArgs e)
|
||||
private void OnGetCanvasSize(object sender, GetPropertyValueEventArgs<SKSize> e)
|
||||
{
|
||||
e.CanvasSize = Control?.CanvasSize ?? SKSize.Empty;
|
||||
e.Value = Control?.CanvasSize ?? SKSize.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ namespace SkiaSharp.Views.Forms
|
|||
#endif
|
||||
}
|
||||
|
||||
public GRContext GRContext => Control.GRContext;
|
||||
|
||||
#if __IOS__
|
||||
protected void SetDisablesUserInteraction(bool disablesUserInteraction)
|
||||
{
|
||||
|
@ -67,6 +69,7 @@ namespace SkiaSharp.Views.Forms
|
|||
// unsubscribe from events
|
||||
oldController.SurfaceInvalidated -= OnSurfaceInvalidated;
|
||||
oldController.GetCanvasSize -= OnGetCanvasSize;
|
||||
oldController.GetGRContext -= OnGetGRContext;
|
||||
}
|
||||
|
||||
if (e.NewElement != null)
|
||||
|
@ -90,6 +93,7 @@ namespace SkiaSharp.Views.Forms
|
|||
// subscribe to events from the user
|
||||
newController.SurfaceInvalidated += OnSurfaceInvalidated;
|
||||
newController.GetCanvasSize += OnGetCanvasSize;
|
||||
newController.GetGRContext += OnGetGRContext;
|
||||
|
||||
// start the rendering
|
||||
SetupRenderLoop(false);
|
||||
|
@ -163,9 +167,15 @@ namespace SkiaSharp.Views.Forms
|
|||
}
|
||||
|
||||
// the user asked for the size
|
||||
private void OnGetCanvasSize(object sender, GetCanvasSizeEventArgs e)
|
||||
private void OnGetCanvasSize(object sender, GetPropertyValueEventArgs<SKSize> e)
|
||||
{
|
||||
e.CanvasSize = Control?.CanvasSize ?? SKSize.Empty;
|
||||
e.Value = Control?.CanvasSize ?? SKSize.Empty;
|
||||
}
|
||||
|
||||
// the user asked for the current GRContext
|
||||
private void OnGetGRContext(object sender, GetPropertyValueEventArgs<GRContext> e)
|
||||
{
|
||||
e.Value = Control?.GRContext;
|
||||
}
|
||||
|
||||
private void OnPaintSurface(object sender, SKNativePaintGLSurfaceEventArgs e)
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace SkiaSharp.Views.Forms
|
||||
{
|
||||
internal class GetCanvasSizeEventArgs : EventArgs
|
||||
internal class GetPropertyValueEventArgs<T> : EventArgs
|
||||
{
|
||||
public SKSize CanvasSize { get; set; }
|
||||
public T Value { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
// the native listens to this event
|
||||
private event EventHandler SurfaceInvalidated;
|
||||
private event EventHandler<GetCanvasSizeEventArgs> GetCanvasSize;
|
||||
private event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
|
||||
// the user asks the for the size
|
||||
public SKSize CanvasSize
|
||||
|
@ -28,9 +28,9 @@ namespace SkiaSharp.Views.Forms
|
|||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetCanvasSizeEventArgs();
|
||||
var args = new GetPropertyValueEventArgs<SKSize>();
|
||||
GetCanvasSize?.Invoke(this, args);
|
||||
return args.CanvasSize;
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace SkiaSharp.Views.Forms
|
|||
remove { SurfaceInvalidated -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetCanvasSizeEventArgs> ISKCanvasViewController.GetCanvasSize
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> ISKCanvasViewController.GetCanvasSize
|
||||
{
|
||||
add { GetCanvasSize += value; }
|
||||
remove { GetCanvasSize -= value; }
|
||||
|
@ -99,7 +99,7 @@ namespace SkiaSharp.Views.Forms
|
|||
{
|
||||
// the native listens to this event
|
||||
event EventHandler SurfaceInvalidated;
|
||||
event EventHandler<GetCanvasSizeEventArgs> GetCanvasSize;
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
|
||||
// the native view tells the user to repaint
|
||||
void OnPaintSurface(SKPaintSurfaceEventArgs e);
|
||||
|
|
|
@ -32,7 +32,8 @@ namespace SkiaSharp.Views.Forms
|
|||
|
||||
// the native listens to this event
|
||||
private event EventHandler SurfaceInvalidated;
|
||||
private event EventHandler<GetCanvasSizeEventArgs> GetCanvasSize;
|
||||
private event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
private event EventHandler<GetPropertyValueEventArgs<GRContext>> GetGRContext;
|
||||
|
||||
// the user asks the for the size
|
||||
public SKSize CanvasSize
|
||||
|
@ -40,9 +41,21 @@ namespace SkiaSharp.Views.Forms
|
|||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetCanvasSizeEventArgs();
|
||||
var args = new GetPropertyValueEventArgs<SKSize>();
|
||||
GetCanvasSize?.Invoke(this, args);
|
||||
return args.CanvasSize;
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
// the user asks the for the current GRContext
|
||||
public GRContext GRContext
|
||||
{
|
||||
get
|
||||
{
|
||||
// send a mesage to the native view
|
||||
var args = new GetPropertyValueEventArgs<GRContext>();
|
||||
GetGRContext?.Invoke(this, args);
|
||||
return args.Value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,12 +86,18 @@ namespace SkiaSharp.Views.Forms
|
|||
remove { SurfaceInvalidated -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetCanvasSizeEventArgs> ISKGLViewController.GetCanvasSize
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> ISKGLViewController.GetCanvasSize
|
||||
{
|
||||
add { GetCanvasSize += value; }
|
||||
remove { GetCanvasSize -= value; }
|
||||
}
|
||||
|
||||
event EventHandler<GetPropertyValueEventArgs<GRContext>> ISKGLViewController.GetGRContext
|
||||
{
|
||||
add { GetGRContext += value; }
|
||||
remove { GetGRContext -= value; }
|
||||
}
|
||||
|
||||
void ISKGLViewController.OnPaintSurface(SKPaintGLSurfaceEventArgs e)
|
||||
{
|
||||
OnPaintSurface(e);
|
||||
|
@ -99,7 +118,8 @@ namespace SkiaSharp.Views.Forms
|
|||
{
|
||||
// the native listens to this event
|
||||
event EventHandler SurfaceInvalidated;
|
||||
event EventHandler<GetCanvasSizeEventArgs> GetCanvasSize;
|
||||
event EventHandler<GetPropertyValueEventArgs<SKSize>> GetCanvasSize;
|
||||
event EventHandler<GetPropertyValueEventArgs<GRContext>> GetGRContext;
|
||||
|
||||
// the native view tells the user to repaint
|
||||
void OnPaintSurface(SKPaintGLSurfaceEventArgs e);
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace SkiaSharp.Views.Android
|
|||
|
||||
public SKSize CanvasSize => renderer.CanvasSize;
|
||||
|
||||
public GRContext GRContext => renderer.GRContext;
|
||||
|
||||
public virtual void SetRenderer(ISKRenderer renderer)
|
||||
{
|
||||
skRenderer = renderer;
|
||||
|
|
|
@ -13,6 +13,8 @@ namespace SkiaSharp.Views.Android
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
protected abstract void OnDrawFrame(SKSurface surface, GRBackendRenderTargetDesc renderTarget);
|
||||
|
||||
public void OnDrawFrame(IGL10 gl)
|
||||
|
|
|
@ -28,6 +28,8 @@ namespace SkiaSharp.Views.iOS
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
public virtual void Render()
|
||||
{
|
||||
if (glContext == null)
|
||||
|
|
|
@ -75,6 +75,8 @@ namespace SkiaSharp.Views.iOS
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
public new void DrawInRect(GLKView view, CGRect rect)
|
||||
{
|
||||
if (designMode)
|
||||
|
|
|
@ -21,6 +21,8 @@ namespace SkiaSharp.Views.Desktop
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => grContext;
|
||||
|
||||
public event EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
|
|
|
@ -20,6 +20,8 @@ namespace SkiaSharp.Views.Mac
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
public event EventHandler<SKPaintGLSurfaceEventArgs> PaintSurface;
|
||||
|
||||
public virtual void DrawInSurface(SKSurface surface, GRBackendRenderTargetDesc renderTarget)
|
||||
|
|
|
@ -63,6 +63,8 @@ namespace SkiaSharp.Views.Mac
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
public override void PrepareOpenGL()
|
||||
{
|
||||
base.PrepareOpenGL();
|
||||
|
|
|
@ -25,6 +25,8 @@ namespace SkiaSharp.Views.UWP
|
|||
|
||||
public SKSize CanvasSize => new SKSize(renderTarget.Width, renderTarget.Height);
|
||||
|
||||
public GRContext GRContext => context;
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
var arrange = base.ArrangeOverride(finalSize);
|
||||
|
|
Загрузка…
Ссылка в новой задаче