Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / skia / BUILD.gn
blob25515349312909d576cbab1ebf05d913f01e9bef
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 (component_mode == "shared_library") {
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   }
174 # Internal-facing config for Skia library code.
175 config("skia_library_config") {
176   # These include directories are only included for Skia code and are not
177   # exported to dependents. It's not clear if this is on purpose, but this
178   # matches the GYP build.
179   include_dirs = [
180     "//third_party/skia/include/private",
181     "//third_party/skia/src/core",
182     "//third_party/skia/src/image",
183     "//third_party/skia/src/opts",
184     "//third_party/skia/src/pdf",
185     "//third_party/skia/src/ports",
186     "//third_party/skia/src/sfnt",
187     "//third_party/skia/src/utils",
188     "//third_party/skia/src/lazy",
189   ]
190   if (is_mac || is_ios) {
191     include_dirs += [ "//third_party/skia/include/utils/mac" ]
192   }
193   if (is_mac) {
194     include_dirs += [ "//third_party/skia/include/utils/ios" ]
195   }
197   defines = []
199   if (component_mode == "shared_library") {
200     defines += [ "SKIA_IMPLEMENTATION=1" ]
201   }
203   if (current_cpu == "arm") {
204     if (arm_use_neon) {
205       defines += [ "SK_ARM_HAS_NEON" ]
206     } else if (arm_optionally_use_neon) {
207       defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
208     }
209   }
211   # Settings for text blitting, chosen to approximate the system browser.
212   if (is_linux) {
213     defines += [
214       "SK_GAMMA_EXPONENT=1.2",
215       "SK_GAMMA_CONTRAST=0.2",
216     ]
217   } else if (is_android) {
218     defines += [
219       "SK_GAMMA_APPLY_TO_A8",
220       "SK_GAMMA_EXPONENT=1.4",
221       "SK_GAMMA_CONTRAST=0.0",
222     ]
223   } else if (is_win) {
224     defines += [
225       "SK_GAMMA_SRGB",
226       "SK_GAMMA_CONTRAST=0.5",
227     ]
228   } else if (is_mac) {
229     defines += [
230       "SK_GAMMA_SRGB",
231       "SK_GAMMA_CONTRAST=0.0",
232     ]
233   }
235   if (is_android) {
236     defines += [
237       # Android devices are typically more memory constrained, so default to a
238       # smaller glyph cache (it may be overriden at runtime when the renderer
239       # starts up, depending on the actual device memory).
240       "SK_DEFAULT_FONT_CACHE_LIMIT=1048576",  # 1024 * 1024
241     ]
242   } else {
243     defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
244   }
246   if (is_win) {
247     include_dirs += [
248       "//third_party/skia/include/utils/win",
249       "//third_party/skia/src/utils/win",
250     ]
252     defines += [
253       # On windows, GDI handles are a scarse system-wide resource so we have to
254       # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
255       # fairly small size. http://crbug.com/314387
256       "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
257     ]
259     cflags = [
260       "/wd4244",  # conversion from 'type1( __int64)' to 'type2 (unsigned int)'
261       "/wd4267",  # conversion from 'size_t' (64 bit) to 'type'(32 bit).
262       "/wd4341",  # signed value is out of range for enum constant.
263       "/wd4345",  # Object is default-initialized if initialization is omitted.
264       "/wd4390",  # ';'empty statement found in looping;is it what was intended?
265       "/wd4554",  # 'operator' : check operator precedence for possible error
266       "/wd4748",  # compiler will disable optimizations if a function has inline
267                   # assembly code contains flow control(jmp or jcc) statements.
269       "/wd4800",  # forcing value to bool 'true/false'(assigning int to bool).
270     ]
271   }
274 component("skia") {
275   sources = [
276     # Chrome sources.
277     "ext/SkDiscardableMemory_chrome.cc",
278     "ext/SkMemory_new_handler.cpp",
279     "ext/analysis_canvas.cc",
280     "ext/benchmarking_canvas.cc",
281     "ext/convolver.cc",
282     "ext/event_tracer_impl.cc",
283     "ext/fontmgr_default_win.cc",
284     "ext/google_logging.cc",
285     "ext/image_operations.cc",
286     "ext/opacity_filter_canvas.cc",
287     "ext/pixel_ref_utils.cc",
288     "ext/platform_canvas.cc",
289     "ext/platform_device.cc",
290     "ext/platform_device_linux.cc",
291     "ext/platform_device_mac.cc",
292     "ext/platform_device_win.cc",
293     "ext/recursive_gaussian_convolution.cc",
294     "ext/skia_memory_dump_provider.cc",
295     "ext/skia_utils_base.cc",
296     "ext/skia_utils_ios.mm",
297     "ext/skia_utils_mac.mm",
298     "ext/skia_utils_win.cc",
299   ]
301   if (current_cpu == "x86" || current_cpu == "x64") {
302     sources += [ "ext/convolver_SSE2.cc" ]
303   } else if (current_cpu == "mipsel" && mips_dsp_rev >= 2) {
304     sources += [ "ext/convolver_mips_dspr2.cc" ]
305   }
307   # The skia gypi values are relative to the skia_dir, so we need to rebase.
308   sources += gypi_skia_core.sources
309   sources += gypi_skia_effects.sources
310   sources += gypi_skia_utils.sources
311   sources += gypi_values.skia_library_sources
313   # This and skia_opts are really the same conceptual target so share headers.
314   allow_circular_includes_from = [ ":skia_opts" ]
316   if (current_cpu == "arm") {
317     sources += [ "//third_party/skia/src/core/SkUtilsArm.cpp" ]
318   }
320   # GPU
321   if (skia_support_gpu) {
322     sources += gypi_skia_gpu.skgpu_sources
323     sources += gypi_skia_gpu.skgpu_null_gl_sources
324   }
326   # Remove unused util files include in utils.gypi
327   sources -= [
328     "//third_party/skia/src/utils/SkBitmapHasher.cpp",
329     "//third_party/skia/src/utils/SkBoundaryPatch.cpp",
330     "//third_party/skia/src/utils/SkCamera.cpp",
331     "//third_party/skia/src/utils/SkCubicInterval.cpp",
332     "//third_party/skia/src/utils/SkCullPoints.cpp",
333     "//third_party/skia/src/utils/SkDumpCanvas.cpp",
334     "//third_party/skia/src/utils/SkFrontBufferedStream.cpp",
335     "//third_party/skia/src/utils/SkInterpolator.cpp",
336     "//third_party/skia/src/utils/SkLayer.cpp",
337     "//third_party/skia/src/utils/SkMD5.cpp",
338     "//third_party/skia/src/utils/SkMeshUtils.cpp",
339     "//third_party/skia/src/utils/SkNinePatch.cpp",
340     "//third_party/skia/src/utils/SkOSFile.cpp",
341     "//third_party/skia/src/utils/SkParsePath.cpp",
342     "//third_party/skia/src/utils/SkSHA1.cpp",
344     # We don't currently need to change thread affinity, so leave out this complexity for now.
345     "//third_party/skia/src/utils/SkThreadUtils_pthread_linux.cpp",
346     "//third_party/skia/src/utils/SkThreadUtils_pthread_mach.cpp",
348     #testing
349     "//third_party/skia/src/fonts/SkGScalerContext.cpp",
350   ]
352   if (is_win) {
353     sources -= [
354       # Keeping _win.cpp
355       "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
356       "//third_party/skia/src/utils/SkThreadUtils_pthread_other.cpp",
357     ]
358   } else {
359     sources -= [
360       # Keeping _pthread.cpp and _pthread_other.cpp.
361       "//third_party/skia/src/utils/SkThreadUtils_win.cpp",
362     ]
363   }
365   # need separate win section to handle chromes auto gn filter
366   # (build/config/BUILDCONFIG.gn)
367   if (is_win) {
368     sources -= [
369       #windows
370       "//third_party/skia/src/utils/win/SkAutoCoInitialize.cpp",
371       "//third_party/skia/src/utils/win/SkIStream.cpp",
372       "//third_party/skia/src/utils/win/SkWGL_win.cpp",
373     ]
374   }
376   if (is_android && (!enable_basic_printing && !enable_print_preview)) {
377     sources -= [ "ext/skia_utils_base.cc" ]
378   }
380   # Fixup skia library sources.
381   if (is_win) {
382     sources -= [
383       "//third_party/skia/src/ports/SkOSFile_posix.cpp",
384       "//third_party/skia/src/ports/SkTLS_pthread.cpp",
385       "//third_party/skia/src/ports/SkTime_Unix.cpp",
386     ]
387   } else {
388     sources -= [
389       "//third_party/skia/src/ports/SkFontHost_win.cpp",
390       "//third_party/skia/src/ports/SkFontMgr_win_dw.cpp",
391       "//third_party/skia/src/ports/SkOSFile_win.cpp",
392       "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
393       "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
394       "//third_party/skia/src/ports/SkTLS_win.cpp",
395       "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
396     ]
397   }
398   if (!is_android) {
399     sources -= [
400       "//third_party/skia/src/ports/SkFontMgr_android.cpp",
401       "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
402       "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
403     ]
404   }
405   if (!is_mac) {
406     sources -= [ "//third_party/skia/src/ports/SkFontHost_mac.cpp" ]
407   }
409   if (!is_linux) {
410     sources -= [
411       "//third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp",
412       "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
413       "//third_party/skia/src/ports/SkFontHost_fontconfig.cpp",
414     ]
415   }
417   if (!is_linux && !is_android) {
418     sources -= [
419       "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
420       "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
421     ]
422   }
424   # Select the right BitmapPlatformDevice.
425   if (is_win) {
426     sources += [ "ext/bitmap_platform_device_win.cc" ]
427   } else if (is_mac) {
428     sources += [ "ext/bitmap_platform_device_mac.cc" ]
429   } else if (use_cairo) {
430     sources += [ "ext/bitmap_platform_device_cairo.cc" ]
431   } else {
432     sources += [ "ext/bitmap_platform_device_skia.cc" ]
433   }
435   if (is_clang) {
436     # Skia won't compile with some of the more strict clang warnings.
437     # e.g. it does:
438     #  SkASSERT(!"sk_out_of_memory");
439     configs -= [ "//build/config/clang:extra_warnings" ]
440   }
442   configs -= [ "//build/config/compiler:chromium_code" ]
443   configs += [
444     ":skia_library_config",
445     "//build/config:precompiled_headers",
446     "//build/config/compiler:no_chromium_code",
447   ]
448   public_configs = [ ":skia_config" ]
450   deps = [
451     ":skia_opts",
452     "//base",
453     "//base/third_party/dynamic_annotations",
454     "//third_party/zlib",
455   ]
457   if (is_linux) {
458     configs += [
459       "//build/config/linux:fontconfig",
460       "//build/config/linux:freetype2",
461     ]
462     if (use_pango) {
463       configs += [ "//build/config/linux:pangocairo" ]
464     }
465     deps += [ "//third_party/icu:icuuc" ]
466   }
468   if (is_android) {
469     set_sources_assignment_filter([])
470     sources += [ "ext/platform_device_linux.cc" ]
471     set_sources_assignment_filter(sources_assignment_filter)
472     deps += [
473       "//third_party/expat",
474       "//third_party/freetype-android:freetype",
475       "//third_party/android_tools:cpu_features",
476     ]
477   }
479   if (skia_support_pdf) {
480     deps += [ "//third_party/sfntly" ]
481     sources += gypi_skia_pdf.sources
482   }
484   if (is_android && !is_debug) {
485     configs -= [ "//build/config/compiler:optimize" ]
486     configs += [ "//build/config/compiler:optimize_max" ]
487   }
490 # Separated out so it can be compiled with different flags for SSE.
491 if (current_cpu == "x86" || current_cpu == "x64") {
492   source_set("skia_opts_sse3") {
493     sources = gypi_skia_opts.ssse3_sources
494     if (!is_win || is_clang) {
495       cflags = [ "-mssse3" ]
496     }
497     if (is_win) {
498       defines = [ "SK_CPU_SSE_LEVEL=31" ]
499     }
500     visibility = [ ":skia_opts" ]
501     configs -= [ "//build/config/compiler:chromium_code" ]
502     configs += [
503       ":skia_config",
504       ":skia_library_config",
505       "//build/config/compiler:no_chromium_code",
506     ]
507   }
508   source_set("skia_opts_sse4") {
509     sources = gypi_skia_opts.sse41_sources
510     if (!is_win || is_clang) {
511       cflags = [ "-msse4.1" ]
512     }
513     if (is_win) {
514       defines = [ "SK_CPU_SSE_LEVEL=41" ]
515     }
516     visibility = [ ":skia_opts" ]
517     configs -= [ "//build/config/compiler:chromium_code" ]
518     configs += [
519       ":skia_config",
520       ":skia_library_config",
521       "//build/config/compiler:no_chromium_code",
522     ]
523   }
525 source_set("skia_opts") {
526   cflags = []
527   defines = []
529   deps = [
530     "//base",
531   ]
533   if (current_cpu == "x86" || current_cpu == "x64") {
534     sources = gypi_skia_opts.sse2_sources
535     deps += [
536       ":skia_opts_sse3",
537       ":skia_opts_sse4",
538     ]
539   } else if (current_cpu == "arm") {
540     # The assembly uses the frame pointer register (r7 in Thumb/r11 in
541     # ARM), the compiler doesn't like that.
542     cflags += [ "-fomit-frame-pointer" ]
544     if (arm_version >= 7) {
545       sources = gypi_skia_opts.armv7_sources
546       if (arm_use_neon || arm_optionally_use_neon) {
547         sources += gypi_skia_opts.neon_sources
549         # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
550         # when running this.
551         if (!arm_use_neon) {
552           configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
553           cflags += [ "-mfpu=neon" ]
554         }
555       }
556     } else {
557       sources = gypi_skia_opts.none_sourcees
558     }
559   } else if (current_cpu == "mipsel") {
560     cflags += [ "-fomit-frame-pointer" ]
562     if (mips_dsp_rev >= 1) {
563       sources = gypi_skia_opts.mips_dsp_sources
564     } else {
565       sources = gypi_skia_opts.none_sources
566     }
567   } else {
568     assert(false, "Need to port cpu specific stuff from skia_library_opts.gyp")
569   }
571   if (is_android && !is_debug) {
572     configs -= [ "//build/config/compiler:optimize" ]
573     configs += [ "//build/config/compiler:optimize_max" ]
574   }
576   configs -= [ "//build/config/compiler:chromium_code" ]
577   configs += [
578     ":skia_config",
579     ":skia_library_config",
580     "//build/config/compiler:no_chromium_code",
581   ]
583   visibility = [ ":skia" ]
586 # TODO(GYP): Delete this after we've converted everything to GN.
587 # The _run targets exist only for compatibility w/ GYP.
588 group("skia_unittests_run") {
589   testonly = true
590   deps = [
591     ":skia_unittests",
592   ]
595 test("skia_unittests") {
596   sources = [
597     "ext/analysis_canvas_unittest.cc",
598     "ext/bitmap_platform_device_mac_unittest.cc",
599     "ext/convolver_unittest.cc",
600     "ext/image_operations_unittest.cc",
601     "ext/pixel_ref_utils_unittest.cc",
602     "ext/platform_canvas_unittest.cc",
603     "ext/recursive_gaussian_convolution_unittest.cc",
604     "ext/refptr_unittest.cc",
605     "ext/skia_memory_dump_provider_unittest.cc",
606     "ext/skia_utils_ios_unittest.mm",
607     "ext/skia_utils_mac_unittest.mm",
608   ]
610   if (!is_win && !is_mac) {
611     sources -= [ "ext/platform_canvas_unittest.cc" ]
612   }
614   deps = [
615     ":skia",
616     "//base",
617     "//base/test:run_all_unittests",
618     "//cc:test_support",  # TODO: Fix this test to not depend on cc.
619     "//testing/gtest",
620     "//ui/gfx",
621     "//ui/gfx/geometry",
622   ]
625 if (is_linux && !is_chromeos) {
626   # TODO(GYP): Figure out which of these work and are needed on other platforms.
627   executable("image_operations_bench") {
628     sources = [
629       "ext/image_operations_bench.cc",
630     ]
632     deps = [
633       ":skia",
634       "//base",
635     ]
636   }
638   executable("filter_fuzz_stub") {
639     testonly = true
640     sources = [
641       "tools/filter_fuzz_stub/filter_fuzz_stub.cc",
642     ]
644     deps = [
645       ":skia",
646       "//base",
647       "//base/test:test_support",
648     ]
649   }