From 72ebba8c3e0dcdf3da7b0cd56cee2160d00f628b Mon Sep 17 00:00:00 2001 From: James Walmsley Date: Tue, 22 Feb 2022 21:05:03 +0000 Subject: [PATCH] [SKIABUILD] Initial build-recipe and Docker containers for skiabuild --- .github/workflows/build_containers.yml | 29 +++++ .github/workflows/skiabuild.yml | 79 +++++++++++++ .gitignore | 3 + .gitmodules | 3 + Makefile | 27 +++++ README.md | 4 + configs/skia_defconfig | 1 + docker/skiabuild/Dockerfile | 146 +++++++++++++++++++++++++ docker/skiabuild/devenv.Dockerfile | 5 + docker/skiabuild/docker-compose.yml | 34 ++++++ docker/skiabuild/entrypoint.sh | 12 ++ docker/skiabuild/userentry.sh | 6 + recipes/skia/layers/avalonia_skia.mk | 14 +++ recipes/skia/layers/fontconfig.mk | 17 +++ recipes/skia/layers/freetype.mk | 14 +++ recipes/skia/layers/skia.mk | 70 ++++++++++++ recipes/skia/layers/skia.pc.in | 15 +++ recipes/skia/recipe.mk | 36 ++++++ test/meson.build | 29 +++++ test/testlib.cpp | 82 ++++++++++++++ test/testprog.c | 7 ++ ve-root | 1 + 22 files changed, 634 insertions(+) create mode 100644 .github/workflows/build_containers.yml create mode 100644 .github/workflows/skiabuild.yml create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 Makefile create mode 100644 README.md create mode 100644 configs/skia_defconfig create mode 100644 docker/skiabuild/Dockerfile create mode 100644 docker/skiabuild/devenv.Dockerfile create mode 100644 docker/skiabuild/docker-compose.yml create mode 100755 docker/skiabuild/entrypoint.sh create mode 100755 docker/skiabuild/userentry.sh create mode 100644 recipes/skia/layers/avalonia_skia.mk create mode 100644 recipes/skia/layers/fontconfig.mk create mode 100644 recipes/skia/layers/freetype.mk create mode 100644 recipes/skia/layers/skia.mk create mode 100644 recipes/skia/layers/skia.pc.in create mode 100644 recipes/skia/recipe.mk create mode 100644 test/meson.build create mode 100644 test/testlib.cpp create mode 100644 test/testprog.c create mode 160000 ve-root diff --git a/.github/workflows/build_containers.yml b/.github/workflows/build_containers.yml new file mode 100644 index 0000000..85351e1 --- /dev/null +++ b/.github/workflows/build_containers.yml @@ -0,0 +1,29 @@ +name: Build Docker Containers +on: + push: + paths: + - 'docker/**' + - '.github/workflows/build_containers.yml' +jobs: + build_skiabuild-64: + runs-on: [self-hosted, linux, x64] + container: jameswalmsley/container-builder:latest + steps: + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.JAMES_DOCKER_HUB_USERNAME }} + password: ${{ secrets.JAMES_DOCKER_HUB_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: docker/skiabuild + file: docker/skiabuild/Dockerfile + push: true + tags: jameswalmsley/skiabuild:latest + diff --git a/.github/workflows/skiabuild.yml b/.github/workflows/skiabuild.yml new file mode 100644 index 0000000..98eb56e --- /dev/null +++ b/.github/workflows/skiabuild.yml @@ -0,0 +1,79 @@ +name: Build Skia x-plat +on: [push] +jobs: + build_skia_64: + runs-on: [self-hosted, linux, x64] + container: jameswalmsley/skiabuild:latest + steps: + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v2 + with: + submodules: 'recursive' + - name: Build Skia + run: | + make skia_defconfig + make source-checkout -j$(nproc) + make + + - run: echo "🍏 This job's status is ${{ job.status }}." + - uses: actions/upload-artifact@v3 + with: + name: libskia-x86_64-linux-gnu + path: out/skia/sysroot.tar.gz + # - uses: actions/upload-artifact@v3 + # with: + # name: libskia-x86-linux-gnu + # path: out/skia/sysroot.tar.gz + + + test_skia_archlinux: + runs-on: ubuntu-latest + needs: build_skia_64 + container: archlinux:latest + steps: + - run: echo "Testing skia shim on archlinux" + + test_skia_fedora: + runs-on: ubuntu-latest + needs: build_skia_64 + container: fedora:latest + steps: + - run: echo "Testing skia shim on archlinux" + + test_skia_debian: + runs-on: ubuntu-latest + needs: build_skia_64 + container: debian:latest + steps: + - run: echo "Testing skia shim on archlinux" + + test_skia_alpine: + runs-on: ubuntu-latest + needs: build_skia_64 + container: alpine:latest + steps: + - run: echo "Testing skia shim on archlinux" + + release_libskia: + needs: [build_skia_64] + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + if: startsWith(github.ref, 'refs/tags/v') + + - run: ls -R + if: startsWith(github.ref, 'refs/tags/v') + + - run: tar cvzf avalonia.skialibs.tar.gz * + if: startsWith(github.ref, 'refs/tags/v') + + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/v') + with: + files: | + avalonia.skia.sysroots.tar.gz + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0560e93 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.config +out +sources diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..537fb91 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "ve-root"] + path = ve-root + url = https://github.com/jameswalmsley/ve-root diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..44c9b69 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +BASE:=$(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST))))) +include $(BASE)/ve-root/Makefile + +DOCKER_IMAGE:=skiabuild + +DOCKER:=skiabuild +CONTAINER?=skiabuild + + +# all: +# cd skia && python ./tools/git-sync-deps +# cd skia && ./bin/gn gen out/Shared --args='is_official_build=true skia_use_system_harfbuzz=false is_component_build=true' +# cd skia/out/Shared && ninja -j16 + + +# docker.build: +# cd docker/$(DOCKER) && BASE=$(shell pwd) docker-compose build $(CONTAINER) + +# docker.pull: +# cd docker/$(DOCKER) && BASE=$(shell pwd) docker-compose pull $(CONTAINER) + +# .PHONY: docker +# docker: +# cd docker/$(DOCKER) && BASE=$(shell pwd) CURRENT_DIR=$(shell pwd) CURRENT_UID=$(shell id -u) \ +# CURRENT_GID=$(shell id -g) CURRENT_USER=$(shell whoami) docker-compose run --rm $(CONTAINER) /bin/bash + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..2df938b --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# SkiaBuild +[![Build Skia x-plat](https://github.com/AvaloniaUI/Avalonia.Skia/actions/workflows/skiabuild.yml/badge.svg?branch=main)](https://github.com/AvaloniaUI/Avalonia.Skia/actions/workflows/skiabuild.yml) + +Cross-platform meta build of skia for Avalonia diff --git a/configs/skia_defconfig b/configs/skia_defconfig new file mode 100644 index 0000000..048ff50 --- /dev/null +++ b/configs/skia_defconfig @@ -0,0 +1 @@ +CONFIG_RECIPE:=skia diff --git a/docker/skiabuild/Dockerfile b/docker/skiabuild/Dockerfile new file mode 100644 index 0000000..01dc909 --- /dev/null +++ b/docker/skiabuild/Dockerfile @@ -0,0 +1,146 @@ +FROM centos:7 AS buildbase + +RUN yum --enablerepo=base clean metadata +RUN yum install -y deltarpm +RUN yum update -y +RUN yum install -y tar \ + curl \ + curl-devel \ + m4 \ + autoconf \ + automake \ + libtool \ + pkgconfig \ + openssl-devel \ + file \ + patch \ + bzip2 \ + zlib-devel \ + gettext \ + python-setuptools \ + python-devel \ + epel-release \ + centos-release-scl \ + git \ + gcc \ + gcc-c++ \ + python3 \ + expat-devel \ + dh-autoreconf \ + curl-devel \ + gettext-devel \ + openssl-devel \ + perl-devel \ + zlib-devel \ + mesa-libGL-devel \ + gperf \ + gettext-devel \ + expat-devel \ + binutils-devel \ + python3-devel \ + flex \ + bison \ + texinfo \ + which + + +RUN pip3 install cmake ninja meson + +FROM buildbase AS toolchains + +RUN yum install -y devtoolset-10 + +RUN git clone -v --depth=1 https://github.com/distcc/distcc.git && cd distcc && ./autogen.sh && source /opt/rh/devtoolset-10/enable && ./configure && make -j$(nproc) && make install && rm -rf /distcc + +RUN ln -s /usr/bin/gcc /usr/bin/gcc-4.8.5 +RUN ln -s /usr/bin/g++ /usr/bin/g++-4.8.5 + +RUN yum -y install glibc-devel.i686 + +# # +# # Modern GCC +# # +RUN git clone --depth=1 -b releases/gcc-10.3.0 https://github.com/gcc-mirror/gcc +RUN git clone --depth=1 -b binutils-2_38 https://github.com/bminor/binutils-gdb +RUN mkdir -p binutils-gdb/build + +RUN cd binutils-gdb/build && ../configure CC='distcc gcc-4.8.5' CXX='distcc g++-4.8.5' --disable-shared --disable-gdb --disable-sim --disable-nls --enable-multilib --enable-multiarch +ENV DISTCC_HOSTS="10.1.0.16/1 10.1.0.24/32 10.1.0.32/8 10.1.0.40/20 10.1.0.48/16" +RUN cd binutils-gdb/build && make -j$(distcc -j) +RUN cd binutils-gdb/build && make install + +RUN mkdir -p gcc/build + +RUN cd gcc && ./contrib/download_prerequisites +RUN cd gcc/build && ../configure CC='distcc gcc-4.8.5' CXX='distcc g++-4.8.5' \ + --prefix=/usr \ + --target=x86_64-linux-gnu \ + --enable-languages="c,c++" --enable-multilib --enable-multiarch --enable-threads='posix' --program-suffix=-10 +RUN cd gcc/build && make -j$(distcc -j) +RUN cd gcc/build && make DESTDIR=$(pwd)/out install +RUN cd gcc/build && make install + +RUN git clone -v --depth=1 -b llvmorg-13.0.1 https://github.com/llvm/llvm-project.git + +WORKDIR /llvm-project +RUN mkdir build +RUN cd build && CC="distcc gcc-10" CXX="distcc g++-10" cmake \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_ENABLE_PROJECTS=clang \ + -G "Ninja" ../llvm + +ENV DISTCC_HOSTS="10.1.0.16/8 10.1.0.24/14 10.1.0.40/20 10.1.0.48/16" +RUN cd build && ninja -j$(distcc -j) +RUN cd build && DESTDIR=$(pwd)/out ninja install +RUN cd build && ninja install +RUN cd build/out/usr/local/bin && ln -s clang++ clang++-13 +RUN cd /usr/local/bin && ln -s clang++ clang++-13 + + +WORKDIR / +RUN git clone -v --depth=1 -b v2.35.1 https://github.com/git/git.git +RUN cd git && make configure && ./configure CC='distcc clang-13' CXX='distcc clang++-13' +RUN cd git && make -j$(distcc -j) +RUN cd git && make DESTDIR=out install +RUN cd git && make install + +RUN git clone -v https://gn.googlesource.com/gn +RUN cd gn && CC='distcc clang-13' CXX='distcc clang++-13' ./build/gen.py +RUN cd gn/out && ninja -j$(distcc -j) + +RUN git clone --depth=1 https://gitlab.freedesktop.org/freetype/freetype.git +WORKDIR /freetype +RUN CC="distcc clang-13" CXX="distcc clang++-13" CFLAGS="-fPIC" meson build --buildtype=release && ninja -C build -j$(distcc -j) +RUN ninja -C build install +RUN DESTDIR=$(pwd)/out ninja -C build install + +WORKDIR / +RUN git clone --depth=1 https://github.com/freedesktop/fontconfig.git +WORKDIR /fontconfig +RUN CC="distcc clang-13" CXX="distcc clang++-13" CFLAGS="-fPIC" meson build --buildtype=release -Dtests=disabled && ninja -C build -j$(distcc -j) +RUN ninja -C build install +RUN DESTDIR=$(pwd)/out ninja -C build install + +WORKDIR / +RUN git clone -v --depth=1 https://github.com/distcc/distcc.git && cd distcc && ./autogen.sh && source /opt/rh/devtoolset-10/enable && ./configure && make -j$(nproc) && make DESTDIR=$(pwd)/out install + +WORKDIR / +RUN cd binutils-gdb/build && make DESTDIR=/binutils-gdb/out install + +FROM buildbase + +COPY --from=toolchains distcc/out/ / +COPY --from=toolchains git/out/ / +COPY --from=toolchains binutils-gdb/out/ / +COPY --from=toolchains gcc/build/out/ / +COPY --from=toolchains llvm-project/build/out/ / +COPY --from=toolchains gn/out/gn /usr/local/bin/ +COPY --from=toolchains freetype/out/ / +COPY --from=toolchains fontconfig/out/ / +COPY --from=toolchains gn/out/gn /usr/bin/gn + +RUN yum -y install mesa-libGL-devel.i686 glibc-devel.i686 make + +RUN mkdir -p /usr/local/git/share/git-core/templates + diff --git a/docker/skiabuild/devenv.Dockerfile b/docker/skiabuild/devenv.Dockerfile new file mode 100644 index 0000000..bd1e4ac --- /dev/null +++ b/docker/skiabuild/devenv.Dockerfile @@ -0,0 +1,5 @@ +FROM jameswalmsley/skiabuild:latest + +RUN yum -y install sudo wget epel-release +RUN yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm && yum -y install git +RUN wget https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz && cd /usr && tar xvfh /nvim*.tar.gz --strip-components=1 && rm /nvim*.tar.gz diff --git a/docker/skiabuild/docker-compose.yml b/docker/skiabuild/docker-compose.yml new file mode 100644 index 0000000..8af6ec1 --- /dev/null +++ b/docker/skiabuild/docker-compose.yml @@ -0,0 +1,34 @@ +version: "2" +services: + skiabuild: + build: + context: . + dockerfile: devenv.Dockerfile + volumes: + - /home/${CURRENT_USER}:/home/${CURRENT_USER} + - ./entrypoint.sh:/entrypoint.sh + - ./userentry.sh:/userentry.sh + - /tmp/.X11-unix:/tmp/.X11-unix + - /dev:/dev + - /tmp:/tmp + environment: + - DISPLAY + - CURRENT_UID + - CURRENT_GID + - CURRENT_USER + - CURRENT_DIR + - TERM=xterm-256color + hostname: skiabuild + stdin_open: true + tty: true + privileged: true + entrypoint: /entrypoint.sh + working_dir: /work + + skiabuild_ci: + build: + context: . + dockerfile: Dockerfile + image: jameswalmsley/skiabuild:latest + volumes: + - /home/${CURRENT_USER}:/home/${CURRENT_USER} diff --git a/docker/skiabuild/entrypoint.sh b/docker/skiabuild/entrypoint.sh new file mode 100755 index 0000000..3535ad9 --- /dev/null +++ b/docker/skiabuild/entrypoint.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +groupadd -g ${CURRENT_GID} usergroup +useradd -M -u ${CURRENT_UID} -g ${CURRENT_GID} ${CURRENT_USER} + +usermod -a -G wheel ${CURRENT_USER} + +echo "root ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers +echo "${CURRENT_USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +exec sudo -i -u ${CURRENT_USER} /userentry.sh ${CURRENT_DIR} $@ + diff --git a/docker/skiabuild/userentry.sh b/docker/skiabuild/userentry.sh new file mode 100755 index 0000000..fc297d9 --- /dev/null +++ b/docker/skiabuild/userentry.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export PATH="/usr/local/bin:$PATH" + +cd $1 +exec $2 diff --git a/recipes/skia/layers/avalonia_skia.mk b/recipes/skia/layers/avalonia_skia.mk new file mode 100644 index 0000000..e694f4c --- /dev/null +++ b/recipes/skia/layers/avalonia_skia.mk @@ -0,0 +1,14 @@ +LAYER:=avalonia_skia +include $(DEFINE_LAYER) + +$(call meson_srcdir, avalonia_skia, $(BASE)/test) + +DEPENDS += skia + +include $(BUILD_LAYER) + +$(L): $(BASE)/test/meson.build + + +$(L).clean: + rm -rf $(builddir) diff --git a/recipes/skia/layers/fontconfig.mk b/recipes/skia/layers/fontconfig.mk new file mode 100644 index 0000000..5ad8310 --- /dev/null +++ b/recipes/skia/layers/fontconfig.mk @@ -0,0 +1,17 @@ +LAYER:=fontconfig +include $(DEFINE_LAYER) + +fontconfig_GIT_REF?=main +$(call git_clone, fontconfig, https://gitlab.freedesktop.org/fontconfig/fontconfig.git, $(fontconfig_GIT_REF)) + +$(call meson_srcdir, fontconfig, $(SRC_fontconfig)/fontconfig) + + +DEPENDS += freetype + +include $(BUILD_LAYER) + +$(L).clean: + rm -rf $(builddir) + + diff --git a/recipes/skia/layers/freetype.mk b/recipes/skia/layers/freetype.mk new file mode 100644 index 0000000..42f6084 --- /dev/null +++ b/recipes/skia/layers/freetype.mk @@ -0,0 +1,14 @@ +LAYER:=freetype +include $(DEFINE_LAYER) + +FREETYPE_GIT_REF?=master + +$(call git_clone, freetype, https://gitlab.freedesktop.org/freetype/freetype.git, $(FREETYPE_GIT_REF)) + +$(call meson, freetype) + +include $(BUILD_LAYER) + +$(L).clean: + rm -rf $(builddir) + diff --git a/recipes/skia/layers/skia.mk b/recipes/skia/layers/skia.mk new file mode 100644 index 0000000..dfc90aa --- /dev/null +++ b/recipes/skia/layers/skia.mk @@ -0,0 +1,70 @@ +LAYER:=skia +include $(DEFINE_LAYER) + +SKIA_GIT_REF?=main + +skia:=$(LSTAMP)/skia +skia_sync_deps:=$(LSTAMP)/skia_sync_deps +skia_config:=$(LSTAMP)/skia_config +skia_install:=$(LSTAMP)/skia_install +skia_pkgconfig:=$(LSTAMP)/skia_pkgconfig + +$(call git_clone, skia, https://github.com/google/skia.git, $(SKIA_GIT_REF)) + +$(L) += $(skia_sync_deps) +$(L) += $(skia_config) +$(L) += $(skia) +$(L) += $(skia_install) +$(L) += $(skia_pkgconfig) + + +DEPENDS += fontconfig + + +include $(BUILD_LAYER) + +SKIA_ARCH=x86_64 + +$(skia_sync_deps): + cd $(srcdir)/skia && ./tools/git-sync-deps + $(stamp) + +SKIA_ARGS:= +SKIA_ARGS += is_official_build=true +SKIA_ARGS += skia_enable_tools=false +SKIA_ARGS += extra_ldflags=[\"-L$(SYSROOT)/usr/local/lib64\"] +SKIA_ARGS += target_os=\"linux\" target_cpu=\"$(SKIA_ARCH)\" +SKIA_ARGS += skia_use_icu=false +SKIA_ARGS += skia_use_sfntly=false +SKIA_ARGS += skia_use_piex=true +SKIA_ARGS += skia_use_system_expat=false +SKIA_ARGS += skia_use_system_freetype2=false +SKIA_ARGS += skia_use_system_libjpeg_turbo=false +SKIA_ARGS += skia_use_system_libpng=false +SKIA_ARGS += skia_use_system_libwebp=false +SKIA_ARGS += skia_use_system_zlib=false +SKIA_ARGS += skia_enable_gpu=true +SKIA_ARGS += cc=\"distcc clang-13\" +SKIA_ARGS += cxx=\"distcc clang++-13\" +SKIA_ARGS += ar=\"$(AR)\" + +$(skia_config): $(skia_sync_deps) + cd $(srcdir)/skia && gn gen $(builddir)/skia --args="$(SKIA_ARGS)" + $(stamp) + +$(skia): $(skia_config) + cd $(builddir)/skia && ninja $(BUILD_JOBS) + $(stamp) + +$(skia_install): $(skia) + mkdir -p $(SYSROOT)/usr/local/include/skia + cp -rv $(srcdir)/skia/include $(SYSROOT)/usr/local/include/skia + cp $(builddir)/skia/libskia.a $(SYSROOT)/usr/local/lib64/ + $(stamp) + +$(skia_pkgconfig): $(skia_install) + cp $(BASE_skia)/skia.pc.in $(SYSROOT)/usr/local/lib64/pkgconfig/skia.pc + + +$(L).clean: + rm -rf $(builddir) diff --git a/recipes/skia/layers/skia.pc.in b/recipes/skia/layers/skia.pc.in new file mode 100644 index 0000000..78d40ba --- /dev/null +++ b/recipes/skia/layers/skia.pc.in @@ -0,0 +1,15 @@ +prefix=/usr/local +libdir=${prefix}/lib64 +includedir=${prefix}/include/skia + +sysconfdir=/usr/local/etc +localstatedir=/var/local +confdir=${sysconfdir}/fonts +cachedir=${localstatedir}/cache/fontconfig + +Name: Skia +Version: 1.0 +Description: Skia graphics library +Libs: -L${libdir} -lskia +Cflags: -I${includedir} + diff --git a/recipes/skia/recipe.mk b/recipes/skia/recipe.mk new file mode 100644 index 0000000..a23bfca --- /dev/null +++ b/recipes/skia/recipe.mk @@ -0,0 +1,36 @@ +include $(DEFINE_RECIPE) +SYSROOT?=$(OUT)/sysroot + +export CC:=gcc-10 +export CXX:=g++-10 + +PREFIX=usr/local +LIBDIR=lib64 +export LIBRARY_PATH="$(SYSROOT)/$(PREFIX)/$(LIBDIR):$(SYSROOT)/usr/lib64" + +ifneq ($(shell which distcc),) +export DISTCC_HOSTS=10.1.0.16/4 10.1.0.24/32 10.1.0.40/20 10.1.0.48/16 +export CC:=distcc $(CC) +export CXX:=distcc $(CXX) +endif + +ifneq ($(shell which distcc),) +ifdef DISTCC_HOSTS +BUILD_JOBS=-j $$(distcc -j) +testy: + echo $(BUILD_JOBS) + +endif +endif + +MESON_OPTIONS:= + +LAYERS += meson +LAYERS += freetype +LAYERS += fontconfig +LAYERS += skia +LAYERS += avalonia_skia +LAYERS += sysroot/package + +include $(BUILD_RECIPE) + diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..431496e --- /dev/null +++ b/test/meson.build @@ -0,0 +1,29 @@ +project( + 'avalonia.skia', + ['c','cpp'] +) + +gl_dep = dependency('gl', required: true) +fc_dep = dependency('fontconfig', static: true) +sk_dep = dependency('skia', static: true) + +cpp = meson.get_compiler('cpp') + +# sk_dep = declare_dependency( +# dependencies : cpp.find_library('skia', dirs : meson.current_source_dir()+'/../out/skia/sysroot/usr/local/lib64'), +# include_directories : include_directories('../out/skia/sysroot/usr/local/include/skia') +# ) + +lib = shared_library( + 'avalonia.skia', + ['testlib.cpp'], + dependencies: [fc_dep, gl_dep, sk_dep], + install: true, +) + +testprog = executable( + 'testprog', + ['testprog.c'], + link_with: lib, + install: true +) diff --git a/test/testlib.cpp b/test/testlib.cpp new file mode 100644 index 0000000..f9d930a --- /dev/null +++ b/test/testlib.cpp @@ -0,0 +1,82 @@ +#include + +#include "include/c/sk_canvas.h" +#include "include/c/sk_data.h" +#include "include/c/sk_image.h" +#include "include/c/sk_imageinfo.h" +#include "include/c/sk_paint.h" +#include "include/c/sk_path.h" +#include "include/c/sk_surface.h" + +static sk_surface_t* make_surface(int32_t w, int32_t h) { + sk_imageinfo_t* info = sk_imageinfo_new(w, h, RGBA_8888_SK_COLORTYPE, + PREMUL_SK_ALPHATYPE, NULL); + sk_surface_t* result = sk_surface_new_raster(info, NULL); + sk_imageinfo_delete(info); + return result; +} + +static void emit_png(const char* path, sk_surface_t* surface) { + sk_image_t* image = sk_surface_new_image_snapshot(surface); + sk_data_t* data = sk_image_encode(image); + sk_image_unref(image); + FILE* f = fopen(path, "wb"); + fwrite(sk_data_get_data(data), sk_data_get_size(data), 1, f); + fclose(f); + sk_data_unref(data); +} + +void draw(sk_canvas_t* canvas) { + sk_paint_t* fill = sk_paint_new(); + sk_paint_set_color(fill, sk_color_set_argb(0xFF, 0x00, 0x00, 0xFF)); + sk_canvas_draw_paint(canvas, fill); + + sk_paint_set_color(fill, sk_color_set_argb(0xFF, 0x00, 0xFF, 0xFF)); + sk_rect_t rect; + 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, sk_color_set_argb(0xFF, 0xFF, 0x00, 0x00)); + sk_paint_set_antialias(stroke, true); + sk_paint_set_stroke(stroke, true); + sk_paint_set_stroke_width(stroke, 5.0f); + + sk_pathbuilder_t* path_builder = sk_pathbuilder_new(); + sk_pathbuilder_move_to(path_builder, 50.0f, 50.0f); + sk_pathbuilder_line_to(path_builder, 590.0f, 50.0f); + sk_pathbuilder_cubic_to(path_builder, -490.0f, 50.0f, 1130.0f, 430.0f, 50.0f, 430.0f); + sk_pathbuilder_line_to(path_builder, 590.0f, 430.0f); + + sk_path_t* path = sk_pathbuilder_detach_path(path_builder); + sk_canvas_draw_path(canvas, path, stroke); + + sk_paint_set_color(fill, sk_color_set_argb(0x80, 0x00, 0xFF, 0x00)); + sk_rect_t rect2; + rect2.left = 120.0f; + rect2.top = 120.0f; + rect2.right = 520.0f; + rect2.bottom = 360.0f; + sk_canvas_draw_oval(canvas, &rect2, fill); + + sk_pathbuilder_delete(path_builder); + sk_path_delete(path); + sk_paint_delete(stroke); + sk_paint_delete(fill); +} + +extern "C" { +int do_draw(); +} +int do_draw() { + sk_surface_t* surface = make_surface(640, 480); + sk_canvas_t* canvas = sk_surface_get_canvas(surface); + draw(canvas); + emit_png("skia-c-example.png", surface); + sk_surface_unref(surface); + return 0; +} + diff --git a/test/testprog.c b/test/testprog.c new file mode 100644 index 0000000..cd25d0e --- /dev/null +++ b/test/testprog.c @@ -0,0 +1,7 @@ +extern int do_draw(); + +int main() { + do_draw(); + return 0; +} + diff --git a/ve-root b/ve-root new file mode 160000 index 0000000..4b32eeb --- /dev/null +++ b/ve-root @@ -0,0 +1 @@ +Subproject commit 4b32eeb8a792a7d8859313b32282c924024251ef