Giter Club home page Giter Club logo

mimicry's Introduction

Mimicry

A simple crossplatform SDL2 + skia CMake build environment example/test. Based on simpleSDL (thank you so much!).

Tested to build and run successfully with:

  • Linux (Ubuntu): Clang
  • Android: Gradle + NDK
  • Windows: mingw-w64 or Visual Studio 2015

Table of contents:

  1. Getting started
    1. Requirements
    2. Clone
    3. Preparing skia
  2. Compilling
    1. Linux
    2. Android
    3. Windows
  3. Contributing

Getting started

WIP

Clone

WIP

Requirements

WIP

Preparing skia

The standard skia build does not have CMake compatibility so we will transform the build. Learn more about the skia build.

Step-by-step:

  1. Run python2 tools/git-sync-deps inside externals;

  2. Generate CMake project:

    bin/gn gen out/cmake --ide=json --json-ide-script=../../gn/gn_to_cmake.py --args='is_official_build=true'
    

    to build skia as a static library or

    bin/gn gen out/cmake --ide=json --json-ide-script=../../gn/gn_to_cmake.py --args='is_official_build=true is_component_build=true'
    

    to build skia as a dynamic library. To see all available arguments:

    bin/gn args out/cmake --list
    

    suggestion for Android build:

    bin/gn gen out/cmake --ide=json --json-ide-script=../../gn/gn_to_cmake.py --args='
             skia_use_system_libjpeg_turbo = false
             skia_use_system_libwebp = false
             skia_use_system_expat = false
             skia_use_system_libpng = false
             skia_use_system_freetype2 = false
             ndk="/home/you/Android/Sdk/ndk/21.3.6528147"
             target_os="android" 
             target_cpu="arm"
             is_debug=false
             is_component_build=true
             extra_cflags=["-O3"]
             skia_use_angle = false
             skia_use_icu = false
             skia_use_lua = false
             skia_use_opencl = false
             skia_use_piex = false
             skia_use_zlib = false
             skia_enable_tools = false
             skia_enable_pdf = false
             skia_use_gl = true
             skia_enable_skottie = false
             '
    

Compilling

WIP

Linux

Just run build.sh inside platforms folder.

or

Alternatively you can do something like this in the project root dir:

mkdir build/make_debug
cd build/make_debug
cmake -DCMAKE_BUILD_TYPE:STRING=Debug ../..
make

Android

