Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Feb 5, 2021
2 parents 24f4bb5 + bb8ae10 commit 3d79f41
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Changed:
**PR Checklist**

- [ ] Has tests (if omitted, state reason in description)
- [ ] Rebased on top of master at time of PR
- [ ] Rebased on top of main at time of PR
- [ ] Changes adhere to coding standard
- [ ] Updated documentation
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![SkiaSharp](https://img.shields.io/nuget/vpre/SkiaSharp.svg?maxAge=2592000&label=SkiaSharp%20nuget)](https://www.nuget.org/packages/SkiaSharp) [![SkiaSharp.Views](https://img.shields.io/nuget/vpre/SkiaSharp.Views.svg?maxAge=2592000&label=SkiaSharp.Views%20nuget)](https://www.nuget.org/packages/SkiaSharp.Views) [![SkiaSharp.Views.Forms](https://img.shields.io/nuget/vpre/SkiaSharp.Views.Forms.svg?maxAge=2592000&label=SkiaSharp.Views.Forms%20nuget)](https://www.nuget.org/packages/SkiaSharp.Views.Forms) [![HarfBuzzSharp](https://img.shields.io/nuget/vpre/HarfBuzzSharp.svg?maxAge=2592000&label=HarfBuzzSharp%20nuget)](https://www.nuget.org/packages/HarfBuzzSharp) [![SkiaSharp.Views.Uno](https://img.shields.io/nuget/vpre/SkiaSharp.Views.Uno.svg?maxAge=2592000&label=SkiaSharp.Views.Uno%20nuget)](https://www.nuget.org/packages/SkiaSharp.Views.Uno)
[![chat](https://img.shields.io/badge/chat-xamarin%2FXamarinComponents-E60256.svg)](https://gitter.im/xamarin/XamarinComponents) [![SkiaSharp API Docs](https://img.shields.io/badge/docs-skiasharp-1faece.svg)](https://docs.microsoft.com/dotnet/api/SkiaSharp) [![HarfBuzzSharp API Docs](https://img.shields.io/badge/docs-harfbuzzsharp-1faece.svg)](https://docs.microsoft.com/dotnet/api/SkiaSharp) [![SkiaSharp Guides](https://img.shields.io/badge/docs-guides-1faece.svg)](https://docs.microsoft.com/xamarin/graphics-games/skiasharp/)
[![Build Status](https://dev.azure.com/devdiv/DevDiv/_apis/build/status/Xamarin/Components/SkiaSharp?branchName=master)](https://dev.azure.com/devdiv/DevDiv/_build/latest?definitionId=10789&branchName=master) [![Build Status](https://dev.azure.com/xamarin/public/_apis/build/status/mono/SkiaSharp/SkiaSharp%20(Public)?branchName=master)](https://dev.azure.com/xamarin/public/_build/latest?definitionId=4&branchName=master)
[![Build Status](https://dev.azure.com/devdiv/DevDiv/_apis/build/status/Xamarin/Components/SkiaSharp?branchName=main)](https://dev.azure.com/devdiv/DevDiv/_build/latest?definitionId=10789&branchName=main) [![Build Status](https://dev.azure.com/xamarin/public/_apis/build/status/mono/SkiaSharp/SkiaSharp%20(Public)?branchName=main)](https://dev.azure.com/xamarin/public/_build/latest?definitionId=4&branchName=main)

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's
Skia Graphics Library ([skia.org](https://skia.org/)). It provides a comprehensive 2D API that can
Expand Down
2 changes: 1 addition & 1 deletion binding/Binding.Shared/HashCode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Partial code copied from:
// https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/HashCode.cs
// https://github.com/dotnet/runtime/blob/6072e4d3a7a2a1493f514cdf4be75a3d56580e84/src/libraries/System.Private.CoreLib/src/System/HashCode.cs

using System;
using System.Runtime.CompilerServices;
Expand Down
43 changes: 37 additions & 6 deletions binding/Binding/GRContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,64 @@ public static GRContext Create (GRBackend backend, IntPtr backendContext) =>
// CreateGl

public static GRContext CreateGl () =>
CreateGl (null);
CreateGl (null, null);

public static GRContext CreateGl (GRGlInterface backendContext) =>
GetObject (SkiaApi.gr_direct_context_make_gl (backendContext == null ? IntPtr.Zero : backendContext.Handle));
CreateGl (backendContext, null);

public static GRContext CreateGl (GRContextOptions options) =>
CreateGl (null, options);

public static GRContext CreateGl (GRGlInterface backendContext, GRContextOptions options)
{
var ctx = backendContext == null ? IntPtr.Zero : backendContext.Handle;

if (options == null) {
return GetObject (SkiaApi.gr_direct_context_make_gl (ctx));
} else {
var opts = options.ToNative ();
return GetObject (SkiaApi.gr_direct_context_make_gl_with_options (ctx, &opts));
}
}

// CreateVulkan

public static GRContext CreateVulkan (GRVkBackendContext backendContext)
public static GRContext CreateVulkan (GRVkBackendContext backendContext) =>
CreateVulkan (backendContext, null);

public static GRContext CreateVulkan (GRVkBackendContext backendContext, GRContextOptions options)
{
if (backendContext == null)
throw new ArgumentNullException (nameof (backendContext));

return GetObject (SkiaApi.gr_direct_context_make_vulkan (backendContext.ToNative ()));
if (options == null) {
return GetObject (SkiaApi.gr_direct_context_make_vulkan (backendContext.ToNative ()));
} else {
var opts = options.ToNative ();
return GetObject (SkiaApi.gr_direct_context_make_vulkan_with_options (backendContext.ToNative (), &opts));
}
}

#if __IOS__ || __MACOS__

// CreateMetal

public static GRContext CreateMetal (Metal.IMTLDevice device, Metal.IMTLCommandQueue queue)
public static GRContext CreateMetal (Metal.IMTLDevice device, Metal.IMTLCommandQueue queue) =>
CreateMetal (device, queue, null);

public static GRContext CreateMetal (Metal.IMTLDevice device, Metal.IMTLCommandQueue queue, GRContextOptions options)
{
if (device == null)
throw new ArgumentNullException (nameof (device));
if (queue == null)
throw new ArgumentNullException (nameof (queue));

return GetObject (SkiaApi.gr_direct_context_make_metal ((void*)device.Handle, (void*)queue.Handle));
if (options == null) {
return GetObject (SkiaApi.gr_direct_context_make_metal ((void*)device.Handle, (void*)queue.Handle));
} else {
var opts = options.ToNative ();
return GetObject (SkiaApi.gr_direct_context_make_metal_with_options ((void*)device.Handle, (void*)queue.Handle, &opts));
}
}

#endif
Expand Down
29 changes: 29 additions & 0 deletions binding/Binding/GRContextOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;

namespace SkiaSharp
{
public unsafe class GRContextOptions
{
public bool AvoidStencilBuffers { get; set; } = false;

public int RuntimeProgramCacheSize { get; set; } = 256;

public int GlyphCacheTextureMaximumBytes { get; set; } = 2048 * 1024 * 4;

public bool AllowPathMaskCaching { get; set; } = true;

public bool DoManualMipmapping { get; set; } = false;

public int BufferMapThreshold { get; set; } = -1;

internal GRContextOptionsNative ToNative () =>
new GRContextOptionsNative {
fAllowPathMaskCaching = AllowPathMaskCaching ? (byte)1 : (byte)0,
fAvoidStencilBuffers = AvoidStencilBuffers ? (byte)1 : (byte)0,
fBufferMapThreshold = BufferMapThreshold,
fDoManualMipmapping = DoManualMipmapping ? (byte)1 : (byte)0,
fGlyphCacheTextureMaximumBytes = (IntPtr)GlyphCacheTextureMaximumBytes,
fRuntimeProgramCacheSize = RuntimeProgramCacheSize,
};
}
}
89 changes: 89 additions & 0 deletions binding/Binding/SkiaApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,20 @@ internal static gr_direct_context_t gr_direct_context_make_gl (gr_glinterface_t
(gr_direct_context_make_gl_delegate ??= GetSymbol<Delegates.gr_direct_context_make_gl> ("gr_direct_context_make_gl")).Invoke (glInterface);
#endif

// gr_direct_context_t* gr_direct_context_make_gl_with_options(const gr_glinterface_t* glInterface, const gr_context_options_t* options)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern gr_direct_context_t gr_direct_context_make_gl_with_options (gr_glinterface_t glInterface, GRContextOptionsNative* options);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate gr_direct_context_t gr_direct_context_make_gl_with_options (gr_glinterface_t glInterface, GRContextOptionsNative* options);
}
private static Delegates.gr_direct_context_make_gl_with_options gr_direct_context_make_gl_with_options_delegate;
internal static gr_direct_context_t gr_direct_context_make_gl_with_options (gr_glinterface_t glInterface, GRContextOptionsNative* options) =>
(gr_direct_context_make_gl_with_options_delegate ??= GetSymbol<Delegates.gr_direct_context_make_gl_with_options> ("gr_direct_context_make_gl_with_options")).Invoke (glInterface, options);
#endif

// gr_direct_context_t* gr_direct_context_make_metal(void* device, void* queue)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -538,6 +552,20 @@ internal static gr_direct_context_t gr_direct_context_make_metal (void* device,
(gr_direct_context_make_metal_delegate ??= GetSymbol<Delegates.gr_direct_context_make_metal> ("gr_direct_context_make_metal")).Invoke (device, queue);
#endif

// gr_direct_context_t* gr_direct_context_make_metal_with_options(void* device, void* queue, const gr_context_options_t* options)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern gr_direct_context_t gr_direct_context_make_metal_with_options (void* device, void* queue, GRContextOptionsNative* options);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate gr_direct_context_t gr_direct_context_make_metal_with_options (void* device, void* queue, GRContextOptionsNative* options);
}
private static Delegates.gr_direct_context_make_metal_with_options gr_direct_context_make_metal_with_options_delegate;
internal static gr_direct_context_t gr_direct_context_make_metal_with_options (void* device, void* queue, GRContextOptionsNative* options) =>
(gr_direct_context_make_metal_with_options_delegate ??= GetSymbol<Delegates.gr_direct_context_make_metal_with_options> ("gr_direct_context_make_metal_with_options")).Invoke (device, queue, options);
#endif

// gr_direct_context_t* gr_direct_context_make_vulkan(const gr_vk_backendcontext_t vkBackendContext)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -552,6 +580,20 @@ internal static gr_direct_context_t gr_direct_context_make_vulkan (GRVkBackendCo
(gr_direct_context_make_vulkan_delegate ??= GetSymbol<Delegates.gr_direct_context_make_vulkan> ("gr_direct_context_make_vulkan")).Invoke (vkBackendContext);
#endif

// gr_direct_context_t* gr_direct_context_make_vulkan_with_options(const gr_vk_backendcontext_t vkBackendContext, const gr_context_options_t* options)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
internal static extern gr_direct_context_t gr_direct_context_make_vulkan_with_options (GRVkBackendContextNative vkBackendContext, GRContextOptionsNative* options);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
internal delegate gr_direct_context_t gr_direct_context_make_vulkan_with_options (GRVkBackendContextNative vkBackendContext, GRContextOptionsNative* options);
}
private static Delegates.gr_direct_context_make_vulkan_with_options gr_direct_context_make_vulkan_with_options_delegate;
internal static gr_direct_context_t gr_direct_context_make_vulkan_with_options (GRVkBackendContextNative vkBackendContext, GRContextOptionsNative* options) =>
(gr_direct_context_make_vulkan_with_options_delegate ??= GetSymbol<Delegates.gr_direct_context_make_vulkan_with_options> ("gr_direct_context_make_vulkan_with_options")).Invoke (vkBackendContext, options);
#endif

// void gr_direct_context_perform_deferred_cleanup(gr_direct_context_t* context, long long ms)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -13337,6 +13379,53 @@ internal static void sk_managedtracememorydump_set_procs (SKManagedTraceMemoryDu

#region Structs

// gr_context_options_t
[StructLayout (LayoutKind.Sequential)]
internal unsafe partial struct GRContextOptionsNative : IEquatable<GRContextOptionsNative> {
// public bool fAvoidStencilBuffers
public Byte fAvoidStencilBuffers;

// public int fRuntimeProgramCacheSize
public Int32 fRuntimeProgramCacheSize;

// public size_t fGlyphCacheTextureMaximumBytes
public /* size_t */ IntPtr fGlyphCacheTextureMaximumBytes;

// public bool fAllowPathMaskCaching
public Byte fAllowPathMaskCaching;

// public bool fDoManualMipmapping
public Byte fDoManualMipmapping;

// public int fBufferMapThreshold
public Int32 fBufferMapThreshold;

public readonly bool Equals (GRContextOptionsNative obj) =>
fAvoidStencilBuffers == obj.fAvoidStencilBuffers && fRuntimeProgramCacheSize == obj.fRuntimeProgramCacheSize && fGlyphCacheTextureMaximumBytes == obj.fGlyphCacheTextureMaximumBytes && fAllowPathMaskCaching == obj.fAllowPathMaskCaching && fDoManualMipmapping == obj.fDoManualMipmapping && fBufferMapThreshold == obj.fBufferMapThreshold;

public readonly override bool Equals (object obj) =>
obj is GRContextOptionsNative f && Equals (f);

public static bool operator == (GRContextOptionsNative left, GRContextOptionsNative right) =>
left.Equals (right);

public static bool operator != (GRContextOptionsNative left, GRContextOptionsNative right) =>
!left.Equals (right);

public readonly override int GetHashCode ()
{
var hash = new HashCode ();
hash.Add (fAvoidStencilBuffers);
hash.Add (fRuntimeProgramCacheSize);
hash.Add (fGlyphCacheTextureMaximumBytes);
hash.Add (fAllowPathMaskCaching);
hash.Add (fDoManualMipmapping);
hash.Add (fBufferMapThreshold);
return hash.ToHashCode ();
}

}

// gr_gl_framebufferinfo_t
[StructLayout (LayoutKind.Sequential)]
public unsafe partial struct GRGlFramebufferInfo : IEquatable<GRGlFramebufferInfo> {
Expand Down
4 changes: 4 additions & 0 deletions binding/libSkiaSharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
"cs": "GRMetalTextureInfoNative",
"internal": true
},
"gr_context_options_t": {
"cs": "GRContextOptionsNative",
"internal": true
},
"sk_color4f_t": {
"cs": "SKColorF",
"readonly": true,
Expand Down
2 changes: 1 addition & 1 deletion cake/UtilsManaged.cake
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ string GetDownloadUrl(string id)
else if (!string.IsNullOrEmpty (GIT_BRANCH_NAME))
version += "branch." + GIT_BRANCH_NAME.Replace ("/", ".").ToLower ();
else
version += "branch.master";
version += "branch.main";

return string.Format (PREVIEW_FEED_URL, id.ToLower(), version);
}
2 changes: 1 addition & 1 deletion externals/skia
8 changes: 4 additions & 4 deletions scripts/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
trigger:
- master
- main
- develop
- patch/*
- refs/tags/*

pr:
- master
- main
- develop
- patch/*

Expand Down Expand Up @@ -684,7 +684,7 @@ stages:
parameters:
name: native_checks_windows
displayName: Run Code Checks
condition: and(always(), eq('refs/heads/master', variables['Build.SourceBranch']))
condition: and(always(), eq('refs/heads/main', variables['Build.SourceBranch']))
vmImage: $(VM_IMAGE_WINDOWS_PREVIOUS)
target: git-sync-deps
installWindowsSdk: false
Expand Down Expand Up @@ -731,7 +731,7 @@ stages:
tsaVersion: 'TsaV2'
codebase: 'NewOrUpdate'
tsaEnvironment: 'PROD'
codeBaseName: 'SkiaSharp_master'
codeBaseName: 'SkiaSharp_main'
notificationAlias: 'xamacomd@microsoft.com'
notifyAlwaysV2: false
instanceUrlForTsaV2: 'DEVDIV'
Expand Down
2 changes: 1 addition & 1 deletion source/SkiaSharp.Views/SkiaSharp.Views.WPF/SKElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void OnRender(DrawingContext drawingContext)
if (designMode)
return;

if (Visibility != Visibility.Visible)
if (Visibility != Visibility.Visible || PresentationSource.FromVisual(this) == null)
return;

var size = CreateSize(out var scaleX, out var scaleY);
Expand Down
30 changes: 30 additions & 0 deletions tests/Tests/GRContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ public void CreateDefaultContextIsValid()
}
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void CreateDefaultContextWithOptionsIsValid()
{
using var ctx = CreateGlContext();
ctx.MakeCurrent();

var options = new GRContextOptions();
var grContext = GRContext.CreateGl(options);

Assert.NotNull(grContext);
}

[Obsolete]
[SkippableFact]
public void ToGlSizedFormat()
Expand Down Expand Up @@ -51,6 +64,23 @@ public void CreateSpecificContextIsValid()
}
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void CreateSpecificContextWithOptionsIsValid()
{
using var ctx = CreateGlContext();
ctx.MakeCurrent();

var glInterface = GRGlInterface.Create();

Assert.True(glInterface.Validate());

var options = new GRContextOptions();
var grContext = GRContext.CreateGl(glInterface, options);

Assert.NotNull(grContext);
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void GpuSurfaceIsCreated()
Expand Down
25 changes: 25 additions & 0 deletions tests/VulkanTests/GRContextTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,30 @@ public void CreateVkContextIsValid()

Assert.NotNull(grContext);
}

[Trait(CategoryKey, GpuCategory)]
[SkippableFact]
public void CreateVkContextWithOptionsIsValid()
{
using var ctx = CreateVkContext();

using var grVkBackendContext = new GRVkBackendContext
{
VkInstance = (IntPtr)ctx.Instance.RawHandle.ToUInt64(),
VkPhysicalDevice = (IntPtr)ctx.PhysicalDevice.RawHandle.ToUInt64(),
VkDevice = (IntPtr)ctx.Device.RawHandle.ToUInt64(),
VkQueue = (IntPtr)ctx.GraphicsQueue.RawHandle.ToUInt64(),
GraphicsQueueIndex = ctx.GraphicsFamily,
GetProcedureAddress = ctx.GetProc
};

Assert.NotNull(grVkBackendContext);

var options = new GRContextOptions();

using var grContext = GRContext.CreateVulkan(grVkBackendContext, options);

Assert.NotNull(grContext);
}
}
}

0 comments on commit 3d79f41

Please sign in to comment.