_FindMode is now more robust and really tries everything it can to find a mode...

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-07-16 22:50:17 +00:00
parent 821426f66e
commit 05ffbfbc24
2 changed files with 60 additions and 30 deletions
+43 -18
View File
@@ -110,8 +110,10 @@ Screen::SetMode(uint16 width, uint16 height, uint32 colorspace,
mode.virtual_width = 640;
mode.virtual_height = 480;
mode.space = B_CMAP8;
ret = _FindMode(width, height, colorspace, frequency, &mode);
}
if (ret >= B_OK)
ret = SetMode(mode);
return ret;
@@ -158,7 +160,7 @@ Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
uint32 count;
status_t err = fHWInterface->GetModeList(&dm, &count);
if (err < B_OK) {
if (err < B_OK || count <= 0) {
// We've run into quite a problem here! This is a function which is a requirement
// for a graphics module. The best thing that we can hope for is 640x480x8 without
// knowing anything else. While even this seems like insanity to assume that we
@@ -170,12 +172,43 @@ Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
return err;
}
bool found = false;
#if __HAIKU__
int32 index = _FindMode(dm, count, width, height, colorspace, frequency);
if (index < 0) {
fprintf(stderr, "mode not found (%d, %d, %f) -> ignoring frequency and using B_CMAP8!\n", width, height, frequency);
index = _FindMode(dm, count, width, height, B_CMAP8, frequency, true);
}
#else
// Ignore frequency in test mode
int32 index = _FindMode(dm, count, width, height, colorspace, frequency, true);
#endif
if (index < 0) {
fprintf(stderr, "mode not found (%d, %d, %f) -> using first mode from list!\n", width, height, frequency);
// fallback to first mode from list - TODO: ?!?
// NOTE: count > 0 is checked above
*mode = dm[0];
} else {
*mode = dm[index];
}
delete[] dm;
return B_OK;
}
// _FindMode
int32
Screen::_FindMode(const display_mode* dm, uint32 count,
uint16 width, uint16 height, uint32 colorspace,
float frequency, bool ignoreFrequency) const
{
int32 index = -1;
for (uint32 i = 0; i < count; i++) {
if (dm[i].virtual_width == width
&& dm[i].virtual_height == height
&& dm[i].space == colorspace) {
#if __HAIKU__
if (!ignoreFrequency) {
// we have found a mode with the correct width, height and format
// now see if the frequency matches (don't be too picky)
float modeFrequency = 0.0;
@@ -184,24 +217,16 @@ Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
modeFrequency = dm[i].timing.pixel_clock * 1000.f / t;
if (int(modeFrequency/* * 10.0*/ + 0.5) == int(frequency/* * 10.0*/ + 0.5)) {
*mode = dm[i];
found = true;
index = i;
break;
}
#else
// Ignore frequency in test mode
*mode = dm[i];
found = true;
} else {
// ignore frequency
index = i;
break;
#endif // __HAIKU__
}
}
delete[] dm;
if (!found) {
fprintf(stderr, "mode not found (%d, %d, %f)!\n", width, height, frequency);
}
return found ? B_OK : B_ERROR;
}
}
return index;
}
+5
View File
@@ -57,6 +57,11 @@ class Screen {
float frequency,
display_mode* mode) const;
int32 _FindMode(const display_mode* modeList,
uint32 count, uint16 width, uint16 height, uint32 colorspace,
float frequency,
bool ignoreFrequency = false) const;
int32 fID;
DisplayDriver* fDriver;
HWInterface* fHWInterface;