1 // Copyright 2014 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 #include "ui/base/cocoa/remote_layer_api.h"
7 #include "base/command_line.h"
8 #include "base/mac/mac_util.h"
9 #include "ui/base/ui_base_switches.h"
11 #include <objc/runtime.h>
15 bool RemoteLayerAPISupported() {
16 // This API only works on Mac OS 10.9 and later.
17 if (!base::mac::IsOSMavericksOrLater())
20 bool disabled_at_command_line =
21 base::CommandLine::ForCurrentProcess()->HasSwitch(
22 switches::kDisableRemoteCoreAnimation) ||
23 base::CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kEnableNSGLSurfaces);
25 if (disabled_at_command_line)
28 // Verify the GPU process interfaces are present.
29 static Class caContextClass = NSClassFromString(@"CAContext");
33 // Note that because the contextId and layer properties are dynamic,
34 // instancesRespondToSelector will return NO for them.
35 static bool caContextClassValid =
36 [caContextClass respondsToSelector:
37 @selector(contextWithCGSConnection:options:)] &&
38 class_getProperty(caContextClass, "contextId") &&
39 class_getProperty(caContextClass, "layer");
40 if (!caContextClassValid)
43 // Verify the browser process interfaces are present.
44 static Class caLayerHostClass = NSClassFromString(@"CALayerHost");
45 if (!caLayerHostClass)
48 static bool caLayerHostClassValid =
49 [caLayerHostClass instancesRespondToSelector:@selector(contextId)] &&
50 [caLayerHostClass instancesRespondToSelector:@selector(setContextId:)];
51 if (!caLayerHostClassValid)
54 // If everything is there, we should be able to use the API.