public void StartAnimation() { if (displayLink != null && !displayLink.IsRunning) { displayLink.Start(); } }
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 override void Start() { if (link != null) { return; } link = new CVDisplayLink(); link.SetOutputCallback(DisplayLinkOutputCallback); link.Start(); }
public void Startup() { DisplayTitle(); displayLink = new CVDisplayLink(); displayLink.SetOutputCallback(DisplayLinkOutputCallback); tickStopWatch = new Stopwatch(); tickStopWatch.Start(); displayLink.Start(); }
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(); }
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(); }
private void StartAnimation(double updatesPerSecond) { if (!animating) { if (displayLinkSupported) { if (displayLink != null && !displayLink.IsRunning) { displayLink.Start(); } } else { // Can't use TimeSpan.FromSeconds() as that only has 1ms // resolution, and we need better (e.g. 60fps doesn't fit nicely // in 1ms resolution, but does in ticks). var timeout = new TimeSpan((long)(((1.0 * TimeSpan.TicksPerSecond) / updatesPerSecond) + 0.5)); if (SwapInterval) { animationTimer = NSTimer.CreateRepeatingScheduledTimer(timeout, delegate { NeedsDisplay = true; }); } else { animationTimer = NSTimer.CreateRepeatingScheduledTimer(timeout, delegate { RenderScene(); }); } NSRunLoop.Current.AddTimer(animationTimer, NSRunLoopMode.Default); NSRunLoop.Current.AddTimer(animationTimer, NSRunLoopMode.EventTracking); } } animating = true; }
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(); }
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; } // create the loop displayLink = new CVDisplayLink(); displayLink.SetOutputCallback(delegate { var formsView = Control; var nativeView = Element; // redraw the view formsView?.Display(); // stop the render loop if this was a one-shot, or the views are disposed if (formsView == null || nativeView == null || !nativeView.HasRenderLoop) { displayLink.Stop(); displayLink.Dispose(); displayLink = null; } return(CVReturn.Success); }); displayLink.Start(); }
protected override void EnableTimer() { _link = new CVDisplayLink(); _link.SetOutputCallback(DisplayLinkOutputCallback); _link.Start(); }