• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5#include "ui/base/cocoa/remote_layer_api.h"
6
7#include "base/command_line.h"
8#include "ui/base/ui_base_switches.h"
9
10#include <objc/runtime.h>
11
12namespace ui {
13
14bool RemoteLayerAPISupported() {
15  bool enabled_at_command_line =
16      CommandLine::ForCurrentProcess()->HasSwitch(
17          switches::kEnableRemoteCoreAnimation);
18  if (!enabled_at_command_line)
19    return false;
20
21  // Verify the GPU process interfaces are present.
22  static Class caContextClass = NSClassFromString(@"CAContext");
23  if (!caContextClass)
24    return false;
25
26  // Note that because the contextId and layer properties are dynamic,
27  // instancesRespondToSelector will return NO for them.
28  static bool caContextClassValid =
29      [caContextClass respondsToSelector:
30          @selector(contextWithCGSConnection:options:)] &&
31      class_getProperty(caContextClass, "contextId") &&
32      class_getProperty(caContextClass, "layer");
33  if (!caContextClassValid)
34    return false;
35
36  // Verify the browser process interfaces are present.
37  static Class caLayerHostClass = NSClassFromString(@"CALayerHost");
38  if (!caLayerHostClass)
39    return false;
40
41  static bool caLayerHostClassValid =
42      [caLayerHostClass instancesRespondToSelector:@selector(contextId)] &&
43      [caLayerHostClass instancesRespondToSelector:@selector(setContextId:)];
44  if (!caLayerHostClassValid)
45    return false;
46
47  // If everything is there, we should be able to use the API.
48  return true;
49}
50
51}  // namespace
52
53