[M120 Migration][MM] Fix EME AD insert issue
[platform/framework/web/chromium-efl.git] / skia / BUILD.gn
1 # Copyright 2013 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import("//build/buildflag_header.gni")
6 import("//build/config/compiler/compiler.gni")
7 import("//build/config/features.gni")
8 import("//build/config/freetype/freetype.gni")
9 import("//build/config/rust.gni")
10 import("//build/config/sanitizers/sanitizers.gni")
11 import("//build/rust/rust_static_library.gni")
12 import("//gpu/vulkan/features.gni")
13 import("//testing/test.gni")
14 import("//third_party/skia/gn/shared_sources.gni")
15 import("//third_party/skia/modules/skcms/skcms.gni")
16 import("features.gni")
17
18 if (current_cpu == "arm") {
19   import("//build/config/arm.gni")
20 }
21 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
22   import("//build/config/mips.gni")
23 }
24
25 buildflag_header("buildflags") {
26   header = "buildflags.h"
27   flags = [
28     "SKIA_SUPPORT_SKOTTIE=$skia_support_skottie",
29     "SKIA_USE_DAWN=$skia_use_dawn",
30     "SKIA_USE_METAL=$skia_use_metal",
31   ]
32 }
33
34 if (use_typeface_fontations) {
35   source_set("path_bridge") {
36     sources = [ "//third_party/skia/src/ports/fontations/src/skpath_bridge.h" ]
37   }
38
39   rust_static_library("bridge_rust_side") {
40     allow_unsafe = true
41     crate_root = "//third_party/skia/src/ports/fontations/src/ffi.rs"
42     sources = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ]
43     cxx_bindings = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ]
44     deps = [
45       ":path_bridge",
46       "//third_party/rust/font_types/v0_4:lib",
47       "//third_party/rust/read_fonts/v0_11:lib",
48       "//third_party/rust/skrifa/v0_10:lib",
49     ]
50     configs -= [ "//build/config/compiler:chromium_code" ]
51     configs += [
52       ":skia_config",
53       "//build/config/compiler:no_chromium_code",
54     ]
55   }
56 }
57
58 # External-facing config for dependent code.
59 config("skia_config") {
60   defines = [
61     "SK_ENABLE_SKSL",
62     "SK_UNTIL_CRBUG_1187654_IS_FIXED",
63     "SK_USER_CONFIG_HEADER=\"../../skia/config/SkUserConfig.h\"",
64     "SK_WIN_FONTMGR_NO_SIMULATIONS",
65     "SK_DISABLE_LEGACY_SKSURFACE_METHODS",
66     "SK_DISABLE_LEGACY_GRAPHITE_IMAGE_FACTORIES",
67     "SK_DISABLE_LEGACY_GRAPHITE_IMAGE_METHODS",
68     "SK_DISABLE_LEGACY_SKSURFACE_FACTORIES",
69     "SK_DISABLE_LEGACY_SKSURFACE_FLUSH",
70     "SK_DISABLE_LEGACY_SKSURFACE_AS_IMAGE",
71     "SK_DISABLE_LEGACY_SKSURFACE_DISPLAYLIST",
72     "SK_DISABLE_LEGACY_IMAGE_SUBSET_METHODS",
73     "SK_DISABLE_LEGACY_IMAGE_COLORSPACE_METHODS",
74     "SK_DISABLE_LEGACY_IMAGE_RELEASE_PROCS",
75     "SK_DISABLE_LEGACY_GL_BACKEND_SURFACE",
76     "SK_DISABLE_LEGACY_INIT_DECODERS",
77     "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_FLUSH",
78     "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_BOOLS",
79     "SK_DISABLE_LEGACY_GL_GRDIRECTCONTEXT_FACTORIES",
80     "SK_DISABLE_LEGACY_PNG_WRITEBUFFER",
81     "SK_SLUG_DISABLE_LEGACY_DESERIALIZE",
82     "SK_DISABLE_LEGACY_VK_GRDIRECTCONTEXT_FACTORIES",
83   ]
84
85   include_dirs = [
86     "//third_party/skia",
87     "$root_gen_dir/third_party/skia",
88   ]
89
90   if (use_blink) {
91     # TODO(kjlubick) make these not necessary
92     defines += [
93       "SK_CODEC_DECODES_JPEG",
94       "SK_ENCODE_JPEG",
95       "SK_ENCODE_PNG",
96       "SK_ENCODE_WEBP",
97     ]
98     include_dirs += [ "//third_party/wuffs/src/release/c" ]
99   } else {
100     # Decoder sources are only added when use_blink == true, but SkCodec.cpp is
101     # always present.  SK_DISABLE_LEGACY_INIT_DECODERS ensures that SkCodec.cpp
102     # is not attempting to reference inexistent codec code.
103     defines += [ "SK_DISABLE_LEGACY_INIT_DECODERS" ]
104   }
105
106   if (is_component_build) {
107     defines += [ "SKIA_DLL" ]
108     if (is_win) {
109       defines += [ "SKCMS_API=__declspec(dllexport)" ]
110     } else {
111       defines += [ "SKCMS_API=__attribute__((visibility(\"default\")))" ]
112     }
113   }
114
115   if (is_android) {
116     defines += [
117       "SK_BUILD_FOR_ANDROID",
118       "USE_CHROMIUM_SKIA",
119     ]
120   }
121
122   if (is_mac) {
123     defines += [ "SK_BUILD_FOR_MAC" ]
124   }
125   if (is_ios) {
126     defines += [ "SK_BUILD_FOR_IOS" ]
127   }
128
129   if (is_win) {
130     defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
131   }
132
133   if (skia_support_gpu) {
134     workaround_header = "gpu/config/gpu_driver_bug_workaround_autogen.h"
135     configs = []
136     defines += [
137       "SK_GANESH",
138       "SK_GPU_WORKAROUNDS_HEADER=\"$workaround_header\"",
139     ]
140     if (skia_use_gl) {
141       defines += [ "SK_GL" ]
142     }
143     if (enable_vulkan) {
144       defines += [ "SK_VULKAN=1" ]
145       include_dirs += [ "//third_party/vulkan/include" ]
146       configs += [
147         "//third_party/vulkan-deps/vulkan-headers/src:vulkan_headers_config",
148       ]
149     }
150
151     # Graphite
152     defines += [ "SK_GRAPHITE" ]
153     if (skia_use_dawn) {
154       defines += [ "SK_DAWN" ]
155       configs += [ "//third_party/dawn/include/dawn:public" ]
156     }
157     if (skia_use_metal) {
158       defines += [ "SK_METAL" ]
159     }
160   }
161 }
162
163 # Internal-facing config for Skia library code.
164 config("skia_library_config") {
165   # Turn on SK_API to export Skia's public API
166   defines = [
167     "IS_SKIA_IMPL=1",
168     "SKIA_IMPLEMENTATION=1",
169   ]
170
171   if (use_blink && !use_system_freetype) {
172     defines += [ "SK_FREETYPE_MINIMUM_RUNTIME_VERSION=(((FREETYPE_MAJOR) * 0x01000000) | ((FREETYPE_MINOR) * 0x00010000) | ((FREETYPE_PATCH) * 0x00000100))" ]
173   }
174   if (use_blink) {
175     defines += [ "SK_TYPEFACE_FACTORY_FREETYPE" ]
176   }
177   if (is_win) {
178     defines += [ "SK_TYPEFACE_FACTORY_DIRECTWRITE" ]
179   }
180   if (is_apple) {
181     defines += [ "SK_TYPEFACE_FACTORY_CORETEXT" ]
182   }
183
184   if (current_cpu == "arm") {
185     if (arm_use_neon) {
186       defines += [ "SK_ARM_HAS_NEON" ]
187     } else if (arm_optionally_use_neon) {
188       defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
189     }
190   }
191
192   # Settings for text blitting, chosen to approximate the system browser.
193   if (is_linux || is_chromeos) {
194     defines += [
195       "SK_GAMMA_EXPONENT=1.2",
196       "SK_GAMMA_CONTRAST=0.2",
197     ]
198   } else if (is_android) {
199     defines += [
200       "SK_GAMMA_APPLY_TO_A8",
201       "SK_GAMMA_EXPONENT=1.4",
202       "SK_GAMMA_CONTRAST=0.0",
203     ]
204   } else if (is_win) {
205     defines += [
206       "SK_GAMMA_SRGB",
207       "SK_GAMMA_CONTRAST=0.5",
208     ]
209   } else if (is_mac) {
210     defines += [
211       "SK_GAMMA_SRGB",
212       "SK_GAMMA_CONTRAST=0.0",
213     ]
214   }
215
216   if (is_android) {
217     defines += [
218       # Android devices are typically more memory constrained, so default to a
219       # smaller glyph cache (it may be overriden at runtime when the renderer
220       # starts up, depending on the actual device memory).
221       "SK_DEFAULT_FONT_CACHE_LIMIT=1048576",  # 1024 * 1024
222     ]
223   } else {
224     defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
225   }
226
227   if (is_win) {
228     defines += [
229       # On windows, GDI handles are a scarse system-wide resource so we have to
230       # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
231       # fairly small size. http://crbug.com/314387
232       "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
233     ]
234   }
235 }
236
237 # Split out into separate target so that path_bridge can depend on the public
238 # headers only and we can avoid a cyclic dependency when building the C++ native
239 # code for the Fontations rust backend.
240 source_set("skia_core_public_headers") {
241   public = skia_core_public
242 }
243
244 source_set("skcms") {
245   cflags = []
246   if (!is_win || is_clang) {
247     cflags += [
248       "-w",
249       "-std=c11",
250     ]
251   }
252
253   # LLVM automatically sets the equivalent of GCC's -mfp16-format=ieee on ARM
254   # builds by default, while GCC itself does not. We need it to enable support
255   # for half-precision floating point data types used by SKCMS on ARM.
256   if ((is_linux || is_chromeos) && !is_clang && current_cpu == "arm") {
257     cflags += [ "-mfp16-format=ieee" ]
258   }
259
260   public = [ "//third_party/skia/modules/skcms/skcms.h" ]
261   include_dirs = [ "//third_party/skia/modules/skcms" ]
262   sources = rebase_path(skcms_sources, ".", "//third_party/skia/modules/skcms")
263 }
264
265 component("skia") {
266   deps = []
267   public = [
268     "ext/benchmarking_canvas.h",
269     "ext/cicp.h",
270     "ext/convolver.h",
271     "ext/event_tracer_impl.h",
272     "ext/image_operations.h",
273     "ext/legacy_display_globals.h",
274     "ext/opacity_filter_canvas.h",
275     "ext/recursive_gaussian_convolution.h",
276     "ext/rgba_to_yuva.h",
277     "ext/skcolorspace_primaries.h",
278     "ext/skcolorspace_trfn.h",
279     "ext/skia_memory_dump_provider.h",
280     "ext/skia_trace_memory_dump_impl.h",
281     "ext/skia_utils_base.h",
282   ]
283   sources = [
284     # Chrome sources.
285     "config/SkUserConfig.h",
286     "config/sk_ref_cnt_ext_debug.h",
287     "config/sk_ref_cnt_ext_release.h",
288     "ext/SkDiscardableMemory_chrome.cc",
289     "ext/SkDiscardableMemory_chrome.h",
290     "ext/SkMemory_new_handler.cpp",
291     "ext/benchmarking_canvas.cc",
292     "ext/cicp.cc",
293     "ext/convolver.cc",
294     "ext/event_tracer_impl.cc",
295     "ext/google_logging.cc",
296     "ext/image_operations.cc",
297     "ext/legacy_display_globals.cc",
298     "ext/opacity_filter_canvas.cc",
299     "ext/recursive_gaussian_convolution.cc",
300     "ext/rgba_to_yuva.cc",
301     "ext/skcolorspace_primaries.cc",
302     "ext/skcolorspace_trfn.cc",
303     "ext/skia_histogram.cc",
304     "ext/skia_histogram.h",
305     "ext/skia_memory_dump_provider.cc",
306     "ext/skia_trace_memory_dump_impl.cc",
307     "ext/skia_utils_base.cc",
308   ]
309   if (!is_apple) {
310     public += [ "ext/fontmgr_default.h" ]
311     sources += [ "ext/fontmgr_default.cc" ]
312   }
313   if (is_android) {
314     sources += [ "ext/fontmgr_default_android.cc" ]
315   }
316   if (is_linux || is_chromeos || is_tizen) {
317     sources += [ "ext/fontmgr_default_linux.cc" ]
318   }
319   if (is_ios) {
320     public += [ "ext/skia_utils_ios.h" ]
321     sources += [ "ext/skia_utils_ios.mm" ]
322   }
323   if (is_mac) {
324     public += [ "ext/skia_utils_mac.h" ]
325     sources += [ "ext/skia_utils_mac.mm" ]
326   }
327   if (is_win) {
328     public += [ "ext/skia_utils_win.h" ]
329     sources += [
330       "ext/fontmgr_default_win.cc",
331       "ext/skia_utils_win.cc",
332     ]
333   }
334
335   if (use_blink) {
336     public += [ "ext/platform_canvas.h" ]
337     sources += [ "ext/platform_canvas.cc" ]
338   }
339   if (!is_ios && (current_cpu == "x86" || current_cpu == "x64")) {
340     sources += [
341       "ext/convolver_SSE2.cc",
342       "ext/convolver_SSE2.h",
343     ]
344   } else if (current_cpu == "mipsel" && mips_dsp_rev >= 2) {
345     sources += [
346       "ext/convolver_mips_dspr2.cc",
347       "ext/convolver_mips_dspr2.h",
348     ]
349   } else if (current_cpu == "arm" || current_cpu == "arm64") {
350     if (arm_use_neon) {
351       sources += [
352         "ext/convolver_neon.cc",
353         "ext/convolver_neon.h",
354       ]
355     }
356   }
357
358   if (is_win) {
359     sources += [
360       # Select the right BitmapPlatformDevice.
361       "ext/raster_handle_allocator_win.cc",
362     ]
363   }
364
365   # skia_core_public is included via public_deps instead as the path_bridge
366   # target needs it as well.
367   public += skia_utils_public
368   public += skia_effects_public
369   public += skia_effects_imagefilter_public
370   public += skia_utils_chromium
371   public += skia_discardable_memory_chromium
372   public += skia_encode_public
373   public += skia_encode_png_public
374   public += skia_encode_webp_public
375
376   # The imported Skia gni source paths are made absolute by gn.
377   defines = []
378   sources += skia_sksl_sources
379   sources += skia_codec_core
380   sources += skia_utils_private
381   sources += skia_xps_sources
382   sources += skia_encode_srcs
383   sources += skia_encode_png_srcs
384   sources += skia_encode_webp_srcs
385   sources += [
386     "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp",
387     "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp",
388     "//third_party/skia/src/ports/SkGlobalInitialization_default.cpp",
389     "//third_party/skia/src/ports/SkImageGenerator_none.cpp",
390     "//third_party/skia/src/ports/SkOSFile_stdio.cpp",
391     "//third_party/skia/src/sfnt/SkOTTable_name.cpp",
392     "//third_party/skia/src/sfnt/SkOTUtils.cpp",
393   ]
394   if (use_blink) {
395     sources -= [ "//third_party/skia/src/ports/SkImageGenerator_none.cpp" ]
396     sources += skia_codec_decode_bmp
397     sources += skia_encode_jpeg_srcs
398     public += skia_encode_jpeg_public
399     sources += [
400       "//third_party/skia/src/codec/SkEncodedInfo.cpp",
401       "//third_party/skia/src/codec/SkIcoCodec.cpp",
402       "//third_party/skia/src/codec/SkJpegCodec.cpp",
403       "//third_party/skia/src/codec/SkJpegDecoderMgr.cpp",
404       "//third_party/skia/src/codec/SkJpegMultiPicture.cpp",
405       "//third_party/skia/src/codec/SkJpegSegmentScan.cpp",
406       "//third_party/skia/src/codec/SkJpegSourceMgr.cpp",
407       "//third_party/skia/src/codec/SkJpegUtility.cpp",
408       "//third_party/skia/src/codec/SkParseEncodedOrigin.cpp",
409       "//third_party/skia/src/codec/SkPngCodec.cpp",
410       "//third_party/skia/src/codec/SkWebpCodec.cpp",
411       "//third_party/skia/src/codec/SkWuffsCodec.cpp",
412       "//third_party/skia/src/ports/SkImageGenerator_skia.cpp",
413     ]
414     deps += [ "//third_party/wuffs" ]
415   } else {
416     sources += skia_no_encode_jpeg_srcs
417   }
418
419   if (skia_support_xmp) {
420     sources += skia_xml_sources
421     sources += skia_codec_xmp
422     sources += skia_codec_jpeg_xmp
423     deps += [ "//third_party/expat" ]
424     defines += [ "SK_CODEC_DECODES_JPEG_GAINMAPS" ]
425   }
426
427   # Remove unused util sources.
428   sources -= [ "//third_party/skia/src/utils/SkParsePath.cpp" ]
429
430   if (is_win) {
431     libs = [ "fontsub.lib" ]
432   }
433
434   # need separate win section to handle chromes auto gn filter
435   # (build/config/BUILDCONFIG.gn)
436   if (is_win) {
437     sources -= [
438       #windows
439       "//third_party/skia/src/utils/win/SkWGL_win.cpp",
440     ]
441   }
442
443   # Select Skia ports.
444
445   # FreeType is needed everywhere where blink is used, on Linux and Android as main
446   # font backend, on Windows and Mac as fallback backend for Variations.
447   if (use_blink) {
448     # See SK_TYPEFACE_FACTORY_FREETYPE
449     sources += [
450       "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
451       "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
452     ]
453   }
454
455   if (use_typeface_fontations) {
456     sources += [
457       "//third_party/skia/src/ports/SkTypeface_fontations.cpp",
458       "//third_party/skia/src/ports/SkTypeface_fontations_priv.h",
459     ]
460     deps += [
461       ":bridge_rust_side",
462       ":path_bridge",
463     ]
464   }
465
466   if (is_win) {
467     # See SK_TYPEFACE_FACTORY_DIRECTWRITE
468     sources += [
469       "//third_party/skia/src/ports/SkFontMgr_win_dw.cpp",
470       "//third_party/skia/src/ports/SkOSFile_win.cpp",
471       "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
472       "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
473       "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
474     ]
475   } else {
476     sources += [ "//third_party/skia/src/ports/SkOSFile_posix.cpp" ]
477   }
478
479   if (is_apple) {
480     # See SK_TYPEFACE_FACTORY_CORETEXT
481     sources += [
482       "//third_party/skia/include/ports/SkFontMgr_mac_ct.h",
483       "//third_party/skia/src/ports/SkFontMgr_mac_ct.cpp",
484       "//third_party/skia/src/ports/SkFontMgr_mac_ct_factory.cpp",
485       "//third_party/skia/src/ports/SkScalerContext_mac_ct.cpp",
486       "//third_party/skia/src/ports/SkScalerContext_mac_ct.h",
487       "//third_party/skia/src/ports/SkTypeface_mac_ct.cpp",
488       "//third_party/skia/src/ports/SkTypeface_mac_ct.h",
489     ]
490   }
491
492   if (is_linux || is_tizen || is_chromeos) {
493     sources += [
494       "//third_party/skia/src/ports/SkFontConfigInterface.cpp",
495       "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
496       "//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp",
497       "//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp",
498     ]
499   }
500
501   if (is_linux || is_tizen || is_chromeos || is_android) {
502     sources += [
503       # Retain the files for the SkFontMgr_Android on linux to emulate android
504       # fonts. See content/zygote/zygote_main_linux.cc
505       # Note that this requires expat.
506       "//third_party/skia/src/ports/SkFontMgr_android.cpp",
507       "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
508     ]
509   }
510
511   if (is_win || (is_apple && use_blink)) {
512     sources += [
513       # Add the FreeType custom font manager as a fallback backend for variable fonts.
514       "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
515       "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
516     ]
517   }
518
519   if (is_fuchsia) {
520     sources += [
521       "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
522       "//third_party/skia/src/ports/SkFontMgr_fuchsia.cpp",
523       "ext/fontmgr_default_fuchsia.cc",
524     ]
525     deps += [
526       "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
527       "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_hlcpp",
528       "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
529       "//third_party/fuchsia-sdk/sdk/pkg/zx",
530       "//third_party/icu:icuuc",
531     ]
532   }
533
534   configs -= [ "//build/config/compiler:chromium_code" ]
535   configs += [
536     ":skia_config",
537     ":skia_library_config",
538     "//build/config/compiler:no_chromium_code",
539   ]
540   all_dependent_configs = [ ":skia_config" ]
541
542   deps += [
543     ":skcms",
544     ":skia_opts",
545     "//base",
546     "//base/third_party/dynamic_annotations",
547     "//third_party/libpng",
548     "//third_party/libwebp",
549     "//third_party/libwebp:libwebp_webp",
550   ]
551   public_deps = [
552     ":buildflags",
553     ":skia_core_and_effects",
554     ":skia_core_public_headers",
555   ]
556
557   if (use_blink) {
558     deps += [
559       "//build/config/freetype",
560       "//third_party:jpeg",
561     ]
562   }
563
564   if (is_linux || is_chromeos) {
565     deps += [
566       "//third_party/expat",
567       "//third_party/fontconfig",
568       "//third_party/icu:icuuc",
569     ]
570   }
571
572   if (is_android) {
573     deps += [
574       "//third_party/cpu_features:ndk_compat",
575       "//third_party/expat",
576     ]
577   }
578
579   if (is_tizen) {
580     deps += [ "//third_party/expat" ]
581   }
582
583   if (!is_debug) {
584     configs -= [ "//build/config/compiler:default_optimization" ]
585     configs += [ "//build/config/compiler:optimize_max" ]
586   }
587
588   frameworks = []
589   if (is_ios) {
590     frameworks += [ "ImageIO.framework" ]
591   }
592   if (is_apple && skia_support_gpu) {
593     frameworks += [
594       "CoreFoundation.framework",
595       "CoreGraphics.framework",
596       "CoreText.framework",
597       "Foundation.framework",
598     ]
599     if (is_mac) {
600       frameworks += [ "AppKit.framework" ]
601     }
602     if (is_ios) {
603       frameworks += [ "IOSurface.framework" ]
604     }
605   }
606
607   if (is_fuchsia) {
608     deps += [ "//third_party/expat" ]
609   }
610
611   if (skia_support_gpu) {
612     public += skia_gpu_public
613     public += skia_gpu_chromium_public
614     sources += skia_ganesh_private
615     sources += skia_null_gpu_sources
616     sources += skia_sksl_gpu_sources
617     sources += skia_shared_gpu_sources
618     if (skia_use_gl) {
619       public += skia_gpu_gl_public
620       sources += skia_gpu_gl_private
621     }
622     if (enable_vulkan) {
623       public += skia_gpu_vk_public
624       public += skia_gpu_vk_chromium_public
625       sources += skia_gpu_vk_private
626       sources += skia_shared_vk_sources
627       sources += skia_gpu_vk_chromium_private
628     }
629
630     public_deps += [ ":skia_graphite_public" ]
631     deps += [ ":skia_graphite_private" ]
632
633     if (skia_use_metal) {
634       deps += [ ":skia_ganesh_metal" ]
635     }
636     deps += [ "//gpu/config:workaround_list" ]
637   } else {
638     sources += skia_no_slug_srcs
639   }
640
641   if (skia_support_pdf) {
642     deps += [
643       "//third_party:freetype_harfbuzz",
644       "//third_party/zlib",
645     ]
646     public += skia_pdf_public
647     sources += skia_pdf_sources
648     if (use_blink) {
649       # Blink includes Skia's JPEG decoder
650       sources += skia_pdf_jpeginfo_lib
651     } else {
652       sources += skia_pdf_jpeginfo_none
653     }
654   } else {
655     sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
656   }
657
658   if (skia_support_skottie) {
659     import("//third_party/skia/modules/skottie/skottie.gni")
660     import("//third_party/skia/modules/skresources/skresources.gni")
661     import("//third_party/skia/modules/sksg/sksg.gni")
662     import("//third_party/skia/modules/skshaper/skshaper.gni")
663     public += skia_skottie_public
664     sources += skia_skottie_sources
665     sources += skia_skresources_sources
666     sources += skia_sksg_sources
667     sources += skia_shaper_primitive_sources
668   }
669 }
670
671 # Template for things that are logically part of :skia, but need to be split out
672 # so custom compile flags can be applied.
673 #
674 # These are all opted out of check_includes, due to (logically) being part of
675 # skia.
676 template("skia_source_set") {
677   source_set(target_name) {
678     forward_variables_from(invoker, "*")
679
680     check_includes = false
681
682     if (!is_debug) {
683       configs -= [ "//build/config/compiler:default_optimization" ]
684       configs += [ "//build/config/compiler:optimize_max" ]
685     }
686
687     configs -= [ "//build/config/compiler:chromium_code" ]
688     configs += [
689       ":skia_config",
690       ":skia_library_config",
691       "//build/config/compiler:no_chromium_code",
692     ]
693     public_configs = [ ":skia_config" ]
694
695     if (is_apple) {
696       # Do not compile with ARC because Skia code is not compatible with being
697       # compiled with ARC.
698       configs -= [ "//build/config/compiler:enable_arc" ]
699     }
700
701     # Android, the only user of mismatched sample files (for now), gets a small
702     # binary size decrease by using AFDO to optimize for size in these
703     # source_sets. However, that also comes at a relatively big performance
704     # cost.
705     if (using_mismatched_sample_profile && !is_tizen) {
706       configs -= [ "//build/config/compiler:afdo_optimize_size" ]
707     }
708     if (is_win) {
709       cflags_cc = [
710         "/wd5041",  # out-of-line definition for constexpr static data member is
711                     # not needed and is deprecated in C++17
712       ]
713     }
714   }
715 }
716
717 # Split out for targeted removal of the afdo_optimize_size config on Android.
718 skia_source_set("skia_core_and_effects") {
719   defines = []
720   sources = skia_core_sources
721   sources += skia_colorfilters_sources
722   sources += skia_effects_sources
723   sources += skia_effects_imagefilter_sources
724   if (skia_support_gpu) {
725     deps = [ "//gpu/config:workaround_list" ]
726   }
727   if (skia_use_dawn) {
728     # Note: This is needed as files in this target include GrDawnTypes.h, which
729     # includes Dawn headers that are generated by the below target. Normally it
730     # would be enough for the target that has GrDawnTypes.h in it to just have
731     # cpp_headers in its public deps. However, that file is in
732     # sk_gpu_dawn_public, which we add to the "skia" target, which depends on
733     # skia_core_and_effects rather than the other way around.
734     public_deps = [ "//third_party/dawn/include/dawn:cpp_headers" ]
735   }
736   visibility = [ ":skia" ]
737 }
738
739 # Bits that involve special vector-y hardware.
740 if (current_cpu == "x86" || current_cpu == "x64") {
741   skia_source_set("skia_opts_hsw") {
742     sources = skia_opts.hsw_sources
743     if (!is_win) {
744       cflags = [
745         "-mavx2",
746         "-mbmi",
747         "-mbmi2",
748         "-mf16c",
749         "-mfma",
750       ]
751     }
752     if (is_win) {
753       cflags = [ "/arch:AVX2" ]
754     }
755     visibility = [ ":skia_opts" ]
756   }
757 }
758
759 skia_source_set("skia_opts") {
760   cflags = []
761   defines = []
762
763   deps = [ "//base" ]
764
765   if (current_cpu == "x86" || current_cpu == "x64") {
766     deps += [ ":skia_opts_hsw" ]
767   } else if (current_cpu == "arm") {
768     # The assembly uses the frame pointer register (r7 in Thumb/r11 in
769     # ARM), the compiler doesn't like that.
770     if (!is_ios) {
771       cflags += [ "-fomit-frame-pointer" ]
772     }
773
774     if (arm_version >= 7) {
775       if (arm_use_neon || arm_optionally_use_neon) {
776         # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
777         # when running this.
778         if (!arm_use_neon) {
779           configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
780           cflags += [ "-mfpu=neon" ]
781         }
782       }
783     }
784   } else if (current_cpu == "arm64") {
785     # Conditional and empty body needed to avoid assert() below.
786   } else if (current_cpu == "mipsel") {
787     cflags += [ "-fomit-frame-pointer" ]
788   } else if (current_cpu == "mips64el") {
789     cflags += [ "-fomit-frame-pointer" ]
790   } else if (current_cpu == "ppc64") {
791     # Conditional and empty body needed to avoid assert() below.
792   } else if (current_cpu == "s390x") {
793     # Conditional and empty body needed to avoid assert() below.
794   } else if (current_cpu == "riscv64") {
795     # Conditional and empty body needed to avoid assert() below.
796   } else {
797     assert(false, "Unknown cpu target")
798   }
799
800   visibility = [ ":skia" ]
801 }
802
803 # Split out Graphite sources because of conflicting file names with Ganesh.
804 # Split into separate private and public source sets because we want to allow
805 # shared GPU code in ":skia" to include private Graphite headers, but want to
806 # limit external code to only depend on public headers. Only define these source
807 # sets when skia_support_gpu is true so that on iOS non-Blink builds, headers in
808 # these source sets are considered unknown and skipped by gn check.
809 if (skia_support_gpu) {
810   skia_source_set("skia_graphite_public") {
811     public = skia_graphite_public
812     if (skia_use_dawn) {
813       public += skia_graphite_dawn_public
814       public_deps = [
815         "//third_party/dawn/include/dawn:cpp_headers",
816         "//third_party/dawn/src/dawn:cpp",
817         "//third_party/dawn/src/dawn:proc",
818       ]
819     }
820     if (skia_use_metal) {
821       public += skia_graphite_mtl_public
822       frameworks = [ "Metal.framework" ]
823     }
824     deps = [ "//gpu/config:workaround_list" ]
825   }
826
827   # If a source set contains only sources and no public files, then dependents can
828   # include any file from sources.
829   skia_source_set("skia_graphite_private") {
830     sources = skia_graphite_sources
831     if (skia_use_dawn) {
832       sources += skia_shared_dawn_sources
833       sources += skia_graphite_dawn_sources
834     }
835     if (skia_use_metal) {
836       sources += skia_shared_mtl_sources
837       sources += skia_graphite_mtl_sources
838     }
839     deps = [ "//gpu/config:workaround_list" ]
840     if (skia_use_dawn) {
841       deps += [ "//third_party/dawn/include/dawn:cpp_headers" ]
842     }
843     visibility = [ ":skia" ]
844   }
845
846   if (skia_use_metal) {
847     # Split out Ganesh Metal sources, because they require ARC.
848     skia_source_set("skia_ganesh_metal") {
849       sources = skia_gpu_metal_public
850       sources += skia_gpu_metal_private
851       cflags_objcc = [
852         "-Wno-unguarded-availability",
853         "-fobjc-arc",
854       ]
855       deps = [ "//gpu/config:workaround_list" ]
856       if (skia_use_dawn) {
857         # Needed due to include chain containing webgpu_cpp.h via GrDawnTypes.h.
858         public_deps = [ "//third_party/dawn/include/dawn:cpp_headers" ]
859       }
860       visibility = [ ":skia" ]
861     }
862   }
863 }
864
865 # Font copies.
866 if (is_fuchsia) {
867   copy("copy_fuchsia_fonts_manifest") {
868     sources = [ "ext/data/test_fonts/fuchsia_test_fonts_manifest.json" ]
869     outputs = [ "$root_out_dir/test_fonts/all.font_manifest.json" ]
870   }
871 }
872 if (is_apple) {
873   bundle_data("test_fonts_bundle_data") {
874     public_deps = [ "//third_party/test_fonts" ]
875
876     sources = [
877       "$root_out_dir/test_fonts/Ahem.ttf",
878       "ext/data/test_fonts/ChromiumAATTest.ttf",
879     ]
880
881     outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
882   }
883 }
884
885 group("test_fonts_resources") {
886   testonly = true
887   deps = []
888   data_deps = []
889
890   if (is_apple) {
891     deps += [ ":test_fonts_bundle_data" ]
892     data_deps += [ ":test_fonts_bundle_data" ]
893   } else {
894     deps += [ "//third_party/test_fonts" ]
895     data_deps += [ "//third_party/test_fonts" ]
896   }
897
898   if (is_fuchsia) {
899     deps += [ ":copy_fuchsia_fonts_manifest" ]
900     data_deps += [ ":copy_fuchsia_fonts_manifest" ]
901   }
902 }
903
904 # Fuchsia components that use the test fonts must include
905 # "//build/config/fuchsia/test/test_fonts.shard.test-cml" in their
906 # `additional_manifest_fragments`.
907 source_set("test_fonts") {
908   testonly = true
909
910   deps = [ ":test_fonts_resources" ]
911
912   if (is_fuchsia) {
913     public = [
914       "ext/test_fonts.h",
915       "ext/test_fonts_fuchsia.h",
916     ]
917     sources = [
918       "ext/test_fonts_fuchsia.cc",
919       "ext/test_fonts_fuchsia_cfv2.cc",
920     ]
921     public_deps = [
922       "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
923     ]
924     deps += [
925       "//base",
926       "//skia",
927       "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
928     ]
929   }
930   if (is_apple) {
931     public = [ "ext/test_fonts.h" ]
932     sources = [ "ext/test_fonts_mac.mm" ]
933     deps += [ "//base" ]
934   }
935 }
936
937 test("skia_unittests") {
938   sources = [
939     "ext/convolver_unittest.cc",
940     "ext/image_operations_unittest.cc",
941     "ext/platform_canvas_unittest.cc",
942     "ext/recursive_gaussian_convolution_unittest.cc",
943     "ext/skcolorspace_primaries_unittest.cc",
944     "ext/skcolorspace_trfn_unittest.cc",
945     "ext/skia_memory_dump_provider_unittest.cc",
946     "ext/skia_utils_base_unittest.cc",
947   ]
948   if (is_ios) {
949     sources += [ "ext/skia_utils_ios_unittest.mm" ]
950   }
951   if (is_mac) {
952     sources += [ "ext/skia_utils_mac_unittest.mm" ]
953   }
954
955   if (!is_win) {
956     sources -= [ "ext/platform_canvas_unittest.cc" ]
957   }
958
959   deps = [
960     ":skcms",
961     ":skia",
962     ":test_fonts",
963     "//base",
964     "//base/test:test_support",
965     "//mojo/core/test:run_all_unittests",
966     "//testing/gtest",
967     "//ui/gfx",
968     "//ui/gfx/geometry",
969   ]
970
971   data_deps = [ "//testing/buildbot/filters:skia_unittests_filters" ]
972
973   if (!is_ios) {
974     sources += [ "public/mojom/test/mojom_traits_unittest.cc" ]
975     deps += [
976       "//mojo/public/cpp/bindings",
977       "//mojo/public/cpp/test_support:test_utils",
978       "//skia/public/mojom",
979     ]
980   }
981
982   if (is_fuchsia) {
983     sources += [ "ext/fontmgr_fuchsia_unittest.cc" ]
984     deps += [
985       "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
986     ]
987     additional_manifest_fragments =
988         [ "//build/config/fuchsia/test/test_fonts.shard.test-cml" ]
989   }
990
991   if (skia_support_skottie) {
992     sources += [ "ext/skottie_unittest.cc" ]
993   }
994 }
995
996 if (!is_ios) {
997   executable("image_operations_bench") {
998     sources = [ "ext/image_operations_bench.cc" ]
999
1000     deps = [
1001       ":skia",
1002       "//base",
1003       "//build/win:default_exe_manifest",
1004     ]
1005   }
1006
1007   executable("filter_fuzz_stub") {
1008     testonly = true
1009     sources = [ "tools/filter_fuzz_stub/filter_fuzz_stub.cc" ]
1010
1011     deps = [
1012       ":skia",
1013       "//base",
1014       "//base/test:test_support",
1015       "//build/win:default_exe_manifest",
1016     ]
1017   }
1018 }
1019
1020 group("fuzzers") {
1021   deps = [ "//skia/tools/fuzzers" ]
1022 }