示例#1
0
        private (IRef <Scene> scene, bool updated) UpdateRenderLayersAndConsumeSceneIfNeeded(ref IDrawingContextImpl context,
                                                                                             bool recursiveCall = false)
        {
            IRef <Scene> sceneRef;

            lock (_sceneLock)
                sceneRef = _scene?.Clone();
            if (sceneRef == null)
            {
                return(null, false);
            }
            using (sceneRef)
            {
                var scene = sceneRef.Item;
                if (scene.Generation != _lastSceneId)
                {
                    EnsureDrawingContext(ref context);

                    Layers.Update(scene, context);

                    RenderToLayers(scene);

                    if (DebugFramesPath != null)
                    {
                        SaveDebugFrames(scene.Generation);
                    }

                    lock (_sceneLock)
                        _lastSceneId = scene.Generation;


                    var isUiThread = Dispatcher.UIThread.CheckAccess();
                    // We have consumed the previously available scene, but there might be some dirty
                    // rects since the last update. *If* we are on UI thread, we can force immediate scene
                    // rebuild before rendering anything on-screen
                    // We are calling the same method recursively here
                    if (!recursiveCall && isUiThread && NeedsUpdate)
                    {
                        UpdateScene();
                        var(rs, _) = UpdateRenderLayersAndConsumeSceneIfNeeded(ref context, true);
                        return(rs, true);
                    }

                    // We are rendering a new scene version, so it's highly likely
                    // that there is already a pending update for animations
                    // So we are scheduling an update call so UI thread could prepare a scene before
                    // the next render timer tick
                    if (!recursiveCall && !isUiThread)
                    {
                        Dispatcher.UIThread.Post(_updateSceneIfNeededDelegate, DispatcherPriority.Render);
                    }

                    // Indicate that we have updated the layers
                    return(sceneRef.Clone(), true);
                }

                // Just return scene, layers weren't updated
                return(sceneRef.Clone(), false);
            }
        }
示例#2
0
 void IRenderLoopTask.Render()
 {
     using (var scene = _scene?.Clone())
     {
         Render(scene?.Item);
     }
 }
示例#3
0
        /// <summary>
        /// Replaces an item in the <see cref="DrawOperations"/> collection.
        /// </summary>
        /// <param name="index">The operation to be replaced.</param>
        /// <param name="operation">The operation to add.</param>
        public void ReplaceDrawOperation(int index, IRef <IDrawOperation> operation)
        {
            EnsureDrawOperationsCreated();
            var old = _drawOperations[index];

            _drawOperations[index] = operation.Clone();
            old.Dispose();
        }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageNode"/> class.
 /// </summary>
 /// <param name="transform">The transform.</param>
 /// <param name="source">The image to draw.</param>
 /// <param name="opacity">The draw opacity.</param>
 /// <param name="sourceRect">The source rect.</param>
 /// <param name="destRect">The destination rect.</param>
 public ImageNode(Matrix transform, IRef <IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect)
     : base(destRect, transform, null)
 {
     Transform  = transform;
     Source     = source.Clone();
     Opacity    = opacity;
     SourceRect = sourceRect;
     DestRect   = destRect;
 }
