blob: 1612f17f6ec59d85eb806c49f7ac6c937c4f5eee [file] [log] [blame]
dsinclair11988d72016-05-04 10:17:00 -07001# 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")
brettw784548a2016-09-06 11:39:46 -07008import("//third_party/skia/gn/shared_sources.gni")
dsinclair11988d72016-05-04 10:17:00 -07009
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
dsinclair11988d72016-05-04 10:17:00 -070020# External-facing config for dependent code.
21config("skia_config") {
22 include_dirs = [
23 "config",
24 "ext",
25 "//third_party/skia/include/c",
Mike Reed72b82a82017-10-16 13:56:53 -040026 "//third_party/skia/include/codec",
dsinclair11988d72016-05-04 10:17:00 -070027 "//third_party/skia/include/config",
28 "//third_party/skia/include/core",
29 "//third_party/skia/include/effects",
Hal Canary5e57faa2017-06-21 09:56:46 -040030 "//third_party/skia/include/encode",
dsinclair11988d72016-05-04 10:17:00 -070031 "//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",
Cary Clarkf452f562017-04-27 16:14:47 -040038 "//third_party/skia/third_party/vulkan",
dsinclair11988d72016-05-04 10:17:00 -070039 ]
40
41 defines = []
42
dan sinclairecc3c832017-04-10 10:47:18 -040043 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
dsinclair11988d72016-05-04 10:17:00 -070054 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",
Florin Malita05f33592017-05-25 16:35:02 -040094 "//third_party/skia/src/shaders",
ethannicholas52ef14e2016-10-12 13:08:18 -070095 "//third_party/skia/src/sksl",
dsinclair11988d72016-05-04 10:17:00 -070096 "//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
dan sinclairecc3c832017-04-10 10:47:18 -0400108 if (is_component_build) {
109 defines += [ "SKIA_IMPLEMENTATION=1" ]
110 }
111
dsinclair11988d72016-05-04 10:17:00 -0700112 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 = [
thestig19ea3092016-05-13 11:24:26 -0700185 # PDFium sources.
dsinclair11988d72016-05-04 10:17:00 -0700186 "config/SkUserConfig.h",
187 "ext/google_logging.cc",
188 ]
189
Lei Zhang65a21922017-04-15 21:30:32 -0700190 # The skia sources values are relative to the skia_dir, so we need to rebase.
brettw784548a2016-09-06 11:39:46 -0700191 sources += skia_core_sources
192 sources += skia_effects_sources
ethannicholas52ef14e2016-10-12 13:08:18 -0700193 sources += skia_sksl_sources
brettw784548a2016-09-06 11:39:46 -0700194 sources += skia_utils_sources
195 sources += [
brettw784548a2016-09-06 11:39:46 -0700196 "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp",
197 "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp",
Hal Canary5e57faa2017-06-21 09:56:46 -0400198 "//third_party/skia/src/images/SkImageEncoder.cpp",
brettw784548a2016-09-06 11:39:46 -0700199 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
caryclark429a9ff2016-10-04 06:32:58 -0700200 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
brettw784548a2016-09-06 11:39:46 -0700201 "//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",
caryclark429a9ff2016-10-04 06:32:58 -0700206 "//third_party/skia/src/ports/SkImageGenerator_none.cpp",
brettw784548a2016-09-06 11:39:46 -0700207 "//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",
Ben Wanger9d5fd1d2017-02-09 11:21:11 -0500224 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
brettw784548a2016-09-06 11:39:46 -0700225 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
226 "//third_party/skia/src/ports/SkMemory_malloc.cpp",
227 ]
dsinclair11988d72016-05-04 10:17:00 -0700228
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) {
brettw784548a2016-09-06 11:39:46 -0700238 sources += skia_gpu_sources
239 sources += skia_null_gpu_sources
dsinclair11988d72016-05-04 10:17:00 -0700240 }
241
Lei Zhang65a21922017-04-15 21:30:32 -0700242 # Remove unused util files include in utils.gni
dsinclair11988d72016-05-04 10:17:00 -0700243 sources -= [
dsinclair11988d72016-05-04 10:17:00 -0700244 "//third_party/skia/src/utils/SkCamera.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700245 "//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
246 "//third_party/skia/src/utils/SkInterpolator.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700247 "//third_party/skia/src/utils/SkParsePath.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700248 ]
249
250 if (is_win) {
251 sources -= [
252 # Keeping _win.cpp
253 "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
254 ]
255 } else {
256 sources -= [
257 # Keeping _pthread.cpp
258 "//third_party/skia/src/utils/SkThreadUtils_win.cpp",
259 ]
260 }
261
262 # need separate win section to handle chromes auto gn filter
263 # (build/config/BUILDCONFIG.gn)
264 if (is_win) {
265 sources -= [
266 #windows
267 "//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp",
268 "//third_party/skia/src/utils/win/SkIStream.cpp",
269 "//third_party/skia/src/utils/win/SkWGL_win.cpp",
270 ]
271 }
272
273 # Fixup skia library sources.
274 if (is_win) {
275 sources -= [
276 "//third_party/skia/src/ports/SkOSFile_posix.cpp",
277 "//third_party/skia/src/ports/SkTLS_pthread.cpp",
278 ]
279 } else {
280 sources -= [
281 "//third_party/skia/src/ports/SkFontHost_win.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700282 "//third_party/skia/src/ports/SkOSFile_win.cpp",
283 "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
284 "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
285 "//third_party/skia/src/ports/SkTLS_win.cpp",
286 "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
287 ]
288 }
289 if (!is_android) {
290 sources -= [
291 "//third_party/skia/src/ports/SkFontMgr_android.cpp",
292 "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
293 "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
294 ]
295 }
caryclark8b301622016-07-21 06:12:33 -0700296 if (!is_linux && !is_android && !is_win && !is_mac) {
dsinclair11988d72016-05-04 10:17:00 -0700297 sources -= [
298 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
299 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
weilica0bc7d2016-06-22 07:24:20 -0700300 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
301 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700302 ]
303 }
304
305 if (is_clang && !is_nacl) {
306 # Skia won't compile with some of the more strict clang warnings.
307 # e.g. it does:
308 # SkASSERT(!"sk_out_of_memory");
309 configs -= [ "//build/config/clang:extra_warnings" ]
310 }
311
312 configs -= [ "//build/config/compiler:chromium_code" ]
313 configs += [
314 ":skia_config",
315 ":skia_library_config",
316 "//build/config/compiler:no_chromium_code",
317 ]
318 public_configs = [ ":skia_config" ]
319
320 deps = [
321 ":skia_opts",
Miklos Vajna2df760f2017-05-06 01:54:54 +0200322 "../third_party:zlib",
Lei Zhangeb39cdb2017-03-31 12:26:15 -0700323 "//:freetype_common",
dsinclair11988d72016-05-04 10:17:00 -0700324 ]
325
326 if (is_linux) {
caryclark72708b92016-06-13 06:08:25 -0700327 deps += [ "//third_party/icu:icuuc" ]
dsinclair11988d72016-05-04 10:17:00 -0700328 }
329
330 if (is_android) {
331 set_sources_assignment_filter([])
332 set_sources_assignment_filter(sources_assignment_filter)
333 deps += [
334 "//third_party/android_tools:cpu_features",
335 "//third_party/expat",
336 "//third_party/freetype-android:freetype",
337 ]
338 }
339
340 if (skia_support_pdf) {
341 deps += [ "//third_party/sfntly" ]
brettw784548a2016-09-06 11:39:46 -0700342 sources += skia_pdf_sources
dsinclair11988d72016-05-04 10:17:00 -0700343 } else {
344 sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
345 }
346
347 if (is_android && !is_debug) {
348 configs -= [ "//build/config/compiler:default_optimization" ]
349 configs += [ "//build/config/compiler:optimize_max" ]
350 }
351
352 if (is_ios) {
353 libs = [ "ImageIO.framework" ]
354 set_sources_assignment_filter([])
355 sources += [
356 "//third_party/skia/src/ports/SkFontHost_mac.cpp",
357 "//third_party/skia/src/utils/mac/SkCreateCGImageRef.cpp",
358 "//third_party/skia/src/utils/mac/SkStream_mac.cpp",
359 ]
360 set_sources_assignment_filter(sources_assignment_filter)
361
362 # To disable warning "CGContextSelectFont' is deprecated"
363 cflags = [ "-Wno-deprecated-declarations" ]
364 }
365}
366
367# Separated out so it can be compiled with different flags for SSE.
368if (current_cpu == "x86" || current_cpu == "x64") {
369 source_set("skia_opts_sse3") {
brettw784548a2016-09-06 11:39:46 -0700370 sources = skia_opts.ssse3_sources
dsinclair11988d72016-05-04 10:17:00 -0700371 if (!is_win || is_clang) {
372 cflags = [ "-mssse3" ]
373 }
374 if (is_win) {
375 defines = [ "SK_CPU_SSE_LEVEL=31" ]
376 }
377 visibility = [ ":skia_opts" ]
378 configs -= [ "//build/config/compiler:chromium_code" ]
379 configs += [
380 ":skia_config",
381 ":skia_library_config",
382 "//build/config/compiler:no_chromium_code",
383 ]
384 }
385 source_set("skia_opts_sse41") {
brettw784548a2016-09-06 11:39:46 -0700386 sources = skia_opts.sse41_sources
dsinclair11988d72016-05-04 10:17:00 -0700387 if (!is_win || is_clang) {
388 cflags = [ "-msse4.1" ]
389 }
390 if (is_win) {
391 defines = [ "SK_CPU_SSE_LEVEL=41" ]
392 }
393 visibility = [ ":skia_opts" ]
394 configs -= [ "//build/config/compiler:chromium_code" ]
395 configs += [
396 ":skia_config",
397 ":skia_library_config",
398 "//build/config/compiler:no_chromium_code",
399 ]
400 }
401 source_set("skia_opts_sse42") {
brettw784548a2016-09-06 11:39:46 -0700402 sources = skia_opts.sse42_sources
dsinclair11988d72016-05-04 10:17:00 -0700403 if (!is_win || is_clang) {
404 cflags = [ "-msse4.2" ]
405 }
406 if (is_win) {
407 defines = [ "SK_CPU_SSE_LEVEL=42" ]
408 }
409 visibility = [ ":skia_opts" ]
410 configs -= [ "//build/config/compiler:chromium_code" ]
411 configs += [
412 ":skia_config",
413 ":skia_library_config",
414 "//build/config/compiler:no_chromium_code",
415 ]
416 }
417 source_set("skia_opts_avx") {
brettw784548a2016-09-06 11:39:46 -0700418 sources = skia_opts.avx_sources
dsinclair11988d72016-05-04 10:17:00 -0700419 if (!is_win) {
420 cflags = [ "-mavx" ]
421 }
422 if (is_win) {
423 cflags = [ "/arch:AVX" ]
424 }
425 visibility = [ ":skia_opts" ]
426 configs -= [ "//build/config/compiler:chromium_code" ]
427 configs += [
428 ":skia_config",
429 ":skia_library_config",
430 "//build/config/compiler:no_chromium_code",
431 ]
432 }
caryclark429a9ff2016-10-04 06:32:58 -0700433 source_set("skia_opts_hsw") {
434 sources = skia_opts.hsw_sources
dsinclair11988d72016-05-04 10:17:00 -0700435 if (!is_win) {
caryclark429a9ff2016-10-04 06:32:58 -0700436 cflags = [
437 "-mavx2",
438 "-mbmi",
439 "-mbmi2",
440 "-mf16c",
441 "-mfma",
442 ]
dsinclair11988d72016-05-04 10:17:00 -0700443 }
444 if (is_win) {
445 cflags = [ "/arch:AVX2" ]
446 }
447 visibility = [ ":skia_opts" ]
448 configs -= [ "//build/config/compiler:chromium_code" ]
449 configs += [
450 ":skia_config",
451 ":skia_library_config",
452 "//build/config/compiler:no_chromium_code",
453 ]
454 }
455}
456source_set("skia_opts") {
457 cflags = []
458 defines = []
459
460 if (current_cpu == "x86" || current_cpu == "x64") {
brettw784548a2016-09-06 11:39:46 -0700461 sources = skia_opts.sse2_sources
dsinclair11988d72016-05-04 10:17:00 -0700462 deps = [
463 ":skia_opts_avx",
caryclark429a9ff2016-10-04 06:32:58 -0700464 ":skia_opts_hsw",
dsinclair11988d72016-05-04 10:17:00 -0700465 ":skia_opts_sse3",
466 ":skia_opts_sse41",
467 ":skia_opts_sse42",
468 ]
469 } else if (current_cpu == "arm") {
470 # The assembly uses the frame pointer register (r7 in Thumb/r11 in
471 # ARM), the compiler doesn't like that.
472 cflags += [ "-fomit-frame-pointer" ]
473
474 if (arm_version >= 7) {
brettw784548a2016-09-06 11:39:46 -0700475 sources = skia_opts.armv7_sources
dsinclair11988d72016-05-04 10:17:00 -0700476 if (arm_use_neon || arm_optionally_use_neon) {
brettw784548a2016-09-06 11:39:46 -0700477 sources += skia_opts.neon_sources
dsinclair11988d72016-05-04 10:17:00 -0700478
479 # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
480 # when running this.
481 if (!arm_use_neon) {
482 configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
483 cflags += [ "-mfpu=neon" ]
484 }
485 }
486 } else {
brettw784548a2016-09-06 11:39:46 -0700487 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700488 }
489 } else if (current_cpu == "arm64") {
brettw784548a2016-09-06 11:39:46 -0700490 sources = skia_opts.arm64_sources
dsinclair11988d72016-05-04 10:17:00 -0700491 } else if (current_cpu == "mipsel") {
492 cflags += [ "-fomit-frame-pointer" ]
493
494 if (mips_dsp_rev >= 1) {
brettw784548a2016-09-06 11:39:46 -0700495 sources = skia_opts.mips_dsp_sources
dsinclair11988d72016-05-04 10:17:00 -0700496 } else {
brettw784548a2016-09-06 11:39:46 -0700497 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700498 }
499 } else if (current_cpu == "mips64el") {
500 cflags += [ "-fomit-frame-pointer" ]
brettw784548a2016-09-06 11:39:46 -0700501 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700502 } else {
Lei Zhang65a21922017-04-15 21:30:32 -0700503 assert(false, "Need to port cpu specific stuff from gn/BUILDCONFIG.gn")
dsinclair11988d72016-05-04 10:17:00 -0700504 }
505
506 if (is_android && !is_debug) {
507 configs -= [ "//build/config/compiler:default_optimization" ]
508 configs += [ "//build/config/compiler:optimize_max" ]
509 }
510
511 configs -= [ "//build/config/compiler:chromium_code" ]
512 configs += [
513 ":skia_config",
514 ":skia_library_config",
515 "//build/config/compiler:no_chromium_code",
516 ]
517
518 visibility = [ ":skia" ]
519}