Skip to content

Commit

Permalink
Merge pull request #652 from mono/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
mattleibow authored Oct 15, 2018
2 parents 9bfa766 + 61a067f commit 4a32821
Show file tree
Hide file tree
Showing 366 changed files with 16,605 additions and 1,213 deletions.
12 changes: 12 additions & 0 deletions binding/Binding/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public enum SKCodecResult {
Unimplemented,
}

[Obsolete ("Use SKEncodedOrigin instead.")]
public enum SKCodecOrigin {
TopLeft = 1,
TopRight = 2,
BottomRight = 3,
BottomLeft = 4,
LeftTop = 5,
RightTop = 6,
RightBottom = 7,
LeftBottom = 8,
}

public enum SKEncodedOrigin {
TopLeft = 1,
TopRight = 2,
Expand Down
2 changes: 1 addition & 1 deletion binding/Binding/GRBackendRenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public GRBackendRenderTarget (GRBackend backend, GRBackendRenderTargetDesc desc)
case GRBackend.Metal:
throw new NotSupportedException ();
case GRBackend.OpenGL:
var glInfo = new GRGlFramebufferInfo ((uint)desc.RenderTargetHandle, desc.Config.ToSizedFormat ());
var glInfo = new GRGlFramebufferInfo ((uint)desc.RenderTargetHandle, desc.Config.ToGlSizedFormat ());
CreateGl (desc.Width, desc.Height, desc.SampleCount, desc.StencilBits, glInfo);
break;
case GRBackend.Vulkan:
Expand Down
6 changes: 4 additions & 2 deletions binding/Binding/GRBackendTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public GRBackendTexture (GRGlBackendTextureDesc desc)
{
var handle = desc.TextureHandle;
if (handle.Format == 0) {
handle.Format = desc.Config.ToSizedFormat ();
handle.Format = desc.Config.ToGlSizedFormat ();
}
CreateGl (desc.Width, desc.Height, false, handle);
}
Expand All @@ -29,7 +29,7 @@ public GRBackendTexture (GRBackendTextureDesc desc)
var handlePtr = desc.TextureHandle;
var oldHandle = PtrToStructure<GRTextureInfoObsolete> (handlePtr);

var handle = new GRGlTextureInfo (oldHandle.fTarget, oldHandle.fID, desc.Config.ToSizedFormat ());
var handle = new GRGlTextureInfo (oldHandle.fTarget, oldHandle.fID, desc.Config.ToGlSizedFormat ());
CreateGl (desc.Width, desc.Height, false, handle);
}

Expand Down Expand Up @@ -62,6 +62,8 @@ protected override void Dispose (bool disposing)
public int Height => SkiaApi.gr_backendtexture_get_height (Handle);
public bool HasMipMaps => SkiaApi.gr_backendtexture_has_mipmaps (Handle);
public GRBackend Backend => SkiaApi.gr_backendtexture_get_backend (Handle);
public SKSizeI Size => new SKSizeI (Width, Height);
public SKRectI Rect => new SKRectI (0, 0, Width, Height);

