Example #1
0
 public virtual void OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
 {
     if (type == PaintElementType.View)
     {
         m_Lock.EnterUpgradeableReadLock();
         try
         {
             if (!Buffer.IsAllocated ||
                 width != Width ||
                 height != Height)
             {
                 m_Lock.EnterWriteLock();
                 try
                 {
                     Width      = width;
                     Height     = height;
                     BufferSize = width * height * 4;
                     if (Buffer.IsAllocated)
                     {
                         Buffer.Free();
                     }
                     Buffer = GCHandle.Alloc(new byte[BufferSize], GCHandleType.Pinned);
                 }
                 finally
                 {
                     m_Lock.ExitWriteLock();
                 }
             }
             WinApi.CopyMemory(Buffer.AddrOfPinnedObject(), buffer, (uint)BufferSize);
         }
         finally
         {
             m_Lock.ExitUpgradeableReadLock();
         }
     }
 }