bug 606574 - Cocoa event loop instrumentation. r=smichaud,cjones

--HG--
extra : rebase_source : 5970911521b53d504b3c51588f2f112a2da5efe1
This commit is contained in:
Ted Mielczarek 2011-03-03 11:20:02 -05:00
parent bd93205f7e
commit a69e6e1ece
6 changed files with 227 additions and 39 deletions

View File

@ -5101,6 +5101,7 @@ cairo-cocoa)
LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS) $(LIBXUL_DIST)/bin/XUL'
MOZ_FS_LAYOUT=bundle
MOZ_WEBGL=1
MOZ_INSTRUMENT_EVENT_LOOP=1
;;
cairo-android)

View File

@ -88,6 +88,8 @@ private:
static PRBool sProcessedGetURLEvent = PR_FALSE;
@class GeckoNSApplication;
// Methods that can be called from non-Objective-C code.
// This is needed, on relaunch, to force the OS to use the "Cocoa Dock API"
@ -97,7 +99,7 @@ EnsureUseCocoaDockAPI()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
[NSApplication sharedApplication];
[GeckoNSApplication sharedApplication];
NS_OBJC_END_TRY_ABORT_BLOCK;
}
@ -112,7 +114,7 @@ SetupMacApplicationDelegate()
AutoAutoreleasePool pool;
// Ensure that ProcessPendingGetURLAppleEvents() doesn't regress bug 377166.
[NSApplication sharedApplication];
[GeckoNSApplication sharedApplication];
// This call makes it so that application:openFile: doesn't get bogus calls
// from Cocoa doing its own parsing of the argument string. And yes, we need

View File

@ -0,0 +1,51 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ted Mielczarek <ted.mielczarek@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* This file defines constants to be used in the "subtype" field of
* NSApplicationDefined type NSEvents.
*/
#ifndef WIDGET_COCOA_CUSTOMCOCOAEVENTS_H_
#define WIDGET_COCOA_CUSTOMCOCOAEVENTS_H_
// Empty event, just used for prodding the event loop into responding.
const short kEventSubtypeNone = 0;
// Tracer event, used for timing the event loop responsiveness.
const short kEventSubtypeTrace = 1;
#endif /* WIDGET_COCOA_CUSTOMCOCOAEVENTS_H_ */

View File

@ -60,40 +60,41 @@ EXPORTS = \
$(NULL)
CMMSRCS = \
nsBidiKeyboard.mm \
nsClipboard.mm \
nsMenuX.mm \
nsMenuBarX.mm \
nsMenuItemX.mm \
nsMenuItemIconX.mm \
nsMenuUtilsX.mm \
nsMenuGroupOwnerX.mm \
nsFilePicker.mm \
nsDragService.mm \
nsToolkit.mm \
nsAppShell.mm \
nsCocoaUtils.mm \
nsCocoaWindow.mm \
nsChildView.mm \
nsWindowMap.mm \
nsWidgetFactory.mm \
nsCursorManager.mm \
nsMacCursor.mm \
nsScreenCocoa.mm \
nsScreenManagerCocoa.mm \
nsSound.mm \
nsLookAndFeel.mm \
nsNativeThemeCocoa.mm \
nsDeviceContextSpecX.mm \
nsPrintDialogX.mm \
nsPrintOptionsX.mm \
nsPrintSettingsX.mm \
nsIdleServiceX.mm \
nsCocoaTextInputHandler.mm \
nsMacDockSupport.mm \
nsStandaloneNativeMenu.mm \
GfxInfo.mm \
$(NULL)
nsBidiKeyboard.mm \
nsClipboard.mm \
nsMenuX.mm \
nsMenuBarX.mm \
nsMenuItemX.mm \
nsMenuItemIconX.mm \
nsMenuUtilsX.mm \
nsMenuGroupOwnerX.mm \
nsFilePicker.mm \
nsDragService.mm \
nsToolkit.mm \
nsAppShell.mm \
nsCocoaUtils.mm \
nsCocoaWindow.mm \
nsChildView.mm \
nsWindowMap.mm \
nsWidgetFactory.mm \
nsCursorManager.mm \
nsMacCursor.mm \
nsScreenCocoa.mm \
nsScreenManagerCocoa.mm \
nsSound.mm \
nsLookAndFeel.mm \
nsNativeThemeCocoa.mm \
nsDeviceContextSpecX.mm \
nsPrintDialogX.mm \
nsPrintOptionsX.mm \
nsPrintSettingsX.mm \
nsIdleServiceX.mm \
nsCocoaTextInputHandler.mm \
nsMacDockSupport.mm \
nsStandaloneNativeMenu.mm \
GfxInfo.mm \
WidgetTraceEvent.mm \
$(NULL)
ifeq (x86_64,$(TARGET_CPU))
CMMSRCS += ComplexTextInputPanel.mm

