From 5cba584f622a3f4b771248ffbe22a50328368667 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 20 Sep 2024 19:46:17 +0100 Subject: [PATCH 01/71] Make GL version setting specific to Mac OS only Refining earlier change (#214). It turns out that Xvfb's GL behavior on Linux differ depending on whether there is actual graphic hardware or entirely headless. The Apple GL settings works on Xvfb on my computer (AMD Radeon R5 Graphics), but fails in github headless CI. Fixes #266 --- docs/tutorial/canvas.rst | 18 ++++++++++-------- tests/conftest.py | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/docs/tutorial/canvas.rst b/docs/tutorial/canvas.rst index 16eb1791..ff658761 100644 --- a/docs/tutorial/canvas.rst +++ b/docs/tutorial/canvas.rst @@ -91,10 +91,11 @@ The following example uses glfw package to create an OpenGL context. Install glfw.window_hint(glfw.VISIBLE, glfw.FALSE) glfw.window_hint(glfw.STENCIL_BITS, 8) # see https://www.glfw.org/faq#macos - glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) - glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) - glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) - glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) + if sys.platform.startswith("darwin"): + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) window = glfw.create_window(640, 480, '', None, None) glfw.make_context_current(window) yield window @@ -144,10 +145,11 @@ Here's a complete example: raise RuntimeError('glfw.init() failed') glfw.window_hint(glfw.STENCIL_BITS, 8) # see https://www.glfw.org/faq#macos - glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) - glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) - glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) - glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) + if sys.platform.startswith("darwin"): + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) window = glfw.create_window(WIDTH, HEIGHT, '', None, None) glfw.make_context_current(window) yield window diff --git a/tests/conftest.py b/tests/conftest.py index a8b40518..0658d2ae 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,10 +16,11 @@ def glfw_context(): glfw.window_hint(glfw.VISIBLE, glfw.FALSE) glfw.window_hint(glfw.STENCIL_BITS, 8) # see https://www.glfw.org/faq#macos - glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) - glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) - glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) - glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) + if sys.platform.startswith("darwin"): + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2) + glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True) + glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) context = glfw.create_window(640, 480, '', None, None) glfw.make_context_current(context) logger.debug('glfw context created') From b249d0dd5fdc69802e4ca16a7bc5c40844398542 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 16 Oct 2024 23:06:24 +0100 Subject: [PATCH 02/71] Roll skia forward slightly on m130 (canvaskit/0.38.2-6408-g0f81dc8b2e to canvaskit/0.38.2-6411-g3c64459d5d --- skia | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skia b/skia index 0f81dc8b..3c64459d 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit 0f81dc8b2e43c060972a8d8d229b346694a674f8 +Subproject commit 3c64459d5df2fa9794b277f0959ed8a92552bf4c From 63e5e65e5eefb0551d0441c30ec549613ce9dc7e Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 16 Oct 2024 23:07:19 +0100 Subject: [PATCH 03/71] Bump version up to 131.0b10 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e4494234..ad7ede41 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ pass NAME = 'skia-python' -__version__ = '130.0b10' +__version__ = '131.0b10' SKIA_PATH = os.getenv('SKIA_PATH', 'skia') SKIA_OUT_PATH = os.getenv( From 0faf3cb640c81a92596a7199e287cb2176c7c10d Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 16 Oct 2024 23:08:21 +0100 Subject: [PATCH 04/71] Update skia to m131 (canvaskit/0.38.2-6411-g3c64459d5d to canvaskit/0.38.2-6682-gf7f63e2604) --- skia | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skia b/skia index 3c64459d..f7f63e26 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit 3c64459d5df2fa9794b277f0959ed8a92552bf4c +Subproject commit f7f63e2604e9d436f56daeaba55b103b578fc19e From f6daa0befa8e70320f8d7c72d9148715c31ced37 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 16 Oct 2024 23:36:52 +0100 Subject: [PATCH 05/71] skia m131 patch plus adjustments --- .github/workflows/ci.yml | 2 +- patch/skia-m131-minimize-download.patch | 70 +++++++++++++++++++++++++ scripts/build_Linux.sh | 2 +- scripts/build_Windows.sh | 2 +- scripts/build_macOS.sh | 2 +- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 patch/skia-m131-minimize-download.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f104578c..806faaa3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: key: linux-aarch64-skia-${{ github.sha }}-3rd-party - name: Pre-fetch skia deps if: ${{ steps.cache-skia.outputs.cache-hit != 'true' }} - run: git config --global core.compression 0 && cd skia && patch -p1 -i ../patch/skia-m130-minimize-download.patch && python tools/git-sync-deps && patch -p1 -R -i ../patch/skia-m130-minimize-download.patch + run: git config --global core.compression 0 && cd skia && patch -p1 -i ../patch/skia-m131-minimize-download.patch && python tools/git-sync-deps && patch -p1 -R -i ../patch/skia-m131-minimize-download.patch - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Build skia 3rd-Party diff --git a/patch/skia-m131-minimize-download.patch b/patch/skia-m131-minimize-download.patch new file mode 100644 index 00000000..2d3642cc --- /dev/null +++ b/patch/skia-m131-minimize-download.patch @@ -0,0 +1,70 @@ +diff --git a/DEPS b/DEPS +index a30e242..3d8dd72 100644 +--- a/DEPS ++++ b/DEPS +@@ -31,53 +31,18 @@ vars = { + # ./tools/git-sync-deps + deps = { + "buildtools" : "https://chromium.googlesource.com/chromium/src/buildtools.git@b138e6ce86ae843c42a1a08f37903207bebcca75", +- "third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@78a694a1b82a01623226a418cf2f765c75e45c70", +- "third_party/externals/brotli" : "https://skia.googlesource.com/external/github.com/google/brotli.git@6d03dfbedda1615c4cba1211f8d81735575209c8", +- "third_party/externals/d3d12allocator" : "https://skia.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git@169895d529dfce00390a20e69c2f516066fe7a3b", +- # Dawn requires jinja2 and markupsafe for the code generator, tint for SPIRV compilation, and abseil for string formatting. +- # When the Dawn revision is updated these should be updated from the Dawn DEPS as well. +- "third_party/externals/dawn" : "https://dawn.googlesource.com/dawn.git@f3c7cc5c580eb743829c78bb77df0c1e8f6a6ce3", +- "third_party/externals/jinja2" : "https://chromium.googlesource.com/chromium/src/third_party/jinja2@e2d024354e11cc6b041b0cff032d73f0c7e43a07", +- "third_party/externals/markupsafe" : "https://chromium.googlesource.com/chromium/src/third_party/markupsafe@0bad08bb207bbfc1d6f3bbc82b9242b0c50e5794", +- "third_party/externals/abseil-cpp" : "https://skia.googlesource.com/external/github.com/abseil/abseil-cpp.git@65a55c2ba891f6d2492477707f4a2e327a0b40dc", + "third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@c8d0c9b1d16bfda56f15165d39e0ffa360a11123", +- "third_party/externals/egl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/EGL-Registry@b055c9b483e70ecd57b3cf7204db21f5a06f9ffe", +- "third_party/externals/emsdk" : "https://skia.googlesource.com/external/github.com/emscripten-core/emsdk.git@a896e3d066448b3530dbcaa48869fafefd738f57", + "third_party/externals/expat" : "https://chromium.googlesource.com/external/github.com/libexpat/libexpat.git@624da0f593bb8d7e146b9f42b06d8e6c80d032a3", + "third_party/externals/freetype" : "https://chromium.googlesource.com/chromium/src/third_party/freetype2.git@83af801b552111e37d9466a887e1783a0fb5f196", + "third_party/externals/harfbuzz" : "https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git@a070f9ebbe88dc71b248af9731dd49ec93f4e6e6", +- "third_party/externals/highway" : "https://chromium.googlesource.com/external/github.com/google/highway.git@424360251cdcfc314cfc528f53c872ecd63af0f0", + "third_party/externals/icu" : "https://chromium.googlesource.com/chromium/deps/icu.git@364118a1d9da24bb5b770ac3d762ac144d6da5a4", +- "third_party/externals/icu4x" : "https://chromium.googlesource.com/external/github.com/unicode-org/icu4x.git@bcf4f7198d4dc5f3127e84a6ca657c88e7d07a13", +- "third_party/externals/imgui" : "https://skia.googlesource.com/external/github.com/ocornut/imgui.git@55d35d8387c15bf0cfd71861df67af8cfbda7456", +- "third_party/externals/libavif" : "https://skia.googlesource.com/external/github.com/AOMediaCodec/libavif.git@55aab4ac0607ab651055d354d64c4615cf3d8000", +- "third_party/externals/libgav1" : "https://chromium.googlesource.com/codecs/libgav1.git@5cf722e659014ebaf2f573a6dd935116d36eadf1", +- "third_party/externals/libgrapheme" : "https://skia.googlesource.com/external/github.com/FRIGN/libgrapheme/@c0cab63c5300fa12284194fbef57aa2ed62a94c0", + "third_party/externals/libjpeg-turbo" : "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@ccfbe1c82a3b6dbe8647ceb36a3f9ee711fba3cf", +- "third_party/externals/libjxl" : "https://chromium.googlesource.com/external/gitlab.com/wg1/jpeg-xl.git@a205468bc5d3a353fb15dae2398a101dff52f2d3", + "third_party/externals/libpng" : "https://skia.googlesource.com/third_party/libpng.git@ed217e3e601d8e462f7fd1e04bed43ac42212429", + "third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@845d5476a866141ba35ac133f856fa62f0b7445f", +- "third_party/externals/libyuv" : "https://chromium.googlesource.com/libyuv/libyuv.git@d248929c059ff7629a85333699717d7a677d8d96", +- "third_party/externals/microhttpd" : "https://android.googlesource.com/platform/external/libmicrohttpd@748945ec6f1c67b7efc934ab0808e1d32f2fb98d", +- "third_party/externals/oboe" : "https://chromium.googlesource.com/external/github.com/google/oboe.git@b02a12d1dd821118763debec6b83d00a8a0ee419", +- "third_party/externals/opengl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/OpenGL-Registry@14b80ebeab022b2c78f84a573f01028c96075553", +- "third_party/externals/partition_alloc" : "https://chromium.googlesource.com/chromium/src/base/allocator/partition_allocator.git@ca4487e127c2e071da5d4a36a9f71fd7b65b1434", +- "third_party/externals/perfetto" : "https://android.googlesource.com/platform/external/perfetto@93885509be1c9240bc55fa515ceb34811e54a394", + "third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@bb217acdca1cc0c16b704669dd6f91a1b509c406", +- "third_party/externals/swiftshader" : "https://swiftshader.googlesource.com/SwiftShader@7a9a492a38b7c701f7c96a15a76046aed8f8c0c3", + "third_party/externals/vulkanmemoryallocator" : "https://chromium.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator@a6bfc237255a6bac1513f7c1ebde6d8aed6b5191", +- # vulkan-deps is a meta-repo containing several interdependent Khronos Vulkan repositories. +- # When the vulkan-deps revision is updated, those repos (spirv-*, vulkan-*) should be updated as well. + "third_party/externals/vulkan-deps" : "https://chromium.googlesource.com/vulkan-deps@8f346c5caf5a624f42324ffb88167fc90992cab5", +- "third_party/externals/spirv-cross" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Cross@b8fcf307f1f347089e3c46eb4451d27f32ebc8d3", + "third_party/externals/spirv-headers" : "https://skia.googlesource.com/external/github.com/KhronosGroup/SPIRV-Headers.git@50bc4debdc3eec5045edbeb8ce164090e29b91f3", +- "third_party/externals/spirv-tools" : "https://skia.googlesource.com/external/github.com/KhronosGroup/SPIRV-Tools.git@42b315c15b1ff941b46bb3949c105e5386be8717", +- "third_party/externals/vello" : "https://skia.googlesource.com/external/github.com/linebender/vello.git@3ee3bea02164c5a816fe6c16ef4e3a810edb7620", +- "third_party/externals/vulkan-headers" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Headers@d91597a82f881d473887b560a03a7edf2720b72c", +- "third_party/externals/vulkan-tools" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Tools@eb9b6043be165f06c7ec78fadbb1ff773c5fc19c", +- "third_party/externals/vulkan-utility-libraries": "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Utility-Libraries@bfd85956e1b4c1c79842ce857fc7fb15adb8a573", +- "third_party/externals/unicodetools" : "https://chromium.googlesource.com/external/github.com/unicode-org/unicodetools@66a3fa9dbdca3b67053a483d130564eabc5fe095", +- #"third_party/externals/v8" : "https://chromium.googlesource.com/v8/v8.git@5f1ae66d5634e43563b2d25ea652dfb94c31a3b4", + "third_party/externals/wuffs" : "https://skia.googlesource.com/external/github.com/google/wuffs-mirror-release-c.git@e3f919ccfe3ef542cfc983a82146070258fb57f8", + "third_party/externals/zlib" : "https://chromium.googlesource.com/chromium/src/third_party/zlib@646b7f569718921d7d4b5b8e22572ff6c76f2596", + +diff --git a/bin/activate-emsdk b/bin/activate-emsdk +index 687ca9f..7167d8d 100755 +--- a/bin/activate-emsdk ++++ b/bin/activate-emsdk +@@ -17,6 +17,7 @@ EMSDK_PATH = os.path.join(EMSDK_ROOT, 'emsdk.py') + EMSDK_VERSION = '3.1.44' + + def main(): ++ return + if sysconfig.get_platform() in ['linux-aarch64', 'linux-arm64']: + # This platform cannot install emsdk at the provided version. See + # https://github.com/emscripten-core/emsdk/blob/main/emscripten-releases-tags.json#L5 diff --git a/scripts/build_Linux.sh b/scripts/build_Linux.sh index 8fc6efca..123e749c 100644 --- a/scripts/build_Linux.sh +++ b/scripts/build_Linux.sh @@ -60,7 +60,7 @@ git clone https://gn.googlesource.com/gn && \ # Build skia cd skia && \ - patch -p1 < ../patch/skia-m130-minimize-download.patch && \ + patch -p1 < ../patch/skia-m131-minimize-download.patch && \ patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ cp -f ../gn/out/gn bin/gn && \ diff --git a/scripts/build_Windows.sh b/scripts/build_Windows.sh index ce694e46..f64409af 100644 --- a/scripts/build_Windows.sh +++ b/scripts/build_Windows.sh @@ -4,7 +4,7 @@ export PATH="${PWD}/depot_tools:$PATH" # Build skia cd skia && \ - patch -p1 < ../patch/skia-m130-minimize-download.patch && \ + patch -p1 < ../patch/skia-m131-minimize-download.patch && \ patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ python tools/git-sync-deps && \ bin/gn gen out/Release --args=' diff --git a/scripts/build_macOS.sh b/scripts/build_macOS.sh index 666d1fdb..07c44900 100644 --- a/scripts/build_macOS.sh +++ b/scripts/build_macOS.sh @@ -22,7 +22,7 @@ function apply_patch { } cd skia && \ - patch -p1 < ../patch/skia-m130-minimize-download.patch && \ + patch -p1 < ../patch/skia-m131-minimize-download.patch && \ patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ bin/gn gen out/Release --args=" From f47ad720ea8185add10ce9cedd354e0268e0cd77 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 16 Oct 2024 23:51:48 +0100 Subject: [PATCH 06/71] m130: Many headers moved from include/gpu/ to include/gpu/ganesh/ Milestone 130 ------------- * Ganesh files have been moved out of include/gpu/ into include/gpu/ganesh/. Shims have been left in place, but clients should migrate to the new paths. --- src/skia/GrContext.cpp | 12 ++++++------ src/skia/GrContext_gl.cpp | 4 ++-- src/skia/GrContext_mock.cpp | 4 ++-- src/skia/GrContext_vk.cpp | 2 +- src/skia/Image.cpp | 2 +- src/skia/Surface.cpp | 2 +- src/skia/common.h | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/skia/GrContext.cpp b/src/skia/GrContext.cpp index caaf7dd4..ca64a562 100644 --- a/src/skia/GrContext.cpp +++ b/src/skia/GrContext.cpp @@ -1,14 +1,14 @@ #include "common.h" #include -#include -#include -#include +#include +#include +#include #include -#include -#include +#include +#include #include #include -#include +#include #include #include #include diff --git a/src/skia/GrContext_gl.cpp b/src/skia/GrContext_gl.cpp index 6024abea..b0413997 100644 --- a/src/skia/GrContext_gl.cpp +++ b/src/skia/GrContext_gl.cpp @@ -1,6 +1,6 @@ #include "common.h" -#include -#include +#include +#include void initGrContext_gl(py::module &m) { diff --git a/src/skia/GrContext_mock.cpp b/src/skia/GrContext_mock.cpp index 24d94a10..3b9f7307 100644 --- a/src/skia/GrContext_mock.cpp +++ b/src/skia/GrContext_mock.cpp @@ -1,6 +1,6 @@ #include "common.h" -#include -#include +#include +#include #include void initGrContext_mock(py::module &m) { diff --git a/src/skia/GrContext_vk.cpp b/src/skia/GrContext_vk.cpp index 7a0705bd..75bdaa21 100644 --- a/src/skia/GrContext_vk.cpp +++ b/src/skia/GrContext_vk.cpp @@ -1,6 +1,6 @@ #include "common.h" #include -#include +#include void initGrContext_vk(py::module &m) { diff --git a/src/skia/Image.cpp b/src/skia/Image.cpp index 13bb1c97..dbc2f1b2 100644 --- a/src/skia/Image.cpp +++ b/src/skia/Image.cpp @@ -1,7 +1,7 @@ #include "common.h" #include #include -#include +#include #include #include #include diff --git a/src/skia/Surface.cpp b/src/skia/Surface.cpp index 7ecaf7e7..d4bbc026 100644 --- a/src/skia/Surface.cpp +++ b/src/skia/Surface.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/skia/common.h b/src/skia/common.h index d6f4d9d8..0cd21ab9 100644 --- a/src/skia/common.h +++ b/src/skia/common.h @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include From 58e316f48208a3f6d10263fdd0d19ada1ee2c821 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 17 Oct 2024 00:02:29 +0100 Subject: [PATCH 07/71] m131: SkPDF::StructureElementNode::fAdditionalNodeIds removed, as it was never used https://github.com/google/skia/commit/16722e4e9e6de3fd0e9d4e795796eb771cfa12e9 Revert "Allow passing multiple node IDs per PDF structure node." This reverts commit 2a016ba. StructureElemementNode::fAdditionalNodeIds is currently unused and appears to never have been used. Change-Id: If2c1aae88909dc3ec701e94008108e2dc02504bb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/905896 --- src/skia/Document.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/skia/Document.cpp b/src/skia/Document.cpp index 102cc10e..cdab79f7 100644 --- a/src/skia/Document.cpp +++ b/src/skia/Document.cpp @@ -216,8 +216,11 @@ py::class_(pdf, "StructureElementNode", // &SkPDF::StructureElementNode::fChildVector) .def_readwrite("fNodeId", &SkPDF::StructureElementNode::fNodeId) +/* Removed in m131 */ +/* .def_readonly("fAdditionalNodeIds", &SkPDF::StructureElementNode::fAdditionalNodeIds) +*/ .def_readonly("fAttributes", &SkPDF::StructureElementNode::fAttributes) .def_readwrite("fAlt", From c301867010eda91028399e214acaa0e8bbc3534f Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 17 Oct 2024 00:17:24 +0100 Subject: [PATCH 08/71] m131: GrDirectContext::submit now overloaded and needs "py::overload_cast" --- src/skia/GrContext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skia/GrContext.cpp b/src/skia/GrContext.cpp index ca64a562..2c5e88fe 100644 --- a/src/skia/GrContext.cpp +++ b/src/skia/GrContext.cpp @@ -898,7 +898,7 @@ py::class_, GrRecordingContext>(m, "GrDi )docstring", py::arg("info")) .def("flush", py::overload_cast<>(&GrDirectContext::flush)) - .def("submit", &GrDirectContext::submit, + .def("submit", py::overload_cast(&GrDirectContext::submit), R"docstring( Submit outstanding work to the gpu from all previously un-submitted flushes. The return value of the submit will indicate whether or not the From b942888da5239e9e13ee61467b89803b0cd9162e Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 23 Oct 2024 15:34:46 +0100 Subject: [PATCH 09/71] Adding tests for factory functions returning non-None; part of checking icudtl.dat+MakeFromShapedText failure Conflicts: tests/test_font.py --- tests/test_font.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_font.py b/tests/test_font.py index 2a220f98..bbecbd99 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -240,6 +240,17 @@ def svg_blob(svgface): blob = skia.TextBlob.MakeFromShapedText(text, font) return blob +def test_svg_blob_1(svgface): + text = "abcdefgh" + font = skia.Font(svgface,109) + blob = skia.TextBlob.MakeFromText(text, font) + assert blob is not None + +def test_svg_blob_2(svgface): + text = "abcdefgh" + font = skia.Font(svgface,109) + blob = skia.TextBlob.MakeFromShapedText(text, font) + assert blob is not None # This test doesn't really test that the SVG table loads correctly - # Rather, it depends on the fact that, for this particular font, @@ -418,6 +429,8 @@ def test_FontMgr_ref_unref(fontmgr): def font(): return skia.Font(skia.Typeface("")) +def test_font(): + assert skia.Font(skia.Typeface("")) is not None @pytest.mark.parametrize('args', [ tuple(), From eec96375fbdb8036ca1fd34512291e973a0e6ca8 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 17 Oct 2024 01:28:02 +0100 Subject: [PATCH 10/71] Header not needed, apparently --- src/skia/Shader.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/skia/Shader.cpp b/src/skia/Shader.cpp index e89f95b5..d1b37690 100644 --- a/src/skia/Shader.cpp +++ b/src/skia/Shader.cpp @@ -1,5 +1,4 @@ #include "common.h" -#include #include #include #include From e66d5bfcbad2781d4420e5220627c690380fb8ff Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 23 Oct 2024 19:29:58 +0100 Subject: [PATCH 11/71] First build-able SkRuntimeEffect binding initRuntimeEffect in main() Needs a default sk_sp holder type for "RuntimeEffect" Without this, the runtime error is: ImportError: generic_type: type "RuntimeEffect" does not have a non-default holder type while its base "SkRefCnt" does --- src/skia/RuntimeEffect.cpp | 57 ++++++++++++++++++++++++++++++++++++++ src/skia/main.cpp | 2 ++ 2 files changed, 59 insertions(+) create mode 100644 src/skia/RuntimeEffect.cpp diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp new file mode 100644 index 00000000..b9db6e3c --- /dev/null +++ b/src/skia/RuntimeEffect.cpp @@ -0,0 +1,57 @@ +#include "common.h" +#include + +void initRuntimeEffect(py::module &m) { +py::class_, SkRefCnt> runtime_effect(m, "RuntimeEffect"); + +py::class_ runtime_effect_result(m, "RuntimeEffectResult"); +py::class_ runtime_effect_childptr(m, "RuntimeEffectChildPtr"); + +py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); + +/* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ +runtime_effect + .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), + py::arg("sksl"), py::arg("options")) + .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), + py::arg("sksl")) + .def_static("MakeForShader", py::overload_cast(&SkRuntimeEffect::MakeForShader), + py::arg("sksl"), py::arg("options")) + .def_static("MakeForShader", py::overload_cast(&SkRuntimeEffect::MakeForShader), + py::arg("sksl")) + .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), + py::arg("sksl"), py::arg("options")) + .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), + py::arg("sksl")) + // missing overloaded methods involving "SkSpan..." + .def("makeShader", + py::overload_cast, sk_sp[], size_t, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("childCount"), py::arg("localMatrix") = nullptr) + .def("makeColorFilter", + py::overload_cast>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms")) + .def("makeColorFilter", + py::overload_cast, sk_sp[], size_t>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("childCount")) + .def("makeBlender", + py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children") = SkSpan{}) + ; + +runtime_effect_builder + .def(py::init>()) + .def(py::init, sk_sp>()) + .def("uniform", &SkRuntimeEffectBuilder::uniform, + py::arg("name")) + .def("child", &SkRuntimeEffectBuilder::child, + py::arg("name")) + .def("uniforms", &SkRuntimeEffectBuilder::uniforms) + .def("children", &SkRuntimeEffectBuilder::children) + .def("makeShader", &SkRuntimeEffectBuilder::makeShader, + py::arg("localMatrix") = nullptr) + .def("makeColorFilter", &SkRuntimeEffectBuilder::makeColorFilter) + .def("makeBlender", &SkRuntimeEffectBuilder::makeBlender) + ; +} diff --git a/src/skia/main.cpp b/src/skia/main.cpp index 8d7caca5..450e7b1e 100644 --- a/src/skia/main.cpp +++ b/src/skia/main.cpp @@ -29,6 +29,7 @@ void initPoint(py::module &); void initRect(py::module &); void initRefCnt(py::module &); void initRegion(py::module &); +void initRuntimeEffect(py::module &); void initSamplingOptions(py::module &); void initScalar(py::module &); void initSize(py::module &); @@ -75,6 +76,7 @@ PYBIND11_MODULE(skia, m) { initPathMeasure(m); initPicture(m); initPixmap(m); + initRuntimeEffect(m); initScalar(m); initTextBlob(m); initVertices(m); From 6b303f451b61c8813defb4aee2efaab58ef18a11 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 23 Oct 2024 20:08:56 +0100 Subject: [PATCH 12/71] Simplified SkRuntimeEffect::makeBlender overload, since we cannot bind SkSpan yet --- src/skia/RuntimeEffect.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index b9db6e3c..b7b74e69 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -35,9 +35,16 @@ runtime_effect py::overload_cast, sk_sp[], size_t>(&SkRuntimeEffect::makeColorFilter, py::const_), py::arg("uniforms"), py::arg("children"), py::arg("childCount")) + .def("makeBlender", + [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { + return runtime_effect.makeColorFilter(uniforms, {}); + }, + py::arg("uniforms")) +/* .def("makeBlender", py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), py::arg("uniforms"), py::arg("children") = SkSpan{}) +*/ ; runtime_effect_builder From b91c73da0a9c80f03a4e236f896e8a8b5de1c5c5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 23 Oct 2024 20:20:24 +0100 Subject: [PATCH 13/71] Needs access to members in SkRuntimeEffect::Result --- src/skia/RuntimeEffect.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index b7b74e69..f9cfe1e6 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -9,6 +9,11 @@ py::class_ runtime_effect_childptr(m, "RuntimeEffectC py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); +runtime_effect_result + .def_readwrite("effect", &SkRuntimeEffect::Result::effect) + .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) + ; + /* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ runtime_effect .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), From bce29eaddf2ad016065c9a30ea19c3681516a4f3 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 23 Oct 2024 20:35:37 +0100 Subject: [PATCH 14/71] Simplified overload of SkRuntimeEffect::makeShader --- src/skia/RuntimeEffect.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index f9cfe1e6..5c921fc7 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -29,6 +29,11 @@ runtime_effect .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), py::arg("sksl")) // missing overloaded methods involving "SkSpan..." + .def("makeShader", + [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { + return runtime_effect.makeShader(uniforms, {}); + }, + py::arg("uniforms")) .def("makeShader", py::overload_cast, sk_sp[], size_t, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), py::arg("uniforms"), py::arg("children"), From 1d06b2b7cc9f47ea6510a41d46b05e5ccf255106 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 21 Oct 2024 01:31:11 +0100 Subject: [PATCH 15/71] Build for python 3.13 too, now that it is out Split CI machinery into two nearly identical sections, one for 3.8/3.9, another for 3.10 to 3.13. This is mainly due to newer cibuildwheel for 3.13 dropping 3.8 and 3.9, and older cibuildwheel not supporting 3.13. Fixes #230 --- .github/workflows/ci.yml | 78 +++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 806faaa3..0dde6bb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,27 +75,87 @@ jobs: matrix: os: [ubuntu-22.04, windows-2022, macos-12] arch: [auto64] - cp: ["cp3{8,9,10,11,12}"] + cp: ["cp3{10,11,12,13}"] include: - os: macos-12 arch: arm64 - cp: "cp3{8,9,10,11,12}" + cp: "cp3{10,11,12,13}" # aarch64 is emulated and takes longer, build one wheel per job - os: ubuntu-22.04 arch: aarch64 - cp: cp38 + cp: cp310 - os: ubuntu-22.04 arch: aarch64 - cp: cp39 + cp: cp311 - os: ubuntu-22.04 arch: aarch64 - cp: cp310 + cp: cp312 - os: ubuntu-22.04 arch: aarch64 - cp: cp311 + cp: cp313 + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: actions/cache/restore@v4 + if: runner.os == 'Linux' && matrix.arch == 'aarch64' + with: + path: | + gn + skia + key: linux-aarch64-skia-${{ github.sha }} + + - name: Set up QEMU + if: runner.os == 'Linux' && matrix.arch == 'aarch64' + uses: docker/setup-qemu-action@v3 + with: + platforms: ${{ matrix.arch }} + + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.3 + env: + CIBW_BUILD: "${{ matrix.cp }}-*" + CIBW_SKIP: "*musllinux*" + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_ENVIRONMENT_MACOS: TARGET_ARCH=${{ matrix.arch }} MACOSX_DEPLOYMENT_TARGET=11.0 + CIBW_BEFORE_ALL: bash scripts/build_${{ runner.os }}.sh + CIBW_BEFORE_BUILD: pip install pybind11 numpy + CIBW_TEST_REQUIRES: pytest pillow glfw + CIBW_TEST_REQUIRES_MACOS: pytest pillow pyopengl + CIBW_TEST_COMMAND: python -m pytest {project}/tests + CIBW_TEST_COMMAND_LINUX: > + xvfb-run -s "-screen 0 640x480x24" python -m pytest {project}/tests + CIBW_TEST_SKIP: "*-macosx_arm64" + + - uses: actions/upload-artifact@v4 + with: + name: wheel-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.cp }} + path: ./wheelhouse/*.whl + + # identical to "build_wheels", except with the older pypa/cibuildwheel@v2.19.2 + build_wheels_old: + name: Build wheels on ${{ matrix.os }} (${{ matrix.arch }}) for ${{ matrix.cp }} + needs: prebuild_linux_aarch64 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04, windows-2022, macos-12] + arch: [auto64] + cp: ["cp3{8,9}"] + include: + - os: macos-12 + arch: arm64 + cp: "cp3{8,9}" + # aarch64 is emulated and takes longer, build one wheel per job - os: ubuntu-22.04 arch: aarch64 - cp: cp312 + cp: cp38 + - os: ubuntu-22.04 + arch: aarch64 + cp: cp39 steps: - uses: actions/checkout@v4 @@ -139,7 +199,7 @@ jobs: build_docs: name: Build docs - needs: [build_wheels] + needs: [build_wheels, build_wheels_old] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -169,7 +229,7 @@ jobs: publish: name: Upload packages to PyPI - needs: [build_wheels] + needs: [build_wheels, build_wheels_old] runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' permissions: From 6dc456e1daac3a352017955c9451369516867a6b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 25 Oct 2024 10:34:40 +0100 Subject: [PATCH 16/71] Update README.md to mention python 3.13 support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37b2bfa8..43388386 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Binary package is available on PyPI: pip install skia-python ``` -Supported platforms: Python 3.8-3.12 (CPython) on +Supported platforms: Python 3.8-3.13 (CPython) on - Linux x86_64, aarch64 - macOS x86_64, arm64 From 682899bc209c1fa6a3a865a3a9bc0f2adc3046ce Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 21 Oct 2024 01:31:11 +0100 Subject: [PATCH 17/71] Build for python 3.13 too, now that it is out Split CI machinery into two nearly identical sections, one for 3.8/3.9, another for 3.10 to 3.13. This is mainly due to newer cibuildwheel for 3.13 dropping 3.8 and 3.9, and older cibuildwheel not supporting 3.13. Fixes #230 --- .github/workflows/ci.yml | 78 +++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f104578c..d58e85da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,27 +75,87 @@ jobs: matrix: os: [ubuntu-22.04, windows-2022, macos-12] arch: [auto64] - cp: ["cp3{8,9,10,11,12}"] + cp: ["cp3{10,11,12,13}"] include: - os: macos-12 arch: arm64 - cp: "cp3{8,9,10,11,12}" + cp: "cp3{10,11,12,13}" # aarch64 is emulated and takes longer, build one wheel per job - os: ubuntu-22.04 arch: aarch64 - cp: cp38 + cp: cp310 - os: ubuntu-22.04 arch: aarch64 - cp: cp39 + cp: cp311 - os: ubuntu-22.04 arch: aarch64 - cp: cp310 + cp: cp312 - os: ubuntu-22.04 arch: aarch64 - cp: cp311 + cp: cp313 + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - uses: actions/cache/restore@v4 + if: runner.os == 'Linux' && matrix.arch == 'aarch64' + with: + path: | + gn + skia + key: linux-aarch64-skia-${{ github.sha }} + + - name: Set up QEMU + if: runner.os == 'Linux' && matrix.arch == 'aarch64' + uses: docker/setup-qemu-action@v3 + with: + platforms: ${{ matrix.arch }} + + - name: Build wheels + uses: pypa/cibuildwheel@v2.21.3 + env: + CIBW_BUILD: "${{ matrix.cp }}-*" + CIBW_SKIP: "*musllinux*" + CIBW_ARCHS: ${{ matrix.arch }} + CIBW_ENVIRONMENT_MACOS: TARGET_ARCH=${{ matrix.arch }} MACOSX_DEPLOYMENT_TARGET=11.0 + CIBW_BEFORE_ALL: bash scripts/build_${{ runner.os }}.sh + CIBW_BEFORE_BUILD: pip install pybind11 numpy + CIBW_TEST_REQUIRES: pytest pillow glfw + CIBW_TEST_REQUIRES_MACOS: pytest pillow pyopengl + CIBW_TEST_COMMAND: python -m pytest {project}/tests + CIBW_TEST_COMMAND_LINUX: > + xvfb-run -s "-screen 0 640x480x24" python -m pytest {project}/tests + CIBW_TEST_SKIP: "*-macosx_arm64" + + - uses: actions/upload-artifact@v4 + with: + name: wheel-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.cp }} + path: ./wheelhouse/*.whl + + # identical to "build_wheels", except with the older pypa/cibuildwheel@v2.19.2 + build_wheels_old: + name: Build wheels on ${{ matrix.os }} (${{ matrix.arch }}) for ${{ matrix.cp }} + needs: prebuild_linux_aarch64 + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04, windows-2022, macos-12] + arch: [auto64] + cp: ["cp3{8,9}"] + include: + - os: macos-12 + arch: arm64 + cp: "cp3{8,9}" + # aarch64 is emulated and takes longer, build one wheel per job - os: ubuntu-22.04 arch: aarch64 - cp: cp312 + cp: cp38 + - os: ubuntu-22.04 + arch: aarch64 + cp: cp39 steps: - uses: actions/checkout@v4 @@ -139,7 +199,7 @@ jobs: build_docs: name: Build docs - needs: [build_wheels] + needs: [build_wheels, build_wheels_old] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -169,7 +229,7 @@ jobs: publish: name: Upload packages to PyPI - needs: [build_wheels] + needs: [build_wheels, build_wheels_old] runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' permissions: From ec34b43307dd291984dbfbd3ecacfce252c0c294 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 25 Oct 2024 10:34:40 +0100 Subject: [PATCH 18/71] Update README.md to mention python 3.13 support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 37b2bfa8..43388386 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Binary package is available on PyPI: pip install skia-python ``` -Supported platforms: Python 3.8-3.12 (CPython) on +Supported platforms: Python 3.8-3.13 (CPython) on - Linux x86_64, aarch64 - macOS x86_64, arm64 From 7ee8d3a5ffcd7a2156cc3bc7abb9822027eb2b8b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 24 Oct 2024 22:19:09 +0100 Subject: [PATCH 19/71] Binding SkV3 and SkV4 structs, used by some of the SkSL examples --- src/skia/RuntimeEffect.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 5c921fc7..a511d497 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -1,5 +1,6 @@ #include "common.h" #include +//#include // defines SkV3, SkV4 ; M44 used in Matrix/Canvas ; Revisit. void initRuntimeEffect(py::module &m) { py::class_, SkRefCnt> runtime_effect(m, "RuntimeEffect"); @@ -9,6 +10,20 @@ py::class_ runtime_effect_childptr(m, "RuntimeEffectC py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); +py::class_(m, "V3") + .def(py::init( + [] (float x, float y, float z) { + return SkV3{x, y, z}; + })) + ; + +py::class_(m, "V4") + .def(py::init( + [] (float x, float y, float z, float w) { + return SkV4{x, y, z, w}; + })) + ; + runtime_effect_result .def_readwrite("effect", &SkRuntimeEffect::Result::effect) .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) From 3ecd3c9741a5248b43802177306cb09cea17a305 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 24 Oct 2024 22:36:16 +0100 Subject: [PATCH 20/71] Simplier ways of binding SkRuntimeEffect::Result --- src/skia/RuntimeEffect.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index a511d497..47d61ed8 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -5,7 +5,6 @@ void initRuntimeEffect(py::module &m) { py::class_, SkRefCnt> runtime_effect(m, "RuntimeEffect"); -py::class_ runtime_effect_result(m, "RuntimeEffectResult"); py::class_ runtime_effect_childptr(m, "RuntimeEffectChildPtr"); py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); @@ -24,7 +23,7 @@ py::class_(m, "V4") })) ; -runtime_effect_result +py::class_(m, "RuntimeEffectResult") .def_readwrite("effect", &SkRuntimeEffect::Result::effect) .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) ; From 0a537b2b20043f4833b73ef09dfc2c3a7b41ed6f Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 24 Oct 2024 23:43:00 +0100 Subject: [PATCH 21/71] SkSpan class we only need the reference constructor? --- src/skia/RuntimeEffect.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 47d61ed8..7cc246bc 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -7,6 +7,8 @@ py::class_, SkRefCnt> runtime_effect(m, py::class_ runtime_effect_childptr(m, "RuntimeEffectChildPtr"); +py::class_> span_runtime_effect_childptr(m, "SpanRuntimeEffectChildPtr"); + py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); py::class_(m, "V3") @@ -28,6 +30,11 @@ py::class_(m, "RuntimeEffectResult") .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) ; +span_runtime_effect_childptr + .def(py::init<>()) + .def(py::init&>()) + ; + /* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ runtime_effect .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), From e7c8612bb0f94462790d5a879e7b9810f07e5bb6 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 24 Oct 2024 23:52:21 +0100 Subject: [PATCH 22/71] Constructors of runtime_effect_childptr --- src/skia/RuntimeEffect.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 7cc246bc..50dfc3d9 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -30,8 +30,16 @@ py::class_(m, "RuntimeEffectResult") .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) ; +runtime_effect_childptr + .def(py::init<>()) + .def(py::init>()) + .def(py::init>()) + .def(py::init>()) + ; + span_runtime_effect_childptr .def(py::init<>()) + .def(py::init()) .def(py::init&>()) ; From 08fffff2a19a36ff4fcf9af73bad61c28623062e Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 25 Oct 2024 00:15:43 +0100 Subject: [PATCH 23/71] The rest of SkSpan methods --- src/skia/RuntimeEffect.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 50dfc3d9..66675ef0 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -57,7 +57,6 @@ runtime_effect py::arg("sksl"), py::arg("options")) .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), py::arg("sksl")) - // missing overloaded methods involving "SkSpan..." .def("makeShader", [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { return runtime_effect.makeShader(uniforms, {}); @@ -67,6 +66,10 @@ runtime_effect py::overload_cast, sk_sp[], size_t, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), py::arg("uniforms"), py::arg("children"), py::arg("childCount"), py::arg("localMatrix") = nullptr) + .def("makeShader", + py::overload_cast, SkSpan, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("localMatrix") = nullptr) .def("makeColorFilter", py::overload_cast>(&SkRuntimeEffect::makeColorFilter, py::const_), py::arg("uniforms")) @@ -74,16 +77,17 @@ runtime_effect py::overload_cast, sk_sp[], size_t>(&SkRuntimeEffect::makeColorFilter, py::const_), py::arg("uniforms"), py::arg("children"), py::arg("childCount")) + .def("makeColorFilter", + py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children")) .def("makeBlender", [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { return runtime_effect.makeColorFilter(uniforms, {}); }, py::arg("uniforms")) -/* .def("makeBlender", py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), py::arg("uniforms"), py::arg("children") = SkSpan{}) -*/ ; runtime_effect_builder From 4ed6cad8fc7b1cf56fcb8d749c990fde7296f7d5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 25 Oct 2024 14:56:39 +0100 Subject: [PATCH 24/71] The rest of SkImage::makeShader overloads --- src/skia/Image.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/skia/Image.cpp b/src/skia/Image.cpp index dbc2f1b2..d5093cf8 100644 --- a/src/skia/Image.cpp +++ b/src/skia/Image.cpp @@ -1230,7 +1230,59 @@ image py::arg_v("tmy", SkTileMode::kClamp, "skia.TileMode.kClamp"), py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), py::arg("localMatrix") = nullptr) - // TODO: Other makeShader overloads. + .def("makeShader", + py::overload_cast( + &SkImage::makeShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + :py:class:`Shader` uses :py:class:`TileMode` rules to fill drawn area + outside :py:class:`Image`. localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.TileMode tmx: tiling in the x direction + :param skia.TileMode tmy: tiling in the y direction + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("tmx", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("tmy", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix")) + .def("makeShader", + py::overload_cast( + &SkImage::makeShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix")) + .def("makeShader", + py::overload_cast( + &SkImage::makeShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix") = nullptr) .def("peekPixels", &SkImage::peekPixels, R"docstring( Copies :py:class:`Image` pixel address, row bytes, and From fc61507f83774ccc65a7d5180dad6b88bf247bc8 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 27 Oct 2024 01:16:20 +0100 Subject: [PATCH 25/71] Initialize SkSpan from std::vector& --- src/skia/RuntimeEffect.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 66675ef0..4aa5b4ee 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -1,12 +1,16 @@ #include "common.h" #include //#include // defines SkV3, SkV4 ; M44 used in Matrix/Canvas ; Revisit. +#include + +PYBIND11_MAKE_OPAQUE(std::vector) void initRuntimeEffect(py::module &m) { py::class_, SkRefCnt> runtime_effect(m, "RuntimeEffect"); py::class_ runtime_effect_childptr(m, "RuntimeEffectChildPtr"); +py::bind_vector>(m, "VectorSkRuntimeEffectChildPtr"); py::class_> span_runtime_effect_childptr(m, "SpanRuntimeEffectChildPtr"); py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); @@ -41,6 +45,11 @@ span_runtime_effect_childptr .def(py::init<>()) .def(py::init()) .def(py::init&>()) + .def(py::init( + [] (std::vector& v) { + return SkSpan(&v[0], v.size()); + })) + .def(py::init&>()) ; /* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ From c9e69a60d11520783db0876007f25590edd9966b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 27 Oct 2024 14:26:33 +0000 Subject: [PATCH 26/71] Make std::vector implicit convertible to SkSpan --- src/skia/RuntimeEffect.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 4aa5b4ee..45e58ebc 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -52,6 +52,8 @@ span_runtime_effect_childptr .def(py::init&>()) ; +py::implicitly_convertible, SkSpan>(); + /* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ runtime_effect .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), From 5ccbbdefc89f5dee5a36c704ef354dac46d4b0b0 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 27 Oct 2024 14:55:35 +0000 Subject: [PATCH 27/71] Adding implicit conversion to SkRuntimeEffect::ChildPtr --- src/skia/RuntimeEffect.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 45e58ebc..48e7bc89 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -52,6 +52,9 @@ span_runtime_effect_childptr .def(py::init&>()) ; +py::implicitly_convertible, SkRuntimeEffect::ChildPtr>(); +py::implicitly_convertible, SkRuntimeEffect::ChildPtr>(); +py::implicitly_convertible, SkRuntimeEffect::ChildPtr>(); py::implicitly_convertible, SkSpan>(); /* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ From 59a283ba541667d917309efa53489f9d8a3635f5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 27 Oct 2024 18:44:06 +0000 Subject: [PATCH 28/71] SkRuntimeEffectBuilder::BuilderUniform SkRuntimeEffectBuilder::BuilderChild classes and Runtime*Builder aliases --- src/skia/RuntimeEffect.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 48e7bc89..9b113866 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -104,6 +104,14 @@ runtime_effect py::arg("uniforms"), py::arg("children") = SkSpan{}) ; +py::class_(m, "RuntimeEffectBuilderUniform") + .def(py::init<>()) + ; + +py::class_(m, "RuntimeEffectBuilderChild") + .def(py::init<>()) + ; + runtime_effect_builder .def(py::init>()) .def(py::init, sk_sp>()) @@ -118,4 +126,8 @@ runtime_effect_builder .def("makeColorFilter", &SkRuntimeEffectBuilder::makeColorFilter) .def("makeBlender", &SkRuntimeEffectBuilder::makeBlender) ; + +m.attr("RuntimeShaderBuilder") = m.attr("RuntimeEffectBuilder"); +m.attr("RuntimeColorFilterBuilder") = m.attr("RuntimeEffectBuilder"); +m.attr("RuntimeBlendBuilder") = m.attr("RuntimeEffectBuilder"); } From 08d2dec2f208b365844aa03d57c5c1f68fe749ea Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 28 Oct 2024 22:06:06 +0000 Subject: [PATCH 29/71] Adding Image::makeRawShader --- src/skia/Image.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/skia/Image.cpp b/src/skia/Image.cpp index d5093cf8..1d987ee4 100644 --- a/src/skia/Image.cpp +++ b/src/skia/Image.cpp @@ -1277,6 +1277,100 @@ image localMatrix permits transforming :py:class:`Image` before :py:class:`Canvas` matrix is applied. + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix") = nullptr) + .def("makeRawShader", + py::overload_cast( + &SkImage::makeRawShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + makeRawShader functions like makeShader, but for images that contain non-color data. + This includes images encoding things like normals, material properties (eg, roughness), + heightmaps, or any other purely mathematical data that happens to be stored in an image. + These types of images are useful with some programmable shaders (see: SkRuntimeEffect). + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + :py:class:`Shader` uses :py:class:`TileMode` rules to fill drawn area + outside :py:class:`Image`. localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.TileMode tmx: tiling in the x direction + :param skia.TileMode tmy: tiling in the y direction + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("tmx", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("tmy", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix") = nullptr) + .def("makeRawShader", + py::overload_cast( + &SkImage::makeRawShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + makeRawShader functions like makeShader, but for images that contain non-color data. + This includes images encoding things like normals, material properties (eg, roughness), + heightmaps, or any other purely mathematical data that happens to be stored in an image. + These types of images are useful with some programmable shaders (see: SkRuntimeEffect). + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + :py:class:`Shader` uses :py:class:`TileMode` rules to fill drawn area + outside :py:class:`Image`. localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.TileMode tmx: tiling in the x direction + :param skia.TileMode tmy: tiling in the y direction + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("tmx", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("tmy", SkTileMode::kClamp, "skia.TileMode.kClamp"), + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix")) + .def("makeRawShader", + py::overload_cast( + &SkImage::makeRawShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + makeRawShader functions like makeShader, but for images that contain non-color data. + This includes images encoding things like normals, material properties (eg, roughness), + heightmaps, or any other purely mathematical data that happens to be stored in an image. + These types of images are useful with some programmable shaders (see: SkRuntimeEffect). + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or + nullptr + :return: :py:class:`Shader` containing :py:class:`Image` + )docstring", + py::arg_v("samplingOptions", SkSamplingOptions(), "skia.SamplingOptions()"), + py::arg("localMatrix")) + .def("makeRawShader", + py::overload_cast( + &SkImage::makeRawShader, py::const_), + R"docstring( + Creates :py:class:`Shader` from :py:class:`Image`. + + makeRawShader functions like makeShader, but for images that contain non-color data. + This includes images encoding things like normals, material properties (eg, roughness), + heightmaps, or any other purely mathematical data that happens to be stored in an image. + These types of images are useful with some programmable shaders (see: SkRuntimeEffect). + + :py:class:`Shader` dimensions are taken from :py:class:`Image`. + localMatrix permits transforming + :py:class:`Image` before :py:class:`Canvas` matrix is applied. + :param skia.Matrix localMatrix: :py:class:`Image` transformation, or nullptr :return: :py:class:`Shader` containing :py:class:`Image` From 84e8556fcfa93a5594f2edc6569ceb3318ae2fd7 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 28 Oct 2024 22:49:36 +0000 Subject: [PATCH 30/71] Adding SkRuntimeEffectBuilder::setUniform/setChild --- src/skia/RuntimeEffect.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 9b113866..ba873f23 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -119,6 +119,30 @@ runtime_effect_builder py::arg("name")) .def("child", &SkRuntimeEffectBuilder::child, py::arg("name")) + .def("setUniform", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, int uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) + .def("setUniform", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV3& uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) + .def("setUniform", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV4& uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) + .def("setChild", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { + auto v = builder.child(name); + v = child; + }, + py::arg("name"), py::arg("child")) .def("uniforms", &SkRuntimeEffectBuilder::uniforms) .def("children", &SkRuntimeEffectBuilder::children) .def("makeShader", &SkRuntimeEffectBuilder::makeShader, From 8f8fb772b8697048cb842afa7e94ab1ce1a55135 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 29 Oct 2024 18:10:03 +0000 Subject: [PATCH 31/71] Adding SkNamedTransferFn::kLinear, SkNamedTransferFn::kSRGB and SkNamedGamut::kRec2020 constexpr as static class attributes --- src/skia/ColorSpace.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/skia/ColorSpace.cpp b/src/skia/ColorSpace.cpp index 25a5549f..7e54edb8 100644 --- a/src/skia/ColorSpace.cpp +++ b/src/skia/ColorSpace.cpp @@ -37,6 +37,10 @@ py::class_(skcms, "TransferFunction", }; }), py::arg("v")); +m.attr("cms").attr("NamedTransferFn") = m.attr("cms").attr("TransferFunction"); +m.attr("cms").attr("TransferFunction").attr("kLinear") = SkNamedTransferFn::kLinear; +m.attr("cms").attr("TransferFunction").attr("kSRGB") = SkNamedTransferFn::kSRGB; + py::class_(skcms, "Matrix3x3", R"docstring( A row-major 3x3 matrix (ie vals[row][col]) @@ -52,6 +56,9 @@ py::class_(skcms, "Matrix3x3", }}; }), py::arg("v")); +m.attr("cms").attr("NamedGamut") = m.attr("cms").attr("Matrix3x3"); +m.attr("cms").attr("Matrix3x3").attr("kRec2020") = SkNamedGamut::kRec2020; + py::class_>(m, "ColorSpace") .def("toProfile", [] (const SkColorSpace& colorspace) { From 3b0b3b57374e7ee5fe56fd063bd51d81fc7e63c0 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 29 Oct 2024 23:43:17 +0000 Subject: [PATCH 32/71] throw std::runtime_error from SkRuntimeEffect::MakeFor*, or return valid effect --- src/skia/RuntimeEffect.cpp | 49 +++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index ba873f23..a696e6e0 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -1,3 +1,4 @@ +#include #include "common.h" #include //#include // defines SkV3, SkV4 ; M44 used in Matrix/Canvas ; Revisit. @@ -59,17 +60,53 @@ py::implicitly_convertible, SkSpan(&SkRuntimeEffect::MakeForColorFilter), + .def_static("MakeForColorFilter", + [] (SkString sksl, const SkRuntimeEffect::Options& options) { + auto [effect, err] = SkRuntimeEffect::MakeForColorFilter(sksl, options); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl"), py::arg("options")) - .def_static("MakeForColorFilter", py::overload_cast(&SkRuntimeEffect::MakeForColorFilter), + .def_static("MakeForColorFilter", + [] (SkString sksl) { + auto [effect, err] = SkRuntimeEffect::MakeForColorFilter(sksl); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl")) - .def_static("MakeForShader", py::overload_cast(&SkRuntimeEffect::MakeForShader), + .def_static("MakeForShader", + [] (SkString sksl, const SkRuntimeEffect::Options& options) { + auto [effect, err] = SkRuntimeEffect::MakeForShader(sksl, options); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl"), py::arg("options")) - .def_static("MakeForShader", py::overload_cast(&SkRuntimeEffect::MakeForShader), + .def_static("MakeForShader", + [] (SkString sksl) { + auto [effect, err] = SkRuntimeEffect::MakeForShader(sksl); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl")) - .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), + .def_static("MakeForBlender", + [] (SkString sksl, const SkRuntimeEffect::Options& options) { + auto [effect, err] = SkRuntimeEffect::MakeForBlender(sksl, options); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl"), py::arg("options")) - .def_static("MakeForBlender", py::overload_cast(&SkRuntimeEffect::MakeForBlender), + .def_static("MakeForBlender", + [] (SkString sksl) { + auto [effect, err] = SkRuntimeEffect::MakeForBlender(sksl); + if (!effect) + throw std::runtime_error(err.data()); + return effect; + }, py::arg("sksl")) .def("makeShader", [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { From 6de5965155708fbe63e76fc5097c477941a07d00 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 30 Oct 2024 14:19:02 +0000 Subject: [PATCH 33/71] The other constexpr's under SkNamedTransferFn/SkNamedGamut than used by upstream examples --- src/skia/ColorSpace.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/skia/ColorSpace.cpp b/src/skia/ColorSpace.cpp index 7e54edb8..e6e0b6e7 100644 --- a/src/skia/ColorSpace.cpp +++ b/src/skia/ColorSpace.cpp @@ -38,8 +38,12 @@ py::class_(skcms, "TransferFunction", }), py::arg("v")); m.attr("cms").attr("NamedTransferFn") = m.attr("cms").attr("TransferFunction"); -m.attr("cms").attr("TransferFunction").attr("kLinear") = SkNamedTransferFn::kLinear; -m.attr("cms").attr("TransferFunction").attr("kSRGB") = SkNamedTransferFn::kSRGB; +m.attr("cms").attr("TransferFunction").attr("kSRGB") = SkNamedTransferFn::kSRGB; +m.attr("cms").attr("TransferFunction").attr("k2Dot2") = SkNamedTransferFn::k2Dot2; +m.attr("cms").attr("TransferFunction").attr("kLinear") = SkNamedTransferFn::kLinear; +m.attr("cms").attr("TransferFunction").attr("kRec2020") = SkNamedTransferFn::kRec2020; +m.attr("cms").attr("TransferFunction").attr("kPQ") = SkNamedTransferFn::kPQ; +m.attr("cms").attr("TransferFunction").attr("kHLG") = SkNamedTransferFn::kHLG; py::class_(skcms, "Matrix3x3", R"docstring( @@ -57,7 +61,11 @@ py::class_(skcms, "Matrix3x3", }), py::arg("v")); m.attr("cms").attr("NamedGamut") = m.attr("cms").attr("Matrix3x3"); -m.attr("cms").attr("Matrix3x3").attr("kRec2020") = SkNamedGamut::kRec2020; +m.attr("cms").attr("Matrix3x3").attr("kSRGB") = SkNamedGamut::kSRGB; +m.attr("cms").attr("Matrix3x3").attr("kAdobeRGB") = SkNamedGamut::kAdobeRGB; +m.attr("cms").attr("Matrix3x3").attr("kDisplayP3") = SkNamedGamut::kDisplayP3; +m.attr("cms").attr("Matrix3x3").attr("kRec2020") = SkNamedGamut::kRec2020; +m.attr("cms").attr("Matrix3x3").attr("kXYZ") = SkNamedGamut::kXYZ; py::class_>(m, "ColorSpace") .def("toProfile", From 4050f2193654c922856f9f86164a7f2fba7af2bc Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 30 Oct 2024 14:24:03 +0000 Subject: [PATCH 34/71] Re-indent to fit general coding style; no code change --- src/skia/RuntimeEffect.cpp | 168 ++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index a696e6e0..c427b15d 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -61,84 +61,84 @@ py::implicitly_convertible, SkSpan uniforms) { - return runtime_effect.makeShader(uniforms, {}); - }, + [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { + return runtime_effect.makeShader(uniforms, {}); + }, py::arg("uniforms")) .def("makeShader", - py::overload_cast, sk_sp[], size_t, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), - py::arg("uniforms"), py::arg("children"), - py::arg("childCount"), py::arg("localMatrix") = nullptr) + py::overload_cast, sk_sp[], size_t, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("childCount"), py::arg("localMatrix") = nullptr) .def("makeShader", - py::overload_cast, SkSpan, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), - py::arg("uniforms"), py::arg("children"), - py::arg("localMatrix") = nullptr) + py::overload_cast, SkSpan, const SkMatrix*>(&SkRuntimeEffect::makeShader, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("localMatrix") = nullptr) .def("makeColorFilter", - py::overload_cast>(&SkRuntimeEffect::makeColorFilter, py::const_), - py::arg("uniforms")) + py::overload_cast>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms")) .def("makeColorFilter", - py::overload_cast, sk_sp[], size_t>(&SkRuntimeEffect::makeColorFilter, py::const_), - py::arg("uniforms"), py::arg("children"), - py::arg("childCount")) + py::overload_cast, sk_sp[], size_t>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children"), + py::arg("childCount")) .def("makeColorFilter", - py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), - py::arg("uniforms"), py::arg("children")) + py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children")) .def("makeBlender", - [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { - return runtime_effect.makeColorFilter(uniforms, {}); - }, - py::arg("uniforms")) + [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { + return runtime_effect.makeColorFilter(uniforms, {}); + }, + py::arg("uniforms")) .def("makeBlender", - py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), - py::arg("uniforms"), py::arg("children") = SkSpan{}) + py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::arg("uniforms"), py::arg("children") = SkSpan{}) ; py::class_(m, "RuntimeEffectBuilderUniform") @@ -157,29 +157,29 @@ runtime_effect_builder .def("child", &SkRuntimeEffectBuilder::child, py::arg("name")) .def("setUniform", - [] (SkRuntimeEffectBuilder& builder, std::string_view name, int uniform) { - auto v = builder.uniform(name); - v = uniform; - }, - py::arg("name"), py::arg("uniform")) + [] (SkRuntimeEffectBuilder& builder, std::string_view name, int uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) .def("setUniform", - [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV3& uniform) { - auto v = builder.uniform(name); - v = uniform; - }, - py::arg("name"), py::arg("uniform")) + [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV3& uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) .def("setUniform", - [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV4& uniform) { - auto v = builder.uniform(name); - v = uniform; - }, - py::arg("name"), py::arg("uniform")) + [] (SkRuntimeEffectBuilder& builder, std::string_view name, const SkV4& uniform) { + auto v = builder.uniform(name); + v = uniform; + }, + py::arg("name"), py::arg("uniform")) .def("setChild", - [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { - auto v = builder.child(name); - v = child; - }, - py::arg("name"), py::arg("child")) + [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { + auto v = builder.child(name); + v = child; + }, + py::arg("name"), py::arg("child")) .def("uniforms", &SkRuntimeEffectBuilder::uniforms) .def("children", &SkRuntimeEffectBuilder::children) .def("makeShader", &SkRuntimeEffectBuilder::makeShader, From b7840b518c673153e565eaafd424ada1c87212ed Mon Sep 17 00:00:00 2001 From: meetwq Date: Mon, 4 Nov 2024 17:13:16 +0800 Subject: [PATCH 35/71] package icudtl.dat file in setup.py Fixes #278 and #268 and #195 --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index e4494234..a9d2bdbc 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ 'SKIA_OUT_PATH', os.path.join(SKIA_PATH, 'out', 'Release') ) +data_files = [] if sys.platform == 'win32': DEFINE_MACROS = [] # doesn't work for cl.exe LIBRARIES = [ @@ -54,6 +55,7 @@ '/OPT:ICF', '/OPT:REF', ] + data_files = [('Lib/site-packages', [os.path.join(SKIA_OUT_PATH, 'icudtl.dat')])] elif sys.platform == 'darwin': DEFINE_MACROS = [ ('VERSION_INFO', __version__), @@ -173,6 +175,7 @@ def build_extensions(self): long_description=open('README.md', 'r').read(), long_description_content_type='text/markdown', ext_modules=[extension], + data_files=data_files, install_requires=[ 'numpy', 'pybind11>=2.6' From 9bda7613dbba004c692c0fa7cae63f6c76ed356b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 1 Oct 2024 20:18:19 +0100 Subject: [PATCH 36/71] Re-enable Paragraph-related tests affected by icudtl.dat Revert "skip test_Paragraph_init0 on windows for now; investigate later" This reverts commit 10bf421b692a507510214cb710be9fc7246624bc. --- tests/test_paragraph.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_paragraph.py b/tests/test_paragraph.py index fb759af9..724dc5ef 100644 --- a/tests/test_paragraph.py +++ b/tests/test_paragraph.py @@ -1,6 +1,5 @@ import skia import pytest -import sys def test_FontCollection_init0(): assert isinstance(skia.textlayout.FontCollection(), skia.textlayout_FontCollection) @@ -21,8 +20,6 @@ def test_ParagraphBuilder_init0(paragraph_builder): assert isinstance(paragraph_builder, skia.textlayout_ParagraphBuilder) def test_Paragraph_init0(paragraph_builder): - if sys.platform.startswith("win"): - pytest.skip("Known not to work; To be investigated.") paragraph_builder.addText("") paragraph = paragraph_builder.Build() assert isinstance(paragraph, skia.textlayout_Paragraph) From eca5ba4061a9745a39e2e6bd6e2bbd19c3157c6d Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 1 Oct 2024 20:19:33 +0100 Subject: [PATCH 37/71] Re-enable Unicodes-related tests affected by icudtl.dat Revert "skia.Unicodes.ICU.Make() returns "None" on windows. Disabling skia.Unicodes tests on windows for the moment." This reverts commit 01e9fc5795bc0bbedc3d3a3c0af3187ad59b8551. Revert "missing import sys" This reverts commit 39b6e0db9925320050354c9b46987f15f517e35a. --- tests/test_unicode.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/test_unicode.py b/tests/test_unicode.py index 9a1684e4..c7b8a364 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -1,20 +1,13 @@ import skia import pytest -import sys def test_Unicodes_init0(): - if sys.platform.startswith("win"): - pytest.skip("Known not to work; To be investigated.") assert isinstance(skia.Unicode(), skia.Unicode) # recommended alias (upstream): def test_Unicodes_init1(): - if sys.platform.startswith("win"): - pytest.skip("Known not to work; To be investigated.") assert isinstance(skia.Unicodes.ICU.Make(), skia.Unicode) # Canonical def test_Unicodes_init2(): - if sys.platform.startswith("win"): - pytest.skip("Known not to work; To be investigated.") assert isinstance(skia.Unicode.ICU_Make(), skia.Unicode) From d12cb90ef6246aa506a825519492464ba92f1660 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 4 Nov 2024 14:21:24 +0000 Subject: [PATCH 38/71] Emoji modifier test from #195, for all platforms. --- tests/test_font.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_font.py b/tests/test_font.py index 2a220f98..8fd8a656 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -1,3 +1,5 @@ +import os +import sys import skia import pytest @@ -643,3 +645,42 @@ def test_FontMetrics_hasStrikeoutThickness(fontmetrics): def test_FontMetrics_hasStrikeoutPosition(fontmetrics): position = 0. assert isinstance(fontmetrics.hasStrikeoutPosition(position), bool) + + +@pytest.fixture +def color_emoji_run(): + if sys.platform.startswith("linux"): + typeface = skia.Typeface("Noto Color Emoji") + if sys.platform.startswith("darwin"): + typeface = skia.Typeface("Apple Color Emoji") + if sys.platform.startswith("win"): + typeface = skia.Typeface("Segoe UI Emoji") # COLRv0 + text = "✌✌🏻" + font = skia.Font(typeface,109) + blob = skia.TextBlob.MakeFromShapedText(text, font) + run = [x for x in blob] + return run[0] + +def test_emoji_count(color_emoji_run): + assert (color_emoji_run.fGlyphCount == 2) + +def test_emoji_typeface(color_emoji_run): + assert ((color_emoji_run.fTypeface.getFamilyName() == "Noto Color Emoji") + or (color_emoji_run.fTypeface.getFamilyName() == "Apple Color Emoji") + or (color_emoji_run.fTypeface.getFamilyName() == "Segoe UI Emoji")) + +# The numbers are hardcoded for three specific version of fonts, +# and will change if the hosts are upgraded. +def test_emoji_glyph1(color_emoji_run): + if (os.getenv("GITHUB_ACTION") == True): + assert ((color_emoji_run.fGlyphIndices[0] == 148) + or (color_emoji_run.fGlyphIndices[0] == 247) + or (color_emoji_run.fGlyphIndices[0] == 1567)) + +# The numbers are hardcoded for three specific version of fonts, +# and will change if the hosts are upgraded. +def test_emoji_glyph2(color_emoji_run): + if (os.getenv("GITHUB_ACTION") == True): + assert ((color_emoji_run.fGlyphIndices[1] == 1512) + or (color_emoji_run.fGlyphIndices[1] == 248) + or (color_emoji_run.fGlyphIndices[1] == 1571)) From 1aaecaad506ea517f8f4ca644084b5a354ed296f Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Mon, 4 Nov 2024 14:29:14 +0000 Subject: [PATCH 39/71] Update README.m130.md on icudtl.dat --- relnotes/README.m130.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/relnotes/README.m130.md b/relnotes/README.m130.md index fa8bc7ba..4b61d791 100644 --- a/relnotes/README.m130.md +++ b/relnotes/README.m130.md @@ -16,10 +16,10 @@ Since m128 (last beta release): overloaded as an alias to this, too. * The `SkUnicode` class is now available under python as `skia.Unicode`. - The constructor is known to fail on windows - It is likely that downloading - a `icudtl.dat` file, renaming from the versioned data-bin-{l,b}.zip in - https://github.com/unicode-org/icu/releases, is needed. Windows users please report - success/failure on this. + The constructor is known to fail on windows on m130, without a bundled + `icudtl.dat` file. + + EDIT: Therefore, we bundle a `icudtl.dat` file for windows from m131 onward. * There are two examples `shape_text.py` (a python port of upstream's example), and `skparagraph-example.py` hosted [elsewhere](https://github.com/HinTak/skia-python-examples/). From a9a4d2eab7acec8d0d696a611dda2ec2ea481de2 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 5 Nov 2024 00:12:52 +0000 Subject: [PATCH 40/71] Load Noto Color Emoji from disk on Ubuntu --- tests/test_font.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_font.py b/tests/test_font.py index 8fd8a656..b895633f 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -650,7 +650,12 @@ def test_FontMetrics_hasStrikeoutPosition(fontmetrics): @pytest.fixture def color_emoji_run(): if sys.platform.startswith("linux"): - typeface = skia.Typeface("Noto Color Emoji") + if (os.getenv("GITHUB_ACTION") == True): + # Ubuntu is weird - the font is on disk but not accessible to fontconfig + # - Possibly https://bugs.launchpad.net/bugs/2054924 + typeface = skia.Typeface.MakeFromFile("/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf") + else: + pytest.skip("Not in Ubuntu CI") if sys.platform.startswith("darwin"): typeface = skia.Typeface("Apple Color Emoji") if sys.platform.startswith("win"): From d00fa9af5ae715021a9f504394ad8a92f98d6d74 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 5 Nov 2024 00:19:33 +0000 Subject: [PATCH 41/71] macos-12 deprecated, begins failing 4th Nov; ends 3rd Dec. https://github.com/actions/runner-images/issues/10721 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f104578c..b25b71de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,11 +73,11 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, windows-2022, macos-12] + os: [ubuntu-22.04, windows-2022, macos-13] arch: [auto64] cp: ["cp3{8,9,10,11,12}"] include: - - os: macos-12 + - os: macos-13 arch: arm64 cp: "cp3{8,9,10,11,12}" # aarch64 is emulated and takes longer, build one wheel per job From 892d9437cb16696ffab25579594a7c59d942bff8 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 5 Nov 2024 18:47:52 +0000 Subject: [PATCH 42/71] New Paragraph test, adapted from #278; also refactoring existing tests. --- tests/test_paragraph.py | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/tests/test_paragraph.py b/tests/test_paragraph.py index 724dc5ef..5f463358 100644 --- a/tests/test_paragraph.py +++ b/tests/test_paragraph.py @@ -1,14 +1,29 @@ import skia import pytest -def test_FontCollection_init0(): - assert isinstance(skia.textlayout.FontCollection(), skia.textlayout_FontCollection) +@pytest.fixture(scope='session') +def textlayout_font_collection(): + return skia.textlayout.FontCollection() + +def test_FontCollection_init0(textlayout_font_collection): + assert isinstance(textlayout_font_collection, skia.textlayout_FontCollection) + + +@pytest.fixture(scope='session') +def paragraph_style(): + return skia.textlayout.ParagraphStyle() -def test_ParagraphStyle_init0(): - assert isinstance(skia.textlayout.ParagraphStyle(),skia.textlayout_ParagraphStyle) +def test_ParagraphStyle_init0(paragraph_style): + assert isinstance(paragraph_style, skia.textlayout_ParagraphStyle) + + +@pytest.fixture(scope='session') +def textlayout_text_style(): + return skia.textlayout.TextStyle() + +def test_TextStyle_init0(textlayout_text_style): + assert isinstance(textlayout_text_style, skia.textlayout_TextStyle) -def test_TextStyle_init0(): - assert isinstance(skia.textlayout.TextStyle(), skia.textlayout_TextStyle) @pytest.fixture(scope='session') def paragraph_builder(): @@ -23,3 +38,26 @@ def test_Paragraph_init0(paragraph_builder): paragraph_builder.addText("") paragraph = paragraph_builder.Build() assert isinstance(paragraph, skia.textlayout_Paragraph) + + +# Adapted from #278, to make sure that "\n" results in a line break (rather that .notdef). +# Height is larger than twice width, if a break happens. +def test_Paragraph_linebreak(paragraph_builder, textlayout_text_style, textlayout_font_collection, paragraph_style): + paint = skia.Paint() + paint.setColor(skia.ColorBLACK) + paint.setAntiAlias(True) + + textlayout_text_style.setFontSize(50) + textlayout_text_style.setForegroundPaint(paint) + + textlayout_font_collection.setDefaultFontManager(skia.FontMgr()) + + builder = skia.textlayout.ParagraphBuilder.make( + paragraph_style, textlayout_font_collection, skia.Unicodes.ICU.Make() + ) + builder.pushStyle(textlayout_text_style) + + builder.addText("o\no") + paragraph = builder.Build() + paragraph.layout(300) + assert (paragraph.Height > 0) and (paragraph.Height > paragraph.LongestLine * 2) From e5ec86d767868009ae8750c96864bdd8bdefafc6 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Tue, 5 Nov 2024 00:19:33 +0000 Subject: [PATCH 43/71] macos-12 deprecated, begins failing 4th Nov; ends 3rd Dec. https://github.com/actions/runner-images/issues/10721 --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0dde6bb4..3c44f8a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,11 +73,11 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, windows-2022, macos-12] + os: [ubuntu-22.04, windows-2022, macos-13] arch: [auto64] cp: ["cp3{10,11,12,13}"] include: - - os: macos-12 + - os: macos-13 arch: arm64 cp: "cp3{10,11,12,13}" # aarch64 is emulated and takes longer, build one wheel per job @@ -142,11 +142,11 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, windows-2022, macos-12] + os: [ubuntu-22.04, windows-2022, macos-13] arch: [auto64] cp: ["cp3{8,9}"] include: - - os: macos-12 + - os: macos-13 arch: arm64 cp: "cp3{8,9}" # aarch64 is emulated and takes longer, build one wheel per job From 7c16335fbf0be96862eadfeab0ba2b2c1e97dee5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 15:53:28 +0000 Subject: [PATCH 44/71] README.m131 --- README.md | 2 +- relnotes/README.m131.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 relnotes/README.m131.md diff --git a/README.md b/README.md index 43388386..32add7be 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ https://kyamagu.github.io/skia-python [README.m120](relnotes/README.m120.md), [README.m121](relnotes/README.m121.md), [README.m122](relnotes/README.m122.md), [README.m123](relnotes/README.m123.md), [README.m124](relnotes/README.m124.md), [README.m125](relnotes/README.m125.md), [README.m126](relnotes/README.m126.md), [README.m127](relnotes/README.m127.md), [README.m128](relnotes/README.m128.md), - [README.m129](relnotes/README.m129.md), [README.m130](relnotes/README.m130.md). + [README.m129](relnotes/README.m129.md), [README.m130](relnotes/README.m130.md), [README.m131](relnotes/README.m131.md). ## Contributing diff --git a/relnotes/README.m131.md b/relnotes/README.m131.md new file mode 100644 index 00000000..3c2602b8 --- /dev/null +++ b/relnotes/README.m131.md @@ -0,0 +1,10 @@ +Since m130: + +- We now build for Mac OS 13 (12 deprecated at github), and support python 3.13 + +- GL examples and tests updated, to restrict "Mac OS friendly" GL settings to Mac only. + Some Linux installations - specifically, inside github CI - are sensitive to those; + typical desktop linux boxes with real graphic cards seem not to be affected. + +- `PDF.StructureElementNode.fAdditionalNodeIds` withdrawn. + `SkPDF::StructureElementNode::fAdditionalNodeIds` removed upstream. From 4fdd2e18a1799789ff3a4370f79dd16b660749aa Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 19:34:51 +0000 Subject: [PATCH 45/71] README.m132 --- README.md | 3 ++- relnotes/README.m132.md | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 relnotes/README.m132.md diff --git a/README.md b/README.md index 32add7be..5b84501a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ https://kyamagu.github.io/skia-python [README.m120](relnotes/README.m120.md), [README.m121](relnotes/README.m121.md), [README.m122](relnotes/README.m122.md), [README.m123](relnotes/README.m123.md), [README.m124](relnotes/README.m124.md), [README.m125](relnotes/README.m125.md), [README.m126](relnotes/README.m126.md), [README.m127](relnotes/README.m127.md), [README.m128](relnotes/README.m128.md), - [README.m129](relnotes/README.m129.md), [README.m130](relnotes/README.m130.md), [README.m131](relnotes/README.m131.md). + [README.m129](relnotes/README.m129.md), [README.m130](relnotes/README.m130.md), [README.m131](relnotes/README.m131.md), + [README.m132](relnotes/README.m132.md). ## Contributing diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md new file mode 100644 index 00000000..1e3b8042 --- /dev/null +++ b/relnotes/README.m132.md @@ -0,0 +1,24 @@ +Since m131: + +- We now bundle a `icudtl.dat` for windows. This fixes windows-specific problems + with SkUnicode, libSkShaper, and SkParagraph. Thanks @meetwq for the change. + Relevant CI tests re-enabled and added. + +- Upstream's `SkNamedTransferFn::*` now available as `cms.NamedTransferFn.*`, + and `SkNamedGamut::*` as `cms.NamedGamut.*`. These are used in RuntimeEffect-related + code. + +- More overloads of `SkImage::makeShader` added, and `SkImage::makeRawShader` added + as `Image.makeRawShader`. + +- We binds `SkRuntimeEffect` as `skia.RuntimeEffect`. Added some helper classes: + `SkV3` as `skia.V3`, `SkV4` as `skia.V4`, + `SkRuntimeEffect::Result` as `RuntimeEffectResult`, + `SkRuntimeEffect::ChildPtr` as `RuntimeEffectChildPtr`, + `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder', + `std::vector` as `VectorSkRuntimeEffectChildPtr`, + `SkSpan` as `SpanRuntimeEffectChildPtr`, + `SkRuntimeEffectBuilder::BuilderUniform` as `RuntimeEffectBuilderUniform`, + `SkRuntimeEffectBuilder::BuilderChild` as `RuntimeEffectBuilderChild`. + Details are subjected to change. We ported all 9 of current upstream SkSL c++ examples, + hosted [elsewhere](https://github.com/HinTak/skia-python-examples/). \ No newline at end of file From b0aa3ce54a5253cf289ade868c2e5597b8080118 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 20:00:10 +0000 Subject: [PATCH 46/71] Tests for image.makeRawShader(), and additional parameters for testing image.makeShader() --- tests/test_image.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_image.py b/tests/test_image.py index 57ee5f47..91a8d7cc 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -161,11 +161,27 @@ def test_Image_isOpaque(image): (skia.TileMode.kRepeat, skia.TileMode.kRepeat), (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions()), (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions(), None), + (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions(), skia.Matrix()), + (skia.SamplingOptions(), None), + (skia.SamplingOptions(), skia.Matrix()), ]) def test_Image_makeShader(image, args): assert isinstance(image.makeShader(*args), skia.Shader) +@pytest.mark.parametrize('args', [ + tuple(), + (skia.TileMode.kRepeat, skia.TileMode.kRepeat), + (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions()), + (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions(), None), + (skia.TileMode.kRepeat, skia.TileMode.kRepeat, skia.SamplingOptions(), skia.Matrix()), + (skia.SamplingOptions(), None), + (skia.SamplingOptions(), skia.Matrix()), +]) +def test_Image_makeRawShader(image, args): + assert isinstance(image.makeRawShader(*args), skia.Shader) + + def test_Image_peekPixels(image): assert isinstance(image.peekPixels(skia.Pixmap()), bool) From edd96a703b9c1669b6fd2d3a7962441d4b1a1583 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 21:51:11 +0000 Subject: [PATCH 47/71] cut-and-paste typo discovered while writing tests --- src/skia/RuntimeEffect.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index c427b15d..7f3a4914 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -133,11 +133,11 @@ runtime_effect py::arg("uniforms"), py::arg("children")) .def("makeBlender", [] (SkRuntimeEffect& runtime_effect, sk_sp uniforms) { - return runtime_effect.makeColorFilter(uniforms, {}); + return runtime_effect.makeBlender(uniforms, {}); }, py::arg("uniforms")) .def("makeBlender", - py::overload_cast, SkSpan>(&SkRuntimeEffect::makeColorFilter, py::const_), + py::overload_cast, SkSpan>(&SkRuntimeEffect::makeBlender, py::const_), py::arg("uniforms"), py::arg("children") = SkSpan{}) ; From 720e5f35af2b7482f3f0eb1966c9d0b5fa325e4f Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 21:17:53 +0000 Subject: [PATCH 48/71] tests/test_runtime_effect.py --- tests/test_runtime_effect.py | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/test_runtime_effect.py diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py new file mode 100644 index 00000000..604a3f20 --- /dev/null +++ b/tests/test_runtime_effect.py @@ -0,0 +1,77 @@ +import skia +import pytest + +@pytest.fixture(scope='session') +def runtime_effect(): + return skia.RuntimeEffect.MakeForShader("half4 main(float2 coord){return half4(0,0,0,0);}") + +def test_RuntimeEffect_init0(runtime_effect): + assert isinstance(runtime_effect, skia.RuntimeEffect) + + +def test_V3_init0(): + assert isinstance(skia.V3(0,0,0), skia.V3) + +def test_V4_init0(): + assert isinstance(skia.V4(0,0,0,0), skia.V4) + + +@pytest.fixture(scope='session') +def runtime_effect_builder(runtime_effect): + return skia.RuntimeEffectBuilder(runtime_effect) + +def test_RuntimeEffectBuilder_init0(runtime_effect_builder): + assert isinstance(runtime_effect_builder, skia.RuntimeEffectBuilder) + +# setUniform is polymorphic, so we are just testing that the +# accepted object types do not throw errors. +@pytest.mark.parametrize('arg', [ + (skia.V3(0,0,0)), + (skia.V4(0,0,0,0)), +]) +def test_RuntimeEffectBuilder_setUniform(runtime_effect_builder, arg): + runtime_effect_builder.setUniform("bogus", arg) + + +def test_RuntimeEffect_make_type1(runtime_effect): + assert isinstance(runtime_effect.makeShader(None), skia.Shader) + +@pytest.mark.xfail(reason="Current SkSL snipplet returns None as ColorFilter; TODO: Find useful SkSL snipplet for construction") +def test_RuntimeEffect_make_type2(runtime_effect): + assert isinstance(runtime_effect.makeColorFilter(None), skia.ColorFilter) + +@pytest.mark.xfail(reason="We don't bind SkBlender yet. TODO") +def test_RuntimeEffect_make_type3(runtime_effect): + assert isinstance(runtime_effect.makeBlender(None), skia.Blender) + + +# These test implicit conversion to RuntimeEffectChildPtr +def test_RuntimeEffectBuilder_setChild1(runtime_effect_builder, runtime_effect): + runtime_effect_builder.setChild("bogus", runtime_effect.makeShader(None)) + +def test_RuntimeEffectBuilder_setChild2(runtime_effect_builder, runtime_effect): + runtime_effect_builder.setChild("bogus", runtime_effect.makeColorFilter(None)) + +@pytest.mark.xfail(reason="We don't bind SkBlender yet. TODO") +def test_RuntimeEffectBuilder_setChild3(runtime_effect_builder, runtime_effect): + runtime_effect_builder.setChild("bogus", runtime_effect.makeBlender(None)) + + +@pytest.mark.xfail(reason="We throw on invalid struct and don't use the whole struct anymore / at the moment.") +def test_RuntimeEffectResult_init0(): + assert isinstance(skia.RuntimeEffectResult(), skia.RuntimeEffectResult) + +def test_RuntimeEffectChildPtr_init0(): + assert isinstance(skia.RuntimeEffectChildPtr(), skia.RuntimeEffectChildPtr) + +def test_VectorSkRuntimeEffectChildPtr_init0(): + assert isinstance(skia.VectorSkRuntimeEffectChildPtr(), skia.VectorSkRuntimeEffectChildPtr) + +def test_SpanRuntimeEffectChildPtr_init0(): + assert isinstance(skia.SpanRuntimeEffectChildPtr(), skia.SpanRuntimeEffectChildPtr) + +def test_RuntimeEffectBuilderUniform_init0(): + assert isinstance(skia.RuntimeEffectBuilderUniform(), skia.RuntimeEffectBuilderUniform) + +def test_RuntimeEffectBuilderChild_init0(): + assert isinstance(skia.RuntimeEffectBuilderChild(), skia.RuntimeEffectBuilderChild) From a3c1d2bb45a1f9116c651d8cc98be8f9dda1d8ba Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 22:42:17 +0000 Subject: [PATCH 49/71] Update comment --- src/skia/RuntimeEffect.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 7f3a4914..29e7fef6 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -58,7 +58,10 @@ py::implicitly_convertible, SkRuntimeEffect::ChildPtr>(); py::implicitly_convertible, SkRuntimeEffect::ChildPtr>(); py::implicitly_convertible, SkSpan>(); -/* Should all of these static methods just check Result.effect being non-null, throw with errorText if null? */ +/* + All of these static methods check Result.effect being non-null, throw with errorText if null; + they differ from upsteam c++ APIs, which asks clients to check. +*/ runtime_effect .def_static("MakeForColorFilter", [] (SkString sksl, const SkRuntimeEffect::Options& options) { From 4e3702f89af2f664ae293f24c55e325d4b8b7110 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 22:57:12 +0000 Subject: [PATCH 50/71] Comments --- src/skia/ColorSpace.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/skia/ColorSpace.cpp b/src/skia/ColorSpace.cpp index e6e0b6e7..c93bcf79 100644 --- a/src/skia/ColorSpace.cpp +++ b/src/skia/ColorSpace.cpp @@ -37,6 +37,8 @@ py::class_(skcms, "TransferFunction", }; }), py::arg("v")); +/* Upstream static constexpr's, which function like enum's, + but cannot be bound that way. */ m.attr("cms").attr("NamedTransferFn") = m.attr("cms").attr("TransferFunction"); m.attr("cms").attr("TransferFunction").attr("kSRGB") = SkNamedTransferFn::kSRGB; m.attr("cms").attr("TransferFunction").attr("k2Dot2") = SkNamedTransferFn::k2Dot2; @@ -60,6 +62,8 @@ py::class_(skcms, "Matrix3x3", }}; }), py::arg("v")); +/* Upstream static constexpr's, which function like enum's, + but cannot be bound that way. */ m.attr("cms").attr("NamedGamut") = m.attr("cms").attr("Matrix3x3"); m.attr("cms").attr("Matrix3x3").attr("kSRGB") = SkNamedGamut::kSRGB; m.attr("cms").attr("Matrix3x3").attr("kAdobeRGB") = SkNamedGamut::kAdobeRGB; From d1d0b4fb97d90db1dff2e8d93d67821151f378a8 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 23:57:49 +0000 Subject: [PATCH 51/71] Adding tests for RuntimeEffect.MakeForColorFilter/RuntimeEffect.MakeForBlender Update SkSL snipplet to reflect recommended prototypes from SkRuntimeEffect.h: Color filter SkSL: vec4 main(vec4 inColor) { ... } Shader SkSL: vec4 main(vec2 inCoords) { ... } Blend SkSL: vec4 main(vec4 srcColor, vec4 dstColor) { ... } --- tests/test_runtime_effect.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py index 604a3f20..a4d9100f 100644 --- a/tests/test_runtime_effect.py +++ b/tests/test_runtime_effect.py @@ -3,11 +3,24 @@ @pytest.fixture(scope='session') def runtime_effect(): - return skia.RuntimeEffect.MakeForShader("half4 main(float2 coord){return half4(0,0,0,0);}") + return skia.RuntimeEffect.MakeForShader("vec4 main(vec2 inCoords){return vec4(0,0,0,0);}") + +@pytest.fixture(scope='session') +def runtime_effect_color(): + return skia.RuntimeEffect.MakeForColorFilter("vec4 main(vec4 inColor){return vec4(0,0,0,0);}") + +@pytest.fixture(scope='session') +def runtime_effect_blender(): + return skia.RuntimeEffect.MakeForBlender("vec4 main(vec4 srcColor, vec4 dstColor){return vec4(0,0,0,0);}") def test_RuntimeEffect_init0(runtime_effect): assert isinstance(runtime_effect, skia.RuntimeEffect) +def test_RuntimeEffect_init1(runtime_effect_color): + assert isinstance(runtime_effect_color, skia.RuntimeEffect) + +def test_RuntimeEffect_init2(runtime_effect_blender): + assert isinstance(runtime_effect_blender, skia.RuntimeEffect) def test_V3_init0(): assert isinstance(skia.V3(0,0,0), skia.V3) From e5b035d4bbfc82499c523510448e84628872ed11 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 00:12:10 +0000 Subject: [PATCH 52/71] Adding more SkRuntimeEffectBuilder::Child= overloads --- src/skia/RuntimeEffect.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 29e7fef6..6dc826a4 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -183,6 +183,18 @@ runtime_effect_builder v = child; }, py::arg("name"), py::arg("child")) + .def("setChild", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { + auto v = builder.child(name); + v = child; + }, + py::arg("name"), py::arg("child")) + .def("setChild", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { + auto v = builder.child(name); + v = child; + }, + py::arg("name"), py::arg("child")) .def("uniforms", &SkRuntimeEffectBuilder::uniforms) .def("children", &SkRuntimeEffectBuilder::children) .def("makeShader", &SkRuntimeEffectBuilder::makeShader, From 0fbf262f287543793257446ca159198b2851690a Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 00:14:57 +0000 Subject: [PATCH 53/71] Use runtime_effect_color/runtime_effect_blender for testing; Now test_RuntimeEffect_make_type2 works --- tests/test_runtime_effect.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py index a4d9100f..dc8d540e 100644 --- a/tests/test_runtime_effect.py +++ b/tests/test_runtime_effect.py @@ -49,25 +49,24 @@ def test_RuntimeEffectBuilder_setUniform(runtime_effect_builder, arg): def test_RuntimeEffect_make_type1(runtime_effect): assert isinstance(runtime_effect.makeShader(None), skia.Shader) -@pytest.mark.xfail(reason="Current SkSL snipplet returns None as ColorFilter; TODO: Find useful SkSL snipplet for construction") -def test_RuntimeEffect_make_type2(runtime_effect): - assert isinstance(runtime_effect.makeColorFilter(None), skia.ColorFilter) +def test_RuntimeEffect_make_type2(runtime_effect_color): + assert isinstance(runtime_effect_color.makeColorFilter(None), skia.ColorFilter) @pytest.mark.xfail(reason="We don't bind SkBlender yet. TODO") -def test_RuntimeEffect_make_type3(runtime_effect): - assert isinstance(runtime_effect.makeBlender(None), skia.Blender) +def test_RuntimeEffect_make_type3(runtime_effect_blender): + assert isinstance(runtime_effect_blender.makeBlender(None), skia.Blender) # These test implicit conversion to RuntimeEffectChildPtr def test_RuntimeEffectBuilder_setChild1(runtime_effect_builder, runtime_effect): runtime_effect_builder.setChild("bogus", runtime_effect.makeShader(None)) -def test_RuntimeEffectBuilder_setChild2(runtime_effect_builder, runtime_effect): - runtime_effect_builder.setChild("bogus", runtime_effect.makeColorFilter(None)) +def test_RuntimeEffectBuilder_setChild2(runtime_effect_builder, runtime_effect_color): + runtime_effect_builder.setChild("bogus", runtime_effect_color.makeColorFilter(None)) @pytest.mark.xfail(reason="We don't bind SkBlender yet. TODO") -def test_RuntimeEffectBuilder_setChild3(runtime_effect_builder, runtime_effect): - runtime_effect_builder.setChild("bogus", runtime_effect.makeBlender(None)) +def test_RuntimeEffectBuilder_setChild3(runtime_effect_builder, runtime_effect_blender): + runtime_effect_builder.setChild("bogus", runtime_effect_blender.makeBlender(None)) @pytest.mark.xfail(reason="We throw on invalid struct and don't use the whole struct anymore / at the moment.") From 631e48e2f5acd00d0c4d254b9a8183571e14ef71 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 00:36:03 +0000 Subject: [PATCH 54/71] Remove "Sk" from "VectorSkRuntimeEffectChildPtr" --- relnotes/README.m132.md | 2 +- src/skia/RuntimeEffect.cpp | 2 +- tests/test_runtime_effect.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md index 1e3b8042..5fa030e1 100644 --- a/relnotes/README.m132.md +++ b/relnotes/README.m132.md @@ -16,7 +16,7 @@ Since m131: `SkRuntimeEffect::Result` as `RuntimeEffectResult`, `SkRuntimeEffect::ChildPtr` as `RuntimeEffectChildPtr`, `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder', - `std::vector` as `VectorSkRuntimeEffectChildPtr`, + `std::vector` as `VectorRuntimeEffectChildPtr`, `SkSpan` as `SpanRuntimeEffectChildPtr`, `SkRuntimeEffectBuilder::BuilderUniform` as `RuntimeEffectBuilderUniform`, `SkRuntimeEffectBuilder::BuilderChild` as `RuntimeEffectBuilderChild`. diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index 6dc826a4..ee4f99bc 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -11,7 +11,7 @@ py::class_, SkRefCnt> runtime_effect(m, py::class_ runtime_effect_childptr(m, "RuntimeEffectChildPtr"); -py::bind_vector>(m, "VectorSkRuntimeEffectChildPtr"); +py::bind_vector>(m, "VectorRuntimeEffectChildPtr"); py::class_> span_runtime_effect_childptr(m, "SpanRuntimeEffectChildPtr"); py::class_ runtime_effect_builder(m, "RuntimeEffectBuilder"); diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py index dc8d540e..8df97b1c 100644 --- a/tests/test_runtime_effect.py +++ b/tests/test_runtime_effect.py @@ -76,8 +76,8 @@ def test_RuntimeEffectResult_init0(): def test_RuntimeEffectChildPtr_init0(): assert isinstance(skia.RuntimeEffectChildPtr(), skia.RuntimeEffectChildPtr) -def test_VectorSkRuntimeEffectChildPtr_init0(): - assert isinstance(skia.VectorSkRuntimeEffectChildPtr(), skia.VectorSkRuntimeEffectChildPtr) +def test_VectorRuntimeEffectChildPtr_init0(): + assert isinstance(skia.VectorRuntimeEffectChildPtr(), skia.VectorRuntimeEffectChildPtr) def test_SpanRuntimeEffectChildPtr_init0(): assert isinstance(skia.SpanRuntimeEffectChildPtr(), skia.SpanRuntimeEffectChildPtr) From c1a6a5d76beeae9705da8bb2d7fef98689bd5018 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 00:45:52 +0000 Subject: [PATCH 55/71] Tests for font file at location, instead of GITHUB_ACTION env --- tests/test_font.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_font.py b/tests/test_font.py index f92fbdcd..8e1d78e5 100644 --- a/tests/test_font.py +++ b/tests/test_font.py @@ -663,10 +663,12 @@ def test_FontMetrics_hasStrikeoutPosition(fontmetrics): @pytest.fixture def color_emoji_run(): if sys.platform.startswith("linux"): - if (os.getenv("GITHUB_ACTION") == True): + if os.path.exists("/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf"): # Ubuntu CI # Ubuntu is weird - the font is on disk but not accessible to fontconfig # - Possibly https://bugs.launchpad.net/bugs/2054924 typeface = skia.Typeface.MakeFromFile("/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf") + elif os.path.exists("/usr/share/fonts/google-noto-color-emoji-fonts/NotoColorEmoji.ttf"): # Fedora + typeface = skia.Typeface.MakeFromFile("/usr/share/fonts/google-noto-color-emoji-fonts/NotoColorEmoji.ttf") else: pytest.skip("Not in Ubuntu CI") if sys.platform.startswith("darwin"): @@ -679,6 +681,7 @@ def color_emoji_run(): run = [x for x in blob] return run[0] +# We want this exactly two (and not three) on all platforms, under all circumstances; no conditionals. def test_emoji_count(color_emoji_run): assert (color_emoji_run.fGlyphCount == 2) From 664de84b45ec84ad30776876df1b83e63efe7846 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 14:50:11 +0000 Subject: [PATCH 56/71] Make SkV3/SkV4 convertible from py::list --- src/skia/RuntimeEffect.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/skia/RuntimeEffect.cpp b/src/skia/RuntimeEffect.cpp index ee4f99bc..ee40d27a 100644 --- a/src/skia/RuntimeEffect.cpp +++ b/src/skia/RuntimeEffect.cpp @@ -21,15 +21,33 @@ py::class_(m, "V3") [] (float x, float y, float z) { return SkV3{x, y, z}; })) + .def(py::init( + [] (py::tuple v3) { + if (v3.size() != 3) + throw py::value_error("V3 must have exactly three elements."); + return SkV3{v3[0].cast(), v3[1].cast(), v3[2].cast()}; + }), + py::arg("v3")) ; +py::implicitly_convertible(); + py::class_(m, "V4") .def(py::init( [] (float x, float y, float z, float w) { return SkV4{x, y, z, w}; })) + .def(py::init( + [] (py::tuple v4) { + if (v4.size() != 4) + throw py::value_error("V4 must have exactly four elements."); + return SkV4{v4[0].cast(), v4[1].cast(), v4[2].cast(), v4[3].cast()}; + }), + py::arg("v4")) ; +py::implicitly_convertible(); + py::class_(m, "RuntimeEffectResult") .def_readwrite("effect", &SkRuntimeEffect::Result::effect) .def_readwrite("errorText", &SkRuntimeEffect::Result::errorText) @@ -177,6 +195,17 @@ runtime_effect_builder v = uniform; }, py::arg("name"), py::arg("uniform")) + .def("setUniform", + [] (SkRuntimeEffectBuilder& builder, std::string_view name, py::list vN) { + if (vN.size() != 3 && vN.size() != 4) + throw py::value_error("Input must have exactly three or four elements."); + auto v = builder.uniform(name); + if (vN.size() == 3) + v = SkV3{vN[0].cast(), vN[1].cast(), vN[2].cast()}; + if (vN.size() == 4) + v = SkV4{vN[0].cast(), vN[1].cast(), vN[2].cast(), vN[3].cast()}; + }, + py::arg("name"), py::arg("uniform")) .def("setChild", [] (SkRuntimeEffectBuilder& builder, std::string_view name, sk_sp child) { auto v = builder.child(name); From 1ca55fc6d50a390a919e4d6e83ec6f211434fc2a Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 17:37:18 +0000 Subject: [PATCH 57/71] Testing more setUniform argument signatures --- tests/test_runtime_effect.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py index 8df97b1c..0377647c 100644 --- a/tests/test_runtime_effect.py +++ b/tests/test_runtime_effect.py @@ -39,8 +39,11 @@ def test_RuntimeEffectBuilder_init0(runtime_effect_builder): # setUniform is polymorphic, so we are just testing that the # accepted object types do not throw errors. @pytest.mark.parametrize('arg', [ + (0), (skia.V3(0,0,0)), (skia.V4(0,0,0,0)), + ([0,0,0]), + ([0,0,0,0]), ]) def test_RuntimeEffectBuilder_setUniform(runtime_effect_builder, arg): runtime_effect_builder.setUniform("bogus", arg) From 88e4e531a54b985e91911414f87fe4d310375052 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Thu, 7 Nov 2024 22:41:18 +0000 Subject: [PATCH 58/71] Adding tests: tuples as arguments to setUniform also work --- tests/test_runtime_effect.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_runtime_effect.py b/tests/test_runtime_effect.py index 0377647c..8f62ca2f 100644 --- a/tests/test_runtime_effect.py +++ b/tests/test_runtime_effect.py @@ -44,6 +44,8 @@ def test_RuntimeEffectBuilder_init0(runtime_effect_builder): (skia.V4(0,0,0,0)), ([0,0,0]), ([0,0,0,0]), + ((0,0,0)), + ((0,0,0,0)), ]) def test_RuntimeEffectBuilder_setUniform(runtime_effect_builder, arg): runtime_effect_builder.setUniform("bogus", arg) From e7fada6bb90bb77ad0c2bf135c3d94f11079a4d7 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 6 Nov 2024 22:48:29 +0000 Subject: [PATCH 59/71] White space --- relnotes/README.m132.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md index 5fa030e1..e4b0ec00 100644 --- a/relnotes/README.m132.md +++ b/relnotes/README.m132.md @@ -12,8 +12,8 @@ Since m131: as `Image.makeRawShader`. - We binds `SkRuntimeEffect` as `skia.RuntimeEffect`. Added some helper classes: - `SkV3` as `skia.V3`, `SkV4` as `skia.V4`, - `SkRuntimeEffect::Result` as `RuntimeEffectResult`, + `SkV3` as `skia.V3`, `SkV4` as `skia.V4`, + `SkRuntimeEffect::Result` as `RuntimeEffectResult`, `SkRuntimeEffect::ChildPtr` as `RuntimeEffectChildPtr`, `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder', `std::vector` as `VectorRuntimeEffectChildPtr`, @@ -21,4 +21,4 @@ Since m131: `SkRuntimeEffectBuilder::BuilderUniform` as `RuntimeEffectBuilderUniform`, `SkRuntimeEffectBuilder::BuilderChild` as `RuntimeEffectBuilderChild`. Details are subjected to change. We ported all 9 of current upstream SkSL c++ examples, - hosted [elsewhere](https://github.com/HinTak/skia-python-examples/). \ No newline at end of file + hosted [elsewhere](https://github.com/HinTak/skia-python-examples/). From 3c71d616cee29c0d13f3da8cc31a9f5fac619a4f Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Fri, 8 Nov 2024 13:57:44 +0000 Subject: [PATCH 60/71] typo --- relnotes/README.m132.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md index e4b0ec00..9fc10120 100644 --- a/relnotes/README.m132.md +++ b/relnotes/README.m132.md @@ -15,7 +15,7 @@ Since m131: `SkV3` as `skia.V3`, `SkV4` as `skia.V4`, `SkRuntimeEffect::Result` as `RuntimeEffectResult`, `SkRuntimeEffect::ChildPtr` as `RuntimeEffectChildPtr`, - `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder', + `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder`, `std::vector` as `VectorRuntimeEffectChildPtr`, `SkSpan` as `SpanRuntimeEffectChildPtr`, `SkRuntimeEffectBuilder::BuilderUniform` as `RuntimeEffectBuilderUniform`, From 702256120c6e50cdd3eede47a32e60fe80f7de28 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 20:46:16 +0000 Subject: [PATCH 61/71] Roll skia on m131 slightly (from canvaskit/0.38.2-6682-gf7f63e2604 to canvaskit/0.38.2-6684-g94631d9b9a) --- skia | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skia b/skia index f7f63e26..94631d9b 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit f7f63e2604e9d436f56daeaba55b103b578fc19e +Subproject commit 94631d9b9a10697325589e1642af63a0137cac94 From 9ab4b750ec11bf39be5d6b78586d7c4f12894378 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 20:48:20 +0000 Subject: [PATCH 62/71] Update skia to m132 (from canvaskit/0.38.2-6684-g94631d9b9a to canvaskit/0.38.2-6914-gb1fb88ac03) --- skia | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/skia b/skia index 94631d9b..b1fb88ac 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit 94631d9b9a10697325589e1642af63a0137cac94 +Subproject commit b1fb88ac03b77cf36a1aa9802a5bdb673e3ff983 From eccb8fb4ef86147ee0b303de42b03cd2ec633df7 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:27:01 +0000 Subject: [PATCH 63/71] Bump version to 132.0b11 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ad7ede41..425127bd 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ pass NAME = 'skia-python' -__version__ = '131.0b10' +__version__ = '132.0b11' SKIA_PATH = os.getenv('SKIA_PATH', 'skia') SKIA_OUT_PATH = os.getenv( From fe72809c8eec01fc2d26c7d961b034310a95b2b4 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:32:10 +0000 Subject: [PATCH 64/71] COLRv1 patch adjusted to small header addition, and expose SkFontDescriptor class also The new header in m132 is "src/ports/SkFontScanner_FreeType_priv.h". The SkFontDescriptor is possibly useful for accessing the COLRv1 palette (in my own experimental m129 changes); as is the new SkFontScanner API. --- patch/skia-m132-colrv1-freetype.diff | 122 +++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 patch/skia-m132-colrv1-freetype.diff diff --git a/patch/skia-m132-colrv1-freetype.diff b/patch/skia-m132-colrv1-freetype.diff new file mode 100644 index 00000000..7d818119 --- /dev/null +++ b/patch/skia-m132-colrv1-freetype.diff @@ -0,0 +1,122 @@ +diff --git a/src/core/SkFontDescriptor.h b/src/core/SkFontDescriptor.h +index a3018ee..5eadbed 100644 +--- a/src/core/SkFontDescriptor.h ++++ b/src/core/SkFontDescriptor.h +@@ -82,7 +82,7 @@ private: + skia_private::AutoSTMalloc<4, SkFontArguments::Palette::Override> fPaletteOverrides; + }; + +-class SkFontDescriptor : SkNoncopyable { ++class SK_SPI SkFontDescriptor : SkNoncopyable { + public: + SkFontDescriptor(); + // Does not affect ownership of SkStream. +diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp +index 7798b91..7637709 100644 +--- a/src/ports/SkFontHost_FreeType.cpp ++++ b/src/ports/SkFontHost_FreeType.cpp +@@ -32,7 +32,6 @@ + #include "src/core/SkMask.h" + #include "src/core/SkMaskGamma.h" + #include "src/core/SkScalerContext.h" +-#include "src/ports/SkFontHost_FreeType_common.h" + #include "src/ports/SkFontScanner_FreeType_priv.h" + #include "src/ports/SkTypeface_FreeType.h" + #include "src/sfnt/SkOTUtils.h" +@@ -52,6 +51,7 @@ + #ifdef FT_COLOR_H // 2.10.0 + # include + #endif ++#include "src/ports/SkFontHost_FreeType_common.h" + #include + #include + #include +diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp +index be5bc52..12bd7fe 100644 +--- a/src/ports/SkFontHost_FreeType_common.cpp ++++ b/src/ports/SkFontHost_FreeType_common.cpp +@@ -6,7 +6,6 @@ + * found in the LICENSE file. + */ + +-#include "src/ports/SkFontHost_FreeType_common.h" + + #include "include/core/SkBitmap.h" + #include "include/core/SkCanvas.h" +@@ -34,6 +33,7 @@ + #ifdef FT_COLOR_H + # include + #endif ++#include "src/ports/SkFontHost_FreeType_common.h" + #include + #include + #include +@@ -1575,6 +1575,41 @@ bool SkScalerContextFTUtils::drawCOLRv1Glyph(FT_Face face, const SkGlyph& glyph, + face, glyph.getGlyphID(), + FT_COLOR_INCLUDE_ROOT_TRANSFORM, &activePaints); + } ++/* ++ * This content is mostly just ++ * SkTypeface_FreeType::FaceRec::setupPalette() ++ + + SkScalerContext_FreeType_Base::drawCOLRv1Glyph() ++ +*/ ++bool SkScalerContextFTUtils::skia_colrv1_start_glyph(SkCanvas* canvas, ++ FT_Face face, ++ uint16_t glyphId, ++ FT_UShort palette_index, ++ FT_Color_Root_Transform rootTransform ++ ) { ++ uint32_t fForegroundColor{SK_ColorBLACK}; ++ FT_Palette_Data paletteData; ++ FT_Palette_Data_Get(face, &paletteData); ++ ++ FT_Color* ftPalette = nullptr; ++ FT_Palette_Select(face, palette_index, &ftPalette); ++ std::unique_ptr ptr_palette(new SkColor[paletteData.num_palette_entries]); ++ for (int i = 0; i < paletteData.num_palette_entries; ++i) { ++ ptr_palette[i] = SkColorSetARGB(ftPalette[i].alpha, ++ ftPalette[i].red, ++ ftPalette[i].green, ++ ftPalette[i].blue); ++ } ++ SkSpan palette(ptr_palette.get(), paletteData.num_palette_entries); ++ ++ VisitedSet activePaints; ++ bool haveLayers = colrv1_start_glyph(canvas, palette, ++ fForegroundColor, // FT_Palette_Get_Foreground_Color? ++ face, glyphId, ++ FT_COLOR_INCLUDE_ROOT_TRANSFORM, ++ &activePaints); ++ SkASSERTF(haveLayers, "Could not get COLRv1 layers from '%s'.", face->family_name); ++ return haveLayers; ++} + #endif // TT_SUPPORT_COLRV1 + + #ifdef FT_COLOR_H +diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h +index cd19ec7..40842c5 100644 +--- a/src/ports/SkFontHost_FreeType_common.h ++++ b/src/ports/SkFontHost_FreeType_common.h +@@ -20,6 +20,7 @@ class SkCanvas; + // These are forward declared to avoid pimpl but also hide the FreeType implementation. + typedef struct FT_FaceRec_* FT_Face; + typedef signed long FT_Pos; ++typedef unsigned short FT_UShort; /* freetype/fttypes.h */ + + + #ifdef SK_DEBUG +@@ -31,7 +32,13 @@ const char* SkTraceFtrGetError(int); + #define SK_TRACEFTR(ERR, ...) do { sk_ignore_unused_variable(ERR); } while (false) + #endif + +-struct SkScalerContextFTUtils { ++struct SK_SPI SkScalerContextFTUtils { ++ static bool skia_colrv1_start_glyph(SkCanvas* canvas, ++ FT_Face face, ++ uint16_t glyphId, ++ FT_UShort palette_index, ++ FT_Color_Root_Transform rootTransform ++ ); + SkColor fForegroundColor; + SkScalerContext::Flags fFlags; + From f111dd29f05f09b695889a1b40f1e42c8c1f59c9 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:39:12 +0000 Subject: [PATCH 65/71] Switch to use m132-colrv1 patch --- scripts/build_Linux.sh | 2 +- scripts/build_Windows.sh | 2 +- scripts/build_macOS.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/build_Linux.sh b/scripts/build_Linux.sh index 123e749c..75be91b3 100644 --- a/scripts/build_Linux.sh +++ b/scripts/build_Linux.sh @@ -61,7 +61,7 @@ git clone https://gn.googlesource.com/gn && \ # Build skia cd skia && \ patch -p1 < ../patch/skia-m131-minimize-download.patch && \ - patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ + patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ cp -f ../gn/out/gn bin/gn && \ bin/gn gen out/Release --args=" diff --git a/scripts/build_Windows.sh b/scripts/build_Windows.sh index f64409af..c18b00d4 100644 --- a/scripts/build_Windows.sh +++ b/scripts/build_Windows.sh @@ -5,7 +5,7 @@ export PATH="${PWD}/depot_tools:$PATH" # Build skia cd skia && \ patch -p1 < ../patch/skia-m131-minimize-download.patch && \ - patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ + patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python tools/git-sync-deps && \ bin/gn gen out/Release --args=' is_official_build=true diff --git a/scripts/build_macOS.sh b/scripts/build_macOS.sh index 07c44900..ee896c78 100644 --- a/scripts/build_macOS.sh +++ b/scripts/build_macOS.sh @@ -23,7 +23,7 @@ function apply_patch { cd skia && \ patch -p1 < ../patch/skia-m131-minimize-download.patch && \ - patch -p1 < ../patch/skia-m123-colrv1-freetype.diff && \ + patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ bin/gn gen out/Release --args=" is_official_build=true From 832fc56a7872ce2e7dd23e5bb2be21bdb93f6024 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:46:44 +0000 Subject: [PATCH 66/71] skia-m132-minimize-download patch plus adjustments --- .github/workflows/ci.yml | 2 +- patch/skia-m132-minimize-download.patch | 70 +++++++++++++++++++++++++ scripts/build_Linux.sh | 2 +- scripts/build_Windows.sh | 2 +- scripts/build_macOS.sh | 2 +- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 patch/skia-m132-minimize-download.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c44f8a2..434cc580 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: key: linux-aarch64-skia-${{ github.sha }}-3rd-party - name: Pre-fetch skia deps if: ${{ steps.cache-skia.outputs.cache-hit != 'true' }} - run: git config --global core.compression 0 && cd skia && patch -p1 -i ../patch/skia-m131-minimize-download.patch && python tools/git-sync-deps && patch -p1 -R -i ../patch/skia-m131-minimize-download.patch + run: git config --global core.compression 0 && cd skia && patch -p1 -i ../patch/skia-m132-minimize-download.patch && python tools/git-sync-deps && patch -p1 -R -i ../patch/skia-m132-minimize-download.patch - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Build skia 3rd-Party diff --git a/patch/skia-m132-minimize-download.patch b/patch/skia-m132-minimize-download.patch new file mode 100644 index 00000000..ffb54097 --- /dev/null +++ b/patch/skia-m132-minimize-download.patch @@ -0,0 +1,70 @@ +diff --git a/DEPS b/DEPS +index 16d496c..eb6a7cb 100644 +--- a/DEPS ++++ b/DEPS +@@ -31,53 +31,18 @@ vars = { + # ./tools/git-sync-deps + deps = { + "buildtools" : "https://chromium.googlesource.com/chromium/src/buildtools.git@b138e6ce86ae843c42a1a08f37903207bebcca75", +- "third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@7fea539cc99bed8fd315cfbc5026952a133ac3ae", +- "third_party/externals/brotli" : "https://skia.googlesource.com/external/github.com/google/brotli.git@6d03dfbedda1615c4cba1211f8d81735575209c8", +- "third_party/externals/d3d12allocator" : "https://skia.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git@169895d529dfce00390a20e69c2f516066fe7a3b", +- # Dawn requires jinja2 and markupsafe for the code generator, tint for SPIRV compilation, and abseil for string formatting. +- # When the Dawn revision is updated these should be updated from the Dawn DEPS as well. +- "third_party/externals/dawn" : "https://dawn.googlesource.com/dawn.git@2a86250e561c56e9b1b9af5774f1253d9d66be97", +- "third_party/externals/jinja2" : "https://chromium.googlesource.com/chromium/src/third_party/jinja2@e2d024354e11cc6b041b0cff032d73f0c7e43a07", +- "third_party/externals/markupsafe" : "https://chromium.googlesource.com/chromium/src/third_party/markupsafe@0bad08bb207bbfc1d6f3bbc82b9242b0c50e5794", +- "third_party/externals/abseil-cpp" : "https://skia.googlesource.com/external/github.com/abseil/abseil-cpp.git@65a55c2ba891f6d2492477707f4a2e327a0b40dc", + "third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@c8d0c9b1d16bfda56f15165d39e0ffa360a11123", +- "third_party/externals/egl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/EGL-Registry@b055c9b483e70ecd57b3cf7204db21f5a06f9ffe", +- "third_party/externals/emsdk" : "https://skia.googlesource.com/external/github.com/emscripten-core/emsdk.git@a896e3d066448b3530dbcaa48869fafefd738f57", + "third_party/externals/expat" : "https://chromium.googlesource.com/external/github.com/libexpat/libexpat.git@624da0f593bb8d7e146b9f42b06d8e6c80d032a3", + "third_party/externals/freetype" : "https://chromium.googlesource.com/chromium/src/third_party/freetype2.git@83af801b552111e37d9466a887e1783a0fb5f196", + "third_party/externals/harfbuzz" : "https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git@a070f9ebbe88dc71b248af9731dd49ec93f4e6e6", +- "third_party/externals/highway" : "https://chromium.googlesource.com/external/github.com/google/highway.git@424360251cdcfc314cfc528f53c872ecd63af0f0", + "third_party/externals/icu" : "https://chromium.googlesource.com/chromium/deps/icu.git@364118a1d9da24bb5b770ac3d762ac144d6da5a4", +- "third_party/externals/icu4x" : "https://chromium.googlesource.com/external/github.com/unicode-org/icu4x.git@bcf4f7198d4dc5f3127e84a6ca657c88e7d07a13", +- "third_party/externals/imgui" : "https://skia.googlesource.com/external/github.com/ocornut/imgui.git@55d35d8387c15bf0cfd71861df67af8cfbda7456", +- "third_party/externals/libavif" : "https://skia.googlesource.com/external/github.com/AOMediaCodec/libavif.git@55aab4ac0607ab651055d354d64c4615cf3d8000", +- "third_party/externals/libgav1" : "https://chromium.googlesource.com/codecs/libgav1.git@5cf722e659014ebaf2f573a6dd935116d36eadf1", +- "third_party/externals/libgrapheme" : "https://skia.googlesource.com/external/github.com/FRIGN/libgrapheme/@c0cab63c5300fa12284194fbef57aa2ed62a94c0", + "third_party/externals/libjpeg-turbo" : "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@ccfbe1c82a3b6dbe8647ceb36a3f9ee711fba3cf", +- "third_party/externals/libjxl" : "https://chromium.googlesource.com/external/gitlab.com/wg1/jpeg-xl.git@a205468bc5d3a353fb15dae2398a101dff52f2d3", + "third_party/externals/libpng" : "https://skia.googlesource.com/third_party/libpng.git@ed217e3e601d8e462f7fd1e04bed43ac42212429", + "third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@845d5476a866141ba35ac133f856fa62f0b7445f", +- "third_party/externals/libyuv" : "https://chromium.googlesource.com/libyuv/libyuv.git@d248929c059ff7629a85333699717d7a677d8d96", +- "third_party/externals/microhttpd" : "https://android.googlesource.com/platform/external/libmicrohttpd@748945ec6f1c67b7efc934ab0808e1d32f2fb98d", +- "third_party/externals/oboe" : "https://chromium.googlesource.com/external/github.com/google/oboe.git@b02a12d1dd821118763debec6b83d00a8a0ee419", +- "third_party/externals/opengl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/OpenGL-Registry@14b80ebeab022b2c78f84a573f01028c96075553", +- "third_party/externals/partition_alloc" : "https://chromium.googlesource.com/chromium/src/base/allocator/partition_allocator.git@ce13777cb731e0a60c606d1741091fd11a0574d7", +- "third_party/externals/perfetto" : "https://android.googlesource.com/platform/external/perfetto@93885509be1c9240bc55fa515ceb34811e54a394", + "third_party/externals/piex" : "https://android.googlesource.com/platform/external/piex.git@bb217acdca1cc0c16b704669dd6f91a1b509c406", +- "third_party/externals/swiftshader" : "https://swiftshader.googlesource.com/SwiftShader@76855a9baecc97fa144ce70d7ae43a9f878e14c8", + "third_party/externals/vulkanmemoryallocator" : "https://chromium.googlesource.com/external/github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator@a6bfc237255a6bac1513f7c1ebde6d8aed6b5191", +- # vulkan-deps is a meta-repo containing several interdependent Khronos Vulkan repositories. +- # When the vulkan-deps revision is updated, those repos (spirv-*, vulkan-*) should be updated as well. + "third_party/externals/vulkan-deps" : "https://chromium.googlesource.com/vulkan-deps@a2dfb2276ea5f9467eb84c9a19ecf917d92e4135", +- "third_party/externals/spirv-cross" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/SPIRV-Cross@b8fcf307f1f347089e3c46eb4451d27f32ebc8d3", + "third_party/externals/spirv-headers" : "https://skia.googlesource.com/external/github.com/KhronosGroup/SPIRV-Headers.git@996c728cf7dcfb29845cfa15222822318f047810", +- "third_party/externals/spirv-tools" : "https://skia.googlesource.com/external/github.com/KhronosGroup/SPIRV-Tools.git@9117e042b93d4ff08d2406542708170f77aaa2a3", +- "third_party/externals/vello" : "https://skia.googlesource.com/external/github.com/linebender/vello.git@3ee3bea02164c5a816fe6c16ef4e3a810edb7620", +- "third_party/externals/vulkan-headers" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Headers@cbcad3c0587dddc768d76641ea00f5c45ab5a278", +- "third_party/externals/vulkan-tools" : "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Tools@15f2de809304aba619ee327f3273425418ca83de", +- "third_party/externals/vulkan-utility-libraries": "https://chromium.googlesource.com/external/github.com/KhronosGroup/Vulkan-Utility-Libraries@87ab6b39a97d084a2ef27db85e3cbaf5d2622a09", +- "third_party/externals/unicodetools" : "https://chromium.googlesource.com/external/github.com/unicode-org/unicodetools@66a3fa9dbdca3b67053a483d130564eabc5fe095", +- #"third_party/externals/v8" : "https://chromium.googlesource.com/v8/v8.git@5f1ae66d5634e43563b2d25ea652dfb94c31a3b4", + "third_party/externals/wuffs" : "https://skia.googlesource.com/external/github.com/google/wuffs-mirror-release-c.git@e3f919ccfe3ef542cfc983a82146070258fb57f8", + "third_party/externals/zlib" : "https://chromium.googlesource.com/chromium/src/third_party/zlib@646b7f569718921d7d4b5b8e22572ff6c76f2596", + +diff --git a/bin/activate-emsdk b/bin/activate-emsdk +index 687ca9f..7167d8d 100755 +--- a/bin/activate-emsdk ++++ b/bin/activate-emsdk +@@ -17,6 +17,7 @@ EMSDK_PATH = os.path.join(EMSDK_ROOT, 'emsdk.py') + EMSDK_VERSION = '3.1.44' + + def main(): ++ return + if sysconfig.get_platform() in ['linux-aarch64', 'linux-arm64']: + # This platform cannot install emsdk at the provided version. See + # https://github.com/emscripten-core/emsdk/blob/main/emscripten-releases-tags.json#L5 diff --git a/scripts/build_Linux.sh b/scripts/build_Linux.sh index 75be91b3..4fda21eb 100644 --- a/scripts/build_Linux.sh +++ b/scripts/build_Linux.sh @@ -60,7 +60,7 @@ git clone https://gn.googlesource.com/gn && \ # Build skia cd skia && \ - patch -p1 < ../patch/skia-m131-minimize-download.patch && \ + patch -p1 < ../patch/skia-m132-minimize-download.patch && \ patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ cp -f ../gn/out/gn bin/gn && \ diff --git a/scripts/build_Windows.sh b/scripts/build_Windows.sh index c18b00d4..e56cc6de 100644 --- a/scripts/build_Windows.sh +++ b/scripts/build_Windows.sh @@ -4,7 +4,7 @@ export PATH="${PWD}/depot_tools:$PATH" # Build skia cd skia && \ - patch -p1 < ../patch/skia-m131-minimize-download.patch && \ + patch -p1 < ../patch/skia-m132-minimize-download.patch && \ patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python tools/git-sync-deps && \ bin/gn gen out/Release --args=' diff --git a/scripts/build_macOS.sh b/scripts/build_macOS.sh index ee896c78..2286603f 100644 --- a/scripts/build_macOS.sh +++ b/scripts/build_macOS.sh @@ -22,7 +22,7 @@ function apply_patch { } cd skia && \ - patch -p1 < ../patch/skia-m131-minimize-download.patch && \ + patch -p1 < ../patch/skia-m132-minimize-download.patch && \ patch -p1 < ../patch/skia-m132-colrv1-freetype.diff && \ python3 tools/git-sync-deps && \ bin/gn gen out/Release --args=" From 5850c6ddf8a7142f21d47d27b08932d076532de5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:12:57 +0000 Subject: [PATCH 67/71] m132: `SkPathEffect::{DashType, DashInfo, asADash}` have been removed from the public API. Milestone 132 ------------- * `SkPathEffect::DashType`, `SkPathEffect::DashInfo` and `SkPathEffect::asADash` have been removed from the public API. --- src/skia/PathEffect.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/skia/PathEffect.cpp b/src/skia/PathEffect.cpp index 3e6a10ba..a01f2e7d 100644 --- a/src/skia/PathEffect.cpp +++ b/src/skia/PathEffect.cpp @@ -138,6 +138,8 @@ py::class_, SkFlattenable> ~skia.TrimPathEffect )docstring"); +/* SkPathEffect::DashInfo withdrawn from public API in m132 */ +/* py::class_(patheffect, "DashInfo") .def(py::init<>()) .def_property_readonly("fIntervals", @@ -160,6 +162,7 @@ py::class_(patheffect, "DashInfo") Offset into the dashed interval pattern. )docstring") ; +*/ /* py::class_ pointdata(patheffect, "PointData", @@ -195,6 +198,8 @@ pointdata ; */ +/* SkPathEffect::DashType withdrawn from public API in m132 */ +/* py::enum_(patheffect, "DashType", R"docstring( If the :py:class:`PathEffect` can be represented as a dash pattern, asADash @@ -215,6 +220,7 @@ py::enum_(patheffect, "DashType", .value("kDash_DashType", SkPathEffect::DashType::kDash_DashType, "fills in all of the info parameter") .export_values(); +*/ patheffect .def("filterPath", py::overload_cast(&SkPathEffect::filterPath, py::const_), @@ -251,7 +257,10 @@ patheffect py::arg("results"), py::arg("src"), py::arg("stroke_rec"), py::arg("matrix"), py::arg("cullR")) */ +/* SkPathEffect::asADash withdrawn from public API in m132 */ +/* .def("asADash", &SkPathEffect::asADash, py::arg("info")) +*/ .def_static("MakeSum", [] (const SkPathEffect& first, const SkPathEffect& second) { auto first_ = first.serialize(); From e2f53400b0c64e8ec42d105d5ab65af089cd2bc5 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:19:26 +0000 Subject: [PATCH 68/71] Update tests involving withdrawn PathEffect::DashInfo and PathEffect::asADash as xfail --- tests/test_patheffect.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_patheffect.py b/tests/test_patheffect.py index 69330489..b98da4ed 100644 --- a/tests/test_patheffect.py +++ b/tests/test_patheffect.py @@ -104,14 +104,17 @@ def patheffect_dashinfo(): return skia.PathEffect.DashInfo() +@pytest.mark.xfail(reason='Withdrawn from public API in m132') def test_PathEffect_DashInfo_fIntervals(patheffect_dashinfo): assert isinstance(patheffect_dashinfo.fIntervals, list) +@pytest.mark.xfail(reason='Withdrawn from public API in m132') def test_PathEffect_DashInfo_fCount(patheffect_dashinfo): assert isinstance(patheffect_dashinfo.fCount, int) +@pytest.mark.xfail(reason='Withdrawn from public API in m132') def test_PathEffect_DashInfo_fPhase(patheffect_dashinfo): assert isinstance(patheffect_dashinfo.fPhase, float) @@ -191,6 +194,7 @@ def test_PathEffect_asPoints(patheffect): patheffect.asPoints(results, path, rec, matrix, None), bool) +@pytest.mark.xfail(reason='Withdrawn from public API in m132') def test_PathEffect_asADash(patheffect): dashinfo = skia.PathEffect.DashInfo() assert isinstance(patheffect.asADash(dashinfo), skia.PathEffect.DashType) From 7fe38750823a654a8263202ec697c7c9b74c003c Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:49:21 +0000 Subject: [PATCH 69/71] Current state of SkRuntimeEffect-binding:relnotes/README.m132.md --- relnotes/README.m132.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 relnotes/README.m132.md diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md new file mode 100644 index 00000000..9fc10120 --- /dev/null +++ b/relnotes/README.m132.md @@ -0,0 +1,24 @@ +Since m131: + +- We now bundle a `icudtl.dat` for windows. This fixes windows-specific problems + with SkUnicode, libSkShaper, and SkParagraph. Thanks @meetwq for the change. + Relevant CI tests re-enabled and added. + +- Upstream's `SkNamedTransferFn::*` now available as `cms.NamedTransferFn.*`, + and `SkNamedGamut::*` as `cms.NamedGamut.*`. These are used in RuntimeEffect-related + code. + +- More overloads of `SkImage::makeShader` added, and `SkImage::makeRawShader` added + as `Image.makeRawShader`. + +- We binds `SkRuntimeEffect` as `skia.RuntimeEffect`. Added some helper classes: + `SkV3` as `skia.V3`, `SkV4` as `skia.V4`, + `SkRuntimeEffect::Result` as `RuntimeEffectResult`, + `SkRuntimeEffect::ChildPtr` as `RuntimeEffectChildPtr`, + `SkRuntimeEffectBuilder` as `RuntimeEffectBuilder`, + `std::vector` as `VectorRuntimeEffectChildPtr`, + `SkSpan` as `SpanRuntimeEffectChildPtr`, + `SkRuntimeEffectBuilder::BuilderUniform` as `RuntimeEffectBuilderUniform`, + `SkRuntimeEffectBuilder::BuilderChild` as `RuntimeEffectBuilderChild`. + Details are subjected to change. We ported all 9 of current upstream SkSL c++ examples, + hosted [elsewhere](https://github.com/HinTak/skia-python-examples/). From ef51e6dc7dd607ff2ff0b5c8ba3d8b501524935b Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:54:28 +0000 Subject: [PATCH 70/71] Adding m132 upstream changes to README.m132.md --- relnotes/README.m132.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md index 9fc10120..3e6f769f 100644 --- a/relnotes/README.m132.md +++ b/relnotes/README.m132.md @@ -1,4 +1,6 @@ Since m131: +- `PathEffect.{DashType, DashInfo, asADash}` withdrawn. + Upstream removed them from public API in m132. - We now bundle a `icudtl.dat` for windows. This fixes windows-specific problems with SkUnicode, libSkShaper, and SkParagraph. Thanks @meetwq for the change. From a34686e5063d33dce8763a32003e7ca3a79bbdc6 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 13 Nov 2024 21:54:28 +0000 Subject: [PATCH 71/71] Adding m132 upstream changes to README.m132.md --- relnotes/README.m132.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/relnotes/README.m132.md b/relnotes/README.m132.md index 9fc10120..3e6f769f 100644 --- a/relnotes/README.m132.md +++ b/relnotes/README.m132.md @@ -1,4 +1,6 @@ Since m131: +- `PathEffect.{DashType, DashInfo, asADash}` withdrawn. + Upstream removed them from public API in m132. - We now bundle a `icudtl.dat` for windows. This fixes windows-specific problems with SkUnicode, libSkShaper, and SkParagraph. Thanks @meetwq for the change.