1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
  258
  259
  260
  261
  262
  263
  264
  265
  266
  267
  268
  269
  270
  271
  272
  273
  274
  275
  276
  277
  278
  279
  280
  281
  282
  283
  284
  285
  286
  287
  288
  289
  290
  291
  292
  293
  294
  295
  296
  297
  298
  299
  300
  301
  302
  303
  304
  305
  306
  307
  308
  309
  310
  311
  312
  313
  314
  315
  316
  317
  318
  319
  320
  321
  322
  323
  324
  325
  326
  327
  328
  329
  330
  331
  332
  333
  334
  335
  336
  337
  338
  339
  340
  341
  342
  343
  344
  345
  346
  347
  348
  349
  350
  351
  352
  353
  354
  355
  356
  357
  358
  359
  360
  361
  362
  363
  364
  365
  366
  367
  368
  369
  370
  371
  372
  373
  374
  375
  376
  377
  378
  379
  380
  381
  382
  383
  384
  385
  386
  387
  388
  389
  390
  391
  392
  393
  394
  395
  396
  397
  398
  399
  400
  401
  402
  403
  404
  405
  406
  407
  408
  409
  410
  411
  412
  413
  414
  415
  416
  417
  418
  419
  420
  421
  422
  423
  424
  425
  426
  427
  428
  429
  430
  431
  432
  433
  434
  435
  436
  437
  438
  439
  440
  441
  442
  443
  444
  445
  446
  447
  448
  449
  450
  451
  452
  453
  454
  455
  456
  457
  458
  459
  460
  461
  462
  463
  464
  465
  466
  467
  468
  469
  470
  471
  472
  473
  474
  475
  476
  477
  478
  479
  480
  481
  482
  483
  484
  485
  486
  487
  488
  489
  490
  491
  492
  493
  494
  495
  496
  497
  498
  499
  500
  501
  502
  503
  504
  505
  506
  507
  508
  509
  510
  511
  512
  513
  514
  515
  516
  517
  518
  519
  520
  521
  522
  523
  524
  525
  526
  527
  528
  529
  530
  531
  532
  533
  534
  535
  536
  537
  538
  539
  540
  541
  542
  543
  544
  545
  546
  547
  548
  549
  550
  551
  552
  553
  554
  555
  556
  557
  558
  559
  560
  561
  562
  563
  564
  565
  566
  567
  568
  569
  570
  571
  572
  573
  574
  575
  576
  577
  578
  579
  580
  581
  582
  583
  584
  585
  586
  587
  588
  589
  590
  591
  592
  593
  594
  595
  596
  597
  598
  599
  600
  601
  602
  603
  604
  605
  606
  607
  608
  609
  610
  611
  612
  613
  614
  615
  616
  617
  618
  619
  620
  621
  622
  623
  624
  625
  626
  627
  628
  629
  630
  631
  632
  633
  634
  635
  636
  637
  638
  639
  640
  641
  642
  643
  644
  645
  646
  647
  648
  649
  650
  651
  652
  653
  654
  655
  656
  657
  658
  659
  660
  661
  662
  663
  664
  665
  666
  667
  668
  669
  670
  671
  672
  673
  674
  675
  676
  677
  678
  679
  680
  681
  682
  683
  684
  685
  686
  687
  688
  689
  690
  691
  692
  693
  694
  695
  696
  697
  698
  699
  700
  701
  702
  703
  704
  705
  706
  707
  708
  709
  710
  711
  712
  713
  714
  715
  716
  717
  718
  719
  720
  721
  722
  723
  724
  725
  726
  727
  728
  729
  730
  731
  732
  733
  734
  735
  736
  737
  738
  739
  740
  741
  742
  743
  744
  745
  746
  747
  748
  749
  750
  751
  752
  753
  754
  755
  756
  757
  758
  759
  760
  761
  762
  763
  764
  765
  766
  767
  768
  769
  770
  771
  772
  773
  774
  775
  776
  777
  778
  779
  780
  781
  782
  783
  784
  785
  786
  787
  788
  789
  790
  791
  792
  793
  794
  795
  796
  797
  798
  799
  800
  801
  802
  803
  804
  805
  806
  807
  808
  809
  810
  811
  812
  813
  814
  815
  816
  817
  818
  819
  820
  821
  822
  823
  824
  825
  826
  827
  828
  829
  830
  831
  832
  833
  834
  835
  836
  837
  838
  839
  840
  841
  842
  843
  844
  845
  846
  847
  848
  849
  850
  851
  852
  853
  854
  855
  856
  857
  858
  859
  860
  861
  862
  863
  864
  865
  866
  867
  868
  869
  870
  871
  872
  873
  874
  875
  876
  877
  878
  879
  880
  881
  882
  883
  884
  885
  886
  887
  888
  889
  890
  891
  892
  893
  894
  895
  896
  897
  898
  899
  900
  901
  902
  903
  904
  905
  906
  907
  908
  909
  910
  911
  912
  913
  914
  915
  916
  917
  918
  919
  920
  921
  922
  923
  924
  925
  926
  927
  928
  929
  930
  931
  932
  933
  934
  935
  936
  937
  938
  939
  940
  941
  942
  943
  944
  945
  946
  947
  948
  949
  950
  951
  952
  953
  954
  955
  956
  957
  958
  959
  960
  961
  962
  963
  964
  965
  966
  967
  968
  969
  970
  971
  972
  973
  974
  975
  976
  977
  978
  979
  980
  981
  982
  983
  984
  985
  986
  987
  988
  989
  990
  991
  992
  993
  994
  995
  996
  997
  998
  999
 1000
 1001
 1002
 1003
 1004
 1005
 1006
 1007
 1008
 1009
 1010
 1011
 1012
 1013
 1014
 1015
 1016
 1017
 1018
 1019
 1020
 1021
 1022
 1023
 1024
 1025
 1026
 1027
 1028
 1029
 1030
 1031
 1032
 1033
 1034
 1035
 1036
 1037
 1038
 1039
 1040
 1041
 1042
 1043
 1044
 1045
 1046
 1047
 1048
 1049
 1050
 1051
 1052
 1053
 1054
 1055
 1056
 1057
 1058
 1059
 1060
 1061
 1062
 1063
 1064
 1065
 1066
 1067
 1068
 1069
 1070
 1071
 1072
 1073
 1074
 1075
 1076
 1077
 1078
 1079
 1080
 1081
 1082
 1083
 1084
 1085
 1086
 1087
 1088
 1089
 1090
 1091
 1092
 1093
 1094
 1095
 1096
 1097
 1098
 1099
 1100
 1101
 1102
 1103
 1104
 1105
 1106
 1107
 1108
 1109
 1110
 1111
 1112

