Home | History | Annotate | Download | only in skia
      1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
      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/config/features.gni")
      6 import("//build/config/ui.gni")
      7 import("//testing/test.gni")
      8 import("//third_party/skia/gn/shared_sources.gni")
      9 
     10 if (current_cpu == "arm") {
     11   import("//build/config/arm.gni")
     12 }
     13 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
     14   import("//build/config/mips.gni")
     15 }
     16 
     17 skia_support_gpu = !is_ios
     18 skia_support_pdf = false  #!is_ios && (enable_basic_printing || enable_print_preview)
     19 
     20 # External-facing config for dependent code.
     21 config("skia_config") {
     22   include_dirs = [
     23     "config",
     24     "ext",
     25     "//third_party/skia/include/c",
     26     "//third_party/skia/include/config",
     27     "//third_party/skia/include/core",
     28     "//third_party/skia/include/effects",
     29     "//third_party/skia/include/images",
     30     "//third_party/skia/include/lazy",
     31     "//third_party/skia/include/pathops",
     32     "//third_party/skia/include/pdf",
     33     "//third_party/skia/include/pipe",
     34     "//third_party/skia/include/ports",
     35     "//third_party/skia/include/utils",
     36 
     37     # TODO(dsinclair): Right way to use //third_party/freetype?
     38     "//third_party/freetype/include",
     39   ]
     40 
     41   defines = []
     42 
     43   if (skia_support_gpu) {
     44     include_dirs += [
     45       "//third_party/skia/include/gpu",
     46       "//third_party/skia/src/gpu",
     47     ]
     48     defines += [ "SK_SUPPORT_GPU=1" ]
     49   } else {
     50     defines += [ "SK_SUPPORT_GPU=0" ]
     51   }
     52 
     53   if (is_android) {
     54     defines += [
     55       "SK_BUILD_FOR_ANDROID",
     56       "USE_CHROMIUM_SKIA",
     57     ]
     58   }
     59 
     60   if (is_mac) {
     61     defines += [ "SK_BUILD_FOR_MAC" ]
     62   }
     63 
     64   if (is_win) {
     65     defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
     66   }
     67 }
     68 
     69 # Internal-facing config for Skia library code.
     70 config("skia_library_config") {
     71   # These include directories are only included for Skia code and are not
     72   # exported to dependents. It's not clear if this is on purpose, but this
     73   # matches the GYP build.
     74   include_dirs = [
     75     "//third_party/skia/include/private",
     76     "//third_party/skia/include/client/android",
     77     "//third_party/skia/src/core",
     78     "//third_party/skia/src/image",
     79     "//third_party/skia/src/opts",
     80     "//third_party/skia/src/pdf",
     81     "//third_party/skia/src/ports",
     82     "//third_party/skia/src/sfnt",
     83     "//third_party/skia/src/sksl",
     84     "//third_party/skia/src/utils",
     85     "//third_party/skia/src/lazy",
     86   ]
     87   if (is_mac || is_ios) {
     88     include_dirs += [ "//third_party/skia/include/utils/mac" ]
     89   }
     90   if (is_mac) {
     91     include_dirs += [ "//third_party/skia/include/utils/ios" ]
     92   }
     93 
     94   defines = []
     95 
     96   if (current_cpu == "arm") {
     97     if (arm_use_neon) {
     98       defines += [ "SK_ARM_HAS_NEON" ]
     99     } else if (arm_optionally_use_neon) {
    100       defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
    101     }
    102   }
    103 
    104   # Settings for text blitting, chosen to approximate the system browser.
    105   if (is_linux) {
    106     defines += [
    107       "SK_GAMMA_EXPONENT=1.2",
    108       "SK_GAMMA_CONTRAST=0.2",
    109     ]
    110   } else if (is_android) {
    111     defines += [
    112       "SK_GAMMA_APPLY_TO_A8",
    113       "SK_GAMMA_EXPONENT=1.4",
    114       "SK_GAMMA_CONTRAST=0.0",
    115     ]
    116   } else if (is_win) {
    117     defines += [
    118       "SK_GAMMA_SRGB",
    119       "SK_GAMMA_CONTRAST=0.5",
    120     ]
    121   } else if (is_mac) {
    122     defines += [
    123       "SK_GAMMA_SRGB",
    124       "SK_GAMMA_CONTRAST=0.0",
    125     ]
    126   }
    127 
    128   if (is_android) {
    129     defines += [
    130       # Android devices are typically more memory constrained, so default to a
    131       # smaller glyph cache (it may be overriden at runtime when the renderer
    132       # starts up, depending on the actual device memory).
    133       "SK_DEFAULT_FONT_CACHE_LIMIT=1048576",  # 1024 * 1024
    134     ]
    135   } else {
    136     defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
    137   }
    138 
    139   if (is_win) {
    140     include_dirs += [
    141       "//third_party/skia/include/utils/win",
    142       "//third_party/skia/src/utils/win",
    143     ]
    144 
    145     defines += [
    146       # On windows, GDI handles are a scarse system-wide resource so we have to
    147       # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
    148       # fairly small size. http://crbug.com/314387
    149       "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
    150     ]
    151 
    152     cflags = [
    153       "/wd4244",  # conversion from 'type1( __int64)' to 'type2 (unsigned int)'
    154       "/wd4267",  # conversion from 'size_t' (64 bit) to 'type'(32 bit).
    155       "/wd4341",  # signed value is out of range for enum constant.
    156       "/wd4345",  # Object is default-initialized if initialization is omitted.
    157       "/wd4390",  # ';'empty statement found in looping;is it what was intended?
    158       "/wd4554",  # 'operator' : check operator precedence for possible error
    159       "/wd4748",  # compiler will disable optimizations if a function has inline
    160                   # assembly code contains flow control(jmp or jcc) statements.
    161 
    162       "/wd4800",  # forcing value to bool 'true/false'(assigning int to bool).
    163     ]
    164   }
    165 }
    166 
    167 component("skia") {
    168   sources = [
    169     # PDFium sources.
    170     "config/SkUserConfig.h",
    171     "ext/google_logging.cc",
    172   ]
    173 
    174   # The skia gypi values are relative to the skia_dir, so we need to rebase.
    175   sources += skia_core_sources
    176   sources += skia_effects_sources
    177   sources += skia_sksl_sources
    178   sources += skia_utils_sources
    179   sources += [
    180     "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp",
    181     "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp",
    182     "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
    183     "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
    184     "//third_party/skia/src/ports/SkFontHost_win.cpp",
    185     "//third_party/skia/src/ports/SkFontMgr_android.cpp",
    186     "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
    187     "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
    188     "//third_party/skia/src/ports/SkGlobalInitialization_default.cpp",
    189     "//third_party/skia/src/ports/SkImageEncoder_none.cpp",
    190     "//third_party/skia/src/ports/SkImageGenerator_none.cpp",
    191     "//third_party/skia/src/ports/SkOSFile_posix.cpp",
    192     "//third_party/skia/src/ports/SkOSFile_stdio.cpp",
    193     "//third_party/skia/src/ports/SkOSFile_win.cpp",
    194     "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
    195     "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
    196     "//third_party/skia/src/ports/SkTLS_pthread.cpp",
    197     "//third_party/skia/src/ports/SkTLS_win.cpp",
    198     "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
    199     "//third_party/skia/src/sfnt/SkOTTable_name.cpp",
    200     "//third_party/skia/src/sfnt/SkOTUtils.cpp",
    201 
    202     #mac
    203     "//third_party/skia/src/utils/mac/SkStream_mac.cpp",
    204 
    205     #pdfium
    206     "//third_party/skia/src/ports/SkDiscardableMemory_none.cpp",
    207     "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
    208     "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
    209     "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
    210     "//third_party/skia/src/ports/SkMemory_malloc.cpp",
    211   ]
    212 
    213   # This and skia_opts are really the same conceptual target so share headers.
    214   allow_circular_includes_from = [ ":skia_opts" ]
    215 
    216   if (current_cpu == "arm") {
    217     sources += [ "//third_party/skia/src/core/SkUtilsArm.cpp" ]
    218   }
    219 
    220   # GPU
    221   if (skia_support_gpu) {
    222     sources += skia_gpu_sources
    223     sources += skia_null_gpu_sources
    224   }
    225 
    226   # Remove unused util files include in utils.gypi
    227   sources -= [
    228     "//third_party/skia/src/utils/SkBoundaryPatch.cpp",
    229     "//third_party/skia/src/utils/SkCamera.cpp",
    230     "//third_party/skia/src/utils/SkDumpCanvas.cpp",
    231     "//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
    232     "//third_party/skia/src/utils/SkInterpolator.cpp",
    233     "//third_party/skia/src/utils/SkMeshUtils.cpp",
    234     "//third_party/skia/src/utils/SkParsePath.cpp",
    235   ]
    236 
    237   if (is_win) {
    238     sources -= [
    239       # Keeping _win.cpp
    240       "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
    241     ]
    242   } else {
    243     sources -= [
    244       # Keeping _pthread.cpp
    245       "//third_party/skia/src/utils/SkThreadUtils_win.cpp",
    246     ]
    247   }
    248 
    249   # need separate win section to handle chromes auto gn filter
    250   # (build/config/BUILDCONFIG.gn)
    251   if (is_win) {
    252     sources -= [
    253       #windows
    254       "//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp",
    255       "//third_party/skia/src/utils/win/SkIStream.cpp",
    256       "//third_party/skia/src/utils/win/SkWGL_win.cpp",
    257     ]
    258   }
    259 
    260   # Fixup skia library sources.
    261   if (is_win) {
    262     sources -= [
    263       "//third_party/skia/src/ports/SkOSFile_posix.cpp",
    264       "//third_party/skia/src/ports/SkTLS_pthread.cpp",
    265     ]
    266   } else {
    267     sources -= [
    268       "//third_party/skia/src/ports/SkFontHost_win.cpp",
    269       "//third_party/skia/src/ports/SkOSFile_win.cpp",
    270       "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
    271       "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
    272       "//third_party/skia/src/ports/SkTLS_win.cpp",
    273       "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
    274     ]
    275   }
    276   if (!is_android) {
    277     sources -= [
    278       "//third_party/skia/src/ports/SkFontMgr_android.cpp",
    279       "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
    280       "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
    281     ]
    282   }
    283   if (!is_linux && !is_android && !is_win && !is_mac) {
    284     sources -= [
    285       "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
    286       "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
    287       "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
    288       "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
    289     ]
    290   }
    291 
    292   if (is_clang && !is_nacl) {
    293     # Skia won't compile with some of the more strict clang warnings.
    294     # e.g. it does:
    295     #  SkASSERT(!"sk_out_of_memory");
    296     configs -= [ "//build/config/clang:extra_warnings" ]
    297   }
    298 
    299   configs -= [ "//build/config/compiler:chromium_code" ]
    300   configs += [
    301     ":skia_config",
    302     ":skia_library_config",
    303     "//build/config/compiler:no_chromium_code",
    304   ]
    305   public_configs = [ ":skia_config" ]
    306 
    307   deps = [
    308     ":skia_opts",
    309     "../third_party:fx_zlib",
    310   ]
    311 
    312   if (is_linux) {
    313     deps += [ "//third_party/icu:icuuc" ]
    314   }
    315 
    316   if (is_android) {
    317     set_sources_assignment_filter([])
    318     set_sources_assignment_filter(sources_assignment_filter)
    319     deps += [
    320       "//third_party/android_tools:cpu_features",
    321       "//third_party/expat",
    322       "//third_party/freetype-android:freetype",
    323     ]
    324   }
    325 
    326   if (skia_support_pdf) {
    327     deps += [ "//third_party/sfntly" ]
    328     sources += skia_pdf_sources
    329   } else {
    330     sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
    331   }
    332 
    333   if (is_android && !is_debug) {
    334     configs -= [ "//build/config/compiler:default_optimization" ]
    335     configs += [ "//build/config/compiler:optimize_max" ]
    336   }
    337 
    338   if (is_ios) {
    339     libs = [ "ImageIO.framework" ]
    340     set_sources_assignment_filter([])
    341     sources += [
    342       "//third_party/skia/src/ports/SkFontHost_mac.cpp",
    343       "//third_party/skia/src/utils/mac/SkCreateCGImageRef.cpp",
    344       "//third_party/skia/src/utils/mac/SkStream_mac.cpp",
    345     ]
    346     set_sources_assignment_filter(sources_assignment_filter)
    347 
    348     # To disable warning "CGContextSelectFont' is deprecated"
    349     cflags = [ "-Wno-deprecated-declarations" ]
    350   }
    351 }
    352 
    353 # Separated out so it can be compiled with different flags for SSE.
    354 if (current_cpu == "x86" || current_cpu == "x64") {
    355   source_set("skia_opts_sse3") {
    356     sources = skia_opts.ssse3_sources
    357     if (!is_win || is_clang) {
    358       cflags = [ "-mssse3" ]
    359     }
    360     if (is_win) {
    361       defines = [ "SK_CPU_SSE_LEVEL=31" ]
    362     }
    363     visibility = [ ":skia_opts" ]
    364     configs -= [ "//build/config/compiler:chromium_code" ]
    365     configs += [
    366       ":skia_config",
    367       ":skia_library_config",
    368       "//build/config/compiler:no_chromium_code",
    369     ]
    370   }
    371   source_set("skia_opts_sse41") {
    372     sources = skia_opts.sse41_sources
    373     if (!is_win || is_clang) {
    374       cflags = [ "-msse4.1" ]
    375     }
    376     if (is_win) {
    377       defines = [ "SK_CPU_SSE_LEVEL=41" ]
    378     }
    379     visibility = [ ":skia_opts" ]
    380     configs -= [ "//build/config/compiler:chromium_code" ]
    381     configs += [
    382       ":skia_config",
    383       ":skia_library_config",
    384       "//build/config/compiler:no_chromium_code",
    385     ]
    386   }
    387   source_set("skia_opts_sse42") {
    388     sources = skia_opts.sse42_sources
    389     if (!is_win || is_clang) {
    390       cflags = [ "-msse4.2" ]
    391     }
    392     if (is_win) {
    393       defines = [ "SK_CPU_SSE_LEVEL=42" ]
    394     }
    395     visibility = [ ":skia_opts" ]
    396     configs -= [ "//build/config/compiler:chromium_code" ]
    397     configs += [
    398       ":skia_config",
    399       ":skia_library_config",
    400       "//build/config/compiler:no_chromium_code",
    401     ]
    402   }
    403   source_set("skia_opts_avx") {
    404     sources = skia_opts.avx_sources
    405     if (!is_win) {
    406       cflags = [ "-mavx" ]
    407     }
    408     if (is_win) {
    409       cflags = [ "/arch:AVX" ]
    410     }
    411     visibility = [ ":skia_opts" ]
    412     configs -= [ "//build/config/compiler:chromium_code" ]
    413     configs += [
    414       ":skia_config",
    415       ":skia_library_config",
    416       "//build/config/compiler:no_chromium_code",
    417     ]
    418   }
    419   source_set("skia_opts_hsw") {
    420     sources = skia_opts.hsw_sources
    421     if (!is_win) {
    422       cflags = [
    423         "-mavx2",
    424         "-mbmi",
    425         "-mbmi2",
    426         "-mf16c",
    427         "-mfma",
    428       ]
    429     }
    430     if (is_win) {
    431       cflags = [ "/arch:AVX2" ]
    432     }
    433     visibility = [ ":skia_opts" ]
    434     configs -= [ "//build/config/compiler:chromium_code" ]
    435     configs += [
    436       ":skia_config",
    437       ":skia_library_config",
    438       "//build/config/compiler:no_chromium_code",
    439     ]
    440   }
    441 }
    442 source_set("skia_opts") {
    443   cflags = []
    444   defines = []
    445 
    446   if (current_cpu == "x86" || current_cpu == "x64") {
    447     sources = skia_opts.sse2_sources
    448     deps = [
    449       ":skia_opts_avx",
    450       ":skia_opts_hsw",
    451       ":skia_opts_sse3",
    452       ":skia_opts_sse41",
    453       ":skia_opts_sse42",
    454     ]
    455   } else if (current_cpu == "arm") {
    456     # The assembly uses the frame pointer register (r7 in Thumb/r11 in
    457     # ARM), the compiler doesn't like that.
    458     cflags += [ "-fomit-frame-pointer" ]
    459 
    460     if (arm_version >= 7) {
    461       sources = skia_opts.armv7_sources
    462       if (arm_use_neon || arm_optionally_use_neon) {
    463         sources += skia_opts.neon_sources
    464 
    465         # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
    466         # when running this.
    467         if (!arm_use_neon) {
    468           configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
    469           cflags += [ "-mfpu=neon" ]
    470         }
    471       }
    472     } else {
    473       sources = skia_opts.none_sources
    474     }
    475   } else if (current_cpu == "arm64") {
    476     sources = skia_opts.arm64_sources
    477   } else if (current_cpu == "mipsel") {
    478     cflags += [ "-fomit-frame-pointer" ]
    479 
    480     if (mips_dsp_rev >= 1) {
    481       sources = skia_opts.mips_dsp_sources
    482     } else {
    483       sources = skia_opts.none_sources
    484     }
    485   } else if (current_cpu == "mips64el") {
    486     cflags += [ "-fomit-frame-pointer" ]
    487     sources = skia_opts.none_sources
    488   } else {
    489     assert(false, "Need to port cpu specific stuff from skia_library_opts.gyp")
    490   }
    491 
    492   if (is_android && !is_debug) {
    493     configs -= [ "//build/config/compiler:default_optimization" ]
    494     configs += [ "//build/config/compiler:optimize_max" ]
    495   }
    496 
    497   configs -= [ "//build/config/compiler:chromium_code" ]
    498   configs += [
    499     ":skia_config",
    500     ":skia_library_config",
    501     "//build/config/compiler:no_chromium_code",
    502   ]
    503 
    504   visibility = [ ":skia" ]
    505 }
    506