Every BApplication (even applications which didn't use it) allocated a BPrivateScreen object. Now they are created/destroyed on demand (when a BScreen object is constructed), and reference counted, so that there is still only one per app. Note that since we are creating/deleting them, constructing a BScreen object can be more time consuming than before, but personally I find this approach much cleaner.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13006 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-06-08 07:36:41 +00:00
parent e9b005131f
commit 8eae8b05e8
2 changed files with 44 additions and 33 deletions

View File

@ -57,7 +57,6 @@
#include <MenuWindow.h>
#include <ObjectLocker.h>
#include <PortLink.h>
#include <PrivateScreen.h>
#include <ServerProtocol.h>
using namespace BPrivate;
@ -70,12 +69,6 @@ BResources *BApplication::_app_resources = NULL;
BLocker BApplication::_app_resources_lock("_app_resources_lock");
// Used by PrivateScreen.cpp
// TODO: This setup won`t let us have multiple screens. Change this.
namespace BPrivate {
BPrivateScreen *gPrivateScreen = NULL;
};
static property_info
sPropertyInfo[] = {
{
@ -441,8 +434,6 @@ DBG(OUT("BApplication::InitData(`%s', %p)\n", signature, _error));
#ifndef RUN_WITHOUT_APP_SERVER
// Initialize the IK after we have set be_app because of a construction of a
// BAppServerLink (which depends on be_app) nested inside the call to get_menu_info.
if (fInitError == B_OK)
get_scs();
if (fInitError == B_OK)
fInitError = _init_interface_kit_();
// create global system cursors
@ -1042,13 +1033,6 @@ BApplication::EndRectTracking()
}
void
BApplication::get_scs()
{
gPrivateScreen = new BPrivateScreen();
}
void
BApplication::setup_server_heaps()
{

View File

@ -24,9 +24,10 @@
// Description: BPrivateScreen is the class which does the real work
// for the proxy class BScreen (it interacts with the app server).
//------------------------------------------------------------------------------
#include <Debug.h>
#include <Locker.h>
#include <Window.h>
#include <stdio.h>
#include <stdlib.h>
#include "AppServerLink.h"
@ -44,10 +45,11 @@ struct screen_desc {
};
// Defined in Application.cpp
namespace BPrivate {
extern BPrivateScreen *gPrivateScreen;
};
static BPrivateScreen *sScreen;
static int32 sScreenRefCount;
// used to synchronize creation/deletion of the sScreen object
static BLocker sScreenLock("screen lock");
using namespace BPrivate;
@ -55,30 +57,55 @@ using namespace BPrivate;
BPrivateScreen *
BPrivateScreen::CheckOut(BWindow *win)
{
// TODO: If we start supporting multiple monitors, we
// should return the right screen for the passed BWindow
return gPrivateScreen;
sScreenLock.Lock();
if (atomic_add(&sScreenRefCount, 1) == 0) {
// TODO: If we start supporting multiple monitors, we
// should return the right screen for the passed BWindow
ASSERT(sScreen == NULL);
sScreen = new BPrivateScreen();
}
sScreenLock.Unlock();
return sScreen;
}
BPrivateScreen *
BPrivateScreen::CheckOut(screen_id id)
{
// TODO: If we start supporting multiple monitors, we
// should return the right object for the given screen_id
return gPrivateScreen;
sScreenLock.Lock();
if (atomic_add(&sScreenRefCount, 1) == 0) {
// TODO: If we start supporting multiple monitors, we
// should return the right object for the given screen_id
ASSERT(sScreen == NULL);
sScreen = new BPrivateScreen();
}
sScreenLock.Unlock();
return sScreen;
}
void
BPrivateScreen::Return(BPrivateScreen *screen)
{
// Not much to do here. I guess it's some legacy from pre-R5,
// where BScreen could not be used for long time,
// as they blocked the BApplication
sScreenLock.Lock();
if (atomic_add(&sScreenRefCount, -1) == 1) {
// TODO: Check if the passed object is the same we are deleting
// here. Not much important for now though, since we only have one.
delete sScreen;
sScreen = NULL;
}
sScreenLock.Unlock();
}
status_t
BPrivateScreen::SetToNext()
{
@ -426,7 +453,7 @@ BPrivateScreen::get_screen_desc(screen_desc *desc)
return status;
}
// Private, called by BApplication::get_scs()
BPrivateScreen::BPrivateScreen()
:
@ -445,7 +472,7 @@ BPrivateScreen::BPrivateScreen()
if (reply == SERVER_TRUE) {
fColorMap = (color_map *)malloc(sizeof(color_map));
fOwnsColorMap = true;
// TODO: This doesn't work. We probably run into a port
// TODO: This doesn't work. We probably ran into a port
// capacity issue ?
//link.Read<color_map>(fColorMap);
}