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_private 177 sources += skia_xps_sources 178 sources += skia_needs_sksl_sources 179 sources += skia_codec_core 180 sources += skia_codec_decode_bmp 181 sources += skia_encode_srcs 182 sources += skia_encode_png_srcs 183 sources += [ 184 "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp", 185 "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp", 186 "//third_party/skia/src/ports/SkGlobalInitialization_default.cpp", 187 "//third_party/skia/src/ports/SkImageGenerator_none.cpp", 188 "//third_party/skia/src/ports/SkOSFile_stdio.cpp", 189 "//third_party/skia/src/sfnt/SkOTTable_name.cpp", 190 "//third_party/skia/src/sfnt/SkOTUtils.cpp", 191 192 #pdfium 193 "//third_party/skia/src/ports/SkDiscardableMemory_none.cpp", 194 "//third_party/skia/src/ports/SkMemory_malloc.cpp", 195 ] 196 197 # This and skia_opts are really the same conceptual target so share headers. 198 allow_circular_includes_from = [ ":skia_opts" ] 199 200 # GPU 201 if (skia_use_ganesh_backend) { 202 sources += skia_gpu_public 203 sources += skia_ganesh_private 204 sources += skia_null_gpu_sources 205 sources += skia_shared_gpu_sources 206 if (skia_use_gl) { 207 sources += skia_gpu_gl_public 208 sources += skia_gpu_gl_private 209 } 210 } 211 212 # Remove unused util files include in utils.gni 213 sources -= [ 214 "//third_party/skia/src/utils/SkCamera.cpp", 215 "//third_party/skia/src/utils/SkParsePath.cpp", 216 ] 217 218 if (is_win) { 219 libs = [ "fontsub.lib" ] 220 } 221 222 # need separate win section to handle chromes auto gn filter 223 # (build/config/BUILDCONFIG.gn) 224 if (is_win) { 225 sources -= [ 226 #windows 227 "//third_party/skia/src/utils/win/SkWGL_win.cpp", 228 ] 229 } 230 231 # Select Skia ports. 232 233 # FreeType is needed everywhere (except on iOS), on Linux and Android as main 234 # font backend, on Windows and Mac as fallback backend for Variations. 235 if (!is_ios) { 236 sources += [ 237 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp", 238 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp", 239 ] 240 } 241 242 if (is_win) { 243 sources += [ 244 "//third_party/skia/src/ports/SkFontHost_win.cpp", 245 246 # TODO(crbug.com/pdfium/1830) Consider using SkFontMgr_win_dw_factory 247 # instead of SkFontMgr_custom_empty (which is what the embedder test 248 # hashes are based upon). 249 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 250 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 251 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp", 252 "//third_party/skia/src/ports/SkFontMgr_win_dw.cpp", 253 "//third_party/skia/src/ports/SkOSFile_win.cpp", 254 "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp", 255 "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp", 256 "//third_party/skia/src/ports/SkTypeface_win_dw.cpp", 257 ] 258 } else { 259 sources += [ "//third_party/skia/src/ports/SkOSFile_posix.cpp" ] 260 } 261 262 frameworks = [] 263 if (is_apple) { 264 sources += [ 265 # TODO(crbug.com/pdfium/1830) Consider using SkFontMgr_mac_ct instead of 266 # SkFontMgr_custom_empty (which is what the embedder test hashes are 267 # based upon). 268 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 269 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 270 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp", 271 "//third_party/skia/src/ports/SkScalerContext_mac_ct.cpp", 272 "//third_party/skia/src/ports/SkScalerContext_mac_ct.h", 273 "//third_party/skia/src/ports/SkTypeface_mac_ct.cpp", 274 "//third_party/skia/src/ports/SkTypeface_mac_ct.h", 275 ] 276 frameworks += [ 277 "CoreFoundation.framework", 278 "CoreGraphics.framework", 279 "CoreText.framework", 280 ] 281 } 282 283 if (is_linux || is_chromeos) { 284 sources += [ 285 "//third_party/skia/src/ports/SkFontConfigInterface.cpp", 286 "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp", 287 "//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp", 288 "//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp", 289 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 290 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 291 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp", 292 ] 293 } 294 295 if (is_android) { 296 sources += [ 297 # Unlike Chromium, standalone PDFium on Linux and Chrome OS does not 298 # require these files, since PDFium does not perform Android emulation. 299 # Note that this requires expat. 300 "//third_party/skia/src/ports/SkFontMgr_android.cpp", 301 "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp", 302 "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp", 303 ] 304 } 305 306 if (is_fuchsia) { 307 sources += [ 308 # TODO(crbug.com/pdfium/2019): Consider using SkFontMgr_fuchsia.cpp 309 # instead of SkFontMgr_custom_empty.cpp. 310 "//third_party/skia/src/ports/SkFontMgr_custom.cpp", 311 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp", 312 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp", 313 ] 314 deps += [ 315 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp", 316 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_hlcpp", 317 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sys:fuchsia.sys_hlcpp", 318 "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp", 319 "//third_party/fuchsia-sdk/sdk/pkg/zx", 320 "//third_party/icu:icuuc", 321 ] 322 } 323 324 if (is_clang && !is_nacl) { 325 # Skia won't compile with some of the more strict clang warnings. 326 # e.g. it does: 327 # SkASSERT(!"sk_out_of_memory"); 328 configs -= [ "//build/config/clang:extra_warnings" ] 329 } 330 331 configs -= [ "//build/config/compiler:chromium_code" ] 332 configs += [ 333 ":skia_config", 334 ":skia_library_config", 335 "//build/config/compiler:no_chromium_code", 336 ] 337 public_configs = [ ":skia_config" ] 338 339 deps += [ 340 ":skcms", 341 ":skia_opts", 342 "../third_party:png", 343 "../third_party:zlib", 344 "//:freetype_common", 345 ] 346 public_deps = [ ":skia_core_and_effects" ] 347 348 if (is_linux || is_chromeos) { 349 deps += [ 350 "//third_party:fontconfig", 351 "//third_party/icu:icuuc", 352 ] 353 } 354 355 if (is_android) { 356 deps += [ 357 "//third_party/cpu_features:ndk_compat", 358 "//third_party/expat", 359 ] 360 } 361 362 if (is_android && !is_debug) { 363 configs -= [ "//build/config/compiler:default_optimization" ] 364 configs += [ "//build/config/compiler:optimize_max" ] 365 } 366 367 if (is_ios) { 368 frameworks += [ "ImageIO.framework" ] 369 } 370 371 if (skia_support_pdf) { 372 deps += [ "//third_party/sfntly" ] 373 sources += skia_pdf_sources 374 } else { 375 sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ] 376 } 377} 378 379# Template for things that are logically part of :skia, but need to be split out 380# so custom compile flags can be applied. 381# 382# These are all opted out of check_includes, due to (logically) being part of 383# skia. 384template("skia_source_set") { 385 source_set(target_name) { 386 forward_variables_from(invoker, "*") 387 388 check_includes = false 389 390 if (!is_debug) { 391 configs -= [ "//build/config/compiler:default_optimization" ] 392 configs += [ "//build/config/compiler:optimize_max" ] 393 } 394 395 configs -= [ "//build/config/compiler:chromium_code" ] 396 configs += [ 397 ":skia_config", 398 ":skia_library_config", 399 "//build/config/compiler:no_chromium_code", 400 ] 401 public_configs = [ ":skia_config" ] 402 403 if (is_win) { 404 cflags_cc = [ 405 "/wd5041", # out-of-line definition for constexpr static data member is 406 # not needed and is deprecated in C++17 407 ] 408 } 409 } 410} 411 412skia_source_set("skia_core_and_effects") { 413 defines = [] 414 sources = skia_core_sources 415 sources += skia_effects_sources 416 sources += skia_colorfilters_sources 417 sources += skia_colorfilters_sksl_sources 418 sources += skia_effects_imagefilter_sources 419 420 visibility = [ ":skia" ] 421} 422 423# Bits that involve special vector-y hardware. 424if (current_cpu == "x86" || current_cpu == "x64") { 425 skia_source_set("skia_opts_sse3") { 426 sources = skia_opts.ssse3_sources 427 if (!is_win || is_clang) { 428 cflags = [ "-mssse3" ] 429 } 430 if (is_win) { 431 defines = [ "SK_CPU_SSE_LEVEL=31" ] 432 } 433 visibility = [ ":skia_opts" ] 434 } 435 skia_source_set("skia_opts_avx") { 436 sources = skia_opts.avx_sources 437 if (!is_win) { 438 cflags = [ "-mavx" ] 439 } 440 if (is_win) { 441 cflags = [ "/arch:AVX" ] 442 } 443 visibility = [ ":skia_opts" ] 444 } 445 skia_source_set("skia_opts_hsw") { 446 sources = skia_opts.hsw_sources 447 if (!is_win) { 448 cflags = [ 449 "-mavx2", 450 "-mbmi", 451 "-mbmi2", 452 "-mf16c", 453 "-mfma", 454 ] 455 } 456 if (is_win) { 457 cflags = [ "/arch:AVX2" ] 458 } 459 visibility = [ ":skia_opts" ] 460 } 461} 462 463skia_source_set("skia_opts") { 464 cflags = [] 465 defines = [] 466 467 if (current_cpu == "x86" || current_cpu == "x64") { 468 deps = [ 469 ":skia_opts_avx", 470 ":skia_opts_hsw", 471 ":skia_opts_sse3", 472 ] 473 } else if (current_cpu == "arm") { 474 # The assembly uses the frame pointer register (r7 in Thumb/r11 in 475 # ARM), the compiler doesn't like that. 476 cflags += [ "-fomit-frame-pointer" ] 477 478 if (arm_version >= 7) { 479 if (arm_use_neon || arm_optionally_use_neon) { 480 # Root build config sets -mfpu=$arm_fpu, which we expect to be neon 481 # when running this. 482 if (!arm_use_neon) { 483 configs -= [ "//build/config/compiler:compiler_arm_fpu" ] 484 cflags += [ "-mfpu=neon" ] 485 } 486 } 487 } 488 } else if (current_cpu == "arm64") { 489 # Conditional and empty body needed to avoid assert below 490 } else if (current_cpu == "mipsel" || current_cpu == "mips64el") { 491 cflags += [ "-fomit-frame-pointer" ] 492 } else { 493 assert(false, "Unsupported target CPU " + current_cpu) 494 } 495 496 if (is_android && !is_debug) { 497 configs -= [ "//build/config/compiler:default_optimization" ] 498 configs += [ "//build/config/compiler:optimize_max" ] 499 } 500 501 visibility = [ ":skia" ] 502} 503