示例#5
0
 public CompositionRenderTarget(EglPlatformOpenGlInterface egl,
                                IRef <WinUICompositedWindow> window,
                                IEglWindowGlPlatformSurfaceInfo info)
     : base(egl)
 {
     _egl    = egl;
     _window = window.Clone();
     _info   = info;
     _window.Item.ResizeIfNeeded(_info.Size);
 }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageNode"/> class.
 /// </summary>
 /// <param name="transform">The transform.</param>
 /// <param name="source">The image to draw.</param>
 /// <param name="opacity">The draw opacity.</param>
 /// <param name="sourceRect">The source rect.</param>
 /// <param name="destRect">The destination rect.</param>
 /// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
 public ImageNode(Matrix transform, IRef <IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
     : base(destRect, transform, null)
 {
     Transform  = transform;
     Source     = source.Clone();
     Opacity    = opacity;
     SourceRect = sourceRect;
     DestRect   = destRect;
     BitmapInterpolationMode = bitmapInterpolationMode;
     SourceVersion           = Source.Item.Version;
 }
示例#7
0
 private void Render(bool forceComposite)
 {
     using (var l = _lock.TryLock())
         if (l != null)
         {
             using (var scene = _scene?.Clone())
             {
                 Render(scene?.Item, forceComposite);
             }
         }
 }
示例#8
0
        private (IRef <Scene> scene, bool updated) UpdateRenderLayersAndConsumeSceneIfNeeded(ref IDrawingContextImpl context,
                                                                                             bool recursiveCall = false)
        {
            IRef <Scene> sceneRef;

            lock (_sceneLock)
                sceneRef = _scene?.Clone();
            if (sceneRef == null)
            {
                return(null, false);
            }
            using (sceneRef)
            {
                var scene = sceneRef.Item;
                if (scene.Generation != _lastSceneId)
                {
                    EnsureDrawingContext(ref context);

                    Layers.Update(scene, context);

                    RenderToLayers(scene);

                    if (DebugFramesPath != null)
                    {
                        SaveDebugFrames(scene.Generation);
                    }

                    lock (_sceneLock)
                        _lastSceneId = scene.Generation;


                    // We have consumed the previously available scene, but there might be some dirty
                    // rects since the last update. *If* we are on UI thread, we can force immediate scene
                    // rebuild before rendering anything on-screen
                    // We are calling the same method recursively here
                    if (!recursiveCall && Dispatcher.UIThread.CheckAccess() && NeedsUpdate)
                    {
                        UpdateScene();
                        var(rs, _) = UpdateRenderLayersAndConsumeSceneIfNeeded(ref context, true);
                        return(rs, true);
                    }

                    // Indicate that we have updated the layers
                    return(sceneRef.Clone(), true);
                }

                // Just return scene, layers weren't updated
                return(sceneRef.Clone(), false);
            }
        }
示例#9
0
 /// <summary>
 /// Makes a copy of the node
 /// </summary>
 /// <param name="parent">The new parent node.</param>
 /// <returns>A cloned node.</returns>
 public VisualNode Clone(IVisualNode parent)
 {
     return(new VisualNode(Visual, parent)
     {
         Transform = Transform,
         ClipBounds = ClipBounds,
         ClipToBounds = ClipToBounds,
         GeometryClip = GeometryClip,
         _opacity = Opacity,
         OpacityMask = OpacityMask,
         _drawOperations = _drawOperations,
         _drawOperationsRefCounter = _drawOperationsRefCounter?.Clone(),
         _drawOperationsCloned = true,
         LayerRoot = LayerRoot,
     });
 }
示例#10
0
        private void OnRenderLoopTick(object sender, EventArgs e)
        {
            if (Monitor.TryEnter(_rendering))
            {
                try
                {
                    if (!_updateQueued && (_dirty == null || _dirty.Count > 0))
                    {
                        _updateQueued = true;
                        _dispatcher.Post(UpdateScene, DispatcherPriority.Render);
                    }

                    using (var scene = _scene?.Clone())
                    {
                        Render(scene?.Item);
                    }
                }
                catch { }
                finally
                {
                    Monitor.Exit(_rendering);
                }
            }
        }
示例#11
0
 /// <summary>
 /// Adds an operation to the <see cref="DrawOperations"/> collection.
 /// </summary>
 /// <param name="operation">The operation to add.</param>
 public void AddDrawOperation(IRef <IDrawOperation> operation)
 {
     EnsureDrawOperationsCreated();
     _drawOperations.Add(operation.Clone());
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Bitmap"/> class.
 /// </summary>
 /// <param name="impl">A platform-specific bitmap implementation.</param>
 public Bitmap(IRef <IBitmapImpl> impl)
 {
     PlatformImpl = impl.Clone();
 }