public GRGlTextureInfo GetGlTextureInfo ()
{
Expand Down
4 changes: 2 additions & 2 deletions binding/Binding/GRDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public struct GRGlBackendTextureDesc

public static partial class SkiaExtensions
{
public static uint ToSizedFormat (this SKColorType colorType)
public static uint ToGlSizedFormat (this SKColorType colorType)
{
switch (colorType) {
case SKColorType.Unknown:
Expand Down Expand Up @@ -227,7 +227,7 @@ public static uint ToSizedFormat (this SKColorType colorType)
}
}

public static uint ToSizedFormat (this GRPixelConfig config)
public static uint ToGlSizedFormat (this GRPixelConfig config)
{
switch (config) {
case GRPixelConfig.Alpha8:
Expand Down
15 changes: 10 additions & 5 deletions binding/Binding/SKCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace SkiaSharp
{
// TODO: `Create(...)` should have overloads that accept a SKPngChunkReader
// TODO: missing the `QueryYuv8` and `GetYuv8Planes` members
// TODO: might be useful to wrap `GetFrameInfo` (single result)

public class SKCodec : SKObject
{
Expand Down Expand Up @@ -36,7 +35,10 @@ public SKImageInfo Info {
}
}

public SKEncodedOrigin Origin {
[Obsolete ("Use EncodedOrigin instead.")]
public SKCodecOrigin Origin => (SKCodecOrigin)EncodedOrigin;

public SKEncodedOrigin EncodedOrigin {
get { return SkiaApi.sk_codec_get_origin (Handle); }
}

Expand Down Expand Up @@ -123,8 +125,9 @@ public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, int rowBytes, S
fPriorFrame = options.PriorFrame,
fPremulBehavior = options.PremulBehavior,
};
var subset = default(SKRectI);
if (options.HasSubset) {
var subset = options.Subset.Value;
subset = options.Subset.Value;
nOptions.fSubset = &subset;
}
return SkiaApi.sk_codec_get_pixels (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
Expand Down Expand Up @@ -198,8 +201,9 @@ public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, in
fPriorFrame = options.PriorFrame,
fPremulBehavior = options.PremulBehavior,
};
var subset = default (SKRectI);
if (options.HasSubset) {
var subset = options.Subset.Value;
subset = options.Subset.Value;
nOptions.fSubset = &subset;
}

Expand Down Expand Up @@ -247,8 +251,9 @@ public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions optio
fPriorFrame = options.PriorFrame,
fPremulBehavior = options.PremulBehavior,
};
var subset = default (SKRectI);
if (options.HasSubset) {
var subset = options.Subset.Value;
subset = options.Subset.Value;
nOptions.fSubset = &subset;
}

Expand Down
38 changes: 20 additions & 18 deletions binding/Binding/SKFontManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace SkiaSharp
{
Expand All @@ -24,6 +26,15 @@ protected override void Dispose (bool disposing)

public int FontFamilyCount => SkiaApi.sk_fontmgr_count_families (Handle);

public IEnumerable<string> FontFamilies {
get {
var count = FontFamilyCount;
for (var i = 0; i < count; i++) {
yield return GetFamilyName (i);
}
}
}

public string GetFamilyName (int index)
{
using (var str = new SKString ()) {
Expand All @@ -32,22 +43,14 @@ public string GetFamilyName (int index)
}
}

public string[] GetFontFamilies ()
{
var count = FontFamilyCount;
var families = new string[count];
for (int i = 0; i < count; i++) {
families[i] = GetFamilyName (i);
}
return families;
}
public string[] GetFontFamilies () => FontFamilies.ToArray ();

public SKFontStyleSet CreateStyleSet (int index)
public SKFontStyleSet GetFontStyles (int index)
{
return GetObject<SKFontStyleSet> (SkiaApi.sk_fontmgr_create_styleset (Handle, index));
}

public SKFontStyleSet MatchFamily (string familyName)
public SKFontStyleSet GetFontStyles (string familyName)
{
return GetObject<SKFontStyleSet> (SkiaApi.sk_fontmgr_match_family (Handle, familyName));
}
Expand All @@ -60,7 +63,6 @@ public SKTypeface MatchFamily (string familyName, SKFontStyle style)
return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_family_style (Handle, familyName, style.Handle));
}

[Obsolete]
public SKTypeface MatchTypeface (SKTypeface face, SKFontStyle style)
{
if (face == null)
Expand All @@ -71,7 +73,7 @@ public SKTypeface MatchTypeface (SKTypeface face, SKFontStyle style)
return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_face_style (Handle, face.Handle, style.Handle));
}

public SKTypeface FromFile (string path, int index = 0)
public SKTypeface CreateTypeface (string path, int index = 0)
{
if (path == null)
throw new ArgumentNullException (nameof (path));
Expand All @@ -80,12 +82,12 @@ public SKTypeface FromFile (string path, int index = 0)
if (stream == null) {
return null;
} else {
return FromStream (stream, index);
return CreateTypeface (stream, index);
}
}
}

public SKTypeface FromStream (Stream stream, int index = 0)
public SKTypeface CreateTypeface (Stream stream, int index = 0)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
Expand All @@ -103,10 +105,10 @@ public SKTypeface FromStream (Stream stream, int index = 0)
fontStream = null;
}

return FromStream (new SKManagedStream (stream, true), index);
return CreateTypeface (new SKManagedStream (stream, true), index);
}

public SKTypeface FromStream (SKStreamAsset stream, int index = 0)
public SKTypeface CreateTypeface (SKStreamAsset stream, int index = 0)
{
if (stream == null)
throw new ArgumentNullException (nameof (stream));
Expand All @@ -116,7 +118,7 @@ public SKTypeface FromStream (SKStreamAsset stream, int index = 0)
return typeface;
}

