private CVReturn HandleDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { try { if (_paused) { return(CVReturn.Success); } if (GraphicsDevice != null) { if (_resized) { _resized = false; MainSwapchain.Resize(_width, _height); Resized?.Invoke(); } Rendering?.Invoke(); } } catch (Exception e) { Debug.WriteLine("Encountered an error while rendering: " + e); throw; } return(CVReturn.Success); }
public void DefaultConstructorTest() { TestRuntime.AssertNotVSTS(); Assert.DoesNotThrow(() => { using var displayLink = new CVDisplayLink(); }); }
void SetupRenderLoop(bool oneShot) { if (_displayLink != null) { return; } if (!oneShot && !Element.HasRenderLoop) { return; } _displayLink = new CVDisplayLink(); //.Create(() => //{ // var control = Control; // var model = Element; // if (control != null) // control.Display(); // if (control == null || model == null || !model.HasRenderLoop) // { // _displayLink.Invalidate(); // _displayLink.Dispose(); // _displayLink = null; // } //}); //_displayLink.(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); }
public void GetTypeIdTest() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); Assert.DoesNotThrow(() => { CVDisplayLink.GetTypeId(); }, "Throws"); }
public void SetCurrentDisplayOpenGLTest() { TestRuntime.AssertNotVSTS(); Assert.DoesNotThrow(() => { using var displayLink = new CVDisplayLink(); displayLink.SetCurrentDisplay(CGDisplay.MainDisplayID); }); }
protected override void EnableTimer() { this.link = Xamarin CoreAnimation.CADisplayLink.Create(() => this.SendSignals (-1)); this.link.Start(); // TODO: Does this work? //this.link.AddToRunLoop (NSRunLoop.Current, NSRunLoop.NSRunLoopCommonModes); }
public void GetCurrentDisplayTest() { TestRuntime.AssertNotVSTS(); Assert.DoesNotThrow(() => { using var displayLink = new CVDisplayLink(); Assert.AreEqual(CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay()); }); }
public void CreateFromDisplayWrongIdTest() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); Assert.DoesNotThrow(() => { using var displayLink = CVDisplayLink.CreateFromDisplayId(UInt32.MaxValue); Assert.Null(displayLink, "null"); }, "Throws"); }
public void CreateFromDisplayIdValidIdTest() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); Assert.DoesNotThrow(() => { using var displayLink = CVDisplayLink.CreateFromDisplayId((uint)CGDisplay.MainDisplayID); Assert.NotNull(displayLink, "Not null"); Assert.AreEqual(CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay(), "DisplayId"); }, "Throws"); }
protected override void SetupRenderLoop(bool oneShot) { // only start if we haven't already if (displayLink != null) { return; } // bail out if we are requesting something that the view doesn't want to if (!oneShot && !Element.HasRenderLoop) { return; } // if this is a one shot request, don't bother with the display link if (oneShot) { var nativeView = Control; nativeView?.BeginInvokeOnMainThread(() => { if (nativeView.Handle != IntPtr.Zero) { nativeView.NeedsDisplay = true; } }); return; } // create the loop displayLink = new CVDisplayLink(); displayLink.SetOutputCallback(delegate { var nativeView = Control; var formsView = Element; // stop the render loop if this was a one-shot, or the views are disposed if (nativeView == null || formsView == null || nativeView.Handle == IntPtr.Zero || !formsView.HasRenderLoop) { displayLink.Stop(); displayLink.Dispose(); displayLink = null; return(CVReturn.Success); } // redraw the view nativeView?.BeginInvokeOnMainThread(() => { if (nativeView != null) { nativeView.NeedsDisplay = true; } }); return(CVReturn.Success); }); displayLink.Start(); }
public void CreateFromOpenGLMaskTest() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); var openGLMask = CGDisplay.GetOpenGLDisplayMask(CGDisplay.MainDisplayID); Assert.DoesNotThrow(() => { using var displayLink = CVDisplayLink.CreateFromOpenGLMask((uint)openGLMask); Assert.NotNull(displayLink, "Not null"); }, "Throws"); }
public override void Stop() { if (link == null) { return; } link?.Stop(); link?.Dispose(); link = null; }
public override void Start() { if (link != null) { return; } link = new CVDisplayLink(); link.SetOutputCallback(DisplayLinkOutputCallback); link.Start(); }
public void CreateFromDisplayIdsTest() { TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); // we might not have more than one display, therefore we will use an array // with a single one, there is nothing in the docs that say that we cannot do that Assert.DoesNotThrow(() => { using var displayLink = CVDisplayLink.CreateFromDisplayIds(new [] { (uint)CGDisplay.MainDisplayID }); Assert.NotNull(displayLink, "Not null"); }, "Throws"); }
private CVReturn HandleDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { if (_newRenderSize != null) { Callback.OnResize(Widget, new ResizeEventArgs(_newRenderSize.Value)); _newRenderSize = null; } Callback.OnDraw(Widget, EventArgs.Empty); return(CVReturn.Success); }
protected override void DisableTimer() { if (this.link != null) { this.link.Stop(); // TODO: Does this work? //this.link.RemoveFromRunLoop (NSRunLoop.Current, NSRunLoop.NSRunLoopCommonModes); this.link.Dispose(); } this.link = null; }
void DeAllocate() { if (_displayLink == null) { return; } _displayLink.Stop(); _displayLink.Dispose(); _displayLink = null; }
public CVReturn DisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects // ReSharper disable once UnusedVariable using (var pool = new NSAutoreleasePool()) { Device.BeginInvokeOnMainThread(() => SendSignals()); } return(CVReturn.Success); }
protected override void Dispose(bool disposing) { // stop the render loop if (displayLink != null) { displayLink.Stop(); displayLink.Dispose(); displayLink = null; } base.Dispose(disposing); }
public void Startup() { DisplayTitle(); displayLink = new CVDisplayLink(); displayLink.SetOutputCallback(DisplayLinkOutputCallback); tickStopWatch = new Stopwatch(); tickStopWatch.Start(); displayLink.Start(); }
private void SetupDisplayLink() { // Create a display link capable of being used with all active displays displayLink = new CVDisplayLink(); // Set the renderer output callback function displayLink.SetOutputCallback(MyDisplayLinkOutputCallback); // Set the display link for the current renderer CGLContext cglContext = openGLContext.CGLContext; CGLPixelFormat cglPixelFormat = PixelFormat.CGLPixelFormat; displayLink.SetCurrentDisplay(cglContext, cglPixelFormat); }
private void Control_Draw(object sender, EventArgs e) { Callback.OnInitializeBackend(Widget, new InitializeEventArgs(RenderSize)); if (Widget.Backend == GraphicsBackend.Metal) { _displayLink = new CVDisplayLink(); _displayLink.SetOutputCallback(HandleDisplayLinkOutputCallback); _displayLink.Start(); } Control.Draw -= Control_Draw; Widget.SizeChanged += Widget_SizeChanged; }
void SetupDisplayLink() { _displayLink = new CVDisplayLink(); // Set the renderer output callback function SetOutputCallback(_displayLink, DisplayLinkOutputCallback); // Set the display link for the current renderer var cglContext = OpenGLContext.CGLContext; var cglPixelFormat = PixelFormat.CGLPixelFormat; _displayLink.SetCurrentDisplay(cglContext, cglPixelFormat); _displayLink.Start(); }
// Private Callback function for CVDisplayLink private CVReturn MyDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { //CVReturn result = GetFrameForTime (inOutputTime); CVReturn result = CVReturn.Error; // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool()) { // Update the animation RenderScene(); result = CVReturn.Success; } return(result); }
protected override void Dispose(bool disposing) { if (_displayLink != null) { _displayLink.Dispose(); _displayLink = null; if (Element != null) { ((IOpenGlViewController)Element).DisplayRequested -= Display; } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (_displayLink != null) { _displayLink.Dispose(); _displayLink = null; if (Element != null) { Element.DisplayRequested -= Display; } } base.Dispose(disposing); }
public void TryTranslateTimeValidTest() { TestRuntime.AssertNotVSTS(); TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); var outTime = new CVTimeStamp { Version = 0, Flags = (1L << 0) | (1L << 1), // kCVTimeStampVideoTimeValid | kCVTimeStampHostTimeValid }; using var displayLink = new CVDisplayLink(); // it has to be running else you will get a crash if (displayLink.Start() == 0) { displayLink.GetCurrentTime(out var timeStamp); Assert.True(displayLink.TryTranslateTime(timeStamp, ref outTime)); displayLink.Stop(); } }
partial void DoEnableRenderLoop(bool enable) { // stop the render loop if (!enable) { if (displayLink != null) { displayLink.Stop(); displayLink.Dispose(); displayLink = null; } return; } // only start if we haven't already if (displayLink != null) { return; } // create the loop displayLink = new CVDisplayLink(); displayLink.SetOutputCallback(delegate { // redraw the view glView?.BeginInvokeOnMainThread(() => { if (glView != null) { glView.NeedsDisplay = true; } }); // stop the render loop if it has been disabled or the views are disposed if (glView == null || !EnableRenderLoop) { DoEnableRenderLoop(false); } return(CVReturn.Success); }); displayLink.Start(); }
public static double GetRefreshRate(uint display) { var result = CVDisplayLinkCreateWithCGDisplay(display, out var handle); if (result != 0 || handle == IntPtr.Zero) { return(0.0); } using var dl = new CVDisplayLink(handle); var period = dl.NominalOutputVideoRefreshPeriod; if (((CVTimeFlags)period.Flags).HasFlag(CVTimeFlags.IsIndefinite) || period.TimeValue == 0) { return(0.0); } return(period.TimeScale / (double)period.TimeValue); }
public override void ViewDidMoveToWindow() { base.ViewDidMoveToWindow(); var swapchainSource = SwapchainSource.CreateNSView(Handle); var swapchainDescription = new SwapchainDescription(swapchainSource, (uint)Frame.Width, (uint)Frame.Height, null, true, true); if (_backend == GraphicsBackend.Metal) { GraphicsDevice = GraphicsDevice.CreateMetal(_deviceOptions); } MainSwapchain = GraphicsDevice.ResourceFactory.CreateSwapchain(swapchainDescription); DeviceReady?.Invoke(); _displayLink = new CVDisplayLink(); _displayLink.SetOutputCallback(HandleDisplayLinkOutputCallback); _displayLink.Start(); }
public CVReturn MyDisplayLinkOutputCallback (CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { CVReturn result = GetFrameForTime (inOutputTime); return result; }
private void SetupDisplayLink () { // Create a display link capable of being used with all active displays displayLink = new CVDisplayLink (); // Set the renderer output callback function displayLink.SetOutputCallback (MyDisplayLinkOutputCallback); // Set the display link for the current renderer CGLContext cglContext = openGLContext.CGLContext; CGLPixelFormat cglPixelFormat = PixelFormat.CGLPixelFormat; displayLink.SetCurrentDisplay (cglContext, cglPixelFormat); }