Code Monkey home page Code Monkey logo

skiakit's Introduction

SkiaKit

Go to macOS / iOS / tvOS | Go to Linux

SkiaKit is a 2D Graphics Library for use with Swift. It is powered by Google's Skia graphics library, the same library that powers Google Chrome and Android graphics.

You can review the API Documentation

The Swift bindings are intended to be cross-platform, both to Apple platforms, Linux, and new platforms where Skia and Swift run.

This work uses extensive code from Microsoft's SkiaSharp bindings authored by Matthew Leibowitz and dozens of contributors. SkiaSharp just happens to have a very advanced set of bridge APIs to the underlying Skia engine that does not existing in the upstream Google Skia project.

Getting this to work

Apple

Supports:

  • x86_64 Mac: anything from 2008 MacBook to M1 (using x86 emulation)
  • arm64 iPhone: anything past iPhone 5S
  • arm64 iPad: anything past iPad Air / iPad mini 2 (post-2013)
  • iPhone Simulator
  • iPad Simulator
  • tvOS

Not currently supported:

  • Mac Catalyst

Recommended usage

You can add SkiaKit to your project by putting this dependency in your Package.swift:

.package(url: "https://github.com/migueldeicaza/SkiaKit.git", from: "1.0.0")

Using manually

If using manually, you'll need to download and assemble the SkiaSharp.xcframework required.

This must be ran on macOS with the Command Line Tools for XCode installed.

git clone https://github.com/migueldeicaza/SkiaKit.git
cd SkiaKit
make download-payload

Linux

SkiaKit is platform agnostic and makes a best-effort support for Linux. An .so for the SkiaSharp library is included and supports the following Linux distributions.

The libSkiaSharp.so file will need to be distributed alongside your project.

Recommended usage

You can add SkiaKit to your project by putting this dependency in your Package.swift:

.package(url: "https://github.com/migueldeicaza/SkiaKit.git", .branch("generated"))

Using manually

If using manually, you'll need to provide libSkiaSharp.so in the root of the SkiaKit folder. For certain Linux distros, a convenience script is provided.

This script requires curl and unzip.

git clone https://github.com/migueldeicaza/SkiaKit.git
cd SkiaKit
make download-payload-linux

skiakit's People

Contributors

mbullington avatar migueldeicaza avatar zats avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

skiakit's Issues

download-payload.sh was deleted but make download-payload still invokes it.

commit: a156496 deleted download-payload.sh. I'm assuming the intent is to move to swift package manager entirely.

a156496#diff-c1c5e6d88fda70033edb0b3a2df69ed5663d226e5cd2990cb87c8b80f1de4b78

I have a hybrid c++\swift app I want to upgrade to 1.2.5, but I don't have the energy to update my build system to figure out how to make swift package manager and cmake play nice. What do you suppose it would take if I wanted to support my own download-payload.sh script?

Is this project still maintained? Sample and steps for adding package do not work.

I was looking to port a project I built in Xamarin Forms / MAUI which uses SkiaSharp to Swift but the sample project doesn't build and I can't even get a default SwiftUI project to build following steps provided or by using the swift package manager.

Before I invest anymore time in looking at porting I just want to check if this project is maintained and if so would it be possible for updated steps or sample app be provided?

Many thanks in advance.

Path missing bits

  • Offset
  • ArcTo
  • RArcTo
  • ConvertConicToQuads

I have not found users of this code, so may not be worth doing:

  • Iterators
  • OpBuilder

Canvas missing bits

  • saveLayer
  • drawPicture
  • drawDrawable
  • drawSurface
  • drawAnnotation
  • drawUrlAnnotation
  • drawNamedDestinationAnnotation
  • drawLinkDestinationAnnotation
  • DrawBitmapLattice
  • DrawImageLattice
  • drawVertices

