Miscellaneous performance improvements, mostly related to image loads. Cache a copy of the IO service on the Pres Context for use in starting image loads. b=170116 r=darin sr=bzbarsky

This commit is contained in:
dbaron%fas.harvard.edu 2002-11-06 12:58:05 +00:00
Родитель b2d4d4e2cf
Коммит 3d2853cfbf
11 изменённых файлов: 105 добавлений и 45 удалений

Просмотреть файл

@ -888,24 +888,42 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode)
return NS_OK;
}
/* This function has now been deprecated. It is no longer necesary to
* hold on to presContext just to get a nsLookAndFeel. nsLookAndFeel is
* now a service provided by ServiceManager.
/*
* It is no longer necesary to hold on to presContext just to get a
* nsILookAndFeel, which can now be obtained through the service
* manager. However, this cached copy can be used when a pres context
* is available, for faster performance.
*/
NS_IMETHODIMP
nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel)
{
NS_PRECONDITION(aLookAndFeel, "null out param");
nsresult result = NS_OK;
if (! mLookAndFeel) {
mLookAndFeel = do_GetService(kLookAndFeelCID,&result);
nsresult rv;
mLookAndFeel = do_GetService(kLookAndFeelCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
*aLookAndFeel = mLookAndFeel;
NS_IF_ADDREF(*aLookAndFeel);
return result;
NS_ADDREF(*aLookAndFeel);
return NS_OK;
}
/*
* Get the cached IO service, faster than the service manager could.
*/
NS_IMETHODIMP
nsPresContext::GetIOService(nsIIOService** aIOService)
{
NS_PRECONDITION(aIOService, "null out param");
if (! mIOService) {
nsresult rv;
mIOService = do_GetIOService(&rv);
NS_ENSURE_SUCCESS(rv, rv);
}
*aIOService = mIOService;
NS_ADDREF(*aIOService);
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetBaseURL(nsIURI** aResult)
@ -1517,10 +1535,7 @@ nsPresContext::GetContainer(nsISupports** aResult)
NS_IMETHODIMP
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
{
NS_PRECONDITION(nsnull != aManager, "null ptr");
if (nsnull == aManager) {
return NS_ERROR_NULL_POINTER;
}
NS_PRECONDITION(aManager, "null ptr");
if (!mEventManager) {
nsresult rv;
@ -1528,10 +1543,10 @@ nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
if (NS_FAILED(rv)) {
return rv;
}
}
//Not refcnted, set null in destructor
mEventManager->SetPresContext(this);
//Not refcnted, set null in destructor
mEventManager->SetPresContext(this);
}
*aManager = mEventManager;
NS_IF_ADDREF(*aManager);

Просмотреть файл

@ -67,6 +67,7 @@ class nsString;
class nsIEventStateManager;
class nsIURI;
class nsILookAndFeel;
class nsIIOService;
class nsICSSPseudoComparator;
class nsILanguageAtom;
class nsITheme;
@ -161,10 +162,15 @@ public:
NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0;
/**
* Get look and feel object
* Get cached look and feel service.
*/
NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0;
/**
* Get cached IO service.
*/
NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0;
/**
* Get base url for presentation
*/

Просмотреть файл

@ -67,6 +67,7 @@ class nsString;
class nsIEventStateManager;
class nsIURI;
class nsILookAndFeel;
class nsIIOService;
class nsICSSPseudoComparator;
class nsILanguageAtom;
class nsITheme;
@ -161,10 +162,15 @@ public:
NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0;
/**
* Get look and feel object
* Get cached look and feel service.
*/
NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0;
/**
* Get cached IO service.
*/
NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0;
/**
* Get base url for presentation
*/

Просмотреть файл

@ -67,6 +67,7 @@ class nsString;
class nsIEventStateManager;
class nsIURI;
class nsILookAndFeel;
class nsIIOService;
class nsICSSPseudoComparator;
class nsILanguageAtom;
class nsITheme;
@ -161,10 +162,15 @@ public:
NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0;
/**
* Get look and feel object
* Get cached look and feel service.
*/
NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0;
/**
* Get cached IO service.
*/
NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0;
/**
* Get base url for presentation
*/

Просмотреть файл

@ -888,24 +888,42 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode)
return NS_OK;
}
/* This function has now been deprecated. It is no longer necesary to
* hold on to presContext just to get a nsLookAndFeel. nsLookAndFeel is
* now a service provided by ServiceManager.
/*
* It is no longer necesary to hold on to presContext just to get a
* nsILookAndFeel, which can now be obtained through the service
* manager. However, this cached copy can be used when a pres context
* is available, for faster performance.
*/
NS_IMETHODIMP
nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel)
{
NS_PRECONDITION(aLookAndFeel, "null out param");
nsresult result = NS_OK;
if (! mLookAndFeel) {
mLookAndFeel = do_GetService(kLookAndFeelCID,&result);
nsresult rv;
mLookAndFeel = do_GetService(kLookAndFeelCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
*aLookAndFeel = mLookAndFeel;
NS_IF_ADDREF(*aLookAndFeel);
return result;
NS_ADDREF(*aLookAndFeel);
return NS_OK;
}
/*
* Get the cached IO service, faster than the service manager could.
*/
NS_IMETHODIMP
nsPresContext::GetIOService(nsIIOService** aIOService)
{
NS_PRECONDITION(aIOService, "null out param");
if (! mIOService) {
nsresult rv;
mIOService = do_GetIOService(&rv);
NS_ENSURE_SUCCESS(rv, rv);
}
*aIOService = mIOService;
NS_ADDREF(*aIOService);
return NS_OK;
}
NS_IMETHODIMP
nsPresContext::GetBaseURL(nsIURI** aResult)
@ -1517,10 +1535,7 @@ nsPresContext::GetContainer(nsISupports** aResult)
NS_IMETHODIMP
nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
{
NS_PRECONDITION(nsnull != aManager, "null ptr");
if (nsnull == aManager) {
return NS_ERROR_NULL_POINTER;
}
NS_PRECONDITION(aManager, "null ptr");
if (!mEventManager) {
nsresult rv;
@ -1528,10 +1543,10 @@ nsPresContext::GetEventStateManager(nsIEventStateManager** aManager)
if (NS_FAILED(rv)) {
return rv;
}
}
//Not refcnted, set null in destructor
mEventManager->SetPresContext(this);
//Not refcnted, set null in destructor
mEventManager->SetPresContext(this);
}
*aManager = mEventManager;
NS_IF_ADDREF(*aManager);

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsIEventStateManager.h"
#include "nsIObserver.h"
#include "nsILookAndFeel.h"
#include "nsIIOService.h"
#ifdef IBMBIDI
#include "nsBidiUtils.h"
#endif
@ -78,6 +79,7 @@ public:
NS_IMETHOD SetImageAnimationMode(PRUint16 aMode);
NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags);
NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel);
NS_IMETHOD GetIOService(nsIIOService** aIOService);
NS_IMETHOD GetBaseURL(nsIURI** aURLResult);
NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0;
NS_IMETHOD ClearStyleDataAndReflow(void);
@ -213,6 +215,7 @@ protected:
nsILinkHandler* mLinkHandler; // [WEAK]
nsISupports* mContainer; // [WEAK]
nsCOMPtr<nsILookAndFeel> mLookAndFeel;
nsCOMPtr<nsIIOService> mIOService;
nsFont mDefaultVariableFont;
nsFont mDefaultFixedFont;

