<commit_before>﻿// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using Avalonia.Platform;
using Avalonia.VisualTree;

namespace Avalonia.Rendering
{
    public class Renderer : IDisposable, IRenderer
    {
        private IRenderLoop _renderLoop;
        private IRenderRoot _root;
        private IRenderTarget _renderTarget;
        private bool _dirty;
        private bool _rendering;

        public void Attach(IRenderRoot root, IRenderLoop renderLoop)
        {
            Contract.Requires<ArgumentNullException>(root != null);

            _root = root;
            _renderLoop = renderLoop;
            _renderLoop.Tick += OnRenderLoopTick;
        }

        public void AddDirty(IVisual visual)
        {
            _dirty = true;
        }

        public void Dispose()
        {
            _renderLoop.Tick -= OnRenderLoopTick;
        }

        public void Render(Rect rect)
        {
            if (_rendering)
            {
                return;
            }

            if (_renderTarget == null)
            {
                _renderTarget = _root.CreateRenderTarget();
            }

            try
            {
                _rendering = true;
                _renderTarget.Render(_root);
            }
            catch (RenderTargetCorruptedException ex)
            {
                Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex);
                _renderTarget.Dispose();
                _renderTarget = null;
            }
            finally
            {
                _rendering = false;
                _dirty = false;
            }
        }

        private void OnRenderLoopTick(object sender, EventArgs e)
        {
            if (_dirty)
            {
                _root.Invalidate(new Rect(_root.ClientSize));
            }
        }
    }
}
<commit_msg>Don't need reentry guard here.<commit_after>﻿// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.

using System;
using Avalonia.Platform;
using Avalonia.VisualTree;

namespace Avalonia.Rendering
{
    public class Renderer : IDisposable, IRenderer
    {
        private IRenderLoop _renderLoop;
        private IRenderRoot _root;
        private IRenderTarget _renderTarget;
        private bool _dirty;

        public void Attach(IRenderRoot root, IRenderLoop renderLoop)
        {
            Contract.Requires<ArgumentNullException>(root != null);

            _root = root;
            _renderLoop = renderLoop;
            _renderLoop.Tick += OnRenderLoopTick;
        }

        public void AddDirty(IVisual visual)
        {
            _dirty = true;
        }

        public void Dispose()
        {
            _renderLoop.Tick -= OnRenderLoopTick;
        }

        public void Render(Rect rect)
        {
            if (_renderTarget == null)
            {
                _renderTarget = _root.CreateRenderTarget();
            }

            try
            {
                _renderTarget.Render(_root);
            }
            catch (RenderTargetCorruptedException ex)
            {
                Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex);
                _renderTarget.Dispose();
                _renderTarget = null;
            }
            finally
            {
                _dirty = false;
            }
        }

        private void OnRenderLoopTick(object sender, EventArgs e)
        {
            if (_dirty)
            {
                _root.Invalidate(new Rect(_root.ClientSize));
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.07292759706190975, 'fraction_numerical': 0.0005246589716684155, 'mean_word_length': 1.4840390879478826, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1878589', 'n_tokens_mistral': 973, 'n_tokens_neox': 943, 'n_words': 242}