Progress

  • GRBackendRenderTarget.cs
  • GRBackendTexture.cs
  • GRContext.cs
  • GRDefinitions.cs
  • GRGlInterface.cs
  • SKAbstractManagedStream.cs
  • SKAbstractManagedWStream.cs
  • SKAutoCoInitialize.cs
  • SKBitmap.cs
  • SKCanvas.cs
  • SKCodec.cs
  • SKColor.cs
  • SKColorFilter.cs
  • SKColorSpace.cs
  • SKColorTable.cs
  • SKData.cs (missing sk_data_new_with_proc)
  • SKDocument.cs
  • SKDrawable.cs
  • SKFontManager.cs
  • SKFontStyle.cs
  • SKFontStyleSet.cs
  • SKFrontBufferedManagedStream.cs
  • SKFrontBufferedStream.cs
  • SKImage.cs
  • SKImageFilter.cs
  • SKImageInfo.cs
  • SKManagedStream.cs
  • SKManagedWStream.cs
  • SKMask.cs
  • SKMaskFilter.cs
  • SKMatrix.cs
  • SKNWayCanvas.cs
  • SKNoDrawCanvas.cs
  • SKOverdrawCanvas.cs
  • SKPaint.cs
  • SKPath.cs
  • SKPathEffect.cs
  • SKPathMeasure.cs
  • SKPicture.cs
  • SKPictureRecorder.cs
  • SKPixelSerializer.cs
  • SKPixmap.cs
  • SKRegion.cs
  • SKRoundRect.cs
  • SKRunBuffer.cs
  • SKSVG.cs
  • SKShader.cs
  • SKStream.cs
  • SKString.cs
  • SKSurface.cs
  • SKSurfaceProperties.cs
  • SKSwizzle.cs
  • SKTextBlob.cs
  • SKTypeface.cs
  • SKVertices.cs
  • SKXml.cs
  • Util.cs

Undefined reference to sk_path_is_convex

libSkiaSharp.so 2.80.3-preview.40 appears to lack the sk_path_is_convex symbol necessary to run the tests.

LD_LIBRARY_PATH=. swift test
Building for debugging...
error: link command failed with exit code 1 (use -v to see invocation)
/home/lukeh/CVSRoot/SkiaKit/.build/x86_64-unknown-linux-gnu/debug/SkiaKit.build/Path.swift.o:Path.swift.o:function $s7SkiaKit4PathC8isConvexSbvg: error: undefined reference to 'sk_path_is_convex'
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
error: fatalError
[0/1] Linking SkiaKitPackageTests.xctest
error: fatalError

SkiaKit package resolution failed

When i try to add SkiaKit package using swift package manager it is throwing me this error.
Screenshot 2023-06-15 at 12 30 19 PM

Could someone please help me resolve above issue?

Pixmap missing methods

  • The variations of encode for Jpeg
  • The variations of encode for Webp
  • The variations of encode for Png

GetGlyphWidths using sk_font_get_widths_bounds

`public func getGlyphWidths(text: String) -> [Float] {
var paint: Paint? = nil
var textChar = Character

    var n = countGlyphs(str: text)
    if n <= 0 {
        return [Float]()
    }
    
    var widths: [Float] = Array.init (repeating: Float.zero, count: Int(n))
    var bounds: [Rect] = Array.init (repeating: Rect(width: 0, height: 0), count: Int(n))
    
    var w: UnsafeMutablePointer<Float>? = nil
    if !widths.isEmpty {
        w = UnsafeMutablePointer<Float>.allocate(capacity: widths.count)
        w?.initialize(from: &widths, count: widths.count)
    }

    var b: UnsafeMutablePointer<Rect>? = nil
    if !bounds.isEmpty {
        b = UnsafeMutablePointer<Rect>.allocate(capacity: bounds.count)
        b?.initialize(from: &bounds, count: bounds.count)
    }

    
    if var glyphs = getGlyphs(str: text) {
        sk_font_get_widths_bounds(handle, &glyphs, Int32 (glyphs.count), w, b, paint?.handle)
    }
    
    
    // Deallocate memory and free pointers when done
    w?.deallocate()
    b?.deallocate()
    
    return widths
}

`
I have implemented the above API, could you please let me know if there is something that i missed here?