Просмотреть файл

@ -1966,7 +1966,9 @@ nsImageFrame::RealLoadImage(const nsAString& aSpec, nsIPresContext *aPresContext
nsCOMPtr<nsIURI> realURI;
/* don't load the image if some security check fails... */
GetRealURI(aSpec, getter_AddRefs(realURI));
nsCOMPtr<nsIIOService> ioService;
aPresContext->GetIOService(getter_AddRefs(ioService));
GetRealURI(aSpec, ioService, getter_AddRefs(realURI));
if (aCheckContentPolicy)
if (!CanLoadImage(realURI)) return NS_ERROR_FAILURE;
@ -2052,12 +2054,14 @@ nsImageFrame::GetURI(const nsAString& aSpec, nsIURI **aURI)
newURI.Assign(NS_LITERAL_STRING("resource:/res/html/gopher-") +
Substring(aSpec, INTERNAL_GOPHER_LENGTH, aSpec.Length() - INTERNAL_GOPHER_LENGTH) +
NS_LITERAL_STRING(".gif"));
GetRealURI(newURI, aURI);
// XXXldb Using GetRealURI seems silly.
GetRealURI(newURI, nsnull, aURI);
}
}
void
nsImageFrame::GetRealURI(const nsAString& aSpec, nsIURI **aURI)
nsImageFrame::GetRealURI(const nsAString& aSpec, nsIIOService *aIOService,
nsIURI **aURI)
{
nsCOMPtr<nsIURI> baseURI;
GetBaseURI(getter_AddRefs(baseURI));
@ -2065,7 +2069,7 @@ nsImageFrame::GetRealURI(const nsAString& aSpec, nsIURI **aURI)
GetDocumentCharacterSet(charset);
NS_NewURI(aURI, aSpec,
charset.IsEmpty() ? nsnull : NS_ConvertUCS2toUTF8(charset).get(),
baseURI);
baseURI, aIOService);
}
void

