blob: 00a9c3c9277c7c9968a5cca39953112c505f744f [file] [log] [blame]
// 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 linux
package device
// #cgo LDFLAGS: -lX11 -lGL
// #include <X11/Xresource.h>
// #include <GL/glx.h>
// #include <string.h>
//
// const char* gpuArch() {
// static char out[128] = "unknown";
// Display* display = XOpenDisplay(0);
// if (display) {
// const int visualAttribs[] = {
// GLX_RED_SIZE, 8,
// GLX_GREEN_SIZE, 8,
// GLX_BLUE_SIZE, 8,
// GLX_ALPHA_SIZE, 8,
// GLX_DEPTH_SIZE, 24,
// GLX_STENCIL_SIZE, 8,
// GLX_RENDER_TYPE, GLX_RGBA_BIT,
// GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
// None
// };
// int fbConfigsCount;
// GLXFBConfig* fbConfigs = glXChooseFBConfig(display,
// DefaultScreen(display),
// visualAttribs,
// &fbConfigsCount);
// if (fbConfigs) {
// GLXFBConfig fbConfig = fbConfigs[0];
// GLXContext context = glXCreateNewContext(display,
// fbConfig,
// GLX_RGBA_TYPE,
// 0,
// True);
// if (context) {
// const int pbufferAttribs[] = {
// GLX_PBUFFER_WIDTH, 32, GLX_PBUFFER_HEIGHT, 32, None
// };
// GLXPbuffer pbuffer = glXCreatePbuffer(display, fbConfig, pbufferAttribs);
// if (pbuffer) {
// glXMakeContextCurrent(display, pbuffer, pbuffer, context);
// const char* renderer = glGetString(GL_RENDERER);
// if (renderer) {
// strncpy(out, renderer, sizeof(out)-1);
// }
// glXDestroyPbuffer(display, pbuffer);
// }
// glXDestroyContext(display, context);
// }
// XFree(fbConfigs);
// }
// XCloseDisplay(display);
// }
// return out;
// }
import "C"
import (
"bytes"
"regexp"
"runtime"
"strings"
"android.googlesource.com/platform/tools/gpu/client/shell"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
func hostModelName(ctx log.Context) string {
stdout := &bytes.Buffer{}
if shell.Command("dmesg").Capture(stdout, nil).Run(ctx) == nil {
re := regexp.MustCompile(`DMI: *([^\/]*)\/`)
if match := re.FindStringSubmatch(stdout.String()); len(match) > 1 {
return match[1]
}
}
return "unknown"
}
func hostCPUName(ctx log.Context) string { return "" }
func hostABIName(ctx log.Context) string { return "" }
func hostOS(ctx log.Context) OS {
distro := "linux"
buf := &bytes.Buffer{}
if err := shell.Command("lsb_release", "-ics").Capture(buf, nil).Run(ctx); err == nil {
str := strings.TrimSpace(buf.String())
distro = strings.Join(strings.Split(str, "\n"), " ")
}
return LinuxOS(distro, 1, 0)
}
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),
},
},
}
}