{\r
class Method4 : IBench\r
{\r
- public int fillAreaSize { get { return bmpSize.Width * bmpSize.Height * this.loopCount; } }\r
+ public int fillAreaSize { get { return bmp.Width * bmp.Height * this.loopCount; } }\r
public string methodName { get { return "D2DBitBlt"; } }\r
public int loopCount { get; set; }\r
\r
- D2D1.Factory Factory2D;\r
- DW.Factory FactoryDWrite;\r
- WindowRenderTarget render;\r
Drawing.Size ClientSize;\r
Random rnd;\r
- const string showStr = "D2DBenchMark";\r
- Drawing.Size bmpSize;\r
- D2D1.Bitmap bmp;\r
+ IRender d2d;\r
+ IBitmap bmp;\r
\r
- public void Init(Control ctrl, bool antialias)\r
+ public void Init(Control ctrl, bool antialias, RenderMethod method)\r
{\r
ClientSize = ctrl.ClientSize;\r
- Factory2D = new SharpDX.Direct2D1.Factory();\r
- FactoryDWrite = new SharpDX.DirectWrite.Factory();\r
- HwndRenderTargetProperties hwndprops = new HwndRenderTargetProperties { Hwnd = ctrl.Handle, PixelSize = ClientSize, PresentOptions = PresentOptions.Immediately };\r
- render = new WindowRenderTarget(Factory2D, new RenderTargetProperties(), hwndprops);\r
- bmpSize = Resources.image.Size;\r
- bmp = Load(render, Resources.image);\r
+ if (method == RenderMethod.Direct2D)\r
+ this.d2d = new Direct2D(ctrl, ClientSize, antialias);\r
+ else\r
+ this.d2d = new GDI(ctrl);\r
+ this.bmp = this.d2d.Load(Resources.image);\r
rnd = new Random();\r
- render.AntialiasMode = antialias ? AntialiasMode.PerPrimitive : AntialiasMode.Aliased;\r
}\r
\r
public void Dispose()\r
{\r
- bmp.Dispose();\r
- render.Dispose();\r
- Factory2D.Dispose();\r
- FactoryDWrite.Dispose();\r
+ this.d2d.UnLoad(this.bmp);\r
+ this.d2d.Dispose();\r
}\r
\r
public void Exec()\r
{\r
- render.BeginDraw();\r
+ this.d2d.BeginDraw();\r
for (int i = 0; i < this.loopCount; i++)\r
{\r
- SharpDX.RectangleF rect = new SharpDX.RectangleF();\r
- rect.Left = rnd.Next(ClientSize.Width);\r
- rect.Top = rnd.Next(ClientSize.Height);\r
- rect.Right = rect.Left + bmpSize.Width;\r
- rect.Bottom = rect.Top + bmpSize.Height;\r
- render.DrawBitmap(bmp, rect, 1.0f, BitmapInterpolationMode.NearestNeighbor);\r
+ int left = rnd.Next(ClientSize.Width);\r
+ int top = rnd.Next(ClientSize.Height);\r
+ this.d2d.DrawBitmap(bmp,\r
+ left,\r
+ top,\r
+ left + bmp.Width,\r
+ top + bmp.Height);\r
}\r
- render.EndDraw();\r
- }\r
-\r
- D2D1.Bitmap Load(WindowRenderTarget render, Drawing.Bitmap srcBitmap)\r
- {\r
- var bitmapData = srcBitmap.LockBits(\r
- new Drawing.Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height),\r
- System.Drawing.Imaging.ImageLockMode.ReadOnly,\r
- System.Drawing.Imaging.PixelFormat.Format32bppPArgb);\r
-\r
- var stream = new DataStream(bitmapData.Scan0, bitmapData.Stride * bitmapData.Height, true, false);\r
-\r
- var properties = new BitmapProperties()\r
- {\r
- PixelFormat = new D2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)\r
- };\r
- var bitmap = new D2D1.Bitmap(render, srcBitmap.Size, stream, bitmapData.Stride, properties);\r
-\r
- srcBitmap.UnlockBits(bitmapData);\r
-\r
- return bitmap;\r
+ this.d2d.EndDraw();\r
}\r
}\r
}\r