skia / BUILD.gn [blame]

# Copyright 2013 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/features.gni")
import("//build/config/freetype/freetype.gni")
import("//build/config/rust.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/rust/rust_static_library.gni")
import("//gpu/vulkan/features.gni")
import("//skia/skia.gni")
import("//testing/test.gni")
import("//third_party/skia/gn/shared_sources.gni")
import("//third_party/skia/modules/skcms/skcms.gni")
import("features.gni")

if (current_cpu == "arm") {
  import("//build/config/arm.gni")
}
if (current_cpu == "mipsel" || current_cpu == "mips64el") {
  import("//build/config/mips.gni")
}
if (enable_rust_png) {
  import("//build/rust/rust_static_library.gni")
}

buildflag_header("buildflags") {
  header = "buildflags.h"
  flags = [
    "SKIA_BUILD_RUST_PNG=$enable_rust_png",
    "SKIA_SUPPORT_SKOTTIE=$skia_support_skottie",
    "SKIA_USE_DAWN=$skia_use_dawn",
    "SKIA_USE_METAL=$skia_use_metal",
  ]
}

source_set("path_bridge") {
  sources = skia_fontations_path_bridge_sources
}

rust_static_library("bridge_rust_side") {
  allow_unsafe = true
  crate_root = skia_fontations_bridge_root
  sources = skia_fontations_bridge_sources
  cxx_bindings = skia_fontations_bridge_sources
  deps = [
    ":path_bridge",
    "//third_party/rust/font_types/v0_7:lib",
    "//third_party/rust/read_fonts/v0_23:lib",
    "//third_party/rust/skrifa/v0_24:lib",
  ]
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":skia_config",
    "//build/config/compiler:no_chromium_code",
  ]
}

# External-facing config for dependent code.
config("skia_config") {
  defines = [
    "SK_ENABLE_SKSL",
    "SK_UNTIL_CRBUG_1187654_IS_FIXED",
    "SK_USER_CONFIG_HEADER=\"../../skia/config/SkUserConfig.h\"",
    "SK_WIN_FONTMGR_NO_SIMULATIONS",
    "SK_DISABLE_LEGACY_INIT_DECODERS",
    "SK_DISABLE_LEGACY_BACKEND_TEXTURE_FUNCS",
    "SK_DISABLE_LEGACY_TEXTURE_INFO_FUNCS",
    "SK_DISABLE_LEGACY_BACKEND_SEMAPHORE_FUNCS",
    "SK_DISABLE_LEGACY_GRAPHITE_IMAGES",
    "SK_DISABLE_LEGACY_DAWN_TEXTURE_INFO_FUNCS",
    "SK_DISABLE_LEGACY_DAWN_BACKEND_TEXTURE_FUNCS",
  ]

  include_dirs = [
    "//third_party/skia",
    "$root_gen_dir/third_party/skia",
  ]

  if (use_blink) {
    # TODO(kjlubick) make these not necessary
    defines += [
      "SK_CODEC_DECODES_JPEG",
      "SK_ENCODE_JPEG",
      "SK_ENCODE_PNG",
      "SK_ENCODE_WEBP",
    ]
    include_dirs += [ "//third_party/wuffs/src/release/c" ]
  }

  if (is_component_build) {
    defines += [ "SKIA_DLL" ]
    if (is_win) {
      defines += [ "SKCMS_API=__declspec(dllexport)" ]
    } else {
      defines += [ "SKCMS_API=__attribute__((visibility(\"default\")))" ]
    }
  }

  if (is_android) {
    defines += [
      "SK_BUILD_FOR_ANDROID",
      "USE_CHROMIUM_SKIA",
    ]
  }

  if (is_mac) {
    defines += [ "SK_BUILD_FOR_MAC" ]
  }
  if (is_ios) {
    defines += [ "SK_BUILD_FOR_IOS" ]
    if (ios_is_app_extension) {
      defines += [ "SK_BUILD_FOR_IOS_APP_EXTENSION" ]
    }
  }

  if (is_win) {
    defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
  }

  if (skia_support_gpu) {
    workaround_header = "gpu/config/gpu_driver_bug_workaround_autogen.h"
    configs = []
    defines += [
      "SK_GANESH",
      "SK_GPU_WORKAROUNDS_HEADER=\"$workaround_header\"",
    ]
    if (skia_use_gl) {
      defines += [ "SK_GL" ]
    }
    if (enable_vulkan) {
      defines += [ "SK_VULKAN=1" ]
      include_dirs += [ "//third_party/vulkan/include" ]
      configs += [ "//third_party/vulkan-headers/src:vulkan_headers_config" ]
    }

    # Graphite
    defines += [ "SK_GRAPHITE" ]
    if (skia_use_dawn) {
      defines += [ "SK_DAWN" ]
      configs += [ "//third_party/dawn/include/dawn:public" ]
    }
    if (skia_use_metal) {
      defines += [ "SK_METAL" ]
    }
  }
  if (current_cpu == "loong64") {
    cflags = [
      "-mlsx",
      "-flax-vector-conversions=all",
    ]
  }
}