Make sure you have NDK and CMake plugins installed on Android SDK (https://developer.android.com/studio/projects/add-native-code.html).

Step-by-step:

  1. Make sure you have installed:

    1. Android SDK Build Tools 30;
    2. NDK 21;
    3. Android CMake 10.
  2. Have the ANDROID_HOME environment variable;

  3. Copy all content from

    externals/SDL/android-project/app/src/main/java/org/libsdl/app
    

    and put it into

    platforms/android/android-app/src/main/java/org/libsdl/app/
    
  4. Pay attention to the skia build and see if all the arguments are in the arg.gn file. See build options here.

  5. Run gradlew assemble in platforms/android

    or

    Open the project in Android Studio and build using the IDE. NOTE: Make sure to open the platforms/android/ dir. Android studio can also open the root dir but it's not recognized as an android project.

The included Android Gradle CMake project is pretty much what Android Studio generates when you create a new empty app with native CMake support. Just pointing to the CMakeLists.txt in the project root.

Windows

WIP

Contributing

WIP

mimicry's People

Contributors

acmlira avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

sukovf

mimicry's Issues

Undefined reference to AHardwareBuffer

Android SDK NDK CMake skia SDL
30 21 10 chrome/m87 2.0.12

I had some problems when compiling skia with Android SDK 30. These were my build flags:

skia_use_system_libjpeg_turbo = false
skia_use_system_libwebp = false
skia_use_system_expat = false
skia_use_system_libpng = false
skia_use_system_freetype2 = false
ndk="/home/allan/Android/Sdk/ndk/21.3.6528147"
target_os="android" 
target_cpu="arm"
is_debug=false
is_component_build=true
extra_cflags=["-O3"]
skia_use_angle = false
skia_use_icu = false
skia_use_lua = false
skia_use_opencl = false
skia_use_piex = false
skia_use_zlib = false
skia_enable_tools = false
skia_enable_pdf = false
skia_use_gl = true
skia_enable_skottie = false

This was the error log:

../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:53: error: undefined reference to 'AHardwareBuffer_describe'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:74: error: undefined reference to 'AHardwareBuffer_acquire'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:78: error: undefined reference to 'AHardwareBuffer_release'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:78: error: undefined reference to 'AHardwareBuffer_release'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:117: error: undefined reference to 'AHardwareBuffer_acquire'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:125: error: undefined reference to 'AHardwareBuffer_release'
../../../../../../../../externals/skia/src/gpu/GrAHardwareBufferImageGenerator.cpp:125: error: undefined reference to 'AHardwareBuffer_release'
../../../../../../../../externals/skia/src/image/SkImage_Gpu.cpp:668: error: undefined reference to 'AHardwareBuffer_describe'
../../../../../../../../externals/skia/src/image/SkSurface_Gpu.cpp:700: error: undefined reference to 'AHardwareBuffer_describe'

clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

These errors are generated by the AHardwareBuffer class I didn't find skia build arguments that solve this and as this is only compiled with versions greater than 26 of the Android API, backing down the version was also not possible since the SDL requires that the API be greater than 26 to fit as well. I had to change the source code of skia to compile. For each file mentioned in the log I had to change the following line:

#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26

to:

#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ > 30

This solves the problem but is not ideal

No type named MakeGL in GrDirectContext (or GrContext)

Android SDK NDK CMake skia SDL
30 21 10 chrome/m87 2.0.12

During the compilation of the application I realized that GrDirectContext and GrContext hasn't type named MakeGL. The skia build flags were these:

skia_use_system_libjpeg_turbo = false
skia_use_system_libwebp = false
skia_use_system_expat = false
skia_use_system_libpng = false
skia_use_system_freetype2 = false
ndk="/home/allan/Android/Sdk/ndk/21.3.6528147"
target_os="android" 
target_cpu="arm"
is_debug=false
is_component_build=true
extra_cflags=["-O3"]
skia_use_angle = false
skia_use_icu = false
skia_use_lua = false
skia_use_opencl = false
skia_use_piex = false
skia_use_zlib = false
skia_enable_tools = false
skia_enable_pdf = false
skia_use_gl = true
skia_enable_skottie = false

This was the error log:

../../../../../../../../sources/main.cpp:203:55: error: no type named 'MakeGL' in 'GrDirectContext'
      sk_sp<GrDirectContext> grContext(GrDirectContext::MakeGL(interface));
                                       ~~~~~~~~~~~~~~~~~^
../../../../../../../../sources/main.cpp:203:37: warning: parentheses were disambiguated as a function declaration [-Wvexing-parse]
      sk_sp<GrDirectContext> grContext(GrDirectContext::MakeGL(interface));
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../../../../../../../sources/main.cpp:203:38: note: add a pair of parentheses to declare a variable
      sk_sp<GrDirectContext> grContext(GrDirectContext::MakeGL(interface));
                                       ^
                                       (
1 warning and 1 error generated.
[2/49] Building CXX object externals/skia/out/cmake/CMakeFiles/skia.dir/__/__/src/core/SkDeferredDisplayList.cpp.o

Let's see the skia code snippet:

#ifdef SK_GL
    /**
     * Creates a GrDirectContext for a backend context. If no GrGLInterface is provided then the
     * result of GrGLMakeNativeInterface() is used if it succeeds.
     */
    static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
    static sk_sp<GrDirectContext> MakeGL(sk_sp<const GrGLInterface>);
    static sk_sp<GrDirectContext> MakeGL(const GrContextOptions&);
    static sk_sp<GrDirectContext> MakeGL();
#endif

Apparently the SK_GL flag is not being set correctly. My workaround was just adding -DCMAKE_CXX_FLAGS="-DSK_GL" to my build script.

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.