_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
+55 -30
View File
@@ -110,9 +110,11 @@ Screen::SetMode(uint16 width, uint16 height, uint32 colorspace,
mode.virtual_width = 640; mode.virtual_width = 640;
mode.virtual_height = 480; mode.virtual_height = 480;
mode.space = B_CMAP8; mode.space = B_CMAP8;
ret = _FindMode(width, height, colorspace, frequency, &mode);
} }
ret = SetMode(mode); if (ret >= B_OK)
ret = SetMode(mode);
return ret; return ret;
} }
@@ -152,13 +154,13 @@ Screen::Frame() const
status_t status_t
Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace, Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
float frequency, display_mode* mode) const float frequency, display_mode* mode) const
{ {
display_mode* dm = NULL; display_mode* dm = NULL;
uint32 count; uint32 count;
status_t err = fHWInterface->GetModeList(&dm, &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 // 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 // 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 // knowing anything else. While even this seems like insanity to assume that we
@@ -170,38 +172,61 @@ Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
return err; return err;
} }
bool found = false;
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 __HAIKU__
// we have found a mode with the correct width, height and format int32 index = _FindMode(dm, count, width, height, colorspace, frequency);
// now see if the frequency matches (don't be too picky) if (index < 0) {
float modeFrequency = 0.0; fprintf(stderr, "mode not found (%d, %d, %f) -> ignoring frequency and using B_CMAP8!\n", width, height, frequency);
float t = dm[i].timing.h_total * dm[i].timing.v_total; index = _FindMode(dm, count, width, height, B_CMAP8, frequency, true);
if (t != 0.0) }
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;
break;
}
#else #else
// Ignore frequency in test mode // Ignore frequency in test mode
*mode = dm[i]; int32 index = _FindMode(dm, count, width, height, colorspace, frequency, true);
found = true; #endif
break;
#endif // __HAIKU__ 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; delete[] dm;
if (!found) { return B_OK;
fprintf(stderr, "mode not found (%d, %d, %f)!\n", width, height, frequency); }
}
return found ? B_OK : B_ERROR; // _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 (!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;
float t = dm[i].timing.h_total * dm[i].timing.v_total;
if (t != 0.0)
modeFrequency = dm[i].timing.pixel_clock * 1000.f / t;
if (int(modeFrequency/* * 10.0*/ + 0.5) == int(frequency/* * 10.0*/ + 0.5)) {
index = i;
break;
}
} else {
// ignore frequency
index = i;
break;
}
}
}
return index;
} }
+5
View File
@@ -57,6 +57,11 @@ class Screen {
float frequency, float frequency,
display_mode* mode) const; 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; int32 fID;
DisplayDriver* fDriver; DisplayDriver* fDriver;
HWInterface* fHWInterface; HWInterface* fHWInterface;