Пример #1
0
        void StartRenderLoop()
        {
            // If the render loop is already running then do not start another thread.
            if (mRenderLoopWorker != null && mRenderLoopWorker.Status == AsyncStatus.Started)
            {
                return;
            }

            //var throttler = new Helpers.EventThrottler<TextChangedEventArgs>(Constants.TypingTimeout, handler => SearchField.TextChanged += new TextChangedEventHandler(handler));
            //throttler.Invoked += (s, args) =>
            //{
            //    // s is SearchField
            //    // args is TextChangedEventArgs
            //};

            // Create a task for rendering that will be run on a background thread.
            var workItemHandler =
                new Windows.System.Threading.WorkItemHandler(action =>
            {
                lock (mRenderSurfaceCriticalSection)
                {
                    mOpenGLES.MakeCurrent(mRenderSurface);

                    //var renderer = new RendererBase();
                    var renderer = RendererInit();

                    while (action.Status == AsyncStatus.Started)
                    {
                        int panelWidth  = 0;
                        int panelHeight = 0;
                        mOpenGLES.GetSurfaceDimensions(mRenderSurface, ref panelWidth, ref panelHeight);

                        // Logic to update the scene could go here
                        renderer.UpdateWindowSize(panelWidth, panelHeight);
                        renderer.Draw();

                        // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost)
                        // If the call fails, then we must reinitialize EGL and the GL resources.
                        if (mOpenGLES.SwapBuffers(mRenderSurface) != EGL.TRUE)
                        {
                            // XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                            swapChainPanel.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                               new DispatchedHandler(() =>
                            {
                                RecoverFromLostDevice();
                            }));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

                            return;
                        }
                    }
                }
            });

            // Run task on a dedicated high priority background thread.
            mRenderLoopWorker = Windows.System.Threading.ThreadPool.RunAsync(workItemHandler,
                                                                             Windows.System.Threading.WorkItemPriority.High,
                                                                             Windows.System.Threading.WorkItemOptions.TimeSliced);
        }
Пример #2
0
        void StartRenderLoop()
        {
            // If the render loop is already running then do not start another thread.
            if (mRenderLoopWorker != null && mRenderLoopWorker.Status == Windows.Foundation.AsyncStatus.Started)
            {
                return;
            }

            // Create a task for rendering that will be run on a background thread.
            var workItemHandler =
                new Windows.System.Threading.WorkItemHandler(action =>
            {
                lock (mRenderSurfaceCriticalSection)
                {
                    mOpenGLES.MakeCurrent(mRenderSurface);
                    SimpleRenderer renderer = new SimpleRenderer();

                    while (action.Status == Windows.Foundation.AsyncStatus.Started)
                    {
                        int panelWidth  = 0;
                        int panelHeight = 0;
                        mOpenGLES.GetSurfaceDimensions(mRenderSurface, ref panelWidth, ref panelHeight);

                        // Logic to update the scene could go here
                        renderer.UpdateWindowSize(panelWidth, panelHeight);
                        renderer.Draw();

                        // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost)
                        // If the call fails, then we must reinitialize EGL and the GL resources.
                        if (mOpenGLES.SwapBuffers(mRenderSurface) != EGL.TRUE)
                        {
                            // XAML objects like the SwapChainPanel must only be manipulated on the UI thread.
                            swapChainPanel.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High,
                                                               new Windows.UI.Core.DispatchedHandler(() =>
                            {
                                RecoverFromLostDevice();
                            }));

                            return;
                        }
                    }
                }
            });

            // Run task on a dedicated high priority background thread.
            mRenderLoopWorker = Windows.System.Threading.ThreadPool.RunAsync(workItemHandler,
                                                                             Windows.System.Threading.WorkItemPriority.High,
                                                                             Windows.System.Threading.WorkItemOptions.TimeSliced);
        }
Пример #3
0
        private async void DrawNextFrame(IntPtr context)
        {
            // Wait for the UI Thread to run to render the next frame.
            await videoBox.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, new DispatchedHandler(() =>
            {
                // Get the Width and Height of the Window (it can change at anytime)
                int w = (int)((Frame)Window.Current.Content).ActualWidth;
                int h = (int)((Frame)Window.Current.Content).ActualHeight;

                // Draw the next frame, swap buffers, and report the frame has been flipped
                mpv.OpenGLCallbackDraw(0, w, -h);
                mOpenGLES.SwapBuffers(mRenderSurface);
                mpv.OpenGLCallbackReportFlip();
            }));
        }