Added the initial mac forms source

This commit is contained in:
Matthew Leibowitz 2017-04-23 15:28:32 -04:00
Родитель a94b9474c4
Коммит 302dae5b0a
12 изменённых файлов: 261 добавлений и 0 удалений

Просмотреть файл

@ -171,6 +171,7 @@ Task ("libs")
CopyFileToDirectory ("./source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms/bin/Release/SkiaSharp.Views.Forms.dll", "./output/portable/");
CopyFileToDirectory ("./source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.Android/bin/Release/SkiaSharp.Views.Forms.dll", "./output/android/");
CopyFileToDirectory ("./source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.iOS/bin/Release/SkiaSharp.Views.Forms.dll", "./output/ios/");
CopyFileToDirectory ("./source/SkiaSharp.Views.Forms/SkiaSharp.Views.Forms.Mac/bin/Release/SkiaSharp.Views.Forms.dll", "./output/osx/");
// copy SVG
CopyFileToDirectory ("./source/SkiaSharp.Svg/SkiaSharp.Svg/bin/Release/SkiaSharp.Svg.dll", "./output/portable/");

Просмотреть файл

@ -27,11 +27,17 @@
<dependency id="SkiaSharp" version="1.57.1" />
<dependency id="SkiaSharp.Views" version="1.57.1" />
</group>
<group targetFramework="XamarinMac">
<dependency id="Xamarin.Forms" version="2.3.5.233-pre1" />
<dependency id="SkiaSharp" version="1.57.1" />
<dependency id="SkiaSharp.Views" version="1.57.1" />
</group>
</dependencies>
</metadata>
<files>
<file src="output/portable/SkiaSharp.Views.Forms.dll" target="lib/portable-net45+win8+wpa81+wp8" />
<file src="output/android/SkiaSharp.Views.Forms.dll" target="lib/MonoAndroid" />
<file src="output/ios/SkiaSharp.Views.Forms.dll" target="lib/XamariniOS" />
<file src="output/osx/SkiaSharp.Views.Forms.dll" target="lib/XamarinMac" />
</files>
</package>

Просмотреть файл

@ -27,6 +27,11 @@
<dependency id="SkiaSharp" version="1.57.1" />
<dependency id="SkiaSharp.Views" version="1.57.1" />
</group>
<group targetFramework="XamarinMac">
<dependency id="Xamarin.Forms" version="2.3.5.233-pre1" />
<dependency id="SkiaSharp" version="1.57.1" />
<dependency id="SkiaSharp.Views" version="1.57.1" />
</group>
<group targetFramework="uap10.0">
<dependency id="Xamarin.Forms" version="2.3.0" />
<dependency id="SkiaSharp" version="1.57.1" />
@ -38,6 +43,7 @@
<file src="output/portable/SkiaSharp.Views.Forms.dll" target="lib/portable-net45+win8+wpa81+wp8" />
<file src="output/android/SkiaSharp.Views.Forms.dll" target="lib/MonoAndroid" />
<file src="output/ios/SkiaSharp.Views.Forms.dll" target="lib/XamariniOS" />
<file src="output/osx/SkiaSharp.Views.Forms.dll" target="lib/XamarinMac" />
<file src="output/uwp/SkiaSharp.Views.Forms.dll" target="lib/uap10.0" />
</files>
</package>

Просмотреть файл

@ -0,0 +1,18 @@
using Xamarin.Forms;
using SKFormsView = SkiaSharp.Views.Forms.SKCanvasView;
using SKNativeView = SkiaSharp.Views.Mac.SKCanvasView;
[assembly: ExportRenderer(typeof(SKFormsView), typeof(SkiaSharp.Views.Forms.SKCanvasViewRenderer))]
namespace SkiaSharp.Views.Forms
{
public class SKCanvasViewRenderer : SKCanvasViewRendererBase<SKFormsView, SKNativeView>
{
protected override SKNativeView CreateNativeControl()
{
var view = base.CreateNativeControl();
return view;
}
}
}

Просмотреть файл

@ -0,0 +1,68 @@
using CoreVideo;
using Foundation;
using Xamarin.Forms;
using SKFormsView = SkiaSharp.Views.Forms.SKGLView;
using SKNativeView = SkiaSharp.Views.Mac.SKGLView;
[assembly: ExportRenderer(typeof(SKFormsView), typeof(SkiaSharp.Views.Forms.SKGLViewRenderer))]
namespace SkiaSharp.Views.Forms
{
public class SKGLViewRenderer : SKGLViewRendererBase<SKFormsView, SKNativeView>
{
private CVDisplayLink displayLink;
protected override SKNativeView CreateNativeControl()
{
var view = base.CreateNativeControl();
return view;
}
protected override void Dispose(bool disposing)
{
// stop the render loop
if (displayLink != null)
{
displayLink.Stop();
displayLink.Dispose();
displayLink = null;
}
base.Dispose(disposing);
}
protected override void SetupRenderLoop(bool oneShot)
{
// only start if we haven't already
if (displayLink != null)
return;
// bail out if we are requesting something that the view doesn't want to
if (!oneShot && !Element.HasRenderLoop)
return;
// create the loop
displayLink = new CVDisplayLink();
displayLink.SetOutputCallback(delegate
{
var formsView = Control;
var nativeView = Element;
// redraw the view
formsView?.Display();
// stop the render loop if this was a one-shot, or the views are disposed
if (formsView == null || nativeView == null || !nativeView.HasRenderLoop)
{
displayLink.Stop();
displayLink.Dispose();
displayLink = null;
}
return CVReturn.Success;
});
displayLink.Start();
}
}
}