# Internal-facing config for Skia library code.
config("skia_library_config") {
  # Turn on SK_API to export Skia's public API
  defines = [
    "IS_SKIA_IMPL=1",
    "SKIA_IMPLEMENTATION=1",
  ]

  if (use_blink && !use_system_freetype) {
    defines += [ "SK_FREETYPE_MINIMUM_RUNTIME_VERSION_IS_BUILD_VERSION" ]
  }
  if (use_blink && enable_freetype) {
    defines += [
      "SK_TYPEFACE_FACTORY_FREETYPE",
      "SK_TYPEFACE_FACTORY_FONTATIONS",
      "SK_FONTMGR_FREETYPE_EMPTY_AVAILABLE",
    ]
  }
  if (is_win) {
    defines += [ "SK_TYPEFACE_FACTORY_DIRECTWRITE" ]
  }
  if (is_apple) {
    defines += [ "SK_TYPEFACE_FACTORY_CORETEXT" ]
  }

  if (current_cpu == "arm") {
    if (arm_use_neon) {
      defines += [ "SK_ARM_HAS_NEON" ]
    } else if (arm_optionally_use_neon) {
      defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
    }
  }

  # Settings for text blitting, chosen to approximate the system browser.
  if (is_linux || is_chromeos) {
    defines += [
      "SK_GAMMA_EXPONENT=1.2",
      "SK_GAMMA_CONTRAST=0.2",
    ]
  } else if (is_android) {
    defines += [
      "SK_GAMMA_APPLY_TO_A8",
      "SK_GAMMA_EXPONENT=1.4",
      "SK_GAMMA_CONTRAST=0.0",
    ]
  } else if (is_win) {
    defines += [
      "SK_GAMMA_SRGB",
      "SK_GAMMA_CONTRAST=0.5",
    ]
  } else if (is_mac) {
    defines += [
      "SK_GAMMA_SRGB",
      "SK_GAMMA_CONTRAST=0.0",
    ]
  }

  if (is_android) {
    defines += [
      # Android devices are typically more memory constrained, so default to a
      # smaller glyph cache (it may be overriden at runtime when the renderer
      # starts up, depending on the actual device memory).
      "SK_DEFAULT_FONT_CACHE_LIMIT=1048576",  # 1024 * 1024
    ]
  } else {
    defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
  }

  if (is_win) {
    defines += [
      # On windows, GDI handles are a scarse system-wide resource so we have to
      # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
      # fairly small size. http://crbug.com/314387
      "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
    ]
  }
}

# Split out into separate target so that path_bridge can depend on the public
# headers only and we can avoid a cyclic dependency when building the C++ native
# code for the Fontations rust backend.
source_set("skia_core_public_headers") {
  public = skia_core_public
}

