<commit_before>using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.RenderHelpers;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Platform;

namespace Avalonia.Skia
{
    internal class DrawingContextImpl : IDrawingContextImpl
    {
        private readonly Matrix? _postTransform;
        private readonly IDisposable[] _disposables;
        private Stack<PaintWrapper> maskStack = new Stack<PaintWrapper>();
        
        public SKCanvas Canvas { get; private set; }

        public DrawingContextImpl(SKCanvas canvas, Matrix? postTransform = null, params IDisposable[] disposables)
        {
            if (postTransform.HasValue && !postTransform.Value.IsIdentity)
                _postTransform = postTransform;
            _disposables = disposables;
            Canvas = canvas;
            Canvas.Clear();
            Transform = Matrix.Identity;
        }

        public void Clear(Color color)
        {
            Canvas.Clear(color.ToSKColor());
        }

        public void DrawImage(IBitmapImpl source, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl = (BitmapImpl)source;
            var s = sourceRect.ToSKRect();
            var d = destRect.ToSKRect();
            using (var paint = new SKPaint()
                    { Color = new SKColor(255, 255, 255, (byte)(255 * opacity)) })
            {
                Canvas.DrawBitmap(impl.Bitmap, s, d, paint);
            }
        }

        public void DrawImage(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
        {
            PushOpacityMask(opacityMask, opacityMaskRect);
            DrawImage(source, 1, new Rect(0, 0, source.PixelWidth, source.PixelHeight), destRect);
            PopOpacityMask();
        }

        public void DrawLine(Pen pen, Point p1, Point p2)
        {
            using (var paint = CreatePaint(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))))<commit_msg>Don't clear skia canvas when creating drawing ctx.<commit_after>using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.RenderHelpers;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Platform;

namespace Avalonia.Skia
{
    internal class DrawingContextImpl : IDrawingContextImpl
    {
        private readonly Matrix? _postTransform;
        private readonly IDisposable[] _disposables;
        private Stack<PaintWrapper> maskStack = new Stack<PaintWrapper>();
        
        public SKCanvas Canvas { get; private set; }

        public DrawingContextImpl(SKCanvas canvas, Matrix? postTransform = null, params IDisposable[] disposables)
        {
            if (postTransform.HasValue && !postTransform.Value.IsIdentity)
                _postTransform = postTransform;
            _disposables = disposables;
            Canvas = canvas;
            Transform = Matrix.Identity;
        }

        public void Clear(Color color)
        {
            Canvas.Clear(color.ToSKColor());
        }

        public void DrawImage(IBitmapImpl source, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl = (BitmapImpl)source;
            var s = sourceRect.ToSKRect();
            var d = destRect.ToSKRect();
            using (var paint = new SKPaint()
                    { Color = new SKColor(255, 255, 255, (byte)(255 * opacity)) })
            {
                Canvas.DrawBitmap(impl.Bitmap, s, d, paint);
            }
        }

        public void DrawImage(IBitmapImpl source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
        {
            PushOpacityMask(opacityMask, opacityMaskRect);
            DrawImage(source, 1, new Rect(0, 0, source.PixelWidth, source.PixelHeight), destRect);
            PopOpacityMask();
        }

        public void DrawLine(Pen pen, Point p1, Point p2)
        {
            using (var paint = CreatePaint(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y))))
{'fraction_non_alphanumeric': 0.09111277072442121, 'fraction_numerical': 0.010455563853622106, 'mean_word_length': 2.285363859362224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5207288', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1083, 'n_words': 285}