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