component("skia") {
  deps = []
  public = [
    "ext/benchmarking_canvas.h",
    "ext/cicp.h",
    "ext/codec_utils.h",
    "ext/convolver.h",
    "ext/draw_gainmap_image.h",
    "ext/event_tracer_impl.h",
    "ext/font_utils.h",
    "ext/geometry.h",
    "ext/image_operations.h",
    "ext/legacy_display_globals.h",
    "ext/opacity_filter_canvas.h",
    "ext/recursive_gaussian_convolution.h",
    "ext/rgba_to_yuva.h",
    "ext/skcolorspace_primaries.h",
    "ext/skcolorspace_trfn.h",
    "ext/skia_memory_dump_provider.h",
    "ext/skia_trace_memory_dump_impl.h",
    "ext/skia_utils_base.h",
    "rusty_png_feature.h",
  ]
  sources = [
    # Chrome sources.
    "config/SkUserConfig.h",
    "config/sk_ref_cnt_ext_debug.h",
    "config/sk_ref_cnt_ext_release.h",
    "ext/SkDiscardableMemory_chrome.cc",
    "ext/SkDiscardableMemory_chrome.h",
    "ext/SkMemory_new_handler.cpp",
    "ext/benchmarking_canvas.cc",
    "ext/cicp.cc",
    "ext/codec_utils.cc",
    "ext/convolver.cc",
    "ext/draw_gainmap_image.cc",
    "ext/event_tracer_impl.cc",
    "ext/font_utils.cc",
    "ext/geometry.cc",
    "ext/google_logging.cc",
    "ext/image_operations.cc",
    "ext/legacy_display_globals.cc",
    "ext/opacity_filter_canvas.cc",
    "ext/recursive_gaussian_convolution.cc",
    "ext/rgba_to_yuva.cc",
    "ext/skcolorspace_primaries.cc",
    "ext/skcolorspace_trfn.cc",
    "ext/skia_histogram.cc",
    "ext/skia_histogram.h",
    "ext/skia_memory_dump_provider.cc",
    "ext/skia_trace_memory_dump_impl.cc",
    "ext/skia_utils_base.cc",
    "rusty_png_feature.cc",
  ]
  if (is_ios) {
    public += [ "ext/skia_utils_ios.h" ]
    sources += [ "ext/skia_utils_ios.mm" ]
  }
  if (is_mac) {
    public += [ "ext/skia_utils_mac.h" ]
    sources += [ "ext/skia_utils_mac.mm" ]
  }
  if (is_win) {
    public += [ "ext/skia_utils_win.h" ]
    sources += [ "ext/skia_utils_win.cc" ]
  }

  if (use_blink) {
    public += [ "ext/platform_canvas.h" ]
    sources += [ "ext/platform_canvas.cc" ]
  }
  if (!is_ios && (current_cpu == "x86" || current_cpu == "x64")) {
    sources += [
      "ext/convolver_SSE2.cc",
      "ext/convolver_SSE2.h",
    ]
  } else if (current_cpu == "mipsel" && mips_dsp_rev >= 2) {
    sources += [
      "ext/convolver_mips_dspr2.cc",
      "ext/convolver_mips_dspr2.h",
    ]
  } else if (current_cpu == "arm" || current_cpu == "arm64") {
    if (arm_use_neon) {
      sources += [
        "ext/convolver_neon.cc",
        "ext/convolver_neon.h",
      ]
    }
  } else if (current_cpu == "loong64") {
    sources += [
      "ext/convolver_LSX.cc",
      "ext/convolver_LSX.h",
    ]
  }

  if (is_win) {
    sources += [
      # Select the right BitmapPlatformDevice.
      "ext/raster_handle_allocator_win.cc",
    ]
  }

  # skia_core_public is included via public_deps instead as the path_bridge
  # target needs it as well.
  public += skia_utils_public
  public += skia_effects_public
  public += skia_effects_imagefilter_public
  public += skia_utils_chromium
  public += skia_discardable_memory_chromium
  public += skia_codec_public
  public += skia_encode_public
  public += skia_encode_png_public
  public += skia_encode_webp_public

  # The imported Skia gni source paths are made absolute by gn.
  defines = []
  sources += skia_ports_sources
  sources += skia_sksl_core_sources
  sources += skia_sksl_core_module_sources
  sources += skia_codec_shared
  sources += skia_codec_png_base
  sources += skia_codec_libpng_srcs
  sources += skia_utils_private
  sources += skia_xps_sources
  sources += skia_encode_srcs
  sources += skia_encode_png_base
  sources += skia_encode_libpng_srcs
  sources += skia_encode_webp_srcs
  sources += [
    "//third_party/skia/src/sfnt/SkOTTable_name.cpp",
    "//third_party/skia/src/sfnt/SkOTUtils.cpp",
  ]
  if (use_blink) {
    sources += skia_codec_decode_bmp
    sources += skia_encode_jpeg_srcs
    public += skia_encode_jpeg_public
    sources += [
      "//third_party/skia/src/codec/SkIcoCodec.cpp",
      "//third_party/skia/src/codec/SkJpegCodec.cpp",
      "//third_party/skia/src/codec/SkJpegDecoderMgr.cpp",
      "//third_party/skia/src/codec/SkJpegMetadataDecoderImpl.cpp",
      "//third_party/skia/src/codec/SkJpegMultiPicture.cpp",
      "//third_party/skia/src/codec/SkJpegSegmentScan.cpp",
      "//third_party/skia/src/codec/SkJpegSourceMgr.cpp",
      "//third_party/skia/src/codec/SkJpegUtility.cpp",
      "//third_party/skia/src/codec/SkWebpCodec.cpp",
      "//third_party/skia/src/codec/SkWuffsCodec.cpp",
    ]
    deps += [ "//third_party/wuffs" ]
  } else {
    sources += skia_no_encode_jpeg_srcs
  }

  if (skia_support_xmp) {
    sources += skia_xml_sources
    sources += skia_codec_xmp
    sources += skia_codec_jpeg_xmp
    deps += [ "//third_party/expat" ]
    defines += [ "SK_CODEC_DECODES_JPEG_GAINMAPS" ]
  }

  # Remove unused util sources.
  sources -= [ "//third_party/skia/src/utils/SkParsePath.cpp" ]

  if (is_win) {
    libs = [ "fontsub.lib" ]
  }

  # Select Skia ports.

  # FreeType is needed everywhere where blink is used, on Linux and Android as main
  # font backend, on Windows and Mac as fallback backend for Variations. Pdfium
  # also uses this when decoding data out of the device cache.
  # Fontations is the backend we are migrating to. In preparation for rollout
  # default compile-in Fontations as well.
  if (use_blink) {
    # See SK_TYPEFACE_FACTORY_FREETYPE and SK_TYPEFACE_FACTORY_FONTATIONS
    if (enable_freetype) {
      sources += skia_ports_freetype_sources
      sources += skia_ports_fontmgr_custom_sources
      sources += skia_ports_fontmgr_empty_sources
      public += skia_ports_fontmgr_empty_public
    }
    sources += skia_ports_typeface_proxy_sources
    sources += skia_ports_typeface_fontations_sources

    # Fontations Rust/C++ bridge interfaces.
    deps += [
      ":bridge_rust_side",
      ":path_bridge",
    ]
  }

  if (is_win) {
    # See SK_TYPEFACE_FACTORY_DIRECTWRITE
    sources += skia_ports_windows_fonts_sources
    sources += skia_ports_windows_sources
  } else {
    sources += [ "//third_party/skia/src/ports/SkOSFile_posix.cpp" ]
  }

  if (is_apple) {
    # See SK_TYPEFACE_FACTORY_CORETEXT
    public += skia_ports_fontmgr_coretext_public
    sources += skia_ports_fontmgr_coretext_sources
  }

  if (is_linux || is_chromeos) {
    public += skia_ports_fci_public
    sources += skia_ports_fci_sources
  }

  if (is_linux || is_chromeos || is_android) {
    # Retain the files for the SkFontMgr_Android on linux to emulate android
    # fonts. See content/zygote/zygote_main_linux.cc
    # Note that this requires expat.
    sources += skia_ports_fontmgr_android_sources
  }

  if (is_fuchsia) {
    public += skia_ports_fontmgr_fuchsia_public
    sources += skia_ports_fontmgr_fuchsia_sources

    # This is already here if use_blink is set
    if (!use_blink) {
      sources += skia_ports_fontmgr_custom_sources
    }
    deps += [
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_hlcpp",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
      "//third_party/fuchsia-sdk/sdk/pkg/zx",
      "//third_party/icu:icuuc",
    ]
  }

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    ":skia_config",
    ":skia_library_config",
    "//build/config/compiler:no_chromium_code",
  ]
  all_dependent_configs = [ ":skia_config" ]

  deps += [
    ":skcms",
    ":skia_opts",
    ":skia_switches",
    "//base",
    "//third_party/libpng",
    "//third_party/libwebp",
    "//third_party/libwebp:libwebp_webp",
    "//ui/base:features",
  ]
  public_deps = [
    ":buildflags",
    ":skia_core_and_effects",
    ":skia_core_public_headers",
  ]

  if (use_blink) {
    deps += [
      "//build/config/freetype",
      "//third_party:jpeg",
    ]
  }

  if (is_linux || is_chromeos) {
    deps += [
      "//third_party/expat",
      "//third_party/fontconfig",
      "//third_party/icu:icuuc",
    ]
  }

  if (is_android) {
    deps += [
      "//third_party/cpu_features:ndk_compat",
      "//third_party/expat",
    ]
  }

  if (!is_debug) {
    configs -= [ "//build/config/compiler:default_optimization" ]
    configs += [ "//build/config/compiler:optimize_max" ]
  }

  frameworks = []
  if (is_ios) {
    frameworks += [ "ImageIO.framework" ]
  }
  if (is_apple && skia_support_gpu) {
    frameworks += [
      "CoreFoundation.framework",
      "CoreGraphics.framework",
      "CoreText.framework",
      "Foundation.framework",
    ]
    if (is_mac) {
      frameworks += [ "AppKit.framework" ]
    }
    if (is_ios) {
      frameworks += [ "IOSurface.framework" ]
    }
  }

  if (is_fuchsia) {
    deps += [ "//third_party/expat" ]
  }

  if (skia_support_gpu) {
    public += skia_gpu_public
    public += skia_gpu_chromium_public
    sources += skia_ganesh_private
    sources += skia_null_gpu_sources
    sources += skia_sksl_pipeline_sources
    sources += skia_sksl_codegen_sources
    sources += skia_shared_gpu_sources
    if (skia_use_gl) {
      public += skia_gpu_gl_public
      sources += skia_gpu_gl_private
    }
    if (enable_vulkan) {
      public += skia_gpu_vk_public
      public += skia_gpu_vk_chromium_public
      sources += skia_gpu_vk_private
      sources += skia_shared_vk_sources
      sources += skia_gpu_vk_chromium_private
    }

    public_deps += [ ":skia_graphite_public" ]
    deps += [ ":skia_graphite_private" ]

    if (skia_use_metal) {
      deps += [ ":skia_ganesh_metal" ]
    }
    deps += [ "//gpu/config:workaround_list" ]
  } else {
    sources += skia_no_slug_srcs
  }

  if (skia_support_pdf) {
    # Blink includes Skia's JPEG encoder and decoder which pdf uses.
    assert(use_blink)
    deps += [
      "//third_party:freetype_harfbuzz",
      "//third_party/zlib",
    ]
    public += skia_pdf_public
    sources += skia_pdf_sources
  } else {
    sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
  }

  if (skia_support_skottie) {
    import("//third_party/skia/modules/jsonreader/jsonreader.gni")
    import("//third_party/skia/modules/skottie/skottie.gni")
    import("//third_party/skia/modules/skresources/skresources.gni")
    import("//third_party/skia/modules/sksg/sksg.gni")
    import("//third_party/skia/modules/skshaper/skshaper.gni")
    public += skia_skottie_public
    sources += skia_jsonreader_sources
    sources += skia_shaper_primitive_sources
    sources += skia_skottie_sources
    sources += skia_skresources_sources
    sources += skia_sksg_sources
    defines += [
      "SK_SHAPER_PRIMITIVE_AVAILABLE",
      "SKOTTIE_TRIVIAL_FONTRUN_ITER",
    ]
  }

  if (enable_rust_png) {
    deps += [ ":rust_png_ffi" ]
    public += skia_codec_rust_png_public
    sources += skia_codec_rust_png
    public += skia_encode_rust_png_public
    sources += skia_encode_rust_png_srcs
  }
}

