Commit 81d8c2ad by Corentin Wallez Committed by Corentin Wallez

MetalSurface: set layer.device to a ref of the system default device.

If layer.device is null, [layer nextDrawable] returns nil, so on surface initialization we set layer.device to a dummy MTLDevice by getting a reference of the system default device. Using MTLCreateSystemDefaultDevice() requires linking against Metal.framework but Chromium needs to ship on platforms that don't have Metal. This means we can't directly link against the framework, instead we "weakly" link against it so that if it is not present, the function pointers are just null (instead of failing to launch). Bug: dawn:269 Change-Id: I8719c45a19718ff79ef21f47515fe1c15b99628b Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/43112 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarCorentin Wallez <cwallez@google.com>
parent 1c29477a
......@@ -14,6 +14,15 @@
import("../swiftshader.gni")
config("WSI_metal_weak_framework") {
if (is_mac) {
ldflags = [
"-weak_framework",
"Metal",
]
}
}
swiftshader_source_set("WSI") {
sources = [
"VkSurfaceKHR.cpp",
......@@ -42,13 +51,14 @@ swiftshader_source_set("WSI") {
if (is_mac) {
sources += [
"MetalSurface.mm",
"MetalSurface.h",
"MetalSurface.mm",
]
libs = [
"Cocoa.framework",
"QuartzCore.framework",
]
public_configs = [ ":WSI_metal_weak_framework" ]
}
include_dirs = [
......@@ -63,5 +73,5 @@ swiftshader_source_set("WSI") {
"../Vulkan:swiftshader_libvulkan_headers",
]
configs = [ "../Vulkan:swiftshader_libvulkan_private_config", ]
configs = [ "../Vulkan:swiftshader_libvulkan_private_config" ]
}
......@@ -40,6 +40,7 @@ public:
{
layer = (CAMetalLayer*)[obj retain];
layer.framebufferOnly = false;
layer.device = MTLCreateSystemDefaultDevice();
}
else
{
......@@ -68,6 +69,7 @@ public:
{
if(layer)
{
[layer.device release];
[layer release];
}
if(view)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment