Skip to content

Commit

Permalink
* Add presets for Skia (pull #418)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored and saudet committed May 17, 2017
1 parent d1aa79f commit bd963fc
Show file tree
Hide file tree
Showing 12 changed files with 4,471 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ matrix:
- jdk: oraclejdk7
os: linux
env: PROJ=videoinput OS=linux-x86_64
- jdk: oraclejdk7
os: linux
env: PROJ=skia OS=linux-x86_64
- os: osx
env: PROJ=artoolkitplus OS=macosx-x86_64
- os: osx
Expand Down Expand Up @@ -88,6 +91,8 @@ matrix:
env: PROJ=tensorflow OS=macosx-x86_64
- os: osx
env: PROJ=videoinput OS=macosx-x86_64
- os: osx
env: PROJ=skia OS=macosx-x86_64

before_install:
#maybe this needs to go into new first job
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Each child module in turn relies on its corresponding native libraries being alr
* MXnet https://github.com/dmlc/mxnet
* TensorFlow 1.1.0 https://github.com/tensorflow/tensorflow
* LiquidFun http://google.github.io/liquidfun/
* Skia https://skia.org

Once everything installed and configured, simply execute
```bash
Expand Down
2 changes: 1 addition & 1 deletion cppbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function download {
}

if [[ -z ${PROJECTS:-} ]]; then
PROJECTS=(opencv ffmpeg flycapture libdc1394 libfreenect libfreenect2 librealsense videoinput artoolkitplus chilitags flandmark hdf5 mkl openblas fftw gsl llvm leptonica tesseract caffe cuda mxnet tensorflow liquidfun)
PROJECTS=(opencv ffmpeg flycapture libdc1394 libfreenect libfreenect2 librealsense videoinput artoolkitplus chilitags flandmark hdf5 mkl openblas fftw gsl llvm leptonica tesseract caffe cuda mxnet tensorflow liquidfun skia)
fi

for PROJECT in ${PROJECTS[@]}; do
Expand Down
6 changes: 6 additions & 0 deletions platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<module>../mxnet/platform</module>
<module>../tensorflow/platform</module>
<module>../liquidfun/platform</module>
<module>../skia/platform</module>
</modules>

<dependencies>
Expand Down Expand Up @@ -168,6 +169,11 @@
<artifactId>liquidfun-platform</artifactId>
<version>20150401-0708ce1-${project.version}</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>skia-platform</artifactId>
<version>20170511-53d6729-${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<module>mxnet</module>
<module>tensorflow</module>
<module>liquidfun</module>
<module>skia</module>
</modules>

<prerequisites>
Expand Down
27 changes: 27 additions & 0 deletions skia/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2011 Google Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128 changes: 128 additions & 0 deletions skia/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
JavaCPP Presets for Skia
========================

Introduction
------------
This directory contains the JavaCPP Presets module for:

* [mono/skia](https://github.com/mono/skia) branch `update-master` as of 2017-05-11 https://skia.org/

Please refer to the parent README.md file for more detailed information about the JavaCPP Presets.


Documentation
-------------
Java API documentation is available here:

* http://bytedeco.org/javacpp-presets/skia/apidocs/

&lowast; Bindings are currently available only for the C API of Skia.

Sample Usage
------------
Here is a simple example of Skia ported to Java from this C source file:

* https://github.com/mono/skia/blob/update-master/experimental/c-api-example/skia-c-example.c

We can use [Maven 3](http://maven.apache.org/) to download and install automatically all the class files as well as the native binaries. To run this sample code, after creating the `pom.xml` and `src/main/java/SkiaCExample.java` source files below, simply execute on the command line:
```bash
$ mvn compile exec:java
```

### The `pom.xml` build file
```xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.bytedeco.javacpp-presets.skia</groupId>
<artifactId>skiaexample</artifactId>
<version>1.3.3-SNAPSHOT</version>
<properties>
<exec.mainClass>SkiaCExample</exec.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>skia-platform</artifactId>
<version>20170511-53d6729-1.3.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
```

### The `src/main/java/SkiaCExample.java` source file
```java
import java.io.FileOutputStream;
import java.io.IOException;

import org.bytedeco.javacpp.*;

import static org.bytedeco.javacpp.Skia.*;

public class SkiaCExample {
private static sk_surface_t makeSurface(int w, int h) {
sk_imageinfo_t info = new sk_imageinfo_t();
info.width(w);
info.height(h);
info.colorType(sk_colortype_get_default_8888());
info.alphaType(PREMUL_SK_ALPHATYPE);
return sk_surface_new_raster(info, null);
}

private static void emitPng(String path, sk_surface_t surface) throws IOException {
sk_image_t image = sk_surface_new_image_snapshot(surface);
sk_data_t data = sk_image_encode(image);
sk_image_unref(image);
Pointer pointer = sk_data_get_data(data).limit(sk_data_get_size(data));
FileOutputStream out = new FileOutputStream(path);
out.getChannel().write(pointer.asByteBuffer());
out.close();
}

private static void draw(sk_canvas_t canvas) {
sk_paint_t fill = sk_paint_new();
sk_paint_set_color(fill, 0xFF0000FF);
sk_canvas_draw_paint(canvas, fill);

sk_paint_set_color(fill, 0xFF00FFFF);
sk_rect_t rect = new sk_rect_t();
rect.left(100.0f);
rect.top(100.0f);
rect.right(540.0f);
rect.bottom(380.0f);
sk_canvas_draw_rect(canvas, rect, fill);

sk_paint_t stroke = sk_paint_new();
sk_paint_set_color(stroke, 0xFFFF0000);
sk_paint_set_antialias(stroke, true);
sk_paint_set_style(stroke, STROKE_SK_PAINT_STYLE);
sk_paint_set_stroke_width(stroke, 5.0f);
sk_path_t path = sk_path_new();

sk_path_move_to(path, 50.0f, 50.0f);
sk_path_line_to(path, 590.0f, 50.0f);
sk_path_cubic_to(path, -490.0f, 50.0f, 1130.0f, 430.0f, 50.0f, 430.0f);
sk_path_line_to(path, 590.0f, 430.0f);
sk_canvas_draw_path(canvas, path, stroke);

sk_paint_set_color(fill, 0x8000FF00);
sk_rect_t rect2 = new sk_rect_t();
rect2.left(120.0f);
rect2.top(120.0f);
rect2.right(520.0f);
rect2.bottom(360.0f);
sk_canvas_draw_oval(canvas, rect2, fill);

sk_path_delete(path);
sk_paint_delete(stroke);
sk_paint_delete(fill);
}

public static void main (String[] args) throws IOException {
sk_surface_t surface = makeSurface(640, 480);
sk_canvas_t canvas = sk_surface_get_canvas(surface);
draw(canvas);
emitPng("skia-c-example.png", surface);
sk_surface_unref(surface);
}
}
```
49 changes: 49 additions & 0 deletions skia/cppbuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
# This file is meant to be included by the parent cppbuild.sh script
if [[ -z "$PLATFORM" ]]; then
pushd ..
bash cppbuild.sh "$@" skia
popd
exit
fi

case $PLATFORM in
linux-x86)
export CC="gcc -m32"
export CXX="g++ -m32"
;;
linux-x86_64)
export CC="gcc -m64"
export CXX="g++ -m64"
;;
macosx-*)
;;
*)
echo "Error: Platform \"$PLATFORM\" is not supported"
return 0
;;
esac

# Must be kept in sync with skia.version in pom.xml
SKIA_VERSION=53d672981d2f4535d61da05befa793a73103c4fd
download "https://github.com/mono/skia/archive/$SKIA_VERSION.zip" "skia-$SKIA_VERSION.zip"

if [ ! -d depot_tools ]; then
echo "Fetching depot_tools..."
git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git' depot_tools
fi
export PATH="$PWD/depot_tools:$PATH"

mkdir -p "$PLATFORM"
cd "$PLATFORM"
if [ ! -d "skia-$SKIA_VERSION" ]; then
echo "Decompressing archives..."
unzip "../skia-$SKIA_VERSION.zip"
fi
cd "skia-$SKIA_VERSION"
python tools/git-sync-deps

bin/gn gen out/Shared --args='is_official_build=false is_debug=false is_component_build=true extra_cflags=["-DSKIA_C_DLL"]'
ninja -C out/Shared

cd ../..
68 changes: 68 additions & 0 deletions skia/platform/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp-presets</artifactId>
<version>1.3.3-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>skia-platform</artifactId>
<version>20170511-53d6729-${project.parent.version}</version>
<name>JavaCPP Presets Platform for Skia</name>

<properties>
<javacpp.moduleId>skia</javacpp.moduleId>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-x86}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.linux-x86_64}</classifier>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${javacpp.moduleId}</artifactId>
<version>${project.version}</version>
<classifier>${javacpp.platform.macosx-x86_64}</classifier>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<configuration>
<archive>
<manifestEntries>
<Class-Path>${javacpp.moduleId}.jar ${javacpp.moduleId}-linux-x86.jar ${javacpp.moduleId}-linux-x86_64.jar ${javacpp.moduleId}-macosx-x86_64.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit bd963fc

Please sign in to comment.