2005-11-18 15:26:20 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2005, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT license.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Adi Oanca <adioanca@myrealbox.com>
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
* Stephan Aßmus, <superstippi@gmx.de>
|
|
|
|
*/
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2004-01-12 01:12:55 +03:00
|
|
|
#include <Accelerant.h>
|
|
|
|
#include <Point.h>
|
|
|
|
#include <GraphicsDefs.h>
|
2005-05-26 13:21:51 +04:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2004-01-12 01:12:55 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-11-04 18:54:16 +03:00
|
|
|
#include "DrawingEngine.h"
|
2005-06-24 03:46:17 +04:00
|
|
|
#include "HWInterface.h"
|
|
|
|
|
2004-01-12 01:12:55 +03:00
|
|
|
#include "ServerScreen.h"
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-11-18 15:26:20 +03:00
|
|
|
Screen::Screen(::HWInterface *interface, int32 id)
|
2005-06-24 03:46:17 +04:00
|
|
|
: fID(id),
|
2005-11-04 18:23:54 +03:00
|
|
|
fDriver(interface ? new DrawingEngine(interface) : NULL),
|
2005-06-24 03:46:17 +04:00
|
|
|
fHWInterface(interface)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-11-18 15:26:20 +03:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
Screen::Screen()
|
|
|
|
: fID(-1),
|
|
|
|
fDriver(NULL),
|
|
|
|
fHWInterface(NULL)
|
2004-01-12 01:12:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
Screen::~Screen()
|
2004-02-12 04:25:41 +03:00
|
|
|
{
|
2005-06-24 03:46:17 +04:00
|
|
|
Shutdown();
|
2005-06-08 05:40:22 +04:00
|
|
|
delete fDriver;
|
2005-06-24 03:46:17 +04:00
|
|
|
delete fHWInterface;
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t
|
|
|
|
Screen::Initialize()
|
2004-02-12 04:25:41 +03:00
|
|
|
{
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t ret = B_NO_INIT;
|
|
|
|
if (fDriver) {
|
|
|
|
// this will also init the graphics hardware the driver is attached to
|
|
|
|
ret = fDriver->Initialize();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2004-01-12 01:12:55 +03:00
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
void
|
|
|
|
Screen::Shutdown()
|
|
|
|
{
|
|
|
|
if (fDriver)
|
|
|
|
fDriver->Shutdown();
|
|
|
|
}
|
2004-01-12 01:12:55 +03:00
|
|
|
|
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t
|
|
|
|
Screen::SetMode(display_mode mode)
|
|
|
|
{
|
|
|
|
status_t ret = fHWInterface->SetMode(mode);
|
|
|
|
|
2005-11-04 18:23:54 +03:00
|
|
|
// the DrawingEngine needs to adjust itself
|
2005-06-24 03:46:17 +04:00
|
|
|
if (ret >= B_OK)
|
|
|
|
fDriver->Update();
|
|
|
|
|
|
|
|
return ret;
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t
|
|
|
|
Screen::SetMode(uint16 width, uint16 height, uint32 colorspace,
|
|
|
|
float frequency)
|
2004-02-12 04:25:41 +03:00
|
|
|
{
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t ret = B_ERROR;
|
2004-01-12 01:12:55 +03:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
// search for a matching mode
|
2005-05-26 13:21:51 +04:00
|
|
|
display_mode mode;
|
2005-06-24 03:46:17 +04:00
|
|
|
ret = _FindMode(width, height, colorspace, frequency, &mode);
|
2004-01-12 01:12:55 +03:00
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
if (ret < B_OK) {
|
2005-07-17 03:43:30 +04:00
|
|
|
// TODO: Move fallback elsewhere, this function should simply
|
|
|
|
// fail if requested to set unsupported mode.
|
2005-06-24 03:46:17 +04:00
|
|
|
// Ups. Not good. Ignore the requested mode and use fallback params.
|
2005-07-17 03:43:30 +04:00
|
|
|
ret = _FindMode(640, 480, B_CMAP8, 60.0, &mode);
|
2005-06-24 03:46:17 +04:00
|
|
|
}
|
|
|
|
|
2005-07-17 02:50:17 +04:00
|
|
|
if (ret >= B_OK)
|
|
|
|
ret = SetMode(mode);
|
2005-06-24 03:46:17 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Screen::GetMode(display_mode* mode) const
|
|
|
|
{
|
|
|
|
fHWInterface->GetMode(mode);
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
void
|
2005-06-24 03:46:17 +04:00
|
|
|
Screen::GetMode(uint16 &width, uint16 &height, uint32 &colorspace,
|
|
|
|
float &frequency) const
|
2005-05-26 13:21:51 +04:00
|
|
|
{
|
|
|
|
display_mode mode;
|
2005-06-24 03:46:17 +04:00
|
|
|
fHWInterface->GetMode(&mode);
|
2005-05-26 13:21:51 +04:00
|
|
|
|
|
|
|
width = mode.virtual_width;
|
|
|
|
height = mode.virtual_height;
|
|
|
|
colorspace = mode.space;
|
|
|
|
frequency = mode.timing.pixel_clock * 1000.f
|
|
|
|
/ (mode.timing.h_total * mode.timing.v_total);
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
|
|
|
|
2005-05-26 13:21:51 +04:00
|
|
|
|
2005-07-15 16:45:23 +04:00
|
|
|
BRect
|
|
|
|
Screen::Frame() const
|
|
|
|
{
|
|
|
|
display_mode mode;
|
|
|
|
fHWInterface->GetMode(&mode);
|
|
|
|
|
|
|
|
return BRect(0, 0, mode.virtual_width - 1, mode.virtual_height - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-26 19:55:23 +03:00
|
|
|
color_space
|
|
|
|
Screen::ColorSpace() const
|
|
|
|
{
|
|
|
|
display_mode mode;
|
|
|
|
fHWInterface->GetMode(&mode);
|
|
|
|
|
|
|
|
return (color_space)mode.space;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-24 03:46:17 +04:00
|
|
|
status_t
|
|
|
|
Screen::_FindMode(uint16 width, uint16 height, uint32 colorspace,
|
2005-07-17 02:50:17 +04:00
|
|
|
float frequency, display_mode* mode) const
|
2004-02-12 04:25:41 +03:00
|
|
|
{
|
2005-06-24 03:46:17 +04:00
|
|
|
display_mode* dm = NULL;
|
|
|
|
uint32 count;
|
|
|
|
|
|
|
|
status_t err = fHWInterface->GetModeList(&dm, &count);
|
2005-07-17 02:50:17 +04:00
|
|
|
if (err < B_OK || count <= 0) {
|
2005-06-24 03:46:17 +04:00
|
|
|
// 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
|
|
|
|
// can support this, the only lower mode supported is 640x400, but we shouldn't even
|
|
|
|
// bother with such a pathetic possibility.
|
|
|
|
if (width == 640 && height == 480 && colorspace == B_CMAP8)
|
|
|
|
return B_OK;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-07-17 02:50:17 +04:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2005-11-18 15:26:20 +03:00
|
|
|
|
2005-07-17 02:50:17 +04:00
|
|
|
int32
|
|
|
|
Screen::_FindMode(const display_mode* dm, uint32 count,
|
|
|
|
uint16 width, uint16 height, uint32 colorspace,
|
|
|
|
float frequency, bool ignoreFrequency) const
|
|
|
|
{
|
|
|
|
int32 index = -1;
|
2005-06-24 03:46:17 +04:00
|
|
|
for (uint32 i = 0; i < count; i++) {
|
|
|
|
if (dm[i].virtual_width == width
|
|
|
|
&& dm[i].virtual_height == height
|
|
|
|
&& dm[i].space == colorspace) {
|
2005-07-17 02:50:17 +04:00
|
|
|
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;
|
2005-06-24 03:46:17 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-17 02:50:17 +04:00
|
|
|
return index;
|
2004-01-12 01:12:55 +03:00
|
|
|
}
|
|
|
|
|