Skip to content

Commit 4a32821

Browse files
authored
Merge pull request #652 from mono/development
Development
2 parents 9bfa766 + 61a067f commit 4a32821

File tree

366 files changed

+16605
-1213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

366 files changed

+16605
-1213
lines changed

binding/Binding/Definitions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ public enum SKCodecResult {
1919
Unimplemented,
2020
}
2121

22+
[Obsolete ("Use SKEncodedOrigin instead.")]
23+
public enum SKCodecOrigin {
24+
TopLeft = 1,
25+
TopRight = 2,
26+
BottomRight = 3,
27+
BottomLeft = 4,
28+
LeftTop = 5,
29+
RightTop = 6,
30+
RightBottom = 7,
31+
LeftBottom = 8,
32+
}
33+
2234
public enum SKEncodedOrigin {
2335
TopLeft = 1,
2436
TopRight = 2,

binding/Binding/GRBackendRenderTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public GRBackendRenderTarget (GRBackend backend, GRBackendRenderTargetDesc desc)
1818
case GRBackend.Metal:
1919
throw new NotSupportedException ();
2020
case GRBackend.OpenGL:
21-
var glInfo = new GRGlFramebufferInfo ((uint)desc.RenderTargetHandle, desc.Config.ToSizedFormat ());
21+
var glInfo = new GRGlFramebufferInfo ((uint)desc.RenderTargetHandle, desc.Config.ToGlSizedFormat ());
2222
CreateGl (desc.Width, desc.Height, desc.SampleCount, desc.StencilBits, glInfo);
2323
break;
2424
case GRBackend.Vulkan:

binding/Binding/GRBackendTexture.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public GRBackendTexture (GRGlBackendTextureDesc desc)
1717
{
1818
var handle = desc.TextureHandle;
1919
if (handle.Format == 0) {
20-
handle.Format = desc.Config.ToSizedFormat ();
20+
handle.Format = desc.Config.ToGlSizedFormat ();
2121
}
2222
CreateGl (desc.Width, desc.Height, false, handle);
2323
}
@@ -29,7 +29,7 @@ public GRBackendTexture (GRBackendTextureDesc desc)
2929
var handlePtr = desc.TextureHandle;
3030
var oldHandle = PtrToStructure<GRTextureInfoObsolete> (handlePtr);
3131

32-
var handle = new GRGlTextureInfo (oldHandle.fTarget, oldHandle.fID, desc.Config.ToSizedFormat ());
32+
var handle = new GRGlTextureInfo (oldHandle.fTarget, oldHandle.fID, desc.Config.ToGlSizedFormat ());
3333
CreateGl (desc.Width, desc.Height, false, handle);
3434
}
3535

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

