Skip to content

Commit c1e169e

Browse files
authored
Split SkiaSharp package into smaller "Native Asset" packages (mono#1758)
1 parent 491aa08 commit c1e169e

16 files changed

+720
-280
lines changed

VERSIONS.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ SkiaSharp.NativeAssets.Linux nuget 2.88.0
5757
SkiaSharp.NativeAssets.Linux.NoDependencies nuget 2.88.0
5858
SkiaSharp.NativeAssets.NanoServer nuget 2.88.0
5959
SkiaSharp.NativeAssets.WebAssembly nuget 2.88.0
60+
SkiaSharp.NativeAssets.Android nuget 2.88.0
61+
SkiaSharp.NativeAssets.iOS nuget 2.88.0
62+
SkiaSharp.NativeAssets.MacCatalyst nuget 2.88.0
63+
SkiaSharp.NativeAssets.macOS nuget 2.88.0
64+
SkiaSharp.NativeAssets.Tizen nuget 2.88.0
65+
SkiaSharp.NativeAssets.tvOS nuget 2.88.0
66+
SkiaSharp.NativeAssets.UWP nuget 2.88.0
67+
SkiaSharp.NativeAssets.watchOS nuget 2.88.0
68+
SkiaSharp.NativeAssets.Win32 nuget 2.88.0
6069
SkiaSharp.Views nuget 2.88.0
6170
SkiaSharp.Views.Desktop.Common nuget 2.88.0
6271
SkiaSharp.Views.Gtk2 nuget 2.88.0

build.cake

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ var TRACKED_NUGETS = new Dictionary<string, Version> {
6666
{ "SkiaSharp.NativeAssets.Linux.NoDependencies", new Version (1, 57, 0) },
6767
{ "SkiaSharp.NativeAssets.NanoServer", new Version (1, 57, 0) },
6868
{ "SkiaSharp.NativeAssets.WebAssembly", new Version (1, 57, 0) },
69+
{ "SkiaSharp.NativeAssets.Android", new Version (1, 57, 0) },
70+
{ "SkiaSharp.NativeAssets.iOS", new Version (1, 57, 0) },
71+
{ "SkiaSharp.NativeAssets.MacCatalyst", new Version (1, 57, 0) },
72+
{ "SkiaSharp.NativeAssets.macOS", new Version (1, 57, 0) },
73+
{ "SkiaSharp.NativeAssets.Tizen", new Version (1, 57, 0) },
74+
{ "SkiaSharp.NativeAssets.tvOS", new Version (1, 57, 0) },
75+
{ "SkiaSharp.NativeAssets.UWP", new Version (1, 57, 0) },
76+
{ "SkiaSharp.NativeAssets.watchOS", new Version (1, 57, 0) },
77+
{ "SkiaSharp.NativeAssets.Win32", new Version (1, 57, 0) },
6978
{ "SkiaSharp.Views", new Version (1, 57, 0) },
7079
{ "SkiaSharp.Views.Desktop.Common", new Version (1, 57, 0) },
7180
{ "SkiaSharp.Views.Gtk2", new Version (1, 57, 0) },
@@ -379,8 +388,8 @@ Task ("samples-generate")
379388
{
380389
EnsureDirectoryExists ("./output/");
381390

382-
// create the workbooks archive
383-
Zip ("./workbooks", "./output/workbooks.zip");
391+
// create the interactive archive
392+
Zip ("./interactive", "./output/interactive.zip");
384393

385394
// create the samples archive
386395
CreateSamplesDirectory ("./samples/", "./output/samples/");

interactive/Gradients.dib

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!markdown
2+
3+
# Gradients
4+
5+
SkiaSharp has may features that allow us to create any image we may want. One such feature is gradients. There are a few gradient types:
6+
7+
- linear
8+
- radial
9+
- sweep
10+
- two-point conical
11+
12+
In this example, are are going to use a linear gradient as a background to a ball created with a two-point conical gradient.
13+
14+
The first thing we need to do is intsall the package:
15+
16+
#!csharp
17+
18+
#i https://aka.ms/skiasharp-eap/index.json
19+
#r nuget:SkiaSharp,*-*
20+
21+
#!markdown
22+
23+
After installing the `SkiaSharp` NuGet package, we can now add the typical `using` statements:
24+
25+
#!csharp
26+
27+
using SkiaSharp;
28+
29+
#!markdown
30+
31+
Now, we can start coding. Here we create a simple 256x256 canvas and clear off any contents:
32+
33+
#!csharp
34+
35+
var info = new SKImageInfo(256, 256);
36+
var surface = SKSurface.Create(info);
37+
38+
var canvas = surface.Canvas;
39+
canvas.Clear();
40+
41+
#!markdown
42+
43+
To make things easier, we are just going to use two colors (black and white) for both the background and the ball:
44+
45+
#!csharp
46+
47+
var lightColor = SKColors.White;
48+
var darkColor = SKColors.Black;
49+
50+
var colors = new[] { lightColor, darkColor };
51+
52+
colors
53+
54+
#!markdown
55+
56+
The first gradient we are going to make is for the background. This is a linear gradient and has 3 main pieces of information:
57+
58+
- start & end points
59+
- colors
60+
- clamp mode
61+
62+
For a linear gradient, the points represent the coordinates of the line that will form the direction of the gradient. Since we want the full image, we can use a line down the side of the canvas. It doesn't really matter where along the x-axis we put the line since it goes on for infinity:
63+
64+
#!csharp
65+
66+
var backgroundShader = SKShader.CreateLinearGradient(
67+
start: new SKPoint(0, 0),
68+
end: new SKPoint(0, info.Height),
69+
colors: colors,
70+
mode: SKShaderTileMode.Clamp);
71+
72+
#!markdown
73+
74+
To draw this shader, we create a new `SKPaint` instance and set the `Shader` property to the shadr we just created. And then we draw it:
75+
76+
#!csharp
77+
78+
var backgroundPaint = new SKPaint
79+
{
80+
IsAntialias = true,
81+
Shader = backgroundShader,
82+
};
83+
84+
canvas.DrawPaint(backgroundPaint);
85+
86+
surface
87+
88+
#!markdown
89+
90+
That is looking very nice!
91+
92+
The next thing we need to do is draw the ball. Like the background, we need to use a shader. This shader now has more information:
93+
94+
- start & end points
95+
- start & end radii
96+
- colors
97+
- clamp mode
98+
99+
The gradient we are going to draw is similar to a radial gradient, but instead we want to control the start and end circles as well as those circles being offset a bit. This will allows us to create an image that looks 3D but is not at all:
100+
101+
#!csharp
102+
103+
var ballShader = SKShader.CreateTwoPointConicalGradient(
104+
start: new SKPoint(115.2f, 102.4f),
105+
startRadius: 20.0f,
106+
end: new SKPoint(102.4f, 102.4f),
107+
endRadius: 128.0f,
108+
colors: new[] { lightColor, darkColor },
109+
mode: SKShaderTileMode.Clamp);
110+
111+
#!markdown
112+
113+
Again like the background, we create a paint object and draw that. However, to give the illusion that it is a 3D ball, we are going to draw the shader inside a circle. This will effectively clip the gradient to a circle shape giving the edges to the ball:
114+
115+
#!csharp
116+
117+
var ballPaint = new SKPaint
118+
{
119+
IsAntialias = true,
120+
Shader = ballShader,
121+
};
122+
123+
canvas.DrawOval(new SKRect(51.2f, 51.2f, 204.8f, 204.8f), ballPaint);
124+
125+
surface
126+
127+
#!markdown
128+
129+
All done. The image is rendered and we have a gray ball floating in space.
Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,45 @@
1-
---
2-
id: 21aa1668-c9a4-480b-ab86-9f7655776547
3-
title: SkiaSharp
4-
uti: com.xamarin.workbook
5-
platforms:
6-
- DotNetCore
7-
packages:
8-
- id: SkiaSharp
9-
version: 1.60.2
10-
---
11-
12-
# SkiaSharp Workbook
1+
#!markdown
2+
3+
# SkiaSharp
134

145
Welcome to SkiaSharp, the most awesome, cross-platform 2D-graphics engine. It is powered by the same engine that powers Android and Chrome.
156

16-
After installing the `SkiaSharp` NuGet package, we must make sure that the references have been added:
7+
The first thing we need to do is intsall the package:
8+
9+
#!csharp
10+
11+
#i https://aka.ms/skiasharp-eap/index.json
12+
#r nuget:SkiaSharp,2.80.*-*
1713

18-
```csharp
19-
#r "SkiaSharp"
20-
```
14+
#!markdown
2115

22-
That being done, we can now add the typical `using` statements:
16+
After installing the `SkiaSharp` NuGet package, we can now add the typical `using` statements:
17+
18+
#!csharp
2319

24-
```csharp
2520
using SkiaSharp;
26-
```
21+
22+
#!markdown
2723

2824
Now, we can start coding. Here we create a simple 256x256 canvas:
2925

30-
```csharp
26+
#!csharp
27+
3128
// create the bitmap that will hold the pixels
3229
var bitmap = new SKBitmap(256, 256);
3330

34-
// create the canvas so that we can draw on thet bitmap
31+
// create the canvas so that we can draw on that bitmap
3532
var canvas = new SKCanvas(bitmap);
3633

3734
// clear the canvas, so that it is fresh
3835
canvas.Clear(SKColors.Transparent);
3936

40-
// appear in Workbooks
41-
bitmap
42-
```
37+
#!markdown
4338

4439
Before we can draw anything, we need to create the object that will be used to describe how the thing we are drawing will look. To do this, we need a `SKPaint` object:
4540

46-
```csharp
41+
#!csharp
42+
4743
var paint = new SKPaint {
4844
IsAntialias = true, // smooth text
4945
TextSize = 50, // 50px high text
@@ -52,21 +48,24 @@ var paint = new SKPaint {
5248
Style = SKPaintStyle.Fill, // solid text
5349
Typeface = SKTypeface.FromFamilyName("Trebuchet") // use the Trebuchet typeface
5450
};
55-
```
51+
52+
#!markdown
5653

5754
Now that our canvas is all ready, we can start drawing. Here we are writing the word “SkiaSharp” in the middle:
5855

59-
```csharp
56+
#!csharp
57+
6058
// clear the canvas, just in case we are running this a second time
6159
canvas.Clear(SKColors.Transparent);
6260

6361
// draw the text using the paint
6462
canvas.DrawText("SkiaSharp", 128, 128 + (paint.TextSize / 2), paint);
6563

66-
// appear in Workbooks
64+
// appear in VS Code
6765
bitmap
68-
```
66+
67+
#!markdown
6968

7069
That’s it! So simple! And, best of all, this code can be used ANYWHERE!
7170

72-
Check out the code on GitHub: [https://github.com/mono/SkiaSharp](https://github.com/mono/SkiaSharp "mono/SkiaSharp").
71+
Check out the code on GitHub: [https://github.com/mono/SkiaSharp](https://github.com/mono/SkiaSharp "mono/SkiaSharp").
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
5+
<!-- package -->
6+
<id>SkiaSharp.NativeAssets.Android</id>
7+
<title>SkiaSharp - Native Assets for Android</title>
8+
<version>1.0.0</version>
9+
<description>
10+
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library.
11+
It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
12+
</description>
13+
<summary>
14+
SkiaSharp is a cross-platform 2D graphics API for .NET platforms that can be used across mobile, server and desktop models to render images.
15+
</summary>
16+
<releaseNotes>
17+
Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release notes.
18+
</releaseNotes>
19+
<projectUrl>https://go.microsoft.com/fwlink/?linkid=868515</projectUrl>
20+
<iconUrl>https://go.microsoft.com/fwlink/?linkid=2130524</iconUrl>
21+
<tags>xamarin graphics ios android linux windows uwp tvos watchos macos tizen cross-platform skiasharp</tags>
22+
23+
<!-- legal -->
24+
<licenseUrl>https://go.microsoft.com/fwlink/?linkid=868514</licenseUrl>
25+
<authors>Microsoft</authors>
26+
<owners>Microsoft</owners>
27+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
28+
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
29+
30+
<dependencies>
31+
<group targetFramework="monoandroid1.0">
32+
</group>
33+
<group targetFramework="net6.0-android30.0">
34+
</group>
35+
</dependencies>
36+
37+
</metadata>
38+
<files>
39+
40+
<!-- the build bits -->
41+
<file src="build/monoandroid1.0/SkiaSharp.targets" target="build/monoandroid1.0/SkiaSharp.NativeAssets.Android.targets" />
42+
<file src="build/monoandroid1.0/SkiaSharp.targets" target="buildTransitive/monoandroid1.0/SkiaSharp.NativeAssets.Android.targets" />
43+
<file src="build/net6.0-android/SkiaSharp.targets" target="build/net6.0-android30.0/SkiaSharp.NativeAssets.Android.targets" />
44+
<file src="build/net6.0-android/SkiaSharp.targets" target="buildTransitive/net6.0-android30.0/SkiaSharp.NativeAssets.Android.targets" />
45+
46+
<!-- libSkiaSharp.dll and other native files -->
47+
<file platform="macos,windows" src="runtimes/android-x64/native/libSkiaSharp.so" />
48+
<file platform="macos,windows" src="runtimes/android-x86/native/libSkiaSharp.so" />
49+
<file platform="macos,windows" src="runtimes/android-arm/native/libSkiaSharp.so" />
50+
<file platform="macos,windows" src="runtimes/android-arm64/native/libSkiaSharp.so" />
51+
52+
<!-- placeholders -->
53+
<file src="_._" target="lib/monoandroid1.0/_._" />
54+
<file src="_._" target="lib/net6.0-android30.0/_._" />
55+
56+
<!-- legal -->
57+
<file src="LICENSE.txt" />
58+
<file src="THIRD-PARTY-NOTICES.txt" />
59+
60+
</files>
61+
</package>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package>
3+
<metadata>
4+
5+
<!-- package -->
6+
<id>SkiaSharp.NativeAssets.MacCatalyst</id>
7+
<title>SkiaSharp - Native Assets for Mac Catalyst</title>
8+
<version>1.0.0</version>
9+
<description>
10+
SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library.
11+
It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
12+
</description>
13+
<summary>
14+
SkiaSharp is a cross-platform 2D graphics API for .NET platforms that can be used across mobile, server and desktop models to render images.
15+
</summary>
16+
<releaseNotes>
17+
Please visit https://go.microsoft.com/fwlink/?linkid=868517 to view the release notes.
18+
</releaseNotes>
19+
<projectUrl>https://go.microsoft.com/fwlink/?linkid=868515</projectUrl>
20+
<iconUrl>https://go.microsoft.com/fwlink/?linkid=2130524</iconUrl>
21+
<tags>xamarin graphics ios android linux windows uwp tvos watchos macos tizen cross-platform skiasharp</tags>
22+
23+
<!-- legal -->
24+
<licenseUrl>https://go.microsoft.com/fwlink/?linkid=868514</licenseUrl>
25+
<authors>Microsoft</authors>
26+
<owners>Microsoft</owners>
27+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
28+
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
29+
30+
<dependencies>
31+
<group targetFramework="net6.0-maccatalyst13.5">
32+
</group>
33+
</dependencies>
34+
35+
</metadata>
36+
<files>
37+
38+
<!-- the build bits -->
39+
<!-- <file src="build/net6.0-macos/SkiaSharp.targets" target="build/net6.0-macos10.15/SkiaSharp.NativeAssets.macOS.targets" /> -->
40+
<!-- <file src="build/net6.0-macos/SkiaSharp.targets" target="buildTransitive/net6.0-macos10.15/SkiaSharp.NativeAssets.macOS.targets" /> -->
41+
42+
<!-- libSkiaSharp.dll and other native files -->
43+
<!-- <file platform="macos" src="runtimes/maccatalyst/native/libSkiaSharp.framework/**/*" target="runtimes/maccatalyst/native/libSkiaSharp.framework" /> -->
44+
45+
<!-- placeholders -->
46+
<file src="_._" target="lib/net6.0-maccatalyst13.5/_._" />
47+
48+
<!-- legal -->
49+
<file src="LICENSE.txt" />
50+
<file src="THIRD-PARTY-NOTICES.txt" />
51+
52+
</files>
53+
</package>

0 commit comments

Comments
 (0)