-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chrome's Native Client backend implementation
- Loading branch information
Showing
37 changed files
with
2,265 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
================================================================================ | |||
Simple DirectMedia Layer for Native Client | |||
================================================================================ | |||
|
|||
Requirements: | |||
|
|||
* Native Client SDK (https://developer.chrome.com/native-client), | |||
(tested with Pepper version 33 or higher). | |||
|
|||
The SDL backend for Chrome's Native Client has been tested only with the PNaCl | |||
toolchain, which generates binaries designed to run on ARM and x86_32/64 | |||
platforms. This does not mean it won't work with the other toolchains! | |||
|
|||
================================================================================ | |||
Building SDL for NaCl | |||
================================================================================ | |||
|
|||
Set up the right environment variables (see naclbuild.sh), then configure SDL with: | |||
|
|||
configure --host=pnacl --prefix some/install/destination | |||
|
|||
Then "make". | |||
|
|||
As an example of how to create a deployable app a Makefile project is provided | |||
in test/nacl/Makefile, which includes some monkey patching of the common.mk file | |||
provided by NaCl, without which linking properly to SDL won't work (the search | |||
path can't be modified externally, so the linker won't find SDL's binaries unless | |||
you dump them into the SDK path, which is inconvenient). | |||
Also provided in test/nacl is the required support file, such as index.html, | |||
manifest.json, etc. | |||
|
|||
|
|||
================================================================================ | |||
Running tests | |||
================================================================================ | |||
|
|||
Due to the nature of NaCl programs, building and running SDL tests is not as | |||
straightforward as one would hope. The script naclbuild.sh in build-scripts | |||
automates the process and should serve as a guide for users of SDL trying to build | |||
their own applications. | |||
|
|||
Basic usage: | |||
|
|||
./naclbuild.sh path/to/pepper/toolchain (i.e. ~/naclsdk/pepper_35) | |||
|
|||
This will build testgles2.c by default. | |||
|
|||
If you want to build a different test, for example testrendercopyex.c: | |||
|
|||
SOURCES=~/sdl/SDL/test/testrendercopyex.c ./naclbuild.sh ~/naclsdk/pepper_35 | |||
|
|||
Once the build finishes, you have to serve the contents with a web server (the | |||
script will give you instructions on how to do that with Python). | |||
|
|||
================================================================================ | |||
TODO - Known Issues | |||
================================================================================ | |||
* Audio backend is not usable yet. | |||
* Testing of all systems with a real application (something other than SDL's tests) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
#!/bin/bash | |||
if [ -z "$1" ] && [ -z "$NACL_SDK_ROOT" ]; then | |||
echo "Usage: ./naclbuild ~/nacl/pepper_33" | |||
echo "This will build SDL for Native Client, and testgles2.c as a demo" | |||
echo "You can set env vars CC, AR, LD and RANLIB to override the default PNaCl toolchain used" | |||
echo "You can set env var SOURCES to select a different source file than testgles2.c" | |||
exit 1 | |||
fi | |||
|
|||
if [ -n "$1" ]; then | |||
NACL_SDK_ROOT="$1" | |||
fi | |||
|
|||
CC="" | |||
|
|||
if [ -n "$2" ]; then | |||
CC="$2" | |||
fi | |||
|
|||
echo "Using SDK at $NACL_SDK_ROOT" | |||
|
|||
export NACL_SDK_ROOT="$NACL_SDK_ROOT" | |||
export CFLAGS="$CFLAGS -I$NACL_SDK_ROOT/include" | |||
|
|||
NCPUS="1" | |||
case "$OSTYPE" in | |||
darwin*) | |||
NCPU=`sysctl -n hw.ncpu` | |||
;; | |||
linux*) | |||
if [ -n `which nproc` ]; then | |||
NCPUS=`nproc` | |||
fi | |||
;; | |||
*);; | |||
esac | |||
|
|||
CURDIR=`pwd -P` | |||
SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )" | |||
BUILDPATH="$SDLPATH/build/nacl" | |||
TESTBUILDPATH="$BUILDPATH/test" | |||
SDL2_STATIC="$BUILDPATH/build/.libs/libSDL2.a" | |||
mkdir -p $BUILDPATH | |||
mkdir -p $TESTBUILDPATH | |||
|
|||
if [ -z "$CC" ]; then | |||
export CC="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-clang" | |||
fi | |||
if [ -z "$AR" ]; then | |||
export AR="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar" | |||
fi | |||
if [ -z "$LD" ]; then | |||
export LD="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar" | |||
fi | |||
if [ -z "$RANLIB" ]; then | |||
export RANLIB="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ranlib" | |||
fi | |||
|
|||
if [ -z "$SOURCES" ]; then | |||
export SOURCES="$SDLPATH/test/testgles2.c" | |||
fi | |||
|
|||
if [ ! -f "$CC" ]; then | |||
echo "Could not find compiler at $CC" | |||
exit 1 | |||
fi | |||
|
|||
|
|||
|
|||
|
|||
cd $BUILDPATH | |||
$SDLPATH/configure --host=pnacl --prefix $TESTBUILDPATH | |||
make -j$NCPUS CFLAGS="$CFLAGS -I./include" | |||
make install | |||
|
|||
if [ ! -f "$SDL2_STATIC" ]; then | |||
echo "Build failed! $SDL2_STATIC" | |||
exit 1 | |||
fi | |||
|
|||
echo "Building test" | |||
cp -f $SDLPATH/test/nacl/* $TESTBUILDPATH | |||
# Some tests need these resource files | |||
cp -f $SDLPATH/test/*.bmp $TESTBUILDPATH | |||
cp -f $SDLPATH/test/*.wav $TESTBUILDPATH | |||
cp -f $SDL2_STATIC $TESTBUILDPATH | |||
|
|||
# Copy user sources | |||
_SOURCES=($SOURCES) | |||
for src in "${_SOURCES[@]}" | |||
do | |||
cp $src $TESTBUILDPATH | |||
done | |||
export SOURCES="$SOURCES" | |||
|
|||
cd $TESTBUILDPATH | |||
make -j$NCPUS CONFIG="Release" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include" | |||
make -j$NCPUS CONFIG="Debug" CFLAGS="$CFLAGS -I$TESTBUILDPATH/include/SDL2 -I$SDLPATH/include" | |||
|
|||
echo | |||
echo "Run the test with: " | |||
echo "cd $TESTBUILDPATH;python -m SimpleHTTPServer" | |||
echo "Then visit http://localhost:8000 with Chrome" | |||
|
|||
cd $CURDIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.