6668
public GRGlTextureInfo GetGlTextureInfo ()
6769
{

binding/Binding/GRDefinitions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public struct GRGlBackendTextureDesc
197197

198198
public static partial class SkiaExtensions
199199
{
200-
public static uint ToSizedFormat (this SKColorType colorType)
200+
public static uint ToGlSizedFormat (this SKColorType colorType)
201201
{
202202
switch (colorType) {
203203
case SKColorType.Unknown:
@@ -227,7 +227,7 @@ public static uint ToSizedFormat (this SKColorType colorType)
227227
}
228228
}
229229

230-
public static uint ToSizedFormat (this GRPixelConfig config)
230+
public static uint ToGlSizedFormat (this GRPixelConfig config)
231231
{
232232
switch (config) {
233233
case GRPixelConfig.Alpha8:

binding/Binding/SKCodec.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace SkiaSharp
55
{
66
// TODO: `Create(...)` should have overloads that accept a SKPngChunkReader
77
// TODO: missing the `QueryYuv8` and `GetYuv8Planes` members
8-
// TODO: might be useful to wrap `GetFrameInfo` (single result)
98

109
public class SKCodec : SKObject
1110
{
@@ -36,7 +35,10 @@ public SKImageInfo Info {
3635
}
3736
}
3837

39-
public SKEncodedOrigin Origin {
38+
[Obsolete ("Use EncodedOrigin instead.")]
39+
public SKCodecOrigin Origin => (SKCodecOrigin)EncodedOrigin;
40+
41+
public SKEncodedOrigin EncodedOrigin {
4042
get { return SkiaApi.sk_codec_get_origin (Handle); }
4143
}
4244

@@ -123,8 +125,9 @@ public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, int rowBytes, S
123125
fPriorFrame = options.PriorFrame,
124126
fPremulBehavior = options.PremulBehavior,
125127
};
128+
var subset = default(SKRectI);
126129
if (options.HasSubset) {
127-
var subset = options.Subset.Value;
130+
subset = options.Subset.Value;
128131
nOptions.fSubset = &subset;
129132
}
130133
return SkiaApi.sk_codec_get_pixels (Handle, ref nInfo, pixels, (IntPtr)rowBytes, ref nOptions);
@@ -198,8 +201,9 @@ public SKCodecResult StartIncrementalDecode (SKImageInfo info, IntPtr pixels, in
198201
fPriorFrame = options.PriorFrame,
199202
fPremulBehavior = options.PremulBehavior,
200203
};
204+
var subset = default (SKRectI);
201205
if (options.HasSubset) {
202-
var subset = options.Subset.Value;
206+
subset = options.Subset.Value;
203207
nOptions.fSubset = &subset;
204208
}
205209

@@ -247,8 +251,9 @@ public SKCodecResult StartScanlineDecode (SKImageInfo info, SKCodecOptions optio
247251
fPriorFrame = options.PriorFrame,
248252
fPremulBehavior = options.PremulBehavior,
249253
};
254+
var subset = default (SKRectI);
250255
if (options.HasSubset) {
251-
var subset = options.Subset.Value;
256+
subset = options.Subset.Value;
252257
nOptions.fSubset = &subset;
253258
}
254259

binding/Binding/SKFontManager.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35

46
namespace SkiaSharp
57
{
@@ -24,6 +26,15 @@ protected override void Dispose (bool disposing)
2426

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

29+
public IEnumerable<string> FontFamilies {
30+
get {
31+
var count = FontFamilyCount;
32+
for (var i = 0; i < count; i++) {
33+
yield return GetFamilyName (i);
34+
}
35+
}
36+
}
37+
2738
public string GetFamilyName (int index)
2839
{
2940
using (var str = new SKString ()) {
@@ -32,22 +43,14 @@ public string GetFamilyName (int index)
3243
}
3344
}
3445

35-
public string[] GetFontFamilies ()
36-
{
37-
var count = FontFamilyCount;
38-
var families = new string[count];
39-
for (int i = 0; i < count; i++) {
40-
families[i] = GetFamilyName (i);
41-
}
42-
return families;
43-
}
46+
public string[] GetFontFamilies () => FontFamilies.ToArray ();
4447

45-
public SKFontStyleSet CreateStyleSet (int index)
48+
public SKFontStyleSet GetFontStyles (int index)
4649
{
4750
return GetObject<SKFontStyleSet> (SkiaApi.sk_fontmgr_create_styleset (Handle, index));
4851
}
4952

50-
public SKFontStyleSet MatchFamily (string familyName)
53+
public SKFontStyleSet GetFontStyles (string familyName)
5154
{
5255
return GetObject<SKFontStyleSet> (SkiaApi.sk_fontmgr_match_family (Handle, familyName));
5356
}
@@ -60,7 +63,6 @@ public SKTypeface MatchFamily (string familyName, SKFontStyle style)
6063
return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_family_style (Handle, familyName, style.Handle));
6164
}
6265

63-
[Obsolete]
6466
public SKTypeface MatchTypeface (SKTypeface face, SKFontStyle style)
6567
{
6668
if (face == null)
@@ -71,7 +73,7 @@ public SKTypeface MatchTypeface (SKTypeface face, SKFontStyle style)
7173
return GetObject<SKTypeface> (SkiaApi.sk_fontmgr_match_face_style (Handle, face.Handle, style.Handle));
7274
}
7375

74-
public SKTypeface FromFile (string path, int index = 0)
76+
public SKTypeface CreateTypeface (string path, int index = 0)
7577
{
7678
if (path == null)
7779
throw new ArgumentNullException (nameof (path));
@@ -80,12 +82,12 @@ public SKTypeface FromFile (string path, int index = 0)
8082
if (stream == null) {
8183
return null;
8284
} else {
83-
return FromStream (stream, index);
85+
return CreateTypeface (stream, index);
8486
}
8587
}
8688
}
8789

88-
public SKTypeface FromStream (Stream stream, int index = 0)
90+
public SKTypeface CreateTypeface (Stream stream, int index = 0)
8991
{
9092
if (stream == null)
9193
throw new ArgumentNullException (nameof (stream));
@@ -103,10 +105,10 @@ public SKTypeface FromStream (Stream stream, int index = 0)
103105
fontStream = null;
104106
}
105107

106-
return FromStream (new SKManagedStream (stream, true), index);
108+
return CreateTypeface (new SKManagedStream (stream, true), index);
107109
}
108110

109-
public SKTypeface FromStream (SKStreamAsset stream, int index = 0)
111+
public SKTypeface CreateTypeface (SKStreamAsset stream, int index = 0)
110112
{
111113
if (stream == null)
112114
throw new ArgumentNullException (nameof (stream));
@@ -116,7 +118,7 @@ public SKTypeface FromStream (SKStreamAsset stream, int index = 0)
116118
return typeface;
117119
}
118120

119-
public SKTypeface FromData (SKData data, int index = 0)
121+
public SKTypeface CreateTypeface (SKData data, int index = 0)
120122
{
121123
if (data == null)
122124
throw new ArgumentNullException (nameof (data));

binding/Binding/SKFontStyleSet.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
24

35
namespace SkiaSharp
46
{
5-
public class SKFontStyleSet : SKObject
7+
public class SKFontStyleSet : SKObject, IEnumerable<SKFontStyle>, IReadOnlyCollection<SKFontStyle>, IReadOnlyList<SKFontStyle>
68
{
79
[Preserve]
810
internal SKFontStyleSet (IntPtr handle, bool owns)
@@ -26,12 +28,13 @@ protected override void Dispose (bool disposing)
2628

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

29-
public void GetStyle(int index, out SKFontStyle fontStyle, out string styleName)
31+
public SKFontStyle this[int index] => GetStyle (index);
32+
33+
public string GetStyleName (int index)
3034
{
31-
fontStyle = new SKFontStyle ();
3235
using (var str = new SKString ()) {
33-
SkiaApi.sk_fontstyleset_get_style (Handle, index, fontStyle.Handle, str.Handle);
34-
styleName = (string)str;
36+
SkiaApi.sk_fontstyleset_get_style (Handle, index, IntPtr.Zero, str.Handle);
37+
return (string)str;
3538
}
3639
}
3740

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

5154
return GetObject<SKTypeface> (SkiaApi.sk_fontstyleset_match_style (Handle, style.Handle));
5255
}
56+
57+
public IEnumerator<SKFontStyle> GetEnumerator () => GetStyles ().GetEnumerator ();
58+
59+
IEnumerator IEnumerable.GetEnumerator () => GetStyles ().GetEnumerator ();
60+
61+
private IEnumerable<SKFontStyle> GetStyles ()
62+
{
63+
var count = Count;
64+
for (var i = 0; i < count; i++) {
65+
yield return GetStyle (i);
66+
}
67+
}
68+
69+
private SKFontStyle GetStyle (int index)
70+
{
71+
var fontStyle = new SKFontStyle ();
72+
SkiaApi.sk_fontstyleset_get_style (Handle, index, fontStyle.Handle, IntPtr.Zero);
73+
return fontStyle;
74+
}
5375
}
5476
}

binding/Binding/SKImage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public SKData Encode ()
356356
return GetObject<SKData> (SkiaApi.sk_image_encode (Handle));
357357
}
358358

359+
[Obsolete]
359360
public SKData Encode (SKPixelSerializer serializer)
360361
{
361362
if (serializer == null)

binding/Binding/SKPath.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ public static int ConvertConicToQuads (SKPoint p0, SKPoint p1, SKPoint p2, float
527527

528528
public class Iterator : SKNativeObject
529529
{
530-
SKPath Path => path;
531-
SKPath path;
530+
private readonly SKPath path;
532531

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

563562
public class RawIterator : SKNativeObject
564563
{
565-
SKPath Path => path;
566-
SKPath path;
564+
private readonly SKPath path;
567565

568566
internal RawIterator (SKPath path)
569567
: base (SkiaApi.sk_path_create_rawiter (path.Handle))

binding/Binding/SKPixelSerializer.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
namespace SkiaSharp
44
{
5-
public abstract class SKPixelSerializer : IDisposable
5+
[Obsolete]
6+
public abstract class SKPixelSerializer : SKObject
67
{
8+
protected SKPixelSerializer ()
9+
: base (IntPtr.Zero, false)
10+
{
11+
}
12+
713
public bool UseEncodedData (IntPtr data, ulong length)
814
{
915
if (SKObject.SizeOf<IntPtr> () == 4 && length > UInt32.MaxValue)
@@ -33,16 +39,9 @@ public static SKPixelSerializer Create (Func<IntPtr, IntPtr, bool> onUseEncodedD
3339
{
3440
return new SKSimplePixelSerializer (onUseEncodedData, onEncode);
3541
}
36-
37-
public void Dispose ()
38-
{
39-
}
40-
41-
protected virtual void Dispose (bool disposing)
42-
{
43-
}
4442
}
4543

44+
[Obsolete]
4645
internal class SKSimplePixelSerializer : SKPixelSerializer
4746
{
4847
private readonly Func<IntPtr, IntPtr, bool> onUseEncodedData;
@@ -65,7 +64,7 @@ protected override bool OnUseEncodedData (IntPtr data, IntPtr length)
6564
}
6665
}
6766

68-
[Obsolete ("Use SKPixelSerializer instead.")]
67+
[Obsolete]
6968
public abstract class SKManagedPixelSerializer : SKPixelSerializer
7069
{
7170
public SKManagedPixelSerializer()

binding/Binding/SKTypeface.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ protected override void Dispose (bool disposing)
3030
base.Dispose (disposing);
3131
}
3232

33+
public static SKTypeface Default => GetObject<SKTypeface> (SkiaApi.sk_typeface_ref_default ());
34+
35+
public static SKTypeface CreateDefault ()
36+
{
37+
return GetObject<SKTypeface> (SkiaApi.sk_typeface_create_default ());
38+
}
39+
3340
[Obsolete ("Use FromFamilyName(string, SKFontStyleWeight, SKFontStyleWidth, SKFontStyleSlant) instead.")]
3441
public static SKTypeface FromFamilyName (string familyName, SKTypefaceStyle style)
3542
{

binding/Binding/SkiaApi.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ internal static class SkiaApi
977977

978978
// typeface
979979
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
980+
public extern static sk_typeface_t sk_typeface_create_default();
981+
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
982+
public extern static sk_typeface_t sk_typeface_ref_default();
983+
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
980984
public extern static sk_typeface_t sk_typeface_create_from_name_with_font_style([MarshalAs(UnmanagedType.LPStr)] string familyName, sk_fontstyle_t style);
981985
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
982986
public extern static sk_typeface_t sk_typeface_create_from_file([MarshalAs(UnmanagedType.LPStr)] string path, int index);

0 commit comments

Comments
 (0)