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