Merge m-c to b-i

This commit is contained in:
Phil Ringnalda 2013-10-22 20:09:33 -07:00
commit d6a04e83b5
422 changed files with 6826 additions and 1909 deletions

View File

@ -329,7 +329,7 @@ DocManager::AddListeners(nsIDocument* aDocument,
{
nsPIDOMWindow* window = aDocument->GetWindow();
EventTarget* target = window->GetChromeEventHandler();
nsEventListenerManager* elm = target->GetListenerManager(true);
nsEventListenerManager* elm = target->GetOrCreateListenerManager();
elm->AddEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture());
@ -359,7 +359,7 @@ DocManager::RemoveListeners(nsIDocument* aDocument)
if (!target)
return;
nsEventListenerManager* elm = target->GetListenerManager(true);
nsEventListenerManager* elm = target->GetOrCreateListenerManager();
elm->RemoveEventListenerByType(this, NS_LITERAL_STRING("pagehide"),
dom::TrustedEventsAtCapture());

View File

@ -56,13 +56,6 @@ public:
return *this;
}
Relation& operator = (Relation& aRelation)
{
mFirstIter = aRelation.mFirstIter;
mLastIter = aRelation.mLastIter;
return *this;
}
operator RelationCopyHelper()
{
return RelationCopyHelper(mFirstIter.forget(), mLastIter);

View File

@ -46,7 +46,7 @@ nsCoreUtils::HasClickListener(nsIContent *aContent)
{
NS_ENSURE_TRUE(aContent, false);
nsEventListenerManager* listenerManager =
aContent->GetListenerManager(false);
aContent->GetExistingListenerManager();
return listenerManager &&
(listenerManager->HasListenersFor(nsGkAtoms::onclick) ||

View File

@ -814,6 +814,9 @@ pref("devtools.debugger.unix-domain-socket", "/data/local/debugger-socket");
pref("gfx.canvas.azure.backends", "skia");
pref("gfx.canvas.azure.accelerated", true);
// Turn on dynamic cache size for Skia
pref("gfx.canvas.skiagl.dynamic-cache", true);
// Enable Telephony API
pref("dom.telephony.enabled", true);

View File

@ -216,8 +216,8 @@ MOZ_UNICHARUTIL_LIBS = $(LIBXUL_DIST)/lib/$(LIB_PREFIX)unicharutil_s.$(LIB_SUFFI
MOZ_WIDGET_SUPPORT_LIBS = $(DIST)/lib/$(LIB_PREFIX)widgetsupport_s.$(LIB_SUFFIX)
ifdef _MSC_VER
CC_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
CXX_WRAPPER ?= $(PYTHON) -O $(topsrcdir)/build/cl.py
CC_WRAPPER = $(call py_action,cl)
CXX_WRAPPER = $(call py_action,cl)
endif # _MSC_VER
CC := $(CC_WRAPPER) $(CC)
@ -896,15 +896,3 @@ MOZ_GTK2_CFLAGS := -I$(topsrcdir)/widget/gtk/compat $(MOZ_GTK2_CFLAGS)
endif
DEFINES += -DNO_NSPR_10_SUPPORT
# Run a named Python build action. The first argument is the name of the build
# action. The second argument are the arguments to pass to the action (space
# delimited arguments). e.g.
#
# libs::
# $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
ifdef .PYMAKE
py_action = %mozbuild.action.$(1) main $(2)
else
py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
endif

View File

@ -20,3 +20,15 @@ core_abspath = $(error core_abspath is unsupported, use $$(abspath) instead)
core_realpath = $(error core_realpath is unsupported)
core_winabspath = $(error core_winabspath is unsupported)
# Run a named Python build action. The first argument is the name of the build
# action. The second argument are the arguments to pass to the action (space
# delimited arguments). e.g.
#
# libs::
# $(call py_action,purge_manifests,_build_manifests/purge/foo.manifest)
ifdef .PYMAKE
py_action = %mozbuild.action.$(1) main $(2)
else
py_action = $(PYTHON) -m mozbuild.action.$(1) $(2)
endif

View File

@ -5369,7 +5369,7 @@ AC_SUBST(MOZ_NATIVE_LIBVPX)
AC_SUBST(MOZ_LIBVPX_CFLAGS)
AC_SUBST(MOZ_LIBVPX_LIBS)
if test "$MOZ_WEBM"; then
if test "$MOZ_WEBM" -o "$MOZ_OGG"; then
MOZ_CUBEB=1
if test "$MOZ_SAMPLE_TYPE_FLOAT32"; then
MOZ_VORBIS=1
@ -5491,10 +5491,23 @@ if test -n "$MOZ_CUBEB"; then
AC_DEFINE(MOZ_CUBEB)
fi
if test -n "$MOZ_OPUS" -a -z "$MOZ_OGG"; then
AC_MSG_ERROR([MOZ_OPUS requires MOZ_OGG which is disabled.])
fi
if test -n "$MOZ_VORBIS" -a -z "$MOZ_OGG"; then
AC_MSG_ERROR([MOZ_VORBIS requires MOZ_OGG which is disabled.
Note that you need vorbis support for WebM playback.])
fi
if test -n "$MOZ_VORBIS" -a -n "$MOZ_TREMOR"; then
AC_MSG_ERROR([MOZ_VORBIS and MOZ_TREMOR are mutually exclusive! The build system should not allow them both to be set, but they are. Please file a bug at https://bugzilla.mozilla.org/])
fi
if test -n "$MOZ_WEBRTC" -a -z "$MOZ_OPUS"; then
AC_MSG_ERROR([MOZ_WEBRTC requires MOZ_OPUS which is disabled.])
fi
if test -n "$MOZ_VORBIS"; then
AC_DEFINE(MOZ_VORBIS)
fi

View File

@ -1059,15 +1059,19 @@ public:
nsCycleCollectionTraversalCallback &cb);
/**
* Get the eventlistener manager for aNode. If a new eventlistener manager
* was created, aCreated is set to true.
* Get the eventlistener manager for aNode, creating it if it does not
* already exist.
*
* @param aNode The node for which to get the eventlistener manager.
* @param aCreateIfNotFound If false, returns a listener manager only if
* one already exists.
*/
static nsEventListenerManager* GetListenerManager(nsINode* aNode,
bool aCreateIfNotFound);
static nsEventListenerManager* GetListenerManagerForNode(nsINode* aNode);
/**
* Get the eventlistener manager for aNode, returning null if it does not
* already exist.
*
* @param aNode The node for which to get the eventlistener manager.
*/
static nsEventListenerManager* GetExistingListenerManagerForNode(const nsINode* aNode);
static void UnmarkGrayJSListenersInCCGenerationDocuments(uint32_t aGeneration);

View File

@ -800,6 +800,12 @@ public:
* See nsIDOMEventTarget
*/
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
using nsIDOMEventTarget::AddEventListener;
virtual void AddEventListener(const nsAString& aType,

View File

@ -1813,7 +1813,7 @@ Element::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
bool* aDefer)
{
*aDefer = true;
return GetListenerManager(true);
return GetOrCreateListenerManager();
}
Element::nsAttrInfo

View File

@ -1224,7 +1224,7 @@ FragmentOrElement::MarkNodeChildren(nsINode* aNode)
JS::ExposeObjectToActiveJS(o);
}
nsEventListenerManager* elm = aNode->GetListenerManager(false);
nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}

View File

@ -144,7 +144,7 @@ MarkMessageManagers()
continue;
}
static_cast<nsInProcessTabChildGlobal*>(et)->MarkForCC();
nsEventListenerManager* elm = et->GetListenerManager(false);
nsEventListenerManager* elm = et->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
@ -188,13 +188,13 @@ MarkContentViewer(nsIContentViewer* aViewer, bool aCleanupJS,
doc->GetMarkedCCGeneration() != nsCCUncollectableMarker::sGeneration) {
doc->MarkUncollectableForCCGeneration(nsCCUncollectableMarker::sGeneration);
if (aCleanupJS) {
nsEventListenerManager* elm = doc->GetListenerManager(false);
nsEventListenerManager* elm = doc->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
nsCOMPtr<EventTarget> win = do_QueryInterface(doc->GetInnerWindow());
if (win) {
elm = win->GetListenerManager(false);
elm = win->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}

View File

@ -3633,7 +3633,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
if (aNode->IsInDoc()) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(window));
if (piTarget) {
nsEventListenerManager* manager = piTarget->GetListenerManager(false);
nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) {
return true;
}
@ -3644,7 +3644,7 @@ nsContentUtils::HasMutationListeners(nsINode* aNode,
// might not be in our chain. If we don't have a window, we might have a
// mutation listener. Check quickly to see.
while (aNode) {
nsEventListenerManager* manager = aNode->GetListenerManager(false);
nsEventListenerManager* manager = aNode->GetExistingListenerManager();
if (manager && manager->HasMutationListeners()) {
return true;
}
@ -3766,13 +3766,8 @@ nsContentUtils::TraverseListenerManager(nsINode *aNode,
}
nsEventListenerManager*
nsContentUtils::GetListenerManager(nsINode *aNode,
bool aCreateIfNotFound)
nsContentUtils::GetListenerManagerForNode(nsINode *aNode)
{
if (!aCreateIfNotFound && !aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener
// manager.
@ -3780,17 +3775,6 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return nullptr;
}
if (!aCreateIfNotFound) {
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
@ -3809,6 +3793,31 @@ nsContentUtils::GetListenerManager(nsINode *aNode,
return entry->mListenerManager;
}
nsEventListenerManager*
nsContentUtils::GetExistingListenerManagerForNode(const nsINode *aNode)
{
if (!aNode->HasFlag(NODE_HAS_LISTENERMANAGER)) {
return nullptr;
}
if (!sEventListenerManagersHash.ops) {
// We're already shut down, don't bother creating an event listener
// manager.
return nullptr;
}
EventListenerManagerMapEntry *entry =
static_cast<EventListenerManagerMapEntry *>
(PL_DHashTableOperate(&sEventListenerManagersHash, aNode,
PL_DHASH_LOOKUP));
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
return entry->mListenerManager;
}
return nullptr;
}
/* static */
void
nsContentUtils::RemoveListenerManager(nsINode *aNode)

View File

@ -1659,7 +1659,7 @@ nsDocument::DeleteCycleCollectable()
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsDocument)
if (Element::CanSkip(tmp, aRemovingAllowed)) {
nsEventListenerManager* elm = tmp->GetListenerManager(false);
nsEventListenerManager* elm = tmp->GetExistingListenerManager();
if (elm) {
elm->MarkForCC();
}
@ -6971,9 +6971,9 @@ nsDocument::GetViewportInfo(const ScreenIntSize& aDisplaySize)
}
nsEventListenerManager*
nsDocument::GetListenerManager(bool aCreateIfNotFound)
nsDocument::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
SetFlags(NODE_HAS_LISTENERMANAGER);
@ -6982,6 +6982,12 @@ nsDocument::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsDocument::GetExistingListenerManager() const
{
return mListenerManager;
}
nsresult
nsDocument::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
{
@ -7675,8 +7681,7 @@ nsDocument::CanSavePresentation(nsIRequest *aNewRequest)
// Check our event listener manager for unload/beforeunload listeners.
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(mScriptGlobalObject);
if (piTarget) {
nsEventListenerManager* manager =
piTarget->GetListenerManager(false);
nsEventListenerManager* manager = piTarget->GetExistingListenerManager();
if (manager && manager->HasUnloadListeners()) {
return false;
}

View File

@ -773,8 +773,8 @@ public:
// nsIDOMEventTarget
virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetListenerManager(bool aCreateIfNotFound) MOZ_OVERRIDE;
virtual nsEventListenerManager* GetOrCreateListenerManager() MOZ_OVERRIDE;
virtual nsEventListenerManager* GetExistingListenerManager() const MOZ_OVERRIDE;
// nsIScriptObjectPrincipal
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE;

View File

@ -1782,6 +1782,7 @@ GK_ATOM(blockFrame, "BlockFrame")
GK_ATOM(boxFrame, "BoxFrame")
GK_ATOM(brFrame, "BRFrame")
GK_ATOM(bulletFrame, "BulletFrame")
GK_ATOM(colorControlFrame, "colorControlFrame")
GK_ATOM(columnSetFrame, "ColumnSetFrame")
GK_ATOM(comboboxControlFrame, "ComboboxControlFrame")
GK_ATOM(comboboxDisplayFrame, "ComboboxDisplayFrame")

View File

@ -1038,7 +1038,7 @@ nsINode::AddEventListener(const nsAString& aType,
aWantsUntrusted = true;
}
nsEventListenerManager* listener_manager = GetListenerManager(true);
nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
NS_ENSURE_STATE(listener_manager);
listener_manager->AddEventListener(aType, aListener, aUseCapture,
aWantsUntrusted);
@ -1059,7 +1059,7 @@ nsINode::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* listener_manager = GetListenerManager(true);
nsEventListenerManager* listener_manager = GetOrCreateListenerManager();
if (!listener_manager) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -1095,7 +1095,7 @@ nsINode::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -1157,9 +1157,15 @@ nsINode::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager*
nsINode::GetListenerManager(bool aCreateIfNotFound)
nsINode::GetOrCreateListenerManager()
{
return nsContentUtils::GetListenerManager(this, aCreateIfNotFound);
return nsContentUtils::GetListenerManagerForNode(this);
}
nsEventListenerManager*
nsINode::GetExistingListenerManager() const
{
return nsContentUtils::GetExistingListenerManagerForNode(this);
}
nsIScriptContext*
@ -2164,8 +2170,7 @@ size_t
nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
{
size_t n = 0;
nsEventListenerManager* elm =
const_cast<nsINode*>(this)->GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
n += elm->SizeOfIncludingThis(aMallocSizeOf);
}
@ -2183,13 +2188,13 @@ nsINode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
#define EVENT(name_, id_, type_, struct_) \
EventHandlerNonNull* nsINode::GetOn##name_() { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \
} \
void nsINode::SetOn##name_(EventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
} \

View File

@ -231,7 +231,7 @@ nsNodeUtils::LastRelease(nsINode* aNode)
#ifdef DEBUG
if (nsContentUtils::IsInitialized()) {
nsEventListenerManager* manager =
nsContentUtils::GetListenerManager(aNode, false);
nsContentUtils::GetExistingListenerManagerForNode(aNode);
if (!manager) {
NS_ERROR("Huh, our bit says we have a listener manager list, "
"but there's nothing in the hash!?!!");
@ -480,7 +480,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsPIDOMWindow* window = newDoc->GetInnerWindow();
if (window) {
nsEventListenerManager* elm = aNode->GetListenerManager(false);
nsEventListenerManager* elm = aNode->GetExistingListenerManager();
if (elm) {
window->SetMutationListeners(elm->MutationListenerBits());
if (elm->MayHavePaintEventListener()) {

View File

@ -2172,7 +2172,8 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
NS_ASSERTION(!(mState & XML_HTTP_REQUEST_SYNCLOOPING),
"We weren't supposed to support HTML parsing with XHR!");
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(mResponseXML);
nsEventListenerManager* manager = eventTarget->GetListenerManager(true);
nsEventListenerManager* manager =
eventTarget->GetOrCreateListenerManager();
manager->AddEventListenerByType(new nsXHRParseEndListener(this),
NS_LITERAL_STRING("DOMContentLoaded"),
dom::TrustedEventsAtSystemGroupBubble());

View File

@ -26,8 +26,8 @@ template <class T> struct Nullable;
// IID for the dom::EventTarget interface
#define NS_EVENTTARGET_IID \
{ 0x0a5aed21, 0x0bab, 0x48b3, \
{ 0xbe, 0x4b, 0xd4, 0xf9, 0xd4, 0xea, 0xc7, 0xdb } }
{ 0xce3817d0, 0x177b, 0x402f, \
{ 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
class EventTarget : public nsIDOMEventTarget,
public nsWrapperCache
@ -70,6 +70,17 @@ public:
// current inner or if there is no window around at all.
virtual nsIDOMWindow* GetOwnerGlobal() = 0;
/**
* Get the event listener manager, creating it if it does not already exist.
*/
virtual nsEventListenerManager* GetOrCreateListenerManager() = 0;
/**
* Get the event listener manager, returning null if it does not already
* exist.
*/
virtual nsEventListenerManager* GetExistingListenerManager() const = 0;
protected:
EventHandlerNonNull* GetEventHandler(nsIAtom* aType,
const nsAString& aTypeString);

View File

@ -16,7 +16,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
bool aUseCapture,
ErrorResult& aRv)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -25,7 +25,7 @@ EventTarget::RemoveEventListener(const nsAString& aType,
EventHandlerNonNull*
EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
}
@ -52,7 +52,7 @@ void
EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
EventHandlerNonNull* aHandler)
{
GetListenerManager(true)->SetEventHandler(aType, aTypeString, aHandler);
GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
}
} // namespace dom

View File

@ -154,7 +154,7 @@ nsDOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsEventListenerManager* elm = GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
@ -181,7 +181,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
NS_ENSURE_SUCCESS(rv, rv);
}
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -205,7 +205,7 @@ nsDOMEventTargetHelper::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -319,15 +319,21 @@ nsDOMEventTargetHelper::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager*
nsDOMEventTargetHelper::GetListenerManager(bool aCreateIfNotFound)
nsDOMEventTargetHelper::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager = new nsEventListenerManager(this);
}
return mListenerManager;
}
nsEventListenerManager*
nsDOMEventTargetHelper::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext*
nsDOMEventTargetHelper::GetContextForEventHandlers(nsresult* aRv)
{

View File

@ -44,6 +44,12 @@ public:
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsDOMEventTargetHelper)
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,
@ -219,8 +225,11 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
virtual nsresult DispatchDOMEvent(mozilla::WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent, nsPresContext* aPresContext, nsEventStatus* aEventStatus) { \
return _to DispatchDOMEvent(aEvent, aDOMEvent, aPresContext, aEventStatus); \
} \
virtual nsEventListenerManager * GetListenerManager(bool aMayCreate) { \
return _to GetListenerManager(aMayCreate); \
virtual nsEventListenerManager * GetOrCreateListenerManager() { \
return _to GetOrCreateListenerManager(); \
} \
virtual nsEventListenerManager * GetExistingListenerManager() const { \
return _to GetExistingListenerManager(); \
} \
virtual nsIScriptContext * GetContextForEventHandlers(nsresult *aRv) { \
return _to GetContextForEventHandlers(aRv); \
@ -232,6 +241,14 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
#define NS_REALLY_FORWARD_NSIDOMEVENTTARGET(_class) \
using _class::AddEventListener; \
using _class::RemoveEventListener; \
NS_FORWARD_NSIDOMEVENTTARGET(_class::)
NS_FORWARD_NSIDOMEVENTTARGET(_class::) \
virtual nsEventListenerManager* \
GetOrCreateListenerManager() { \
return _class::GetOrCreateListenerManager(); \
} \
virtual nsEventListenerManager* \
GetExistingListenerManager() const { \
return _class::GetExistingListenerManager(); \
}
#endif // nsDOMEventTargetHelper_h_

View File

@ -185,8 +185,7 @@ public:
if (!MayHaveListenerManager() && !aCd.MayHaveNewListenerManager()) {
return NS_OK;
}
mManager =
static_cast<nsEventListenerManager*>(mTarget->GetListenerManager(false));
mManager = mTarget->GetExistingListenerManager();
}
if (mManager) {
NS_ASSERTION(aVisitor.mEvent->currentTarget == nullptr,

View File

@ -560,7 +560,8 @@ NS_AddSystemEventListener(mozilla::dom::EventTarget* aTarget,
bool aUseCapture,
bool aWantsUntrusted)
{
nsEventListenerManager* listenerManager = aTarget->GetListenerManager(true);
nsEventListenerManager* listenerManager =
aTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(listenerManager);
mozilla::dom::EventListenerFlags flags;
flags.mInSystemGroup = true;

View File

@ -162,8 +162,11 @@ nsEventListenerService::GetListenerInfoFor(nsIDOMEventTarget* aEventTarget,
*aCount = 0;
*aOutArray = nullptr;
nsCOMArray<nsIEventListenerInfo> listenerInfos;
nsEventListenerManager* elm =
aEventTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
if (elm) {
elm->GetListenerInfo(&listenerInfos);
}
@ -221,7 +224,10 @@ nsEventListenerService::HasListenersFor(nsIDOMEventTarget* aEventTarget,
const nsAString& aType,
bool* aRetVal)
{
nsEventListenerManager* elm = aEventTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aEventTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* elm = eventTarget->GetExistingListenerManager();
*aRetVal = elm && elm->HasListenersFor(aType);
return NS_OK;
}
@ -235,7 +241,10 @@ nsEventListenerService::AddSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(true);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
EventListenerFlags flags =
@ -254,7 +263,10 @@ nsEventListenerService::RemoveSystemEventListener(nsIDOMEventTarget *aTarget,
NS_PRECONDITION(aTarget, "Missing target");
NS_PRECONDITION(aListener, "Missing listener");
nsEventListenerManager* manager = aTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
if (manager) {
EventListenerFlags flags =
aUseCapture ? TrustedEventsAtSystemGroupCapture() :
@ -273,7 +285,11 @@ nsEventListenerService::AddListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup)
{
NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(true);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
manager->AddListenerForAllEvents(aListener, aUseCapture, aWantsUntrusted,
aSystemEventGroup);
@ -287,7 +303,11 @@ nsEventListenerService::RemoveListenerForAllEvents(nsIDOMEventTarget* aTarget,
bool aSystemEventGroup)
{
NS_ENSURE_STATE(aTarget && aListener);
nsEventListenerManager* manager = aTarget->GetListenerManager(false);
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(aTarget);
NS_ENSURE_TRUE(eventTarget, NS_ERROR_NO_INTERFACE);
nsEventListenerManager* manager = eventTarget->GetExistingListenerManager();
if (manager) {
manager->RemoveListenerForAllEvents(aListener, aUseCapture, aSystemEventGroup);
}

View File

@ -2677,6 +2677,14 @@ HTMLInputElement::SetValueInternal(const nsAString& aValue,
OnValueChanged(!mParserCreating);
}
// Call parent's SetAttr for color input so its control frame is notified
// and updated
if (mType == NS_FORM_INPUT_COLOR) {
return nsGenericHTMLFormElement::SetAttr(kNameSpaceID_None,
nsGkAtoms::value, aValue,
true);
}
return NS_OK;
}
@ -3530,6 +3538,7 @@ HTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
case NS_FORM_INPUT_RESET:
case NS_FORM_INPUT_SUBMIT:
case NS_FORM_INPUT_IMAGE: // Bug 34418
case NS_FORM_INPUT_COLOR:
{
WidgetMouseEvent event(aVisitor.mEvent->mFlags.mIsTrusted,
NS_MOUSE_CLICK, nullptr,

View File

@ -842,7 +842,7 @@ nsGenericHTMLElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
if ((win = document->GetInnerWindow())) {
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(win));
return piTarget->GetListenerManager(true);
return piTarget->GetOrCreateListenerManager();
}
return nullptr;
@ -1009,8 +1009,7 @@ nsGenericHTMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
UnsetFlags(NODE_HAS_ACCESSKEY);
}
else if (IsEventAttributeName(aAttribute)) {
nsEventListenerManager* manager = GetListenerManager(false);
if (manager) {
if (nsEventListenerManager* manager = GetExistingListenerManager()) {
manager->RemoveEventHandler(aAttribute, EmptyString());
}
}

View File

@ -1562,8 +1562,7 @@ nsTextEditorState::UnbindFromFrame(nsTextControlFrame* aFrame)
mTextListener->SetFrame(nullptr);
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager =
target->GetListenerManager(false);
nsEventListenerManager* manager = target->GetExistingListenerManager();
if (manager) {
manager->RemoveEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"),
@ -1970,7 +1969,7 @@ nsTextEditorState::InitializeKeyboardEventListeners()
{
//register key listeners
nsCOMPtr<EventTarget> target = do_QueryInterface(mTextCtrlElement);
nsEventListenerManager* manager = target->GetListenerManager(true);
nsEventListenerManager* manager = target->GetOrCreateListenerManager();
if (manager) {
manager->AddEventListenerByType(mTextListener,
NS_LITERAL_STRING("keydown"),

View File

@ -372,7 +372,7 @@ nsSMILTimeValueSpec::GetEventListenerManager(Element* aTarget)
if (!target)
return nullptr;
return target->GetListenerManager(true);
return target->GetOrCreateListenerManager();
}
void

View File

@ -96,11 +96,7 @@ SVGEllipseElement::ConstructPath(gfxContext *aCtx)
GetAnimatedLengthValues(&x, &y, &rx, &ry, nullptr);
if (rx > 0.0f && ry > 0.0f) {
aCtx->Save();
aCtx->Translate(gfxPoint(x, y));
aCtx->Scale(rx, ry);
aCtx->Arc(gfxPoint(0, 0), 1, 0, 2 * M_PI);
aCtx->Restore();
aCtx->Ellipse(gfxPoint(x, y), gfxSize(2.0*rx, 2.0*ry));
}
}

View File

@ -3,8 +3,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#ifndef MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_
#define MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_
#include "mozilla/HashFunctions.h" // for HashGeneric
#include "mozilla/TypedEnum.h"
#include "nsWrapperCache.h"
@ -98,6 +100,10 @@ public:
return mDefer;
}
uint32_t Hash() const {
return HashGeneric(mAlign, mMeetOrSlice, mDefer);
}
private:
// We can't use enum types here because some compilers fail to pack them.
uint8_t mAlign;
@ -141,3 +147,5 @@ protected:
} //namespace dom
} //namespace mozilla
#endif // MOZILLA_CONTENT_SVGPRESERVEASPECTRATIO_H_

View File

@ -8,6 +8,7 @@ MODULE = 'content'
EXPORTS += [
'SVGAttrValueWrapper.h',
'SVGPreserveAspectRatio.h',
'SVGStringList.h',
'nsSVGClass.h',
'nsSVGElement.h',

View File

@ -664,7 +664,7 @@ nsSVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsIAtom* aName,
mContentStyleRule = nullptr;
if (IsEventAttributeName(aName)) {
nsEventListenerManager* manager = GetListenerManager(false);
nsEventListenerManager* manager = GetExistingListenerManager();
if (manager) {
nsIAtom* eventName = GetEventNameForAttr(aName);
manager->RemoveEventHandler(eventName, EmptyString());

View File

@ -498,8 +498,7 @@ nsXBLBinding::InstallEventHandlers()
nsXBLPrototypeHandler* handlerChain = mPrototypeBinding->GetPrototypeHandlers();
if (handlerChain) {
nsEventListenerManager* manager =
mBoundElement->GetListenerManager(true);
nsEventListenerManager* manager = mBoundElement->GetOrCreateListenerManager();
if (!manager)
return;
@ -648,7 +647,7 @@ nsXBLBinding::UnhookEventHandlers()
if (handlerChain) {
nsEventListenerManager* manager =
mBoundElement->GetListenerManager(false);
mBoundElement->GetExistingListenerManager();
if (!manager) {
return;
}

View File

@ -561,7 +561,7 @@ nsXBLService::AttachGlobalKeyHandler(EventTarget* aTarget)
piTarget = doc; // We're a XUL keyset. Attach to our document.
}
nsEventListenerManager* manager = piTarget->GetListenerManager(true);
nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
if (!piTarget || !manager)
return NS_ERROR_FAILURE;
@ -611,7 +611,7 @@ nsXBLService::DetachGlobalKeyHandler(EventTarget* aTarget)
if (doc)
piTarget = do_QueryInterface(doc);
nsEventListenerManager* manager = piTarget->GetListenerManager(true);
nsEventListenerManager* manager = piTarget->GetOrCreateListenerManager();
if (!piTarget || !manager)
return NS_ERROR_FAILURE;

View File

@ -496,7 +496,7 @@ nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
*aDefer = false;
return piTarget->GetListenerManager(true);
return piTarget->GetOrCreateListenerManager();
}
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
@ -1670,7 +1670,7 @@ nsXULElement::AddPopupListener(nsIAtom* aName)
new nsXULPopupListener(this, isContext);
// Add the popup as a listener on this element.
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
SetFlags(listenerFlag);
if (isContext) {

View File

@ -205,6 +205,7 @@
#include "nsRefreshDriver.h"
#include "mozilla/Services.h"
#include "mozilla/Telemetry.h"
#include "nsLocation.h"
#include "nsHTMLDocument.h"
@ -1570,8 +1571,7 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsGlobalWindow)
if (tmp->mCachedXBLPrototypeHandlers) {
tmp->mCachedXBLPrototypeHandlers->Enumerate(MarkXBLHandlers, nullptr);
}
nsEventListenerManager* elm = tmp->GetListenerManager(false);
if (elm) {
if (nsEventListenerManager* elm = tmp->GetExistingListenerManager()) {
elm->MarkForCC();
}
tmp->UnmarkGrayTimers();
@ -8068,8 +8068,7 @@ nsGlobalWindow::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture)
{
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false);
if (elm) {
if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
return NS_OK;
@ -8124,7 +8123,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
aWantsUntrusted = true;
}
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
NS_ENSURE_STATE(manager);
manager->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -8150,7 +8149,7 @@ nsGlobalWindow::AddEventListener(const nsAString& aType,
wantsUntrusted = aWantsUntrusted.Value();
}
nsEventListenerManager* manager = GetListenerManager(true);
nsEventListenerManager* manager = GetOrCreateListenerManager();
if (!manager) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -8185,11 +8184,11 @@ nsGlobalWindow::AddSystemEventListener(const nsAString& aType,
}
nsEventListenerManager*
nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
nsGlobalWindow::GetOrCreateListenerManager()
{
FORWARD_TO_INNER_CREATE(GetListenerManager, (aCreateIfNotFound), nullptr);
FORWARD_TO_INNER_CREATE(GetOrCreateListenerManager, (), nullptr);
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
}
@ -8197,6 +8196,14 @@ nsGlobalWindow::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsGlobalWindow::GetExistingListenerManager() const
{
FORWARD_TO_INNER(GetExistingListenerManager, (), nullptr);
return mListenerManager;
}
nsIScriptContext*
nsGlobalWindow::GetContextForEventHandlers(nsresult* aRv)
{
@ -8394,7 +8401,7 @@ void nsGlobalWindow::MaybeUpdateTouchState()
if (mMayHaveTouchEventListener) {
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
services::GetObserverService();
if (observerService) {
observerService->NotifyObservers(static_cast<nsIDOMWindow*>(this),
@ -11544,8 +11551,7 @@ nsGlobalWindow::AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const
aWindowSizes->mDOMOther += aWindowSizes->mMallocSizeOf(this);
if (IsInnerWindow()) {
nsEventListenerManager* elm =
const_cast<nsGlobalWindow*>(this)->GetListenerManager(false);
nsEventListenerManager* elm = GetExistingListenerManager();
if (elm) {
aWindowSizes->mDOMOther +=
elm->SizeOfIncludingThis(aWindowSizes->mMallocSizeOf);
@ -12084,7 +12090,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define ERROR_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
if (elm) { \
OnErrorEventHandlerNonNull* h = elm->GetOnErrorEventHandler(); \
if (h) { \
@ -12097,7 +12103,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \
@ -12114,7 +12120,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
JS::Value *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
if (elm) { \
BeforeUnloadEventHandlerNonNull* h = \
elm->GetOnBeforeUnloadEventHandler(); \
@ -12128,7 +12134,7 @@ nsGlobalWindow::DisableNetworkEvent(uint32_t aType)
} \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const JS::Value &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \

View File

@ -371,6 +371,13 @@ public:
// nsIDOMEventTarget
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,
@ -552,7 +559,7 @@ public:
return static_cast<nsGlobalWindow *>(GetOuterWindow());
}
nsGlobalWindow *GetCurrentInnerWindowInternal()
nsGlobalWindow *GetCurrentInnerWindowInternal() const
{
return static_cast<nsGlobalWindow *>(mInnerWindow);
}
@ -708,13 +715,13 @@ public:
#define EVENT(name_, id_, type_, struct_) \
mozilla::dom::EventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
: nullptr; \
} \
void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
} \
@ -722,12 +729,12 @@ public:
#define ERROR_EVENT(name_, id_, type_, struct_) \
mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnErrorEventHandler() : nullptr; \
} \
void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(handler); \
} \
@ -735,12 +742,12 @@ public:
#define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
mozilla::dom::BeforeUnloadEventHandlerNonNull* GetOn##name_() \
{ \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetExistingListenerManager(); \
return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
} \
void SetOn##name_(mozilla::dom::BeforeUnloadEventHandlerNonNull* handler) \
{ \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetOrCreateListenerManager(); \
if (elm) { \
elm->SetEventHandler(handler); \
} \

View File

@ -64,8 +64,7 @@ NS_IMPL_DOMTARGET_DEFAULTS(nsWindowRoot)
NS_IMETHODIMP
nsWindowRoot::RemoveEventListener(const nsAString& aType, nsIDOMEventListener* aListener, bool aUseCapture)
{
nsRefPtr<nsEventListenerManager> elm = GetListenerManager(false);
if (elm) {
if (nsRefPtr<nsEventListenerManager> elm = GetExistingListenerManager()) {
elm->RemoveEventListener(aType, aListener, aUseCapture);
}
return NS_OK;
@ -105,7 +104,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
"aWantsUntrusted to false or make the aWantsUntrusted "
"explicit by making optional_argc non-zero.");
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
NS_ENSURE_STATE(elm);
elm->AddEventListener(aType, aListener, aUseCapture, aWantsUntrusted);
return NS_OK;
@ -119,7 +118,7 @@ nsWindowRoot::AddEventListener(const nsAString& aType,
ErrorResult& aRv)
{
bool wantsUntrusted = !aWantsUntrusted.IsNull() && aWantsUntrusted.Value();
nsEventListenerManager* elm = GetListenerManager(true);
nsEventListenerManager* elm = GetOrCreateListenerManager();
if (!elm) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -145,9 +144,9 @@ nsWindowRoot::AddSystemEventListener(const nsAString& aType,
}
nsEventListenerManager*
nsWindowRoot::GetListenerManager(bool aCreateIfNotFound)
nsWindowRoot::GetOrCreateListenerManager()
{
if (!mListenerManager && aCreateIfNotFound) {
if (!mListenerManager) {
mListenerManager =
new nsEventListenerManager(static_cast<EventTarget*>(this));
}
@ -155,6 +154,12 @@ nsWindowRoot::GetListenerManager(bool aCreateIfNotFound)
return mListenerManager;
}
nsEventListenerManager*
nsWindowRoot::GetExistingListenerManager() const
{
return mListenerManager;
}
nsIScriptContext*
nsWindowRoot::GetContextForEventHandlers(nsresult* aRv)
{

View File

@ -28,6 +28,12 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
using mozilla::dom::EventTarget::RemoveEventListener;
virtual void AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,

View File

@ -157,6 +157,11 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTTARGET
virtual nsEventListenerManager*
GetExistingListenerManager() const MOZ_OVERRIDE;
virtual nsEventListenerManager*
GetOrCreateListenerManager() MOZ_OVERRIDE;
virtual void
AddEventListener(const nsAString& aType,
mozilla::dom::EventListener* aListener,

View File

@ -3476,9 +3476,15 @@ nsDOMDeviceStorage::DispatchDOMEvent(WidgetEvent* aEvent,
}
nsEventListenerManager *
nsDOMDeviceStorage::GetListenerManager(bool aMayCreate)
nsDOMDeviceStorage::GetOrCreateListenerManager()
{
return nsDOMEventTargetHelper::GetListenerManager(aMayCreate);
return nsDOMEventTargetHelper::GetOrCreateListenerManager();
}
nsEventListenerManager *
nsDOMDeviceStorage::GetExistingListenerManager() const
{
return nsDOMEventTargetHelper::GetExistingListenerManager();
}
nsIScriptContext *

View File

@ -45,7 +45,7 @@ interface nsIScriptContext;
interface nsIDOMEventListener;
interface nsIDOMEvent;
[scriptable, builtinclass, uuid(31e92e56-4d23-4a4a-9cfe-a6d12cf434bc)]
[scriptable, builtinclass, uuid(b128448c-7b53-4769-92cb-cd6eafee676c)]
interface nsIDOMEventTarget : nsISupports
{
/**
@ -267,15 +267,6 @@ interface nsIDOMEventTarget : nsISupports
in nsPresContextPtr aPresContext,
in nsEventStatusPtr aEventStatus);
/**
* Get the event listener manager, the guy you talk to to register for events
* on this node.
* @param aMayCreate If PR_FALSE, returns a listener manager only if
* one already exists.
*/
[notxpcom, nostdcall]
nsEventListenerManagerPtr GetListenerManager(in boolean aMayCreate);
/**
* Get the script context in which the event handlers should be run.
* May return null.
@ -305,7 +296,7 @@ aClass::RemoveSystemEventListener(const nsAString& aType, \
nsIDOMEventListener *aListener, \
bool aUseCapture) \
{ \
nsEventListenerManager* listenerManager = GetListenerManager(false); \
nsEventListenerManager* listenerManager = GetExistingListenerManager(); \
if (!listenerManager) { \
return NS_OK; \
} \

View File

@ -24,6 +24,7 @@
#include "mozilla/layers/ShadowLayers.h"
#include "mozilla/layout/RenderFrameChild.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/TextEvents.h"
#include "mozilla/TouchEvents.h"
@ -1202,7 +1203,7 @@ TabChild::~TabChild()
mGlobal = nullptr;
if (mTabChildGlobal) {
nsEventListenerManager* elm = mTabChildGlobal->GetListenerManager(false);
nsEventListenerManager* elm = mTabChildGlobal->GetExistingListenerManager();
if (elm) {
elm->Disconnect();
}
@ -2103,7 +2104,7 @@ TabChild::RecvDestroy()
}
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
mozilla::services::GetObserverService();
observerService->RemoveObserver(this, CANCEL_DEFAULT_PAN_ZOOM);
observerService->RemoveObserver(this, BROWSER_ZOOM_TO_RECT);
@ -2240,7 +2241,7 @@ TabChild::InitRenderingState()
mRemoteFrame = remoteFrame;
nsCOMPtr<nsIObserverService> observerService =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(this,

View File

@ -38,6 +38,7 @@
#include "nsThreadUtils.h"
#include "nsRadioInterfaceLayer.h"
#include "WifiWorker.h"
#include "mozilla/Services.h"
USING_WORKERS_NAMESPACE
@ -353,8 +354,7 @@ SystemWorkerManager::Init()
do_GetService(NS_AUDIOMANAGER_CONTRACTID);
#endif
nsCOMPtr<nsIObserverService> obs =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs) {
NS_WARNING("Failed to get observer service!");
return NS_ERROR_FAILURE;
@ -399,8 +399,7 @@ SystemWorkerManager::Shutdown()
}
mWifiWorker = nullptr;
nsCOMPtr<nsIObserverService> obs =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, WORKERS_SHUTDOWN_TOPIC);
}

View File

@ -22,7 +22,7 @@ Tests of DOM Worker transferable objects
function test1(sizes) {
if (!sizes.length) {
SimpleTest.finish();
runTests();
return;
}
@ -32,10 +32,15 @@ Tests of DOM Worker transferable objects
worker.onmessage = function(event) {
ok(event.data.status, event.data.event);
if (!event.data.status) {
SimpleTest.finish();
runTests();
return;
}
if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
ok(event.data.notEmpty.byteLength != 0,
"P: NotEmpty object received: " + event.data.notEmpty.byteLength);
}
if (!event.data.last)
return;
@ -60,14 +65,57 @@ Tests of DOM Worker transferable objects
ok(true, "P: PostMessage - Exception for duplicate");
}
ab = new ArrayBuffer(size);
var ab = new ArrayBuffer(size);
ok(ab.byteLength == size, "P: The size is: " + size + " == " + ab.byteLength);
worker.postMessage({ data: 0, timeout: 0, ab: ab, cb: ab, size: size }, [ab]);
ok(ab.byteLength == 0, "P: PostMessage - The size is: 0 == " + ab.byteLength)
}
test1([1024 * 1024 * 32, 128, 4]);
function test2() {
var worker = new Worker("transferable_worker.js");
worker.onmessage = function(event) {
ok(event.data.status, event.data.event);
if (!event.data.status) {
runTests();
return;
}
if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
ok(event.data.notEmpty.byteLength != 0,
"P: NotEmpty object received: " + event.data.notEmpty.byteLength);
}
if (event.data.last) {
runTests();
}
}
worker.onerror = function(event) {
ok(false, "No errors!");
}
var f = new Float32Array([0,1,2,3]);
ok(f.byteLength != 0, "P: The size is: " + f.byteLength + " is not 0");
worker.postMessage({ event: "P: postMessage with Float32Array", status: true,
size: 4, notEmpty: f, bc: [ f, f, { dd: f } ] }, [f.buffer]);
ok(f.byteLength == 0, "P: The size is: " + f.byteLength + " is 0");
}
var tests = [
function() { test1([1024 * 1024 * 32, 128, 4]); },
test2
];
function runTests() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
SimpleTest.waitForExplicitFinish();
runTests();
</script>
</pre>

View File

@ -4,30 +4,20 @@
*/
onmessage = function(event) {
if (event.data.data == 0) {
ab = new ArrayBuffer(event.data.size);
postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength,
status: ab.byteLength == event.data.size, last: false });
postMessage({ event: "W: postMessage with arrayBuffer", status: true,
ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]);
postMessage({ event: "W: The size is: 0 == " + ab.byteLength,
status: ab.byteLength == 0, last: false });
postMessage({ event: "last one!", status: true, last: true });
} else {
var worker = new Worker('sync_worker.js');
worker.onmessage = function(event) {
postMessage(event.data);
}
worker.onsyncmessage = function(event) {
var v = postSyncMessage(event.data, null, 500);
event.reply(v);
}
--event.data.data;
worker.postMessage(event.data);
if ("notEmpty" in event.data && "byteLength" in event.data.notEmpty) {
postMessage({ event: "W: NotEmpty object received: " + event.data.notEmpty.byteLength,
status: event.data.notEmpty.byteLength != 0, last: false });
}
var ab = new ArrayBuffer(event.data.size);
postMessage({ event: "W: The size is: " + event.data.size + " == " + ab.byteLength,
status: ab.byteLength == event.data.size, last: false });
postMessage({ event: "W: postMessage with arrayBuffer", status: true,
notEmpty: ab, ab: ab, bc: [ ab, ab, { dd: ab } ] }, [ab]);
postMessage({ event: "W: The size is: 0 == " + ab.byteLength,
status: ab.byteLength == 0, last: false });
postMessage({ event: "W: last one!", status: true, last: true });
}

View File

@ -72,6 +72,7 @@ class Selection;
namespace dom {
class Element;
class EventTarget;
} // namespace dom
} // namespace mozilla
@ -660,7 +661,7 @@ public:
nsIDOMNode *aEndNode,
int32_t aEndOffset);
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget() = 0;
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget() = 0;
// Fast non-refcounting editor root element accessor
mozilla::dom::Element *GetRoot();
@ -816,7 +817,7 @@ protected:
nsCOMPtr<mozilla::dom::Element> mRootElement; // cached root node
nsCOMPtr<nsIPrivateTextRangeList> mIMETextRangeList; // IME special selection ranges
nsCOMPtr<nsIDOMCharacterData> mIMETextNode; // current IME text node
nsCOMPtr<nsIDOMEventTarget> mEventTarget; // The form field as an event receiver
nsCOMPtr<mozilla::dom::EventTarget> mEventTarget; // The form field as an event receiver
nsCOMPtr<nsIDOMEventListener> mEventListener;
nsWeakPtr mSelConWeak; // weak reference to the nsISelectionController
nsWeakPtr mPlaceHolderTxn; // weak reference to placeholder for begin/end batch purposes

View File

@ -6,6 +6,7 @@
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Preferences.h" // for Preferences
#include "mozilla/dom/Element.h" // for Element
#include "mozilla/dom/EventTarget.h" // for EventTarget
#include "nsAString.h"
#include "nsCaret.h" // for nsCaret
#include "nsDebug.h" // for NS_ENSURE_TRUE, etc
@ -55,6 +56,7 @@
class nsPresContext;
using namespace mozilla;
using mozilla::dom::EventTarget;
nsEditorEventListener::nsEditorEventListener() :
mEditor(nullptr), mCommitText(false),
@ -103,11 +105,11 @@ nsEditorEventListener::InstallToEditor()
{
NS_PRECONDITION(mEditor, "The caller must set mEditor");
nsCOMPtr<nsIDOMEventTarget> piTarget = mEditor->GetDOMEventTarget();
nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
// register the event listeners with the listener manager
nsEventListenerManager* elmP = piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
NS_ENSURE_STATE(elmP);
#ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
@ -181,13 +183,12 @@ nsEditorEventListener::Disconnect()
void
nsEditorEventListener::UninstallFromEditor()
{
nsCOMPtr<nsIDOMEventTarget> piTarget = mEditor->GetDOMEventTarget();
nsCOMPtr<EventTarget> piTarget = mEditor->GetDOMEventTarget();
if (!piTarget) {
return;
}
nsEventListenerManager* elmP =
piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
if (!elmP) {
return;
}

View File

@ -70,6 +70,7 @@
#include "nsIParserService.h"
#include "mozilla/Selection.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "nsTextFragment.h"
@ -5218,14 +5219,14 @@ nsHTMLEditor::GetActiveEditingHost()
return content->GetEditingHost();
}
already_AddRefed<nsIDOMEventTarget>
already_AddRefed<mozilla::dom::EventTarget>
nsHTMLEditor::GetDOMEventTarget()
{
// Don't use getDocument here, because we have no way of knowing
// whether Init() was ever called. So we need to get the document
// ourselves, if it exists.
NS_PRECONDITION(mDocWeak, "This editor has not been initialized yet");
nsCOMPtr<nsIDOMEventTarget> target = do_QueryReferent(mDocWeak.get());
nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryReferent(mDocWeak);
return target.forget();
}

View File

@ -106,7 +106,7 @@ public:
virtual already_AddRefed<nsIContent> GetFocusedContent();
virtual already_AddRefed<nsIContent> GetFocusedContentForIME();
virtual bool IsActiveInDOMWindow();
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
virtual mozilla::dom::Element* GetEditorRoot() MOZ_OVERRIDE;
virtual already_AddRefed<nsIContent> FindSelectionRoot(nsINode *aNode);
virtual bool IsAcceptableInputEvent(nsIDOMEvent* aEvent);

View File

@ -1585,10 +1585,10 @@ nsPlaintextEditor::SelectEntireDocument(nsISelection *aSelection)
return NS_OK;
}
already_AddRefed<nsIDOMEventTarget>
already_AddRefed<mozilla::dom::EventTarget>
nsPlaintextEditor::GetDOMEventTarget()
{
nsCOMPtr<nsIDOMEventTarget> copy = mEventTarget;
nsCOMPtr<mozilla::dom::EventTarget> copy = mEventTarget;
return copy.forget();
}

View File

@ -120,7 +120,7 @@ public:
virtual nsresult HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent);
virtual already_AddRefed<nsIDOMEventTarget> GetDOMEventTarget();
virtual already_AddRefed<mozilla::dom::EventTarget> GetDOMEventTarget();
virtual nsresult BeginIMEComposition();
virtual nsresult UpdateIMEComposition(const nsAString &aCompositionString,

View File

@ -865,7 +865,7 @@ nsDocShellTreeOwner::AddChromeListeners()
nsCOMPtr<EventTarget> target;
GetDOMEventTarget(mWebBrowser, getter_AddRefs(target));
nsEventListenerManager* elmP = target->GetListenerManager(true);
nsEventListenerManager* elmP = target->GetOrCreateListenerManager();
if (elmP) {
elmP->AddEventListenerByType(this, NS_LITERAL_STRING("dragover"),
dom::TrustedEventsAtSystemGroupBubble());
@ -895,7 +895,7 @@ nsDocShellTreeOwner::RemoveChromeListeners()
if (!piTarget)
return NS_OK;
nsEventListenerManager* elmP = piTarget->GetListenerManager(true);
nsEventListenerManager* elmP = piTarget->GetOrCreateListenerManager();
if (elmP)
{
elmP->RemoveEventListenerByType(this, NS_LITERAL_STRING("dragover"),

View File

@ -998,6 +998,9 @@ public:
GrGLInterface* aGrGLInterface,
const IntSize &aSize,
SurfaceFormat aFormat);
static void
SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes);
#endif
#if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE)

View File

@ -512,13 +512,10 @@ DrawTargetCairo::DrawSurface(SourceSurface *aSurface,
cairo_set_antialias(mContext, GfxAntialiasToCairoAntialias(aOptions.mAntialiasMode));
double clipX1, clipY1, clipX2, clipY2;
cairo_clip_extents(mContext, &clipX1, &clipY1, &clipX2, &clipY2);
Rect clip(clipX1, clipY1, clipX2 - clipX1, clipY2 - clipY1); // Narrowing of doubles to floats
// If the destination rect covers the entire clipped area, then unbounded and bounded
// operations are identical, and we don't need to push a group.
bool needsGroup = !IsOperatorBoundByMask(aOptions.mCompositionOp) &&
!aDest.Contains(clip);
!aDest.Contains(GetUserSpaceClip());
cairo_translate(mContext, aDest.X(), aDest.Y());
@ -638,8 +635,6 @@ DrawTargetCairo::DrawPattern(const Pattern& aPattern,
(!IsOperatorBoundByMask(aOptions.mCompositionOp) && !aPathBoundsClip)) {
cairo_push_group_with_content(mContext, CAIRO_CONTENT_COLOR_ALPHA);
ClearSurfaceForUnboundedSource(aOptions.mCompositionOp);
// Don't want operators to be applied twice
cairo_set_operator(mContext, CAIRO_OPERATOR_OVER);
@ -656,7 +651,6 @@ DrawTargetCairo::DrawPattern(const Pattern& aPattern,
cairo_set_operator(mContext, GfxOpToCairoOp(aOptions.mCompositionOp));
cairo_paint_with_alpha(mContext, aOptions.mAlpha);
} else {
ClearSurfaceForUnboundedSource(aOptions.mCompositionOp);
cairo_set_operator(mContext, GfxOpToCairoOp(aOptions.mCompositionOp));
if (aDrawType == DRAW_STROKE) {
@ -682,13 +676,7 @@ DrawTargetCairo::FillRect(const Rect &aRect,
bool pathBoundsClip = false;
double cexts[4];
cairo_clip_extents(mContext, &cexts[0], &cexts[1], &cexts[2], &cexts[3]);
Rect clipRect(cexts[0], cexts[1], cexts[2] - cexts[0], cexts[3] - cexts[1]);
double pexts[4];
cairo_path_extents(mContext, &pexts[0], &pexts[1], &pexts[2], &pexts[3]);
Rect pathRect(pexts[0], pexts[1], pexts[2] - pexts[0], pexts[3] - pexts[1]);
if (pathRect.Contains(clipRect)) {
if (aRect.Contains(GetUserSpaceClip())) {
pathBoundsClip = true;
}
@ -1192,6 +1180,14 @@ DrawTargetCairo::SetTransform(const Matrix& aTransform)
cairo_set_matrix(mContext, &mat);
}
Rect
DrawTargetCairo::GetUserSpaceClip()
{
double clipX1, clipY1, clipX2, clipY2;
cairo_clip_extents(mContext, &clipX1, &clipY1, &clipX2, &clipY2);
return Rect(clipX1, clipY1, clipX2 - clipX1, clipY2 - clipY1); // Narrowing of doubles to floats
}
cairo_t*
BorrowedCairoContext::BorrowCairoContextFromDrawTarget(DrawTarget* aDT)
{

View File

@ -172,6 +172,8 @@ private: // methods
const IntRect& aSource,
const IntPoint& aDest);
Rect GetUserSpaceClip();
// Call before you make any changes to the backing surface with which this
// context is associated. Pass the path you're going to be using if you have
// one.

View File

@ -76,6 +76,8 @@ public:
};
#ifdef USE_SKIA_GPU
int DrawTargetSkia::sTextureCacheCount = 256;
int DrawTargetSkia::sTextureCacheSizeInBytes = 96*1024*1024;
static std::vector<DrawTargetSkia*>&
GLDrawTargets()
@ -84,35 +86,27 @@ GLDrawTargets()
return targets;
}
#define SKIA_MAX_CACHE_ITEMS 256
// 64MB was chosen because it seems we can pass all of our tests
// on the current hardware (Tegra2) without running out of memory
#define SKIA_TOTAL_CACHE_SIZE 64*1024*1024
static void
SetCacheLimits()
void
DrawTargetSkia::RebalanceCacheLimits()
{
// Divide the global cache limits equally between all currently active GL-backed
// Skia DrawTargets.
std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
uint32_t size = targets.size();
if (size == 0)
uint32_t targetCount = targets.size();
if (targetCount == 0)
return;
int individualCacheSize = SKIA_TOTAL_CACHE_SIZE / size;
for (uint32_t i = 0; i < size; i++) {
targets[i]->SetCacheLimits(SKIA_MAX_CACHE_ITEMS, individualCacheSize);
int individualCacheSize = sTextureCacheSizeInBytes / targetCount;
for (uint32_t i = 0; i < targetCount; i++) {
targets[i]->SetCacheLimits(sTextureCacheCount, individualCacheSize);
}
}
#undef SKIA_MAX_CACHE_ITEMS
#undef SKIA_TOTAL_CACHE_SIZE
static void
AddGLDrawTarget(DrawTargetSkia* target)
{
GLDrawTargets().push_back(target);
SetCacheLimits();
DrawTargetSkia::RebalanceCacheLimits();
}
static void
@ -122,10 +116,18 @@ RemoveGLDrawTarget(DrawTargetSkia* target)
std::vector<DrawTargetSkia*>::iterator it = std::find(targets.begin(), targets.end(), target);
if (it != targets.end()) {
targets.erase(it);
SetCacheLimits();
DrawTargetSkia::RebalanceCacheLimits();
}
}
void
DrawTargetSkia::SetGlobalCacheLimits(int aCount, int aSizeInBytes)
{
sTextureCacheCount = aCount;
sTextureCacheSizeInBytes = aSizeInBytes;
DrawTargetSkia::RebalanceCacheLimits();
}
#endif
DrawTargetSkia::DrawTargetSkia()
@ -732,7 +734,6 @@ DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes)
MOZ_ASSERT(mGrContext, "No GrContext!");
mGrContext->setTextureCacheLimits(aCount, aSizeInBytes);
}
#endif
void

View File

@ -105,7 +105,9 @@ public:
const IntSize &aSize,
SurfaceFormat aFormat) MOZ_OVERRIDE;
void SetCacheLimits(int number, int sizeInBytes);
void SetCacheLimits(int aCount, int aSizeInBytes);
static void SetGlobalCacheLimits(int aCount, int aSizeInBytes);
static void RebalanceCacheLimits();
#endif
operator std::string() const {
@ -130,6 +132,9 @@ private:
RefPtr<GenericRefCountedBase> mGLContext;
SkRefPtr<GrGLInterface> mGrGLInterface;
SkRefPtr<GrContext> mGrContext;
static int sTextureCacheCount;
static int sTextureCacheSizeInBytes;
#endif
IntSize mSize;

View File

@ -513,6 +513,12 @@ Factory::CreateDrawTargetSkiaWithGLContextAndGrGLInterface(GenericRefCountedBase
RefPtr<DrawTarget> newTarget = newDrawTargetSkia;
return newTarget;
}
void
Factory::SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes)
{
DrawTargetSkia::SetGlobalCacheLimits(aCount, aSizeInBytes);
}
#endif // USE_SKIA_GPU
#ifdef USE_SKIA_FREETYPE

View File

@ -62,6 +62,7 @@
#endif
#ifdef USE_SKIA
#include "mozilla/Hal.h"
#include "skia/SkGraphics.h"
#endif
@ -277,6 +278,10 @@ gfxPlatform::gfxPlatform()
uint32_t canvasMask = (1 << BACKEND_CAIRO) | (1 << BACKEND_SKIA);
uint32_t contentMask = 1 << BACKEND_CAIRO;
InitBackendPrefs(canvasMask, contentMask);
#ifdef USE_SKIA
InitializeSkiaCaches();
#endif
}
gfxPlatform*
@ -810,6 +815,39 @@ gfxPlatform::UseAcceleratedSkiaCanvas()
mPreferredCanvasBackend == BACKEND_SKIA;
}
void
gfxPlatform::InitializeSkiaCaches()
{
#ifdef USE_SKIA_GPU
if (UseAcceleratedSkiaCanvas()) {
bool usingDynamicCache = Preferences::GetBool("gfx.canvas.skiagl.dynamic-cache", false);
int cacheItemLimit = Preferences::GetInt("gfx.canvas.skiagl.cache-items", 256);
int cacheSizeLimit = Preferences::GetInt("gfx.canvas.skiagl.cache-size", 96);
// Prefs are in megabytes, but we want the sizes in bytes
cacheSizeLimit *= 1024*1024;
if (usingDynamicCache) {
uint32_t totalMemory = mozilla::hal::GetTotalSystemMemory();
if (totalMemory <= 256*1024*1024) {
// We need a very minimal cache on 256 meg devices
cacheSizeLimit = 2*1024*1024;
} else if (totalMemory > 0) {
cacheSizeLimit = totalMemory / 16;
}
}
#ifdef DEBUG
printf_stderr("Determined SkiaGL cache limits: Size %i, Items: %i\n", cacheSizeLimit, cacheItemLimit);
#endif
Factory::SetGlobalSkiaCacheLimits(cacheItemLimit, cacheSizeLimit);
}
#endif
}
already_AddRefed<gfxASurface>
gfxPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
{

View File

@ -278,6 +278,8 @@ public:
virtual bool UseAcceleratedSkiaCanvas();
virtual void InitializeSkiaCaches();
void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) {
aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend));
aObj.DefineProperty("AzureSkiaAccelerated", UseAcceleratedSkiaCanvas());

View File

@ -1195,5 +1195,12 @@ StopDiskSpaceWatcher()
PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
}
uint32_t
GetTotalSystemMemory()
{
return hal_impl::GetTotalSystemMemory();
}
} // namespace hal
} // namespace mozilla

View File

@ -597,6 +597,13 @@ void StartDiskSpaceWatcher();
*/
void StopDiskSpaceWatcher();
/**
* Get total system memory of device being run on in bytes.
*
* Returns 0 if we are unable to determine this information from /proc/meminfo.
*/
uint32_t GetTotalSystemMemory();
} // namespace MOZ_HAL_NAMESPACE
} // namespace mozilla

View File

@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Hal.h"
namespace mozilla {
namespace hal_impl {
uint32_t
GetTotalSystemMemory()
{
return 0;
}
} // namespace hal_impl
} // namespace mozilla

39
hal/linux/LinuxMemory.cpp Normal file
View File

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include "Hal.h"
namespace mozilla {
namespace hal_impl {
uint32_t
GetTotalSystemMemory()
{
static uint32_t sTotalMemory;
static bool sTotalMemoryObtained = false;
if (!sTotalMemoryObtained) {
sTotalMemoryObtained = true;
FILE* fd = fopen("/proc/meminfo", "r");
if (!fd) {
return 0;
}
int rv = fscanf(fd, "MemTotal: %i kB", &sTotalMemory);
if (fclose(fd) || rv != 1) {
return 0;
}
}
return sTotalMemory * 1024;
}
} // namespace hal_impl
} // namespace mozilla

View File

@ -50,6 +50,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
'android/AndroidSensor.cpp',
'fallback/FallbackPower.cpp',
'fallback/FallbackAlarm.cpp',
'linux/LinuxMemory.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
CPP_SOURCES += [
@ -60,6 +61,7 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
'gonk/GonkSwitch.cpp',
'gonk/UeventPoller.cpp',
'linux/LinuxPower.cpp',
'linux/LinuxMemory.cpp',
]
elif CONFIG['OS_TARGET'] == 'Linux':
CPP_SOURCES += [
@ -68,6 +70,7 @@ elif CONFIG['OS_TARGET'] == 'Linux':
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
'linux/LinuxPower.cpp',
'linux/LinuxMemory.cpp',
]
if CONFIG['MOZ_ENABLE_DBUS']:
CPP_SOURCES += [
@ -85,6 +88,7 @@ elif CONFIG['OS_TARGET'] == 'WINNT':
'fallback/FallbackVibration.cpp',
'windows/WindowsBattery.cpp',
'windows/WindowsSensor.cpp',
'fallback/FallbackMemory.cpp',
]
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
CPP_SOURCES += [
@ -93,6 +97,7 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
'fallback/FallbackPower.cpp',
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackVibration.cpp',
'fallback/FallbackMemory.cpp',
]
elif CONFIG['OS_TARGET'] in ('OpenBSD', 'NetBSD', 'FreeBSD', 'DragonFly'):
CPP_SOURCES += [
@ -101,6 +106,7 @@ elif CONFIG['OS_TARGET'] in ('OpenBSD', 'NetBSD', 'FreeBSD', 'DragonFly'):
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
'fallback/FallbackMemory.cpp',
]
if CONFIG['MOZ_ENABLE_DBUS']:
CPP_SOURCES += [
@ -118,6 +124,7 @@ else:
'fallback/FallbackScreenConfiguration.cpp',
'fallback/FallbackSensor.cpp',
'fallback/FallbackVibration.cpp',
'fallback/FallbackMemory.cpp',
]
# Fallbacks for backends implemented on Gonk only.

View File

@ -9,6 +9,7 @@
#include "ImageFactory.h"
#include "RasterImage.h"
#include "SurfaceCache.h"
#include "imgLoader.h"
#include "imgRequest.h"
@ -84,6 +85,7 @@ imglib_Initialize()
mozilla::image::DiscardTracker::Initialize();
mozilla::image::ImageFactory::Initialize();
mozilla::image::RasterImage::Initialize();
mozilla::image::SurfaceCache::Initialize();
imgLoader::GlobalInit();
return NS_OK;
}
@ -92,6 +94,7 @@ static void
imglib_Shutdown()
{
imgLoader::Shutdown();
mozilla::image::SurfaceCache::Shutdown();
mozilla::image::DiscardTracker::Shutdown();
}

559
image/src/SurfaceCache.cpp Normal file
View File

@ -0,0 +1,559 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* SurfaceCache is a service for caching temporary surfaces in imagelib.
*/
#include "SurfaceCache.h"
#include <algorithm>
#include "mozilla/Attributes.h" // for MOZ_THIS_IN_INITIALIZER_LIST
#include "mozilla/DebugOnly.h"
#include "mozilla/Preferences.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Util.h" // for Maybe
#include "gfxASurface.h"
#include "gfxPattern.h" // Workaround for flaw in bug 921753 part 2.
#include "gfxDrawable.h"
#include "gfxPlatform.h"
#include "nsAutoPtr.h"
#include "nsExpirationTracker.h"
#include "nsHashKeys.h"
#include "nsRefPtrHashtable.h"
#include "nsSize.h"
#include "nsTArray.h"
#include "prsystem.h"
#include "SVGImageContext.h"
using std::max;
using std::min;
using mozilla::gfx::DrawTarget;
/**
* Hashtable key class to use with objects for which Hash() and operator==()
* are defined.
* XXX(seth): This will get moved to xpcom/glue/nsHashKeys.h in a followup bug.
*/
template <typename T>
class nsGenericHashKey : public PLDHashEntryHdr
{
public:
typedef const T& KeyType;
typedef const T* KeyTypePointer;
nsGenericHashKey(KeyTypePointer aKey) : mKey(*aKey) { }
nsGenericHashKey(const nsGenericHashKey<T>& aOther) : mKey(aOther.mKey) { }
KeyType GetKey() const { return mKey; }
bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mKey; }
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
static PLDHashNumber HashKey(KeyTypePointer aKey) { return aKey->Hash(); }
enum { ALLOW_MEMMOVE = true };
private:
T mKey;
};
namespace mozilla {
namespace image {
class CachedSurface;
class SurfaceCacheImpl;
///////////////////////////////////////////////////////////////////////////////
// Static Data
///////////////////////////////////////////////////////////////////////////////
// The single surface cache instance.
static SurfaceCacheImpl* sInstance = nullptr;
///////////////////////////////////////////////////////////////////////////////
// SurfaceCache Implementation
///////////////////////////////////////////////////////////////////////////////
/*
* Cost models the cost of storing a surface in the cache. Right now, this is
* simply an estimate of the size of the surface in bytes, but in the future it
* may be worth taking into account the cost of rematerializing the surface as
* well.
*/
typedef size_t Cost;
static Cost ComputeCost(const nsIntSize aSize)
{
return aSize.width * aSize.height * 4; // width * height * 4 bytes (32bpp)
}
/*
* Since we want to be able to make eviction decisions based on cost, we need to
* be able to look up the CachedSurface which has a certain cost as well as the
* cost associated with a certain CachedSurface. To make this possible, in data
* structures we actually store a CostEntry, which contains a weak pointer to
* its associated surface.
*
* To make usage of the weak pointer safe, SurfaceCacheImpl always calls
* StartTracking after a surface is stored in the cache and StopTracking before
* it is removed.
*/
class CostEntry
{
public:
CostEntry(CachedSurface* aSurface, Cost aCost)
: mSurface(aSurface)
, mCost(aCost)
{
MOZ_ASSERT(aSurface, "Must have a surface");
}
CachedSurface* GetSurface() const { return mSurface; }
Cost GetCost() const { return mCost; }
bool operator==(const CostEntry& aOther) const
{
return mSurface == aOther.mSurface &&
mCost == aOther.mCost;
}
bool operator<(const CostEntry& aOther) const
{
return mCost < aOther.mCost ||
(mCost == aOther.mCost && mSurface < aOther.mSurface);
}
private:
CachedSurface* mSurface;
Cost mCost;
};
/*
* A CachedSurface associates a surface with a key that uniquely identifies that
* surface.
*/
class CachedSurface : public RefCounted<CachedSurface>
{
public:
CachedSurface(DrawTarget* aTarget,
const nsIntSize aTargetSize,
const Cost aCost,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
: mTarget(aTarget)
, mTargetSize(aTargetSize)
, mCost(aCost)
, mImageKey(aImageKey)
, mSurfaceKey(aSurfaceKey)
{
MOZ_ASSERT(mTarget, "Must have a valid DrawTarget");
MOZ_ASSERT(mImageKey, "Must have a valid image key");
}
already_AddRefed<gfxDrawable> Drawable() const
{
nsRefPtr<gfxASurface> surface =
gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mTarget);
nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(surface, mTargetSize);
return drawable.forget();
}
ImageKey GetImageKey() const { return mImageKey; }
SurfaceKey GetSurfaceKey() const { return mSurfaceKey; }
CostEntry GetCostEntry() { return image::CostEntry(this, mCost); }
nsExpirationState* GetExpirationState() { return &mExpirationState; }
private:
nsExpirationState mExpirationState;
nsRefPtr<DrawTarget> mTarget;
const nsIntSize mTargetSize;
const Cost mCost;
const ImageKey mImageKey;
const SurfaceKey mSurfaceKey;
};
/*
* An ImageSurfaceCache is a per-image surface cache. For correctness we must be
* able to remove all surfaces associated with an image when the image is
* destroyed or invalidated. Since this will happen frequently, it makes sense
* to make it cheap by storing the surfaces for each image separately.
*/
class ImageSurfaceCache : public RefCounted<ImageSurfaceCache>
{
public:
typedef nsRefPtrHashtable<nsGenericHashKey<SurfaceKey>, CachedSurface> SurfaceTable;
bool IsEmpty() const { return mSurfaces.Count() == 0; }
void Insert(const SurfaceKey& aKey, CachedSurface* aSurface)
{
MOZ_ASSERT(aSurface, "Should have a surface");
mSurfaces.Put(aKey, aSurface);
}
void Remove(CachedSurface* aSurface)
{
MOZ_ASSERT(aSurface, "Should have a surface");
MOZ_ASSERT(mSurfaces.GetWeak(aSurface->GetSurfaceKey()),
"Should not be removing a surface we don't have");
mSurfaces.Remove(aSurface->GetSurfaceKey());
}
already_AddRefed<CachedSurface> Lookup(const SurfaceKey& aSurfaceKey)
{
nsRefPtr<CachedSurface> surface;
mSurfaces.Get(aSurfaceKey, getter_AddRefs(surface));
return surface.forget();
}
void ForEach(SurfaceTable::EnumReadFunction aFunction, void* aData)
{
mSurfaces.EnumerateRead(aFunction, aData);
}
private:
SurfaceTable mSurfaces;
};
/*
* SurfaceCacheImpl is responsible for determining which surfaces will be cached
* and managing the surface cache data structures. Rather than interact with
* SurfaceCacheImpl directly, client code interacts with SurfaceCache, which
* maintains high-level invariants and encapsulates the details of the surface
* cache's implementation.
*/
class SurfaceCacheImpl
{
public:
SurfaceCacheImpl(uint32_t aSurfaceCacheExpirationTimeMS,
uint32_t aSurfaceCacheSize)
: mExpirationTracker(MOZ_THIS_IN_INITIALIZER_LIST(),
aSurfaceCacheExpirationTimeMS)
, mReporter(new SurfaceCacheReporter)
, mMemoryPressureObserver(new MemoryPressureObserver)
, mMaxCost(aSurfaceCacheSize)
, mAvailableCost(aSurfaceCacheSize)
{
NS_RegisterMemoryReporter(mReporter);
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
}
~SurfaceCacheImpl()
{
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os)
os->RemoveObserver(mMemoryPressureObserver, "memory-pressure");
NS_UnregisterMemoryReporter(mReporter);
}
void Insert(DrawTarget* aTarget,
nsIntSize aTargetSize,
const Cost aCost,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
MOZ_ASSERT(!Lookup(aImageKey, aSurfaceKey).get(),
"Inserting a duplicate drawable into the SurfaceCache");
// If this is bigger than the maximum cache size, refuse to cache it.
if (!CanHold(aCost))
return;
nsRefPtr<CachedSurface> surface =
new CachedSurface(aTarget, aTargetSize, aCost, aImageKey, aSurfaceKey);
// Remove elements in order of cost until we can fit this in the cache.
while (aCost > mAvailableCost) {
MOZ_ASSERT(!mCosts.IsEmpty(), "Removed everything and it still won't fit");
Remove(mCosts.LastElement().GetSurface());
}
// Locate the appropriate per-image cache. If there's not an existing cache
// for this image, create it.
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache) {
cache = new ImageSurfaceCache;
mImageCaches.Put(aImageKey, cache);
}
// Insert.
MOZ_ASSERT(aCost <= mAvailableCost, "Inserting despite too large a cost");
cache->Insert(aSurfaceKey, surface);
StartTracking(surface);
}
void Remove(CachedSurface* aSurface)
{
MOZ_ASSERT(aSurface, "Should have a surface");
const ImageKey imageKey = aSurface->GetImageKey();
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(imageKey);
MOZ_ASSERT(cache, "Shouldn't try to remove a surface with no image cache");
StopTracking(aSurface);
cache->Remove(aSurface);
// Remove the per-image cache if it's unneeded now.
if (cache->IsEmpty()) {
mImageCaches.Remove(imageKey);
}
}
void StartTracking(CachedSurface* aSurface)
{
CostEntry costEntry = aSurface->GetCostEntry();
MOZ_ASSERT(costEntry.GetCost() <= mAvailableCost,
"Cost too large and the caller didn't catch it");
mAvailableCost -= costEntry.GetCost();
mCosts.InsertElementSorted(costEntry);
mExpirationTracker.AddObject(aSurface);
}
void StopTracking(CachedSurface* aSurface)
{
MOZ_ASSERT(aSurface, "Should have a surface");
CostEntry costEntry = aSurface->GetCostEntry();
mExpirationTracker.RemoveObject(aSurface);
DebugOnly<bool> foundInCosts = mCosts.RemoveElementSorted(costEntry);
mAvailableCost += costEntry.GetCost();
MOZ_ASSERT(foundInCosts, "Lost track of costs for this surface");
MOZ_ASSERT(mAvailableCost <= mMaxCost, "More available cost than we started with");
}
already_AddRefed<gfxDrawable> Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache)
return nullptr; // No cached surfaces for this image.
nsRefPtr<CachedSurface> surface = cache->Lookup(aSurfaceKey);
if (!surface)
return nullptr; // Lookup in the per-image cache missed.
mExpirationTracker.MarkUsed(surface);
return surface->Drawable();
}
bool CanHold(const Cost aCost) const
{
return aCost <= mMaxCost;
}
void Discard(const ImageKey aImageKey)
{
nsRefPtr<ImageSurfaceCache> cache = GetImageCache(aImageKey);
if (!cache)
return; // No cached surfaces for this image, so nothing to do.
// Discard all of the cached surfaces for this image.
// XXX(seth): This is O(n^2) since for each item in the cache we are
// removing an element from the costs array. Since n is expected to be
// small, performance should be good, but if usage patterns change we should
// change the data structure used for mCosts.
cache->ForEach(DoStopTracking, this);
// The per-image cache isn't needed anymore, so remove it as well.
mImageCaches.Remove(aImageKey);
}
void DiscardAll()
{
// Remove in order of cost because mCosts is an array and the other data
// structures are all hash tables.
while (!mCosts.IsEmpty()) {
Remove(mCosts.LastElement().GetSurface());
}
}
static PLDHashOperator DoStopTracking(const SurfaceKey&,
CachedSurface* aSurface,
void* aCache)
{
static_cast<SurfaceCacheImpl*>(aCache)->StopTracking(aSurface);
return PL_DHASH_NEXT;
}
int64_t SizeOfSurfacesEstimate() const
{
return int64_t(mMaxCost - mAvailableCost);
}
private:
already_AddRefed<ImageSurfaceCache> GetImageCache(const ImageKey aImageKey)
{
nsRefPtr<ImageSurfaceCache> imageCache;
mImageCaches.Get(aImageKey, getter_AddRefs(imageCache));
return imageCache.forget();
}
struct SurfaceTracker : public nsExpirationTracker<CachedSurface, 2>
{
SurfaceTracker(SurfaceCacheImpl* aCache, uint32_t aSurfaceCacheExpirationTimeMS)
: nsExpirationTracker<CachedSurface, 2>(aSurfaceCacheExpirationTimeMS)
, mCache(aCache)
{ }
protected:
virtual void NotifyExpired(CachedSurface* aSurface) MOZ_OVERRIDE
{
if (mCache) {
mCache->Remove(aSurface);
}
}
private:
SurfaceCacheImpl* const mCache; // Weak pointer to owner.
};
// XXX(seth): This is currently only an estimate and, since we don't know which
// surfaces are in GPU memory and which aren't, it's reported as KIND_OTHER and
// will also show up in heap-unclassified. Bug 923302 will make this nicer.
struct SurfaceCacheReporter : public MemoryUniReporter
{
SurfaceCacheReporter()
: MemoryUniReporter("imagelib-surface-cache",
KIND_OTHER,
UNITS_BYTES,
"Memory used by the imagelib temporary surface cache.")
{ }
protected:
int64_t Amount() MOZ_OVERRIDE
{
return sInstance ? sInstance->SizeOfSurfacesEstimate() : 0;
}
};
struct MemoryPressureObserver : public nsIObserver
{
NS_DECL_ISUPPORTS
virtual ~MemoryPressureObserver() { }
NS_IMETHOD Observe(nsISupports*, const char* aTopic, const PRUnichar*)
{
if (sInstance && strcmp(aTopic, "memory-pressure") == 0) {
sInstance->DiscardAll();
}
return NS_OK;
}
};
nsTArray<CostEntry> mCosts;
nsRefPtrHashtable<nsPtrHashKey<Image>, ImageSurfaceCache> mImageCaches;
SurfaceTracker mExpirationTracker;
nsRefPtr<SurfaceCacheReporter> mReporter;
nsRefPtr<MemoryPressureObserver> mMemoryPressureObserver;
const Cost mMaxCost;
Cost mAvailableCost;
};
NS_IMPL_ISUPPORTS1(SurfaceCacheImpl::MemoryPressureObserver, nsIObserver)
///////////////////////////////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////////////////////////////////
/* static */ void
SurfaceCache::Initialize()
{
// Initialize preferences.
MOZ_ASSERT(!sInstance, "Shouldn't initialize more than once");
// Length of time before an unused surface is removed from the cache, in milliseconds.
// The default value gives an expiration time of 1 minute.
uint32_t surfaceCacheExpirationTimeMS =
Preferences::GetUint("image.mem.surfacecache.min_expiration_ms", 60 * 1000);
// Maximum size of the surface cache, in kilobytes.
// The default is 100MB. (But we may override this for e.g. B2G.)
uint32_t surfaceCacheMaxSizeKB =
Preferences::GetUint("image.mem.surfacecache.max_size_kb", 100 * 1024);
// A knob determining the actual size of the surface cache. Currently the
// cache is (size of main memory) / (surface cache size factor) KB
// or (surface cache max size) KB, whichever is smaller. The formula
// may change in the future, though.
// The default value is 64, which yields a 64MB cache on a 4GB machine.
// The smallest machines we are likely to run this code on have 256MB
// of memory, which would yield a 4MB cache on the default setting.
uint32_t surfaceCacheSizeFactor =
Preferences::GetUint("image.mem.surfacecache.size_factor", 64);
// Clamp to avoid division by zero below.
surfaceCacheSizeFactor = max(surfaceCacheSizeFactor, 1u);
// Compute the size of the surface cache.
uint32_t proposedSize = PR_GetPhysicalMemorySize() / surfaceCacheSizeFactor;
uint32_t surfaceCacheSizeBytes = min(proposedSize, surfaceCacheMaxSizeKB * 1024);
// Create the surface cache singleton with the requested expiration time and
// size. Note that the size is a limit that the cache may not grow beyond, but
// we do not actually allocate any storage for surfaces at this time.
sInstance = new SurfaceCacheImpl(surfaceCacheExpirationTimeMS,
surfaceCacheSizeBytes);
}
/* static */ void
SurfaceCache::Shutdown()
{
MOZ_ASSERT(sInstance, "No singleton - was Shutdown() called twice?");
delete sInstance;
sInstance = nullptr;
}
/* static */ already_AddRefed<gfxDrawable>
SurfaceCache::Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
MOZ_ASSERT(sInstance, "Should be initialized");
MOZ_ASSERT(NS_IsMainThread());
return sInstance->Lookup(aImageKey, aSurfaceKey);
}
/* static */ void
SurfaceCache::Insert(DrawTarget* aTarget,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey)
{
MOZ_ASSERT(sInstance, "Should be initialized");
MOZ_ASSERT(NS_IsMainThread());
Cost cost = ComputeCost(aSurfaceKey.Size());
return sInstance->Insert(aTarget, aSurfaceKey.Size(), cost, aImageKey, aSurfaceKey);
}
/* static */ bool
SurfaceCache::CanHold(const nsIntSize& aSize)
{
MOZ_ASSERT(sInstance, "Should be initialized");
MOZ_ASSERT(NS_IsMainThread());
Cost cost = ComputeCost(aSize);
return sInstance->CanHold(cost);
}
/* static */ void
SurfaceCache::Discard(Image* aImageKey)
{
MOZ_ASSERT(sInstance, "Should be initialized");
MOZ_ASSERT(NS_IsMainThread());
return sInstance->Discard(aImageKey);
}
} // namespace image
} // namespace mozilla

172
image/src/SurfaceCache.h Normal file
View File

@ -0,0 +1,172 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* SurfaceCache is a service for caching temporary surfaces in imagelib.
*/
#ifndef MOZILLA_IMAGELIB_SURFACECACHE_H_
#define MOZILLA_IMAGELIB_SURFACECACHE_H_
#include "mozilla/HashFunctions.h" // for HashGeneric and AddToHash
#include "gfxPoint.h" // for gfxSize
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsSize.h" // for nsIntSize
#include "SVGImageContext.h" // for SVGImageContext
class gfxDrawable;
namespace mozilla {
namespace gfx {
class DrawTarget;
} // namespace gfx
namespace image {
class Image;
/*
* ImageKey contains the information we need to look up all cached surfaces for
* a particular image.
*/
typedef Image* ImageKey;
/*
* SurfaceKey contains the information we need to look up a specific cached
* surface. Together with an ImageKey, this uniquely identifies the surface.
*
* XXX(seth): Right now this is specialized to the needs of VectorImage. We'll
* generalize it in bug 919071.
*/
class SurfaceKey
{
public:
SurfaceKey(const nsIntSize aSize,
const gfxSize aScale,
const SVGImageContext* aSVGContext,
const float aAnimationTime,
const uint32_t aFlags)
: mSize(aSize)
, mScale(aScale)
, mSVGContextIsValid(aSVGContext != nullptr)
, mAnimationTime(aAnimationTime)
, mFlags(aFlags)
{
// XXX(seth): Would love to use Maybe<T> here, but see bug 913586.
if (mSVGContextIsValid)
mSVGContext = *aSVGContext;
}
bool operator==(const SurfaceKey& aOther) const
{
bool matchesSVGContext = aOther.mSVGContextIsValid == mSVGContextIsValid &&
(!mSVGContextIsValid || aOther.mSVGContext == mSVGContext);
return aOther.mSize == mSize &&
aOther.mScale == mScale &&
matchesSVGContext &&
aOther.mAnimationTime == mAnimationTime &&
aOther.mFlags == mFlags;
}
uint32_t Hash() const
{
uint32_t hash = HashGeneric(mSize.width, mSize.height);
hash = AddToHash(hash, mScale.width, mScale.height);
hash = AddToHash(hash, mSVGContextIsValid, mSVGContext.Hash());
hash = AddToHash(hash, mAnimationTime, mFlags);
return hash;
}
nsIntSize Size() const { return mSize; }
private:
nsIntSize mSize;
gfxSize mScale;
SVGImageContext mSVGContext;
bool mSVGContextIsValid;
float mAnimationTime;
uint32_t mFlags;
};
/**
* SurfaceCache is an imagelib-global service that allows caching of temporary
* surfaces. Surfaces expire from the cache automatically if they go too long
* without being accessed.
*
* SurfaceCache is not thread-safe; it should only be accessed from the main
* thread.
*/
struct SurfaceCache
{
/*
* Initialize static data. Called during imagelib module initialization.
*/
static void Initialize();
/*
* Release static data. Called during imagelib module shutdown.
*/
static void Shutdown();
/*
* Look up a surface in the cache.
*
* @param aImageKey Key data identifying which image the surface belongs to.
* @param aSurfaceKey Key data which uniquely identifies the requested surface.
*
* @return the requested surface, or nullptr if not found.
*/
static already_AddRefed<gfxDrawable> Lookup(const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey);
/*
* Insert a surface into the cache. It is an error to call this function
* without first calling Lookup to verify that the surface is not already in
* the cache.
*
* @param aTarget The new surface (in the form of a DrawTarget) to insert
* into the cache.
* @param aImageKey Key data identifying which image the surface belongs to.
* @param aSurfaceKey Key data which uniquely identifies the requested surface.
*/
static void Insert(mozilla::gfx::DrawTarget* aTarget,
const ImageKey aImageKey,
const SurfaceKey& aSurfaceKey);
/*
* Checks if a surface of a given size could possibly be stored in the cache.
* If CanHold() returns false, Insert() will always fail to insert the
* surface, but the inverse is not true: Insert() may take more information
* into account than just image size when deciding whether to cache the
* surface, so Insert() may still fail even if CanHold() returns true.
*
* Use CanHold() to avoid the need to create a temporary surface when we know
* for sure the cache can't hold it.
*
* @param aSize The dimensions of a surface in pixels.
*
* @return false if the surface cache can't hold a surface of that size.
*/
static bool CanHold(const nsIntSize& aSize);
/*
* Evicts any cached surfaces associated with the given image from the cache.
* This MUST be called, at a minimum, when the image is destroyed. If
* another image were allocated at the same address it could result in
* subtle, difficult-to-reproduce bugs.
*
* @param aImageKey The image which should be removed from the cache.
*/
static void Discard(const ImageKey aImageKey);
private:
virtual ~SurfaceCache() = 0; // Forbid instantiation.
};
} // namespace image
} // namespace mozilla
#endif // MOZILLA_IMAGELIB_SURFACECACHE_H_

View File

@ -7,6 +7,7 @@
#include "gfxContext.h"
#include "gfxDrawable.h"
#include "gfxPlatform.h"
#include "gfxUtils.h"
#include "imgDecoderObserver.h"
#include "mozilla/AutoRestore.h"
@ -23,6 +24,7 @@
#include "Orientation.h"
#include "SVGDocumentWrapper.h"
#include "nsIDOMEventListener.h"
#include "SurfaceCache.h"
namespace mozilla {
@ -316,6 +318,7 @@ VectorImage::VectorImage(imgStatusTracker* aStatusTracker,
VectorImage::~VectorImage()
{
CancelAllListeners();
SurfaceCache::Discard(this);
}
//------------------------------------------------------------------------------
@ -487,6 +490,9 @@ VectorImage::RequestRefresh(const mozilla::TimeStamp& aTime)
// under WillRefresh() (which would be called by our own refresh driver) so
// that we only send these notifications if we actually have a document
// that is observing us.
// XXX(seth): We may need to duplicate this code so that non-animated images
// get handled correctly. See bug 922899.
SurfaceCache::Discard(this);
mStatusTracker->FrameChanged(&nsIntRect::GetMaxSizedIntRect());
mStatusTracker->OnStopFrame();
}
@ -676,6 +682,65 @@ VectorImage::GetImageContainer(LayerManager* aManager,
return NS_OK;
}
struct SVGDrawingParameters
{
SVGDrawingParameters(gfxContext* aContext,
GraphicsFilter aFilter,
const gfxMatrix& aUserSpaceToImageSpace,
const gfxRect& aFill,
const nsIntRect& aSubimage,
const nsIntSize& aViewportSize,
const SVGImageContext* aSVGContext,
float aAnimationTime,
uint32_t aFlags)
: context(aContext)
, filter(aFilter)
, fill(aFill)
, viewportSize(aViewportSize)
, animationTime(aAnimationTime)
, svgContext(aSVGContext)
, flags(aFlags)
{
// gfxUtils::DrawPixelSnapped may rasterize this image to a temporary surface
// if we hit the tiling path. Unfortunately, the temporary surface isn't
// created at the size at which we'll ultimately draw, causing fuzzy output.
// To fix this we pre-apply the transform's scaling to the drawing parameters
// and remove the scaling from the transform, so the fact that temporary
// surfaces won't take the scaling into account doesn't matter. (Bug 600207.)
scale = aUserSpaceToImageSpace.ScaleFactors(true);
gfxPoint translation(aUserSpaceToImageSpace.GetTranslation());
// Remove the scaling from the transform.
gfxMatrix unscale;
unscale.Translate(gfxPoint(translation.x / scale.width,
translation.y / scale.height));
unscale.Scale(1.0 / scale.width, 1.0 / scale.height);
unscale.Translate(-translation);
userSpaceToImageSpace = aUserSpaceToImageSpace * unscale;
// Rescale drawing parameters.
gfxIntSize drawableSize(aViewportSize.width / scale.width,
aViewportSize.height / scale.height);
sourceRect = userSpaceToImageSpace.Transform(aFill);
imageRect = nsIntRect(0, 0, drawableSize.width, drawableSize.height);
subimage = gfxRect(aSubimage.x, aSubimage.y, aSubimage.width, aSubimage.height);
subimage.ScaleRoundOut(1.0 / scale.width, 1.0 / scale.height);
}
gfxContext* context;
GraphicsFilter filter;
gfxMatrix userSpaceToImageSpace;
gfxRect fill;
gfxRect subimage;
gfxRect sourceRect;
nsIntRect imageRect;
nsIntSize viewportSize;
gfxSize scale;
float animationTime;
const SVGImageContext* svgContext;
uint32_t flags;
};
//******************************************************************************
/* [noscript] void draw(in gfxContext aContext,
* in gfxGraphicsFilter aFilter,
@ -716,58 +781,130 @@ VectorImage::Draw(gfxContext* aContext,
AutoRestore<bool> autoRestoreIsDrawing(mIsDrawing);
mIsDrawing = true;
float time = aWhichFrame == FRAME_FIRST ? 0.0f
: mSVGDocumentWrapper->GetCurrentTime();
AutoSVGRenderingState autoSVGState(aSVGContext,
time,
float animTime = (aWhichFrame == FRAME_FIRST) ? 0.0f
: mSVGDocumentWrapper->GetCurrentTime();
AutoSVGRenderingState autoSVGState(aSVGContext, animTime,
mSVGDocumentWrapper->GetRootSVGElem());
// gfxUtils::DrawPixelSnapped may rasterize this image to a temporary surface
// if we hit the tiling path. Unfortunately, the temporary surface isn't
// created at the size at which we'll ultimately draw, causing fuzzy output.
// To fix this we pre-apply the transform's scaling to the drawing parameters
// and remove the scaling from the transform, so the fact that temporary
// surfaces won't take the scaling into account doesn't matter. (Bug 600207.)
gfxSize scale(aUserSpaceToImageSpace.ScaleFactors(true));
gfxPoint translation(aUserSpaceToImageSpace.GetTranslation());
// Pack up the drawing parameters.
SVGDrawingParameters params(aContext, aFilter, aUserSpaceToImageSpace, aFill,
aSubimage, aViewportSize, aSVGContext, animTime, aFlags);
// Remove the scaling from the transform.
gfxMatrix unscale;
unscale.Translate(gfxPoint(translation.x / scale.width,
translation.y / scale.height));
unscale.Scale(1.0 / scale.width, 1.0 / scale.height);
unscale.Translate(-translation);
gfxMatrix unscaledTransform(aUserSpaceToImageSpace * unscale);
// Check the cache.
nsRefPtr<gfxDrawable> drawable =
SurfaceCache::Lookup(ImageKey(this),
SurfaceKey(params.imageRect.Size(), params.scale,
aSVGContext, animTime, aFlags));
mSVGDocumentWrapper->UpdateViewportBounds(aViewportSize);
// Draw.
if (drawable) {
Show(drawable, params);
} else {
CreateDrawableAndShow(params);
}
return NS_OK;
}
void
VectorImage::CreateDrawableAndShow(const SVGDrawingParameters& aParams)
{
mSVGDocumentWrapper->UpdateViewportBounds(aParams.viewportSize);
mSVGDocumentWrapper->FlushImageTransformInvalidation();
// Rescale drawing parameters.
gfxIntSize drawableSize(aViewportSize.width / scale.width,
aViewportSize.height / scale.height);
gfxRect drawableSourceRect = unscaledTransform.Transform(aFill);
gfxRect drawableImageRect(0, 0, drawableSize.width, drawableSize.height);
gfxRect drawableSubimage(aSubimage.x, aSubimage.y,
aSubimage.width, aSubimage.height);
drawableSubimage.ScaleRoundOut(1.0 / scale.width, 1.0 / scale.height);
nsRefPtr<gfxDrawingCallback> cb =
new SVGDrawingCallback(mSVGDocumentWrapper,
nsIntRect(nsIntPoint(0, 0), aViewportSize),
scale,
aFlags);
nsIntRect(nsIntPoint(0, 0), aParams.viewportSize),
aParams.scale,
aParams.flags);
nsRefPtr<gfxDrawable> drawable = new gfxCallbackDrawable(cb, drawableSize);
nsRefPtr<gfxDrawable> svgDrawable = new gfxCallbackDrawable(cb, aParams.imageRect.Size());
gfxUtils::DrawPixelSnapped(aContext, drawable, unscaledTransform,
drawableSubimage, drawableSourceRect,
drawableImageRect, aFill,
gfxImageFormatARGB32, aFilter, aFlags);
// Refuse to cache animated images.
// XXX(seth): We may remove this restriction in bug 922893.
if (mHaveAnimations)
return Show(svgDrawable, aParams);
// If the image is too big to fit in the cache, don't go any further.
if (!SurfaceCache::CanHold(aParams.imageRect.Size()))
return Show(svgDrawable, aParams);
// Try to create an offscreen surface.
mozilla::RefPtr<mozilla::gfx::DrawTarget> target;
nsRefPtr<gfxContext> ctx;
nsRefPtr<gfxASurface> surface;
if (gfxPlatform::GetPlatform()->SupportsAzureContent()) {
target = gfxPlatform::GetPlatform()->
CreateOffscreenContentDrawTarget(aParams.imageRect.Size(), gfx::FORMAT_B8G8R8A8);
// XXX(seth): All of this ugliness (the backend check, |surface|, the
// GetThebesSurfaceForDrawTarget call) is needed because we can't use Moz2D
// for drawing in all cases yet. See bug 923341.
if (target) {
switch (target->GetType()) {
case mozilla::gfx::BACKEND_DIRECT2D:
case mozilla::gfx::BACKEND_DIRECT2D1_1:
case mozilla::gfx::BACKEND_SKIA:
// Can't cache on this backend.
return Show(svgDrawable, aParams);
default:
surface = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(target);
ctx = new gfxContext(target);
}
}
} else {
target = gfxPlatform::GetPlatform()->
CreateOffscreenCanvasDrawTarget(aParams.imageRect.Size(), gfx::FORMAT_B8G8R8A8);
surface = target ? gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(target)
: nullptr;
ctx = surface ? new gfxContext(surface) : nullptr;
}
// If we couldn't create the draw target, it was probably because it would end
// up way too big. Generally it also wouldn't fit in the cache, but the prefs
// could be set such that the cache isn't the limiting factor. If we couldn't
// create the surface, we are on a platform that does not support
// GetThebesSurfaceForDrawTarget. This will be fixed in bug 923341.
if (!target || !surface)
return Show(svgDrawable, aParams);
// Actually draw. (We use FILTER_NEAREST since we never scale here.)
gfxUtils::DrawPixelSnapped(ctx, svgDrawable, gfxMatrix(),
aParams.imageRect, aParams.imageRect,
aParams.imageRect, aParams.imageRect,
gfxImageFormatARGB32,
GraphicsFilter::FILTER_NEAREST, aParams.flags);
// Attempt to cache the resulting surface.
SurfaceCache::Insert(target,
ImageKey(this),
SurfaceKey(aParams.imageRect.Size(), aParams.scale,
aParams.svgContext, aParams.animationTime,
aParams.flags));
// Draw. Note that if SurfaceCache::Insert failed for whatever reason,
// then |target| is all that is keeping the pixel data alive, so we have
// to draw before returning from this function.
nsRefPtr<gfxDrawable> drawable = new gfxSurfaceDrawable(surface, aParams.imageRect.Size());
Show(drawable, aParams);
}
void
VectorImage::Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams)
{
MOZ_ASSERT(aDrawable, "Should have a gfxDrawable by now");
gfxUtils::DrawPixelSnapped(aParams.context, aDrawable,
aParams.userSpaceToImageSpace,
aParams.subimage, aParams.sourceRect,
aParams.imageRect, aParams.fill,
gfxImageFormatARGB32,
aParams.filter, aParams.flags);
MOZ_ASSERT(mRenderingObserver, "Should have a rendering observer by now");
mRenderingObserver->ResumeHonoringInvalidations();
return NS_OK;
}
//******************************************************************************
@ -815,7 +952,7 @@ VectorImage::UnlockImage()
NS_IMETHODIMP
VectorImage::RequestDiscard()
{
// This method is for image-discarding, which only applies to RasterImages.
SurfaceCache::Discard(this);
return NS_OK;
}

View File

@ -11,6 +11,7 @@
#include "mozilla/MemoryReporting.h"
class nsIRequest;
class gfxDrawable;
namespace mozilla {
namespace layers {
@ -19,10 +20,11 @@ class ImageContainer;
}
namespace image {
class SVGDocumentWrapper;
class SVGRootRenderingObserver;
class SVGLoadEventListener;
class SVGParseCompleteListener;
struct SVGDrawingParameters;
class SVGDocumentWrapper;
class SVGRootRenderingObserver;
class SVGLoadEventListener;
class SVGParseCompleteListener;
class VectorImage : public ImageResource,
public nsIStreamListener
@ -82,6 +84,9 @@ protected:
virtual nsresult StopAnimation();
virtual bool ShouldAnimate();
void CreateDrawableAndShow(const SVGDrawingParameters& aParams);
void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
private:
void CancelAllListeners();

View File

@ -31,6 +31,7 @@ CPP_SOURCES += [
'RasterImage.cpp',
'SVGDocumentWrapper.cpp',
'ScriptedNotificationObserver.cpp',
'SurfaceCache.cpp',
'VectorImage.cpp',
'imgFrame.cpp',
'imgLoader.cpp',

View File

@ -0,0 +1,21 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCP1252ToUnicode.cpp"
#include "nsCharsetConverterManager.cpp"
#include "nsConverterInputStream.cpp"
#include "nsConverterOutputStream.cpp"
#include "nsISO88591ToUnicode.cpp"
#include "nsMacRomanToUnicode.cpp"
#include "nsScriptableUConv.cpp"
#include "nsTextToSubURI.cpp"
#include "nsUConvModule.cpp"
#include "nsUTF8ConverterService.cpp"
#include "nsUTF8ToUnicode.cpp"
#include "nsUnicodeToCP1252.cpp"
#include "nsUnicodeToISO88591.cpp"
#include "nsUnicodeToMacRoman.cpp"
#include "nsUnicodeToUTF8.cpp"

View File

@ -7,21 +7,7 @@
MODULE = 'uconv'
CPP_SOURCES += [
'nsCP1252ToUnicode.cpp',
'nsCharsetConverterManager.cpp',
'nsConverterInputStream.cpp',
'nsConverterOutputStream.cpp',
'nsISO88591ToUnicode.cpp',
'nsMacRomanToUnicode.cpp',
'nsScriptableUConv.cpp',
'nsTextToSubURI.cpp',
'nsUConvModule.cpp',
'nsUTF8ConverterService.cpp',
'nsUTF8ToUnicode.cpp',
'nsUnicodeToCP1252.cpp',
'nsUnicodeToISO88591.cpp',
'nsUnicodeToMacRoman.cpp',
'nsUnicodeToUTF8.cpp',
'UnifiedUCV.cpp',
]
if CONFIG['INTEL_ARCHITECTURE']:

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp1252.ut"
};
nsresult
nsCP1252ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp1252.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -15,8 +15,7 @@
NS_IMPL_ISUPPORTS3(nsConverterInputStream, nsIConverterInputStream,
nsIUnicharInputStream, nsIUnicharLineInputStream)
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
NS_IMETHODIMP
nsConverterInputStream::Init(nsIInputStream* aStream,
@ -24,6 +23,8 @@ nsConverterInputStream::Init(nsIInputStream* aStream,
int32_t aBufferSize,
PRUnichar aReplacementChar)
{
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
if (!aCharset)
aCharset = "UTF-8";

View File

@ -3,6 +3,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsConverterInputStream_h
#define nsConverterInputStream_h
#include "nsIInputStream.h"
#include "nsIConverterInputStream.h"
#include "nsIUnicharLineInputStream.h"
@ -58,3 +61,6 @@ class nsConverterInputStream : public nsIConverterInputStream,
nsAutoPtr<nsLineBuffer<PRUnichar> > mLineBuffer;
};
#endif

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp1252.ut"
};
nsresult
nsISO88591ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp1252.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_MacRomanMappingTable[] = {
#include "macroman.ut"
};
nsresult
nsMacRomanToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_MacRomanMappingTable[] = {
#include "macroman.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_MacRomanMappingTable,
aOuter, aIID, aResult);
}

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_ufMappingTable[] = {
#include "cp1252.uf"
};
nsresult
nsUnicodeToCP1252Constructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_ufMappingTable[] = {
#include "cp1252.uf"
};
return CreateTableEncoder(u1ByteCharset,
(uMappingTable*) &g_ufMappingTable, 1,
aOuter, aIID, aResult);

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_ufMappingTable[] = {
#include "8859-1.uf"
};
nsresult
nsUnicodeToISO88591Constructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_ufMappingTable[] = {
#include "8859-1.uf"
};
return CreateTableEncoder(u1ByteCharset,
(uMappingTable*) &g_ufMappingTable, 1,
aOuter, aIID, aResult);

View File

@ -9,14 +9,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_MacRomanMappingTable[] = {
#include "macroman.uf"
};
nsresult
nsUnicodeToMacRomanConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_MacRomanMappingTable[] = {
#include "macroman.uf"
};
return CreateTableEncoder(u1ByteCharset,
(uMappingTable*) &g_MacRomanMappingTable, 1,
aOuter, aIID, aResult);

View File

@ -0,0 +1,13 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsGBKConvUtil.cpp"
#include "nsGBKToUnicode.cpp"
#include "nsHZToUnicode.cpp"
#include "nsISO2022CNToUnicode.cpp"
#include "nsUnicodeToGB2312V2.cpp"
#include "nsUnicodeToGBK.cpp"
#include "nsUnicodeToHZ.cpp"

View File

@ -11,14 +11,7 @@ EXPORTS += [
]
CPP_SOURCES += [
'nsGBKConvUtil.cpp',
'nsGBKToUnicode.cpp',
'nsHZToUnicode.cpp',
'nsISO2022CNToUnicode.cpp',
'nsUnicodeToGB2312V2.cpp',
'nsUnicodeToGBK.cpp',
'nsUnicodeToHZ.cpp',
'nsUnicodeToISO2022CN.cpp',
'UnifiedUCVCN.cpp',
]
LIBRARY_NAME = 'ucvcn_s'

View File

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCP850ToUnicode.cpp"
#include "nsCP852ToUnicode.cpp"
#include "nsCP855ToUnicode.cpp"
#include "nsCP857ToUnicode.cpp"
#include "nsCP862ToUnicode.cpp"
#include "nsCP864ToUnicode.cpp"
#include "nsUnicodeToCP850.cpp"
#include "nsUnicodeToCP852.cpp"
#include "nsUnicodeToCP855.cpp"
#include "nsUnicodeToCP857.cpp"
#include "nsUnicodeToCP862.cpp"
#include "nsUnicodeToCP864.cpp"

View File

@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCP869ToUnicode.cpp"
#include "nsUnicodeToCP869.cpp"
#include "nsCP1125ToUnicode.cpp"
#include "nsUnicodeToCP1125.cpp"
#include "nsCP1131ToUnicode.cpp"
#include "nsUnicodeToCP1131.cpp"

View File

@ -11,28 +11,12 @@ EXPORTS += [
]
CPP_SOURCES += [
'nsCP850ToUnicode.cpp',
'nsCP852ToUnicode.cpp',
'nsCP855ToUnicode.cpp',
'nsCP857ToUnicode.cpp',
'nsCP862ToUnicode.cpp',
'nsCP864ToUnicode.cpp',
'nsUnicodeToCP850.cpp',
'nsUnicodeToCP852.cpp',
'nsUnicodeToCP855.cpp',
'nsUnicodeToCP857.cpp',
'nsUnicodeToCP862.cpp',
'nsUnicodeToCP864.cpp',
'UnifiedUCVIBM.cpp',
]
if CONFIG['OS_ARCH'] == 'OS2':
CPP_SOURCES += [
'nsCP869ToUnicode.cpp',
'nsUnicodeToCP869.cpp',
'nsCP1125ToUnicode.cpp',
'nsUnicodeToCP1125.cpp',
'nsCP1131ToUnicode.cpp',
'nsUnicodeToCP1131.cpp',
'UnifiedUCVIBMOS2.cpp',
]
LIBRARY_NAME = 'ucvibm_s'

View File

@ -8,10 +8,6 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp1125.ut"
};
//----------------------------------------------------------------------
// Class nsCP1125ToUnicode [implementation]
@ -19,6 +15,10 @@ nsresult
nsCP1125ToUnicodeConstructor(nsISupports* aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp1125.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -8,10 +8,6 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp1131.ut"
};
//----------------------------------------------------------------------
// Class nsCP1131ToUnicode [implementation]
@ -19,6 +15,10 @@ nsresult
nsCP1131ToUnicodeConstructor(nsISupports* aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp1131.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,10 +23,6 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp850.ut"
};
//----------------------------------------------------------------------
// Class nsCP850ToUnicode [implementation]
@ -34,6 +30,10 @@ nsresult
nsCP850ToUnicodeConstructor(nsISupports* aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp850.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,14 +23,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp852.ut"
};
nsresult
nsCP852ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp852.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,14 +23,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp855.ut"
};
nsresult
nsCP855ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp855.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,14 +23,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp857.ut"
};
nsresult
nsCP857ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp857.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,14 +23,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp862.ut"
};
nsresult
nsCP862ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp862.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -23,14 +23,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp864.ut"
};
nsresult
nsCP864ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp864.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -8,14 +8,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_utMappingTable[] = {
#include "cp869.ut"
};
nsresult
nsCP869ToUnicodeConstructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_utMappingTable[] = {
#include "cp869.ut"
};
return CreateOneByteDecoder((uMappingTable*) &g_utMappingTable,
aOuter, aIID, aResult);
}

View File

@ -8,14 +8,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_ufMappingTable[] = {
#include "cp1125.uf"
};
nsresult
nsUnicodeToCP1125Constructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_ufMappingTable[] = {
#include "cp1125.uf"
};
return CreateTableEncoder(u1ByteCharset,
(uMappingTable*) &g_ufMappingTable, 1,
aOuter, aIID, aResult);

View File

@ -8,14 +8,14 @@
//----------------------------------------------------------------------
// Global functions and data [declaration]
static const uint16_t g_ufMappingTable[] = {
#include "cp1131.uf"
};
nsresult
nsUnicodeToCP1131Constructor(nsISupports *aOuter, REFNSIID aIID,
void **aResult)
{
static const uint16_t g_ufMappingTable[] = {
#include "cp1131.uf"
};
return CreateTableEncoder(u1ByteCharset,
(uMappingTable*) &g_ufMappingTable, 1,
aOuter, aIID, aResult);

Some files were not shown because too many files have changed in this diff Show More