Beispiel #1
0
        /// <summary>
        /// Освободить все используемые ресурсы.
        /// </summary>
        /// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }

            lock (this)
            {
                if (RazorGFX != null)
                {
                    RazorGFX.Dispose();
                }
                if (RazorBMP != null)
                {
                    RazorBMP.Dispose();
                }
                if (hDCGraphics != null)
                {
                    hDCGraphics.Dispose();
                }
                RP.Dispose();
            }

            base.Dispose(disposing);
        }
Beispiel #2
0
        public RazorPainterWPFCtl()
        {
            InitializeComponent();

            hDCGraphics = RazorBackend1.CreateGraphics();
            hDCRef      = new HandleRef(hDCGraphics, hDCGraphics.GetHdc());
            RP          = new RazorPainter();

            RazorBMP = new System.Drawing.Bitmap(RazorWidth, RazorHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            RazorGFX = System.Drawing.Graphics.FromImage(RazorBMP);

            RazorBackend1.Resize += (sender, args) =>
            {
                lock (RazorLock)
                {
                    if (RazorGFX != null)
                    {
                        RazorGFX.Dispose();
                    }
                    if (RazorBMP != null)
                    {
                        RazorBMP.Dispose();
                    }
                    RazorBMP = new System.Drawing.Bitmap(RazorWidth, RazorWidth, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    RazorGFX = System.Drawing.Graphics.FromImage(RazorBMP);
                }
            };
        }
 protected override void Dispose(bool disposing)
 {
     lock (RazorLock)
     {
         if (RazorGFX != null)
         {
             RazorGFX.Dispose();
         }
         if (RazorBMP != null)
         {
             RazorBMP.Dispose();
         }
         //hDCGraphics.ReleaseHdc();
         if (hDCGraphics != null)
         {
             hDCGraphics.Dispose();
         }
         //RP.Dispose();
     }
     base.Dispose(disposing);
 }
Beispiel #4
0
        void Render()
        {
            long realTicks = sw.ElapsedTicks, dt = realTicks - curTicks;

            //Console.Write(" " + dt/10);
            if (curTicks != long.MinValue)
            {
                double ms     = realTicks * 1e3 / Stopwatch.Frequency;
                double pixels = (ms / ms2pixel) % this.ClientSize.Width;
                //Stats.Add(dt * 1e3 / Stopwatch.Frequency);
                //BiStats.Add(n, ms);
                //curTicks = realTicks;

                // Tested on:
                // YODA. 1920x1018 AMD HD 6570, W7x64 i5-3470 [email protected], Mem speed is ~20GB/s, so
                // 8MB*65 times ~ 0.5GB => / 20 = 2,5% read and 5% copy, should be.
                // SEASHELL. 1366x705, W10x64 i5-3317U [email protected], Mem speed ~15GB/s, so
                // 4MB*65 ~ 0.25GB => /15 = 1.7% read and 3.3% copy.

                // 0. Nop.
                // YODA: 3.3% out of 25%, 65 FPS (max)
                // SEASHELL: 4.3% out of 25%, 64 FPS (max)
                //PlaceBitmapDummy(RazorGFX, tbmp.Bitmap, 0);

                // 1. float DrawImage
                // YODA: 12 FPS, 25%
                // SEASHELL: 64 FPS, 18%
                //float fx = (float)pixels;
                //PlaceBitmapFloat(RazorGFX, tbmp.Bitmap, fx);

                // 2. int DrawImage
                // YODA: 24%, 65 FPS.
                // SEASHELL: 18%, 64 FPS
                int x = (int)pixels;
                //PlaceBitmapInt(RazorGFX, tbmp.Bitmap, x);

                // 3. DrawImageUnscaled
                // YODA: 24%, 65 FPS, no shift, just to try.
                //PlaceBitmapUnscaled(RazorGFX, tbmp.Bitmap, 0);

                // 4. unsafe copy int*w*h + 2*(Lock+Unlock)Bits
                // YODA: 11.6%
                // SEASHELL: 13-14%
                //PlaceBitmapUnsafe(RazorBMP, tbmp.Bitmap, x);

                // 4'. unsafe memcpy (int*w)*h + 2*(Lock+Unlock)Bits
                // YODA: 6.2%
                // SEASHELL: 6.8%
                PlaceBitmapUnsafe2(RazorBMP, tbmp.Bitmap, x);

                // 5. SetDIBitsToDevice + (Lock/Unlock)Bits + (Get/Release)Hdc
                // YODA: 10.0%
                // SeaShell: 11%
                //PlaceBitmapSetDIBitsToDevice(RazorGFX, tbmp.Bitmap, x);

                // 6. BitBlt + 2*(Get/Release)Hdc + GetHBitmap/DeleteObject + 2*SelectObject
                // YODA: 38 FPS, but can be cached (Bitmap.GetHBitmap and hDCs)
                // SeaShell: 50 FPS, 25%
                //PlaceBitmapBitBlt(RazorGFX, tbmp.Bitmap, x);

                // DIBPainter:  YODA 8.9%, SEASHELL 11.0%, mustn't cache destination Graphics!
                // BlitPainter: YODA 9.6%, SEASHELL 12.3%, mustn't cache destination Graphics!
                //painter.PlaceBitmap(x);
                int    scanline = viewport.GetScanline();
                string s        = String.Format(" {0}", scanline < 0 ? "VBLANK" : scanline.ToString());
                RazorGFX.DrawString(s, SystemFonts.CaptionFont, SystemBrushes.Window, 0, 0);
            }

            this.RazorPaint();
            FramesCounter++;
            //Console.Write(" {0,-4:G3}", (sw.ElapsedTicks - realTicks) * 1000d / Stopwatch.Frequency);
        }