* BPrivateScreen used B_CURRENT_WORKSPACE where an index was required. This

was reason that caused bug #2658.
* Introduced a new constant B_CURRENT_WORKSPACE_INDEX in PrivateScreen.h; maybe
  this should be made public one day.
* Fixed another reason that caused bug #2658: BPrivateScreen waited 100ms
  between frame updates, leaving a large window open for such problems; I've
  reduced it to 10ms now, but the actual bug fix is to reset the counter for
  each BScreen object, so that when you create a new BScreen object, the frame
  is retrieved timely.
* The reference count was not initialized, causing BPrivateScreens to be leaked
  forever.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32557 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-08-21 09:20:25 +00:00
parent 50dfc607fb
commit aadbd94ef7
3 changed files with 37 additions and 14 deletions

View File

@ -31,6 +31,7 @@
using namespace BPrivate;
static BObjectList<BPrivateScreen> sScreens(2, true);
// used to synchronize creation/deletion of the sScreen object
@ -159,7 +160,7 @@ color_space
BPrivateScreen::ColorSpace()
{
display_mode mode;
if (GetMode(B_CURRENT_WORKSPACE, &mode) == B_OK)
if (GetMode(B_CURRENT_WORKSPACE_INDEX, &mode) == B_OK)
return (color_space)mode.space;
return B_NO_COLOR_SPACE;
@ -171,10 +172,10 @@ BPrivateScreen::Frame()
{
// If something goes wrong, we just return this rectangle.
if (system_time() > fLastUpdate + 100000) {
// invalidate the settings after 0.1 secs
if (system_time() > fLastUpdate + 10000) {
// invalidate the settings after 10 msecs
display_mode mode;
if (GetMode(B_CURRENT_WORKSPACE, &mode) == B_OK) {
if (GetMode(B_CURRENT_WORKSPACE_INDEX, &mode) == B_OK) {
fFrame.Set(0, 0, (float)mode.virtual_width - 1,
(float)mode.virtual_height - 1);
fLastUpdate = system_time();
@ -649,6 +650,23 @@ BPrivateScreen::BytesPerRow()
// #pragma mark - private methods
void
BPrivateScreen::_Acquire()
{
fReferenceCount++;
fLastUpdate = 0;
// force an update for the new BScreen object
}
bool
BPrivateScreen::_Release()
{
return --fReferenceCount == 0;
}
sem_id
BPrivateScreen::_RetraceSemaphore()
{
@ -687,6 +705,7 @@ BPrivateScreen::_GetFrameBufferConfig(frame_buffer_config& config)
BPrivateScreen::BPrivateScreen(int32 id)
:
fID(id),
fReferenceCount(0),
fColorMap(NULL),
fRetraceSem(-1),
fRetraceSemValid(false),

View File

@ -22,6 +22,9 @@ class BApplication;
class BWindow;
#define B_CURRENT_WORKSPACE_INDEX (~0L)
namespace BPrivate {
class BPrivateScreen {
@ -88,8 +91,8 @@ private:
BPrivateScreen(int32 id);
~BPrivateScreen();
void _Acquire() { fRefCount++; }
bool _Release() { return --fRefCount == 0; }
void _Acquire();
bool _Release();
sem_id _RetraceSemaphore();
status_t _GetFrameBufferConfig(
@ -100,7 +103,7 @@ private:
private:
int32 fID;
int32 fRefCount;
int32 fReferenceCount;
color_map* fColorMap;
sem_id fRetraceSem;
bool fRetraceSemValid;

View File

@ -7,6 +7,7 @@
* Axel Dörfler, axeld@pinc-software.de
*/
/*! BScreen lets you retrieve and change the display settings. */
@ -15,11 +16,10 @@
#include <Screen.h>
#include <Window.h>
using namespace BPrivate;
static const uint32 kCurrentWorkspaceIndex = ~0;
/*! \brief Creates a BScreen object which represents the display with the given
screen_id
\param id The screen_id of the screen to get.
@ -250,7 +250,7 @@ rgb_color
BScreen::DesktopColor()
{
if (fScreen != NULL)
return fScreen->DesktopColor(kCurrentWorkspaceIndex);
return fScreen->DesktopColor(B_CURRENT_WORKSPACE_INDEX);
return rgb_color();
}
@ -280,7 +280,7 @@ void
BScreen::SetDesktopColor(rgb_color rgb, bool stick)
{
if (fScreen != NULL)
fScreen->SetDesktopColor(rgb, kCurrentWorkspaceIndex, stick);
fScreen->SetDesktopColor(rgb, B_CURRENT_WORKSPACE_INDEX, stick);
}
@ -345,12 +345,13 @@ status_t
BScreen::GetMode(display_mode* mode)
{
if (fScreen != NULL)
return fScreen->GetMode(kCurrentWorkspaceIndex, mode);
return fScreen->GetMode(B_CURRENT_WORKSPACE_INDEX, mode);
return B_ERROR;
}
/*! \brief Copies the current display_mode of the given workspace into mode.
\param workspace The index of the workspace to query.
\param mode A pointer to a display_mode structure,
where the current display_mode will be copied.
\return \c B_OK if the operation was succesful.
@ -373,13 +374,13 @@ status_t
BScreen::SetMode(display_mode* mode, bool makeDefault)
{
if (fScreen != NULL)
return fScreen->SetMode(kCurrentWorkspaceIndex, mode, makeDefault);
return fScreen->SetMode(B_CURRENT_WORKSPACE_INDEX, mode, makeDefault);
return B_ERROR;
}
/*! \brief Set the given workspace to the given mode.
\param workspace The workspace that you want to change.
\param workspace The index of the workspace that you want to change.
\param mode A pointer to a display_mode.
\param makeDefault If true, the mode becomes the default for the workspace.
\return \c B_OK.