public SKTypeface FromData (SKData data, int index = 0)
public SKTypeface CreateTypeface (SKData data, int index = 0)
{
if (data == null)
throw new ArgumentNullException (nameof (data));
Expand Down
32 changes: 27 additions & 5 deletions binding/Binding/SKFontStyleSet.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace SkiaSharp
{
public class SKFontStyleSet : SKObject
public class SKFontStyleSet : SKObject, IEnumerable<SKFontStyle>, IReadOnlyCollection<SKFontStyle>, IReadOnlyList<SKFontStyle>
{
[Preserve]
internal SKFontStyleSet (IntPtr handle, bool owns)
Expand All @@ -26,12 +28,13 @@ protected override void Dispose (bool disposing)

public int Count => SkiaApi.sk_fontstyleset_get_count (Handle);

public void GetStyle(int index, out SKFontStyle fontStyle, out string styleName)
public SKFontStyle this[int index] => GetStyle (index);

public string GetStyleName (int index)
{
fontStyle = new SKFontStyle ();
using (var str = new SKString ()) {
SkiaApi.sk_fontstyleset_get_style (Handle, index, fontStyle.Handle, str.Handle);
styleName = (string)str;
SkiaApi.sk_fontstyleset_get_style (Handle, index, IntPtr.Zero, str.Handle);
return (string)str;
}
}

Expand All @@ -50,5 +53,24 @@ public SKTypeface CreateTypeface (SKFontStyle style)

return GetObject<SKTypeface> (SkiaApi.sk_fontstyleset_match_style (Handle, style.Handle));
}

public IEnumerator<SKFontStyle> GetEnumerator () => GetStyles ().GetEnumerator ();

IEnumerator IEnumerable.GetEnumerator () => GetStyles ().GetEnumerator ();

private IEnumerable<SKFontStyle> GetStyles ()
{
var count = Count;
for (var i = 0; i < count; i++) {
yield return GetStyle (i);
}
}

private SKFontStyle GetStyle (int index)
{
var fontStyle = new SKFontStyle ();
SkiaApi.sk_fontstyleset_get_style (Handle, index, fontStyle.Handle, IntPtr.Zero);
return fontStyle;
}
}
}
1 change: 1 addition & 0 deletions binding/Binding/SKImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public SKData Encode ()
return GetObject<SKData> (SkiaApi.sk_image_encode (Handle));
}

[Obsolete]
public SKData Encode (SKPixelSerializer serializer)
{
if (serializer == null)
Expand Down
6 changes: 2 additions & 4 deletions binding/Binding/SKPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,7 @@ public static int ConvertConicToQuads (SKPoint p0, SKPoint p1, SKPoint p2, float

public class Iterator : SKNativeObject
{
SKPath Path => path;
SKPath path;
private readonly SKPath path;

internal Iterator (SKPath path, bool forceClose)
: base (SkiaApi.sk_path_create_iter (path.Handle, forceClose ? 1 : 0))
Expand Down Expand Up @@ -562,8 +561,7 @@ public SKPathVerb Next (SKPoint [] points, bool doConsumeDegenerates = true, boo

public class RawIterator : SKNativeObject
{
SKPath Path => path;
SKPath path;
private readonly SKPath path;

internal RawIterator (SKPath path)
: base (SkiaApi.sk_path_create_rawiter (path.Handle))
Expand Down
19 changes: 9 additions & 10 deletions binding/Binding/SKPixelSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace SkiaSharp
{
public abstract class SKPixelSerializer : IDisposable
[Obsolete]
public abstract class SKPixelSerializer : SKObject
{
protected SKPixelSerializer ()
: base (IntPtr.Zero, false)
{
}

public bool UseEncodedData (IntPtr data, ulong length)
{
if (SKObject.SizeOf<IntPtr> () == 4 && length > UInt32.MaxValue)
Expand Down Expand Up @@ -33,16 +39,9 @@ public static SKPixelSerializer Create (Func<IntPtr, IntPtr, bool> onUseEncodedD
{
return new SKSimplePixelSerializer (onUseEncodedData, onEncode);
}

public void Dispose ()
{
}

protected virtual void Dispose (bool disposing)
{
}
}

[Obsolete]
internal class SKSimplePixelSerializer : SKPixelSerializer
{
private readonly Func<IntPtr, IntPtr, bool> onUseEncodedData;
Expand All @@ -65,7 +64,7 @@ protected override bool OnUseEncodedData (IntPtr data, IntPtr length)
}
}

[Obsolete ("Use SKPixelSerializer instead.")]
[Obsolete]
public abstract class SKManagedPixelSerializer : SKPixelSerializer
{
public SKManagedPixelSerializer()
Expand Down
7 changes: 7 additions & 0 deletions binding/Binding/SKTypeface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ protected override void Dispose (bool disposing)
base.Dispose (disposing);
}

public static SKTypeface Default => GetObject<SKTypeface> (SkiaApi.sk_typeface_ref_default ());

public static SKTypeface CreateDefault ()
{
return GetObject<SKTypeface> (SkiaApi.sk_typeface_create_default ());
}

[Obsolete ("Use FromFamilyName(string, SKFontStyleWeight, SKFontStyleWidth, SKFontStyleSlant) instead.")]
public static SKTypeface FromFamilyName (string familyName, SKTypefaceStyle style)
{
Expand Down
4 changes: 4 additions & 0 deletions binding/Binding/SkiaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ internal static class SkiaApi

// typeface
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_typeface_t sk_typeface_create_default();
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_typeface_t sk_typeface_ref_default();
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_typeface_t sk_typeface_create_from_name_with_font_style([MarshalAs(UnmanagedType.LPStr)] string familyName, sk_fontstyle_t style);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static sk_typeface_t sk_typeface_create_from_file([MarshalAs(UnmanagedType.LPStr)] string path, int index);
Expand Down
Loading

0 comments on commit 4a32821

Please sign in to comment.