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.
5 #include "components/metal_util/device.h"
7 #import <Metal/Metal.h>
9 #include "base/logging.h"
13 id<MTLDevice> GetDefaultDevice() {
14 // First attempt to find a low power device to use.
16 for (id<MTLDevice> device in MTLCopyAllDevices()) {
17 if (device.lowPower) {
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.";
29 return system_default;