Просмотреть файл

@ -0,0 +1,49 @@
using System.Threading;
using System.Threading.Tasks;
using AppKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.MacOS;
using SkiaSharp.Views.Mac;
[assembly: ExportImageSourceHandler(typeof(SkiaSharp.Views.Forms.SKImageImageSource), typeof(SkiaSharp.Views.Forms.SKImageSourceHandler))]
[assembly: ExportImageSourceHandler(typeof(SkiaSharp.Views.Forms.SKBitmapImageSource), typeof(SkiaSharp.Views.Forms.SKImageSourceHandler))]
[assembly: ExportImageSourceHandler(typeof(SkiaSharp.Views.Forms.SKPixmapImageSource), typeof(SkiaSharp.Views.Forms.SKImageSourceHandler))]
[assembly: ExportImageSourceHandler(typeof(SkiaSharp.Views.Forms.SKPictureImageSource), typeof(SkiaSharp.Views.Forms.SKImageSourceHandler))]
namespace SkiaSharp.Views.Forms
{
public sealed class SKImageSourceHandler : IImageSourceHandler
{
public Task<NSImage> LoadImageAsync(ImageSource imagesource, CancellationToken cancelationToken = default(CancellationToken), float scale = 1f)
{
NSImage image = null;
var imageImageSource = imagesource as SKImageImageSource;
if (imageImageSource != null)
{
image = imageImageSource.Image?.ToNSImage();
}
var bitmapImageSource = imagesource as SKBitmapImageSource;
if (bitmapImageSource != null)
{
image = bitmapImageSource.Bitmap?.ToNSImage();
}
var pixmapImageSource = imagesource as SKPixmapImageSource;
if (pixmapImageSource != null)
{
image = pixmapImageSource.Pixmap?.ToNSImage();
}
var pictureImageSource = imagesource as SKPictureImageSource;
if (pictureImageSource != null)
{
image = pictureImageSource.Picture?.ToNSImage(pictureImageSource.Dimensions);
}
return Task.FromResult(image);
}
}
}

Просмотреть файл

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}</ProjectGuid>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>SkiaSharp.Views.Forms</RootNamespace>
<AssemblyName>SkiaSharp.Views.Forms</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;__MACOS__</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CreatePackage>false</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>false</IncludeMonoRuntime>
<LinkMode>None</LinkMode>
<XamMacArch></XamMacArch>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<DefineConstants>__MACOS__</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnableCodeSigning>false</EnableCodeSigning>
<CreatePackage>false</CreatePackage>
<EnablePackageSigning>false</EnablePackageSigning>
<IncludeMonoRuntime>false</IncludeMonoRuntime>
<LinkMode>None</LinkMode>
<XamMacArch></XamMacArch>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
<Reference Include="Xamarin.Forms.Core">
<HintPath>..\..\packages\Xamarin.Forms.2.3.5.233-pre1\lib\Xamarin.Mac\Xamarin.Forms.Core.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform">
<HintPath>..\..\packages\Xamarin.Forms.2.3.5.233-pre1\lib\Xamarin.Mac\Xamarin.Forms.Platform.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Platform.macOS">
<HintPath>..\..\packages\Xamarin.Forms.2.3.5.233-pre1\lib\Xamarin.Mac\Xamarin.Forms.Platform.macOS.dll</HintPath>
</Reference>
<Reference Include="Xamarin.Forms.Xaml">
<HintPath>..\..\packages\Xamarin.Forms.2.3.5.233-pre1\lib\Xamarin.Mac\Xamarin.Forms.Xaml.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="SKCanvasViewRenderer.cs" />
<Compile Include="SKGLViewRenderer.cs" />
<Compile Include="SKImageSourceHandler.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SkiaSharp.Views\SkiaSharp.Views.Mac\SkiaSharp.Views.Mac.csproj">
<Project>{809A15DC-E675-4A24-83FA-DF13160F7E4C}</Project>
<Name>SkiaSharp.Views.Mac</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Binding\SkiaSharp.OSX\SkiaSharp.OSX.csproj">
<Project>{4588A759-3853-49B8-8A68-6C7917BE9220}</Project>
<Name>SkiaSharp.OSX</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="..\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.projitems" Label="Shared" Condition="Exists('..\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.projitems')" />
<Import Project="..\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems" Label="Shared" Condition="Exists('..\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
<Import Project="..\..\packages\Xamarin.Forms.2.3.5.233-pre1\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.5.233-pre1\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
</Project>