component("skia_switches") {
  sources = [
    "ext/switches.cc",
    "ext/switches.h",
    "ext/switches_export.h",
  ]

  defines = [ "SKIA_SWITCHES_IMPLEMENTATION" ]

  deps = [ "//base" ]
}

if (enable_rust_png) {
  rust_static_library("rust_png_ffi") {
    visibility = [ ":*" ]
    allow_unsafe = true  # For FFI
    crate_root = skia_codec_rust_png_ffi_crate_root
    sources = skia_codec_rust_png_ffi_rs_srcs
    cxx_bindings = skia_codec_rust_png_ffi_cxx_bridge_srcs
    public_deps = [ ":rust_png_ffi_cpp" ]
    deps = [ "//third_party/rust/png/v0_17:lib" ]
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      ":skia_config",
      "//build/config/compiler:no_chromium_code",
    ]
  }

  source_set("rust_png_ffi_cpp") {
    visibility = [ ":*" ]
    public = skia_codec_rust_png_ffi_cpp_hdrs
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      ":skia_config",
      "//build/config/compiler:no_chromium_code",
    ]
  }
}

# Template for things that are logically part of :skia, but need to be split out
# so custom compile flags can be applied.
#
# These are all opted out of check_includes, due to (logically) being part of
# skia.
template("skia_source_set") {
  source_set(target_name) {
    forward_variables_from(invoker, "*")

    check_includes = false

    if (!is_debug) {
      configs -= [ "//build/config/compiler:default_optimization" ]
      configs += [ "//build/config/compiler:optimize_max" ]
    }

    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [
      ":skia_config",
      ":skia_library_config",
      "//build/config/compiler:no_chromium_code",
    ]
    public_configs = [ ":skia_config" ]

    if (is_apple) {
      # Do not compile with ARC because Skia code is not compatible with being
      # compiled with ARC.
      configs -= [ "//build/config/compiler:enable_arc" ]
    }

    # Android, the only user of mismatched sample files (for now), gets a small
    # binary size decrease by using AFDO to optimize for size in these
    # source_sets. However, that also comes at a relatively big performance
    # cost.
    if (using_mismatched_sample_profile) {
      configs -= [ "//build/config/compiler:afdo_optimize_size" ]
    }
    if (is_win) {
      cflags_cc = [
        "/wd5041",  # out-of-line definition for constexpr static data member is
                    # not needed and is deprecated in C++17
      ]
    }
  }
}

