FontFileEnumerator FontCollectionLoader.CreateEnumeratorFromKey(Factory factory, DataPointer collectionKey)
        {
            var enumerator = new ResourceFontFileEnumerator(factory, this, collectionKey);
            _enumerators.Add(enumerator);

            return enumerator;
        }
        /// <summary>	
        /// <p>Obtains the last write time of the file from the font file reference key.</p>	
        /// </summary>	
        /// <param name="referenceKey"><dd> <p>The font file reference key that uniquely identifies the local font file within the scope of the font loader being used.</p> </dd></param>	
        /// <returns><dd> <p>The time of the last font file modification.</p> </dd></returns>	
        /// <msdn-id>dd371247</msdn-id>	
        /// <unmanaged>HRESULT IDWriteLocalFontFileLoader::GetLastWriteTimeFromKey([In, Buffer] const void* fontFileReferenceKey,[In] unsigned int fontFileReferenceKeySize,[Out] FILETIME* lastWriteTime)</unmanaged>	
        /// <unmanaged-short>IDWriteLocalFontFileLoader::GetLastWriteTimeFromKey</unmanaged-short>	
        public DateTime GetLastWriteTime(DataPointer referenceKey)
        {
            if (referenceKey.IsEmpty)
            {
                throw new ArgumentNullException("referenceKey", "DatePointer cannot be null");
            }

            var fileTime = GetLastWriteTimeFromKey(referenceKey.Pointer, referenceKey.Size);
            return DateTime.FromFileTime(fileTime);
        }
Example #3
0
        public unsafe void SetData(DataPointer from, int offsetInBytes = 0)
        {
            DeviceContext dc = GraphicManager.DeviceContext;

            DataStream stream;

            DataBox dataBox = dc.MapSubresource(_nativeBuffer, MapMode.WriteDiscard, MapFlags.None, out stream);
            IntPtr to = (IntPtr)((byte*)dataBox.DataPointer + offsetInBytes);
            Utilities.CopyMemory(to, from.Pointer, from.Size);
        }
        /// <summary>	
        /// <p>Obtains the absolute font file path from the font file reference key.</p>	
        /// </summary>	
        /// <param name="referenceKey"><dd> <p>The font file reference key that uniquely identifies the local font file within the scope of the font loader being used.</p> </dd></param>	
        /// <returns><p>If this method succeeds, the absolute font file path from the font file reference key.</p></returns>	
        /// <msdn-id>dd371241</msdn-id>	
        /// <unmanaged>HRESULT IDWriteLocalFontFileLoader::GetFilePathFromKey([In, Buffer] const void* fontFileReferenceKey,[In] unsigned int fontFileReferenceKeySize,[Out, Buffer] wchar_t* filePath,[In] unsigned int filePathSize)</unmanaged>	
        /// <unmanaged-short>IDWriteLocalFontFileLoader::GetFilePathFromKey</unmanaged-short>	
        public unsafe string GetFilePath(DataPointer referenceKey)
        {
            if (referenceKey.IsEmpty)
            {
                throw new ArgumentNullException("referenceKey", "DatePointer cannot be null");
            }

            var fileNameSize = GetFilePathLengthFromKey(referenceKey.Pointer, referenceKey.Size);
            var buffer = new char[fileNameSize + 1];
            fixed(void* pBuffer = buffer)
            {
                GetFilePathFromKey(referenceKey.Pointer, referenceKey.Size, new IntPtr(pBuffer), fileNameSize + 1 );
            }
            return new string(buffer, 0, fileNameSize);
        }
Example #5
0
            public void ReadFrame(DataPointer Buffer)
            {
                int startFrame = readCursor;

                Buffer.CopyFrom(buffer, readCursor, frameSize);

                readCursor += frameSize;

                if (readCursor >= bufferSize)
                {
                    readCursor = 0;
                    if (writeWrap)
                    {
                        writeWrap = false;
                    }
                    else
                    {
                        Reset();
                    }
                }
                CheckOverread();
            }
