SKIA for Linux ARM

3,066 views
Skip to first unread message

jam7...@gmail.com

unread,
Mar 25, 2016, 4:47:29 AM3/25/16
to skia-discuss
Does SKIA support Linux ARM?
If yes, can you please provide the steps.

Hal Canary

unread,
Mar 25, 2016, 12:25:57 PM3/25/16
to skia-discuss

Yes. ARM Linux is not too different from ARM Android, which is where Skia is used the most.

I have built a Skia for ARM Linux with a  cross-compiler before. The hard part was making sure we had all of the dependencies we needed. 

What system are you targeting?  If it is a full distribution like Raspbian, it should be easier.

This morning, I plugged in my Raspberry Pi 2B (with Raspbian OS) and did the following:

sudo apt-get install -y build-essential ninja-build libfontconfig-dev libglu1-mesa-dev
# make sure you have at least two gigs of storage git clone 'https://chromium.googlesdu -shource.com/chromium/tools/depot_tools.git'
export PATH="${PWD}/depot_tools:${PATH}"
git clone 'https://skia.googlesource.com/skia'
cd skia
GYP_GENERATORS=ninja GYP_DEFINES="skia_arch_type=arm" bin/sync-and-gyp
/usr/bin/ninja -C out/Debug dm
# go get some coffee  then some lunch.
out/Debug/dm --gpu 0

I haven't got Ganesh to work yet.

Joe Gregorio

unread,
Mar 25, 2016, 12:31:13 PM3/25/16
to skia-discuss
The GL support on the rPi is very new and still experimental. I did succeed in getting SampleApp to compile and link with GPU support, and it does run, but running some samples in GPU mode will either crash SampleApp, or freeze the rPi entirely.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Rene Hollander

unread,
Dec 26, 2016, 3:39:11 PM12/26/16
to skia-discuss
Since skia moved to gn as a meta build system, I don't even make it past the compilation stage. Building on the Raspberry itself is impossible, since gn is not provided with an arm build. I tried cross compiling, but I am failing with setting the correct toolchain to be used by gn.
I tried using linaro gcc 6 for arm to build by setting the following flags when generating the ninja build files:
gn gen out/Static --args='is_official_build=true target_os="linux" target_cpu="arm" ar="/home/vagrant/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ar" cc="/home/vagrant/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++" cxx="/home/vagrant/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++"'
As soon as I try to compile, gcc throws the following error:
arm-linux-gnueabihf-g++: error: unrecognized command line option '-momit-leaf-frame-pointer'; did you mean '-fomit-frame-pointer'?

I really don't know what to do now. I tried so many different things, but I just can't get it to compile...

Did somebody else succeed in building on ARM linux?

Hal Canary

unread,
Dec 26, 2016, 3:48:22 PM12/26/16
to skia-discuss

I'm taking the day off today, but I'll take a look at this tomorrow morning. 


--

Mike Klein

unread,
Dec 27, 2016, 12:11:00 AM12/27/16
to skia-discuss
We do not continuously test that platform, so it is always likely to be broken. You need some gumption to build Skia on platforms that we don't test.

In this case, you seem to be set up fine, but it looks like your compiler doesn't like -momit-leaf-frame-pointer.  A quick scan through docs online makes me think GCC treats this flag as x86-only, while Clang supports it on any platform.  It's not a very important flag.  You may want to
  • git grep for it and remove it from your local .gn files, or 
  • replace it with -fomit-frame-pointer as it suggests, which is more aggressive but fine, or 
  • try Clang.

Hal Canary

unread,
Dec 27, 2016, 11:53:41 AM12/27/16
to skia-d...@googlegroups.com
Okay, I was able to cross-compile libskia.a from ubuntu-x86 to rasbian-armhf.

