diff --git a/BUILD.bazel b/BUILD.bazel index aa048009adcb..08b8ca222493 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,10 +1,28 @@ load("//:defines.bzl", "DEFAULT_DEFINES", "DEFAULT_LOCAL_DEFINES") -load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library") +load("@skia_user_config//:copts.bzl", "DEFAULT_OBJC_COPTS") +load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library", "skia_objc_library") licenses(["notice"]) exports_files_legacy() +# All the mm files from the Skia library are rolled up to this objc library since cc_library +# ignores mm files. This private library is then deps'ed into the public and internal versions +# of the SKia library below. The Skia library Objective-C code requires ARC, while non-library code +# does not. +skia_objc_library( + name = "skia_objc", + srcs = [ + "//src:objc_srcs", + ], + copts = DEFAULT_OBJC_COPTS + ["-fobjc-arc"], + defines = DEFAULT_DEFINES, + deps = [ + "//src:deps", + "@skia_user_config//:user_config", + ], +) + # This target exposes the Skia public API. It is what external clients should use. skia_cc_library( name = "skia_public", @@ -21,7 +39,10 @@ skia_cc_library( deps = [ "//src:deps", "@skia_user_config//:user_config", - ], + ] + select({ + "//src/gpu:metal_backend": ["//:skia_objc"], + "//conditions:default": [], + }), ) # This target exposes headers beyond the public, supported API. It is intended to be @@ -48,7 +69,10 @@ skia_cc_library( deps = [ "//src:deps", "@skia_user_config//:user_config", - ], + ] + select({ + "//src/gpu:metal_backend": ["//:skia_objc"], + "//conditions:default": [], + }), ) #################################################################### diff --git a/bazel/buildrc b/bazel/buildrc index c57985c481f1..68d31bf672ca 100644 --- a/bazel/buildrc +++ b/bazel/buildrc @@ -132,6 +132,9 @@ build:vulkan_ganesh --enable_gpu_test_utils --gpu_backend=vulkan_backend \ build:dawn_ganesh --enable_gpu_test_utils --gpu_backend=dawn_backend \ --cc_output_directory_tag=dawn_ganesh +build:metal_ganesh --enable_gpu_test_utils --gpu_backend=metal_backend \ + --cc_output_directory_tag=metal_ganesh + # Short-hand aliases build:cpu --config=cpu_only build:gl --config=gl_ganesh diff --git a/bazel/exporter_tool/main.go b/bazel/exporter_tool/main.go index 62903a4c759f..58d421ab309a 100644 --- a/bazel/exporter_tool/main.go +++ b/bazel/exporter_tool/main.go @@ -356,7 +356,8 @@ var gniExportDescs = []exporter.GNIExportDesc{ }}, {Var: "skia_gpu_metal_private", Rules: []string{ - "//src/gpu/ganesh/surface:mtl_srcs", + "//include/private/gpu/ganesh:mtl_private_hdrs", + "//src/gpu/ganesh/surface:mtl_objc_srcs", "//src/gpu/ganesh/mtl:mtl_hdrs", "//src/gpu/ganesh/mtl:mtl_srcs", }}, @@ -403,7 +404,8 @@ var gniExportDescs = []exporter.GNIExportDesc{ {Var: "skia_shared_mtl_sources", Rules: []string{ "//include/gpu/mtl:shared_public_hdrs", - "//src/gpu/mtl:shared_srcs", + "//src/gpu/mtl:mtl_hdrs", + "//src/gpu/mtl:mtl_srcs", }}, {Var: "skia_piet_gpu_sources", Rules: []string{ diff --git a/bazel/skia_rules.bzl b/bazel/skia_rules.bzl index f3fd82465f96..167eba00cf54 100644 --- a/bazel/skia_rules.bzl +++ b/bazel/skia_rules.bzl @@ -153,7 +153,7 @@ def skia_filegroup(**kwargs): native.filegroup(**kwargs) def skia_objc_library(name, copts = DEFAULT_OBJC_COPTS, **kwargs): - """A wrapper around cc_library for Skia Objective C libraries. + """A wrapper around objc_library for Skia Objective C libraries. This lets us provide compiler flags (copts) consistently to the Skia build (e.g. //:skia_public) and builds which depend on those targets (e.g. things in //tools or //modules). diff --git a/defines.bzl b/defines.bzl index 34a42bae3603..d4a0fcc0c1f5 100644 --- a/defines.bzl +++ b/defines.bzl @@ -76,6 +76,10 @@ GPU_DEFINES = select_multi({ "SK_GANESH", "VK_USE_PLATFORM_XCB_KHR", # TODO(kjlubick) support dawn's dawn_enable_vulkan etc ], + "//src/gpu:metal_backend": [ + "SK_METAL", + "SK_GANESH", + ], }) + select({ "//src/gpu:gl_standard": [ "SK_ASSUME_GL=1", diff --git a/example/BUILD.bazel b/example/BUILD.bazel index 7afe24100b57..b1d2d5db2906 100644 --- a/example/BUILD.bazel +++ b/example/BUILD.bazel @@ -84,6 +84,32 @@ cc_binary_with_flags( ], ) +cc_binary_with_flags( + name = "hello_world_metal", + testonly = True, + srcs = [ + "HelloWorld.cpp", + "HelloWorld.h", + ], + # These flags are defined in //bazel/common_config_settings/BUILD.bazel + set_flags = { + "gpu_backend": [ + "metal_backend", + ], + # Load fonts from the standard system directory (e.g. "/usr/share/fonts/") + # as defined in //src/ports/SkFontMgr_custom_directory_factory.cpp + "fontmgr_factory": [ + "custom_directory_fontmgr_factory", + ], + }, + deps = [ + "//:skia_public", + ] + select({ + "@platforms//os:macos": ["//tools/sk_app:sk_app_objc"], + "//conditions:default": [], + }), +) + cc_binary_with_flags( name = "vulkan_basic", testonly = True, diff --git a/gn/gpu.gni b/gn/gpu.gni index 1d98598e912c..abf410f58a30 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -907,10 +907,12 @@ skia_gpu_metal_public = [ ] # List generated by Bazel rules: -# //src/gpu/ganesh/surface:mtl_srcs +# //include/private/gpu/ganesh:mtl_private_hdrs +# //src/gpu/ganesh/surface:mtl_objc_srcs # //src/gpu/ganesh/mtl:mtl_hdrs # //src/gpu/ganesh/mtl:mtl_srcs skia_gpu_metal_private = [ + "$_include/private/gpu/ganesh/GrMtlTypesPriv.h", "$_src/gpu/ganesh/mtl/GrMtlAttachment.h", "$_src/gpu/ganesh/mtl/GrMtlAttachment.mm", "$_src/gpu/ganesh/mtl/GrMtlBuffer.h", @@ -1096,7 +1098,8 @@ skia_shared_vk_sources = [ # List generated by Bazel rules: # //include/gpu/mtl:shared_public_hdrs -# //src/gpu/mtl:shared_srcs +# //src/gpu/mtl:mtl_hdrs +# //src/gpu/mtl:mtl_srcs skia_shared_mtl_sources = [ "$_include/gpu/mtl/MtlMemoryAllocator.h", "$_src/gpu/mtl/MtlMemoryAllocatorImpl.h", diff --git a/include/gpu/BUILD.bazel b/include/gpu/BUILD.bazel index 1550ef4bbf35..4d3883fede18 100644 --- a/include/gpu/BUILD.bazel +++ b/include/gpu/BUILD.bazel @@ -39,7 +39,8 @@ skia_filegroup( { "//src/gpu:dawn_backend": ["//include/gpu/dawn:public_hdrs"], "//src/gpu:vulkan_backend": ["//include/gpu/vk:public_hdrs"], - # TODO(kjlubick) mtl and d3d backend + "//src/gpu:metal_backend": ["//include/gpu/mtl:public_hdrs"], + # TODO(kjlubick) d3d backend }, ), visibility = ["//include:__pkg__"], diff --git a/include/gpu/mtl/BUILD.bazel b/include/gpu/mtl/BUILD.bazel index 4331c46d7747..26b08926d027 100644 --- a/include/gpu/mtl/BUILD.bazel +++ b/include/gpu/mtl/BUILD.bazel @@ -4,7 +4,6 @@ licenses(["notice"]) exports_files_legacy() -# Not referenced by Bazel target. # for exporting to //gn/gpu.gni:skia_shared_mtl_sources. skia_filegroup( name = "shared_public_hdrs", @@ -13,12 +12,13 @@ skia_filegroup( ], ) -# Not referenced by Bazel target. -# for exporting to //gn/gpu.gni:skia_metal_sources. +# Group is exported to //gn/gpu.gni:skia_gpu_metal_public. skia_filegroup( name = "public_hdrs", srcs = [ "GrMtlBackendContext.h", "GrMtlTypes.h", + ":shared_public_hdrs", ], + visibility = ["//include/gpu:__pkg__"], ) diff --git a/include/private/gpu/ganesh/BUILD.bazel b/include/private/gpu/ganesh/BUILD.bazel index 240687c90869..f9bed76da0fc 100644 --- a/include/private/gpu/ganesh/BUILD.bazel +++ b/include/private/gpu/ganesh/BUILD.bazel @@ -22,6 +22,12 @@ skia_filegroup( srcs = ["GrD3DTypesMinimal.h"], ) +# In own group for mapping to //gn/gpu.gni:skia_gpu_metal_private. +skia_filegroup( + name = "mtl_private_hdrs", + srcs = ["GrMtlTypesPriv.h"], +) + skia_filegroup( name = "private_hdrs", srcs = [ @@ -35,7 +41,8 @@ skia_filegroup( "//src/gpu:dawn_backend": [":dawn_private_hdrs"], "//src/gpu:gl_backend": ["GrGLTypesPriv.h"], "//src/gpu:vulkan_backend": [":vk_private_hdrs"], - # TODO(kjlubick) Direct3D and Metal Backends + "//src/gpu:metal_backend": [":mtl_private_hdrs"], + # TODO(kjlubick) Direct3D Backend }, ), visibility = ["//include/private/gpu:__pkg__"], diff --git a/src/BUILD.bazel b/src/BUILD.bazel index a87d9e6bdd9d..b904f2695d23 100644 --- a/src/BUILD.bazel +++ b/src/BUILD.bazel @@ -60,6 +60,15 @@ skia_filegroup( visibility = ["//:__pkg__"], ) +skia_filegroup( + name = "objc_srcs", + srcs = select({ + "//src/gpu:has_gpu_backend": ["//src/gpu:objc_srcs"], + "//conditions:default": [], + }), + visibility = ["//:__pkg__"], +) + skia_filegroup( name = "private_hdrs", srcs = [ diff --git a/src/gpu/BUILD.bazel b/src/gpu/BUILD.bazel index d18836e93ceb..ddcdfc6ca50f 100644 --- a/src/gpu/BUILD.bazel +++ b/src/gpu/BUILD.bazel @@ -55,6 +55,7 @@ string_flag_with_values( "gl_backend", "vulkan_backend", "dawn_backend", + "metal_backend", ], ) @@ -73,6 +74,7 @@ selects.config_setting_group( ":gl_backend", ":dawn_backend", ":vulkan_backend", + ":metal_backend", ], visibility = ["//:__subpackages__"], ) @@ -113,6 +115,15 @@ skia_filegroup( visibility = ["//src:__pkg__"], ) +skia_filegroup( + name = "objc_srcs", + srcs = [ + "//src/gpu/ganesh:objc_srcs", + "//src/gpu/mtl:shared_objc_srcs", + ], + visibility = ["//src:__pkg__"], +) + skia_filegroup( name = "private_hdrs", srcs = [ @@ -124,6 +135,7 @@ skia_filegroup( { "//src/gpu:dawn_backend": ["//src/gpu/dawn:private_hdrs"], "//src/gpu:vulkan_backend": ["//src/gpu/vk:private_hdrs"], + "//src/gpu:metal_backend": ["//src/gpu/mtl:private_hdrs"], }, ), visibility = ["//src:__pkg__"], diff --git a/src/gpu/ganesh/BUILD.bazel b/src/gpu/ganesh/BUILD.bazel index 284e5006c9e8..ddfb232e2347 100644 --- a/src/gpu/ganesh/BUILD.bazel +++ b/src/gpu/ganesh/BUILD.bazel @@ -278,7 +278,20 @@ skia_filegroup( "//src/gpu:dawn_backend": ["//src/gpu/ganesh/dawn:srcs"], "//src/gpu:gl_backend": ["//src/gpu/ganesh/gl:srcs"], "//src/gpu:vulkan_backend": ["//src/gpu/ganesh/vk:srcs"], - # TODO(kjlubick) mtl and d3d backend + # TODO(kjlubick) d3d backend + }, + ), + visibility = ["//src/gpu:__pkg__"], +) + +skia_filegroup( + name = "objc_srcs", + srcs = select_multi( + { + "//src/gpu:metal_backend": [ + "//src/gpu/ganesh/mtl:objc_srcs", + "//src/gpu/ganesh/surface:mtl_objc_srcs", + ], }, ), visibility = ["//src/gpu:__pkg__"], @@ -304,7 +317,8 @@ skia_filegroup( "//src/gpu:dawn_backend": ["//src/gpu/ganesh/dawn:private_hdrs"], "//src/gpu:gl_backend": ["//src/gpu/ganesh/gl:private_hdrs"], "//src/gpu:vulkan_backend": ["//src/gpu/ganesh/vk:private_hdrs"], - # TODO(kjlubick) mtl and d3d backend + "//src/gpu:metal_backend": ["//src/gpu/ganesh/mtl:private_hdrs"], + # TODO(kjlubick) d3d backend }, ), visibility = ["//src/gpu:__pkg__"], diff --git a/src/gpu/ganesh/mtl/BUILD.bazel b/src/gpu/ganesh/mtl/BUILD.bazel index 8a91e60d75ee..c503e15c1058 100644 --- a/src/gpu/ganesh/mtl/BUILD.bazel +++ b/src/gpu/ganesh/mtl/BUILD.bazel @@ -15,8 +15,6 @@ skia_filegroup( ], ) -# Not currently in a Bazel target. -# This list is exported to to gpu.gni:skia_metal_sources. MTL_FILES = [ "GrMtlAttachment.h", "GrMtlAttachment.mm", @@ -68,3 +66,20 @@ split_srcs_and_hdrs( name = "mtl", files = MTL_FILES, ) + +skia_filegroup( + name = "objc_srcs", + srcs = [ + ":mtl_srcs", + ], + visibility = ["//src/gpu/ganesh:__pkg__"], +) + +skia_filegroup( + name = "private_hdrs", + srcs = [ + ":mtl_cpp_hdrs", + ":mtl_hdrs", + ], + visibility = ["//src/gpu/ganesh:__pkg__"], +) diff --git a/src/gpu/ganesh/surface/BUILD.bazel b/src/gpu/ganesh/surface/BUILD.bazel index 66a3fc3f724c..a36aa0848370 100644 --- a/src/gpu/ganesh/surface/BUILD.bazel +++ b/src/gpu/ganesh/surface/BUILD.bazel @@ -14,11 +14,11 @@ split_srcs_and_hdrs( files = SURFACE_FILES, ) -# Not referenced by Bazel target. # File group use to export to //gn/gpu.gni:skia_metal_sources. skia_filegroup( - name = "mtl_srcs", + name = "mtl_objc_srcs", srcs = ["SkSurface_GaneshMtl.mm"], + visibility = ["//src/gpu/ganesh:__pkg__"], ) skia_filegroup( diff --git a/src/gpu/mtl/BUILD.bazel b/src/gpu/mtl/BUILD.bazel index e790ce884e55..f8f30311d0b6 100644 --- a/src/gpu/mtl/BUILD.bazel +++ b/src/gpu/mtl/BUILD.bazel @@ -1,17 +1,29 @@ -load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup") +load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_filegroup", "split_srcs_and_hdrs") licenses(["notice"]) exports_files_legacy() -# Not referenced by Bazel target. -# for exporting to //gn/gpu.gni:skia_shared_mtl_sources. +MTL_FILES = [ + "MtlMemoryAllocatorImpl.h", + "MtlMemoryAllocatorImpl.mm", + "MtlUtils.mm", + "MtlUtilsPriv.h", +] + +split_srcs_and_hdrs( + name = "mtl", + files = MTL_FILES, +) + +skia_filegroup( + name = "shared_objc_srcs", + srcs = [":mtl_srcs"], + visibility = ["//src/gpu:__pkg__"], +) + skia_filegroup( - name = "shared_srcs", - srcs = [ - "MtlMemoryAllocatorImpl.h", - "MtlMemoryAllocatorImpl.mm", - "MtlUtils.mm", - "MtlUtilsPriv.h", - ], + name = "private_hdrs", + srcs = [":mtl_hdrs"], + visibility = ["//src/gpu:__pkg__"], ) diff --git a/tools/gpu/BUILD.bazel b/tools/gpu/BUILD.bazel index b1ccc6fea6b2..ba8297255da3 100644 --- a/tools/gpu/BUILD.bazel +++ b/tools/gpu/BUILD.bazel @@ -45,6 +45,10 @@ skia_cc_library( "//tools/gpu/dawn:private_hdrs", "//tools/gpu/dawn:srcs", ], + "//src/gpu:metal_backend": [ + "//tools/gpu/mtl:private_hdrs", + "//tools/gpu/mtl:srcs", + ], # TODO(kjlubick) Handle other backends }), hdrs = [ diff --git a/tools/sk_app/BUILD.bazel b/tools/sk_app/BUILD.bazel index dd02cdbfa087..cb3e7ad20d7c 100644 --- a/tools/sk_app/BUILD.bazel +++ b/tools/sk_app/BUILD.bazel @@ -58,7 +58,7 @@ skia_objc_library( "RasterWindowContext.h", ] + select_multi( { - # TODO(kjlubick, jmbetancourt) Graphite and Metal backend + # TODO(kjlubick, jmbetancourt) Graphite backend "//src/gpu:dawn_backend": [ "DawnWindowContext.h", "DawnWindowContext.cpp", @@ -67,6 +67,10 @@ skia_objc_library( "GLWindowContext.cpp", "GLWindowContext.h", ], + "//src/gpu:metal_backend": [ + "MetalWindowContext.h", + "MetalWindowContext.mm", + ], }, ) + select({ "@platforms//os:macos": ["//tools/sk_app/mac:srcs"], diff --git a/tools/sk_app/mac/BUILD.bazel b/tools/sk_app/mac/BUILD.bazel index c0090bae78c1..71e40984af97 100644 --- a/tools/sk_app/mac/BUILD.bazel +++ b/tools/sk_app/mac/BUILD.bazel @@ -14,9 +14,10 @@ skia_filegroup( "Window_mac.h", "main_mac.mm", ] + select({ - # TODO(kjlubick, jmbetancourt) Graphite and Metal backend + # TODO(kjlubick, jmbetancourt) Graphite backend "//src/gpu:gl_backend": ["GLWindowContext_mac.mm"], "//src/gpu:dawn_backend": ["DawnMTLWindowContext_mac.mm"], + "//src/gpu:metal_backend": ["MetalWindowContext_mac.mm"], "//conditions:default": [], }), visibility = ["//tools/sk_app:__pkg__"],