Update optimize_png_files.sh to work on msysgit bash.
[chromium-blink-merge.git] / skia / BUILD.gn
blobd98763fc597a62d7ce2ccdc651e555bad49513b0
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 if (cpu_arch == "arm") {
8   import("//build/config/arm.gni")
11 skia_support_gpu = !is_ios
12 skia_support_pdf = !is_ios && enable_printing != 0
14 # The list of Skia defines that are to be set for chromium.
15 gypi_skia_defines = exec_script(
16     "//build/gypi_to_gn.py",
17     [ rebase_path("//third_party/skia/gyp/skia_for_chromium_defines.gypi"),
18       "--replace=<(skia_include_path)=//third_party/skia/include",
19       "--replace=<(skia_src_path)=//third_party/skia/src" ],
20     "scope",
21     [ "//third_party/skia/gyp/skia_for_chromium_defines.gypi" ])
23 # The list of Skia core sources that are to be set for chromium.
24 gypi_skia_core = exec_script(
25     "//build/gypi_to_gn.py",
26     [ rebase_path("//third_party/skia/gyp/core.gypi"),
27       "--replace=<(skia_include_path)=//third_party/skia/include",
28       "--replace=<(skia_src_path)=//third_party/skia/src" ],
29     "scope",
30     [ "//third_party/skia/gyp/core.gypi" ])
32 # The list of Skia gpu sources that are to be set for chromium.
33 gypi_skia_gpu = exec_script(
34     "//build/gypi_to_gn.py",
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     "scope",
39     [ "//third_party/skia/gyp/gpu.gypi" ])
41 # The list of Skia pdf sources that are to be set for chromium.
42 gypi_skia_pdf = exec_script(
43     "//build/gypi_to_gn.py",
44     [ rebase_path("//third_party/skia/gyp/pdf.gypi"),
45       "--replace=<(skia_include_path)=//third_party/skia/include",
46       "--replace=<(skia_src_path)=//third_party/skia/src" ],
47     "scope",
48     [ "//third_party/skia/gyp/pdf.gypi" ])
50 # The list of Skia effects that are to be set for chromium.
51 gypi_skia_effects = exec_script(
52     "//build/gypi_to_gn.py",
53     [ rebase_path("//third_party/skia/gyp/effects.gypi"),
54       "--replace=<(skia_include_path)=//third_party/skia/include",
55       "--replace=<(skia_src_path)=//third_party/skia/src" ],
56     "scope",
57     [ "//third_party/skia/gyp/effects.gypi" ])
59 # The list of Skia files is kept in skia_gn_files.gypi. Read it.
60 gypi_values = exec_script(
61     "//build/gypi_to_gn.py",
62     [ rebase_path("skia_gn_files.gypi"),
63       "--replace=<(skia_include_path)=//third_party/skia/include",
64       "--replace=<(skia_src_path)=//third_party/skia/src" ],
65     "scope",
66     [ "skia_gn_files.gypi" ])
68 # External-facing config for dependent code.
69 config("skia_config") {
70   include_dirs = [
71     "config",
72     "ext",
73     "//third_party/skia/include/config",
74     "//third_party/skia/include/core",
75     "//third_party/skia/include/effects",
76     "//third_party/skia/include/images",
77     "//third_party/skia/include/lazy",
78     "//third_party/skia/include/pathops",
79     "//third_party/skia/include/pdf",
80     "//third_party/skia/include/pipe",
81     "//third_party/skia/include/ports",
82     "//third_party/skia/include/utils",
83     "//third_party/skia/src/core",
84     "//third_party/skia/src/image",
85     "//third_party/skia/src/opts",
86     "//third_party/skia/src/ports",
87     "//third_party/skia/src/sfnt",
88     "//third_party/skia/src/utils",
89     "//third_party/skia/src/lazy",
90   ]
92   defines = gypi_skia_defines.skia_for_chromium_defines
94   defines += [
95     "SK_ENABLE_INST_COUNT=0",
96     "GR_GL_CUSTOM_SETUP_HEADER=\"GrGLConfig_chrome.h\"",
97     "SK_ENABLE_LEGACY_API_ALIASING=1",
98     "SK_ATTR_DEPRECATED=SK_NOTHING_ARG1",
99     "GR_GL_IGNORE_ES3_MSAA=0",
100     "SK_WILL_NEVER_DRAW_PERSPECTIVE_TEXT",
101     "SK_SUPPORT_LEGACY_GETTOTALCLIP",
102   ]
104   if (component_mode == "shared_library") {
105     defines += [ "SKIA_DLL" ]
106   }
108   if (skia_support_gpu) {
109     include_dirs += [
110       "//third_party/skia/include/gpu",
111       "//third_party/skia/src/gpu",
112     ]
113     defines += [ "SK_SUPPORT_GPU=1" ]
114   } else {
115     defines += [ "SK_SUPPORT_GPU=0" ]
116   }
118   # For POSIX platforms, prefer the Mutex implementation provided by Skia
119   # since it does not generate static initializers.
120   if (is_posix) {
121     defines += [ "SK_USE_POSIX_THREADS" ]
122   }
124   if (is_android) {
125     defines += [
126       "SK_BUILD_FOR_ANDROID",
127       "USE_CHROMIUM_SKIA",
128     ]
129   }
132 # Internal-facing config for Skia library code.
133 config("skia_library_config") {
134   # These include directories are only included for Skia code and are not
135   # exported to dependents. It's not clear if this is on purpose, but this
136   # matches the GYP build.
137   include_dirs = []
138   if (is_mac || is_ios) {
139     include_dirs += [ "//third_party/skia/include/utils/mac" ]
140   }
141   if (is_mac) {
142     include_dirs += [ "//third_party/skia/include/utils/ios" ]
143   }
145   defines = [
146     #skia_export_defines ???) TODO
148     # skia uses static initializers to initialize the serialization logic
149     # of its "pictures" library. This is currently not used in chrome; if
150     # it ever gets used the processes that use it need to call
151     # SkGraphics::Init().
152     "SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0",
154     # Forcing the unoptimized path for the offset image filter in skia until
155     # all filters used in Blink support the optimized path properly
156     "SK_DISABLE_OFFSETIMAGEFILTER_OPTIMIZATION",
158     # Disable this check because it is too strict for some Chromium-specific
159     # subclasses of SkPixelRef. See bug: crbug.com/171776.
160     "SK_DISABLE_PIXELREF_LOCKCOUNT_BALANCE_CHECK",
162     "IGNORE_ROT_AA_RECT_OPT",
164     "SK_IGNORE_BLURRED_RRECT_OPT",
166     "SK_IGNORE_QUAD_RR_CORNERS_OPT",
168     # this flag forces Skia not to use typographic metrics with GDI.
169     "SK_GDI_ALWAYS_USE_TEXTMETRICS_FOR_FONT_METRICS",
171     "SK_USE_DISCARDABLE_SCALEDIMAGECACHE",
172   ]
174   # Settings for text blitting, chosen to approximate the system browser.
175   if (is_linux) {
176     defines += [
177       "SK_GAMMA_EXPONENT=1.2",
178       "SK_GAMMA_CONTRAST=0.2",
179       "SK_HIGH_QUALITY_IS_LANCZOS",
180     ]
181   } else if (is_android) {
182     defines += [
183       "SK_GAMMA_APPLY_TO_A8",
184       "SK_GAMMA_EXPONENT=1.4",
185       "SK_GAMMA_CONTRAST=0.0",
186     ]
187   } else if (is_win) {
188     defines += [
189       "SK_GAMMA_SRGB",
190       "SK_GAMMA_CONTRAST=0.5",
191       "SK_HIGH_QUALITY_IS_LANCZOS",
192     ]
193   } else if (is_mac) {
194     defines += [
195       "SK_GAMMA_SRGB",
196       "SK_GAMMA_CONTRAST=0.0",
197       "SK_HIGH_QUALITY_IS_LANCZOS",
198     ]
199   }
201   if (is_android) {
202     defines += [
203       # Android devices are typically more memory constrained, so default to a
204       # smaller glyph cache (it may be overriden at runtime when the renderer
205       # starts up, depending on the actual device memory).
206       "SK_DEFAULT_FONT_CACHE_LIMIT=1048576"  # 1024 * 1024
207     ]
208   } else {
209     defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ]  # 20 * 1024 * 1024
210   }
212   if (is_win) {
213     include_dirs = [
214       "//third_party/skia/include/utils/win",
215       "//third_party/skia/src/utils/win",
216     ]
218     defines += [ "SK_FONTHOST_USES_FONTMGR" ]
220     cflags = [
221       # TODO(brettw) comment what these are.
222       "/wd4244",
223       "/wd4267",
224       "/wd4341",
225       "/wd4345",
226       "/wd4390",
227       "/wd4554",
228       "/wd4748",
229       "/wd4800",
230     ]
231   }
234 component("skia") {
235   sources = [
236     # Chrome sources.
237     "ext/analysis_canvas.cc",
238     "ext/analysis_canvas.h",
239     "ext/benchmarking_canvas.cc",
240     "ext/benchmarking_canvas.h",
241     "ext/bitmap_platform_device.h",
242     "ext/bitmap_platform_device_cairo.cc",
243     "ext/bitmap_platform_device_cairo.h",
244     "ext/bitmap_platform_device_mac.cc",
245     "ext/bitmap_platform_device_mac.h",
246     #"ext/bitmap_platform_device_skia.cc",
247     #"ext/bitmap_platform_device_skia.h",
248     "ext/bitmap_platform_device_win.cc",
249     "ext/bitmap_platform_device_win.h",
250     "ext/convolver.cc",
251     "ext/convolver.h",
252     "ext/event_tracer_impl.cc",
253     "ext/event_tracer_impl.h",
254     "ext/google_logging.cc",
255     "ext/image_operations.cc",
256     "ext/image_operations.h",
257     "ext/lazy_pixel_ref.cc",
258     "ext/lazy_pixel_ref.h",
259     "ext/SkThread_chrome.cc",
260     "ext/opacity_draw_filter.cc",
261     "ext/opacity_draw_filter.h",
262     "ext/paint_simplifier.cc",
263     "ext/paint_simplifier.h",
264     "ext/pixel_ref_utils.cc",
265     "ext/pixel_ref_utils.h",
266     "ext/platform_canvas.cc",
267     "ext/platform_canvas.h",
268     "ext/platform_device.cc",
269     "ext/platform_device.h",
270     "ext/platform_device_linux.cc",
271     "ext/platform_device_mac.cc",
272     "ext/platform_device_win.cc",
273     "ext/recursive_gaussian_convolution.cc",
274     "ext/recursive_gaussian_convolution.h",
275     "ext/refptr.h",
276     "ext/SkDiscardableMemory_chrome.h",
277     "ext/SkDiscardableMemory_chrome.cc",
278     "ext/SkMemory_new_handler.cpp",
279     "ext/skia_trace_shim.h",
280     "ext/skia_utils_base.cc",
281     "ext/skia_utils_base.h",
282     "ext/skia_utils_ios.mm",
283     "ext/skia_utils_ios.h",
284     "ext/skia_utils_mac.mm",
285     "ext/skia_utils_mac.h",
286     "ext/skia_utils_win.cc",
287     "ext/skia_utils_win.h",
288     "ext/vector_canvas.h",
289     "ext/vector_platform_device_emf_win.cc",
290     "ext/vector_platform_device_emf_win.h",
291     "ext/vector_platform_device_skia.cc",
292     "ext/vector_platform_device_skia.h",
293   ]
295   # The skia gypi values are relative to the skia_dir, so we need to rebase.
296   sources += gypi_skia_core.sources
297   sources += gypi_skia_effects.sources
298   sources += gypi_skia_pdf.sources
299   sources += gypi_values.skia_library_sources
301   # GPU
302   if (skia_support_gpu) {
303     sources += gypi_skia_gpu.skgpu_sources
304     sources += gypi_skia_gpu.skgpu_null_gl_sources
305   }
307   # Fixup Chrome sources.
308   if (is_posix) {
309     sources -= [ "ext/SkThread_chrome.cc" ]
310   }
311   if (is_ios) {
312     sources -= [ "ext/vector_platform_device_skia.cc" ]
313   }
314   if (is_win) {
315     sources -= [ "ext/SkThread_chrome.cc" ]
316   }
317   if (is_android && enable_printing == 0) {
318     sources -= [
319       "ext/skia_utils_base.cc",
320       "ext/vector_platform_device_skia.cc"
321     ]
322   }
324   # Fixup skia library sources.
325   if (is_win) {
326     sources -= [
327       "//third_party/skia/src/ports/SkOSFile_posix.cpp",
328       "//third_party/skia/src/ports/SkTime_Unix.cpp",
329       "//third_party/skia/src/ports/SkTLS_pthread.cpp",
330     ]
331   } else {
332     sources -= [
333       "//third_party/skia/src/ports/SkFontHost_win.cpp",
334       "//third_party/skia/src/ports/SkFontHost_win_dw.cpp",
335       "//third_party/skia/src/ports/SkFontMgr_default_gdi.cpp",
336       "//third_party/skia/src/ports/SkOSFile_win.cpp",
337       "//third_party/skia/src/ports/SkTLS_win.cpp",
338       "//third_party/skia/src/utils/SkThreadUtils_win.cpp",
339     ]
340   }
341   if (!is_android) {
342     sources -= [
343       "//third_party/skia/src/ports/SkFontConfigInterface_android.cpp",
344       "//third_party/skia/src/ports/SkFontConfigParser_android.cpp",
345     ]
346   }
347   if (!is_mac) {
348     sources -= [
349       "//third_party/skia/src/ports/SkFontHost_mac.cpp",
350       "//third_party/skia/src/utils/SkThreadUtils_pthread_mach.cpp",
351     ]
352   }
353   if (!is_linux) {
354     sources -= [
355       "//third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp",
356       "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
357       "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
358       "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
359       "//third_party/skia/src/ports/SkFontHost_fontconfig.cpp",
360       "//third_party/skia/src/ports/SkFontHost_linux.cpp",
361       "//third_party/skia/src/utils/SkThreadUtils_pthread_linux.cpp",
362     ]
363   } else if (!is_android) {
364     sources -= [
365       "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
366       "//third_party/skia/src/fonts/SkFontMgr_fontconfig.cpp",
367     ]
368   }
369   if (!is_posix) {
370     sources -= [
371       "//third_party/skia/src/utils/SkThreadUtils_pthread.cpp",
372     ]
373   }
375   if (!use_cairo) {
376     sources -= [
377       "ext/bitmap_platform_device_cairo.cc",
378       "ext/bitmap_platform_device_cairo.h",
379     ]
380   }
382   if (is_clang) {
383     # Skia won't compile with some of the more strict clang warnings.
384     # e.g. it does:
385     #  SkASSERT(!"sk_out_of_memory");
386     configs -= [ "//build/config/clang:extra_warnings" ]
387   }
389   configs -= [ "//build/config/compiler:chromium_code" ]
390   configs += [
391     ":skia_library_config",
392     "//build/config/compiler:no_chromium_code"
393   ]
394   direct_dependent_configs = [ ":skia_config" ]
396   deps = [
397     ":skia_opts",
398     "//base",
399     "//base/third_party/dynamic_annotations",
400     "//third_party/zlib",
401   ]
403   if (component_mode == "shared_library") {
404     defines = [ "SKIA_IMPLEMENTATION=1" ]
405   }
407   if (is_linux) {
408     configs += [
409       "//build/config/linux:fontconfig",
410       "//build/config/linux:freetype2",
411       "//build/config/linux:pangocairo",
412     ]
413     deps += [
414       "//third_party/icu:icuuc",
415     ]
416   }
418   if (is_android) {
419     deps += [
420       "//third_party/expat",
421       "//third_party/freetype",
422     ]
423   }
425   if (skia_support_pdf) {
426     deps += [ "//third_party/sfntly" ]
427   }
430 # Separated out so it can be compiled with different flags for SSE.
431 source_set("skia_opts") {
432   cflags = []
433   defines = []
435   if (cpu_arch == "x86" || cpu_arch == "x64") {
436     sources = [
437       # SSE 2
438       "//third_party/skia/src/opts/opts_check_x86.cpp",
439       "//third_party/skia/src/opts/SkBitmapFilter_opts_SSE2.cpp",
440       "//third_party/skia/src/opts/SkBitmapProcState_opts_SSE2.cpp",
441       "//third_party/skia/src/opts/SkBlitRect_opts_SSE2.cpp",
442       "//third_party/skia/src/opts/SkBlitRow_opts_SSE2.cpp",
443       "//third_party/skia/src/opts/SkBlurImage_opts_SSE2.cpp",
444       "//third_party/skia/src/opts/SkMorphology_opts_SSE2.cpp",
445       "//third_party/skia/src/opts/SkUtils_opts_SSE2.cpp",
446       "//third_party/skia/src/opts/SkXfermode_opts_SSE2.cpp",
448       # SSE 3
449       "//third_party/skia/src/opts/SkBitmapProcState_opts_SSSE3.cpp",
451       # Chrome-specific.
452       "ext/convolver_SSE2.cc",
454       # These are header files used by this target from the skia one above.
455       "ext/convolver.h",
456       "//third_party/skia/include/core/SkTypes.h",
457     ]
459     if (is_linux || is_mac) {
460       cflags += [ "-mssse3" ]  # Note third 's'.
461     }
462   } else if (cpu_arch == "arm") {
463     sources = [
464       "//third_party/skia/src/opts/SkBitmapProcState_opts_arm.cpp",
465     ]
467     # The assembly uses the frame pointer register (r7 in Thumb/r11 in
468     # ARM), the compiler doesn't like that.
469     cflags += [ "-fomit-frame-pointer" ]
471     if (arm_version >= 7) {
472       if (arm_use_neon || arm_optionally_use_neon) {
473         sources += [
474           "//third_party/skia/src/opts/memset16_neon.S",
475           "//third_party/skia/src/opts/memset32_neon.S",
476           "//third_party/skia/src/opts/SkBitmapProcState_arm_neon.cpp",
477           "//third_party/skia/src/opts/SkBitmapProcState_matrixProcs_neon.cpp",
478           "//third_party/skia/src/opts/SkBitmapProcState_matrix_clamp_neon.h",
479           "//third_party/skia/src/opts/SkBitmapProcState_matrix_repeat_neon.h",
480           "//third_party/skia/src/opts/SkBlitMask_opts_arm_neon.cpp",
481           "//third_party/skia/src/opts/SkBlitRow_opts_arm_neon.cpp",
482           "//third_party/skia/src/opts/SkXfermode_opts_arm_neon.cpp",
483           "//third_party/skia/src/opts/SkBlurImage_opts_neon.cpp",
484           "//third_party/skia/src/opts/SkMorphology_opts_neon.cpp",
485         ]
487         cflags += [
488           # The neon assembly contains conditional instructions which aren't
489           # enclosed in an IT block. The assembler complains without this
490           # option. See #86592.
491           "-Wa,-mimplicit-it=always",
492         ]
494         # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
495         # when running this.
496         assert(arm_fpu == "neon")
498         #ldflags = [
499         #  "-march=armv7-a",
500         #  "-Wl,--fix-cortex-a8",
501         #]
502       }
504       if (arm_use_neon) {
505         defines += [ "__ARM_HAVE_NEON" ]
506       }
507       if (arm_optionally_use_neon) {
508         defines += [ "__ARM_HAVE_OPTIONAL_NEON_SUPPORT" ]
509       }
510     }
512     # Non-Neon ARM code.
513     if (arm_version < 7 || (!arm_use_neon && arm_optionally_use_neon)) {
514       sources += [ "//third_party/skia/src/opts/memset.arm.S" ]
515     }
517     if (arm_version < 6) {
518       sources += [
519         "//third_party/skia/src/opts/SkBlitMask_opts_none.cpp",
520         "//third_party/skia/src/opts/SkBlitRow_opts_none.cpp",
521         "//third_party/skia/src/opts/SkUtils_opts_none.cpp",
522         "//third_party/skia/src/opts/SkXfermode_opts_none.cpp",
523         "//third_party/skia/src/opts/SkMorphology_opts_none.cpp",
524         "//third_party/skia/src/opts/SkBlurImage_opts_none.cpp",
525       ]
526     } else {
527       # arm version >= 6.
528       sources += [
529         "//third_party/skia/src/opts/SkBlitMask_opts_arm.cpp",
530         "//third_party/skia/src/opts/SkBlitRow_opts_arm.cpp",
531         "//third_party/skia/src/opts/SkBlitRow_opts_arm.h",
532         "//third_party/skia/src/opts/SkBlurImage_opts_arm.cpp",
533         "//third_party/skia/src/opts/SkMorphology_opts_arm.cpp",
534         "//third_party/skia/src/opts/SkUtils_opts_arm.cpp",
535         "//third_party/skia/src/opts/SkXfermode_opts_none.cpp",
536       ]
537     }
540   } else {
541     assert(false, "Need to port MIPS stuff from skia_library_opts.gyp")
542   }
544   configs -= [ "//build/config/compiler:chromium_code" ]
545   configs += [
546     ":skia_config",
547     "//build/config/compiler:no_chromium_code"
548   ]
550   deps = [
551     "//base",
552   ]
554   visibility = ":skia"