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