# Split out for targeted removal of the afdo_optimize_size config on Android.
skia_source_set("skia_core_and_effects") {
  defines = []
  sources = skia_core_sources
  sources += skia_colorfilters_sources
  sources += skia_effects_sources
  sources += skia_effects_imagefilter_sources
  if (skia_support_gpu) {
    deps = [ "//gpu/config:workaround_list" ]
  }
  if (skia_use_dawn) {
    # Note: This is needed as files in this target include GrDawnTypes.h, which
    # includes Dawn headers that are generated by the below target. Normally it
    # would be enough for the target that has GrDawnTypes.h in it to just have
    # cpp_headers in its public deps. However, that file is in
    # sk_gpu_dawn_public, which we add to the "skia" target, which depends on
    # skia_core_and_effects rather than the other way around.
    public_deps = [ "//third_party/dawn/include/dawn:cpp_headers" ]
  }
  if (use_blink) {
    # Fontations Rust/C++ bridge interfaces, needed by SkTypeface.
    deps += [
      ":bridge_rust_side",
      ":path_bridge",
    ]
  }
  visibility = [ ":skia" ]
}

# Bits that involve special vector-y hardware.
if (current_cpu == "x86" || current_cpu == "x64") {
  skia_source_set("skia_opts_hsw") {
    sources = skia_opts.hsw_sources
    if (!is_win) {
      cflags = [
        "-mavx2",
        "-mbmi",
        "-mbmi2",
        "-mf16c",
        "-mfma",
      ]
    } else {
      cflags = [ "/arch:AVX2" ]
    }
    visibility = [ ":skia_opts" ]
  }
}

if (current_cpu == "loong64") {
  skia_source_set("skia_opts_lasx") {
    sources = skia_opts.lasx_sources
    cflags = [
      "-mlasx",
      "-flax-vector-conversions=all",
    ]
    visibility = [ ":skia_opts" ]
  }
}