I installed clang-3.8 via apt and symlinked it to bin/clang.  Here's my args.gn file:

    target_cpu = "arm"
    cc = "clang"
    cxx = "clang++"
    skia_enable_gpu = false
    skia_use_libjpeg_turbo = false
    extra_cflags = [
      "-target", "armv7a-linux",
      "-mfloat-abi=hard",
      "-mfpu=neon",
      "--sysroot=/home/hal/PiRoot",
      "-I/home/hal/PiRoot/usr/include/c++/4.9",
      "-I/home/hal/PiRoot/usr/include/arm-linux-gnueabihf",
      "-I/home/hal/PiRoot/usr/include/arm-linux-gnueabihf/c++/4.9",
    ]

On my RPi, I installed 'libc\+\+1', 'libgl1-mesa-dev', and 'libfontconfig1-dev' to get the proper headers.  I then mounted the RPi's root filesystem at ~/PiRoot before running `ninja -C out/pi skia`.

Then I copied libskia.a over to the RPi's filesystem and made a shallow clone of the Skia repositoty there.  I rebooted the rpi.

    $ clang-3.7 -c -Iskia/include/c \
      skia/experimental/c-api-example/skia-c-example.c
    $ clang++-3.7 skia-c-example.o libskia.a \
      -lpthread -lfreetype -lfontconfig -lm
    $ ./a.out
    $ xdg-open skia-c-example.png

So the library seems to work on the target system.



To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Rene Hollander

unread,
Dec 27, 2016, 1:44:27 PM12/27/16
to skia-discuss
May I ask, where to put the args.gn file you specified and how to run gn to actually use it? I just put it into the skia root directory and ran 'gn gen out/pi --args='is_official_build=true''.
It obviously doesn't work, because running ninja yields the following:
FAILED: obj/src/ports/fontmgr_android.SkFontMgr_android.o 
c++ -MMD -MF obj/src/ports/fontmgr_android.SkFontMgr_android.o.d -DNDEBUG -DSK_SAMPLES_FOR_X -DSK_GAMMA_APPLY_TO_A8 -DSK_INTERNAL -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 -DSKIA_IMPLEMENTATION=1 -DXML_STATIC -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/effects -I../../include/gpu -I../../include/gpu/gl -I../../include/images -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/xml -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/effects/gradients -I../../src/fonts -I../../src/gpu -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../third_party/etc1 -I../../third_party/gif -I../../third_party/ktx -I../../third_party/externals/expat/lib -I/usr/include/freetype2 -fstrict-aliasing -fPIC -fvisibility=hidden -Werror -Wall -Wextra -Winit-self -Wpointer-arith -Wsign-compare -Wvla -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-unused-parameter -O3 -momit-leaf-frame-pointer -std=c++11 -fno-threadsafe-statics -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Wnon-virtual-dtor -c ../../src/ports/SkFontMgr_android.cpp -o obj/src/ports/fontmgr_android.SkFontMgr_android.o
In file included from ../../src/ports/SkFontMgr_android.cpp:13:0:
../../src/ports/SkFontHost_FreeType_common.h:20:22: fatal error: ft2build.h: No such file or directory
 #include <ft2build.h>
                      ^
