<commit_before>﻿//BSD, 2014-present, WinterDev
//ArthurHub, <NAME>

// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
// 
// - <NAME>,
// "The Art of War"

using System;


namespace PixelFarm.Drawing.WinGdi
{

    public partial class GdiPlusDrawBoard : DrawBoard, IDisposable
    {
        bool isDisposed;
        GdiPlusRenderSurface _gdigsx;
        static GdiPlusDrawBoard()
        {
            DrawBoardCreator.RegisterCreator(1, (w, h) => new GdiPlusDrawBoard(0, 0, w, h));
        }
        public GdiPlusDrawBoard(int left, int top, int width, int height)
        {
            this.left = left;
            this.top = top;
            this.right = left + width;
            this.bottom = top + height;

            _gdigsx = new GdiPlusRenderSurface(left, top, width, height);
        }

#if DEBUG
        public override string ToString()
        {
            return _gdigsx.ToString();
        }
#endif

        public override Painter GetPainter()
        {
            //create agg painter
            return _gdigsx.GetAggPainter();

        }
        public override void RenderTo(Image destImg, int srcX, int srcYy, int srcW, int srcH)
        {

            //render back buffer to target image

            unsafe
            {
                CpuBlit.ActualBitmap img = destImg as CpuBlit.ActualBitmap;
                if (img != null)
                {
                    CpuBlit.Imaging.TempMemPtr tmpPtr = CpuBlit.ActualBitmap.GetBufferPtr(img);
                    byte* head = (byte*)tmpPtr.Ptr;
                    _gdigsx.RenderTo(head);
                    tmpPtr.Dispose();
                }
            }
        }
        public override void Dispose()
        {
            if (_gdigsx != null)
            {
                _gdigsx.CloseCanvas();
                _gdigsx = null;
            }
        }
        public override void CloseCanvas()
        {
            if (isDisposed)
            {
                return;
            }

            _gdigsx.CloseCanvas();

            isDisposed = true;
            ReleaseUnManagedResource();
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            if (isDisposed)
            {
                return;
            }
            this.CloseCanvas();
        }
        void ClearPreviousStoredValues()
        {
            _gdigsx.ClearPreviousStoredValues();
        }

        void ReleaseUnManagedResource()
        {
            _gdigsx.ReleaseUnManagedResource();
#if DEBUG

            debug_releaseCount++;
#endif
        }

#if DEBUG
        public override void dbug_DrawRuler(int x)
        {
            _gdigsx.dbug_DrawRuler(x);
        }
        public override void dbug_DrawCrossRect(Color color, Rectangle rect)
        {
            _gdigsx.dbug_DrawCrossRect(color, rect);
        }
#endif
    }
}<commit_msg>202: expose GdiPlusRenderSurface<commit_after>﻿//BSD, 2014-present, WinterDev
//ArthurHub, <NAME>

// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
// 
// - <NAME>,
// "The Art of War"

using System;


namespace PixelFarm.Drawing.WinGdi
{

    public partial class GdiPlusDrawBoard : DrawBoard, IDisposable
    {
        bool isDisposed;
        GdiPlusRenderSurface _gdigsx;
        static GdiPlusDrawBoard()
        {
            DrawBoardCreator.RegisterCreator(1, (w, h) => new GdiPlusDrawBoard(0, 0, w, h));
        }
        public GdiPlusDrawBoard(int left, int top, int width, int height)
        {
            this.left = left;
            this.top = top;
            this.right = left + width;
            this.bottom = top + height;

            _gdigsx = new GdiPlusRenderSurface(left, top, width, height);
        }
        public GdiPlusRenderSurface RenderSurface => _gdigsx;
#if DEBUG
        public override string ToString()
        {
            return _gdigsx.ToString();
        }
#endif

        public override Painter GetPainter()
        {
            //create agg painter
            return _gdigsx.GetAggPainter();

        }
        public override void RenderTo(Image destImg, int srcX, int srcYy, int srcW, int srcH)
        {

            //render back buffer to target image

            unsafe
            {
                CpuBlit.ActualBitmap img = destImg as CpuBlit.ActualBitmap;
                if (img != null)
                {
                    CpuBlit.Imaging.TempMemPtr tmpPtr = CpuBlit.ActualBitmap.GetBufferPtr(img);
                    byte* head = (byte*)tmpPtr.Ptr;
                    _gdigsx.RenderTo(head);
                    tmpPtr.Dispose();
                }
            }
        }
        public override void Dispose()
        {
            if (_gdigsx != null)
            {
                _gdigsx.CloseCanvas();
                _gdigsx = null;
            }
        }
        public override void CloseCanvas()
        {
            if (isDisposed)
            {
                return;
            }

            _gdigsx.CloseCanvas();

            isDisposed = true;
            ReleaseUnManagedResource();
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            if (isDisposed)
            {
                return;
            }
            this.CloseCanvas();
        }
        void ClearPreviousStoredValues()
        {
            _gdigsx.ClearPreviousStoredValues();
        }

        void ReleaseUnManagedResource()
        {
            _gdigsx.ReleaseUnManagedResource();
#if DEBUG

            debug_releaseCount++;
#endif
        }

#if DEBUG
        public override void dbug_DrawRuler(int x)
        {
            _gdigsx.dbug_DrawRuler(x);
        }
        public override void dbug_DrawCrossRect(Color color, Rectangle rect)
        {
            _gdigsx.dbug_DrawCrossRect(color, rect);
        }
#endif
    }
}
{'fraction_non_alphanumeric': 0.087534797401794, 'fraction_numerical': 0.002629137024435509, 'mean_word_length': 1.4768288012255841, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, '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': '6892601', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1766, 'n_words': 448}