I don't want to lose anything, sorry if I broke you!

svn path=/branches/dmsnell/heap-buddy/; revision=63512
This commit is contained in:
dsnell 2006-08-09 00:35:46 +00:00
Родитель e11b614f38
Коммит ecaf6913fc
4 изменённых файлов: 113 добавлений и 3 удалений

70
analyzer/Graphics.cs Normal file
Просмотреть файл

@ -0,0 +1,70 @@
using System;
using System.Runtime.InteropServices;
using Cairo;
namespace Gdk
{
public class Context
{
private Context () {}
// Note: we don't need or want a .dll.config since we p/invoke
// the proper lib based on the os check below
// win32 only imports
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern IntPtr gdk_win32_hdc_get(IntPtr drawable, IntPtr gc, int usage);
[DllImport("libgdk-win32-2.0-0.dll")]
internal static extern void gdk_win32_hdc_release(IntPtr drawable,IntPtr gc,int usage);
// x11 only imports
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_drawable_get_xdisplay (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_drawable_get_visual (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_visual_get_xvisual (IntPtr handle);
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_x11_drawable_get_xid (IntPtr handle);
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable)
{
return CreateDrawable (drawable, true);
}
public static Cairo.Context CreateDrawable (Gdk.Drawable drawable, bool double_buffered)
{
int x = 0, y = 0;
Cairo.Surface surface;
PlatformID os = Environment.OSVersion.Platform;
if (drawable is Gdk.Window && double_buffered)
((Gdk.Window)drawable).GetInternalPaintInfo (out drawable, out x, out y);
if (os == PlatformID.Win32Windows || os == PlatformID.Win32NT ||
os == PlatformID.Win32S || os == PlatformID.WinCE) {
Gdk.GC gcc = new Gdk.GC (drawable);
IntPtr windc = gdk_win32_hdc_get (drawable.Handle, gcc.Handle, 0);
surface = new Win32Surface (windc);
if (double_buffered)
gdk_win32_hdc_release (drawable.Handle, gcc.Handle, 0);
} else {
IntPtr display = gdk_x11_drawable_get_xdisplay (drawable.Handle);
IntPtr visual = gdk_drawable_get_visual (drawable.Handle);
IntPtr xvisual = gdk_x11_visual_get_xvisual (visual);
IntPtr xdrawable = gdk_x11_drawable_get_xid (drawable.Handle);
surface = new XlibSurface (display, xdrawable, xvisual, x, y);
}
return new Cairo.Context (surface);
}
}
}

Просмотреть файл

@ -1,6 +1,6 @@
CSC = mcs -debug
CSFLAGS = -target:exe -r:Mono.Cairo
CSFLAGS = -target:exe -r:Mono.Cairo -pkg:gtk-sharp -r:System.Drawing.dll
TARGET = HeapBuddy.exe
WRAPPER = heap-buddy
@ -28,6 +28,7 @@ CSFILES = \
TypeLog.cs \
MethodLog.cs \
MemGraph.cs \
Graphics.cs \
$(REPORT_CSFILES)
bin_SCRIPTS = \

Просмотреть файл

@ -153,7 +153,7 @@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
CSC = mcs -debug
CSFLAGS = -target:exe -r:Mono.Cairo
CSFLAGS = -target:exe -r:Mono.Cairo -pkg:gtk-sharp -r:System.Drawing.dll
TARGET = HeapBuddy.exe
WRAPPER = heap-buddy
REPORT_CSFILES = \
@ -179,6 +179,7 @@ CSFILES = \
TypeLog.cs \
MethodLog.cs \
MemGraph.cs \
Graphics.cs \
$(REPORT_CSFILES)
bin_SCRIPTS = \

Просмотреть файл

@ -1,6 +1,7 @@
using System;
using System.Collections;
using Cairo;
using Gtk;
namespace HeapBuddy {
@ -17,7 +18,7 @@ namespace HeapBuddy {
}
private class MemStampComparer : IComparer {
int IComparer.Compare (Object x, Object y) {
int IComparer.Compare (System.Object x, System.Object y) {
MemStamp a = (MemStamp)x;
MemStamp b = (MemStamp)y;
@ -28,6 +29,7 @@ namespace HeapBuddy {
}
private ArrayList Stamps;
static DrawingArea da;
public MemGraph (OutfileReader reader, string filename)
{
@ -118,6 +120,18 @@ namespace HeapBuddy {
c.MoveTo (GraphOriginX + i * GraphWidth / 10 - 0.5 * e.Width, GraphOriginY + GraphHeight + 10 + e.Height);
c.ShowText (s);
}
Application.Init ();
Window win = new Window ("Heap-Buddy");
win.SetDefaultSize (640, 480);
da = new CairoGraph ();
win.Add (da);
win.ShowAll ();
Application.Run ();
if (filename == null)
filename = "memlog.png";
@ -126,6 +140,8 @@ namespace HeapBuddy {
surface.Finish ();
}
private void CollectStamps (OutfileReader reader)
{
foreach (Gc gc in reader.Gcs) {
@ -146,3 +162,25 @@ namespace HeapBuddy {
}
}
public class CairoGraph : DrawingArea
{
protected override bool OnExposeEvent (Gdk.EventExpose args)
{
Gdk.Window win = args.Window;
Cairo.Context g = Gdk.Context.CreateDrawable (win);
g.ResetClip ();
g.Color = new Color (0, .6, .6, 1);
g.Paint ();
g.Color = new Color (1, 1, 1, 1);
g.MoveTo (0, 0);
g.LineTo (500, 500);
g.LineWidth = 4;
g.Stroke ();
return true;
}
}