skia_source_set("skia_opts") {
  cflags = []
  defines = []

  deps = [ "//base" ]

  if (current_cpu == "x86" || current_cpu == "x64") {
    deps += [ ":skia_opts_hsw" ]
  } else if (current_cpu == "arm") {
    # The assembly uses the frame pointer register (r7 in Thumb/r11 in
    # ARM), the compiler doesn't like that.
    if (!is_ios) {
      cflags += [ "-fomit-frame-pointer" ]
    }

    if (arm_version >= 7) {
      if (arm_use_neon || arm_optionally_use_neon) {
        # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
        # when running this.
        if (!arm_use_neon) {
          configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
          cflags += [ "-mfpu=neon" ]
        }
      }
    }
  } else if (current_cpu == "arm64") {
    # Conditional and empty body needed to avoid assert() below.
  } else if (current_cpu == "mipsel") {
    cflags += [ "-fomit-frame-pointer" ]
  } else if (current_cpu == "mips64el") {
    cflags += [ "-fomit-frame-pointer" ]
  } else if (current_cpu == "ppc64") {
    # Conditional and empty body needed to avoid assert() below.
  } else if (current_cpu == "s390x") {
    # Conditional and empty body needed to avoid assert() below.
  } else if (current_cpu == "riscv64") {
    # Conditional and empty body needed to avoid assert() below.
  } else if (current_cpu == "loong64") {
    deps += [ ":skia_opts_lasx" ]
  } else {
    assert(false, "Unknown cpu target")
  }

  visibility = [ ":skia" ]
}

if (current_cpu == "x64") {
  skia_source_set("skcms_TransformHsw") {
    sources = skcms_TransformHsw
    if (!is_win) {
      cflags = [
        "-w",
        "-mavx2",
        "-mf16c",
        "-std=c11",
      ]
    } else {
      cflags = [ "/arch:AVX2" ]
    }
    visibility = [ ":skcms" ]
  }
  skia_source_set("skcms_TransformSkx") {
    sources = skcms_TransformSkx
    if (!is_win) {
      cflags = [
        "-w",
        "-mavx512f",
        "-mavx512dq",
        "-mavx512cd",
        "-mavx512bw",
        "-mavx512vl",
        "-std=c11",
      ]
    } else {
      cflags = [ "/arch:AVX512" ]
    }
    visibility = [ ":skcms" ]
  }
} else {
  skia_source_set("skcms_TransformHsw") {
    sources = []
    visibility = [ ":skcms" ]
  }
  skia_source_set("skcms_TransformSkx") {
    sources = []
    visibility = [ ":skcms" ]
  }
}

source_set("skcms_TransformBaseline_and_public") {
  if (!is_win || is_clang) {
    cflags = [
      "-w",
      "-std=c11",
    ]
  } else {
    cflags = []
  }

  # LLVM automatically sets the equivalent of GCC's -mfp16-format=ieee on ARM
  # builds by default, while GCC itself does not. We need it to enable support
  # for half-precision floating point data types used by SKCMS on ARM.
  if ((is_linux || is_chromeos) && !is_clang && current_cpu == "arm") {
    cflags += [ "-mfp16-format=ieee" ]
  }
  if (current_cpu == "loong64") {
    cflags += [ "-mlsx" ]
  }

  sources = rebase_path(skcms_TransformBaseline + skcms_public,
                        ".",
                        "//third_party/skia/modules/skcms")
}

source_set("skcms") {
  deps = [
    ":skcms_TransformBaseline_and_public",
    ":skcms_TransformHsw",
    ":skcms_TransformSkx",
  ]
  public =
      rebase_path(skcms_public_headers, ".", "//third_party/skia/modules/skcms")
  include_dirs = [ "//third_party/skia/modules/skcms" ]
}

# Split out Graphite sources because of conflicting file names with Ganesh.
# Split into separate private and public source sets because we want to allow
# shared GPU code in ":skia" to include private Graphite headers, but want to
# limit external code to only depend on public headers. Only define these source
# sets when skia_support_gpu is true so that on iOS non-Blink builds, headers in
# these source sets are considered unknown and skipped by gn check.
if (skia_support_gpu) {
  skia_source_set("skia_graphite_public") {
    public = skia_graphite_public + skia_graphite_precompile_public
    if (skia_use_dawn) {
      public += skia_graphite_dawn_public
      public_deps = [
        "//third_party/dawn/include/dawn:cpp_headers",
        "//third_party/dawn/src/dawn:proc",
      ]
    }
    if (skia_use_metal) {
      public += skia_graphite_mtl_public
      frameworks = [ "Metal.framework" ]
    }
    deps = [ "//gpu/config:workaround_list" ]
  }

  # If a source set contains only sources and no public files, then dependents can
  # include any file from sources.
  skia_source_set("skia_graphite_private") {
    sources = skia_graphite_sources + skia_graphite_precompile_sources +
              skia_sksl_graphite_modules_sources
    if (skia_use_dawn) {
      sources += skia_graphite_dawn_sources
    }
    if (skia_use_metal) {
      sources += skia_shared_mtl_sources
      sources += skia_graphite_mtl_sources
    }
    deps = [ "//gpu/config:workaround_list" ]
    if (skia_use_dawn) {
      deps += [ "//third_party/dawn/include/dawn:cpp_headers" ]
    }
    visibility = [ ":skia" ]
  }

  if (skia_use_metal) {
    # Split out Ganesh Metal sources, because they require ARC.
    skia_source_set("skia_ganesh_metal") {
      sources = skia_gpu_metal_public
      sources += skia_gpu_metal_private
      cflags_objcc = [
        "-Wno-unguarded-availability",
        "-fobjc-arc",
      ]
      deps = [ "//gpu/config:workaround_list" ]
      if (skia_use_dawn) {
        # Needed due to include chain containing webgpu_cpp.h via GrDawnTypes.h.
        public_deps = [ "//third_party/dawn/include/dawn:cpp_headers" ]
      }
      visibility = [ ":skia" ]
    }
  }
}

