1# Copyright 2013 The PDFium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/features.gni") 6import("//build/config/freetype/freetype.gni") 7import("//build/config/ui.gni") 8import("//testing/test.gni") 9import("//third_party/skia/gn/codec.gni") 10import("//third_party/skia/gn/shared_sources.gni") 11import("//third_party/skia/modules/skcms/skcms.gni") 12import("../pdfium.gni") 13import("features.gni") 14 15if (current_cpu == "arm") { 16 import("//build/config/arm.gni") 17} 18if (current_cpu == "mipsel" || current_cpu == "mips64el") { 19 import("//build/config/mips.gni") 20} 21 22if (pdf_enable_fontations) { 23 import("//build/rust/rust_static_library.gni") 24} 25 26skia_use_ganesh_backend = !is_ios 27skia_support_pdf = false 28 29if (pdf_enable_fontations) { 30 source_set("path_bridge") { 31 sources = [ "//third_party/skia/src/ports/fontations/src/skpath_bridge.h" ] 32 } 33 34 rust_static_library("bridge_rust_side") { 35 allow_unsafe = true 36 crate_root = "//third_party/skia/src/ports/fontations/src/ffi.rs" 37 sources = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ] 38 cxx_bindings = [ "//third_party/skia/src/ports/fontations/src/ffi.rs" ] 39 deps = [ 40 ":path_bridge", 41 "//third_party/rust/font_types/v0_7:lib", 42 "//third_party/rust/read_fonts/v0_22:lib", 43 "//third_party/rust/skrifa/v0_22:lib", 44 ] 45 configs -= [ "//build/config/compiler:chromium_code" ] 46 configs += [ 47 ":skia_config", 48 "//build/config/compiler:no_chromium_code", 49 ] 50 } 51} 52 53# External-facing config for dependent code. 54config("skia_config") { 55 include_dirs = [ "//third_party/skia" ] 56 57 defines = [ 58 "SK_ENCODE_PNG", 59 "SK_USER_CONFIG_HEADER=\"../../skia/config/SkPdfiumUserConfig.h\"", 60 "SK_DISABLE_LEGACY_SKSURFACE_METHODS", 61 "SK_DISABLE_LEGACY_GRAPHITE_IMAGE_FACTORIES", 62 "SK_DISABLE_LEGACY_GRAPHITE_IMAGE_METHODS", 63 "SK_DISABLE_LEGACY_SKSURFACE_FACTORIES", 64 "SK_DISABLE_LEGACY_SKSURFACE_FLUSH", 65 "SK_DISABLE_LEGACY_SKSURFACE_AS_IMAGE", 66 "SK_DISABLE_LEGACY_SKSURFACE_DISPLAYLIST", 67 "SK_DISABLE_LEGACY_IMAGE_SUBSET_METHODS", 68 "SK_DISABLE_LEGACY_IMAGE_COLORSPACE_METHODS", 69 "SK_DISABLE_LEGACY_IMAGE_RELEASE_PROCS", 70 "SK_DISABLE_LEGACY_GL_BACKEND_SURFACE", 71 "SK_DISABLE_LEGACY_INIT_DECODERS", 72 "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_FLUSH", 73 "SK_DISABLE_LEGACY_GRDIRECTCONTEXT_BOOLS", 74 "SK_DISABLE_LEGACY_GL_GRDIRECTCONTEXT_FACTORIES", 75 "SK_DISABLE_LEGACY_PNG_WRITEBUFFER", 76 "SK_SLUG_DISABLE_LEGACY_DESERIALIZE", 77 "SK_DISABLE_LEGACY_VK_GRDIRECTCONTEXT_FACTORIES", 78 ] 79 80 if (is_win) { 81 defines += [ "SK_FREETYPE_MINIMUM_RUNTIME_VERSION=(((FREETYPE_MAJOR) * 0x01000000) | ((FREETYPE_MINOR) * 0x00010000) | ((FREETYPE_PATCH) * 0x00000100))" ] 82 } 83 84 if (is_component_build) { 85 defines += [ 86 "SKIA_DLL", 87 "GR_GL_IGNORE_ES3_MSAA=0", 88 ] 89 } 90 91 if (skia_use_ganesh_backend) { 92 defines += [ "SK_GANESH" ] 93 } 94 95 if (skia_use_gl) { 96 defines += [ "SK_GL" ] 97 } 98 99 if (is_android) { 100 defines += [ 101 "SK_BUILD_FOR_ANDROID", 102 "USE_CHROMIUM_SKIA", 103 ] 104 } 105 106 if (is_mac) { 107 defines += [ "SK_BUILD_FOR_MAC" ] 108 } 109 110 if (is_win) { 111 defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ] 112 } 113 114 if (pdf_enable_fontations) { 115 include_dirs += [ "$root_gen_dir/third_party/skia" ] 116 } 117} 118 119# Internal-facing config for Skia library code. 120config("skia_library_config") { 121 # Turn on SK_API to export Skia's public API 122 defines = [ 123 "IS_SKIA_IMPL=1", 124 "SKIA_IMPLEMENTATION=1", 125 ] 126 127 if (use_blink && !use_system_freetype) { 128 defines += [ "SK_FREETYPE_MINIMUM_RUNTIME_VERSION=(((FREETYPE_MAJOR) * 0x01000000) | ((FREETYPE_MINOR) * 0x00010000) | ((FREETYPE_PATCH) * 0x00000100))" ] 129 } 130 if (use_blink) { 131 defines += [ "SK_TYPEFACE_FACTORY_FREETYPE" ] 132 } 133 if (is_win) { 134 defines += [ "SK_TYPEFACE_FACTORY_DIRECTWRITE" ] 135 } 136 if (is_apple) { 137 defines += [ "SK_TYPEFACE_FACTORY_CORETEXT" ] 138 } 139 140 if (current_cpu == "arm") { 141 if (arm_use_neon) { 142 defines += [ "SK_ARM_HAS_NEON" ] 143 } else if (arm_optionally_use_neon) { 144 defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ] 145 } 146 } 147 148 # Settings for text blitting, chosen to approximate the system browser. 149 if (is_linux || is_chromeos) { 150 defines += [ 151 "SK_GAMMA_EXPONENT=1.2", 152 "SK_GAMMA_CONTRAST=0.2", 153 ] 154 } else if (is_android) { 155 defines += [ 156 "SK_GAMMA_APPLY_TO_A8", 157 "SK_GAMMA_EXPONENT=1.4", 158 "SK_GAMMA_CONTRAST=0.0", 159 ] 160 } else if (is_win) { 161 defines += [ 162 "SK_GAMMA_SRGB", 163 "SK_GAMMA_CONTRAST=0.5", 164 ] 165 } else if (is_mac) { 166 defines += [ 167 "SK_GAMMA_SRGB", 168 "SK_GAMMA_CONTRAST=0.0", 169 ] 170 } 171 172 if (is_android) { 173 defines += [ 174 # Android devices are typically more memory constrained, so default to a 175 # smaller glyph cache (it may be overriden at runtime when the renderer 176 # starts up, depending on the actual device memory). 177 "SK_DEFAULT_FONT_CACHE_LIMIT=1048576", # 1024 * 1024 178 ] 179 } else { 180 defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ] # 20 * 1024 * 1024 181 } 182 183 if (is_win) { 184 defines += [ 185 # On windows, GDI handles are a scarse system-wide resource so we have to 186 # keep the glyph cache, which holds up to 4 GDI handles per entry, to a 187 # fairly small size. http://crbug.com/314387 188 "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256", 189 ] 190 191 cflags = [ 192 "/wd4244", # conversion from 'type1( __int64)' to 'type2 (unsigned int)' 193 "/wd4341", # signed value is out of range for enum constant. 194 "/wd4345", # Object is default-initialized if initialization is omitted. 195 "/wd4390", # ';'empty statement found in looping;is it what was intended? 196 "/wd4554", # 'operator' : check operator precedence for possible error 197 "/wd4748", # compiler will disable optimizations if a function has inline 198 # assembly code contains flow control(jmp or jcc) statements. 199 200 "/wd4800", # forcing value to bool 'true/false'(assigning int to bool). 201 "/wd5041", # out-of-line definition for constexpr static data member is 202 # not needed and is deprecated in C++17 203 ] 204 } 205} 206 207component("skia") { 208 deps = [] 209 210 sources = [ 211 # PDFium sources. 212 "config/SkPdfiumUserConfig.h", 213 "ext/google_logging.cc", 214 ] 215 216 # The skia sources values are relative to the skia_dir, so we need to rebase. 217 sources += skia_core_public 218 sources += skia_sksl_pipeline_sources 219 sources += skia_sksl_codegen_sources 220 sources += skia_sksl_core_sources 221 sources += skia_sksl_default_module_sources 222 sources += skia_utils_private 223 sources += skia_xps_sources 224 sources += skia_codec_decode_bmp 225 sources += skia_codec_png 226 sources += skia_codec_shared 227 sources += skia_encode_srcs 228 sources += skia_encode_png_srcs 229 sources += skia_ports_sources 230 sources += [ 231 "//third_party/skia/src/ports/SkImageGenerator_none.cpp", 232 "//third_party/skia/src/sfnt/SkOTTable_name.cpp", 233 "//third_party/skia/src/sfnt/SkOTUtils.cpp", 234 235 #pdfium 236 "//third_party/skia/src/ports/SkDiscardableMemory_none.cpp", 237 "//third_party/skia/src/ports/SkMemory_malloc.cpp", 238 ] 239 240 # This and skia_opts are really the same conceptual target so share headers. 241 allow_circular_includes_from = [ ":skia_opts" ] 242 243 # GPU 244 if (skia_use_ganesh_backend) { 245 sources += skia_gpu_public 246 sources += skia_ganesh_private 247 sources += skia_null_gpu_sources 248 sources += skia_shared_gpu_sources 249 if (skia_use_gl) { 250 sources += skia_gpu_gl_public 251 sources += skia_gpu_gl_private 252 } 253 } 254 255 # Remove unused util files include in utils.gni 256 sources -= [ 257 "//third_party/skia/src/utils/SkCamera.cpp", 258 "//third_party/skia/src/utils/SkParsePath.cpp", 259 ] 260 261 if (is_win) { 262 libs = [ "fontsub.lib" ] 263 } 264 265 # need separate win section to handle chromes auto gn filter 266 # (build/config/BUILDCONFIG.gn) 267 if (is_win) { 268 sources -= [ 269 #windows 270 "//third_party/skia/src/utils/win/SkWGL_win.cpp", 271 ] 272 } 273 274 # Select Skia ports. 275 276 # FreeType is needed everywhere (except on iOS), on Linux and Android as main 277 # font backend, on Windows and Mac as fallback backend for Variations. 278 if (!is_ios) { 279 sources += [ 280 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp", 281 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp", 282 ] 283 } 284 285 if (is_win) { 286 # See SK_TYPEFACE_FACTORY_DIRECTWRITE 287 sources += skia_ports_windows_fonts_sources 288 sources += skia_ports_windows_sources 289 } else { 290 sources += [ "//third_party/skia/src/ports/SkOSFile_posix.cpp" ] 291 } 292 293 frameworks = [] 294 if (is_apple) { 295 # See SK_TYPEFACE_FACTORY_CORETEXT 296 sources += [ 297 "//third_party/skia/include/ports/SkFontMgr_mac_ct.h", 298 "//third_party/skia/src/ports/SkFontMgr_mac_ct.cpp", 299 "//third_party/skia/src/ports/SkScalerContext_mac_ct.cpp", 300 "//third_party/skia/src/ports/SkScalerContext_mac_ct.h", 301 "//third_party/skia/src/ports/SkTypeface_mac_ct.cpp", 302 "//third_party/skia/src/ports/SkTypeface_mac_ct.h", 303 ] 304 frameworks += [ 305 "CoreFoundation.framework", 306 "CoreGraphics.framework", 307 "CoreText.framework", 308 ] 309 } 310 311 if (is_linux || is_chromeos) { 312 sources += [ 313 "//third_party/skia/src/ports/SkFontConfigInterface.cpp", 314 "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp", 315 "//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp", 316 "//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp", 317 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 318 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 319 ] 320 } 321 322 if (is_android) { 323 sources += [ 324 # Unlike Chromium, standalone PDFium on Linux and Chrome OS does not 325 # require these files, since PDFium does not perform Android emulation. 326 # Note that this requires expat. 327 "//third_party/skia/src/ports/SkFontMgr_android.cpp", 328 "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp", 329 "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp", 330 ] 331 } 332 333 if (is_win || (is_apple && use_blink)) { 334 sources += [ 335 # Add the FreeType custom font manager as a fallback backend for variable fonts. 336 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 337 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 338 ] 339 } 340 341 if (pdf_enable_fontations) { 342 sources += [ 343 "//third_party/skia/src/ports/SkTypeface_fontations.cpp", 344 "//third_party/skia/src/ports/SkTypeface_fontations_priv.h", 345 ] 346 347 # Fontations Rust/C++ bridge interfaces. 348 deps += [ 349 ":bridge_rust_side", 350 ":path_bridge", 351 ] 352 } 353 354 if (is_clang && !is_nacl) { 355 # Skia won't compile with some of the more strict clang warnings. 356 # e.g. it does: 357 # SkASSERT(!"sk_out_of_memory"); 358 configs -= [ "//build/config/clang:extra_warnings" ] 359 } 360 361 configs -= [ "//build/config/compiler:chromium_code" ] 362 configs += [ 363 ":skia_config", 364 ":skia_library_config", 365 "//build/config/compiler:no_chromium_code", 366 ] 367 public_configs = [ ":skia_config" ] 368 369 deps += [ 370 ":skcms", 371 ":skia_opts", 372 "../third_party:png", 373 "../third_party:zlib", 374 "//:freetype_common", 375 ] 376 public_deps = [ ":skia_core_and_effects" ] 377 378 if (is_linux || is_chromeos) { 379 deps += [ 380 "//third_party:fontconfig", 381 "//third_party/icu:icuuc", 382 ] 383 } 384 385 if (is_android) { 386 deps += [ 387 "//third_party/cpu_features:ndk_compat", 388 "//third_party/expat", 389 ] 390 } 391 392 if (is_android && !is_debug) { 393 configs -= [ "//build/config/compiler:default_optimization" ] 394 configs += [ "//build/config/compiler:optimize_max" ] 395 } 396 397 if (is_ios) { 398 frameworks += [ "ImageIO.framework" ] 399 } 400 401 if (skia_support_pdf) { 402 sources += skia_pdf_sources 403 } else { 404 sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ] 405 } 406} 407 408# Template for things that are logically part of :skia, but need to be split out 409# so custom compile flags can be applied. 410# 411# These are all opted out of check_includes, due to (logically) being part of 412# skia. 413template("skia_source_set") { 414 source_set(target_name) { 415 forward_variables_from(invoker, "*") 416 417 check_includes = false 418 419 if (!is_debug) { 420 configs -= [ "//build/config/compiler:default_optimization" ] 421 configs += [ "//build/config/compiler:optimize_max" ] 422 } 423 424 configs -= [ "//build/config/compiler:chromium_code" ] 425 configs += [ 426 ":skia_config", 427 ":skia_library_config", 428 "//build/config/compiler:no_chromium_code", 429 ] 430 public_configs = [ ":skia_config" ] 431 432 if (is_win) { 433 cflags_cc = [ 434 "/wd5041", # out-of-line definition for constexpr static data member is 435 # not needed and is deprecated in C++17 436 ] 437 } 438 } 439} 440 441skia_source_set("skia_core_and_effects") { 442 defines = [] 443 sources = skia_core_sources 444 sources += skia_effects_sources 445 sources += skia_colorfilters_sources 446 sources += skia_effects_imagefilter_sources 447 448 visibility = [ ":skia" ] 449} 450 451# Bits that involve special vector-y hardware. 452if (current_cpu == "x86" || current_cpu == "x64") { 453 skia_source_set("skia_opts_hsw") { 454 sources = skia_opts.hsw_sources 455 if (!is_win) { 456 cflags = [ 457 "-mavx2", 458 "-mbmi", 459 "-mbmi2", 460 "-mf16c", 461 "-mfma", 462 ] 463 } 464 if (is_win) { 465 cflags = [ "/arch:AVX2" ] 466 } 467 visibility = [ ":skia_opts" ] 468 } 469} 470 471skia_source_set("skia_opts") { 472 cflags = [] 473 defines = [] 474 475 if (current_cpu == "x86" || current_cpu == "x64") { 476 deps = [ ":skia_opts_hsw" ] 477 } else if (current_cpu == "arm") { 478 # The assembly uses the frame pointer register (r7 in Thumb/r11 in 479 # ARM), the compiler doesn't like that. 480 cflags += [ "-fomit-frame-pointer" ] 481 482 if (arm_version >= 7) { 483 if (arm_use_neon || arm_optionally_use_neon) { 484 # Root build config sets -mfpu=$arm_fpu, which we expect to be neon 485 # when running this. 486 if (!arm_use_neon) { 487 configs -= [ "//build/config/compiler:compiler_arm_fpu" ] 488 cflags += [ "-mfpu=neon" ] 489 } 490 } 491 } 492 } else if (current_cpu == "arm64") { 493 # Conditional and empty body needed to avoid assert below 494 } else if (current_cpu == "mipsel" || current_cpu == "mips64el") { 495 cflags += [ "-fomit-frame-pointer" ] 496 } else { 497 assert(false, "Unsupported target CPU " + current_cpu) 498 } 499 500 if (is_android && !is_debug) { 501 configs -= [ "//build/config/compiler:default_optimization" ] 502 configs += [ "//build/config/compiler:optimize_max" ] 503 } 504 505 visibility = [ ":skia" ] 506} 507 508if (current_cpu == "x64") { 509 skia_source_set("skcms_TransformHsw") { 510 sources = skcms_TransformHsw 511 if (!is_win) { 512 cflags = [ 513 "-w", 514 "-march=haswell", 515 "-std=c11", 516 ] 517 } else { 518 cflags = [ "/arch:AVX2" ] 519 } 520 visibility = [ ":skcms" ] 521 } 522 skia_source_set("skcms_TransformSkx") { 523 sources = skcms_TransformSkx 524 if (!is_win) { 525 cflags = [ 526 "-w", 527 "-march=skylake-avx512", 528 "-std=c11", 529 ] 530 } else { 531 cflags = [ "/arch:AVX512" ] 532 } 533 visibility = [ ":skcms" ] 534 } 535} else { 536 skia_source_set("skcms_TransformHsw") { 537 sources = [] 538 visibility = [ ":skcms" ] 539 } 540 skia_source_set("skcms_TransformSkx") { 541 sources = [] 542 visibility = [ ":skcms" ] 543 } 544} 545 546source_set("skcms_TransformBaseline_and_public") { 547 if (!is_win || is_clang) { 548 cflags = [ 549 "-w", 550 "-std=c11", 551 ] 552 } else { 553 cflags = [] 554 } 555 556 # LLVM automatically sets the equivalent of GCC's -mfp16-format=ieee on ARM 557 # builds by default, while GCC itself does not. We need it to enable support 558 # for half-precision floating point data types used by SKCMS on ARM. 559 if ((is_linux || is_chromeos) && !is_clang && current_cpu == "arm") { 560 cflags += [ "-mfp16-format=ieee" ] 561 } 562 563 sources = rebase_path(skcms_TransformBaseline + skcms_public, 564 ".", 565 "//third_party/skia/modules/skcms") 566} 567 568source_set("skcms") { 569 deps = [ 570 ":skcms_TransformBaseline_and_public", 571 ":skcms_TransformHsw", 572 ":skcms_TransformSkx", 573 ] 574 public = 575 rebase_path(skcms_public_headers, ".", "//third_party/skia/modules/skcms") 576 include_dirs = [ "//third_party/skia/modules/skcms" ] 577} 578