Stream missing bits

  • Class SKWStream
    • Write* helper methods
  • SKFileWStream
  • SKDynamicMemoryWStream

Move documentation to docc

And use the same pattern I used in SwiftGodot: where the documentation is checked into a separate module, to avoid the pollution here.

Surface missing methods

  • Create methods that take a GPU GRContext
  • Create methods that take a GPU GRContext and a GRBackendTexture
  • CreateAsRenderTarget
  • GPU New surface methods
  • Null surface

Paint missing bits

  • BreakText
  • GetTextPath
  • GetFillPath
  • CountGlyphs
  • GetGlyphs
  • ContainsGlyphs
  • GetGlyphWidhts
  • GetTextIntercepts
  • GetPositionedTextIntercepts
  • GetHorizontalTextIntercepts

Black canvas for all examples on device.

Hi, I am encountering an issue when running the sample application on device, where every example shows black screen instead of drawing. On the simulator the drawings are shown properly. Tried running on multiple devices, iOS 15.x

Are you able to replicate the issue or know any possible solutions?

Thank you.
IMG_3D303191DB4A-1

macOS build errors (Xcode 14.2)

On:

% xcodebuild -version
Xcode 14.2
Build version 14C18

I needed the following patch to build:

diff --git a/Package.swift b/Package.swift
index 70bf3b3..78a188a 100644
--- a/Package.swift
+++ b/Package.swift
@@ -29,14 +29,14 @@ target = [
 target = [
        .target (
                name: "CSkiaSharp",
-               dependencies: ["CSkiaSharpBinary"],
+               dependencies: ["SkiaSharp"],
                cSettings: [
                .headerSearchPath("include")
                ]
        ),
        .binaryTarget (
-               name: "CSkiaSharpBinary",
-               url: "https://github.com/migueldeicaza/SkiaKit/releases/download/1.2.4/SkiaSharp.xcframework.zip",
+               name: "SkiaSharp",
+               url: "https://github.com/migueldeicaza/SkiaKit/releases/download/1.2.5/SkiaSharp.xcframework.zip",
                checksum: "6aab048910bdd5a24f3321b2476ab6dd5306c1efb5729776d3a780a806b008b1"
        ),
        .testTarget (

GetGlyphPositions SkiaSharp implementation in Swift

` func getGlyphPositions(text: String) -> [Point] {
var textChar = Character

    var n = countGlyphs(str: text)
    if n <= 0 {
        return [Point]()
    }
    
    var positions: [Point] = Array.init (repeating: Point(x:0, y:0), count: Int(n))
    
    if var glyphs = getGlyphs(str: text) {
        positions = getGlyphPositions(glyphs: &glyphs)
    }

    return positions
}`

Could you also review this?

Image missing bits

  • FromTexture - requires the GRContext implementations
  • FromAdoptedTexture - same
  • FromPicture - needs Picture
  • ApplyImageFilter - needs fixed sk_ipoint_t definition

Region issues

sk_region_contains currently returns void, should return bool

sk_imagefilter_new_blur not implemented

Hello,

I know you are busy. But could you please implement the sk_imagefilter_new_blur in SkiaKit?
The SkiaSharp implementation has HandleDictionary.cs class implementation. Which i think is bit difficult for me to implement on my own.
Any help is appreciated.

Thank you.

Future: drop SkiaSharp dependency

Currently SkiaKit consumes the stable ABI provided by SkiaSharp (Skia itself only exposes a limited stable abi), but because th way enums work in swift there need to be methods that do swift enums to stable enums and those go to the C++ abi.

We might be able to just call C++ directly, and bypass one level. The problem is that Package.swift might not support this scenario.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.