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