blob: 7b0f7216d0d945699bd2eceb32f4afeed3c70bb4 [file] [log] [blame]
K. Moon8636cff2022-11-02 18:45:43 +00001# Copyright 2013 The PDFium Authors
dsinclair11988d72016-05-04 10:17:00 -07002# 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")
Kevin Lubickfe247d32023-01-11 18:48:21 +00008import("//third_party/skia/gn/codec.gni")
brettw784548a2016-09-06 11:39:46 -07009import("//third_party/skia/gn/shared_sources.gni")
Lei Zhang26dc4e62022-06-30 20:57:32 +000010import("//third_party/skia/modules/skcms/skcms.gni")
Lei Zhanga7070ff2019-12-05 21:43:44 +000011import("features.gni")
dsinclair11988d72016-05-04 10:17:00 -070012
13if (current_cpu == "arm") {
14 import("//build/config/arm.gni")
15}
16if (current_cpu == "mipsel" || current_cpu == "mips64el") {
17 import("//build/config/mips.gni")
18}
19
Kevin Lubick7f2d2812023-03-13 18:07:28 +000020skia_use_ganesh_backend = !is_ios
Lei Zhanga7070ff2019-12-05 21:43:44 +000021skia_support_pdf = false
dsinclair11988d72016-05-04 10:17:00 -070022
dsinclair11988d72016-05-04 10:17:00 -070023# External-facing config for dependent code.
24config("skia_config") {
Lei Zhang98350502019-07-12 17:12:34 +000025 include_dirs = [ "//third_party/skia" ]
dsinclair11988d72016-05-04 10:17:00 -070026
K. Moonf446aae2022-11-16 18:15:11 +000027 defines = [
28 "SK_ENCODE_PNG",
29 "SK_USER_CONFIG_HEADER=\"../../skia/config/SkPdfiumUserConfig.h\"",
30 ]
dsinclair11988d72016-05-04 10:17:00 -070031
dan sinclairecc3c832017-04-10 10:47:18 -040032 if (is_win) {
33 defines += [ "SK_FREETYPE_MINIMUM_RUNTIME_VERSION=(((FREETYPE_MAJOR) * 0x01000000) | ((FREETYPE_MINOR) * 0x00010000) | ((FREETYPE_PATCH) * 0x00000100))" ]
34 }
35
36 if (is_component_build) {
37 defines += [
38 "SKIA_DLL",
39 "GR_GL_IGNORE_ES3_MSAA=0",
40 ]
41 }
42
Kevin Lubick7f2d2812023-03-13 18:07:28 +000043 if (skia_use_ganesh_backend) {
44 defines += [ "SK_GANESH" ]
dsinclair11988d72016-05-04 10:17:00 -070045 }
46
Lei Zhanga7070ff2019-12-05 21:43:44 +000047 if (skia_use_gl) {
48 defines += [ "SK_GL" ]
49 }
50
dsinclair11988d72016-05-04 10:17:00 -070051 if (is_android) {
52 defines += [
53 "SK_BUILD_FOR_ANDROID",
54 "USE_CHROMIUM_SKIA",
55 ]
56 }
57
58 if (is_mac) {
59 defines += [ "SK_BUILD_FOR_MAC" ]
60 }
61
62 if (is_win) {
63 defines += [ "GR_GL_FUNCTION_TYPE=__stdcall" ]
64 }
65}
66
67# Internal-facing config for Skia library code.
68config("skia_library_config") {
K. Moon9fc138c2023-02-07 00:58:01 +000069 # Turn on SK_API to export Skia's public API
70 defines = [
71 "IS_SKIA_IMPL=1",
72 "SKIA_IMPLEMENTATION=1",
73 ]
dsinclair11988d72016-05-04 10:17:00 -070074
75 if (current_cpu == "arm") {
76 if (arm_use_neon) {
77 defines += [ "SK_ARM_HAS_NEON" ]
78 } else if (arm_optionally_use_neon) {
79 defines += [ "SK_ARM_HAS_OPTIONAL_NEON" ]
80 }
81 }
82
83 # Settings for text blitting, chosen to approximate the system browser.
Lei Zhang2f5f9552020-08-05 18:51:25 +000084 if (is_linux || is_chromeos) {
dsinclair11988d72016-05-04 10:17:00 -070085 defines += [
86 "SK_GAMMA_EXPONENT=1.2",
87 "SK_GAMMA_CONTRAST=0.2",
88 ]
89 } else if (is_android) {
90 defines += [
91 "SK_GAMMA_APPLY_TO_A8",
92 "SK_GAMMA_EXPONENT=1.4",
93 "SK_GAMMA_CONTRAST=0.0",
94 ]
95 } else if (is_win) {
96 defines += [
97 "SK_GAMMA_SRGB",
98 "SK_GAMMA_CONTRAST=0.5",
99 ]
100 } else if (is_mac) {
101 defines += [
102 "SK_GAMMA_SRGB",
103 "SK_GAMMA_CONTRAST=0.0",
104 ]
105 }
106
107 if (is_android) {
108 defines += [
109 # Android devices are typically more memory constrained, so default to a
110 # smaller glyph cache (it may be overriden at runtime when the renderer
111 # starts up, depending on the actual device memory).
112 "SK_DEFAULT_FONT_CACHE_LIMIT=1048576", # 1024 * 1024
113 ]
114 } else {
115 defines += [ "SK_DEFAULT_FONT_CACHE_LIMIT=20971520" ] # 20 * 1024 * 1024
116 }
117
118 if (is_win) {
dsinclair11988d72016-05-04 10:17:00 -0700119 defines += [
120 # On windows, GDI handles are a scarse system-wide resource so we have to
121 # keep the glyph cache, which holds up to 4 GDI handles per entry, to a
122 # fairly small size. http://crbug.com/314387
123 "SK_DEFAULT_FONT_CACHE_COUNT_LIMIT=256",
124 ]
125
126 cflags = [
127 "/wd4244", # conversion from 'type1( __int64)' to 'type2 (unsigned int)'
dsinclair11988d72016-05-04 10:17:00 -0700128 "/wd4341", # signed value is out of range for enum constant.
129 "/wd4345", # Object is default-initialized if initialization is omitted.
130 "/wd4390", # ';'empty statement found in looping;is it what was intended?
131 "/wd4554", # 'operator' : check operator precedence for possible error
132 "/wd4748", # compiler will disable optimizations if a function has inline
133 # assembly code contains flow control(jmp or jcc) statements.
Lei Zhangf02c8c92019-12-05 19:14:23 +0000134
135 "/wd4800", # forcing value to bool 'true/false'(assigning int to bool).
Lei Zhang95cf31b2020-04-23 16:42:38 +0000136 "/wd5041", # out-of-line definition for constexpr static data member is
137 # not needed and is deprecated in C++17
dsinclair11988d72016-05-04 10:17:00 -0700138 ]
139 }
140}
141
Lei Zhang742f5b22018-10-31 16:41:24 +0000142source_set("skcms") {
143 cflags = []
144 if (!is_win || is_clang) {
145 cflags += [
146 "-w",
147 "-std=c11",
148 ]
149 }
150
151 # LLVM automatically sets the equivalent of GCC's -mfp16-format=ieee on ARM
152 # builds by default, while GCC itself does not. We need it to enable support
153 # for half-precision floating point data types used by SKCMS on ARM.
Lei Zhang2f5f9552020-08-05 18:51:25 +0000154 if ((is_linux || is_chromeos) && !is_clang && current_cpu == "arm") {
Lei Zhang742f5b22018-10-31 16:41:24 +0000155 cflags += [ "-mfp16-format=ieee" ]
156 }
157
Lei Zhang26dc4e62022-06-30 20:57:32 +0000158 public =
159 rebase_path(skcms_public_headers, ".", "//third_party/skia/modules/skcms")
160 sources = rebase_path(skcms_sources, ".", "//third_party/skia/modules/skcms")
Lei Zhang742f5b22018-10-31 16:41:24 +0000161}
162
dsinclair11988d72016-05-04 10:17:00 -0700163component("skia") {
Lei Zhang31bc9142023-04-05 18:42:27 +0000164 deps = []
165
dsinclair11988d72016-05-04 10:17:00 -0700166 sources = [
thestig19ea3092016-05-13 11:24:26 -0700167 # PDFium sources.
Lei Zhang0cd76722022-11-14 22:13:27 +0000168 "config/SkPdfiumUserConfig.h",
dsinclair11988d72016-05-04 10:17:00 -0700169 "ext/google_logging.cc",
170 ]
171
Lei Zhang65a21922017-04-15 21:30:32 -0700172 # The skia sources values are relative to the skia_dir, so we need to rebase.
K. Moon1852aa02022-11-10 18:56:52 +0000173 sources += skia_core_public
Lei Zhangdb9bec62019-07-16 19:14:45 +0000174 sources += skia_sksl_gpu_sources
ethannicholas52ef14e2016-10-12 13:08:18 -0700175 sources += skia_sksl_sources
Kevin Lubick53dcf782023-05-31 20:37:36 +0000176 sources += skia_utils_private
K. Moon505438b2023-06-30 22:20:28 +0000177 sources += skia_xps_sources
Kevin Lubickfe247d32023-01-11 18:48:21 +0000178 sources += skia_codec_core
179 sources += skia_codec_decode_bmp
Kevin Lubickf5756d32023-03-03 16:33:48 +0000180 sources += skia_encode_srcs
181 sources += skia_encode_png_srcs
brettw784548a2016-09-06 11:39:46 -0700182 sources += [
brettw784548a2016-09-06 11:39:46 -0700183 "//third_party/skia/src/fonts/SkFontMgr_indirect.cpp",
184 "//third_party/skia/src/fonts/SkRemotableFontMgr.cpp",
brettw784548a2016-09-06 11:39:46 -0700185 "//third_party/skia/src/ports/SkGlobalInitialization_default.cpp",
caryclark429a9ff2016-10-04 06:32:58 -0700186 "//third_party/skia/src/ports/SkImageGenerator_none.cpp",
brettw784548a2016-09-06 11:39:46 -0700187 "//third_party/skia/src/ports/SkOSFile_stdio.cpp",
brettw784548a2016-09-06 11:39:46 -0700188 "//third_party/skia/src/sfnt/SkOTTable_name.cpp",
189 "//third_party/skia/src/sfnt/SkOTUtils.cpp",
190
brettw784548a2016-09-06 11:39:46 -0700191 #pdfium
192 "//third_party/skia/src/ports/SkDiscardableMemory_none.cpp",
brettw784548a2016-09-06 11:39:46 -0700193 "//third_party/skia/src/ports/SkMemory_malloc.cpp",
194 ]
dsinclair11988d72016-05-04 10:17:00 -0700195
196 # This and skia_opts are really the same conceptual target so share headers.
197 allow_circular_includes_from = [ ":skia_opts" ]
198
dsinclair11988d72016-05-04 10:17:00 -0700199 # GPU
Kevin Lubick7f2d2812023-03-13 18:07:28 +0000200 if (skia_use_ganesh_backend) {
Kevin Lubickfe247d32023-01-11 18:48:21 +0000201 sources += skia_gpu_public
Kevin Lubick469cc8f2023-03-28 15:49:01 +0000202 sources += skia_ganesh_private
brettw784548a2016-09-06 11:39:46 -0700203 sources += skia_null_gpu_sources
Alan Screenc4988272021-12-01 16:37:36 +0000204 sources += skia_shared_gpu_sources
Lei Zhanga7070ff2019-12-05 21:43:44 +0000205 if (skia_use_gl) {
Kevin Lubickfe247d32023-01-11 18:48:21 +0000206 sources += skia_gpu_gl_public
207 sources += skia_gpu_gl_private
Lei Zhanga7070ff2019-12-05 21:43:44 +0000208 }
dsinclair11988d72016-05-04 10:17:00 -0700209 }
210
Lei Zhang65a21922017-04-15 21:30:32 -0700211 # Remove unused util files include in utils.gni
dsinclair11988d72016-05-04 10:17:00 -0700212 sources -= [
dsinclair11988d72016-05-04 10:17:00 -0700213 "//third_party/skia/src/utils/SkCamera.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700214 "//third_party/skia/src/utils/SkParsePath.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700215 ]
216
K. Moon505438b2023-06-30 22:20:28 +0000217 if (is_win) {
218 libs = [ "fontsub.lib" ]
219 }
220
dsinclair11988d72016-05-04 10:17:00 -0700221 # need separate win section to handle chromes auto gn filter
222 # (build/config/BUILDCONFIG.gn)
223 if (is_win) {
224 sources -= [
225 #windows
dsinclair11988d72016-05-04 10:17:00 -0700226 "//third_party/skia/src/utils/win/SkWGL_win.cpp",
227 ]
228 }
229
Lei Zhangb8928e42020-08-06 05:15:47 +0000230 # Select Skia ports.
231
232 # FreeType is needed everywhere (except on iOS), on Linux and Android as main
233 # font backend, on Windows and Mac as fallback backend for Variations.
234 if (!is_ios) {
235 sources += [
236 "//third_party/skia/src/ports/SkFontHost_FreeType.cpp",
237 "//third_party/skia/src/ports/SkFontHost_FreeType_common.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700238 ]
Lei Zhangb8928e42020-08-06 05:15:47 +0000239 }
240
241 if (is_win) {
242 sources += [
dsinclair11988d72016-05-04 10:17:00 -0700243 "//third_party/skia/src/ports/SkFontHost_win.cpp",
Alan Screen19e4ef42022-05-06 21:57:15 +0000244
245 # TODO(crbug.com/pdfium/1830) Consider using SkFontMgr_win_dw_factory
246 # instead of SkFontMgr_custom_empty (which is what the embedder test
247 # hashes are based upon).
248 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
249 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
250 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
Lei Zhangb8928e42020-08-06 05:15:47 +0000251 "//third_party/skia/src/ports/SkFontMgr_win_dw.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700252 "//third_party/skia/src/ports/SkOSFile_win.cpp",
253 "//third_party/skia/src/ports/SkRemotableFontMgr_win_dw.cpp",
254 "//third_party/skia/src/ports/SkScalerContext_win_dw.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700255 "//third_party/skia/src/ports/SkTypeface_win_dw.cpp",
256 ]
Lei Zhangb8928e42020-08-06 05:15:47 +0000257 } else {
Kevin Lubick18021e72022-08-19 20:12:49 +0000258 sources += [ "//third_party/skia/src/ports/SkOSFile_posix.cpp" ]
dsinclair11988d72016-05-04 10:17:00 -0700259 }
Lei Zhangb8928e42020-08-06 05:15:47 +0000260
Alan Screen19e4ef42022-05-06 21:57:15 +0000261 frameworks = []
Lei Zhangb8928e42020-08-06 05:15:47 +0000262 if (is_apple) {
Lei Zhangb8928e42020-08-06 05:15:47 +0000263 sources += [
Alan Screen19e4ef42022-05-06 21:57:15 +0000264 # TODO(crbug.com/pdfium/1830) Consider using SkFontMgr_mac_ct instead of
265 # SkFontMgr_custom_empty (which is what the embedder test hashes are
266 # based upon).
267 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
268 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
269 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
Lei Zhangb8928e42020-08-06 05:15:47 +0000270 "//third_party/skia/src/ports/SkScalerContext_mac_ct.cpp",
271 "//third_party/skia/src/ports/SkScalerContext_mac_ct.h",
272 "//third_party/skia/src/ports/SkTypeface_mac_ct.cpp",
273 "//third_party/skia/src/ports/SkTypeface_mac_ct.h",
274 ]
Alan Screen19e4ef42022-05-06 21:57:15 +0000275 frameworks += [
276 "CoreFoundation.framework",
277 "CoreGraphics.framework",
278 "CoreText.framework",
279 ]
Lei Zhangb8928e42020-08-06 05:15:47 +0000280 }
281
282 if (is_linux || is_chromeos) {
283 sources += [
284 "//third_party/skia/src/ports/SkFontConfigInterface.cpp",
285 "//third_party/skia/src/ports/SkFontConfigInterface_direct.cpp",
286 "//third_party/skia/src/ports/SkFontConfigInterface_direct_factory.cpp",
287 "//third_party/skia/src/ports/SkFontMgr_FontConfigInterface.cpp",
Alan Screen19e4ef42022-05-06 21:57:15 +0000288 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
289 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
290 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
Lei Zhangb8928e42020-08-06 05:15:47 +0000291 ]
292 }
293
Lei Zhang95656f92022-03-01 17:32:21 +0000294 if (is_android) {
Lei Zhangb8928e42020-08-06 05:15:47 +0000295 sources += [
Lei Zhang95656f92022-03-01 17:32:21 +0000296 # Unlike Chromium, standalone PDFium on Linux and Chrome OS does not
297 # require these files, since PDFium does not perform Android emulation.
Lei Zhangb8928e42020-08-06 05:15:47 +0000298 # Note that this requires expat.
299 "//third_party/skia/src/ports/SkFontMgr_android.cpp",
Alan Screen19e4ef42022-05-06 21:57:15 +0000300 "//third_party/skia/src/ports/SkFontMgr_android_factory.cpp",
Lei Zhangb8928e42020-08-06 05:15:47 +0000301 "//third_party/skia/src/ports/SkFontMgr_android_parser.cpp",
dsinclair11988d72016-05-04 10:17:00 -0700302 ]
303 }
304
Lei Zhang31bc9142023-04-05 18:42:27 +0000305 if (is_fuchsia) {
306 sources += [
307 # TODO(crbug.com/pdfium/2019): Consider using SkFontMgr_fuchsia.cpp
308 # instead of SkFontMgr_custom_empty.cpp.
309 "//third_party/skia/src/ports/SkFontMgr_custom.cpp",
310 "//third_party/skia/src/ports/SkFontMgr_custom_empty.cpp",
311 "//third_party/skia/src/ports/SkFontMgr_custom_empty_factory.cpp",
312 ]
313 deps += [
314 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.fonts:fuchsia.fonts_hlcpp",
315 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.io:fuchsia.io_hlcpp",
316 "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sys:fuchsia.sys_hlcpp",
317 "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
318 "//third_party/fuchsia-sdk/sdk/pkg/zx",
319 "//third_party/icu:icuuc",
320 ]
321 }
322
dsinclair11988d72016-05-04 10:17:00 -0700323 if (is_clang && !is_nacl) {
324 # Skia won't compile with some of the more strict clang warnings.
325 # e.g. it does:
326 # SkASSERT(!"sk_out_of_memory");
327 configs -= [ "//build/config/clang:extra_warnings" ]
328 }
329
330 configs -= [ "//build/config/compiler:chromium_code" ]
331 configs += [
332 ":skia_config",
333 ":skia_library_config",
334 "//build/config/compiler:no_chromium_code",
335 ]
336 public_configs = [ ":skia_config" ]
337
Lei Zhang31bc9142023-04-05 18:42:27 +0000338 deps += [
Lei Zhang742f5b22018-10-31 16:41:24 +0000339 ":skcms",
dsinclair11988d72016-05-04 10:17:00 -0700340 ":skia_opts",
K. Moonf446aae2022-11-16 18:15:11 +0000341 "../third_party:png",
Miklos Vajna2df760f2017-05-06 01:54:54 +0200342 "../third_party:zlib",
Lei Zhangeb39cdb2017-03-31 12:26:15 -0700343 "//:freetype_common",
dsinclair11988d72016-05-04 10:17:00 -0700344 ]
Lei Zhang40f9d722020-01-24 00:18:11 +0000345 public_deps = [ ":skia_core_and_effects" ]
dsinclair11988d72016-05-04 10:17:00 -0700346
Lei Zhang2f5f9552020-08-05 18:51:25 +0000347 if (is_linux || is_chromeos) {
Lei Zhange4e6d582022-03-01 17:48:00 +0000348 deps += [
349 "//third_party:fontconfig",
350 "//third_party/icu:icuuc",
351 ]
dsinclair11988d72016-05-04 10:17:00 -0700352 }
353
354 if (is_android) {
dsinclair11988d72016-05-04 10:17:00 -0700355 deps += [
Hui Yingst6c113512023-06-02 01:08:28 +0000356 "//third_party/cpu_features:ndk_compat",
dsinclair11988d72016-05-04 10:17:00 -0700357 "//third_party/expat",
dsinclair11988d72016-05-04 10:17:00 -0700358 ]
359 }
360
dsinclair11988d72016-05-04 10:17:00 -0700361 if (is_android && !is_debug) {
362 configs -= [ "//build/config/compiler:default_optimization" ]
363 configs += [ "//build/config/compiler:optimize_max" ]
364 }
365
366 if (is_ios) {
Alan Screen19e4ef42022-05-06 21:57:15 +0000367 frameworks += [ "ImageIO.framework" ]
dsinclair11988d72016-05-04 10:17:00 -0700368 }
Lei Zhang79263ca2018-10-31 16:40:24 +0000369
370 if (skia_support_pdf) {
371 deps += [ "//third_party/sfntly" ]
372 sources += skia_pdf_sources
373 } else {
374 sources += [ "//third_party/skia/src/pdf/SkDocument_PDF_None.cpp" ]
375 }
dsinclair11988d72016-05-04 10:17:00 -0700376}
377
Lei Zhangbd91edf2018-10-16 20:34:03 +0000378# Template for things that are logically part of :skia, but need to be split out
379# so custom compile flags can be applied.
380#
381# These are all opted out of check_includes, due to (logically) being part of
382# skia.
383template("skia_source_set") {
384 source_set(target_name) {
385 forward_variables_from(invoker, "*")
386
387 check_includes = false
388
389 if (!is_debug) {
390 configs -= [ "//build/config/compiler:default_optimization" ]
391 configs += [ "//build/config/compiler:optimize_max" ]
392 }
393
394 configs -= [ "//build/config/compiler:chromium_code" ]
395 configs += [
396 ":skia_config",
397 ":skia_library_config",
398 "//build/config/compiler:no_chromium_code",
399 ]
400 public_configs = [ ":skia_config" ]
Lei Zhangf02c8c92019-12-05 19:14:23 +0000401
402 if (is_win) {
403 cflags_cc = [
Lei Zhang95cf31b2020-04-23 16:42:38 +0000404 "/wd5041", # out-of-line definition for constexpr static data member is
405 # not needed and is deprecated in C++17
Lei Zhangf02c8c92019-12-05 19:14:23 +0000406 ]
Lei Zhangf02c8c92019-12-05 19:14:23 +0000407 }
Lei Zhangbd91edf2018-10-16 20:34:03 +0000408 }
409}
410
411skia_source_set("skia_core_and_effects") {
Kevin Lubick0fb4f6a2022-08-15 20:56:25 +0000412 defines = []
Lei Zhangbd91edf2018-10-16 20:34:03 +0000413 sources = skia_core_sources
414 sources += skia_effects_sources
Kevin Lubick53dcf782023-05-31 20:37:36 +0000415 sources += skia_colorfilters_sources
Hui Yingst4b062022023-06-27 00:42:15 +0000416 sources += skia_colorfilters_sksl_sources
Lei Zhanged086522018-11-01 14:58:49 +0000417 sources += skia_effects_imagefilter_sources
Lei Zhangbd91edf2018-10-16 20:34:03 +0000418
419 visibility = [ ":skia" ]
420}
421
K. Moonb33a5a62022-11-02 18:53:06 +0000422# Bits that involve special vector-y hardware.
dsinclair11988d72016-05-04 10:17:00 -0700423if (current_cpu == "x86" || current_cpu == "x64") {
Lei Zhangbd91edf2018-10-16 20:34:03 +0000424 skia_source_set("skia_opts_sse3") {
brettw784548a2016-09-06 11:39:46 -0700425 sources = skia_opts.ssse3_sources
dsinclair11988d72016-05-04 10:17:00 -0700426 if (!is_win || is_clang) {
427 cflags = [ "-mssse3" ]
428 }
429 if (is_win) {
430 defines = [ "SK_CPU_SSE_LEVEL=31" ]
431 }
432 visibility = [ ":skia_opts" ]
dsinclair11988d72016-05-04 10:17:00 -0700433 }
Lei Zhangbd91edf2018-10-16 20:34:03 +0000434 skia_source_set("skia_opts_avx") {
brettw784548a2016-09-06 11:39:46 -0700435 sources = skia_opts.avx_sources
dsinclair11988d72016-05-04 10:17:00 -0700436 if (!is_win) {
437 cflags = [ "-mavx" ]
438 }
439 if (is_win) {
440 cflags = [ "/arch:AVX" ]
441 }
442 visibility = [ ":skia_opts" ]
dsinclair11988d72016-05-04 10:17:00 -0700443 }
Lei Zhangbd91edf2018-10-16 20:34:03 +0000444 skia_source_set("skia_opts_hsw") {
caryclark429a9ff2016-10-04 06:32:58 -0700445 sources = skia_opts.hsw_sources
dsinclair11988d72016-05-04 10:17:00 -0700446 if (!is_win) {
caryclark429a9ff2016-10-04 06:32:58 -0700447 cflags = [
448 "-mavx2",
449 "-mbmi",
450 "-mbmi2",
451 "-mf16c",
452 "-mfma",
453 ]
dsinclair11988d72016-05-04 10:17:00 -0700454 }
455 if (is_win) {
456 cflags = [ "/arch:AVX2" ]
457 }
458 visibility = [ ":skia_opts" ]
dsinclair11988d72016-05-04 10:17:00 -0700459 }
460}
Lei Zhangbd91edf2018-10-16 20:34:03 +0000461
462skia_source_set("skia_opts") {
dsinclair11988d72016-05-04 10:17:00 -0700463 cflags = []
464 defines = []
465
466 if (current_cpu == "x86" || current_cpu == "x64") {
dsinclair11988d72016-05-04 10:17:00 -0700467 deps = [
468 ":skia_opts_avx",
caryclark429a9ff2016-10-04 06:32:58 -0700469 ":skia_opts_hsw",
dsinclair11988d72016-05-04 10:17:00 -0700470 ":skia_opts_sse3",
dsinclair11988d72016-05-04 10:17:00 -0700471 ]
472 } else if (current_cpu == "arm") {
473 # The assembly uses the frame pointer register (r7 in Thumb/r11 in
474 # ARM), the compiler doesn't like that.
475 cflags += [ "-fomit-frame-pointer" ]
476
477 if (arm_version >= 7) {
dsinclair11988d72016-05-04 10:17:00 -0700478 if (arm_use_neon || arm_optionally_use_neon) {
dsinclair11988d72016-05-04 10:17:00 -0700479 # Root build config sets -mfpu=$arm_fpu, which we expect to be neon
480 # when running this.
481 if (!arm_use_neon) {
482 configs -= [ "//build/config/compiler:compiler_arm_fpu" ]
483 cflags += [ "-mfpu=neon" ]
484 }
485 }
dsinclair11988d72016-05-04 10:17:00 -0700486 }
487 } else if (current_cpu == "arm64") {
Brian Osman8172e302023-05-23 22:24:54 +0000488 # Conditional and empty body needed to avoid assert below
Kevin Lubicke6e3ca02022-09-15 18:48:40 +0000489 } else if (current_cpu == "mipsel" || current_cpu == "mips64el") {
dsinclair11988d72016-05-04 10:17:00 -0700490 cflags += [ "-fomit-frame-pointer" ]
dsinclair11988d72016-05-04 10:17:00 -0700491 } else {
Kevin Lubicke6e3ca02022-09-15 18:48:40 +0000492 assert(false, "Unsupported target CPU " + current_cpu)
dsinclair11988d72016-05-04 10:17:00 -0700493 }
494
495 if (is_android && !is_debug) {
496 configs -= [ "//build/config/compiler:default_optimization" ]
497 configs += [ "//build/config/compiler:optimize_max" ]
498 }
499
dsinclair11988d72016-05-04 10:17:00 -0700500 visibility = [ ":skia" ]
501}