View File

@ -0,0 +1,110 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ted Mielczarek <ted.mielczarek@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <Cocoa/Cocoa.h>
#include "CustomCocoaEvents.h"
#include <Foundation/NSAutoreleasePool.h>
#include <mozilla/CondVar.h>
#include <mozilla/Mutex.h>
#include "mozilla/WidgetTraceEvent.h"
using mozilla::CondVar;
using mozilla::Mutex;
using mozilla::MutexAutoLock;
namespace {
Mutex* sMutex = NULL;
CondVar* sCondVar = NULL;
bool sTracerProcessed = false;
}
namespace mozilla {
bool InitWidgetTracing()
{
sMutex = new Mutex("Event tracer thread mutex");
sCondVar = new CondVar(*sMutex, "Event tracer thread condvar");
return sMutex && sCondVar;
}
void CleanUpWidgetTracing()
{
delete sMutex;
delete sCondVar;
sMutex = NULL;
sCondVar = NULL;
}
// This function is called from the main (UI) thread.
void SignalTracerThread()
{
MutexAutoLock lock(*sMutex);
NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong");
sTracerProcessed = true;
sCondVar->Notify();
}
// This function is called from the background tracer thread.
bool FireAndWaitForTracerEvent()
{
NS_ABORT_IF_FALSE(sMutex && sCondVar, "Tracing not initialized!");
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
MutexAutoLock lock(*sMutex);
NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong");
// Post an application-defined event to the main thread's event queue
// and wait for it to get processed.
[NSApp postEvent:[NSEvent otherEventWithType:NSApplicationDefined
location:NSMakePoint(0,0)
modifierFlags:0
timestamp:0
windowNumber:0
context:NULL
subtype:kEventSubtypeTrace
data1:0
data2:0]
atStart:NO];
while (!sTracerProcessed)
sCondVar->Wait();
sTracerProcessed = false;
[pool release];
return true;
}
} // namespace mozilla

View File

@ -43,6 +43,8 @@
#import <Cocoa/Cocoa.h>
#include <dlfcn.h>
#include "CustomCocoaEvents.h"
#include "mozilla/WidgetTraceEvent.h"
#include "nsAppShell.h"
#include "nsCOMPtr.h"
#include "nsIFile.h"
@ -169,6 +171,27 @@ PRBool nsCocoaAppModalWindowList::GeckoModalAboveCocoaModal()
return (topItem.mWidget != nsnull);
}
// GeckoNSApplication
//
// Subclass of NSApplication for filtering out certain events.
@interface GeckoNSApplication : NSApplication
{
}
@end
@implementation GeckoNSApplication
- (void)sendEvent:(NSEvent *)anEvent
{
if ([anEvent type] == NSApplicationDefined &&
[anEvent subtype] == kEventSubtypeTrace) {
mozilla::SignalTracerThread();
return;
}
[super sendEvent:anEvent];
}
@end
// AppShellDelegate
//
// Cocoa bridge class. An object of this class is registered to receive
@ -286,7 +309,7 @@ nsAppShell::Init()
[NSBundle loadNibFile:
[NSString stringWithUTF8String:(const char*)nibPath.get()]
externalNameTable:
[NSDictionary dictionaryWithObject:[NSApplication sharedApplication]
[NSDictionary dictionaryWithObject:[GeckoNSApplication sharedApplication]
forKey:@"NSOwner"]
withZone:NSDefaultMallocZone()];
@ -388,7 +411,7 @@ nsAppShell::ProcessGeckoEvents(void* aInfo)
timestamp:0
windowNumber:0
context:NULL
subtype:0
subtype:kEventSubtypeNone
data1:0
data2:0]
atStart:NO];
@ -410,7 +433,7 @@ nsAppShell::ProcessGeckoEvents(void* aInfo)
timestamp:0
windowNumber:0
context:NULL
subtype:0
subtype:kEventSubtypeNone
data1:0
data2:0]
atStart:NO];