Просмотреть файл

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Forms" version="2.3.5.233-pre1" targetFramework="xamarinmac20" />
</packages>

Просмотреть файл

@ -15,6 +15,10 @@ using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.iOS.SKPaintSurfaceEventArg
using Xamarin.Forms.Platform.UWP;
using SKNativeView = SkiaSharp.Views.UWP.SKXamlCanvas;
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.UWP.SKPaintSurfaceEventArgs;
#elif __MACOS__
using Xamarin.Forms.Platform.MacOS;
using SKNativeView = SkiaSharp.Views.Mac.SKCanvasView;
using SKNativePaintSurfaceEventArgs = SkiaSharp.Views.Mac.SKPaintSurfaceEventArgs;
#endif
namespace SkiaSharp.Views.Forms
@ -115,6 +119,8 @@ namespace SkiaSharp.Views.Forms
// repaint the native control
#if __IOS__
Control.SetNeedsDisplay();
#elif __MACOS__
Control.NeedsDisplay = true;
#else
Control.Invalidate();
#endif

Просмотреть файл

@ -16,6 +16,10 @@ using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.iOS.SKPaintGLSurfaceEven
using Xamarin.Forms.Platform.UWP;
using SKNativeView = SkiaSharp.Views.UWP.SKSwapChainPanel;
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.UWP.SKPaintGLSurfaceEventArgs;
#elif __MACOS__
using Xamarin.Forms.Platform.MacOS;
using SKNativeView = SkiaSharp.Views.Mac.SKGLView;
using SKNativePaintGLSurfaceEventArgs = SkiaSharp.Views.Mac.SKPaintGLSurfaceEventArgs;
#endif
namespace SkiaSharp.Views.Forms

Просмотреть файл

@ -57,6 +57,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Extended", "SkiaS
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SkiaSharp.Views.Forms.Native.Shared", "SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.shproj", "{CEBD25FD-DD4F-4D5F-B809-D50D02176F41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Views.Forms.Mac", "SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Mac\SkiaSharp.Views.Forms.Mac.csproj", "{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SkiaSharp.Svg\SkiaSharp.Svg.Shared\SkiaSharp.Svg.Shared.projitems*{04c4399a-6740-4733-b6b7-f968232a76c8}*SharedItemsImports = 4
@ -149,6 +151,10 @@ Global
{FEA1FEC9-950C-46C0-9EB0-A515E0AB8F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEA1FEC9-950C-46C0-9EB0-A515E0AB8F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEA1FEC9-950C-46C0-9EB0-A515E0AB8F19}.Release|Any CPU.Build.0 = Release|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -176,5 +182,6 @@ Global
{E3290CE6-0ADA-486B-9BAB-8BCF07F9BE45} = {8570A43F-3AD6-4EC4-8CD1-92EF9AC23916}
{FEA1FEC9-950C-46C0-9EB0-A515E0AB8F19} = {8570A43F-3AD6-4EC4-8CD1-92EF9AC23916}
{CEBD25FD-DD4F-4D5F-B809-D50D02176F41} = {EB592D4C-48E1-498D-8A9F-3AEA0C7FAB30}
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0} = {EB592D4C-48E1-498D-8A9F-3AEA0C7FAB30}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -75,6 +75,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Extended.NetStand
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SkiaSharp.Views.Forms.Native.Shared", "SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Native.Shared\SkiaSharp.Views.Forms.Native.Shared.shproj", "{CEBD25FD-DD4F-4D5F-B809-D50D02176F41}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkiaSharp.Views.Forms.Mac", "SkiaSharp.Views.Forms\SkiaSharp.Views.Forms.Mac\SkiaSharp.Views.Forms.Mac.csproj", "{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
SkiaSharp.Svg\SkiaSharp.Svg.Shared\SkiaSharp.Svg.Shared.projitems*{04c4399a-6740-4733-b6b7-f968232a76c8}*SharedItemsImports = 4
@ -212,6 +214,10 @@ Global
{36456F7F-388A-49E1-B9C5-CC2DEC82D2C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36456F7F-388A-49E1-B9C5-CC2DEC82D2C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36456F7F-388A-49E1-B9C5-CC2DEC82D2C2}.Release|Any CPU.Build.0 = Release|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -248,5 +254,6 @@ Global
{FEA1FEC9-950C-46C0-9EB0-A515E0AB8F19} = {06F5DF49-E622-4A4C-8F01-0DB0E04721CE}
{36456F7F-388A-49E1-B9C5-CC2DEC82D2C2} = {06F5DF49-E622-4A4C-8F01-0DB0E04721CE}
{CEBD25FD-DD4F-4D5F-B809-D50D02176F41} = {DCADA8CC-D50A-4BD9-B2E6-86696A43D819}
{DA5DA4D8-4885-4AF2-96BB-AE803C344AB0} = {DCADA8CC-D50A-4BD9-B2E6-86696A43D819}
EndGlobalSection
EndGlobal