1
2
3
4
5 package oshi.hardware.platform.mac;
6
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.util.Locale;
10
11 import oshi.annotation.concurrent.Immutable;
12 import oshi.hardware.GraphicsCard;
13 import oshi.hardware.common.AbstractGraphicsCard;
14 import oshi.util.Constants;
15 import oshi.util.ExecutingCommand;
16 import oshi.util.ParseUtil;
17
18
19
20
21 @Immutable
22 final class MacGraphicsCard extends AbstractGraphicsCard {
23
24
25
26
27
28
29
30
31
32
33 MacGraphicsCard(String name, String deviceId, String vendor, String versionInfo, long vram) {
34 super(name, deviceId, vendor, versionInfo, vram);
35 }
36
37
38
39
40
41
42 public static List<GraphicsCard> getGraphicsCards() {
43 List<GraphicsCard> cardList = new ArrayList<>();
44 List<String> sp = ExecutingCommand.runNative("system_profiler SPDisplaysDataType");
45 String name = Constants.UNKNOWN;
46 String deviceId = Constants.UNKNOWN;
47 String vendor = Constants.UNKNOWN;
48 List<String> versionInfoList = new ArrayList<>();
49 long vram = 0;
50 int cardNum = 0;
51 for (String line : sp) {
52 String[] split = line.trim().split(":", 2);
53 if (split.length == 2) {
54 String prefix = split[0].toLowerCase(Locale.ROOT);
55 if (prefix.equals("chipset model")) {
56
57 if (cardNum++ > 0) {
58 cardList.add(new MacGraphicsCard(name, deviceId, vendor,
59 versionInfoList.isEmpty() ? Constants.UNKNOWN : String.join(", ", versionInfoList),
60 vram));
61 versionInfoList.clear();
62 }
63 name = split[1].trim();
64 } else if (prefix.equals("device id")) {
65 deviceId = split[1].trim();
66 } else if (prefix.equals("vendor")) {
67 vendor = split[1].trim();
68 } else if (prefix.contains("version") || prefix.contains("revision")) {
69 versionInfoList.add(line.trim());
70 } else if (prefix.startsWith("vram")) {
71 vram = ParseUtil.parseDecimalMemorySizeToBinary(split[1].trim());
72 }
73 }
74 }
75 cardList.add(new MacGraphicsCard(name, deviceId, vendor,
76 versionInfoList.isEmpty() ? Constants.UNKNOWN : String.join(", ", versionInfoList), vram));
77 return cardList;
78 }
79 }