Create mini-skia for RenderEngine

Bug: b/167743764

Android's RenderEngine is now using Skia, but it doesn't need all the
pieces of Skia used by HWUI. Make a smaller version of Skia that
excludes many of those pieces, in particular where they bring in other
dependencies:
- codecs
- text
- pdf
- xml

Add a new cc_defaults to be shared by the new libskia_mini and libskia.

Manually insert fexceptions into libskia, since it is only needed by
SkRawCodec (not needed by mini).

Add a new SkUserConfig for mini, so it can exclude defines like
SK_CODEC_DECODES_PNG.

Continue to link in libpng (and libz, which it depends on) and build
SkPngEncoder, so that SKP captures can include compressed image files.

Switching to the mini-skia reduces the size of surfaceflinger from 7.4M
to 6.0M.

Change-Id: I6843ee43457b5a0feb36ae88a59d1d61770a6247
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402257
Commit-Queue: Leon Scroggins <scroggo@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
Leon Scroggins III 2021-01-29 15:33:00 -05:00 committed by Skia Commit-Bot
parent 8c281fbd03
commit 6c41bf55b7
2 changed files with 125 additions and 39 deletions

View File

@ -25,9 +25,8 @@ bp = string.Template('''// This file is autogenerated by gn_to_bp.py.
// files it uses) and submit. The autoroller will then create the updated // files it uses) and submit. The autoroller will then create the updated
// Android.bp. Or ask a Skia engineer for help. // Android.bp. Or ask a Skia engineer for help.
cc_library_static { cc_defaults {
name: "libskia", name: "skia_defaults",
host_supported: true,
cflags: [ cflags: [
$cflags $cflags
], ],
@ -44,10 +43,6 @@ cc_library_static {
$local_includes $local_includes
], ],
srcs: [
$srcs
],
arch: { arch: {
arm: { arm: {
srcs: [ srcs: [
@ -83,13 +78,53 @@ cc_library_static {
target: { target: {
android: { android: {
srcs: [ srcs: [
$android_srcs
"third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp", "third_party/vulkanmemoryallocator/GrVulkanMemoryAllocator.cpp",
], ],
local_include_dirs: [ local_include_dirs: [
"android",
"third_party/vulkanmemoryallocator/", "third_party/vulkanmemoryallocator/",
], ],
},
},
}
cc_library_static {
// Smaller version of Skia, without e.g. codecs, intended for use by RenderEngine.
name: "libskia_renderengine",
defaults: ["skia_defaults",
"skia_renderengine_deps"],
srcs: [
$renderengine_srcs
],
local_include_dirs: [
"renderengine",
],
export_include_dirs: [
"renderengine",
],
}
cc_library_static {
name: "libskia",
host_supported: true,
cppflags:[
// Exceptions are necessary for SkRawCodec.
// FIXME: Should we split SkRawCodec into a separate target so the rest
// of Skia need not be compiled with exceptions?
"-fexceptions",
],
srcs: [
$srcs
],
target: {
android: {
srcs: [
$android_srcs
],
local_include_dirs: [
"android",
],
export_include_dirs: [ export_include_dirs: [
"android", "android",
], ],
@ -142,6 +177,7 @@ cc_library_static {
defaults: ["skia_deps", defaults: ["skia_deps",
"skia_pgo", "skia_pgo",
"skia_defaults",
], ],
} }
@ -172,23 +208,20 @@ cc_defaults {
} }
cc_defaults { cc_defaults {
name: "skia_deps", // Subset of the larger "skia_deps", which includes only the dependencies
// needed for libskia_renderengine. Note that it includes libpng and libz
// for the purposes of MSKP captures, but we could instead leave it up to
// RenderEngine to provide its own SkSerializerProcs if another client
// wants an even smaller version of libskia.
name: "skia_renderengine_deps",
shared_libs: [ shared_libs: [
"libcutils", "libcutils",
"libdng_sdk",
"libexpat",
"libft2",
"libjpeg",
"liblog", "liblog",
"libpiex",
"libpng", "libpng",
"libz", "libz",
], ],
static_libs: [ static_libs: [
"libarect", "libarect",
"libsfntly",
"libwebp-decode",
"libwebp-encode",
], ],
group_static_libs: true, group_static_libs: true,
target: { target: {
@ -196,7 +229,6 @@ cc_defaults {
shared_libs: [ shared_libs: [
"libEGL", "libEGL",
"libGLESv2", "libGLESv2",
"libheif",
"libvulkan", "libvulkan",
"libnativewindow", "libnativewindow",
], ],
@ -204,6 +236,30 @@ cc_defaults {
"libvulkan", "libvulkan",
], ],
}, },
},
}
cc_defaults {
name: "skia_deps",
defaults: ["skia_renderengine_deps"],
shared_libs: [
"libdng_sdk",
"libjpeg",
"libpiex",
"libexpat",
"libft2",
],
static_libs: [
"libwebp-decode",
"libwebp-encode",
"libsfntly",
],
target: {
android: {
shared_libs: [
"libheif",
],
},
darwin: { darwin: {
host_ldlibs: [ host_ldlibs: [
"-framework AppKit", "-framework AppKit",
@ -291,7 +347,7 @@ cc_test {
}''') }''')
# We'll run GN to get the main source lists and include directories for Skia. # We'll run GN to get the main source lists and include directories for Skia.
def generate_args(target_os, enable_gpu): def generate_args(target_os, enable_gpu, renderengine = False):
d = { d = {
'is_official_build': 'true', 'is_official_build': 'true',
@ -299,11 +355,9 @@ def generate_args(target_os, enable_gpu):
# files. # files.
'target_cpu': '"none"', 'target_cpu': '"none"',
'skia_enable_android_utils': 'true',
# Use the custom FontMgr, as the framework will handle fonts. # Use the custom FontMgr, as the framework will handle fonts.
'skia_enable_fontmgr_custom_directory': 'false', 'skia_enable_fontmgr_custom_directory': 'false',
'skia_enable_fontmgr_custom_embedded': 'false', 'skia_enable_fontmgr_custom_embedded': 'false',
'skia_enable_fontmgr_custom_empty': 'true',
'skia_enable_fontmgr_android': 'false', 'skia_enable_fontmgr_android': 'false',
'skia_enable_fontmgr_win': 'false', 'skia_enable_fontmgr_win': 'false',
'skia_enable_fontmgr_win_gdi': 'false', 'skia_enable_fontmgr_win_gdi': 'false',
@ -312,19 +366,14 @@ def generate_args(target_os, enable_gpu):
# enable features used in skia_nanobench # enable features used in skia_nanobench
'skia_tools_require_resources': 'true', 'skia_tools_require_resources': 'true',
'skia_use_freetype': 'true',
'skia_use_fontconfig': 'false', 'skia_use_fontconfig': 'false',
'skia_use_fixed_gamma_text': 'true',
'skia_include_multiframe_procs': 'false', 'skia_include_multiframe_procs': 'false',
'skia_libgifcodec_path': '"third_party/libgifcodec"', 'skia_libgifcodec_path': '"third_party/libgifcodec"',
} }
d['target_os'] = target_os d['target_os'] = target_os
if target_os == '"android"': if target_os == '"android"':
d['skia_enable_tools'] = 'true' d['skia_enable_tools'] = 'true'
d['skia_use_libheif'] = 'true'
d['skia_include_multiframe_procs'] = 'true' d['skia_include_multiframe_procs'] = 'true'
else:
d['skia_use_libheif'] = 'false'
if enable_gpu: if enable_gpu:
d['skia_use_vulkan'] = 'true' d['skia_use_vulkan'] = 'true'
@ -342,12 +391,37 @@ def generate_args(target_os, enable_gpu):
d['win_vc'] = '"placeholder_version"' d['win_vc'] = '"placeholder_version"'
d['win_sdk_version'] = '"placeholder_version"' d['win_sdk_version'] = '"placeholder_version"'
d['win_toolchain_version'] = '"placeholder_version"' d['win_toolchain_version'] = '"placeholder_version"'
if target_os == '"android"' and not renderengine:
d['skia_use_libheif'] = 'true'
else:
d['skia_use_libheif'] = 'false'
if renderengine:
d['skia_use_libpng_decode'] = 'false'
d['skia_use_libjpeg_turbo_decode'] = 'false'
d['skia_use_libjpeg_turbo_encode'] = 'false'
d['skia_use_libwebp_decode'] = 'false'
d['skia_use_libwebp_encode'] = 'false'
d['skia_use_libgifcodec'] = 'false'
d['skia_enable_pdf'] = 'false'
d['skia_use_freetype'] = 'false'
d['skia_use_fixed_gamma_text'] = 'false'
d['skia_use_expat'] = 'false'
d['skia_enable_fontmgr_custom_empty'] = 'false'
else:
d['skia_enable_android_utils'] = 'true'
d['skia_use_freetype'] = 'true'
d['skia_use_fixed_gamma_text'] = 'true'
d['skia_enable_fontmgr_custom_empty'] = 'true'
return d return d
gn_args = generate_args('"android"', True) gn_args = generate_args('"android"', True)
gn_args_linux = generate_args('"linux"', False) gn_args_linux = generate_args('"linux"', False)
gn_args_mac = generate_args('"mac"', False) gn_args_mac = generate_args('"mac"', False)
gn_args_win = generate_args('"win"', False) gn_args_win = generate_args('"win"', False)
gn_args_renderengine = generate_args('"android"', True, True)
js = gn_to_bp_utils.GenerateJSONFromGN(gn_args) js = gn_to_bp_utils.GenerateJSONFromGN(gn_args)
@ -406,6 +480,14 @@ android_srcs = android_srcs.difference(srcs)
linux_srcs = linux_srcs.difference(srcs) linux_srcs = linux_srcs.difference(srcs)
mac_srcs = mac_srcs.difference(srcs) mac_srcs = mac_srcs.difference(srcs)
win_srcs = win_srcs.difference(srcs) win_srcs = win_srcs.difference(srcs)
js_renderengine = gn_to_bp_utils.GenerateJSONFromGN(gn_args_renderengine)
renderengine_srcs = strip_slashes(
js_renderengine['targets']['//:skia']['sources'])
gn_to_bp_utils.GrabDependentValues(js_renderengine, '//:skia', 'sources',
renderengine_srcs, None)
renderengine_srcs = strip_headers(renderengine_srcs)
dm_srcs = strip_headers(dm_srcs) dm_srcs = strip_headers(dm_srcs)
nanobench_srcs = strip_headers(nanobench_srcs) nanobench_srcs = strip_headers(nanobench_srcs)
@ -417,10 +499,11 @@ defs = gn_to_bp_utils.GetArchSources(os.path.join(here, 'opts.gni'))
def get_defines(json): def get_defines(json):
return {str(d) for d in json['targets']['//:skia']['defines']} return {str(d) for d in json['targets']['//:skia']['defines']}
android_defines = get_defines(js) android_defines = get_defines(js)
linux_defines = get_defines(js_linux) linux_defines = get_defines(js_linux)
mac_defines = get_defines(js_mac) mac_defines = get_defines(js_mac)
win_defines = get_defines(js_win) win_defines = get_defines(js_win)
renderengine_defines = get_defines(js_renderengine)
def mkdir_if_not_exists(path): def mkdir_if_not_exists(path):
if not os.path.exists(path): if not os.path.exists(path):
@ -429,6 +512,7 @@ mkdir_if_not_exists('android/include/config/')
mkdir_if_not_exists('linux/include/config/') mkdir_if_not_exists('linux/include/config/')
mkdir_if_not_exists('mac/include/config/') mkdir_if_not_exists('mac/include/config/')
mkdir_if_not_exists('win/include/config/') mkdir_if_not_exists('win/include/config/')
mkdir_if_not_exists('renderengine/include/config/')
platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' } platforms = { 'IOS', 'MAC', 'WIN', 'ANDROID', 'UNIX' }
@ -450,13 +534,16 @@ def append_to_file(config, s):
with open(config, 'a') as f: with open(config, 'a') as f:
print(s, file=f) print(s, file=f)
android_config = 'android/include/config/SkUserConfig.h' def write_android_config(config_path, defines):
gn_to_bp_utils.WriteUserConfig(android_config, android_defines) gn_to_bp_utils.WriteUserConfig(config_path, defines)
append_to_file(android_config, ''' append_to_file(config_path, '''
#ifndef SK_BUILD_FOR_ANDROID #ifndef SK_BUILD_FOR_ANDROID
#error "SK_BUILD_FOR_ANDROID must be defined!" #error "SK_BUILD_FOR_ANDROID must be defined!"
#endif''') #endif''')
disallow_platforms(android_config, 'ANDROID') disallow_platforms(config_path, 'ANDROID')
write_android_config('android/include/config/SkUserConfig.h', android_defines)
write_android_config('renderengine/include/config/SkUserConfig.h', renderengine_defines)
def write_config(config_path, defines, platform): def write_config(config_path, defines, platform):
gn_to_bp_utils.WriteUserConfig(config_path, defines) gn_to_bp_utils.WriteUserConfig(config_path, defines)
@ -512,4 +599,6 @@ with open('Android.bp', 'w') as Android_bp:
'linux_srcs': bpfmt(10, linux_srcs), 'linux_srcs': bpfmt(10, linux_srcs),
'mac_srcs': bpfmt(10, mac_srcs), 'mac_srcs': bpfmt(10, mac_srcs),
'win_srcs': bpfmt(10, win_srcs), 'win_srcs': bpfmt(10, win_srcs),
'renderengine_srcs': bpfmt(8, renderengine_srcs),
}), file=Android_bp) }), file=Android_bp)

View File

@ -75,10 +75,7 @@ def CleanupCFlags(cflags):
def CleanupCCFlags(cflags_cc): def CleanupCCFlags(cflags_cc):
# Only use the generated flags related to warnings. # Only use the generated flags related to warnings.
cflags_cc = {s for s in cflags_cc if s.startswith('-W')} return {s for s in cflags_cc if s.startswith('-W')}
# Add the rest of the flags we want.
cflags_cc.add("-fexceptions")
return cflags_cc
def _get_path_info(path, kind): def _get_path_info(path, kind):
assert path == "../src" assert path == "../src"