compilation terminated.
[43/1162] compile ../../src/ports/SkFontConfigInterface_direct_factory.cpp
FAILED: obj/src/ports/fontmgr_fontconfig.SkFontConfigInterface_direct_factory.o 
c++ -MMD -MF obj/src/ports/fontmgr_fontconfig.SkFontConfigInterface_direct_factory.o.d -DNDEBUG -DSK_SAMPLES_FOR_X -DSK_GAMMA_APPLY_TO_A8 -DSK_INTERNAL -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 -DSKIA_IMPLEMENTATION=1 -I../../include/android -I../../include/c -I../../include/codec -I../../include/config -I../../include/core -I../../include/effects -I../../include/gpu -I../../include/gpu/gl -I../../include/images -I../../include/pathops -I../../include/ports -I../../include/svg -I../../include/utils -I../../include/utils/mac -I../../include/xml -I../../include/private -I../../src/c -I../../src/codec -I../../src/core -I../../src/effects -I../../src/effects/gradients -I../../src/fonts -I../../src/gpu -I../../src/image -I../../src/images -I../../src/lazy -I../../src/opts -I../../src/pathops -I../../src/pdf -I../../src/ports -I../../src/sfnt -I../../src/sksl -I../../src/utils -I../../src/utils/win -I../../third_party/etc1 -I../../third_party/gif -I../../third_party/ktx -I/usr/include/freetype2 -fstrict-aliasing -fPIC -fvisibility=hidden -Werror -Wall -Wextra -Winit-self -Wpointer-arith -Wsign-compare -Wvla -Wno-deprecated-declarations -Wno-maybe-uninitialized -Wno-unused-parameter -O3 -momit-leaf-frame-pointer -std=c++11 -fno-threadsafe-statics -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Wnon-virtual-dtor -c ../../src/ports/SkFontConfigInterface_direct_factory.cpp -o obj/src/ports/fontmgr_fontconfig.SkFontConfigInterface_direct_factory.o
In file included from ../../src/ports/SkFontConfigInterface_direct_factory.cpp:8:0:
../../src/ports/SkFontConfigInterface_direct.h:12:35: fatal error: fontconfig/fontconfig.h: No such file or directory
 #include <fontconfig/fontconfig.h>
                                   ^
compilation terminated.

Also checking the toolchain.ninja file in out/pi uses the cc and c++ commands for compilation instead of clang.

Just to test it, I also put a copy of args.gn into the out/pi directory and tried to rerun gn without the --args flag. That did not work either.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

Rene Hollander

unread,
Dec 27, 2016, 1:47:37 PM12/27/16
to skia-discuss
I forgot to add, that I installed the needed libraries on my Raspberry Pi 3 and mounted the sysroot correctly. But because the fontconfig and freetype headers aren't found, I suspect that something with the usage of my args.gn is wrong.

Hal Canary

unread,
Dec 27, 2016, 2:34:25 PM12/27/16
to skia-d...@googlegroups.com

cd ~/src/skia
gn gen out/pi
cat <<-EOF > out/pi/args.gn

target_cpu = "arm"
cc = "clang"

cxx = "clang++"
skia_enable_gpu = false
skia_use_libjpeg_turbo = false
extra_cflags = [
  "-target", "armv7a-linux",
  "-mfloat-abi=hard",
  "-mfpu=neon",

  "--sysroot=${HOME}/PiRoot",
  "-I${HOME}/PiRoot/usr/include/c++/4.9",
  "-I${HOME}/PiRoot/usr/include/arm-linux-gnueabihf",
  "-I${HOME}/PiRoot/usr/include/arm-linux-gnueabihf/c++/4.9",
]
EOF
ninja -C out/pi skia



To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Rene Hollander

unread,
Dec 27, 2016, 3:39:17 PM12/27/16
to skia-discuss
Thanks, it works now.

I had to run "gn gen out/pi" after creating the args.gn file to get it recognized. I also had to install libfreetype6-dev to the computer running the compilation. Maybe you can get around that, by adding more include paths pointing to the appropriate dirs on the sysroot of the Raspberry Pi in the args.gn.

Hal Canary

unread,
Dec 27, 2016, 5:16:46 PM12/27/16
to skia-discuss

Yeah, I probably was using the wrong headers. You can use `dpkg-query -L libfreetype-dev` to find out what directory they were installed in.

Mike Klein

unread,
Dec 27, 2016, 11:32:45 PM12/27/16
to skia-discuss
I think it sounds pretty neat to have a Raspberry Pi bot.  ARMv7 and especially ARMv8 are really important targets.

It should be easy to cross compile with the proper clang --target, and if not, even easier to do on device.  I'd be happy to help to make such a target easy to specify in GN.

Hal Canary

unread,
Dec 28, 2016, 7:43:02 AM12/28/16
to skia-discuss

I'll take a look at getting dm and nanobench compiling.

