1# Copyright 2020 Google Inc. 2# 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5import("../../gn/skia.gni") 6import("../../gn/toolchain/wasm.gni") 7import("canvaskit.gni") 8 9# These targets depend on components that are only declared if 10# `skia_enable_tools` is true. 11if (skia_enable_tools) { 12 component("viewer_wasm") { 13 testonly = true 14 include_dirs = [ "../.." ] 15 sources = [ 16 "../../modules/svg/src/SkSVGAttribute.cpp", 17 "../../modules/svg/src/SkSVGAttributeParser.cpp", 18 "../../modules/svg/src/SkSVGCircle.cpp", 19 "../../modules/svg/src/SkSVGClipPath.cpp", 20 "../../modules/svg/src/SkSVGContainer.cpp", 21 "../../modules/svg/src/SkSVGDOM.cpp", 22 "../../modules/svg/src/SkSVGEllipse.cpp", 23 "../../modules/svg/src/SkSVGFe.cpp", 24 "../../modules/svg/src/SkSVGFeColorMatrix.cpp", 25 "../../modules/svg/src/SkSVGFeComposite.cpp", 26 "../../modules/svg/src/SkSVGFeTurbulence.cpp", 27 "../../modules/svg/src/SkSVGFilter.cpp", 28 "../../modules/svg/src/SkSVGFilterContext.cpp", 29 "../../modules/svg/src/SkSVGGradient.cpp", 30 "../../modules/svg/src/SkSVGLine.cpp", 31 "../../modules/svg/src/SkSVGLinearGradient.cpp", 32 "../../modules/svg/src/SkSVGNode.cpp", 33 "../../modules/svg/src/SkSVGPath.cpp", 34 "../../modules/svg/src/SkSVGPattern.cpp", 35 "../../modules/svg/src/SkSVGPoly.cpp", 36 "../../modules/svg/src/SkSVGRadialGradient.cpp", 37 "../../modules/svg/src/SkSVGRect.cpp", 38 "../../modules/svg/src/SkSVGRenderContext.cpp", 39 "../../modules/svg/src/SkSVGSVG.cpp", 40 "../../modules/svg/src/SkSVGShape.cpp", 41 "../../modules/svg/src/SkSVGStop.cpp", 42 "../../modules/svg/src/SkSVGText.cpp", 43 "../../modules/svg/src/SkSVGTransformableNode.cpp", 44 "../../modules/svg/src/SkSVGUse.cpp", 45 "../../modules/svg/src/SkSVGValue.cpp", 46 "../../tools/viewer/SKPSlide.cpp", 47 "../../tools/viewer/SampleSlide.cpp", 48 "../../tools/viewer/SvgSlide.cpp", 49 ] 50 } 51 52 component("gm_wasm") { 53 testonly = true 54 include_dirs = [ "../.." ] 55 deps = [ 56 "../..:hash_and_encode", 57 "../..:tool_utils", 58 "../../modules/svg:svg", 59 ] 60 defines = [ "SK_GANESH" ] 61 } 62} 63 64component("debugger") { 65 include_dirs = [ "../.." ] 66 sources = [ 67 "../../tools/SkSharingProc.cpp", 68 "../../tools/UrlDataManager.cpp", 69 "../../tools/debugger/DebugCanvas.cpp", 70 "../../tools/debugger/DebugLayerManager.cpp", 71 "../../tools/debugger/DrawCommand.cpp", 72 "../../tools/debugger/JsonWriteBuffer.cpp", 73 ] 74 defines = [ "SK_GANESH" ] 75} 76 77action("create_notomono_cpp") { 78 script = "../../tools/embed_resources.py" 79 80 inputs = [ "fonts/NotoMono-Regular.ttf" ] 81 82 output_path = 83 "$root_out_dir/modules/canvaskit/fonts/NotoMono-Regular.ttf.ninja.cpp" 84 85 outputs = [ output_path ] 86 87 args = [ 88 "--name=SK_EMBEDDED_FONTS", 89 "--input", 90 rebase_path("fonts/NotoMono-Regular.ttf"), 91 "--output", 92 rebase_path(output_path), 93 "--align=4", 94 ] 95} 96 97skia_wasm_lib("canvaskit") { 98 deps = [ "../..:skia" ] 99 if (skia_canvaskit_enable_paragraph) { 100 deps += [ 101 "../../modules/skparagraph:skparagraph", 102 "../../modules/skunicode:skunicode", 103 ] 104 } 105 if (skia_enable_skottie) { 106 deps += [ 107 "../../modules/skottie:skottie", 108 "../../modules/skresources:skresources", 109 "../../modules/sksg:sksg", 110 ] 111 } 112 if (skia_canvaskit_include_viewer) { 113 deps += [ ":viewer_wasm" ] 114 } 115 if (skia_canvaskit_enable_embedded_font) { 116 deps += [ ":create_notomono_cpp" ] 117 } 118 119 sources = [ 120 "WasmCommon.h", 121 "canvaskit_bindings.cpp", 122 ] 123 if (skia_canvaskit_enable_paragraph) { 124 sources += [ 125 "paragraph_bindings.cpp", 126 "paragraph_bindings_gen.cpp", 127 ] 128 } 129 if (skia_enable_skottie) { 130 sources += [ 131 "../../modules/skottie/utils/SkottieUtils.cpp", 132 "../../modules/skottie/utils/TextEditor.cpp", 133 "../../modules/skresources/src/SkResources.cpp", 134 "skottie_bindings.cpp", 135 ] 136 } 137 if (skia_canvaskit_include_viewer) { 138 sources += [ "viewer_bindings.cpp" ] 139 # TODO(kjlubick): remove this 140 } 141 if (skia_canvaskit_enable_debugger) { 142 sources += [ "debugger_bindings.cpp" ] 143 deps += [ ":debugger" ] 144 } 145 if (skia_canvaskit_enable_embedded_font) { 146 sources += [ 147 "$root_out_dir/modules/canvaskit/fonts/NotoMono-Regular.ttf.ninja.cpp", 148 ] 149 } 150 151 ldflags = [] 152 if (is_debug) { 153 ldflags += [ 154 "-O0", 155 "-sDEMANGLE_SUPPORT=1", 156 "-sASSERTIONS=1", 157 "-sGL_ASSERTIONS=1", 158 "-g3", 159 "--pre-js", 160 rebase_path("debug.js"), 161 ] 162 } else { 163 externs_path = rebase_path("externs.js") 164 ldflags += [ 165 "-Oz", 166 "--closure=1", 167 "--pre-js", 168 rebase_path("release.js"), 169 "--closure-args=--externs=$externs_path", 170 ] 171 } 172 if (skia_canvaskit_profile_build) { 173 ldflags += [ 174 "--profiling-funcs", 175 "--closure=0", 176 ] 177 } 178 ldflags += [ "-fno-rtti" ] 179 180 if (skia_canvaskit_enable_webgpu) { 181 ldflags += [ 182 "--pre-js", 183 rebase_path("cpu.js"), 184 "--pre-js", 185 rebase_path("webgpu.js"), 186 "-sUSE_WEBGL2=0", 187 "-sUSE_WEBGPU=1", 188 "-sASYNCIFY", 189 190 # Modules from html5_webgpu for JS<->WASM interop 191 "-sEXPORTED_RUNTIME_METHODS=WebGPU,JsValStore", 192 193 # TODO(skia:13429): The closure compiler doesn't play well with optimized builds and ASYNCIFY. 194 "--closure=0", 195 ] 196 } else if (skia_canvaskit_enable_webgl) { 197 ldflags += [ 198 "-lGL", 199 "--pre-js", 200 rebase_path("cpu.js"), 201 "--pre-js", 202 rebase_path("webgl.js"), 203 "-sUSE_WEBGL2=1", 204 "-sMAX_WEBGL_VERSION=2", 205 ] 206 } else { 207 ldflags += [ 208 "--pre-js", 209 rebase_path("cpu.js"), 210 "-sUSE_WEBGL2=0", 211 ] 212 } 213 214 ldflags += [ 215 "-std=c++17", 216 "--bind", 217 "--no-entry", 218 "--pre-js", 219 rebase_path("preamble.js"), 220 "--pre-js", 221 rebase_path("color.js"), 222 "--pre-js", 223 rebase_path("memory.js"), 224 "--pre-js", 225 rebase_path("util.js"), 226 "--pre-js", 227 rebase_path("interface.js"), 228 ] 229 230 if (skia_canvaskit_enable_matrix_helper) { 231 ldflags += [ 232 "--pre-js", 233 rebase_path("matrix.js"), 234 ] 235 } 236 237 ldflags += [ 238 "--pre-js", 239 rebase_path("paragraph.js"), 240 ] 241 242 if (skia_enable_skottie) { 243 ldflags += [ 244 "--pre-js", 245 rebase_path("skottie.js"), 246 ] 247 } 248 249 if (skia_canvaskit_enable_pathops) { 250 ldflags += [ 251 "--pre-js", 252 rebase_path("pathops.js"), 253 ] 254 } 255 256 if (skia_canvaskit_enable_font) { 257 ldflags += [ 258 "--pre-js", 259 rebase_path("font.js"), 260 ] 261 } 262 263 if (skia_canvaskit_enable_skp_serialization) { 264 ldflags += [ 265 "--pre-js", 266 rebase_path("skp.js"), 267 ] 268 } 269 270 if (skia_canvaskit_enable_rt_shader) { 271 ldflags += [ 272 "--pre-js", 273 rebase_path("rt_shader.js"), 274 ] 275 } 276 277 if (skia_canvaskit_enable_debugger) { 278 ldflags += [ 279 "--pre-js", 280 rebase_path("debugger.js"), 281 ] 282 } 283 284 if (skia_canvaskit_enable_canvas_bindings) { 285 ldflags += [ 286 "--pre-js", 287 rebase_path("htmlcanvas/preamble.js"), 288 "--pre-js", 289 rebase_path("htmlcanvas/util.js"), 290 "--pre-js", 291 rebase_path("htmlcanvas/color.js"), 292 "--pre-js", 293 rebase_path("htmlcanvas/font.js"), 294 "--pre-js", 295 rebase_path("htmlcanvas/canvas2dcontext.js"), 296 "--pre-js", 297 rebase_path("htmlcanvas/htmlcanvas.js"), 298 "--pre-js", 299 rebase_path("htmlcanvas/htmlimage.js"), 300 "--pre-js", 301 rebase_path("htmlcanvas/imagedata.js"), 302 "--pre-js", 303 rebase_path("htmlcanvas/lineargradient.js"), 304 "--pre-js", 305 rebase_path("htmlcanvas/path2d.js"), 306 "--pre-js", 307 rebase_path("htmlcanvas/pattern.js"), 308 "--pre-js", 309 rebase_path("htmlcanvas/radialgradient.js"), 310 "--pre-js", 311 rebase_path("htmlcanvas/postamble.js"), 312 ] 313 } 314 315 ldflags += [ 316 "--pre-js", 317 rebase_path("postamble.js"), 318 "-sALLOW_MEMORY_GROWTH", 319 "-sDISABLE_EXCEPTION_CATCHING", 320 "-sNODEJS_CATCH_EXIT=0", 321 "-sDYNAMIC_EXECUTION=0", 322 "-sEXPORT_NAME=CanvasKitInit", 323 "-sEXPORTED_FUNCTIONS=[_malloc,_free]", 324 "-sFORCE_FILESYSTEM=0", 325 "-sFILESYSTEM=0", 326 "-sMODULARIZE", 327 "-sNO_EXIT_RUNTIME=1", 328 "-sINITIAL_MEMORY=128MB", 329 "-sWASM", 330 "-sSTRICT=1", 331 ] 332 333 defines = [ 334 "SK_FORCE_8_BYTE_ALIGNMENT", 335 "EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0", 336 "SK_DISABLE_LEGACY_PARAGRAPH_UNICODE=1", 337 ] 338 if (is_debug) { 339 defines += [ "SK_DEBUG" ] 340 } else { 341 defines += [ "SK_RELEASE" ] 342 } 343 if (!is_debug && !skia_canvaskit_force_tracing) { 344 defines += [ "SK_DISABLE_TRACING" ] 345 } 346 if (skia_canvaskit_enable_embedded_font) { 347 defines += [ "CK_EMBED_FONT" ] 348 } 349 if (skia_use_icu && skia_use_harfbuzz) { 350 deps += [ 351 "../../modules/skshaper", 352 "../../modules/skunicode", 353 ] 354 } 355 if (skia_canvaskit_enable_paragraph) { 356 defines += [ "CK_INCLUDE_PARAGRAPH" ] 357 } 358 if (skia_canvaskit_enable_skp_serialization) { 359 defines += [ "CK_SERIALIZE_SKP" ] 360 } 361 if (skia_enable_ganesh) { 362 defines += [ 363 "SK_GANESH", 364 "SK_DISABLE_LEGACY_SHADERCONTEXT", 365 ] 366 if (skia_canvaskit_enable_webgl) { 367 defines += [ 368 "SK_GL", 369 "CK_ENABLE_WEBGL", 370 ] 371 } 372 } 373 374 if (skia_canvaskit_enable_pathops) { 375 defines += [ "CK_INCLUDE_PATHOPS" ] 376 } 377 if (skia_canvaskit_enable_rt_shader) { 378 defines += [ "CK_INCLUDE_RUNTIME_EFFECT" ] 379 } 380 if (!skia_canvaskit_enable_alias_font) { 381 defines += [ "CK_NO_ALIAS_FONT" ] 382 } 383 if (skia_canvaskit_legacy_draw_vertices_blend_mode) { 384 # https://github.com/flutter/flutter/issues/98531 385 defines += [ "SK_LEGACY_IGNORE_DRAW_VERTICES_BLEND_WITH_NO_SHADER" ] 386 } 387 if (!skia_canvaskit_enable_font) { 388 defines += [ "CK_NO_FONTS" ] 389 } 390} 391