• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  if (skia_canvaskit_enable_rt_shader) {
151    sources += [ "../../tools/sksltrace/SkSLTraceUtils.cpp" ]
152  }
153
154  ldflags = []
155  if (is_debug) {
156    ldflags += [
157      "-O0",
158      "-sDEMANGLE_SUPPORT=1",
159      "-sASSERTIONS=1",
160      "-sGL_ASSERTIONS=1",
161      "-g3",
162      "--pre-js",
163      rebase_path("debug.js"),
164    ]
165  } else {
166    externs_path = rebase_path("externs.js")
167    ldflags += [
168      "-Oz",
169      "--closure=1",
170      "--pre-js",
171      rebase_path("release.js"),
172      "--closure-args=--externs=$externs_path",
173    ]
174  }
175  if (skia_canvaskit_profile_build) {
176    ldflags += [
177      "--profiling-funcs",
178      "--closure=0",
179    ]
180  }
181  ldflags += [ "-fno-rtti" ]
182
183  if (skia_canvaskit_enable_webgpu) {
184    ldflags += [
185      "--pre-js",
186      rebase_path("cpu.js"),
187      "--pre-js",
188      rebase_path("webgpu.js"),
189      "-sUSE_WEBGL2=0",
190      "-sUSE_WEBGPU=1",
191      "-sASYNCIFY",
192
193      # Modules from html5_webgpu for JS<->WASM interop
194      "-sEXPORTED_RUNTIME_METHODS=WebGPU,JsValStore",
195
196      # TODO(skia:13429): The closure compiler doesn't play well with optimized builds and ASYNCIFY.
197      "--closure=0",
198    ]
199  } else if (skia_canvaskit_enable_webgl) {
200    ldflags += [
201      "-lGL",
202      "--pre-js",
203      rebase_path("cpu.js"),
204      "--pre-js",
205      rebase_path("webgl.js"),
206      "-sUSE_WEBGL2=1",
207      "-sMAX_WEBGL_VERSION=2",
208    ]
209  } else {
210    ldflags += [
211      "--pre-js",
212      rebase_path("cpu.js"),
213      "-sUSE_WEBGL2=0",
214    ]
215  }
216
217  ldflags += [
218    "-std=c++17",
219    "--bind",
220    "--no-entry",
221    "--pre-js",
222    rebase_path("preamble.js"),
223    "--pre-js",
224    rebase_path("color.js"),
225    "--pre-js",
226    rebase_path("memory.js"),
227    "--pre-js",
228    rebase_path("util.js"),
229    "--pre-js",
230    rebase_path("interface.js"),
231  ]
232
233  if (skia_canvaskit_enable_matrix_helper) {
234    ldflags += [
235      "--pre-js",
236      rebase_path("matrix.js"),
237    ]
238  }
239
240  ldflags += [
241    "--pre-js",
242    rebase_path("paragraph.js"),
243  ]
244
245  if (skia_enable_skottie) {
246    ldflags += [
247      "--pre-js",
248      rebase_path("skottie.js"),
249    ]
250  }
251
252  if (skia_canvaskit_enable_pathops) {
253    ldflags += [
254      "--pre-js",
255      rebase_path("pathops.js"),
256    ]
257  }
258
259  if (skia_canvaskit_enable_font) {
260    ldflags += [
261      "--pre-js",
262      rebase_path("font.js"),
263    ]
264  }
265
266  if (skia_canvaskit_enable_skp_serialization) {
267    ldflags += [
268      "--pre-js",
269      rebase_path("skp.js"),
270    ]
271  }
272
273  if (skia_canvaskit_enable_rt_shader) {
274    ldflags += [
275      "--pre-js",
276      rebase_path("rt_shader.js"),
277    ]
278  }
279
280  if (skia_canvaskit_enable_debugger) {
281    ldflags += [
282      "--pre-js",
283      rebase_path("debugger.js"),
284    ]
285  }
286
287  if (skia_canvaskit_enable_canvas_bindings) {
288    ldflags += [
289      "--pre-js",
290      rebase_path("htmlcanvas/preamble.js"),
291      "--pre-js",
292      rebase_path("htmlcanvas/util.js"),
293      "--pre-js",
294      rebase_path("htmlcanvas/color.js"),
295      "--pre-js",
296      rebase_path("htmlcanvas/font.js"),
297      "--pre-js",
298      rebase_path("htmlcanvas/canvas2dcontext.js"),
299      "--pre-js",
300      rebase_path("htmlcanvas/htmlcanvas.js"),
301      "--pre-js",
302      rebase_path("htmlcanvas/htmlimage.js"),
303      "--pre-js",
304      rebase_path("htmlcanvas/imagedata.js"),
305      "--pre-js",
306      rebase_path("htmlcanvas/lineargradient.js"),
307      "--pre-js",
308      rebase_path("htmlcanvas/path2d.js"),
309      "--pre-js",
310      rebase_path("htmlcanvas/pattern.js"),
311      "--pre-js",
312      rebase_path("htmlcanvas/radialgradient.js"),
313      "--pre-js",
314      rebase_path("htmlcanvas/postamble.js"),
315    ]
316  }
317
318  ldflags += [
319    "--pre-js",
320    rebase_path("postamble.js"),
321    "-sALLOW_MEMORY_GROWTH",
322    "-sDISABLE_EXCEPTION_CATCHING",
323    "-sNODEJS_CATCH_EXIT=0",
324    "-sDYNAMIC_EXECUTION=0",
325    "-sEXPORT_NAME=CanvasKitInit",
326    "-sEXPORTED_FUNCTIONS=[_malloc,_free]",
327    "-sFORCE_FILESYSTEM=0",
328    "-sFILESYSTEM=0",
329    "-sMODULARIZE",
330    "-sNO_EXIT_RUNTIME=1",
331    "-sINITIAL_MEMORY=128MB",
332    "-sWASM",
333    "-sSTRICT=1",
334  ]
335
336  defines = [
337    "SK_FORCE_8_BYTE_ALIGNMENT",
338    "EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0",
339    "SK_DISABLE_LEGACY_PARAGRAPH_UNICODE=1",
340  ]
341  if (is_debug) {
342    defines += [ "SK_DEBUG" ]
343  } else {
344    defines += [ "SK_RELEASE" ]
345  }
346  if (!is_debug && !skia_canvaskit_force_tracing) {
347    defines += [ "SK_DISABLE_TRACING" ]
348  }
349  if (skia_canvaskit_enable_embedded_font) {
350    defines += [ "CK_EMBED_FONT" ]
351  }
352  if (skia_use_icu && skia_use_harfbuzz) {
353    deps += [
354      "../../modules/skshaper",
355      "../../modules/skunicode",
356    ]
357  }
358  if (skia_canvaskit_enable_paragraph) {
359    defines += [ "CK_INCLUDE_PARAGRAPH" ]
360  }
361  if (skia_canvaskit_enable_skp_serialization) {
362    defines += [ "CK_SERIALIZE_SKP" ]
363  }
364  if (skia_enable_ganesh) {
365    defines += [
366      "SK_GANESH",
367      "SK_DISABLE_LEGACY_SHADERCONTEXT",
368    ]
369    if (skia_canvaskit_enable_webgl) {
370      defines += [
371        "SK_GL",
372        "CK_ENABLE_WEBGL",
373      ]
374    }
375  }
376
377  if (skia_canvaskit_enable_pathops) {
378    defines += [ "CK_INCLUDE_PATHOPS" ]
379  }
380  if (skia_canvaskit_enable_rt_shader) {
381    defines += [
382      "CK_INCLUDE_RUNTIME_EFFECT",
383      "CK_DEBUG_TRACE_JSON",
384    ]
385  }
386  if (!skia_canvaskit_enable_alias_font) {
387    defines += [ "CK_NO_ALIAS_FONT" ]
388  }
389  if (skia_canvaskit_legacy_draw_vertices_blend_mode) {
390    # https://github.com/flutter/flutter/issues/98531
391    defines += [ "SK_LEGACY_IGNORE_DRAW_VERTICES_BLEND_WITH_NO_SHADER" ]
392  }
393  if (!skia_canvaskit_enable_font) {
394    defines += [ "CK_NO_FONTS" ]
395  }
396}
397