зеркало из https://github.com/mozilla/gecko-dev.git
caching screen objects to avoid repeated memory allocations. r=saari.
This commit is contained in:
Родитель
32c1eabc0e
Коммит
3af4603d30
|
@ -49,11 +49,17 @@ NS_IMPL_ISUPPORTS(nsScreenManagerGtk, NS_GET_IID(nsIScreenManager))
|
|||
//
|
||||
// Utility routine. Creates a new screen object from the given device handle
|
||||
//
|
||||
// NOTE: For this "single-monitor" impl, we just always return the cached primary
|
||||
// screen. This should change when a multi-monitor impl is done.
|
||||
//
|
||||
nsIScreen*
|
||||
nsScreenManagerGtk :: CreateNewScreenObject ( )
|
||||
{
|
||||
nsIScreen* retval = new nsScreenGtk ( );
|
||||
NS_IF_ADDREF(retval);
|
||||
nsIScreen* retval = nsnull;
|
||||
if ( !mCachedMainScreen )
|
||||
mCachedMainScreen = new nsScreenGtk ( );
|
||||
NS_IF_ADDREF(retval = mCachedMainScreen.get());
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
#define nsScreenManagerGtk_h___
|
||||
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
class nsIScreen;
|
||||
#include "nsIScreen.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
|
@ -42,6 +42,9 @@ private:
|
|||
|
||||
nsIScreen* CreateNewScreenObject ( ) ;
|
||||
|
||||
// cache the primary screen object to avoid memory allocation every time
|
||||
nsCOMPtr<nsIScreen> mCachedMainScreen;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsScreenManagerGtk_h___
|
||||
|
|
|
@ -22,6 +22,18 @@
|
|||
|
||||
#include "nsScreenManagerMac.h"
|
||||
#include "nsScreenMac.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
class ScreenListItem
|
||||
{
|
||||
public:
|
||||
ScreenListItem ( GDHandle inGD, nsIScreen* inScreen )
|
||||
: mGD(inGD), mScreen(inScreen) { } ;
|
||||
|
||||
GDHandle mGD;
|
||||
nsCOMPtr<nsIScreen> mScreen;
|
||||
};
|
||||
|
||||
|
||||
nsScreenManagerMac :: nsScreenManagerMac ( )
|
||||
|
@ -36,7 +48,11 @@ nsScreenManagerMac :: nsScreenManagerMac ( )
|
|||
|
||||
nsScreenManagerMac :: ~nsScreenManagerMac()
|
||||
{
|
||||
// nothing to see here.
|
||||
// walk our list of cached screens and delete them.
|
||||
for ( int i = 0; i < mScreenList.Count(); ++i ) {
|
||||
ScreenListItem* item = NS_REINTERPRET_CAST(ScreenListItem*, mScreenList[i]);
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,9 +68,25 @@ NS_IMPL_ISUPPORTS(nsScreenManagerMac, NS_GET_IID(nsIScreenManager))
|
|||
nsIScreen*
|
||||
nsScreenManagerMac :: CreateNewScreenObject ( GDHandle inDevice )
|
||||
{
|
||||
nsIScreen* retval = new nsScreenMac ( inDevice );
|
||||
NS_IF_ADDREF(retval);
|
||||
return retval;
|
||||
nsIScreen* retScreen = nsnull;
|
||||
|
||||
// look through our screen list, hoping to find it. If it's not there,
|
||||
// add it and return the new one.
|
||||
for ( int i = 0; i < mScreenList.Count(); ++i ) {
|
||||
ScreenListItem* curr = NS_REINTERPRET_CAST(ScreenListItem*, mScreenList[i]);
|
||||
if ( inDevice == curr->mGD ) {
|
||||
NS_IF_ADDREF(retScreen = curr->mScreen.get());
|
||||
return retScreen;
|
||||
}
|
||||
} // for each screen.
|
||||
|
||||
// didn't find it in the list, so add it and return that item.
|
||||
retScreen = new nsScreenMac ( inDevice );
|
||||
ScreenListItem* listItem = new ScreenListItem ( inDevice, retScreen );
|
||||
mScreenList.AppendElement ( listItem );
|
||||
|
||||
NS_IF_ADDREF(retScreen);
|
||||
return retScreen;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,10 +24,13 @@
|
|||
#define nsScreenManagerMac_h___
|
||||
|
||||
#include "nsIScreenManager.h"
|
||||
#include <QuickDraw.h>
|
||||
#include <Quickdraw.h>
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsIScreen;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
class nsScreenManagerMac : public nsIScreenManager
|
||||
|
@ -42,7 +45,10 @@ public:
|
|||
private:
|
||||
|
||||
nsIScreen* CreateNewScreenObject ( GDHandle inDevice ) ;
|
||||
|
||||
nsAutoVoidArray mScreenList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // nsScreenManagerMac_h___
|
||||
|
|
|
@ -49,11 +49,17 @@ NS_IMPL_ISUPPORTS(nsScreenManagerWin, NS_GET_IID(nsIScreenManager))
|
|||
//
|
||||
// Utility routine. Creates a new screen object from the given device handle
|
||||
//
|
||||
// NOTE: For this "single-monitor" impl, we just always return the cached primary
|
||||
// screen. This should change when a multi-monitor impl is done.
|
||||
//
|
||||
nsIScreen*
|
||||
nsScreenManagerWin :: CreateNewScreenObject ( HDC inScreen )
|
||||
{
|
||||
nsIScreen* retval = new nsScreenWin ( inScreen );
|
||||
NS_IF_ADDREF(retval);
|
||||
nsIScreen* retval = nsnull;
|
||||
if ( !mCachedMainScreen )
|
||||
mCachedMainScreen = new nsScreenWin ( inScreen );
|
||||
NS_IF_ADDREF(retval = mCachedMainScreen.get());
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "nsIScreenManager.h"
|
||||
#include <windows.h>
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIScreen;
|
||||
|
||||
|
@ -43,6 +44,8 @@ private:
|
|||
|
||||
nsIScreen* CreateNewScreenObject ( HDC inScreen ) ;
|
||||
|
||||
// cache the primary screen object to avoid memory allocation every time
|
||||
nsCOMPtr<nsIScreen> mCachedMainScreen;
|
||||
};
|
||||
|
||||
#endif // nsScreenManagerWin_h___
|
||||
|
|
Загрузка…
Ссылка в новой задаче