Created
June 18, 2014 18:34
-
-
Save kekekeks/c6856162282227ed51ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Kebrum.Widgets | |
{ | |
public class CairoBridge:IDisposable | |
{ | |
private Cairo.ImageSurface m_Surface; | |
private System.Drawing.Graphics m_Graphics; | |
private System.Drawing.Bitmap m_Bitmap; | |
private IntPtr m_Data; | |
public Cairo.ImageSurface Surface | |
{ | |
get | |
{ | |
return m_Surface; | |
} | |
} | |
public System.Drawing.Graphics Graphics | |
{ | |
get | |
{ | |
return m_Graphics; | |
} | |
} | |
public System.Drawing.Bitmap Bitmap | |
{ | |
get | |
{ | |
return m_Bitmap; | |
} | |
} | |
public CairoBridge (int Width, int Height) | |
{ | |
int Stride = Width * 4; | |
m_Data = System.Runtime.InteropServices.Marshal.AllocHGlobal (Width * Height * 4); | |
m_Bitmap = new System.Drawing.Bitmap (Width, Height, Stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, m_Data); | |
m_Graphics = System.Drawing.Graphics.FromImage (m_Bitmap); | |
m_Surface = new Cairo.ImageSurface (m_Data, Cairo.Format.Argb32, Width, Height, Stride); | |
} | |
public void Dispose () | |
{ | |
if (m_Data == IntPtr.Zero) | |
return; | |
m_Graphics.Dispose (); | |
m_Graphics = null; | |
m_Bitmap.Dispose (); | |
m_Bitmap = null; | |
((IDisposable)m_Surface).Dispose (); | |
m_Surface = null; | |
System.Runtime.InteropServices.Marshal.FreeHGlobal (m_Data); | |
m_Data = IntPtr.Zero; | |
} | |
~CairoBridge () | |
{ | |
Dispose (); | |
} | |
private static CairoBridge m_Shared=null; | |
public void Clear (int Width, int Height) | |
{ | |
int Stride = m_Bitmap.Width; | |
unsafe | |
{ | |
uint* curscan = (uint*)m_Data.ToPointer (); | |
for (uint y = 0; y < Height; y++) | |
{ | |
uint* cur = curscan + Stride*y; | |
for (uint x = 0; x < Width; x++) | |
{ | |
*cur = 0; | |
cur++; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment