Use common code to set HttpNetworkSession::Param pointers.
[chromium-blink-merge.git] / skia / BUILD.gn
blob4182c4572b58ddd9a71ef6bbdfe850725e414597
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.
5 import("//build/config/features.gni")
6 import("//build/config/ui.gni")
7 import("//testing/test.gni")
8 if (current_cpu == "arm") {
9   import("//build/config/arm.gni")
11 if (current_cpu == "mipsel" || current_cpu == "mips64el") {
12   import("//build/config/mips.gni")
15 skia_support_gpu = !is_ios
16 skia_support_pdf = !is_ios && (enable_basic_printing || enable_print_preview)
18 # The list of Skia defines that are to be set for blink.
19 gypi_blink_skia_defines =
20     exec_script("//build/gypi_to_gn.py",
21                 [
22                   rebase_path(
23                       "//third_party/WebKit/public/blink_skia_config.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/WebKit/public/blink_skia_config.gypi" ])
30 # The list of Skia defines that are to be set for chromium.
31 gypi_skia_defines =
32     exec_script("//build/gypi_to_gn.py",
33                 [
34                   rebase_path(
35                       "//third_party/skia/gyp/skia_for_chromium_defines.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/skia_for_chromium_defines.gypi" ])
42 # The list of Skia core sources that are to be set for chromium.
43 gypi_skia_core =
44     exec_script("//build/gypi_to_gn.py",
45                 [
46                   rebase_path("//third_party/skia/gyp/core.gypi"),
47                   "--replace=<(skia_include_path)=//third_party/skia/include",
48                   "--replace=<(skia_src_path)=//third_party/skia/src",
49                 ],
50                 "scope",
51                 [ "//third_party/skia/gyp/core.gypi" ])
53 # The list of Skia gpu sources that are to be set for chromium.
54 if (skia_support_gpu) {
55   gypi_skia_gpu =
56       exec_script("//build/gypi_to_gn.py",
57                   [
58                     rebase_path("//third_party/skia/gyp/gpu.gypi"),
59                     "--replace=<(skia_include_path)=//third_party/skia/include",
60                     "--replace=<(skia_src_path)=//third_party/skia/src",
61                   ],
62                   "scope",
63                   [ "//third_party/skia/gyp/gpu.gypi" ])
66 # The list of Skia pdf sources that are to be set for chromium.
67 if (skia_support_pdf) {
68   gypi_skia_pdf =
69       exec_script("//build/gypi_to_gn.py",
70                   [
71                     rebase_path("//third_party/skia/gyp/pdf.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/pdf.gypi" ])
79 # The list of Skia effects that are to be set for chromium.
80 gypi_skia_effects =
81     exec_script("//build/gypi_to_gn.py",
82                 [
83                   rebase_path("//third_party/skia/gyp/effects.gypi"),
84                   "--replace=<(skia_include_path)=//third_party/skia/include",
85                   "--replace=<(skia_src_path)=//third_party/skia/src",
86                 ],
87                 "scope",
88                 [ "//third_party/skia/gyp/effects.gypi" ])
90 # The list of Skia utils that are to be set for chromium.
91 gypi_skia_utils =
92     exec_script("//build/gypi_to_gn.py",
93                 [
94                   rebase_path("//third_party/skia/gyp/utils.gypi"),
95                   "--replace=<(skia_include_path)=//third_party/skia/include",
96                   "--replace=<(skia_src_path)=//third_party/skia/src",
97                 ],
98                 "scope",
99                 [ "//third_party/skia/gyp/utils.gypi" ])
101 gypi_skia_opts =
102     exec_script("//build/gypi_to_gn.py",
103                 [
104                   rebase_path("//third_party/skia/gyp/opts.gypi"),
105                   "--replace=<(skia_include_path)=//third_party/skia/include",
106                   "--replace=<(skia_src_path)=//third_party/skia/src",
107                 ],
108                 "scope",
109                 [ "//third_party/skia/gyp/opts.gypi" ])
111 # The list of Skia files is kept in skia_gn_files.gypi. Read it.
112 gypi_values =
113     exec_script("//build/gypi_to_gn.py",
114                 [
115                   rebase_path("skia_gn_files.gypi"),
116                   "--replace=<(skia_include_path)=//third_party/skia/include",
117                   "--replace=<(skia_src_path)=//third_party/skia/src",
118                 ],
119                 "scope",
120                 [ "skia_gn_files.gypi" ])
122 # External-facing config for dependent code.
123 config("skia_config") {
124   include_dirs = [
125     "config",
126     "ext",
127     "//third_party/skia/include/c",
128     "//third_party/skia/include/config",
129     "//third_party/skia/include/core",
130     "//third_party/skia/include/effects",
131     "//third_party/skia/include/images",
132     "//third_party/skia/include/lazy",
133     "//third_party/skia/include/pathops",
134     "//third_party/skia/include/pdf",
135     "//third_party/skia/include/pipe",
136     "//third_party/skia/include/ports",
137     "//third_party/skia/include/utils",
138   ]
140   defines = gypi_blink_skia_defines.blink_skia_defines
141   defines += gypi_skia_defines.skia_for_chromium_defines
143   defines += []
145   if (is_component_build) {
146     defines += [
147       "SKIA_DLL",
148       "GR_GL_IGNORE_ES3_MSAA=0",
149     ]
150   }
152   if (skia_support_gpu) {
153     include_dirs += [
154       "//third_party/skia/include/gpu",
155       "//third_party/skia/src/gpu",
156     ]
157     defines += [ "SK_SUPPORT_GPU=1" ]
158   } else {
159     defines += [ "SK_SUPPORT_GPU=0" ]
160   }
162   if (is_android) {
163     defines += [
164       "SK_BUILD_FOR_ANDROID",
165       "USE_CHROMIUM_SKIA",
166     ]
167   }
169   if (is_mac) {
170     defines += [ "SK_BUILD_FOR_MAC" ]
171   }
173   if (is_win) {
174     defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
175   }
178 # Internal-facing config for Skia library code.
179 config("skia_library_config") {
180   # These include directories are only included for Skia code and are not
181   # exported to dependents. It's not clear if this is on purpose, but this
182   # matches the GYP build.
183   include_dirs = [
184     "//third_party/skia/include/private",
185     "//third_party/skia/src/core",
186     "//third_party/skia/src/image",
187     "//third_party/skia/src/opts",
188     "//third_party/skia/src/pdf",
189     "//third_party/skia/src/ports",
190     "//third_party/skia/src/sfnt",
191     "//third_party/skia/src/utils",
192     "//third_party/skia/src/lazy",
193   ]
194   if (is_mac || is_ios) {
195     include_dirs += [ "//third_party/skia/include/utils/mac" ]
196   }
197   if (is_mac) {
198     include_dirs += [ "//third_party/skia/include/utils/ios" ]
199   }
201   defines = []
203   if (is_component_build) {
204     defines += [ "SKIA_IMPLEMENTATION=1" ]
205   }
207   if (current_cpu == "arm") {
208     if (arm_use_neon) {
209       defines += [ "SK_ARM_HAS_NEON" ]
210     } else if (arm_optionally_use_neon) {
211       defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
212     }
213   }
215   # Settings for text blitting, chosen to approximate the system browser.
216   if (is_linux) {
217     defines += [
218       "SK_GAMMA_EXPONENT=1.2",
219       "SK_GAMMA_CONTRAST=0.2",
220     ]
221   } else if (is_android) {
222     defines += [
223       "SK_GAMMA_APPLY_TO_A8",
224       "SK_GAMMA_EXPONENT=1.4",
225       "SK_GAMMA_CONTRAST=0.0",
226     ]
227   } else if (is_win) {
228     defines += [
229       "SK_GAMMA_SRGB",
230       "SK_GAMMA_CONTRAST=0.5",
231     ]
232   } else if (is_mac) {
233     defines += [
234       "SK_GAMMA_SRGB",
235       "SK_GAMMA_CONTRAST=0.0",
236     ]
237   }
239   if (is_android) {
240     defines += [
241       # Android devices are typically more memory constrained, so default to a
242       # smaller glyph cache (it may be overriden at runtime when the renderer
243       # starts up, depending on the actual device memory).
244       "SK_DEFAULT_FONT_CACHE_LIMIT=1048576",  # 1024 * 1024
245     ]
246   } else {
247     defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
248   }
250   if (is_win) {
251     include_dirs += [
252       "//third_party/skia/include/utils/win",
253       "//third_party/skia/src/utils/win",
254     ]
256     defines += [
257       # On windows, GDI handles are a scarse system-wide resource so we have to
258       # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
259       # fairly small size. http://crbug.com/314387
260       "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
261     ]
263     cflags = [
264       "/wd4244",  # conversion from 'type1( __int64)' to 'type2 (unsigned int)'
265       "/wd4267",  # conversion from 'size_t' (64 bit) to 'type'(32 bit).
266       "/wd4341",  # signed value is out of range for enum constant.
267       "/wd4345",  # Object is default-initialized if initialization is omitted.
268       "/wd4390",  # ';'empty statement found in looping;is it what was intended?
269       "/wd4554",  # 'operator' : check operator precedence for possible error
270       "/wd4748",  # compiler will disable optimizations if a function has inline
271                   # assembly code contains flow control(jmp or jcc) statements.
273       "/wd4800",  # forcing value to bool 'true/false'(assigning int to bool).
274     ]
275   }
278 component("skia") {
279   sources = [
280     # Chrome sources.
281     "ext/SkDiscardableMemory_chrome.cc",
282     "ext/SkMemory_new_handler.cpp",
283     "ext/analysis_canvas.cc",
284     "ext/benchmarking_canvas.cc",
285     "ext/convolver.cc",
286     "ext/event_tracer_impl.cc",
287     "ext/fontmgr_default_win.cc",
288     "ext/google_logging.cc",
289     "ext/image_operations.cc",
290     "ext/opacity_filter_canvas.cc",
291     "ext/pixel_ref_utils.cc",
292     "ext/platform_device.cc",
293     "ext/platform_device_linux.cc",
294     "ext/platform_device_mac.cc",
295     "ext/platform_device_win.cc",
296     "ext/recursive_gaussian_convolution.cc",
297     "ext/skia_memory_dump_provider.cc",
298     "ext/skia_utils_base.cc",
299     "ext/skia_utils_ios.mm",
300     "ext/skia_utils_mac.mm",
301     "ext/skia_utils_win.cc",
302   ]
304   if (!is_ios) {
305     sources += [ "ext/platform_canvas.cc" ]
306   }
307   if (!is_ios && (current_cpu == "x86" || current_cpu == "x64")) {
308     sources += [ "ext/convolver_SSE2.cc" ]
309   } else if (current_cpu == "mipsel" && mips_dsp_rev >= 2) {
310     sources += [ "ext/convolver_mips_dspr2.cc" ]
311   }
313   # The skia gypi values are relative to the skia_dir, so we need to rebase.
314   sources += gypi_skia_core.sources
315   sources += gypi_skia_effects.sources
316   sources += gypi_skia_utils.sources
317   sources += gypi_values.skia_library_sources
319   # This and skia_opts are really the same conceptual target so share headers.
320   allow_circular_includes_from = [ ":skia_opts" ]
322   if (current_cpu == "arm") {
323     sources += [ "//third_party/skia/src/core/SkUtilsArm.cpp" ]
324   }
326   # GPU
327   if (skia_support_gpu) {
328     sources += gypi_skia_gpu.skgpu_sources
329     sources += gypi_skia_gpu.skgpu_null_gl_sources
330   }
332   # Remove unused util files include in utils.gypi
333   sources -= [
334     "//third_party/skia/src/utils/SkBitmapHasher.cpp",
335     "//third_party/skia/src/utils/SkBoundaryPatch.cpp",
336     "//third_party/skia/src/utils/SkCamera.cpp",
337     "//third_party/skia/src/utils/SkCubicInterval.cpp",
338     "//third_party/skia/src/utils/SkCullPoints.cpp",
339     "//third_party/skia/src/utils/SkDumpCanvas.cpp",
340     "//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
341     "//third_party/skia/src/utils/SkInterpolator.cpp",
342     "//third_party/skia/src/utils/SkLayer.cpp",
343     "//third_party/skia/src/utils/SkMD5.cpp",
344     "//third_party/skia/src/utils/SkMeshUtils.cpp",
345     "//third_party/skia/src/utils/SkNinePatch.cpp",
346     "//third_party/skia/src/utils/SkOSFile.cpp",
347     "//third_party/skia/src/utils/SkParsePath.cpp",
348     "//third_party/skia/src/utils/SkSHA1.cpp",
350     # We don't currently need to change thread affinity, so leave out this complexity for now.
351     "//third_party/skia/src/utils/SkThreadUtils_pthread_linux.cpp",
352     "//third_party/skia/src/utils/SkThreadUtils_pthread_mach.cpp",
354     #testing
355     "//third_party/skia/src/fonts/SkGScalerContext.cpp",
356   ]
358   if (is_win) {
359     sources -= [
360       # Keeping _win.cpp
361       "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
362       "//third_party/skia/src/utils/SkThreadUtils_pthread_other.cpp",
363     ]
364   } else {
365     sources -= [
366       # Keeping _pthread.cpp and _pthread_other.cpp.
367       "//third_party/skia/src/utils/SkThreadUtils_win.cpp",
368     ]
369   }
371   # need separate win section to handle chromes auto gn filter
372   # (build/config/BUILDCONFIG.gn)
373   if (is_win) {
374     sources -= [
375       #windows
376       "//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp",
377       "//third_party/skia/src/utils/win/SkIStream.cpp",
378       "//third_party/skia/src/utils/win/SkWGL_win.cpp",
379     ]
380   }
382   if (is_android && (!enable_basic_printing && !enable_print_preview)) {
383     sources -= [ "ext/skia_utils_base.cc" ]
384   }
386   # Fixup skia library sources.
387   if (is_win) {
388     sources -= [
389       "//third_party/skia/src/ports/SkOSFile_posix.cpp",
390       "//third_party/skia/src/ports/SkTLS_pthread.cpp",
391       "//third_party/skia/src/ports/SkTime_Unix.cpp",
392     ]
393   } else {
394     sources -= [
395       "//third_party/skia/src/ports/SkFontHost_win.cpp",
396       "//third_party/skia/src/ports/SkFontMgr_win_dw.cpp",
397       "//third_party/skia/src/ports/SkOSFile_win.cpp",
398       "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
399       "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
400       "//third_party/skia/src/ports/SkTLS_win.cpp",
401       "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
402     ]
403   }
404   if (!is_android) {
405     sources -= [
406       "//third_party/skia/src/ports/SkFontMgr_android.cpp",
407       "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
408       "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
409     ]
410   }
411   if (!is_mac) {
412     sources -= [ "//third_party/skia/src/ports/SkFontHost_mac.cpp" ]
413   }
415   if (!is_linux) {
416     sources -= [
417       "//third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp",
418       "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
419       "//third_party/skia/src/ports/SkFontHost_fontconfig.cpp",
420     ]
421   }
423   if (!is_linux && !is_android) {
424     sources -= [
425       "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
426       "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
427     ]
428   }
430   # Select the right BitmapPlatformDevice.
431   if (is_win) {
432     sources += [ "ext/bitmap_platform_device_win.cc" ]
433   } else if (is_mac) {
434     sources += [ "ext/bitmap_platform_device_mac.cc" ]
435   } else if (use_cairo) {
436     sources += [ "ext/bitmap_platform_device_cairo.cc" ]
437   } else if (!is_ios) {
438     sources += [ "ext/bitmap_platform_device_skia.cc" ]
439   }
441   if (is_clang) {
442     # Skia won't compile with some of the more strict clang warnings.
443     # e.g. it does:
444     #  SkASSERT(!"sk_out_of_memory");
445     configs -= [ "//build/config/clang:extra_warnings" ]
446   }
448   configs -= [ "//build/config/compiler:chromium_code" ]
449   configs += [
450     ":skia_library_config",
451     "//build/config:precompiled_headers",
452     "//build/config/compiler:no_chromium_code",
453   ]
454   public_configs = [ ":skia_config" ]
456   deps = [
457     ":skia_opts",
458     "//base",
459     "//base/third_party/dynamic_annotations",
460     "//third_party/zlib",
461   ]
463   if (is_linux) {
464     configs += [
465       "//build/config/linux:fontconfig",
466       "//build/config/linux:freetype2",
467     ]
468     if (use_pango) {
469       configs += [ "//build/config/linux:pangocairo" ]
470     }
471     deps += [ "//third_party/icu:icuuc" ]
472   }
474   if (is_android) {
475     set_sources_assignment_filter([])
476     sources += [ "ext/platform_device_linux.cc" ]
477     set_sources_assignment_filter(sources_assignment_filter)
478     deps += [
479       "//third_party/expat",
480       "//third_party/freetype-android:freetype",
481       "//third_party/android_tools:cpu_features",
482     ]
483   }
485   if (skia_support_pdf) {
486     deps += [ "//third_party/sfntly" ]
487     sources += gypi_skia_pdf.sources
488   }
490   if (is_android && !is_debug) {
491     configs -= [ "//build/config/compiler:optimize" ]
492     configs += [ "//build/config/compiler:optimize_max" ]
493   }
495   if (is_ios) {
496     libs = [ "ImageIO.framework" ]
497     set_sources_assignment_filter([])
498     sources += [
499       "//third_party/skia/src/ports/SkFontHost_mac.cpp",
500       "//third_party/skia/src/utils/mac/SkCreateCGImageRef.cpp",
501       "//third_party/skia/src/utils/mac/SkStream_mac.cpp",
502     ]
503     set_sources_assignment_filter(sources_assignment_filter)
505     # To disable warning "CGContextSelectFont' is deprecated"
506     cflags = [ "-Wno-deprecated-declarations" ]
507   }
510 # Separated out so it can be compiled with different flags for SSE.
511 if (current_cpu == "x86" || current_cpu == "x64") {
512   source_set("skia_opts_sse3") {
513     sources = gypi_skia_opts.ssse3_sources
514     if (!is_win || is_clang) {
515       cflags = [ "-mssse3" ]
516     }
517     if (is_win) {
518       defines = [ "SK_CPU_SSE_LEVEL=31" ]
519     }
520     visibility = [ ":skia_opts" ]
521     configs -= [ "//build/config/compiler:chromium_code" ]
522     configs += [
523       ":skia_config",
524       ":skia_library_config",
525       "//build/config/compiler:no_chromium_code",
526     ]
527   }
528   source_set("skia_opts_sse4") {
529     sources = gypi_skia_opts.sse41_sources
530     if (!is_win || is_clang) {
531       cflags = [ "-msse4.1" ]
532     }
533     if (is_win) {
534       defines = [ "SK_CPU_SSE_LEVEL=41" ]
535     }
536     visibility = [ ":skia_opts" ]
537     configs -= [ "//build/config/compiler:chromium_code" ]
538     configs += [
539       ":skia_config",
540       ":skia_library_config",
541       "//build/config/compiler:no_chromium_code",
542     ]
543   }
545 source_set("skia_opts") {
546   cflags = []
547   defines = []
549   deps = [
550     "//base",
551   ]
553   if (current_cpu == "x86" || current_cpu == "x64") {
554     sources = gypi_skia_opts.sse2_sources
555     deps += [
556       ":skia_opts_sse3",
557       ":skia_opts_sse4",
558     ]
559   } else if (current_cpu == "arm") {
560     # The assembly uses the frame pointer register (r7 in Thumb/r11 in
561     # ARM), the compiler doesn't like that.
562     cflags += [ "-fomit-frame-pointer" ]
564     if (arm_version >= 7) {
565       sources = gypi_skia_opts.armv7_sources
566       if (arm_use_neon || arm_optionally_use_neon) {
567         sources += gypi_skia_opts.neon_sources
569         # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
570         # when running this.
571         if (!arm_use_neon) {
572           configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
573           cflags += [ "-mfpu=neon" ]
574         }
575       }
576     } else {
577       sources = gypi_skia_opts.none_sourcees
578     }
579   } else if (current_cpu == "mipsel") {
580     cflags += [ "-fomit-frame-pointer" ]
582     if (mips_dsp_rev >= 1) {
583       sources = gypi_skia_opts.mips_dsp_sources
584     } else {
585       sources = gypi_skia_opts.none_sources
586     }
587   } else {
588     assert(false, "Need to port cpu specific stuff from skia_library_opts.gyp")
589   }
591   if (is_android && !is_debug) {
592     configs -= [ "//build/config/compiler:optimize" ]
593     configs += [ "//build/config/compiler:optimize_max" ]
594   }
596   configs -= [ "//build/config/compiler:chromium_code" ]
597   configs += [
598     ":skia_config",
599     ":skia_library_config",
600     "//build/config/compiler:no_chromium_code",
601   ]
603   visibility = [ ":skia" ]
606 # TODO(GYP): Delete this after we've converted everything to GN.
607 # The _run targets exist only for compatibility w/ GYP.
608 group("skia_unittests_run") {
609   testonly = true
610   deps = [
611     ":skia_unittests",
612   ]
615 test("skia_unittests") {
616   sources = [
617     "ext/analysis_canvas_unittest.cc",
618     "ext/bitmap_platform_device_mac_unittest.cc",
619     "ext/convolver_unittest.cc",
620     "ext/image_operations_unittest.cc",
621     "ext/pixel_ref_utils_unittest.cc",
622     "ext/platform_canvas_unittest.cc",
623     "ext/recursive_gaussian_convolution_unittest.cc",
624     "ext/refptr_unittest.cc",
625     "ext/skia_memory_dump_provider_unittest.cc",
626     "ext/skia_utils_ios_unittest.mm",
627     "ext/skia_utils_mac_unittest.mm",
628   ]
630   if (!is_win && !is_mac) {
631     sources -= [ "ext/platform_canvas_unittest.cc" ]
632   }
634   deps = [
635     ":skia",
636     "//base",
637     "//base/test:run_all_unittests",
638     "//testing/gtest",
639     "//ui/gfx",
640     "//ui/gfx/geometry",
641   ]
643   if (!is_ios) {
644     deps += [ "//cc:test_support" ]  # TODO: Fix this test to not depend on cc.
645   }
648 if (is_linux && !is_chromeos) {
649   # TODO(GYP): Figure out which of these work and are needed on other platforms.
650   executable("image_operations_bench") {
651     sources = [
652       "ext/image_operations_bench.cc",
653     ]
655     deps = [
656       ":skia",
657       "//base",
658     ]
659   }
661   executable("filter_fuzz_stub") {
662     testonly = true
663     sources = [
664       "tools/filter_fuzz_stub/filter_fuzz_stub.cc",
665     ]
667     deps = [
668       ":skia",
669       "//base",
670       "//base/test:test_support",
671     ]
672   }