-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f3767
commit aa4f2ff
Showing
18 changed files
with
567 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace SkiaSharp; | ||
|
||
public unsafe class SKBlender : SKObject, ISKReferenceCounted | ||
{ | ||
private static readonly Dictionary<SKBlendMode, SKBlender> blendModeBlenders; | ||
|
||
static SKBlender () | ||
{ | ||
// TODO: This is not the best way to do this as it will create a lot of objects that | ||
// might not be needed, but it is the only way to ensure that the static | ||
// instances are created before any access is made to them. | ||
// See more info: SKObject.EnsureStaticInstanceAreInitialized() | ||
|
||
var modes = Enum.GetValues (typeof (SKBlendMode)); | ||
blendModeBlenders = new Dictionary<SKBlendMode, SKBlender> (modes.Length); | ||
foreach (SKBlendMode mode in modes) | ||
{ | ||
blendModeBlenders [mode] = new SKBlenderStatic (SkiaApi.sk_blender_new_mode (mode)); | ||
} | ||
} | ||
|
||
internal static void EnsureStaticInstanceAreInitialized () | ||
{ | ||
// IMPORTANT: do not remove to ensure that the static instances | ||
// are initialized before any access is made to them | ||
} | ||
|
||
internal SKBlender(IntPtr handle, bool owns) | ||
: base (handle, owns) | ||
{ | ||
} | ||
|
||
protected override void Dispose (bool disposing) => | ||
base.Dispose (disposing); | ||
|
||
public static SKBlender CreateBlendMode (SKBlendMode mode) | ||
{ | ||
if (!blendModeBlenders.TryGetValue (mode, out var value)) | ||
throw new ArgumentOutOfRangeException (nameof (mode)); | ||
return value; | ||
} | ||
|
||
public static SKBlender CreateArithmetic (float k1, float k2, float k3, float k4, bool enforcePMColor) => | ||
GetObject (SkiaApi.sk_blender_new_arithmetic (k1, k2, k3, k4, enforcePMColor)); | ||
|
||
internal static SKBlender GetObject (IntPtr handle) => | ||
GetOrAddObject (handle, (h, o) => new SKBlender (h, o)); | ||
|
||
// | ||
|
||
private sealed class SKBlenderStatic : SKBlender | ||
{ | ||
internal SKBlenderStatic (IntPtr x) | ||
: base (x, false) | ||
{ | ||
} | ||
|
||
protected override void Dispose (bool disposing) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.