# Font copies.
if (is_fuchsia) {
  copy("copy_fuchsia_fonts_manifest") {
    sources = [ "ext/data/test_fonts/fuchsia_test_fonts_manifest.json" ]
    outputs = [ "$root_out_dir/test_fonts/all.font_manifest.json" ]
  }
}
if (is_apple) {
  bundle_data("test_fonts_bundle_data") {
    public_deps = [ "//third_party/test_fonts" ]

    sources = [
      "$root_out_dir/test_fonts/Ahem.ttf",
      "ext/data/test_fonts/ChromiumAATTest.ttf",
    ]

    outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
  }
}

group("test_fonts_resources") {
  testonly = true
  deps = []
  data_deps = []

  if (is_apple) {
    deps += [ ":test_fonts_bundle_data" ]
    data_deps += [ ":test_fonts_bundle_data" ]
  } else {
    deps += [ "//third_party/test_fonts" ]
    data_deps += [ "//third_party/test_fonts" ]
  }

  if (is_fuchsia) {
    deps += [ ":copy_fuchsia_fonts_manifest" ]
    data_deps += [ ":copy_fuchsia_fonts_manifest" ]
  }
}

# Fuchsia components that use the test fonts must include
# "//build/config/fuchsia/test/test_fonts.shard.test-cml" in their
# `additional_manifest_fragments`.
source_set("test_fonts") {
  testonly = true

  deps = [ ":test_fonts_resources" ]

  if (is_fuchsia) {
    public = [
      "ext/test_fonts.h",
      "ext/test_fonts_fuchsia.h",
    ]
    sources = [
      "ext/test_fonts_fuchsia.cc",
      "ext/test_fonts_fuchsia_cfv2.cc",
    ]
    public_deps = [
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
    ]
    deps += [
      "//base",
      "//skia",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
    ]
  }
  if (is_apple) {
    public = [ "ext/test_fonts.h" ]
    sources = [ "ext/test_fonts_mac.mm" ]
    deps += [ "//base" ]
  }
}

test("skia_unittests") {
  sources = [
    "ext/codec_utils_unittest.cc",
    "ext/convolver_unittest.cc",
    "ext/geometry_unittest.cc",
    "ext/image_operations_unittest.cc",
    "ext/platform_canvas_unittest.cc",
    "ext/recursive_gaussian_convolution_unittest.cc",
    "ext/skcolorspace_primaries_unittest.cc",
    "ext/skcolorspace_trfn_unittest.cc",
    "ext/skia_memory_dump_provider_unittest.cc",
    "ext/skia_utils_base_unittest.cc",
  ]
  if (is_ios) {
    sources += [ "ext/skia_utils_ios_unittest.mm" ]
  }
  if (is_mac) {
    sources += [ "ext/skia_utils_mac_unittest.mm" ]
  }

  if (!is_win) {
    sources -= [ "ext/platform_canvas_unittest.cc" ]
  }

  deps = [
    ":skcms",
    ":skia",
    ":test_fonts",
    "//base",
    "//base/test:test_support",
    "//mojo/core/test:run_all_unittests",
    "//testing/gtest",
    "//ui/gfx",
    "//ui/gfx/geometry",
  ]

  data_deps = [ "//testing/buildbot/filters:skia_unittests_filters" ]

  if (!is_ios) {
    sources += [ "public/mojom/test/mojom_traits_unittest.cc" ]
    deps += [
      "//mojo/public/cpp/bindings",
      "//mojo/public/cpp/test_support:test_utils",
      "//skia/public/mojom",
    ]
  }

  if (is_fuchsia) {
    sources += [ "ext/fontmgr_fuchsia_unittest.cc" ]
    deps += [
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
    ]
    additional_manifest_fragments =
        [ "//build/config/fuchsia/test/test_fonts.shard.test-cml" ]
  }

  if (skia_support_skottie) {
    sources += [ "ext/skottie_unittest.cc" ]
  }
}

if (!is_ios) {
  executable("image_operations_bench") {
    sources = [ "ext/image_operations_bench.cc" ]

    deps = [
      ":skia",
      "//base",
      "//build/win:default_exe_manifest",
    ]
  }

  executable("filter_fuzz_stub") {
    testonly = true
    sources = [ "tools/filter_fuzz_stub/filter_fuzz_stub.cc" ]

    deps = [
      ":skia",
      "//base",
      "//base/test:test_support",
      "//build/win:default_exe_manifest",
    ]
  }
}

group("fuzzers") {
  deps = [ "//skia/tools/fuzzers" ]
}