diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2be88536..59b63028 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -83,7 +83,7 @@ jobs: path: ios android: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - name: Check Out Repo uses: actions/checkout@v3 @@ -99,18 +99,16 @@ jobs: key: third-party-android-${{ hashFiles('DEPS') }}-${{ hashFiles('vendor.json') }} restore-keys: third-party-android- - - uses: seanmiddleditch/gha-setup-ninja@master - - name: Run depsync run: | npm install depsync -g depsync - shell: bash - uses: nttld/setup-ndk@v1 id: setup-ndk with: ndk-version: r19c + link-to-sdk: true local-cache: true - uses: actions/setup-java@v3 @@ -123,8 +121,6 @@ jobs: run: | cd android ./gradlew assembleRelease -Parm64-only - env: - NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - name: Save Third-Party Cache if: ${{ (github.event_name == 'push') && (steps.third-party-cache.outputs.cache-hit != 'true') }} @@ -139,10 +135,10 @@ jobs: uses: actions/upload-artifact@v3 with: name: android_build - path: android/app/build + path: android web: - runs-on: macos-latest + runs-on: windows-latest steps: - name: Check Out Repo uses: actions/checkout@v3 @@ -154,34 +150,9 @@ jobs: uses: actions/cache/restore@v3 with: path: | - /usr/local/Cellar/ninja - /usr/local/Cellar/icu4c - /usr/local/bin/ninja - /usr/local/Cellar/yasm - /usr/local/bin/yasm - /usr/local/Cellar/emsdk - /usr/local/bin/em++ - /usr/local/bin/em-config - /usr/local/bin/emar - /usr/local/bin/embuilder - /usr/local/bin/emcc - /usr/local/bin/emcmake - /usr/local/bin/emconfigure - /usr/local/bin/emdump - /usr/local/bin/emdwp - /usr/local/bin/emmake - /usr/local/bin/emnm - /usr/local/bin/emrun - /usr/local/bin/emprofile - /usr/local/bin/emscons - /usr/local/bin/emsize - /usr/local/bin/emstrip - /usr/local/bin/emsymbolizer - /usr/local/bin/emcc.py - /usr/local/bin/emcmake.py - /usr/local/bin/emar.py + web/emsdk web/node_modules - key: tgfx-environment-web-20231129 + key: tgfx-environment-web-20231130 restore-keys: tgfx-environment-web- - name: Get Third-Party Cache @@ -193,16 +164,27 @@ jobs: key: third-party-web-${{ hashFiles('DEPS') }}-${{ hashFiles('vendor.json') }} restore-keys: third-party-web- + - name: Install Build Tools + if: ${{ (steps.environment-cache.outputs.cache-hit != 'true') }} + run: | + cd web + npm install + git clone https://github.com/emscripten-core/emsdk.git + cd emsdk + ./emsdk install 3.1.20 + ./emsdk activate 3.1.20 + shell: bash + - name: Run depsync run: | - chmod +x sync_deps.sh - ./sync_deps.sh + npm install depsync -g + depsync shell: bash - name: Build Web run: | cd web - npm install + emsdk/emsdk_env npm run build - name: Save Environment Cache @@ -210,34 +192,9 @@ jobs: uses: actions/cache/save@v3 with: path: | - /usr/local/Cellar/ninja - /usr/local/Cellar/icu4c - /usr/local/bin/ninja - /usr/local/Cellar/yasm - /usr/local/bin/yasm - /usr/local/Cellar/emsdk - /usr/local/bin/em++ - /usr/local/bin/em-config - /usr/local/bin/emar - /usr/local/bin/embuilder - /usr/local/bin/emcc - /usr/local/bin/emcmake - /usr/local/bin/emconfigure - /usr/local/bin/emdump - /usr/local/bin/emdwp - /usr/local/bin/emmake - /usr/local/bin/emnm - /usr/local/bin/emrun - /usr/local/bin/emprofile - /usr/local/bin/emscons - /usr/local/bin/emsize - /usr/local/bin/emstrip - /usr/local/bin/emsymbolizer - /usr/local/bin/emcc.py - /usr/local/bin/emcmake.py - /usr/local/bin/emar.py + web/emsdk web/node_modules - key: tgfx-environment-web-20231129 + key: tgfx-environment-web-20231130 - name: Save Third-Party Cache if: ${{ (github.event_name == 'push') && (steps.third-party-cache.outputs.cache-hit != 'true') }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 29496552..11f7f53b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,9 +32,14 @@ elseif (NOT ANDROID) option(TGFX_USE_WEBP_ENCODE "Enable embedded WEBP encoding support" ON) endif () -string(FIND ${CMAKE_COMMAND} "/CLion.app/" CLionPosition) + +if ($ENV{CLION_IDE}) + set(CLION_IDE ON) +else () + set(CLION_IDE OFF) +endif () get_directory_property(HasParent PARENT_DIRECTORY) -if (MACOS AND CLionPosition GREATER -1 AND NOT HasParent) +if (MACOS AND CLION_IDE AND NOT HasParent) # CLion project needs test targets. option(TGFX_BUILD_TESTS "Build tgfx tests" ON) endif () diff --git a/DEPS b/DEPS index 7cec5b57..3b7bdd60 100644 --- a/DEPS +++ b/DEPS @@ -7,7 +7,7 @@ "common": [ { "url": "${PAG_GROUP}/vendor_tools.git", - "commit": "46eb9e91897055bc42e8b86b50cf8d7232f02dc4", + "commit": "2250e9dadc86680ce4fb1c763b58995768040037", "dir": "third_party/vendor_tools" }, { diff --git a/README.md b/README.md index 90c65572..936db88c 100644 --- a/README.md +++ b/README.md @@ -115,8 +115,9 @@ necessary steps to configure your development environment. ### Android Demo The android demo project requires the **Android NDK**. We recommend using the **19.2.5345600** -version, which has been fully tested with the tgfx library. You can download it from -[NDK Downloads](https://developer.android.com/ndk/downloads) or by Android Studio. +version, which has been fully tested with the tgfx library. If you open the project with Android +Studio, it will automatically download the NDK during Gradle synchronization. Alternatively, you +can download it from the [NDK Downloads](https://developer.android.com/ndk/downloads) page. If you choose to manually download the Android NDK, please extract it to the default location. On macOS, this would be: @@ -131,8 +132,7 @@ On Windows, it would be: C:\Users\yourname\AppData\Local\Android\Sdk\ndk\19.2.5345600 ``` -Alternatively, you can set one of -the following environment variables for tgfx to locate the NDK: +Alternatively, you can set one of the following environment variables for tgfx to locate the NDK: ``` ["ANDROID_NDK_HOME", "ANDROID_NDK_ROOT", "ANDROID_NDK", "NDK_HOME", "NDK_ROOT", "NDK_PATH"] @@ -209,10 +209,10 @@ At last, launch XCode and open the `mac/Hello2D.xcworkspace`. You'll be ready to The web demo project requires the **Emscripten SDK**. You can download and install it from the [official website](https://emscripten.org/). We recommend using the **3.1.20** version, which has been fully tested with the tgfx library. If you are on macOS, you can also install it -using the following command: +using the following script: ``` -brew install emscripten +web/script/install-emscripten.sh ``` To begin, navigate to the `web/` directory and execute the following command to install the diff --git a/drawers/src/SimpleText.cpp b/drawers/src/SimpleText.cpp index 96a48037..ba135700 100644 --- a/drawers/src/SimpleText.cpp +++ b/drawers/src/SimpleText.cpp @@ -39,20 +39,19 @@ void SimpleText::onDraw(tgfx::Canvas* canvas, const drawers::AppHost* host) cons auto oldMatrix = canvas->getMatrix(); canvas->concat(matrix); tgfx::Paint paint = {}; + paint.setColor({1.0f, 1.0f, 1.0f, 1.0f}); + paint.setStyle(tgfx::PaintStyle::Stroke); + paint.setStrokeWidth(2 * scale); + canvas->drawSimpleText(text, 0, 0, font, paint); + paint.setStyle(tgfx::PaintStyle::Fill); tgfx::Color cyan = {0.0f, 1.0f, 1.0f, 1.0f}; tgfx::Color magenta = {1.0f, 0.0f, 1.0f, 1.0f}; tgfx::Color yellow = {1.0f, 1.0f, 0.0f, 1.0f}; auto startPoint = tgfx::Point::Make(0.0f, 0.0f); auto endPoint = tgfx::Point::Make(screenWidth, 0.0f); - auto shader = - tgfx::Shader::MakeLinearGradient(startPoint, endPoint, {cyan, magenta, yellow}, {}); + auto shader = tgfx::Shader::MakeLinearGradient(startPoint, endPoint, {cyan, magenta, yellow}, {}); paint.setShader(shader); canvas->drawSimpleText(text, 0, 0, font, paint); - paint.setShader(nullptr); - paint.setColor({1.0f, 1.0f, 1.0f, 1.0f}); - paint.setStyle(tgfx::PaintStyle::Stroke); - paint.setStrokeWidth(scale); - canvas->drawSimpleText(text, 0, 0, font, paint); canvas->setMatrix(oldMatrix); std::string emojis = "🤡👻🐠🤩😃🤪🙈🙊🐒"; diff --git a/test/baseline/version.json b/test/baseline/version.json index cb29ad25..ccd359ae 100644 --- a/test/baseline/version.json +++ b/test/baseline/version.json @@ -27,7 +27,7 @@ "GridBackground": "2ae64df", "ImageWithMipmap": "5a1fb11", "ImageWithShadow": "5a1fb11", - "SimpleText": "2ae64df", + "SimpleText": "46b2963", "SweepGradient": "5a1fb11" }, "ImageReaderTest": { diff --git a/update_baseline.sh b/update_baseline.sh index e463299f..2c09e651 100755 --- a/update_baseline.sh +++ b/update_baseline.sh @@ -42,9 +42,9 @@ echo $CMAKE_COMMAND if [[ $1 == "1" ]]; then - $CMAKE_COMMAND -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -g -O0" -DTGFX_USE_SWIFTSHADER=ON -DTGFX_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ../ + $CMAKE_COMMAND -DCMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage -g -O0" -DTGFX_USE_SWIFTSHADER=ON -DTGFX_BUILD_TESTS=ON -DTGFX_SKIP_BASELINE_CHECK=ON -DCMAKE_BUILD_TYPE=Debug ../ else - $CMAKE_COMMAND -DTGFX_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ../ + $CMAKE_COMMAND -DTGFX_BUILD_TESTS=ON -DTGFX_SKIP_BASELINE_CHECK=ON -DCMAKE_BUILD_TYPE=Debug ../ fi $CMAKE_COMMAND --build . --target UpdateBaseline -- -j 12 diff --git a/web/.gitignore b/web/.gitignore index 8af07932..faa74870 100644 --- a/web/.gitignore +++ b/web/.gitignore @@ -4,4 +4,8 @@ types *.js.map demo/*.js demo/wasm -src/wasm \ No newline at end of file +demo/build-hello2d +demo/.hello2d.wasm.md5 +src/wasm +emsdk/ + diff --git a/web/demo/hello2d.hash b/web/demo/hello2d.hash new file mode 100644 index 00000000..202e6154 --- /dev/null +++ b/web/demo/hello2d.hash @@ -0,0 +1,8 @@ +src/ +CMakeLists.txt +../../include/ +../../src/ +../../drawers/ +../../CMakeLists.txt +../../vendor.json +../../DEPS \ No newline at end of file diff --git a/web/package.json b/web/package.json index cf55282d..10ccc33a 100644 --- a/web/package.json +++ b/web/package.json @@ -10,8 +10,8 @@ "clean:tgfx": "rimraf lib/ types/", "clean": "npm run clean:tgfx && rimraf demo/build demo/wasm demo/*.js demo/*.map demo/cmake-build-*", "build:tgfx": "npm run clean:tgfx && tsc -p ./tsconfig.type.json && rollup -c ./script/rollup.tgfx.js", - "build": "node script/build.demo.js && npm run build:tgfx && rollup -c ./script/rollup.demo.js", - "build:debug": "node script/build.demo.js --debug && npm run build:tgfx && rollup -c ./script/rollup.demo.js", + "build": "node script/cmake.demo.js && npm run build:tgfx && rollup -c ./script/rollup.demo.js", + "build:debug": "node script/cmake.demo.js --debug && npm run build:tgfx && rollup -c ./script/rollup.demo.js", "dev": "npm run build:tgfx && rollup -c ./script/rollup.dev.js -w", "server": "http-server -p 8081 ../ -g -c-1 --cors -o web/demo" }, diff --git a/web/script/build.demo.js b/web/script/build.demo.js deleted file mode 100755 index 60fb6e54..00000000 --- a/web/script/build.demo.js +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env node -const childProcess = require('child_process'); -const os = require('os'); -const fs = require('fs'); -const path = require('path'); - -childProcess.execSync("depsync"); - -let sourceDir = path.resolve(__dirname, "../demo"); -let buildDir = path.resolve(sourceDir, "cmake-build-release"); -let buildType = "Release"; -let args = process.argv.slice(2); -if (args.indexOf("-d") !== -1 || args.indexOf("--debug") !== -1) { - buildDir = path.resolve(sourceDir, "cmake-build-debug"); - buildType = "Debug"; -} -let options = { - shell: os.platform() === "win32" ? "cmd.exe" : true, - maxBuffer: 50 * 1024 * 1024 -} -let currentVersion = childProcess.execSync("emcc --version", options).toString(); -if (fs.existsSync(buildDir)) { - let version = ""; - let versionFile = path.resolve(buildDir, "emscripten_version.txt"); - try { - version = fs.readFileSync(versionFile, "utf-8").toString(); - } catch (e) { - } - if (version !== currentVersion) { - try { - fs.rmSync(buildDir, {recursive: true, force: true}); - } catch (e) { - } - } -} -let wasmDir = path.join(sourceDir, "wasm"); -try { - fs.rmSync(wasmDir, {recursive: true, force: true}); - fs.mkdirSync(wasmDir); -} catch (e) { -} -let cmd = "emcmake cmake -S " + sourceDir + " -B " + buildDir + " -G Ninja -DCMAKE_BUILD_TYPE=" + buildType; -process.stdout.write(cmd); -options.stdio = "inherit"; -childProcess.execSync(cmd, options); -try { - fs.writeFileSync(buildDir + "/emscripten_version.txt", currentVersion); -} catch (err) { - console.error(err); -} -cmd = "cmake --build " + buildDir + " --target hello2d"; -process.stdout.write(cmd); -childProcess.execSync(cmd, options); -fs.copyFileSync(buildDir + "/hello2d.js", path.join(wasmDir, "hello2d.js")); -fs.copyFileSync(buildDir + "/hello2d.wasm", path.join(wasmDir, "hello2d.wasm")); - diff --git a/web/script/cmake.demo.js b/web/script/cmake.demo.js new file mode 100755 index 00000000..f75563a2 --- /dev/null +++ b/web/script/cmake.demo.js @@ -0,0 +1,12 @@ +#!/usr/bin/env node +process.chdir(__dirname); + +process.argv.push("-s"); +process.argv.push("../demo"); +process.argv.push("-o"); +process.argv.push("../demo"); +process.argv.push("-p"); +process.argv.push("web"); +process.argv.push("hello2d"); +require("../../build_tgfx"); +