blob: 7ca7c1912612802493e87f84385dbc1270a9638c [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",
245 "//third_party/skia/src/utils/SkDumpCanvas.cpp",
246 "//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
247 "//third_party/skia/src/utils/SkInterpolator.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700248 "//third_party/skia/src/utils/SkParsePath.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700249 ]
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",
dsinclair11988d72016-05-04 10:17:00 -0700283 "//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 }
caryclark8b301622016-07-21 06:12:33 -0700297 if (!is_linux && !is_android && !is_win && !is_mac) {
dsinclair11988d72016-05-04 10:17:00 -0700298 sources -= [
299 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
300 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
weilica0bc7d2016-06-22 07:24:20 -0700301 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
302 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700303 ]
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",
Miklos Vajna2df760f2017-05-06 01:54:54 +0200323 "../third_party:zlib",
Lei Zhangeb39cdb2017-03-31 12:26:15 -0700324 "//:freetype_common",
dsinclair11988d72016-05-04 10:17:00 -0700325 ]
326
327 if (is_linux) {
caryclark72708b92016-06-13 06:08:25 -0700328 deps += [ "//third_party/icu:icuuc" ]
dsinclair11988d72016-05-04 10:17:00 -0700329 }
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" ]
brettw784548a2016-09-06 11:39:46 -0700343 sources += skia_pdf_sources
dsinclair11988d72016-05-04 10:17:00 -0700344 } 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") {
brettw784548a2016-09-06 11:39:46 -0700371 sources = skia_opts.ssse3_sources
dsinclair11988d72016-05-04 10:17:00 -0700372 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") {
brettw784548a2016-09-06 11:39:46 -0700387 sources = skia_opts.sse41_sources
dsinclair11988d72016-05-04 10:17:00 -0700388 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") {
brettw784548a2016-09-06 11:39:46 -0700403 sources = skia_opts.sse42_sources
dsinclair11988d72016-05-04 10:17:00 -0700404 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") {
brettw784548a2016-09-06 11:39:46 -0700419 sources = skia_opts.avx_sources
dsinclair11988d72016-05-04 10:17:00 -0700420 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 }
caryclark429a9ff2016-10-04 06:32:58 -0700434 source_set("skia_opts_hsw") {
435 sources = skia_opts.hsw_sources
dsinclair11988d72016-05-04 10:17:00 -0700436 if (!is_win) {
caryclark429a9ff2016-10-04 06:32:58 -0700437 cflags = [
438 "-mavx2",
439 "-mbmi",
440 "-mbmi2",
441 "-mf16c",
442 "-mfma",
443 ]
dsinclair11988d72016-05-04 10:17:00 -0700444 }
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") {
brettw784548a2016-09-06 11:39:46 -0700462 sources = skia_opts.sse2_sources
dsinclair11988d72016-05-04 10:17:00 -0700463 deps = [
464 ":skia_opts_avx",
caryclark429a9ff2016-10-04 06:32:58 -0700465 ":skia_opts_hsw",
dsinclair11988d72016-05-04 10:17:00 -0700466 ":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) {
brettw784548a2016-09-06 11:39:46 -0700476 sources = skia_opts.armv7_sources
dsinclair11988d72016-05-04 10:17:00 -0700477 if (arm_use_neon || arm_optionally_use_neon) {
brettw784548a2016-09-06 11:39:46 -0700478 sources += skia_opts.neon_sources
dsinclair11988d72016-05-04 10:17:00 -0700479
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 {
brettw784548a2016-09-06 11:39:46 -0700488 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700489 }
490 } else if (current_cpu == "arm64") {
brettw784548a2016-09-06 11:39:46 -0700491 sources = skia_opts.arm64_sources
dsinclair11988d72016-05-04 10:17:00 -0700492 } else if (current_cpu == "mipsel") {
493 cflags += [ "-fomit-frame-pointer" ]
494
495 if (mips_dsp_rev >= 1) {
brettw784548a2016-09-06 11:39:46 -0700496 sources = skia_opts.mips_dsp_sources
dsinclair11988d72016-05-04 10:17:00 -0700497 } else {
brettw784548a2016-09-06 11:39:46 -0700498 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700499 }
500 } else if (current_cpu == "mips64el") {
501 cflags += [ "-fomit-frame-pointer" ]
brettw784548a2016-09-06 11:39:46 -0700502 sources = skia_opts.none_sources
dsinclair11988d72016-05-04 10:17:00 -0700503 } else {
Lei Zhang65a21922017-04-15 21:30:32 -0700504 assert(false, "Need to port cpu specific stuff from gn/BUILDCONFIG.gn")
dsinclair11988d72016-05-04 10:17:00 -0700505 }
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}