[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metal_util / device.mm
1 // Copyright 2019 The Chromium Authors
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 "components/metal_util/device.h"
6
7 #import <Metal/Metal.h>
8
9 #include "base/logging.h"
10
11 namespace metal {
12
13 id<MTLDevice> GetDefaultDevice() {
14   // First attempt to find a low power device to use.
15 #if BUILDFLAG(IS_MAC)
16   for (id<MTLDevice> device in MTLCopyAllDevices()) {
17     if (device.lowPower) {
18       return device;
19     }
20   }
21 #endif
22   // Failing that, use the system default device.
23   id<MTLDevice> system_default = MTLCreateSystemDefaultDevice();
24   if (!system_default) {
25     DLOG(ERROR) << "Failed to find MTLDevice.";
26     return nil;
27   }
28
29   return system_default;
30 }
31
32 }  // namespace metal