// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Size = @ref.Size; this.SizeImageInfo = @ref.SizeImageInfo; this.ViewCount = @ref.ViewCount; this.ButtonCount = @ref.ButtonCount; this.AxeCount = @ref.AxeCount; this.PovCount = @ref.PovCount; this.BufferSize = @ref.BufferSize; this.BufferUsed = @ref.BufferUsed; this.ImageInfoArrayPointer = @ref.ImageInfoArrayPointer; if (this.BufferSize > 0 && this.ImageInfoArrayPointer != IntPtr.Zero) { int nbImageInfoElements = BufferSize/ sizeof(DeviceImage.__Native); Images = new DeviceImage[nbImageInfoElements]; var pImageInfo = (DeviceImage.__Native*)this.ImageInfoArrayPointer; for (int i = 0; i < Images.Length; i++) { var image = new DeviceImage(); image.__MarshalFrom(ref *pImageInfo); pImageInfo++; } } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.FontFace = (@ref.FontFace == IntPtr.Zero) ? null : new FontFace(@ref.FontFace); // If FontFace != null, adds a reference to it if (FontFace != null) ((IUnknown) this.FontFace).AddReference(); this.FontSize= @ref.FontEmSize; this.GlyphCount = @ref.GlyphCount; if (@ref.GlyphIndices != IntPtr.Zero) { Indices = new short[GlyphCount]; if (GlyphCount > 0) Utilities.Read(@ref.GlyphIndices, Indices, 0, GlyphCount); } if (@ref.GlyphAdvances != IntPtr.Zero) { Advances = new float[GlyphCount]; if (GlyphCount > 0) Utilities.Read(@ref.GlyphAdvances, Advances, 0, GlyphCount); } if (@ref.GlyphOffsets != IntPtr.Zero) { Offsets = new GlyphOffset[GlyphCount]; if (GlyphCount > 0) Utilities.Read(@ref.GlyphOffsets, Offsets, 0, GlyphCount); } this.IsSideways = @ref.IsSideways; this.BidiLevel = @ref.BidiLevel; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(__Native* @ref) { this.Format = null; this.FormatPointer = @ref->FormatPointer; if (this.FormatPointer != IntPtr.Zero) this.Format = WaveFormat.MarshalFrom(this.FormatPointer); this.MaxFrameCount = @ref->MaxFrameCount; }
internal void UpdateNative(ref __Native native, IntPtr pinBuffer) { native.Pointer = pinBuffer; if (managedData != null) { native.Size = managedData.Length; } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.LocaleName = (@ref.LocaleName == IntPtr.Zero) ? null : Marshal.PtrToStringUni(@ref.LocaleName); this.Text = (@ref.Text == IntPtr.Zero) ? null : Marshal.PtrToStringUni(@ref.Text, @ref.TextLength); this.TextLength = @ref.TextLength; this.ClusterMap = @ref.ClusterMap; this.TextPosition = @ref.TextPosition; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.LocaleName = (this.LocaleName == null) ? IntPtr.Zero : Marshal.StringToHGlobalUni(this.LocaleName); @ref.Text = (this.Text == null) ? IntPtr.Zero : Marshal.StringToHGlobalUni(this.Text); @ref.TextLength = (this.Text == null)?0: this.Text.Length; @ref.ClusterMap = this.ClusterMap; @ref.TextPosition = this.TextPosition; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Category = @ref.Category; this.Severity = @ref.Severity; this.Id = @ref.Id; this.Description = (@ref.PDescription == IntPtr.Zero) ? null : Marshal.PtrToStringAnsi(@ref.PDescription, @ref.DescriptionByteLength); this.DescriptionByteLength = @ref.DescriptionByteLength; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.AttribId = @ref.AttribId; this.FaceStart = @ref.FaceStart; this.FaceCount = @ref.FaceCount; this.VertexStart = @ref.VertexStart; this.VertexCount = @ref.VertexCount; this.BonedIdsPointer = @ref.BonedIdsPointer; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Size = this.Size; @ref.Flags = this.Flags; @ref.BufferBytes = this.BufferBytes; @ref.Reserved = this.Reserved; @ref.pFormat = WaveFormat.MarshalToPtr(Format); @ref.AlgorithmFor3D = this.AlgorithmFor3D; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Size = @ref.Size; this.ObjectSize = @ref.ObjectSize; this.Flags = @ref.Flags; this.DataSize = @ref.DataSize; this.ObjectArrayCount = @ref.ObjectArrayCount; this.ObjectArrayPointer = @ref.ObjectArrayPointer; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Category = @ref.Category; this.Priority = @ref.Priority; this.Pitch = @ref.Pitch; this.Volume = @ref.Volume; this.TrackProperties = new TrackProperties[@ref.NumTracks]; fixed (void* ptr = &@ref.TrackPropertiesPointer) Utilities.Read((IntPtr) ptr, this.TrackProperties, 0, @ref.NumTracks); }
// Method to marshal from native to managed struct internal void __MarshalFrom(ref __Native @ref) { waveFormatTag = @ref.pcmWaveFormat.waveFormatTag; channels = @ref.pcmWaveFormat.channels; sampleRate = @ref.pcmWaveFormat.sampleRate; averageBytesPerSecond = @ref.pcmWaveFormat.averageBytesPerSecond; blockAlign = @ref.pcmWaveFormat.blockAlign; bitsPerSample = @ref.pcmWaveFormat.bitsPerSample; extraSize = @ref.extraSize; }
// Method to marshal from managed struct tot native internal void __MarshalTo(ref __Native @ref) { @ref.pcmWaveFormat.waveFormatTag = waveFormatTag; @ref.pcmWaveFormat.channels = channels; @ref.pcmWaveFormat.sampleRate = sampleRate; @ref.pcmWaveFormat.averageBytesPerSecond = averageBytesPerSecond; @ref.pcmWaveFormat.blockAlign = blockAlign; @ref.pcmWaveFormat.bitsPerSample = bitsPerSample; @ref.extraSize = extraSize; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.waveFormatTag = @ref.pcmWaveFormat.waveFormatTag; this.channels = @ref.pcmWaveFormat.channels; this.sampleRate = @ref.pcmWaveFormat.sampleRate; this.averageBytesPerSecond = @ref.pcmWaveFormat.averageBytesPerSecond; this.blockAlign = @ref.pcmWaveFormat.blockAlign; this.bitsPerSample = @ref.pcmWaveFormat.bitsPerSample; this.extraSize = @ref.extraSize; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.AttribId = this.AttribId; @ref.FaceStart = this.FaceStart; @ref.FaceCount = this.FaceCount; @ref.VertexStart = this.VertexStart; @ref.VertexCount = this.VertexCount; @ref.BonedIdsPointer = IntPtr.Zero; if (BoneIds != null) @ref.BonedIdsPointer = Marshal.AllocHGlobal(BoneIds.Length*sizeof (int)); }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.LpfDirectCoefficient = @ref.LPFDirectCoefficient; this.LpfReverbCoefficient = @ref.LPFReverbCoefficient; this.ReverbLevel = @ref.ReverbLevel; this.DopplerFactor = @ref.DopplerFactor; this.EmitterToListenerAngle = @ref.EmitterToListenerAngle; this.EmitterToListenerDistance = @ref.EmitterToListenerDistance; this.EmitterVelocityComponent = @ref.EmitterVelocityComponent; this.ListenerVelocityComponent = @ref.ListenerVelocityComponent; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.FormatPointer = IntPtr.Zero; if (Format != null) { int sizeOfFormat = Marshal.SizeOf(Format); @ref.FormatPointer = Marshal.AllocCoTaskMem(sizeOfFormat); Marshal.StructureToPtr(Format, @ref.FormatPointer, false); } @ref.MaxFrameCount = this.MaxFrameCount; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.EffectFilename = (this.EffectFilename == null) ? IntPtr.Zero : Marshal.StringToHGlobalAnsi(this.EffectFilename); var defaultsNative = (EffectDefault.__Native*)Marshal.AllocHGlobal(Defaults.Length * sizeof(EffectDefault.__Native)); for (int i = 0; i < Defaults.Length; i++) { Defaults[i].__MarshalTo(ref defaultsNative[i]); } @ref.DefaultCount = Defaults.Length; @ref.DefaultPointer = (IntPtr)defaultsNative; }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.EffectFilename = (@ref.EffectFilename == IntPtr.Zero) ? null : Marshal.PtrToStringAnsi(@ref.EffectFilename); var defaultsNative = new EffectDefault.__Native[@ref.DefaultCount]; Utilities.Read(@ref.DefaultPointer, defaultsNative, 0, defaultsNative.Length); Defaults = new EffectDefault[defaultsNative.Length]; for (int i = 0; i < Defaults.Length; i++) { Defaults[i] = new EffectDefault(); Defaults[i].__MarshalFrom(ref defaultsNative[i]); } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Category = @ref.Category; this.Priority = @ref.Priority; this.Pitch = @ref.Pitch; this.Volume = @ref.Volume; this.TrackProperties = new TrackProperties[@ref.NumTracks]; // if there are no tracks - don't read the properties, otherwise a IndexOutOfRangeException is thrown. if (@ref.NumTracks > 0) { fixed (void* ptr = &@ref.TrackPropertiesPointer) Utilities.Read((IntPtr)ptr, this.TrackProperties, 0, @ref.NumTracks); } }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Offset = Offset; @ref.Type = ((int)TypeFlags) | (((TypeFlags & DeviceObjectTypeFlags.AnyInstance) == DeviceObjectTypeFlags.AnyInstance ? 0 : InstanceNumber) << 8); @ref.Flags = Flags; if (Guid == Guid.Empty) { @ref.GuidPointer = IntPtr.Zero; } else { var handle = GCHandle.Alloc(Guid, GCHandleType.Pinned); @ref.GuidPointer = handle.AddrOfPinnedObject(); } }
internal unsafe void __MarshalFrom(ref __Native @ref) { Parameters = new RootParameter1[@ref.NumParameters]; if (@ref.NumParameters > 0) { UnsafeUtilities.Read(@ref.PParameters, Parameters); } StaticSamplers = new StaticSamplerDescription[@ref.NumStaticSamplers]; if (@ref.NumStaticSamplers > 0) { UnsafeUtilities.Read(@ref.PStaticSamplers, StaticSamplers); } Flags = @ref.Flags; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Type = Type; @ref.Flags = Flags; @ref.NumDescs = DescriptorsCount; @ref.DescsLayout = Layout; if (GeometryDescriptions != null && GeometryDescriptions.Length > 0) { @ref.Union.pGeometryDescs = Interop.AllocToPointer(GeometryDescriptions); } else { @ref.Union.InstanceDescs = InstanceDescriptions; } }
internal unsafe void __MarshalFree(ref __Native @ref) { if (@ref.pSODeclaration != null) { for (int i = 0; i < @ref.NumEntries; i++) { Elements[i].__MarshalFree(ref @ref.pSODeclaration[i]); } Marshal.FreeHGlobal((IntPtr)@ref.pSODeclaration); } if (@ref.pBufferStrides != IntPtr.Zero) { Marshal.FreeHGlobal(@ref.pBufferStrides); } }
internal unsafe void __MarshalFree(ref __Native @ref) { if (@ref.shaderBufferSize > 0) { Marshal.FreeHGlobal(@ref.shaderBufferWithInputSignature); } if (@ref.inputElements != null) { for (int i = 0; i < @ref.elementCount; i++) { Elements[i].__MarshalFree(ref @ref.inputElements[i]); } Marshal.FreeHGlobal((IntPtr)@ref.inputElements); } }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.ByteStride = ByteStride; @ref.NumArgumentDescs = IndirectArguments?.Length ?? 0; if (@ref.NumArgumentDescs > 0) { @ref.pArgumentDescs = UnsafeUtilities.Alloc <IndirectArgumentDescription>(@ref.NumArgumentDescs); fixed(void *indirectArgumentsPtr = &IndirectArguments[0]) { MemoryHelpers.CopyMemory( @ref.pArgumentDescs, (IntPtr)indirectArgumentsPtr, @ref.NumArgumentDescs * sizeof(IndirectArgumentDescription)); } } @ref.NodeMask = NodeMask; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Enable9On12 = Enable9On12; @ref.pD3D12Device = MarshallingHelpers.ToCallbackPtr(D3D12Device); @ref.NumQueues = 0; if (D3D12Queue1 != null) { @ref.pD3D12Queue1 = MarshallingHelpers.ToCallbackPtr(D3D12Queue1); @ref.NumQueues++; } if (D3D12Queue2 != null) { @ref.pD3D12Queue2 = MarshallingHelpers.ToCallbackPtr(D3D12Queue2); @ref.NumQueues++; } @ref.NodeMask = NodeMask; }
internal unsafe void __MarshalFrom(ref __Native @ref) { Clsid = @ref.Clsid; fixed(void *__ptr = & @ref.FriendlyName) FriendlyName = SharpDX.Utilities.PtrToStringUni((System.IntPtr)__ptr, 255); fixed(void *__ptr = & @ref.CopyrightInfo) CopyrightInfo = SharpDX.Utilities.PtrToStringUni((System.IntPtr)__ptr, 255); MajorVersion = @ref.MajorVersion; MinorVersion = @ref.MinorVersion; Flags = @ref.Flags; MinInputBufferCount = @ref.MinInputBufferCount; MaxInputBufferCount = @ref.MaxInputBufferCount; MinOutputBufferCount = @ref.MinOutputBufferCount; MaxOutputBufferCount = @ref.MaxOutputBufferCount; }
//// Method to marshal from native to managed struct /// Disabled as it is not used //internal unsafe void __MarshalFrom(ref __Native @ref) //{ // this.OrientFront = @ref.OrientFront; // this.OrientTop = @ref.OrientTop; // this.Position = @ref.Position; // this.Velocity = @ref.Velocity; // this.ConePointer = @ref.ConePointer; //} // Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.OrientFront = this.OrientFront; @ref.OrientTop = this.OrientTop; @ref.Position = this.Position; @ref.Velocity = this.Velocity; if (this.Cone == null) { @ref.ConePointer = IntPtr.Zero; } else { // We can marshal a pointer to inner Cone struct because Native is only allocated on the stack fixed (void* pCone = &@ref.Cone) @ref.ConePointer = (IntPtr)pCone; this.Cone.__MarshalTo(ref @ref.Cone); } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.__MarshalFrom(ref @ref.waveFormat); this.SamplesPerBlock = @ref.samplesPerBlock; this.Coefficients1 = new short[@ref.numberOfCoefficients]; this.Coefficients2 = new short[@ref.numberOfCoefficients]; if (@ref.numberOfCoefficients > 7) { throw new InvalidOperationException("Unable to read Adpcm format. Too may coefficients (max 7)"); fixed(short *pCoefs = & @ref.coefficients) for (int i = 0; i < @ref.numberOfCoefficients; i++) { this.Coefficients1[i] = pCoefs[i * 2]; this.Coefficients2[i] = pCoefs[i * 2 + 1]; } this.extraSize = (short)(sizeof(int) + sizeof(int) * @ref.numberOfCoefficients); }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.FontFace = FontFace == null ? IntPtr.Zero : FontFace.NativePointer; @ref.FontEmSize = FontEmSize; @ref.GlyphCount = GlyphCount; @ref.GlyphIndices = IntPtr.Zero; @ref.GlyphAdvances = IntPtr.Zero; @ref.GlyphOffsets = IntPtr.Zero; @ref.IsSideways = IsSideways; @ref.BidiLevel = BidiLevel; if (GlyphIndices != null) { @ref.GlyphIndices = Marshal.AllocHGlobal(GlyphIndices.Length * sizeof(short)); if (GlyphCount > 0) { Unsafe.CopyBlock(@ref.GlyphIndices.ToPointer(), Unsafe.AsPointer(ref GlyphIndices[0]), (uint)(sizeof(short) * GlyphCount)); } } if (GlyphAdvances != null) { @ref.GlyphAdvances = Marshal.AllocHGlobal(GlyphAdvances.Length * sizeof(float)); if (GlyphCount > 0) { Unsafe.CopyBlock(@ref.GlyphAdvances.ToPointer(), Unsafe.AsPointer(ref GlyphAdvances[0]), (uint)(sizeof(float) * GlyphCount)); } } if (GlyphOffsets != null) { @ref.GlyphOffsets = Marshal.AllocHGlobal(GlyphOffsets.Length * sizeof(GlyphOffset)); if (GlyphCount > 0) { Unsafe.CopyBlock(@ref.GlyphOffsets.ToPointer(), Unsafe.AsPointer(ref GlyphOffsets[0]), (uint)(sizeof(GlyphOffset) * GlyphCount)); } } }
//// Method to marshal from native to managed struct /// Disabled as it is not used //internal unsafe void __MarshalFrom(ref __Native @ref) //{ // this.OrientFront = @ref.OrientFront; // this.OrientTop = @ref.OrientTop; // this.Position = @ref.Position; // this.Velocity = @ref.Velocity; // this.ConePointer = @ref.ConePointer; //} // Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.OrientFront = this.OrientFront; @ref.OrientTop = this.OrientTop; @ref.Position = this.Position; @ref.Velocity = this.Velocity; if (this.Cone == null) { @ref.ConePointer = IntPtr.Zero; } else { // We can marshal a pointer to inner Cone struct because Native is only allocated on the stack fixed(void *pCone = & @ref.Cone) @ref.ConePointer = (IntPtr)pCone; this.Cone.__MarshalTo(ref @ref.Cone); } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.SourceRegionPointer = @ref.SourceRegionPointer; this.DestinationRegionPointer = @ref.DestinationRegionPointer; this.FirstSourceMip = @ref.FirstSourceMip; this.FirstDestinationMip = @ref.FirstDestinationMip; this.MipCount = @ref.MipCount; this.FirstSourceElement = @ref.FirstSourceElement; this.FirstDestinationElement = @ref.FirstDestinationElement; this.ElementCount = @ref.ElementCount; this.Filter = @ref.Filter; this.MipFilter = @ref.MipFilter; this.SourceRegion = new ResourceRegion(); if (@ref.SourceRegionPointer != IntPtr.Zero) Utilities.Read<ResourceRegion>(@ref.SourceRegionPointer, ref this.SourceRegion); this.DestinationRegion = new ResourceRegion(); if (@ref.DestinationRegionPointer != IntPtr.Zero) Utilities.Read<ResourceRegion>(@ref.DestinationRegionPointer, ref this.DestinationRegion); }
internal unsafe void __MarshalFree(ref __Native @ref) { if (@ref.Nodes != IntPtr.Zero) { var nodes = (GraphNodeDescription.__Native *)@ref.Nodes; for (int i = 0; i < Nodes.Length; i++) { ((GraphNodeDescription)Nodes[i]).__MarshalFree(ref nodes[i]); } UnsafeUtilities.Free(@ref.Nodes); } if (@ref.InputEdges != IntPtr.Zero) { var inputEdges = (GraphEdgeDescription.__Native *)@ref.InputEdges; for (int i = 0; i < InputEdges !.Length; i++) { ((GraphEdgeDescription)InputEdges[i]).__MarshalFree(ref inputEdges[i]); } UnsafeUtilities.Free(@ref.InputEdges); } if (@ref.OutputEdges != IntPtr.Zero) { var outputEdges = (GraphEdgeDescription.__Native *)@ref.OutputEdges; for (int i = 0; i < OutputEdges.Length; i++) { ((GraphEdgeDescription)OutputEdges[i]).__MarshalFree(ref outputEdges[i]); } UnsafeUtilities.Free(@ref.OutputEdges); } if (@ref.IntermediateEdges != IntPtr.Zero) { var intermediateEdges = (GraphEdgeDescription.__Native *)@ref.IntermediateEdges; for (int i = 0; i < IntermediateEdges !.Length; i++) { ((GraphEdgeDescription)IntermediateEdges[i]).__MarshalFree(ref intermediateEdges[i]); } UnsafeUtilities.Free(@ref.IntermediateEdges); } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Size = @ref.Size; this.Flags = @ref.Flags; this.Duration = @ref.Duration; this.SamplePeriod = @ref.SamplePeriod; this.Gain = @ref.Gain; this.TriggerButton = @ref.TriggerButton; this.TriggerRepeatInterval = @ref.TriggerRepeatInterval; this.AxeCount = @ref.AxeCount; this.StartDelay = @ref.StartDelay; // Marshal Axes and Directions if (AxeCount > 0) { if (@ref.AxePointer != IntPtr.Zero) { Axes = new int[AxeCount]; Marshal.Copy(@ref.AxePointer, Axes, 0, AxeCount); } if (@ref.DirectionPointer != IntPtr.Zero) { Directions = new int[AxeCount]; Marshal.Copy(@ref.DirectionPointer, Directions, 0, AxeCount); } } // Marshal Envelope if (@ref.EnvelopePointer != IntPtr.Zero) { var envelopeNative = *((Envelope.__Native *)@ref.EnvelopePointer); Envelope = new Envelope(); Envelope.__MarshalFrom(ref envelopeNative); } // Marshal TypeSpecificParameters if (@ref.TypeSpecificParamCount > 0 && @ref.TypeSpecificParamPointer != IntPtr.Zero) { Parameters = new TypeSpecificParameters(@ref.TypeSpecificParamCount, @ref.TypeSpecificParamPointer); } }
private unsafe void __MarshalTo(ref __Native @ref) { if (Coefficients1.Length > 7) { throw new InvalidOperationException("Unable to encode Adpcm format. Too may coefficients (max 7)"); } extraSize = (short)(sizeof(int) + sizeof(int) * Coefficients1.Length); __MarshalTo(ref @ref.waveFormat); @ref.samplesPerBlock = SamplesPerBlock; @ref.numberOfCoefficients = (ushort)Coefficients1.Length; fixed(short *pCoefs = & @ref.coefficients) { for (int i = 0; i < @ref.numberOfCoefficients; i++) { pCoefs[i * 2] = Coefficients1[i]; pCoefs[i * 2 + 1] = Coefficients2[i]; } } }
internal unsafe void __MarshalFrom(ref __Native @ref) { GlyphRun = new GlyphRun(); GlyphRun.__MarshalFrom(ref @ref.GlyphRun); if (@ref.GlyphRunDescription == null) { GlyphRunDescription = null; } else { GlyphRunDescription = new GlyphRunDescription(); GlyphRunDescription.__MarshalFrom(ref *@ref.GlyphRunDescription); } BaselineOriginX = @ref.BaselineOriginX; BaselineOriginY = @ref.BaselineOriginY; RunColor = @ref.RunColor; PaletteIndex = @ref.PaletteIndex; }
internal unsafe void __MarshalFrom(ref __Native @ref) { Type = @ref.Type; Flags = @ref.Flags; DescriptorsCount = @ref.NumDescs; Layout = @ref.DescsLayout; if (@ref.NumDescs > 0) { if (@ref.Type == RaytracingAccelerationStructureType.TopLevel) { InstanceDescriptions = Unsafe.Read <long>(@ref.Union.pGeometryDescs.ToPointer()); } else { GeometryDescriptions = new RaytracingGeometryDescription[@ref.NumDescs]; Interop.Read(@ref.Union.pGeometryDescs, GeometryDescriptions); } } }
internal unsafe void __MarshalFrom(ref __Native @ref) { Categories = new InfoQueueMessageCategory[@ref.NumCategories]; if (@ref.NumCategories > 0) { MemoryHelpers.Read(@ref.PCategoryList, Categories, 0, @ref.NumCategories); } Severities = new InfoQueueMessageSeverity[@ref.NumSeverities]; if (@ref.NumSeverities > 0) { MemoryHelpers.Read(@ref.PSeverityList, Severities, 0, @ref.NumSeverities); } Ids = new int[@ref.NumIDs]; if (@ref.NumIDs > 0) { MemoryHelpers.Read(@ref.PIDList, Ids, 0, @ref.NumIDs); } }
internal unsafe void __MarshalFrom(ref __Native @ref) { Categories = new MessageCategory[@ref.NumCategories]; if (@ref.NumCategories > 0) { Interop.Read(@ref.PCategoryList, Categories); } Severities = new MessageSeverity[@ref.NumSeverities]; if (@ref.NumSeverities > 0) { Interop.Read(@ref.PSeverityList, Severities); } Ids = new MessageId[@ref.NumIDs]; if (@ref.NumIDs > 0) { Interop.Read(@ref.PIDList, Ids); } }
internal unsafe void __MarshalFrom(ref __Native @ref) { FontFace = (@ref.FontFace == IntPtr.Zero) ? null : new IDWriteFontFace(@ref.FontFace); if (FontFace != null) { FontFace.AddRef(); } FontSize = @ref.FontEmSize; GlyphCount = @ref.GlyphCount; GlyphCount = @ref.GlyphCount; if (@ref.GlyphIndices != IntPtr.Zero) { Indices = new ushort[GlyphCount]; if (GlyphCount > 0) { UnsafeUtilities.Read(@ref.GlyphIndices, Indices, GlyphCount); } } if (@ref.GlyphAdvances != IntPtr.Zero) { Advances = new float[GlyphCount]; if (GlyphCount > 0) { UnsafeUtilities.Read(@ref.GlyphAdvances, Advances, GlyphCount); } } if (@ref.GlyphOffsets != IntPtr.Zero) { Offsets = new GlyphOffset[GlyphCount]; if (GlyphCount > 0) { UnsafeUtilities.Read(@ref.GlyphOffsets, Offsets, GlyphCount); } } IsSideways = @ref.IsSideways; BidiLevel = @ref.BidiLevel; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Flags = Flags; @ref.DataSize = DataSize; @ref.ObjectArrayCount = 0; @ref.ObjectArrayPointer = IntPtr.Zero; if (ObjectsFormat != null && ObjectsFormat.Length > 0) { @ref.ObjectArrayCount = ObjectsFormat.Length; var nativeDataFormats = new ObjectDataFormat.__Native[ObjectsFormat.Length]; for (int i = 0; i < ObjectsFormat.Length; i++) { ObjectsFormat[i].__MarshalTo(ref nativeDataFormats[i]); } var handle = GCHandle.Alloc(nativeDataFormats, GCHandleType.Pinned); @ref.ObjectArrayPointer = handle.AddrOfPinnedObject(); } }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Size = this.Size; @ref.Guid = this.Guid; IntPtr effectParameters = IntPtr.Zero; if (Parameters != null) { effectParameters = Marshal.AllocHGlobal(sizeof(EffectParameters.__Native)); var nativeParameters = default(EffectParameters.__Native); Parameters.__MarshalTo(ref nativeParameters); *((EffectParameters.__Native *)effectParameters) = nativeParameters; } @ref.EffectParametersPointer = effectParameters; IntPtr Name_ = Marshal.StringToHGlobalAnsi(this.Name); fixed(void *__ptr = & @ref.Name) Utilities.CopyMemory((IntPtr)__ptr, Name_, this.Name.Length); Marshal.FreeHGlobal(Name_); }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.Size = @ref.Size; this.Flags = @ref.Flags; this.BufferBytes = @ref.BufferBytes; this.Reserved = @ref.Reserved; this.Format = WaveFormat.MarshalFrom(@ref.FormatPointer); this.EffectCount = @ref.EffectCount; if (EffectCount > 0) { var nativeDescriptions = new CaptureEffectDescription.__Native[EffectCount]; Utilities.Read(@ref.EffectDescriptionPointer, nativeDescriptions, 0, EffectCount); EffectDescriptions = new CaptureEffectDescription[EffectCount]; for (int i = 0; i < EffectCount; i++) { EffectDescriptions[i] = new CaptureEffectDescription(); EffectDescriptions[i].__MarshalFrom(ref nativeDescriptions[i]); } } }
internal unsafe void __MarshalFrom(ref __Native @ref) { Options = @ref.Options; switch (Options.SourceType) { case RequestSourceType.File: Source.File.__MarshalFrom(ref @ref.Source.File); break; case RequestSourceType.Memory: Source.Memory = @ref.Source.Memory; break; } switch (Options.DestinationType) { case RequestDestinationType.Memory: Destination.Memory = @ref.Destination.Memory; break; case RequestDestinationType.Buffer: Destination.Buffer.__MarshalFrom(ref @ref.Destination.Buffer); break; case RequestDestinationType.TextureRegion: Destination.Texture.__MarshalFrom(ref @ref.Destination.Texture); break; case RequestDestinationType.MultipleSubresources: Destination.MultipleSubresources.__MarshalFrom(ref @ref.Destination.MultipleSubresources); break; case RequestDestinationType.Tiles: Destination.Tiles.__MarshalFrom(ref @ref.Destination.Tiles); break; } UncompressedSize = @ref.UncompressedSize; CancellationTag = @ref.CancellationTag; Name = Marshal.PtrToStringAnsi(@ref.Name); }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Options = Options; switch (Options.SourceType) { case RequestSourceType.File: Source.File.__MarshalTo(ref @ref.Source.File); break; case RequestSourceType.Memory: @ref.Source.Memory = Source.Memory; break; } switch (Options.DestinationType) { case RequestDestinationType.Memory: @ref.Destination.Memory = Destination.Memory; break; case RequestDestinationType.Buffer: Destination.Buffer.__MarshalTo(ref @ref.Destination.Buffer); break; case RequestDestinationType.TextureRegion: Destination.Texture.__MarshalTo(ref @ref.Destination.Texture); break; case RequestDestinationType.MultipleSubresources: Destination.MultipleSubresources.__MarshalTo(ref @ref.Destination.MultipleSubresources); break; case RequestDestinationType.Tiles: Destination.Tiles.__MarshalTo(ref @ref.Destination.Tiles); break; } @ref.UncompressedSize = UncompressedSize; @ref.CancellationTag = CancellationTag; @ref.Name = Marshal.StringToHGlobalAnsi(Name); }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.FontFace = (@ref.FontFace == IntPtr.Zero) ? null : new FontFace(@ref.FontFace); // If FontFace != null, adds a reference to it if (FontFace != null) { ((IUnknown)this.FontFace).AddReference(); } this.FontSize = @ref.FontEmSize; this.GlyphCount = @ref.GlyphCount; if (@ref.GlyphIndices != IntPtr.Zero) { Indices = new short[GlyphCount]; if (GlyphCount > 0) { Utilities.Read(@ref.GlyphIndices, Indices, 0, GlyphCount); } } if (@ref.GlyphAdvances != IntPtr.Zero) { Advances = new float[GlyphCount]; if (GlyphCount > 0) { Utilities.Read(@ref.GlyphAdvances, Advances, 0, GlyphCount); } } if (@ref.GlyphOffsets != IntPtr.Zero) { Offsets = new GlyphOffset[GlyphCount]; if (GlyphCount > 0) { Utilities.Read(@ref.GlyphOffsets, Offsets, 0, GlyphCount); } } this.IsSideways = @ref.IsSideways; this.BidiLevel = @ref.BidiLevel; }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.shaderBufferSize = ShaderBufferWithInputSignature?.Length ?? 0; if (@ref.shaderBufferSize > 0) { @ref.shaderBufferWithInputSignature = Interop.AllocToPointer(ShaderBufferWithInputSignature); } @ref.elementCount = Elements?.Length ?? 0; if (@ref.elementCount > 0) { var nativeElements = (InputElementDescription.__Native *)Interop.Alloc <InputElementDescription.__Native>(@ref.elementCount); for (int i = 0; i < @ref.elementCount; i++) { Elements[i].__MarshalTo(ref nativeElements[i]); } @ref.inputElements = nativeElements; } @ref.stride = Stride; }
//// Method to marshal from native to managed struct /// disabled as it is not used //internal unsafe void __MarshalFrom(ref __Native @ref) //{ // this.ConePointer = @ref.ConePointer; // this.OrientFront = @ref.OrientFront; // this.OrientTop = @ref.OrientTop; // this.Position = @ref.Position; // this.Velocity = @ref.Velocity; // this.InnerRadius = @ref.InnerRadius; // this.InnerRadiusAngle = @ref.InnerRadiusAngle; // this.ChannelCount = @ref.ChannelCount; // this.ChannelRadius = @ref.ChannelRadius; // this.ChannelAzimuthsPointer = @ref.ChannelAzimuthsPointer; // this.VolumeCurvePointer = @ref.VolumeCurvePointer; // this.LFECurvePointer = @ref.LFECurvePointer; // this.LPFDirectCurvePointer = @ref.LPFDirectCurvePointer; // this.LPFReverbCurvePointer = @ref.LPFReverbCurvePointer; // this.ReverbCurvePointer = @ref.ReverbCurvePointer; // this.CurveDistanceScaler = @ref.CurveDistanceScaler; // this.DopplerScaler = @ref.DopplerScaler; //} // Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.OrientFront = this.OrientFront; @ref.OrientTop = this.OrientTop; @ref.Position = this.Position; @ref.Velocity = this.Velocity; @ref.InnerRadius = this.InnerRadius; @ref.InnerRadiusAngle = this.InnerRadiusAngle; @ref.ChannelCount = this.ChannelCount; @ref.ChannelRadius = this.ChannelRadius; if (this.ChannelAzimuths != null && this.ChannelAzimuths.Length > 0 && ChannelCount > 0) { @ref.ChannelAzimuthsPointer = Marshal.AllocHGlobal(sizeof(float) * Math.Min(ChannelCount, ChannelAzimuths.Length)); Utilities.Write(@ref.ChannelAzimuthsPointer, ChannelAzimuths, 0, ChannelCount); } @ref.VolumeCurvePointer = DistanceCurve.FromCurvePoints(this.VolumeCurve); @ref.LFECurvePointer = DistanceCurve.FromCurvePoints(this.LfeCurve); @ref.LPFDirectCurvePointer = DistanceCurve.FromCurvePoints(this.LpfDirectCurve); @ref.LPFReverbCurvePointer = DistanceCurve.FromCurvePoints(this.LpfReverbCurve); @ref.ReverbCurvePointer = DistanceCurve.FromCurvePoints(this.ReverbCurve); @ref.CurveDistanceScaler = this.CurveDistanceScaler; @ref.DopplerScaler = this.DopplerScaler; if (this.Cone == null) { @ref.ConePointer = IntPtr.Zero; } else { // We can marshal a pointer to inner Cone struct because Native is only allocated on the stack fixed(void *pCone = & @ref.Cone) @ref.ConePointer = (IntPtr)pCone; this.Cone.__MarshalTo(ref @ref.Cone); } }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Type = Type; @ref.NumSubobjects = SubObjects?.Length ?? 0; if (@ref.NumSubobjects > 0) { var subObjectLookup = new Dictionary <StateSubObject, IntPtr>(); var nativeSubObjects = (StateSubObject.__Native *)UnsafeUtilities.Alloc <StateSubObject.__Native>(@ref.NumSubobjects); // Create lookup table first for (int i = 0; i < @ref.NumSubobjects; i++) { subObjectLookup.Add(SubObjects[i], new IntPtr(&nativeSubObjects[i])); } for (int i = 0; i < @ref.NumSubobjects; i++) { SubObjects[i].__MarshalTo(ref nativeSubObjects[i], subObjectLookup); } @ref.pSubobjects = nativeSubObjects; } }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.SourceRegionPointer = @ref.SourceRegionPointer; this.DestinationRegionPointer = @ref.DestinationRegionPointer; this.FirstSourceMip = @ref.FirstSourceMip; this.FirstDestinationMip = @ref.FirstDestinationMip; this.MipCount = @ref.MipCount; this.FirstSourceElement = @ref.FirstSourceElement; this.FirstDestinationElement = @ref.FirstDestinationElement; this.ElementCount = @ref.ElementCount; this.Filter = @ref.Filter; this.MipFilter = @ref.MipFilter; this.SourceRegion = new ResourceRegion(); if (@ref.SourceRegionPointer != IntPtr.Zero) { Utilities.Read <ResourceRegion>(@ref.SourceRegionPointer, ref this.SourceRegion); } this.DestinationRegion = new ResourceRegion(); if (@ref.DestinationRegionPointer != IntPtr.Zero) { Utilities.Read <ResourceRegion>(@ref.DestinationRegionPointer, ref this.DestinationRegion); } }
internal unsafe void __MarshalTo(ref __Native @ref) { @ref.OrientFront = OrientFront; @ref.OrientTop = OrientTop; @ref.Position = Position; @ref.Velocity = Velocity; @ref.InnerRadius = InnerRadius; @ref.InnerRadiusAngle = InnerRadiusAngle; @ref.ChannelCount = ChannelCount; @ref.ChannelRadius = ChannelRadius; if (ChannelAzimuths != null && ChannelAzimuths.Length > 0 && ChannelCount > 0) { @ref.ChannelAzimuthsPointer = Marshal.AllocHGlobal(sizeof(float) * Math.Min(ChannelCount, ChannelAzimuths.Length)); MemoryHelpers.Write(@ref.ChannelAzimuthsPointer, new Span <float>(ChannelAzimuths), ChannelCount); } @ref.VolumeCurvePointer = DistanceCurve.FromCurvePoints(VolumeCurve); @ref.LFECurvePointer = DistanceCurve.FromCurvePoints(LfeCurve); @ref.LPFDirectCurvePointer = DistanceCurve.FromCurvePoints(LpfDirectCurve); @ref.LPFReverbCurvePointer = DistanceCurve.FromCurvePoints(LpfReverbCurve); @ref.ReverbCurvePointer = DistanceCurve.FromCurvePoints(ReverbCurve); @ref.CurveDistanceScaler = CurveDistanceScaler; @ref.DopplerScaler = DopplerScaler; if (Cone == null) { @ref.ConePointer = null; } else { var coneValue = Cone.Value; @ref.ConePointer = Unsafe.AsPointer(ref coneValue); } }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.Offset = this.Offset; @ref.EventNotifyHandlerPointer = this.WaitHandle.SafeWaitHandle.DangerousGetHandle(); }
internal unsafe void __MarshalFree(ref __Native @ref) { @ref.__MarshalFree(); }
// Method to marshal from native to managed struct internal unsafe void __MarshalFrom(ref __Native @ref) { this.__MarshalFrom(ref @ref.waveFormat); this.SamplesPerBlock = @ref.samplesPerBlock; this.Coefficients1 = new short[@ref.numberOfCoefficients]; this.Coefficients2 = new short[@ref.numberOfCoefficients]; if (@ref.numberOfCoefficients > 7) throw new InvalidOperationException("Unable to read Adpcm format. Too may coefficients (max 7)"); fixed(short* pCoefs = &@ref.coefficients) for (int i = 0; i < @ref.numberOfCoefficients; i++) { this.Coefficients1[i] = pCoefs[i*2]; this.Coefficients2[i] = pCoefs[i*2+1]; } this.extraSize = (short)(sizeof(int) + sizeof(int) * @ref.numberOfCoefficients); }
//// Method to marshal from native to managed struct /// disabled as it is not used //internal unsafe void __MarshalFrom(ref __Native @ref) //{ // this.ConePointer = @ref.ConePointer; // this.OrientFront = @ref.OrientFront; // this.OrientTop = @ref.OrientTop; // this.Position = @ref.Position; // this.Velocity = @ref.Velocity; // this.InnerRadius = @ref.InnerRadius; // this.InnerRadiusAngle = @ref.InnerRadiusAngle; // this.ChannelCount = @ref.ChannelCount; // this.ChannelRadius = @ref.ChannelRadius; // this.ChannelAzimuthsPointer = @ref.ChannelAzimuthsPointer; // this.VolumeCurvePointer = @ref.VolumeCurvePointer; // this.LFECurvePointer = @ref.LFECurvePointer; // this.LPFDirectCurvePointer = @ref.LPFDirectCurvePointer; // this.LPFReverbCurvePointer = @ref.LPFReverbCurvePointer; // this.ReverbCurvePointer = @ref.ReverbCurvePointer; // this.CurveDistanceScaler = @ref.CurveDistanceScaler; // this.DopplerScaler = @ref.DopplerScaler; //} // Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.OrientFront = this.OrientFront; @ref.OrientTop = this.OrientTop; @ref.Position = this.Position; @ref.Velocity = this.Velocity; @ref.InnerRadius = this.InnerRadius; @ref.InnerRadiusAngle = this.InnerRadiusAngle; @ref.ChannelCount = this.ChannelCount; @ref.ChannelRadius = this.ChannelRadius; if (this.ChannelAzimuths != null && this.ChannelAzimuths.Length > 0 && ChannelCount > 0) { @ref.ChannelAzimuthsPointer = Marshal.AllocHGlobal(sizeof (float)* Math.Min(ChannelCount, ChannelAzimuths.Length)); Utilities.Write(@ref.ChannelAzimuthsPointer, ChannelAzimuths, 0, ChannelCount); } @ref.VolumeCurvePointer = DistanceCurve.FromCurvePoints(this.VolumeCurve); @ref.LFECurvePointer = DistanceCurve.FromCurvePoints(this.LfeCurve); @ref.LPFDirectCurvePointer = DistanceCurve.FromCurvePoints(this.LpfDirectCurve); @ref.LPFReverbCurvePointer = DistanceCurve.FromCurvePoints(this.LpfReverbCurve); @ref.ReverbCurvePointer = DistanceCurve.FromCurvePoints(this.ReverbCurve); @ref.CurveDistanceScaler = this.CurveDistanceScaler; @ref.DopplerScaler = this.DopplerScaler; if (this.Cone == null) { @ref.ConePointer = IntPtr.Zero; } else { // We can marshal a pointer to inner Cone struct because Native is only allocated on the stack fixed (void* pCone = &@ref.Cone) @ref.ConePointer = (IntPtr)pCone; this.Cone.__MarshalTo(ref @ref.Cone); } }
// Method to marshal from managed struct tot native private unsafe void __MarshalTo(ref __Native @ref) { if (Coefficients1.Length > 7) throw new InvalidOperationException("Unable to encode Adpcm format. Too may coefficients (max 7)"); this.extraSize = (short)(sizeof(int) + sizeof(int) * Coefficients1.Length); this.__MarshalTo(ref @ref.waveFormat); @ref.samplesPerBlock = this.SamplesPerBlock; @ref.numberOfCoefficients = (ushort)this.Coefficients1.Length; fixed (short* pCoefs = &@ref.coefficients) for (int i = 0; i < @ref.numberOfCoefficients; i++) { pCoefs[i*2] = this.Coefficients1[i]; pCoefs[i*2+1] = this.Coefficients2[i]; } }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.FontFace = this.FontFace == null?IntPtr.Zero:this.FontFace.NativePointer; @ref.FontEmSize = this.FontSize; @ref.GlyphCount = -1; @ref.GlyphIndices = IntPtr.Zero; @ref.GlyphAdvances = IntPtr.Zero; @ref.GlyphOffsets = IntPtr.Zero; if (this.Indices != null) { @ref.GlyphCount = this.Indices.Length; @ref.GlyphIndices = Marshal.AllocHGlobal(this.Indices.Length*sizeof (short)); if (this.Indices.Length > 0) Utilities.Write(@ref.GlyphIndices, Indices, 0, this.Indices.Length); } if (this.Advances != null) { if (@ref.GlyphCount >= 0 && @ref.GlyphCount != this.Advances.Length) throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid length for array Advances [{0}] and Indices [{1}]. Indices, Advances and Offsets array must have same size - or may be null", this.Advances.Length, @ref.GlyphCount)); @ref.GlyphCount = this.Advances.Length; @ref.GlyphAdvances = Marshal.AllocHGlobal(this.Advances.Length * sizeof(float)); if (this.Advances.Length > 0) Utilities.Write(@ref.GlyphAdvances, Advances, 0, this.Advances.Length); } if (this.Offsets != null) { if (@ref.GlyphCount >= 0 && @ref.GlyphCount != this.Offsets.Length) throw new InvalidOperationException( string.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid length for array Offsets [{0}]. Indices, Advances and Offsets array must have same size (Current is [{1}]- or may be null", this.Offsets.Length, @ref.GlyphCount)); @ref.GlyphCount = this.Offsets.Length; @ref.GlyphOffsets = Marshal.AllocHGlobal(this.Offsets.Length * sizeof(GlyphOffset)); if (this.Offsets.Length > 0) Utilities.Write(@ref.GlyphOffsets, Offsets, 0, this.Offsets.Length); } if (@ref.GlyphCount < 0) @ref.GlyphCount = 0; // Update GlyphCount only for debug purpose this.GlyphCount = @ref.GlyphCount; @ref.IsSideways = this.IsSideways; @ref.BidiLevel = this.BidiLevel; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.pcmWaveFormat.waveFormatTag = this.waveFormatTag; @ref.pcmWaveFormat.channels = this.channels; @ref.pcmWaveFormat.sampleRate = this.sampleRate; @ref.pcmWaveFormat.averageBytesPerSecond = this.averageBytesPerSecond; @ref.pcmWaveFormat.blockAlign = this.blockAlign; @ref.pcmWaveFormat.bitsPerSample = this.bitsPerSample; @ref.extraSize = this.extraSize; }
// Method to marshal from managed struct tot native internal unsafe void __MarshalTo(ref __Native @ref) { @ref.SourceRegionPointer = Marshal.AllocHGlobal(Utilities.SizeOf<ResourceRegion>()); @ref.DestinationRegionPointer = Marshal.AllocHGlobal(Utilities.SizeOf<ResourceRegion>()); @ref.FirstSourceMip = this.FirstSourceMip; @ref.FirstDestinationMip = this.FirstDestinationMip; @ref.MipCount = this.MipCount; @ref.FirstSourceElement = this.FirstSourceElement; @ref.FirstDestinationElement = this.FirstDestinationElement; @ref.ElementCount = this.ElementCount; @ref.Filter = this.Filter; @ref.MipFilter = this.MipFilter; Utilities.Write(@ref.SourceRegionPointer, ref this.SourceRegion); Utilities.Write(@ref.DestinationRegionPointer, ref this.DestinationRegion); }