| // Copyright (C) 2016 The Android Open Source Project |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| // +build darwin |
| |
| package device |
| |
| // #cgo CFLAGS: -x objective-c |
| // #cgo LDFLAGS: -framework Cocoa -framework OpenGL |
| // #import <OpenGL/gl.h> |
| // #import <AppKit/AppKit.h> |
| // const char* gpuArch() { |
| // const char* out = "unknown"; |
| // NSOpenGLPixelFormatAttribute attributes[] = { |
| // NSOpenGLPFANoRecovery, |
| // NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)32, |
| // NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)24, |
| // NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)8, |
| // NSOpenGLPFAAccelerated, |
| // NSOpenGLPFABackingStore, |
| // NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, |
| // (NSOpenGLPixelFormatAttribute)0 |
| // }; |
| // NSOpenGLPixelFormat* fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; |
| // if (fmt != 0) { |
| // NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:nil]; |
| // if (ctx != 0) { |
| // [ctx makeCurrentContext]; |
| // out = (const char*)(glGetString(GL_RENDERER)); |
| // [ctx release]; |
| // } |
| // [fmt release]; |
| // } |
| // return out; |
| // } |
| // |
| // void osVersion(int* major, int* minor, int* point) { |
| // NSOperatingSystemVersion version = [[NSProcessInfo processInfo] operatingSystemVersion]; |
| // *major = version.majorVersion; |
| // *minor = version.minorVersion; |
| // *point = version.patchVersion; |
| // } |
| import "C" |
| |
| import ( |
| "bytes" |
| "fmt" |
| "regexp" |
| "runtime" |
| |
| "android.googlesource.com/platform/tools/gpu/client/shell" |
| "android.googlesource.com/platform/tools/gpu/framework/log" |
| ) |
| |
| var hostParams map[string]string |
| |
| func getHostParams(ctx log.Context) map[string]string { |
| if hostParams != nil { |
| return hostParams |
| } |
| hostParams = map[string]string{} |
| |
| stdout := &bytes.Buffer{} |
| err := shell.Command("system_profiler", "SPHardwareDataType"). |
| Capture(stdout, nil). |
| Run(ctx) |
| if err != nil { |
| return nil |
| } |
| |
| re := regexp.MustCompile(" *(.*): *(.*)") |
| for _, match := range re.FindAllStringSubmatch(stdout.String(), -1) { |
| if len(match) == 3 { |
| hostParams[match[1]] = match[2] |
| } |
| } |
| return hostParams |
| } |
| |
| func hostModelName(ctx log.Context) string { |
| return getHostParams(ctx)["Model Name"] |
| } |
| |
| func hostCPUName(ctx log.Context) string { |
| params := getHostParams(ctx) |
| if speed, ok := params["Processor Speed"]; ok { |
| if coreCount, ok := params["Total Number of Cores"]; ok { |
| return fmt.Sprintf("%v (%v x %v)", hostCPUName, coreCount, speed) |
| } |
| return fmt.Sprintf("%v (%v)", hostCPUName, speed) |
| } |
| return "" |
| } |
| |
| func hostChipset(ctx log.Context) Chipset { |
| cpu := hostCPUName(ctx) |
| return Chipset{ |
| Name: cpu, |
| GPU: GPU{ |
| Name: C.GoString(C.gpuArch()), |
| }, |
| Cores: []CPU{ |
| { |
| Name: cpu, |
| Architecture: ArchitectureByName(runtime.GOARCH), |
| }, |
| }, |
| } |
| } |
| |
| func hostABIName(ctx log.Context) string { return "x86-64" } |
| |
| func hostOS(ctx log.Context) OS { |
| var major, minor, point C.int |
| C.osVersion(&major, &minor, &point) |
| return OSXOS(int(major), int(minor), int(point)) |
| } |