CopyMemory() private method

private CopyMemory ( IntPtr destination, IntPtr source, uint length ) : void
destination IntPtr
source IntPtr
length uint
return void
Exemplo n.º 1
0
        void IRenderHandler.OnPaint(PaintElementType type, Rect dirtyRect, IntPtr buffer, int width, int height)
        {
            if (type == PaintElementType.View)
            {
                _paintBufferLock.EnterWriteLock();
                try
                {
                    if (_width != width ||
                        _height != height)
                    {
                        _width  = width;
                        _height = height;
                        if (_paintBuffer.IsAllocated == true)
                        {
                            _paintBuffer.Free();
                        }
                        _paintBuffer = GCHandle.Alloc(
                            new byte[_width * _height * 4],
                            GCHandleType.Pinned
                            );
                    }

                    WinApi.CopyMemory(
                        _paintBuffer.AddrOfPinnedObject(),
                        buffer,
                        (uint)(width * height * 4)
                        );
                }
                finally
                {
                    _paintBufferLock.ExitWriteLock();
                }
            }
        }
Exemplo n.º 2
0
 public void RenderToTexture(Texture2D texture)
 {
     if (_dirty == true)
     {
         _dirty = false;
         _paintBufferLock.EnterReadLock();
         try
         {
             if (_width > 0 &&
                 _height > 0)
             {
                 var context = texture.Device.ImmediateContext;
                 var dataBox = context.MapSubresource(
                     texture,
                     0,
                     MapMode.WriteDiscard,
                     MapFlags.None
                     );
                 if (dataBox.IsEmpty == false)
                 {
                     var sourcePtr      = _paintBuffer.AddrOfPinnedObject();
                     var destinationPtr = dataBox.DataPointer;
                     var pitch          = _width * 4;
                     var rowPitch       = dataBox.RowPitch;
                     if (pitch == rowPitch)
                     {
                         WinApi.CopyMemory(
                             destinationPtr,
                             sourcePtr,
                             (uint)(_width * _height * 4)
                             );
                     }
                     else
                     {
                         for (var y = _height; y > 0; --y)
                         {
                             WinApi.CopyMemory(
                                 destinationPtr,
                                 sourcePtr,
                                 (uint)pitch
                                 );
                             sourcePtr      += pitch;
                             destinationPtr += rowPitch;
                         }
                     }
                 }
                 context.UnmapSubresource(texture, 0);
             }
         }
         finally
         {
             _paintBufferLock.ExitReadLock();
         }
     }
 }
Exemplo n.º 3
0
 public void Render()
 {
     m_Lock.EnterReadLock();
     try
     {
         var H = (RenderHandler)RenderHandler;
         if (H.Buffer.IsAllocated)
         {
             var context = m_Texture.Device.ImmediateContext;
             var box     = context.MapSubresource(m_Texture, 0, MapMode.WriteDiscard, MapFlags.None);
             if (box.DataPointer != IntPtr.Zero)
             {
                 if (box.RowPitch == H.Width * 4)
                 {
                     WinApi.CopyMemory(box.DataPointer, H.Buffer.AddrOfPinnedObject(), (uint)H.BufferSize);
                 }
                 else
                 {
                     var dest   = box.DataPointer;
                     var src    = H.Buffer.AddrOfPinnedObject();
                     var pitch  = box.RowPitch;
                     var length = H.Width * 4;
                     var height = H.Height;
                     for (var i = 0; i < height; ++i)
                     {
                         WinApi.CopyMemory(dest, src, (uint)length);
                         dest += pitch;
                         src  += length;
                     }
                 }
             }
             context.UnmapSubresource(m_Texture, 0);
         }
     }
     finally
     {
         m_Lock.ExitReadLock();
     }
 }
Exemplo n.º 4
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();
         }
     }
 }