Do a little bit, and throw exceptions if we do not manage to create the context

This commit is contained in:
Miguel de Icaza 2015-11-13 17:36:07 -05:00
Родитель 341ce87612
Коммит 261c71e6ca
5 изменённых файлов: 35 добавлений и 4 удалений

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

@ -13,21 +13,29 @@ namespace SkiaSharp
public SKSurface (SKImageInfo info)
{
handle = SkiaApi.sk_surface_new_raster (ref info, IntPtr.Zero);
if (handle == IntPtr.Zero)
throw new InvalidOperationException ();
}
public SKSurface (SKImageInfo info, SKSurfaceProps props)
{
handle = SkiaApi.sk_surface_new_raster (ref info, ref props);
if (handle == IntPtr.Zero)
throw new InvalidOperationException ();
}
public SKSurface (SKImageInfo info, IntPtr pixels, int rowBytes)
{
handle = SkiaApi.sk_surface_new_raster_direct (ref info, pixels, (IntPtr)rowBytes, IntPtr.Zero);
if (handle == IntPtr.Zero)
throw new InvalidOperationException ();
}
public SKSurface (SKImageInfo info, IntPtr pixels, int rowBytes, SKSurfaceProps props)
{
handle = SkiaApi.sk_surface_new_raster_direct (ref info, pixels, (IntPtr)rowBytes, ref props);
if (handle == IntPtr.Zero)
throw new InvalidOperationException ();
}
public void Dispose ()
@ -55,6 +63,7 @@ namespace SkiaSharp
public SKCanvas Canvas {
get {
Console.WriteLine ("got: {0:x}", (long)handle);
if (canvas == null)
canvas = new SKCanvas (this, SkiaApi.sk_surface_get_canvas (handle));
return canvas;

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

@ -31,7 +31,6 @@
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="..\Binding\Binding.projitems" Label="Shared" Condition="Exists('..\Binding\Binding.projitems')" />

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

@ -1 +0,0 @@


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

@ -19,6 +19,7 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
@ -28,6 +29,7 @@
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@ -37,4 +39,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="Desktop\Desktop.csproj">
<Project>{467FA6DC-C3FB-4EF8-8B8F-338C13CC8A71}</Project>
<Name>Desktop</Name>
</ProjectReference>
</ItemGroup>
</Project>

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

@ -1,4 +1,7 @@
using System;
using SkiaSharp;
using System.Runtime.InteropServices;
using System.IO;
namespace Driver
{
@ -6,7 +9,20 @@ namespace Driver
{
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
var info = new SKImageInfo (1024, 768, SKColorType.Rgba_8888, SKAlphaType.Opaque);
var buffer = new byte [1024 * 768 * 4];
unsafe {
fixed (byte * f = &buffer[0]) {
using (var surface = new SKSurface (info, (IntPtr) f, 1024 * 4)) {
var canvas = surface.Canvas;
var paint = new SKPaint ();
canvas.DrawRect (new SKRect (10, 10, 1024, 758), paint);
}
}
}
File.WriteAllBytes ("/tmp/path", buffer);
}
}
}
}