Rene Hollander

unread,
Dec 28, 2016, 12:18:06 PM12/28/16
to skia-discuss
I am currently in the process of getting the GPU support running.
Because I don't want to use X and draw directly on the screen, I patched the generated build files like so:
Every occurrance of 'glx' in 'out/pi/obj/skia.ninja' and 'out/pi/obj/gpu.ninja' is replaced with 'egl'. After I did
that I was able to compile and link the library on my pi without problems.
After that I created a sample application that creates the needed egl parts (display, surface, context) and sets
them up.

I then needed to patch the 'GrGLCreateNativeInterface_egl.cpp' file, because eglGetProcAddress returns a NULL
pointer for glGetString, that is needed for the GrGLAssembleInterface.
That also works and I get a valid, at least as valid as I can tell, GrGLInterface* from GrGLCreateNativeInterface(); (main.cpp:167)
But when I create the context I get an exception:
terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call

I traced this exception and it occurs in "src/gpu/gl/GrGLGpu.cpp:188":
GrGLContext* glContext = GrGLContext::Create(glInterface.get(), options);

glInterface.get() throws the error, and I don't know why. The value of glInterface just before the exception is:
(gdb) p glInterface
$7 = {fPtr = 0x7d8918}

Is there something that I am missing, or is this a bug?

Rene Hollander

unread,
Dec 28, 2016, 12:18:44 PM12/28/16
to skia-discuss

Rene Hollander

unread,
Dec 28, 2016, 5:04:37 PM12/28/16
to skia-discuss
I finally figured it out.
eglGetProcAddress doesn't work for non extension functions, so I copied the code from 'GrGLCreateNativeInterface_android.cpp' to my own file, 'GrGLCreateNativeInterface_raspberrypi.cpp'. At least the case for 'glGetShaderPrecisionFormat' was missing, so I wrote a little script that extracts the functions from the gl2.h Header and creates me the needed if statement.
After that I "fixed" the build system to use the GrGLCreateNativeInterface_raspberrypi.cpp file instead of the one for X (I have to look into changing the gn files for that)

But if I run it, I get an exception, that a shader compilation failed:
ERROR:LEX/PARSE-2 (vertex shader, line 11) Undefined identifier../../src/gpu/gl/builders/GrGLProgramBuilder.cpp:207: fatal error: "Error linking program"

Code of the shader (extracted with GDB)
#version 100

precision highp float;
uniform highp vec4 urtAdjustment_Stage0;
attribute highp vec2 inPosition;
attribute mediump vec4 inColor;
varying mediump vec4 vinColor_Stage0;
void main() {
    vinColor_Stage0 = inColor;
    vec2 pos2 = inPosition;
    gl_Position = vec4(pos2.x * urtAdjustment_Stage0.x + urtAdjustment_Stage0.y, pos2.y * urtAdjustment_Stage0.z + urtAdjustment_Stage0.w, 11.00000000000002, -nan.0);
}

I am pretty sure, that -nan.0 is not a correct number. Do you have some pointers on how to actually debug that?

I updated the code to reflect my recent changes: https://gist.github.com/ReneHollander/a4e85ac0ea42c6413693ec4d6fa23ad4

Am Mittwoch, 28. Dezember 2016 18:18:06 UTC+1 schrieb Rene Hollander:

Rene Hollander

unread,
Dec 29, 2016, 11:09:04 AM12/29/16
to skia-discuss
I did some more testing and also played with the context and surface setup. I am able to do a canvas->clear(SK_ColorBLUE) to get a blue screen, but as soon as I draw something, for example a rectangle, the application crashes during shader compilation with the same issue as in my previous post.
For the context and surface setup, I am using the glfw example (https://github.com/google/skia/blob/master/experimental/GLFWTest/glfw_main.cpp), because the code on the website (https://skia.org/user/api/canvas) for the GPU was not even able to color the screen.

Reply all
Reply to author
Forward
0 new messages