Enable disabling WebCore::GraphicsContext in telemetry.
[chromium-blink-merge.git] / skia / BUILD.gn
blobfab5c16d53704b6b6cf84abe0b1a5d18c6710d96
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 (skia_support_pdf) {
419     deps += [ "//third_party/sfntly" ]
420   }
423 # Separated out so it can be compiled with different flags for SSE.
424 source_set("skia_opts") {
425   if (cpu_arch == "x86" || cpu_arch == "x64") {
426     sources = [
427       # SSE 2
428       "//third_party/skia/src/opts/opts_check_x86.cpp",
429       "//third_party/skia/src/opts/SkBitmapFilter_opts_SSE2.cpp",
430       "//third_party/skia/src/opts/SkBitmapProcState_opts_SSE2.cpp",
431       "//third_party/skia/src/opts/SkBlitRect_opts_SSE2.cpp",
432       "//third_party/skia/src/opts/SkBlitRow_opts_SSE2.cpp",
433       "//third_party/skia/src/opts/SkBlurImage_opts_SSE2.cpp",
434       "//third_party/skia/src/opts/SkMorphology_opts_SSE2.cpp",
435       "//third_party/skia/src/opts/SkUtils_opts_SSE2.cpp",
436       "//third_party/skia/src/opts/SkXfermode_opts_SSE2.cpp",
438       # SSE 3
439       "//third_party/skia/src/opts/SkBitmapProcState_opts_SSSE3.cpp",
441       # Chrome-specific.
442       "ext/convolver_SSE2.cc",
444       # These are header files used by this target from the skia one above.
445       "ext/convolver.h",
446       "//third_party/skia/include/core/SkTypes.h",
447     ]
449     if (is_linux || is_mac) {
450       cflags = [ "-mssse3" ]  # Note third 's'.
451     }
452   } else {
453     assert(false, "Need to port ARM/MIPS stuff from skia_library_opts.gyp")
454   }
456   configs -= [ "//build/config/compiler:chromium_code" ]
457   configs += [
458     ":skia_config",
459     "//build/config/compiler:no_chromium_code"
460   ]
462   deps = [
463     "//base",
464   ]
466   visibility = ":skia"