Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[Direct2D1] Replaced DataStream usages by DataPointer where appropiat…
Browse files Browse the repository at this point in the history
…e (github issue #90)
  • Loading branch information
ArtiomCiumac committed Jun 29, 2013
1 parent 971088d commit 372b7fd
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Samples/DirectWrite/CustomFont/ResourceFontFileEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public class ResourceFontFileEnumerator : CallbackBase, FontFileEnumerator
/// </summary>
/// <param name="factory">The factory.</param>
/// <param name="loader">The loader.</param>
/// <param name="keyStream">The key stream.</param>
public ResourceFontFileEnumerator(Factory factory, FontFileLoader loader, DataStream keyStream)
/// <param name="key">The key.</param>
public ResourceFontFileEnumerator(Factory factory, FontFileLoader loader, DataPointer key)
{
_factory = factory;
_loader = loader;
this.keyStream = keyStream;
keyStream = new DataStream(key.Pointer, key.Size, true, false);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Samples/DirectWrite/CustomFont/ResourceFontLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public DataStream Key
/// 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, DataStream collectionKey)
FontFileEnumerator FontCollectionLoader.CreateEnumeratorFromKey(Factory factory, DataPointer collectionKey)
{
var enumerator = new ResourceFontFileEnumerator(factory, this, new DataStream(_keyStream.DataPointer, _keyStream.Length, true,true));
var enumerator = new ResourceFontFileEnumerator(factory, this, collectionKey);
_enumerators.Add(enumerator);

return enumerator;
Expand All @@ -105,9 +105,9 @@ FontFileEnumerator FontCollectionLoader.CreateEnumeratorFromKey(Factory factory,
/// 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(DataStream fontFileReferenceKey)
FontFileStream FontFileLoader.CreateStreamFromKey(DataPointer fontFileReferenceKey)
{
var index = fontFileReferenceKey.Read<int>();
var index = Utilities.Read<int>(fontFileReferenceKey.Pointer);
return _fontStreams[index];
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SharpDX.Direct2D1/DirectWrite/FontCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public partial class FontCollection
/// <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, DataStream collectionKey)
public FontCollection(Factory factory, FontCollectionLoader collectionLoader, DataPointer collectionKey)
{
factory.CreateCustomFontCollection_(FontCollectionLoaderShadow.ToIntPtr(collectionLoader), collectionKey.PositionPointer, (int)collectionKey.RemainingLength, this);
factory.CreateCustomFontCollection_(FontCollectionLoaderShadow.ToIntPtr(collectionLoader), collectionKey.Pointer, collectionKey.Size, this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public partial interface FontCollectionLoader
/// <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>
SharpDX.DirectWrite.FontFileEnumerator CreateEnumeratorFromKey(SharpDX.DirectWrite.Factory factory, DataStream collectionKey);
SharpDX.DirectWrite.FontFileEnumerator CreateEnumeratorFromKey(SharpDX.DirectWrite.Factory factory, DataPointer collectionKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public FontCollectionLoaderVtbl() : base(1)

/// <unmanaged>HRESULT IDWriteFontCollectionLoader::CreateEnumeratorFromKey([None] IDWriteFactory* factory,[In, Buffer] const void* collectionKey,[None] int collectionKeySize,[Out] IDWriteFontFileEnumerator** fontFileEnumerator)</unmanaged>
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int CreateEnumeratorFromKeyDelegate(
IntPtr thisPtr, IntPtr factory, IntPtr collectionKey, int collectionKeySize, out IntPtr fontFileEnumerator);
private delegate int CreateEnumeratorFromKeyDelegate(IntPtr thisPtr, IntPtr factory, IntPtr collectionKey, int collectionKeySize, out IntPtr fontFileEnumerator);

private static int CreateEnumeratorFromKeyImpl(IntPtr thisPtr, IntPtr factory, IntPtr collectionKey, int collectionKeySize, out IntPtr fontFileEnumerator)
{
fontFileEnumerator = IntPtr.Zero;
Expand All @@ -65,7 +65,7 @@ private static int CreateEnumeratorFromKeyImpl(IntPtr thisPtr, IntPtr factory, I
var shadow = ToShadow<FontCollectionLoaderShadow>(thisPtr);
var callback = (FontCollectionLoader)shadow.Callback;
Debug.Assert(factory == shadow._factory.NativePointer);
var enumerator = callback.CreateEnumeratorFromKey(shadow._factory, new DataStream(collectionKey, collectionKeySize, true, true));
var enumerator = callback.CreateEnumeratorFromKey(shadow._factory, new DataPointer(collectionKey, collectionKeySize));
fontFileEnumerator = FontFileEnumeratorShadow.ToIntPtr(enumerator);
}
catch (Exception exception)
Expand Down
6 changes: 3 additions & 3 deletions Source/SharpDX.Direct2D1/DirectWrite/FontFace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ public FontFile[] GetFiles()
/// <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 DataStream tableData, out IntPtr tableContext)
public bool TryGetFontTable(int openTypeTableTag, out DataPointer tableData, out IntPtr tableContext)
{
unsafe
{
tableData = null;
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 DataStream(tableDataPtr, tableDataSize, true, true);
tableData = new DataPointer(tableDataPtr, tableDataSize);
return exists;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/SharpDX.Direct2D1/DirectWrite/FontFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public SharpDX.DirectWrite.FontFileLoader Loader
/// </summary>
/// <returns>the reference to the reference key of a font file. </returns>
/// <unmanaged>HRESULT IDWriteFontFile::GetReferenceKey([Out, Buffer] const void** fontFileReferenceKey,[Out] int* fontFileReferenceKeySize)</unmanaged>
public DataStream GetReferenceKey()
public DataPointer GetReferenceKey()
{
unsafe
{
int keySize;
IntPtr keyPtr;
GetReferenceKey(new IntPtr(&keyPtr), out keySize);
return new DataStream(keyPtr, keySize, true, true);
return new DataPointer(keyPtr, keySize);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SharpDX.Direct2D1/DirectWrite/FontFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public partial interface FontFileLoader
/// <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>
SharpDX.DirectWrite.FontFileStream CreateStreamFromKey(DataStream fontFileReferenceKey);
SharpDX.DirectWrite.FontFileStream CreateStreamFromKey(DataPointer fontFileReferenceKey);
}
}
4 changes: 2 additions & 2 deletions Source/SharpDX.Direct2D1/DirectWrite/FontFileLoaderNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public partial class FontFileLoaderNative
/// <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(DataStream fontFileReferenceKey)
public FontFileStream CreateStreamFromKey(DataPointer fontFileReferenceKey)
{
FontFileStream temp;
CreateStreamFromKey_(fontFileReferenceKey.PositionPointer, (int)fontFileReferenceKey.RemainingLength, out temp);
CreateStreamFromKey_(fontFileReferenceKey.Pointer, fontFileReferenceKey.Size, out temp);
return temp;
}
}
Expand Down
9 changes: 4 additions & 5 deletions Source/SharpDX.Direct2D1/DirectWrite/FontFileLoaderShadow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ public FontFileLoaderVtbl() : base(1)

/// <unmanaged>HRESULT IDWriteFontFileLoader::CreateStreamFromKey([In, Buffer] const void* fontFileReferenceKey,[None] int fontFileReferenceKeySize,[Out] IDWriteFontFileStream** fontFileStream)</unmanaged>
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
private delegate int CreateStreamFromKeyDelegate(
IntPtr thisPtr, IntPtr fontFileReferenceKey, int fontFileReferenceKeySize, out IntPtr fontFileStream);
private static int CreateStreamFromKeyImpl(
IntPtr thisPtr, IntPtr fontFileReferenceKey, int fontFileReferenceKeySize, out IntPtr fontFileStreamPtr)
private delegate int CreateStreamFromKeyDelegate(IntPtr thisPtr, IntPtr fontFileReferenceKey, int fontFileReferenceKeySize, out IntPtr fontFileStream);

private static int CreateStreamFromKeyImpl(IntPtr thisPtr, IntPtr fontFileReferenceKey, int fontFileReferenceKeySize, out IntPtr fontFileStreamPtr)
{
fontFileStreamPtr = IntPtr.Zero;
try
{
var shadow = ToShadow<FontFileLoaderShadow>(thisPtr);
var callback = (FontFileLoader)shadow.Callback;
var fontFileStream = callback.CreateStreamFromKey(new DataStream(fontFileReferenceKey, fontFileReferenceKeySize, true, true));
var fontFileStream = callback.CreateStreamFromKey(new DataPointer(fontFileReferenceKey, fontFileReferenceKeySize));
fontFileStreamPtr = FontFileStreamShadow.ToIntPtr(fontFileStream);
}
catch (Exception exception)
Expand Down
6 changes: 3 additions & 3 deletions Source/SharpDX.Direct2D1/WIC/ColorContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public ColorContext(ImagingFactory factory)
/// <summary>
/// Initializes from memory.
/// </summary>
/// <param name="dataStream">The data stream.</param>
/// <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(DataStream dataStream)
public void InitializeFromMemory(DataPointer dataPointer)
{
InitializeFromMemory(dataStream.PositionPointer, (int) (dataStream.Length - dataStream.Position));
InitializeFromMemory(dataPointer.Pointer, dataPointer.Size);
}

/// <summary>
Expand Down

0 comments on commit 372b7fd

Please sign in to comment.