Here is the code that I am using. A lot of the code has been removed but I think that I have kept all of the relevant parts. Almost all of the CPU time is spent doing the DrawLines at the end of the code.
public class DXTest
{
int[,] ValuesToDraw;
private Device device;
private Surface primary;
private Surface offscreen;
public void Setup()
{
device = new Microsoft.DirectX.DirectDraw.Device();
device.SetCooperativeLevel(this, CooperativeLevelFlags.Normal);
CreatePrimarySurface();
CreateOffscreenSurface();
}
private void CreatePrimarySurface()
{
SurfaceDescription desc = new SurfaceDescription();
desc.SurfaceCaps.PrimarySurface = true;
primary = new Surface(desc, device);
Clipper pClipper = new Clipper(device);
pClipper.Window = OIApp.OIGUI.GetSelectedTabPage();
primary.Clipper = pClipper;
}
private void CreateOffscreenSurface()
{
SurfaceDescription desc = new SurfaceDescription();
desc.SurfaceCaps.OffScreenPlain = true;
desc.Width = this.ClientRectangle.Width;
desc.Height = this.ClientRectangle.Height;
offscreen = new Surface(desc, device);
Clipper oClipper = new Clipper(device);
Rectangle oClipRect = new Rectangle(0,
0,
this.ClientRectangle.Width,
this.ClientRectangle.Height);
oClipper.ClipList = new Rectangle[] { oClipRect };
offscreen.Clipper = oClipper;
}
public void Run(Object state)
{
for(int i=0; i<360; i++)
{
for(int j=0; j<10; j++)
{
offscreen.ForeColor = Color.FromArgb(0,250,0);
offscreen.DrawLine(xs+xt, -ys+yt, xe+xt, -ye+yt);
}
}
primary.Draw(this.ClientRectangle, offscreen, DrawFlags.Wait);
}
}