Просмотреть файл

@ -215,7 +215,8 @@ protected:
inline PRBool CanLoadImage(nsIURI *aURI);
inline void GetURI(const nsAString& aSpec, nsIURI **aURI);
inline void GetRealURI(const nsAString& aSpec, nsIURI **aURI);
inline void GetRealURI(const nsAString& aSpec, nsIIOService *aIOService,
nsIURI **aURI);
inline void GetBaseURI(nsIURI **uri);
inline void GetLoadGroup(nsIPresContext *aPresContext, nsILoadGroup **aLoadGroup);

Просмотреть файл

@ -1966,7 +1966,9 @@ nsImageFrame::RealLoadImage(const nsAString& aSpec, nsIPresContext *aPresContext
nsCOMPtr<nsIURI> realURI;
/* don't load the image if some security check fails... */
GetRealURI(aSpec, getter_AddRefs(realURI));
nsCOMPtr<nsIIOService> ioService;
aPresContext->GetIOService(getter_AddRefs(ioService));
GetRealURI(aSpec, ioService, getter_AddRefs(realURI));
if (aCheckContentPolicy)
if (!CanLoadImage(realURI)) return NS_ERROR_FAILURE;
@ -2052,12 +2054,14 @@ nsImageFrame::GetURI(const nsAString& aSpec, nsIURI **aURI)
newURI.Assign(NS_LITERAL_STRING("resource:/res/html/gopher-") +
Substring(aSpec, INTERNAL_GOPHER_LENGTH, aSpec.Length() - INTERNAL_GOPHER_LENGTH) +
NS_LITERAL_STRING(".gif"));
GetRealURI(newURI, aURI);
// XXXldb Using GetRealURI seems silly.
GetRealURI(newURI, nsnull, aURI);
}
}
void
nsImageFrame::GetRealURI(const nsAString& aSpec, nsIURI **aURI)
nsImageFrame::GetRealURI(const nsAString& aSpec, nsIIOService *aIOService,
nsIURI **aURI)
{
nsCOMPtr<nsIURI> baseURI;
GetBaseURI(getter_AddRefs(baseURI));
@ -2065,7 +2069,7 @@ nsImageFrame::GetRealURI(const nsAString& aSpec, nsIURI **aURI)
GetDocumentCharacterSet(charset);
NS_NewURI(aURI, aSpec,
charset.IsEmpty() ? nsnull : NS_ConvertUCS2toUTF8(charset).get(),
baseURI);
baseURI, aIOService);
}
void

Просмотреть файл

@ -215,7 +215,8 @@ protected:
inline PRBool CanLoadImage(nsIURI *aURI);
inline void GetURI(const nsAString& aSpec, nsIURI **aURI);
inline void GetRealURI(const nsAString& aSpec, nsIURI **aURI);
inline void GetRealURI(const nsAString& aSpec, nsIIOService *aIOService,
nsIURI **aURI);
inline void GetBaseURI(nsIURI **uri);
inline void GetLoadGroup(nsIPresContext *aPresContext, nsILoadGroup **aLoadGroup);

Просмотреть файл

@ -176,8 +176,7 @@ nsMenuPopupFrame::Init(nsIPresContext* aPresContext,
// lookup if we're allowed to overlap the OS bar (menubar/taskbar) from the
// look&feel object
nsCOMPtr<nsILookAndFeel> lookAndFeel;
nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, NS_GET_IID(nsILookAndFeel),
getter_AddRefs(lookAndFeel));
aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel));
if ( lookAndFeel ) {
PRBool tempBool;
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, tempBool);