app_server: Refactor and improve graphics device iteration.
* Do not open() devices while looping but only open() the one we were actually asked to open. * Try the VESA or Framebuffer driver even if deviceNumber is something other than 1. * Start iterating at 0 instead of 1 following loop iteration changes. Ideally this iteration should occur a completely different way, in order to properly support multiple graphics cards, but that's a problem for another day. Fixes #4303.
This commit is contained in:
@@ -197,7 +197,7 @@ AccelerantHWInterface::Initialize()
|
||||
return B_NO_MEMORY;
|
||||
|
||||
if (ret >= B_OK) {
|
||||
for (int32 i = 1; fCardFD != B_ENTRY_NOT_FOUND; i++) {
|
||||
for (int32 i = 0; fCardFD != B_ENTRY_NOT_FOUND; i++) {
|
||||
fCardFD = _OpenGraphicsDevice(i);
|
||||
if (fCardFD < 0) {
|
||||
ATRACE(("Failed to open graphics device\n"));
|
||||
@@ -234,52 +234,45 @@ AccelerantHWInterface::Initialize()
|
||||
int
|
||||
AccelerantHWInterface::_OpenGraphicsDevice(int deviceNumber)
|
||||
{
|
||||
DIR *directory = opendir("/dev/graphics");
|
||||
if (!directory)
|
||||
return -1;
|
||||
|
||||
int device = -1;
|
||||
int count = 0;
|
||||
if (!use_fail_safe_video_mode()) {
|
||||
// TODO: We do not need to avoid the "vesa" or "framebuffer" drivers this way
|
||||
// once they been ported to the new driver architecture - the special case here
|
||||
// can then be removed.
|
||||
DIR *directory = opendir("/dev/graphics");
|
||||
if (!directory)
|
||||
return -1;
|
||||
|
||||
struct dirent *entry;
|
||||
char path[PATH_MAX];
|
||||
while (count < deviceNumber && (entry = readdir(directory)) != NULL) {
|
||||
while ((entry = readdir(directory)) != NULL) {
|
||||
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")
|
||||
|| !strcmp(entry->d_name, "vesa") || !strcmp(entry->d_name, "framebuffer"))
|
||||
continue;
|
||||
|
||||
if (device >= 0) {
|
||||
close(device);
|
||||
device = -1;
|
||||
if (count == deviceNumber) {
|
||||
sprintf(path, "/dev/graphics/%s", entry->d_name);
|
||||
device = open(path, B_READ_WRITE);
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(path, "/dev/graphics/%s", entry->d_name);
|
||||
device = open(path, B_READ_WRITE);
|
||||
if (device >= 0)
|
||||
count++;
|
||||
count++;
|
||||
}
|
||||
|
||||
closedir(directory);
|
||||
}
|
||||
|
||||
// Open VESA or Framebuffer driver if we were not able to get a better one.
|
||||
if (count < deviceNumber) {
|
||||
if (deviceNumber == 1) {
|
||||
device = open("/dev/graphics/vesa", B_READ_WRITE);
|
||||
if (device > 0) {
|
||||
// store the device, so that we can access the planar blitter
|
||||
fVGADevice = device;
|
||||
} else {
|
||||
device = open("/dev/graphics/framebuffer", B_READ_WRITE);
|
||||
}
|
||||
device = open("/dev/graphics/vesa", B_READ_WRITE);
|
||||
if (device > 0) {
|
||||
// store the device, so that we can access the planar blitter
|
||||
fVGADevice = device;
|
||||
} else {
|
||||
close(device);
|
||||
device = B_ENTRY_NOT_FOUND;
|
||||
device = open("/dev/graphics/framebuffer", B_READ_WRITE);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(directory);
|
||||
if (device < 0)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user