Example #6
0
        private ScriptData GetScriptFromFile(string id)
        {
            if (scriptFiles == null || !scriptFiles.ContainsKey(id))
            {
                waywardManager.Log($@"<red>ERROR: Script with id '{id}' not found</red>");
            }

            DataPointer  pointer = scriptFiles[id];
            StreamReader file    = new StreamReader(pointer.filePath);
            ScriptData   data    = new ScriptData();

            try {
                data.code = file.ReadToEnd();
                data.id   = id;
            } catch (Exception e) {
                waywardManager.Log($@"<red>ERROR: Failed retrieving script from '{pointer.filePath}': {e}</red>");
                return(null);
            }

            UpdateScriptMemory(data);
            return(data);
        }
        D2GameInfo ReadGameInfo()
        {
            try
            {
                D2Game game = ReadActiveGameInstance();
                if (game == null || game.Client.IsNull)
                {
                    return(null);
                }

                D2Client client = reader.Read <D2Client>(game.Client);

                // Make sure we are reading a player type.
                if (client.UnitType != 0)
                {
                    return(null);
                }

                // Get the player address from the list of units.
                DataPointer unitAddress = game.UnitLists[0][client.UnitId & 0x7F];
                if (unitAddress.IsNull)
                {
                    return(null);
                }

                // Read player with player data.
                var player     = reader.Read <D2Unit>(unitAddress);
                var playerData = player.UnitData.IsNull
                    ? null
                    : reader.Read <D2PlayerData>(player.UnitData);

                return(new D2GameInfo(game, player, playerData));
            }
            catch (ProcessMemoryReadException)
            {
                return(null);
            }
        }
        public IEnumerable <DataPointer> Parse(CodecContext codecContext, Stream sourceStream, int bufferSize = 4096, long pts = NoPts, long dts = NoPts, long pos = 0)
        {
            IntPtr buffer = AllocZero(bufferSize + AV_INPUT_BUFFER_PADDING_SIZE);

            try
            {
                while (true)
                {
                    int thisBufferLength = sourceStream.Read(ToSpan(buffer, bufferSize));
                    if (thisBufferLength == 0)
                    {
                        break;
                    }

                    DataPointer thisBuffer = new DataPointer(buffer, thisBufferLength);
                    while (thisBuffer.Length > 0)
                    {
                        int offset = Parse(codecContext, thisBuffer, out DataPointer dataPointer, pts, dts, pos);
                        if (dataPointer.Length > 0)
                        {
                            yield return(dataPointer);
                        }
                        thisBuffer = thisBuffer[offset..];
Example #9
0
        public string pointerStore(string varName)
        {
            Feature offs;
            Func <Feature, bool> search = ss => string.Equals(ss.name, varName, StringComparison.OrdinalIgnoreCase);

            offs = FeaturesResources.FirstOrDefault(search) ?? FeaturesCountry.FirstOrDefault(search) ??
                   FeaturesWarfare.FirstOrDefault(search) ?? FeaturesSpecial.FirstOrDefault(search);
            var p      = DataPointer.First(s => s.id == offs.pointerId).pointer;
            var offset = String.IsNullOrEmpty(offs.offset) ? "" : "," + offs.offset;

            return(DataGame.ProcessName + "+" + p + offset);
            // Feature offs;
            // offs = FeaturesResources
            //    .Concat(FeaturesCountry)
            //    .Concat(FeaturesWarfare)
            //    .Concat(FeaturesSpecial)
            //    .First(ss => ss.name == varName);
            //
            // var p = DataPointer.First(s =>
            //     s.id == offs.pointerId).pointer;
            // var offset = String.IsNullOrEmpty(offs.offset) ? "" : "," + offs.offset;
            //
            // return DataGame.ProcessName + "+" + p + offset;
        }
Example #10
0
 public ShaderBytecode(DataPointer dataPointer) : this()
 {
     managedData = null;
     Pointer = dataPointer.Pointer;
     Size = dataPointer.Size;
 }
Example #11
0
 /// <summary>
 /// Creates a Direct2D bitmap from a pointer to in-memory source data.
 /// </summary>
 /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param>
 /// <param name="size">The dimension of the bitmap to create in pixels.</param>
 /// <param name="dataPointer">A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.</param>
 /// <param name="pitch">The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)</param>
 /// <param name="bitmapProperties">The pixel format and dots per inch (DPI) of the bitmap to create.</param>
 /// <msdn-id>dd371800</msdn-id>
 /// <unmanaged>HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)</unmanaged>
 /// <unmanaged-short>ID2D1RenderTarget::CreateBitmap</unmanaged-short>
 public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch, SharpDX.Direct2D1.BitmapProperties bitmapProperties)
     : base(IntPtr.Zero)
 {
     renderTarget.CreateBitmap(size, dataPointer == DataPointer.Zero ? IntPtr.Zero : dataPointer.Pointer, pitch, bitmapProperties, this);
 }
Example #12
0
 public void ReadSilentFrame(DataPointer Buffer)
 {
     Buffer.CopyFrom(silentFrame, 0, frameSize);
 }
Example #13
0
 internal void AllocateSharedMemory(int size)
 {
     sharedPtr = new DataPointer(Utilities.AllocateMemory(size), size);
     ToDispose(sharedPtr.Pointer);
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AudioBuffer" /> class.
 /// </summary>
 /// <param name="dataBuffer">The buffer to get the audio buffer from.</param>
 public AudioBuffer(DataPointer dataBuffer)
 {
     AudioDataPointer = dataBuffer.Pointer;
     Flags = BufferFlags.EndOfStream;
     AudioBytes = dataBuffer.Size;
 }
Example #15
0
        /// <summary>
        /// Creates a font file stream object that encapsulates an open file resource.
        /// </summary>
        /// <param name="fontFileReferenceKey">A reference to a font file reference key that uniquely identifies the font file resource within the scope of the font loader being used. The buffer allocated for this key must at least be the size, in bytes, specified by  fontFileReferenceKeySize.</param>
        /// <returns>
        /// a reference to the newly created <see cref="SharpDX.DirectWrite.FontFileStream"/> object.
        /// </returns>
        /// <remarks>
        /// The resource is closed when the last reference to fontFileStream is released.
        /// </remarks>
        /// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
        FontFileStream FontFileLoader.CreateStreamFromKey(DataPointer fontFileReferenceKey)
        {
            var index = Utilities.Read <int>(fontFileReferenceKey.Pointer);

            return(_fontStreams[index]);
        }
Example #16
0
 public SharpDX.Direct3D12.RootSignature CreateRootSignature(DataPointer rootSignaturePointer)
 {
     return CreateRootSignature(0, rootSignaturePointer);
 }
Example #17
0
    public static void CreateDDSTextureFromMemory(Device d3dDevice,
                                                  DataPointer dataPointer,
                                                  out Resource texture,
                                                  out ShaderResourceView textureView,
                                                  int maxsize                   = 0,
                                                  ResourceUsage usage           = ResourceUsage.Default,
                                                  BindFlags bindFlags           = BindFlags.ShaderResource,
                                                  CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None,
                                                  ResourceOptionFlags miscFlags = ResourceOptionFlags.None,
                                                  bool forceSRGB                = false
                                                  )
    {
        texture     = null;
        textureView = null;

        if (d3dDevice == null)
        {
            throw new SharpDXException(Result.InvalidArg);
        }

        // Validate DDS file in memory
        if (dataPointer.Size < (sizeof(uint) + DdsHeader.SIZE))
        {
            throw new SharpDXException(Result.Fail);
        }

        uint magicNumber = Marshal.PtrToStructure <uint>(dataPointer.Pointer);

        if (magicNumber != DDS_MAGIC)
        {
            throw new SharpDXException(Result.Fail);
        }

        DdsHeader header = Marshal.PtrToStructure <DdsHeader>(dataPointer.Pointer + sizeof(uint));

        // Verify header to validate DDS file
        if (header.size != DdsHeader.SIZE ||
            header.ddspf.size != DdsPixelFormat.SIZE)
        {
            throw new SharpDXException(Result.Fail);
        }

        // Check for DX10 extension
        DdsHeaderDxt10?headerDxt10;

        bool bDXT10Header = false;

        if ((header.ddspf.flags & DDS_FOURCC) != 0 &&
            (MakeFourCC('D', 'X', '1', '0') == header.ddspf.fourCC))
        {
            // Must be long enough for both headers and magic value
            if (dataPointer.Size < (DdsHeader.SIZE + sizeof(uint) + DdsHeaderDxt10.SIZE))
            {
                throw new SharpDXException(Result.Fail);
            }

            bDXT10Header = true;
            headerDxt10  = Marshal.PtrToStructure <DdsHeaderDxt10>(dataPointer.Pointer + sizeof(uint) + DdsHeader.SIZE);
        }
        else
        {
            headerDxt10 = null;
        }

        int offset = sizeof(uint)
                     + DdsHeader.SIZE
                     + (bDXT10Header ? DdsHeaderDxt10.SIZE : 0);

        CreateTextureFromDDS(d3dDevice, header, headerDxt10,
                             dataPointer.Pointer + offset, dataPointer.Size - offset, maxsize,
                             usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
                             out texture, out textureView);
    }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WICStream"/> class from an unmanaged memory through a <see cref="DataStream"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="dataStream">The unmanaged memory stream.</param>
 /// <msdn-id>ee719792</msdn-id>
 /// <unmanaged>HRESULT IWICStream::InitializeFromMemory([In] void* pbBuffer,[In] unsigned int cbBufferSize)</unmanaged>
 /// <unmanaged-short>IWICStream::InitializeFromMemory</unmanaged-short>
 public WICStream(ImagingFactory factory, DataPointer dataStream)
     : base(IntPtr.Zero)
 {
     factory.CreateStream(this);
     InitializeFromMemory(dataStream.Pointer, dataStream.Size);
 }
Example #19
0
        /// <summary>
        /// Copies the content an array of data on CPU memory to this buffer into GPU memory.
        /// </summary>
        /// <param name="buffer">The buffer to update.</param>
        /// <param name="device">The <see cref="SharpDX.Direct3D11.Device"/>.</param>
        /// <param name="fromData">A data pointer.</param>
        /// <param name="offsetInBytes">The offset in bytes to write to.</param>
        /// <param name="mode">Buffer data behavior.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <msdn-id>ff476457</msdn-id>
        ///   <unmanaged>HRESULT ID3D11DeviceContext::Map([In] ID3D11Resource* pResource,[In] unsigned int Subresource,[In] D3D11_MAP MapType,[In] D3D11_MAP_FLAG MapFlags,[Out] D3D11_MAPPED_SUBRESOURCE* pMappedResource)</unmanaged>
        ///   <unmanaged-short>ID3D11DeviceContext::Map</unmanaged-short>
        /// <remarks>
        /// See the unmanaged documentation about Map/UnMap for usage and restrictions.
        /// </remarks>
        public static unsafe void SetData(this Buffer buffer, SharpDX.Direct3D11.Device device, DataPointer fromData, int offsetInBytes = 0, MapMode mode = MapMode.WriteDiscard)
        {
            // Check size validity of data to copy to
            if ((fromData.Size + offsetInBytes) > buffer.Description.SizeInBytes)
            {
                throw new ArgumentException("Size of data to upload + offset is larger than size of buffer");
            }

            var deviceContext = (SharpDX.Direct3D11.DeviceContext)device.ImmediateContext;

            // If this bufefer is declared as default usage, we can only use UpdateSubresource, which is not optimal but better than nothing
            if (buffer.Description.Usage == ResourceUsage.Default)
            {
                // Setup the dest region inside the buffer
                if ((buffer.Description.BindFlags & BindFlags.ConstantBuffer) != 0)
                {
                    deviceContext.UpdateSubresource(new DataBox(fromData.Pointer, 0, 0), buffer);
                }
                else
                {
                    var destRegion = new ResourceRegion(offsetInBytes, 0, 0, offsetInBytes + fromData.Size, 1, 1);
                    deviceContext.UpdateSubresource(new DataBox(fromData.Pointer, 0, 0), buffer, 0, destRegion);
                }
            }
            else
            {
                try
                {
                    var box = deviceContext.MapSubresource(buffer, 0, mode, SharpDX.Direct3D11.MapFlags.None);
                    Utilities.CopyMemory((IntPtr)((byte *)box.DataPointer + offsetInBytes), fromData.Pointer, fromData.Size);
                }
                finally
                {
                    deviceContext.UnmapSubresource(buffer, 0);
                }
            }
        }
Example #20
0
 private D2Unit GetUnit(DataPointer pointer)
 {
     return(pointer.IsNull ? null : processReader.Read <D2Unit>(pointer));
 }
Example #21
0
 /// <summary>
 /// Creates a font collection using a custom font collection loader.
 /// </summary>
 /// <param name="factory">A reference to a DirectWrite factory <see cref="Factory"/></param>
 /// <param name="collectionLoader">An application-defined font collection loader, which must have been previously registered using <see cref="Factory.RegisterFontCollectionLoader_"/>. </param>
 /// <param name="collectionKey">The key used by the loader to identify a collection of font files.  The buffer allocated for this key should at least be the size of collectionKeySize. </param>
 /// <unmanaged>HRESULT IDWriteFactory::CreateCustomFontCollection([None] IDWriteFontCollectionLoader* collectionLoader,[In, Buffer] const void* collectionKey,[None] int collectionKeySize,[Out] IDWriteFontCollection** fontCollection)</unmanaged>
 public FontCollection(Factory factory, FontCollectionLoader collectionLoader, DataPointer collectionKey)
 {
     factory.CreateCustomFontCollection_(FontCollectionLoaderShadow.ToIntPtr(collectionLoader), collectionKey.Pointer, collectionKey.Size, this);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ResourceFontFileEnumerator"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="loader">The loader.</param>
 /// <param name="key">The key.</param>
 public ResourceFontFileEnumerator(Factory factory, FontFileLoader loader, DataPointer key)
 {
     _factory = factory;
     _loader = loader;
     keyStream = new DataStream(key.Pointer, key.Size, true, false);
 }
Example #23
0
        public void PaintToBitmap(Rectangle rc)
        {
            if (bitmap == null || drawType != DrawType.IMAGE)
            {
                return;
            }

            ScDrawNode rootNode;

            graphics.BeginDraw();
            rootNode = reDrawTree.ReCreateReDrawTree(rootScLayer, rc);
            reDrawTree.Draw(graphics);
            graphics.EndDraw();

            if (graphicsType == GraphicsType.D2D && rootNode != null)
            {
                unsafe
                {
                    RectangleF clip = rootNode.clipRect;
                    clip.X      = (int)(clip.X / sizeScale.Width);
                    clip.Y      = (int)(clip.Y / sizeScale.Height);
                    clip.Width  = (int)(clip.Width / sizeScale.Width);
                    clip.Height = (int)(clip.Height / sizeScale.Height);

                    Rectangle  bitmapRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    BitmapData srcBmData  = bitmap.LockBits(bitmapRect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);


                    //DataPointer dataPtr = new DataPointer((IntPtr)srcBmData.Scan0, bitmap.Height * srcBmData.Stride);
                    //wicBitmap.CopyPixels(srcBmData.Stride, dataPtr);
                    byte *ptr = (byte *)srcBmData.Scan0;
                    ptr += (int)clip.Y * srcBmData.Stride + (int)clip.X * 4;
                    DataPointer dataPtr = new DataPointer(ptr, (int)clip.Height * srcBmData.Stride);
                    RawBox      box     = new RawBox((int)clip.X, (int)clip.Y, (int)clip.Width, (int)clip.Height);
                    wicBitmap.CopyPixels(box, srcBmData.Stride, dataPtr);


                    bitmap.UnlockBits(srcBmData);
                }

                //unsafe
                //{
                //    RectangleF clip = rootNode.clipRect;
                //    clip.X = (int)(clip.X / sizeScale.Width);
                //    clip.Y = (int)(clip.Y / sizeScale.Height);
                //    clip.Width = (int)(clip.Width / sizeScale.Width);
                //    clip.Height = (int)(clip.Height / sizeScale.Height);
                //    Rectangle bitmapRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                //    BitmapData srcBmData = bitmap.LockBits(bitmapRect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);


                //    BitmapLock bmplock = wicBitmap.Lock(BitmapLockFlags.Read);
                //    DataRectangle dataRect = bmplock.Data;
                //    byte* wicPtr = (byte*)dataRect.DataPointer;

                //    byte* dstScan = (byte*)(srcBmData.Scan0);
                //    byte* dstPtr = dstScan + (int)clip.Y * srcBmData.Stride + (int)clip.X * 4;
                //    byte* srcPtr = wicPtr + (int)clip.Y * bmplock.Stride + (int)clip.X * 4;
                //    int pos;

                //    for (int i = 0; i < (int)clip.Height; i++)
                //    {
                //        pos = i * srcBmData.Stride;

                //        for (int j = 0; j < (int)clip.Width; j++)
                //        {
                //            *(uint*)(dstPtr + pos) = *(uint*)(srcPtr + pos);
                //            pos += 4;
                //        }
                //    }

                //    bmplock.Dispose();
                //    bitmap.UnlockBits(srcBmData);
                //}
            }
        }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WICStream"/> class from an unmanaged memory through a <see cref="DataStream"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="dataStream">The unmanaged memory stream.</param>
 /// <msdn-id>ee719792</msdn-id>	
 /// <unmanaged>HRESULT IWICStream::InitializeFromMemory([In] void* pbBuffer,[In] unsigned int cbBufferSize)</unmanaged>	
 /// <unmanaged-short>IWICStream::InitializeFromMemory</unmanaged-short>	
 public WICStream(ImagingFactory factory, DataPointer dataStream)
     : base(IntPtr.Zero)
 {
     factory.CreateStream(this);
     InitializeFromMemory(dataStream.Pointer, dataStream.Size);
 }
Example #25
0
 public ResourceFontFileEnumerator(Factory factory, FontFileLoader loader, DataPointer key)
 {
     _factory  = factory;
     _loader   = loader;
     keyStream = new DataStream(key.Pointer, key.Size, true, false);
 }
Example #26
0
 /// <summary>
 /// Creates a new Typed buffer <see cref="ResourceUsage.Default" /> usage.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Typed buffer.</param>
 /// <param name="viewFormat">The view format of the buffer.</param>
 /// <param name="isUnorderedAccess">if set to <c>true</c> this buffer supports unordered access (RW in HLSL).</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Typed buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, PixelFormat viewFormat, bool isUnorderedAccess = false, ResourceUsage usage = ResourceUsage.Default)
 {
     return(Buffer.New(device, value, 0, BufferFlags.ShaderResource | (isUnorderedAccess?BufferFlags.UnorderedAccess : BufferFlags.None), viewFormat, usage));
 }
Example #27
0
 /// <summary>	
 /// No documentation for Direct3D12	
 /// </summary>	
 /// <param name="nodeMask">No documentation.</param>	
 /// <param name="blobWithRootSignatureRef">No documentation.</param>	
 /// <param name="blobLengthInBytes">No documentation.</param>	
 /// <param name="riid">No documentation.</param>	
 /// <returns>No documentation.</returns>	
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateRootSignature']/*"/>	
 /// <unmanaged>HRESULT ID3D12Device::CreateRootSignature([In] unsigned int nodeMask,[In, Buffer] const void* pBlobWithRootSignature,[In] SIZE_T blobLengthInBytes,[In] const GUID&amp; riid,[Out] ID3D12RootSignature** ppvRootSignature)</unmanaged>	
 /// <unmanaged-short>ID3D12Device::CreateRootSignature</unmanaged-short>	
 public SharpDX.Direct3D12.RootSignature CreateRootSignature(int nodeMask, DataPointer rootSignaturePointer)
 {
     return CreateRootSignature(nodeMask, rootSignaturePointer.Pointer, rootSignaturePointer.Size, Utilities.GetGuidFromType(typeof(RootSignature)));
 }
Example #28
0
 public SharpDX.DirectWrite.FontFileStream CreateStreamFromKey(DataPointer fontFileReferenceKey)
 {
     return(_fontStream);
 }
Example #29
0
        /// <summary>
        /// Creates a font file enumerator object that encapsulates a collection of font files. The font system calls back to this interface to create a font collection.
        /// </summary>
        /// <param name="factory">Pointer to the <see cref="SharpDX.DirectWrite.Factory"/> object that was used to create the current font collection.</param>
        /// <param name="collectionKey">A font collection key that uniquely identifies the collection of font files within the scope of the font collection loader being used. The buffer allocated for this key must be at least  the size, in bytes, specified by collectionKeySize.</param>
        /// <returns>
        /// a reference to the newly created font file enumerator.
        /// </returns>
        /// <unmanaged>HRESULT IDWriteFontCollectionLoader::CreateEnumeratorFromKey([None] IDWriteFactory* factory,[In, Buffer] const void* collectionKey,[None] int collectionKeySize,[Out] IDWriteFontFileEnumerator** fontFileEnumerator)</unmanaged>
        FontFileEnumerator FontCollectionLoader.CreateEnumeratorFromKey(Factory factory, DataPointer collectionKey)
        {
            var enumerator = new ResourceFontFileEnumerator(factory, this, collectionKey);

            _enumerators.Add(enumerator);

            return(enumerator);
        }
Example #30
0
 /// <summary>
 /// No documentation for Direct3D12
 /// </summary>
 /// <param name="nodeMask">No documentation.</param>
 /// <param name="blobWithRootSignatureRef">No documentation.</param>
 /// <param name="blobLengthInBytes">No documentation.</param>
 /// <param name="riid">No documentation.</param>
 /// <returns>No documentation.</returns>
 /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='ID3D12Device::CreateRootSignature']/*"/>
 /// <unmanaged>HRESULT ID3D12Device::CreateRootSignature([In] unsigned int nodeMask,[In, Buffer] const void* pBlobWithRootSignature,[In] SIZE_T blobLengthInBytes,[In] const GUID&amp; riid,[Out] ID3D12RootSignature** ppvRootSignature)</unmanaged>
 /// <unmanaged-short>ID3D12Device::CreateRootSignature</unmanaged-short>
 public SharpDX.Direct3D12.RootSignature CreateRootSignature(int nodeMask, DataPointer rootSignaturePointer)
 {
     return(CreateRootSignature(nodeMask, rootSignaturePointer.Pointer, rootSignaturePointer.Size, Utilities.GetGuidFromType(typeof(RootSignature))));
 }
Example #31
0
 /// <summary>	
 /// Creates a font collection using a custom font collection loader. 	
 /// </summary>	
 /// <param name="factory">A reference to a DirectWrite factory <see cref="Factory"/></param>
 /// <param name="collectionLoader">An application-defined font collection loader, which must have been previously registered using <see cref="Factory.RegisterFontCollectionLoader_"/>. </param>
 /// <param name="collectionKey">The key used by the loader to identify a collection of font files.  The buffer allocated for this key should at least be the size of collectionKeySize. </param>
 /// <unmanaged>HRESULT IDWriteFactory::CreateCustomFontCollection([None] IDWriteFontCollectionLoader* collectionLoader,[In, Buffer] const void* collectionKey,[None] int collectionKeySize,[Out] IDWriteFontCollection** fontCollection)</unmanaged>
 public FontCollection(Factory factory, FontCollectionLoader collectionLoader, DataPointer collectionKey)
 {
     factory.CreateCustomFontCollection_(FontCollectionLoaderShadow.ToIntPtr(collectionLoader), collectionKey.Pointer, collectionKey.Size, this);
 }
Example #32
0
 /// <summary>
 /// Creates a font file stream object that encapsulates an open file resource.
 /// </summary>
 /// <param name="fontFileReferenceKey">A reference to a font file reference key that uniquely identifies the font file resource within the scope of the font loader being used. The buffer allocated for this key must at least be the size, in bytes, specified by  fontFileReferenceKeySize.</param>
 /// <returns>
 /// a reference to the newly created <see cref="SharpDX.DirectWrite.FontFileStream"/> object.
 /// </returns>
 /// <remarks>
 /// The resource is closed when the last reference to fontFileStream is released.
 /// </remarks>
 /// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
 FontFileStream FontFileLoader.CreateStreamFromKey(DataPointer fontFileReferenceKey)
 {
     var index = Utilities.Read<int>(fontFileReferenceKey.Pointer);
     return _fontStreams[index];
 }
Example #33
0
 public SharpDX.DirectWrite.FontFileEnumerator CreateEnumeratorFromKey(Factory factory, DataPointer collectionKey)
 {
     return(_fontFileEnumerator);
 }
Example #34
0
 /// <summary>	
 /// Creates a font file stream object that encapsulates an open file resource. 	
 /// </summary>	
 /// <remarks>	
 /// The resource is closed when the last reference to fontFileStream is released.  	
 /// </remarks>	
 /// <param name="fontFileReferenceKey">A reference to a font file reference key that uniquely identifies the font file resource within the scope of the font loader being used. The buffer allocated for this key must at least be the size, in bytes, specified by  fontFileReferenceKeySize. </param>
 /// <returns>a reference to the newly created <see cref="SharpDX.DirectWrite.FontFileStream"/> object. </returns>
 /// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
 public FontFileStream CreateStreamFromKey(DataPointer fontFileReferenceKey)
 {
     FontFileStream temp;
     CreateStreamFromKey_(fontFileReferenceKey.Pointer, fontFileReferenceKey.Size, out temp);
     return temp;
 }
Example #35
0
 public SharpDX.Direct3D12.RootSignature CreateRootSignature(DataPointer rootSignaturePointer)
 {
     return(CreateRootSignature(0, rootSignaturePointer));
 }
Example #36
0
 /// <summary>
 /// Initializes from memory.
 /// </summary>
 /// <param name="dataPointer">The data pointer.</param>
 /// <returns></returns>
 /// <unmanaged>HRESULT IWICColorContext::InitializeFromMemory([In] const void* pbBuffer,[In] unsigned int cbBufferSize)</unmanaged>
 public void InitializeFromMemory(DataPointer dataPointer)
 {
     InitializeFromMemory(dataPointer.Pointer, dataPointer.Size);
 }
Example #37
0
 /// <summary>
 /// Loads an image from an unmanaged memory pointer.
 /// </summary>
 /// <param name="dataBuffer">Pointer to an unmanaged memory. If <see cref="makeACopy"/> is false, this buffer must be allocated with <see cref="Utilities.AllocateMemory"/>.</param>
 /// <param name="makeACopy">True to copy the content of the buffer to a new allocated buffer, false otherwhise.</param>
 /// <returns>An new image.</returns>
 /// <remarks>If <see cref="makeACopy"/> is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose. </remarks>
 public static Image Load(DataPointer dataBuffer, bool makeACopy = false)
 {
     return Load(dataBuffer.Pointer, dataBuffer.Size, makeACopy);
 }
Example #38
0
 /// <summary>
 /// Loads an image from an unmanaged memory pointer.
 /// </summary>
 /// <param name="dataBuffer">Pointer to an unmanaged memory. If <see cref="makeACopy"/> is false, this buffer must be allocated with <see cref="Utilities.AllocateMemory"/>.</param>
 /// <param name="makeACopy">True to copy the content of the buffer to a new allocated buffer, false otherwhise.</param>
 /// <returns>An new image.</returns>
 /// <remarks>If <see cref="makeACopy"/> is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose. </remarks>
 public static Image Load(DataPointer dataBuffer, bool makeACopy = false)
 {
     return(Load(dataBuffer.Pointer, dataBuffer.Size, makeACopy));
 }
Example #39
0
 public void AppendData(DataPointer dataPointer)
 {
     CheckBegin();
     serializer.SerializeMemoryRegion(dataPointer);
 }
            private unsafe void DrawCursor(SharpDX.Direct2D1.RenderTarget renderTarger, CursorInfo cursor)
            {
                var position = cursor.Position;

                var shapeBuff = cursor.PtrShapeBuffer;
                var shapeInfo = cursor.ShapeInfo;

                int width  = shapeInfo.Width;
                int height = shapeInfo.Height;
                int pitch  = shapeInfo.Pitch;

                int left   = position.X;
                int top    = position.Y;
                int right  = position.X + width;
                int bottom = position.Y + height;

                //logger.Debug(left + " " + top + " " + right + " " + bottom);

                if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR)
                {
                    var data       = new DataPointer(shapeBuff, height * pitch);
                    var prop       = new Direct2D.BitmapProperties(new Direct2D.PixelFormat(Format.B8G8R8A8_UNorm, Direct2D.AlphaMode.Premultiplied));
                    var size       = new Size2(width, height);
                    var cursorBits = new Direct2D.Bitmap(renderTarger, size, data, pitch, prop);
                    try
                    {
                        var cursorRect = new RawRectangleF(left, top, right, bottom);

                        renderTarger.DrawBitmap(cursorBits, cursorRect, 1.0f, Direct2D.BitmapInterpolationMode.Linear);
                    }
                    finally
                    {
                        cursorBits?.Dispose();
                    }
                }
                else if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_MONOCHROME)
                {
                    height = height / 2;

                    left   = position.X;
                    top    = position.Y;
                    right  = position.X + width;
                    bottom = position.Y + height;
                    pitch  = width * 4;

                    Texture2D desktopRegionTex = null;
                    try
                    {
                        desktopRegionTex = new Texture2D(device,
                                                         new Texture2DDescription
                        {
                            CpuAccessFlags    = CpuAccessFlags.Read,
                            BindFlags         = BindFlags.None,
                            Format            = Format.B8G8R8A8_UNorm,
                            Width             = width,
                            Height            = height,
                            MipLevels         = 1,
                            ArraySize         = 1,
                            SampleDescription = { Count = 1, Quality = 0 },
                            Usage             = ResourceUsage.Staging,
                            OptionFlags       = ResourceOptionFlags.None,
                        });

                        var region           = new ResourceRegion(left, top, 0, right, bottom, 1);
                        var immediateContext = device.ImmediateContext;
                        immediateContext.CopySubresourceRegion(screenTexture, 0, region, desktopRegionTex, 0);

                        var dataBox = immediateContext.MapSubresource(desktopRegionTex, 0, MapMode.Read, MapFlags.None);
                        try
                        {
                            var desktopBuffer = new byte[width * height * 4];
                            Marshal.Copy(dataBox.DataPointer, desktopBuffer, 0, desktopBuffer.Length);

                            var shapeBufferLenght = width * height * 4;
                            var shapeBuffer       = new byte[shapeBufferLenght];

                            var maskBufferLenght = width * height / 8;
                            var andMaskBuffer    = new byte[maskBufferLenght];
                            Marshal.Copy(shapeBuff, andMaskBuffer, 0, andMaskBuffer.Length);

                            var xorMaskBuffer = new byte[maskBufferLenght];
                            Marshal.Copy(shapeBuff + andMaskBuffer.Length, xorMaskBuffer, 0, xorMaskBuffer.Length);

                            for (var row = 0; row < height; ++row)
                            {
                                byte mask = 0x80;

                                for (var col = 0; col < width; ++col)
                                {
                                    var maskIndex = row * width / 8 + col / 8;

                                    var andMask = ((andMaskBuffer[maskIndex] & mask) == mask) ? 0xFF : 0;
                                    var xorMask = ((xorMaskBuffer[maskIndex] & mask) == mask) ? 0xFF : 0;

                                    int pos = row * width * 4 + col * 4;
                                    for (int i = 0; i < 3; i++)
                                    {// RGB
                                        shapeBuffer[pos] = (byte)((desktopBuffer[pos] & andMask) ^ xorMask);
                                        pos++;
                                    }
                                    // Alpha
                                    shapeBuffer[pos] = (byte)((desktopBuffer[pos] & 0xFF) ^ 0);

                                    if (mask == 0x01)
                                    {
                                        mask = 0x80;
                                    }
                                    else
                                    {
                                        mask = (byte)(mask >> 1);
                                    }
                                }
                            }


                            Direct2D.Bitmap cursorBits = null;
                            try
                            {
                                fixed(byte *ptr = shapeBuffer)
                                {
                                    var data = new DataPointer(ptr, height * pitch);
                                    var prop = new Direct2D.BitmapProperties(new Direct2D.PixelFormat(Format.B8G8R8A8_UNorm, Direct2D.AlphaMode.Premultiplied));
                                    var size = new Size2(width, height);

                                    cursorBits = new Direct2D.Bitmap(renderTarger, size, data, pitch, prop);
                                };

                                var shapeRect = new RawRectangleF(left, top, right, bottom);

                                renderTarger.DrawBitmap(cursorBits, shapeRect, 1.0f, Direct2D.BitmapInterpolationMode.Linear);
                            }
                            finally
                            {
                                cursorBits?.Dispose();
                            }
                        }
                        finally
                        {
                            immediateContext.UnmapSubresource(desktopRegionTex, 0);
                        }
                    }
                    finally
                    {
                        desktopRegionTex?.Dispose();
                    }
                }
                else if (cursor.ShapeInfo.Type == (int)ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR)
                {
                    logger.Warn("Not supported cursor type " + ShapeType.DXGI_OUTDUPL_POINTER_SHAPE_TYPE_COLOR);
                }
            }
Example #41
0
 public override string ToString()
 {
     return(StructureNameHash.ToString() + ": " + DataPointer.ToString() + " (" + DataLength.ToString() + ")");
 }
Example #42
0
            /// <summary>
            /// Creates a new StructuredCounter buffer <see cref="ResourceUsage.Default" /> usage.
            /// </summary>
            /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
            /// <param name="value">The value to initialize the StructuredCounter buffer.</param>
            /// <param name="elementSize">Size of the element.</param>
            /// <returns>A StructuredCounter buffer</returns>
            public static Buffer New(GraphicsDevice device, DataPointer value, int elementSize)
            {
                const BufferFlags BufferFlags = BufferFlags.StructuredCounterBuffer | BufferFlags.ShaderResource | BufferFlags.UnorderedAccess;

                return(Buffer.New(device, value, elementSize, BufferFlags));
            }
Example #43
0
 /// <summary>
 /// Creates a Direct2D bitmap from a pointer to in-memory source data.
 /// </summary>
 /// <param name="renderTarget">an instance of <see cref = "SharpDX.Direct2D1.RenderTarget" /></param>
 /// <param name="size">The dimension of the bitmap to create in pixels.</param>
 /// <param name="dataPointer">A pointer to the memory location of the image data, or NULL to create an uninitialized bitmap.</param>
 /// <param name="pitch">The byte count of each scanline, which is equal to (the image width in pixels * the number of bytes per pixel) + memory padding. If srcData is NULL, this value is ignored. (Note that pitch is also sometimes called stride.)</param>
 /// <msdn-id>dd371800</msdn-id>
 /// <unmanaged>HRESULT ID2D1RenderTarget::CreateBitmap([In] D2D_SIZE_U size,[In, Optional] const void* srcData,[In] unsigned int pitch,[In] const D2D1_BITMAP_PROPERTIES* bitmapProperties,[Out, Fast] ID2D1Bitmap** bitmap)</unmanaged>
 /// <unmanaged-short>ID2D1RenderTarget::CreateBitmap</unmanaged-short>
 public Bitmap(RenderTarget renderTarget, Size2 size, DataPointer dataPointer, int pitch)
     : this(renderTarget, size, dataPointer, pitch, new BitmapProperties(new PixelFormat(Format.Unknown, AlphaMode.Unknown)))
 {
 }
Example #44
0
 /// <summary>	
 /// Finds the specified OpenType font table if it exists and returns a reference to it. The function accesses the underlying font data through the <see cref="T:SharpDX.DirectWrite.FontFileStream" /> interface implemented by the font file loader. 	
 /// </summary>	
 /// <remarks>	
 /// The context for the same tag may be different for each call, so each one must be held and released separately.  	
 /// </remarks>	
 /// <param name="openTypeTableTag">The four-character tag of a OpenType font table to find. Use the DWRITE_MAKE_OPENTYPE_TAG macro to create it as an UINT32. Unlike GDI, it does not support the special TTCF and null tags to access the whole font. </param>
 /// <param name="tableData">When this method returns, contains the address of  a reference to the base of the table in memory. The reference is valid only as long as the font face used to get the font table still exists; (not any other font face, even if it actually refers to the same physical font).</param>
 /// <param name="tableContext">When this method returns, the address of a reference to  the opaque context, which must be freed by calling {{ReleaseFontTable}}. The context actually comes from the lower-level <see cref="T:SharpDX.DirectWrite.FontFileStream" />, which may be implemented by the application or DWrite itself. It is possible for a NULL tableContext to be returned, especially if the implementation performs direct memory mapping on the whole file. Nevertheless, always release it later, and do not use it as a test for function success. The same table can be queried multiple times, but because each returned context can be different, you must release each context separately.  </param>
 /// <returns>TRUE if the font table exists; otherwise, FALSE. </returns>
 /// <unmanaged>HRESULT IDWriteFontFace::TryGetFontTable([In] int openTypeTableTag,[Out, Buffer] const void** tableData,[Out] int* tableSize,[Out] void** tableContext,[Out] BOOL* exists)</unmanaged>
 public bool TryGetFontTable(int openTypeTableTag, out DataPointer tableData, out IntPtr tableContext)
 {
     unsafe
     {
         tableData = DataPointer.Zero;
         IntPtr tableDataPtr = IntPtr.Zero;
         int tableDataSize;
         Bool exists;
         TryGetFontTable(openTypeTableTag, new IntPtr(&tableDataPtr), out tableDataSize, out tableContext, out exists);
         if (tableDataPtr != IntPtr.Zero)
             tableData = new DataPointer(tableDataPtr, tableDataSize);
         return exists;
     }
 }
Example #45
0
        // 1.14d: see game.552F60
        // get unit from the game unit list
        private D2Unit UnitByTypeAndGuid(D2Game game, D2UnitType type, int guid)
        {
            DataPointer unitAddress = game.UnitLists[(int)type][guid & 0x7F];

            return(UnitByGuid(unitAddress, guid));
        }
Example #46
0
 /// <summary>
 /// Initializes from memory.
 /// </summary>
 /// <param name="dataPointer">The data pointer.</param>
 /// <returns></returns>
 /// <unmanaged>HRESULT IWICColorContext::InitializeFromMemory([In] const void* pbBuffer,[In] unsigned int cbBufferSize)</unmanaged>
 public void InitializeFromMemory(DataPointer dataPointer)
 {
     InitializeFromMemory(dataPointer.Pointer, dataPointer.Size);
 }