From 6b0a6c93bb75d0c4aad7e2200b77a38390e9eb02 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Thu, 3 Mar 2011 11:20:02 -0500 Subject: [PATCH 01/57] bug 606574 - Implement event loop instrumentation using native events, core implementation + GTK2 implementation. r=karlt,cjones --- config/autoconf.mk.in | 2 + configure.in | 6 + toolkit/xre/EventTracer.cpp | 182 +++++++++++++++++++++++++++ toolkit/xre/EventTracer.h | 54 ++++++++ toolkit/xre/Makefile.in | 4 + toolkit/xre/nsAppRunner.cpp | 16 +++ widget/public/Makefile.in | 7 +- widget/public/WidgetTraceEvent.h | 50 ++++++++ widget/src/gtk2/Makefile.in | 35 +++--- widget/src/gtk2/WidgetTraceEvent.cpp | 86 +++++++++++++ 10 files changed, 424 insertions(+), 18 deletions(-) create mode 100644 toolkit/xre/EventTracer.cpp create mode 100644 toolkit/xre/EventTracer.h create mode 100644 widget/public/WidgetTraceEvent.h create mode 100644 widget/src/gtk2/WidgetTraceEvent.cpp diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 8b94e1e081eb..90868412620d 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -716,6 +716,8 @@ ANDROID_PACKAGE_NAME = @ANDROID_PACKAGE_NAME@ JS_SHARED_LIBRARY = @JS_SHARED_LIBRARY@ +MOZ_INSTRUMENT_EVENT_LOOP = @MOZ_INSTRUMENT_EVENT_LOOP@ + # We only want to do the pymake sanity on Windows, other os's can cope ifeq (,$(filter-out WINNT WINCE,$(HOST_OS_ARCH))) # Ensure invariants between GNU Make and pymake diff --git a/configure.in b/configure.in index 8f667097278f..8a87470e1bde 100644 --- a/configure.in +++ b/configure.in @@ -5220,6 +5220,7 @@ cairo-gtk2|cairo-gtk2-x11) TK_LIBS='$(MOZ_GTK2_LIBS)' AC_DEFINE(MOZ_WIDGET_GTK2) MOZ_PDF_PRINTING=1 + MOZ_INSTRUMENT_EVENT_LOOP=1 ;; cairo-gtk2-dfb) @@ -5302,6 +5303,10 @@ if test "$MOZ_ENABLE_XREMOTE"; then AC_DEFINE(MOZ_ENABLE_XREMOTE) fi +if test "$MOZ_INSTRUMENT_EVENT_LOOP"; then + AC_DEFINE(MOZ_INSTRUMENT_EVENT_LOOP) +fi + if test "$COMPILE_ENVIRONMENT"; then if test "$MOZ_ENABLE_GTK2"; then if test "$MOZ_X11"; then @@ -9185,6 +9190,7 @@ AC_SUBST(VPX_AS_CONVERSION) AC_SUBST(VPX_ASM_SUFFIX) AC_SUBST(VPX_X86_ASM) AC_SUBST(VPX_ARM_ASM) +AC_SUBST(MOZ_INSTRUMENT_EVENT_LOOP) AC_SUBST(LIBJPEG_TURBO_AS) AC_SUBST(LIBJPEG_TURBO_ASFLAGS) AC_SUBST(LIBJPEG_TURBO_X86_ASM) diff --git a/toolkit/xre/EventTracer.cpp b/toolkit/xre/EventTracer.cpp new file mode 100644 index 000000000000..46b89d2d92f2 --- /dev/null +++ b/toolkit/xre/EventTracer.cpp @@ -0,0 +1,182 @@ +/* ***** 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 + * + * 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 ***** */ + +/* + * Event loop instrumentation. This code attempts to measure the + * latency of the UI-thread event loop by firing native events at it from + * a background thread, and measuring how long it takes for them + * to be serviced. The measurement interval (kMeasureInterval, below) + * is also used as the upper bound of acceptable response time. + * When an event takes longer than that interval to be serviced, + * a sample will be written to the log. + * + * Usage: + * + * Set MOZ_INSTRUMENT_EVENT_LOOP=1 in the environment to enable + * this instrumentation. Currently only the UI process is instrumented. + * + * Set MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT in the environment to a + * file path to contain the log output, the default is to log to stdout. + * + * All logged output lines start with MOZ_EVENT_TRACE. All timestamps + * output are milliseconds since the epoch (PRTime / 1000). + * + * On startup, a line of the form: + * MOZ_EVENT_TRACE start + * will be output. + * + * On shutdown, a line of the form: + * MOZ_EVENT_TRACE stop + * will be output. + * + * When an event servicing time exceeds the threshold, a line of the form: + * MOZ_EVENT_TRACE sample + * will be output, where is the number of milliseconds that + * it took for the event to be serviced. + */ + +#include "EventTracer.h" + +#include + +#include "mozilla/TimeStamp.h" +#include "mozilla/WidgetTraceEvent.h" +#include +#include +#include +#include + +using mozilla::TimeDuration; +using mozilla::TimeStamp; +using mozilla::FireAndWaitForTracerEvent; + +namespace { + +PRThread* sTracerThread = NULL; +bool sExit = false; + +/* + * The tracer thread fires events at the native event loop roughly + * every kMeasureInterval. It will sleep to attempt not to send them + * more quickly, but if the response time is longer than kMeasureInterval + * it will not send another event until the previous response is received. + * + * The output defaults to stdout, but can be redirected to a file by + * settting the environment variable MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT + * to the name of a file to use. + */ +void TracerThread(void *arg) +{ + // This should be set to the maximum latency we'd like to allow + // for responsiveness. + const PRIntervalTime kMeasureInterval = PR_MillisecondsToInterval(50); + + FILE* log = NULL; + char* envfile = PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT"); + if (envfile) { + log = fopen(envfile, "w"); + } + if (log == NULL) + log = stdout; + + fprintf(log, "MOZ_EVENT_TRACE start %llu\n", PR_Now() / PR_USEC_PER_MSEC); + + while (!sExit) { + TimeStamp start(TimeStamp::Now()); + PRIntervalTime next_sleep = kMeasureInterval; + + //TODO: only wait up to a maximum of kMeasureInterval, return + // early if that threshold is exceeded and dump a stack trace + // or do something else useful. + if (FireAndWaitForTracerEvent()) { + TimeDuration duration = TimeStamp::Now() - start; + // Only report samples that exceed our measurement interval. + if (duration.ToMilliseconds() > kMeasureInterval) { + fprintf(log, "MOZ_EVENT_TRACE sample %llu %d\n", + PR_Now() / PR_USEC_PER_MSEC, + int(duration.ToSecondsSigDigits() * 1000)); + } + + if (next_sleep > duration.ToMilliseconds()) { + next_sleep -= int(duration.ToMilliseconds()); + } + else { + // Don't sleep at all if this event took longer than the measure + // interval to deliver. + next_sleep = 0; + } + } + + if (next_sleep != 0 && !sExit) { + PR_Sleep(next_sleep); + } + } + + fprintf(log, "MOZ_EVENT_TRACE stop %llu\n", PR_Now() / PR_USEC_PER_MSEC); + + if (log != stdout) + fclose(log); +} + +} // namespace + +namespace mozilla { + +bool InitEventTracing() +{ + // Create a thread that will fire events back at the + // main thread to measure responsiveness. + NS_ABORT_IF_FALSE(!sTracerThread, "Event tracing already initialized!"); + sTracerThread = PR_CreateThread(PR_USER_THREAD, + TracerThread, + NULL, + PR_PRIORITY_NORMAL, + PR_GLOBAL_THREAD, + PR_JOINABLE_THREAD, + 0); + return sTracerThread != NULL; +} + +void ShutdownEventTracing() +{ + sExit = true; + if (sTracerThread) + PR_JoinThread(sTracerThread); + sTracerThread = NULL; +} + +} // namespace mozilla diff --git a/toolkit/xre/EventTracer.h b/toolkit/xre/EventTracer.h new file mode 100644 index 000000000000..2becc53c9e62 --- /dev/null +++ b/toolkit/xre/EventTracer.h @@ -0,0 +1,54 @@ +/* ***** 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 + * + * 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 ***** */ + +#ifndef XRE_EVENTTRACER_H_ +#define XRE_EVENTTRACER_H_ + +namespace mozilla { + +// Create a thread that will fire events back at the +// main thread to measure responsiveness. Return true +// if the thread was created successfully. +bool InitEventTracing(); + +// Signal the background thread to stop, and join it. +// Must be called from the same thread that called InitEventTracing. +void ShutdownEventTracing(); + +} // namespace mozilla + +#endif /* XRE_EVENTTRACER_H_ */ diff --git a/toolkit/xre/Makefile.in b/toolkit/xre/Makefile.in index 4507fc1eb0a4..648b29476660 100644 --- a/toolkit/xre/Makefile.in +++ b/toolkit/xre/Makefile.in @@ -66,6 +66,10 @@ CPPSRCS = \ nsSigHandlers.cpp \ $(NULL) +ifdef MOZ_INSTRUMENT_EVENT_LOOP +CPPSRCS += EventTracer.cpp +endif + ifdef MOZ_SPLASHSCREEN ifeq ($(OS_ARCH),WINCE) CPPSRCS += nsSplashScreenWin.cpp diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index a47192f65001..8b4db05235f3 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -62,6 +62,10 @@ using mozilla::dom::ContentParent; #include "nsAppRunner.h" #include "nsUpdateDriver.h" +#ifdef MOZ_INSTRUMENT_EVENT_LOOP +#include "EventTracer.h" +#endif + #ifdef XP_MACOSX #include "MacLaunchHelper.h" #include "MacApplicationDelegate.h" @@ -3744,6 +3748,13 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) nativeApp->Enable(); } +#ifdef MOZ_INSTRUMENT_EVENT_LOOP + bool event_tracing_running = false; + if (PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP")) { + event_tracing_running = mozilla::InitEventTracing(); + } +#endif /* MOZ_INSTRUMENT_EVENT_LOOP */ + NS_TIME_FUNCTION_MARK("Next: Run"); NS_TIME_FUNCTION_MARK("appStartup->Run"); @@ -3763,6 +3774,11 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_TIME_FUNCTION_MARK("appStartup->Run done"); +#ifdef MOZ_INSTRUMENT_EVENT_LOOP + if (event_tracing_running) + mozilla::ShutdownEventTracing(); +#endif + // Check for an application initiated restart. This is one that // corresponds to nsIAppStartup.quit(eRestart) if (rv == NS_SUCCESS_RESTART_APP) diff --git a/widget/public/Makefile.in b/widget/public/Makefile.in index 30383b9e7a8b..92dd0bbbd746 100644 --- a/widget/public/Makefile.in +++ b/widget/public/Makefile.in @@ -46,12 +46,17 @@ MODULE = widget XPIDL_MODULE = widget GRE_MODULE = 1 -EXPORTS_NAMESPACES = IPC +EXPORTS_NAMESPACES = IPC mozilla EXPORTS_IPC = \ nsGUIEventIPC.h \ $(NULL) +ifdef MOZ_INSTRUMENT_EVENT_LOOP +EXPORTS_mozilla = \ + WidgetTraceEvent.h +endif + EXPORTS = \ nsIWidget.h \ nsGUIEvent.h \ diff --git a/widget/public/WidgetTraceEvent.h b/widget/public/WidgetTraceEvent.h new file mode 100644 index 000000000000..7866610d7bf9 --- /dev/null +++ b/widget/public/WidgetTraceEvent.h @@ -0,0 +1,50 @@ +/* ***** 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 + * + * 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 ***** */ + +#ifndef WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ +#define WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ + +namespace mozilla { + +// Fire a tracer event at the UI-thread event loop, and block until +// the event is processed. This should only be called by +// a thread that's not the UI thread. +bool FireAndWaitForTracerEvent(); + +} + +#endif // WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ diff --git a/widget/src/gtk2/Makefile.in b/widget/src/gtk2/Makefile.in index a8351d8f9d84..ad75f29de139 100644 --- a/widget/src/gtk2/Makefile.in +++ b/widget/src/gtk2/Makefile.in @@ -62,23 +62,24 @@ ifdef ACCESSIBILITY CSRCS += maiRedundantObjectFactory.c endif -CPPSRCS = \ - nsWindow.cpp \ - nsAppShell.cpp \ - nsWidgetFactory.cpp \ - nsToolkit.cpp \ - nsBidiKeyboard.cpp \ - nsLookAndFeel.cpp \ - nsGtkKeyUtils.cpp \ - nsFilePicker.cpp \ - nsSound.cpp \ - nsNativeKeyBindings.cpp \ - nsScreenGtk.cpp \ - nsScreenManagerGtk.cpp \ - nsImageToPixbuf.cpp \ - nsAccessibilityHelper.cpp \ - nsGtkIMModule.cpp \ - $(NULL) +CPPSRCS = \ + nsWindow.cpp \ + nsAppShell.cpp \ + nsWidgetFactory.cpp \ + nsToolkit.cpp \ + nsBidiKeyboard.cpp \ + nsLookAndFeel.cpp \ + nsGtkKeyUtils.cpp \ + nsFilePicker.cpp \ + nsSound.cpp \ + nsNativeKeyBindings.cpp \ + nsScreenGtk.cpp \ + nsScreenManagerGtk.cpp \ + nsImageToPixbuf.cpp \ + nsAccessibilityHelper.cpp \ + nsGtkIMModule.cpp \ + WidgetTraceEvent.cpp \ + $(NULL) ifdef MOZ_X11 CPPSRCS += nsIdleServiceGTK.cpp diff --git a/widget/src/gtk2/WidgetTraceEvent.cpp b/widget/src/gtk2/WidgetTraceEvent.cpp new file mode 100644 index 000000000000..95753ae3b230 --- /dev/null +++ b/widget/src/gtk2/WidgetTraceEvent.cpp @@ -0,0 +1,86 @@ +/* ***** 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 + * + * 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 "mozilla/WidgetTraceEvent.h" + +#include +#include +#include +#include + +using mozilla::CondVar; +using mozilla::Mutex; +using mozilla::MutexAutoLock; + +namespace { + +Mutex sMutex("Event tracer thread mutex"); +CondVar sCondVar(sMutex, "Event tracer thread condvar"); +bool sTracerProcessed = false; + +// This function is called from the main (UI) thread. +gboolean TracerCallback(gpointer data) +{ + MutexAutoLock lock(sMutex); + NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong"); + sTracerProcessed = true; + sCondVar.Notify(); + return FALSE; +} + +} // namespace + +namespace mozilla { + +// This function is called from the background tracer thread. +bool FireAndWaitForTracerEvent() +{ + // Send a default-priority idle event through the + // event loop, and wait for it to finish. + MutexAutoLock lock(sMutex); + NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong"); + g_idle_add_full(G_PRIORITY_DEFAULT, + TracerCallback, + NULL, + NULL); + while (!sTracerProcessed) + sCondVar.Wait(); + sTracerProcessed = false; + return true; +} + +} // namespace mozilla From ab4ffe654b52e427823350679e9c989be4cbe420 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Thu, 3 Mar 2011 11:20:02 -0500 Subject: [PATCH 02/57] bug 606574 - Win32 event loop instrumentation. r=jimm --- configure.in | 1 + widget/public/WidgetTraceEvent.h | 3 + widget/src/windows/Makefile.in | 53 ++++----- widget/src/windows/WidgetTraceEvent.cpp | 148 ++++++++++++++++++++++++ widget/src/windows/nsWindow.cpp | 8 ++ widget/src/windows/nsWindowDefs.h | 2 + 6 files changed, 189 insertions(+), 26 deletions(-) create mode 100644 widget/src/windows/WidgetTraceEvent.cpp diff --git a/configure.in b/configure.in index 8a87470e1bde..a3e75682d8ea 100644 --- a/configure.in +++ b/configure.in @@ -5203,6 +5203,7 @@ cairo-windows) ;; esac MOZ_PDF_PRINTING=1 + MOZ_INSTRUMENT_EVENT_LOOP=1 ;; cairo-gtk2|cairo-gtk2-x11) diff --git a/widget/public/WidgetTraceEvent.h b/widget/public/WidgetTraceEvent.h index 7866610d7bf9..80ca85b85a51 100644 --- a/widget/public/WidgetTraceEvent.h +++ b/widget/public/WidgetTraceEvent.h @@ -45,6 +45,9 @@ namespace mozilla { // a thread that's not the UI thread. bool FireAndWaitForTracerEvent(); +// Signal that the event has been received by the event loop. +void SignalTracerThread(); + } #endif // WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ diff --git a/widget/src/windows/Makefile.in b/widget/src/windows/Makefile.in index 876fb6c165fe..ba09e342de5b 100644 --- a/widget/src/windows/Makefile.in +++ b/widget/src/windows/Makefile.in @@ -47,32 +47,33 @@ LIBRARY_NAME = widget_windows LIBXUL_LIBRARY = 1 -CPPSRCS = \ - nsWindow.cpp \ - nsWindowGfx.cpp \ - nsWindowDbg.cpp \ - nsAppShell.cpp \ - nsToolkit.cpp \ - nsFilePicker.cpp \ - nsScreenWin.cpp \ - nsScreenManagerWin.cpp \ - nsLookAndFeel.cpp \ - nsUXThemeData.cpp \ - nsNativeThemeWin.cpp \ - nsWinGesture.cpp \ - nsIdleServiceWin.cpp \ - nsSound.cpp \ - nsIMM32Handler.cpp \ - WindowHook.cpp \ - WinTaskbar.cpp \ - TaskbarPreview.cpp \ - TaskbarTabPreview.cpp \ - TaskbarWindowPreview.cpp \ - TaskbarPreviewButton.cpp \ - JumpListBuilder.cpp \ - JumpListItem.cpp \ - GfxInfo.cpp \ - $(NULL) +CPPSRCS = \ + nsWindow.cpp \ + nsWindowGfx.cpp \ + nsWindowDbg.cpp \ + nsAppShell.cpp \ + nsToolkit.cpp \ + nsFilePicker.cpp \ + nsScreenWin.cpp \ + nsScreenManagerWin.cpp \ + nsLookAndFeel.cpp \ + nsUXThemeData.cpp \ + nsNativeThemeWin.cpp \ + nsWinGesture.cpp \ + nsIdleServiceWin.cpp \ + nsSound.cpp \ + nsIMM32Handler.cpp \ + WindowHook.cpp \ + WinTaskbar.cpp \ + TaskbarPreview.cpp \ + TaskbarTabPreview.cpp \ + TaskbarWindowPreview.cpp \ + TaskbarPreviewButton.cpp \ + JumpListBuilder.cpp \ + JumpListItem.cpp \ + GfxInfo.cpp \ + WidgetTraceEvent.cpp \ + $(NULL) ifdef MOZ_CRASHREPORTER CPPSRCS += LSPAnnotator.cpp diff --git a/widget/src/windows/WidgetTraceEvent.cpp b/widget/src/windows/WidgetTraceEvent.cpp new file mode 100644 index 000000000000..0e2f629e180a --- /dev/null +++ b/widget/src/windows/WidgetTraceEvent.cpp @@ -0,0 +1,148 @@ +/* ***** 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 + * + * 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 ***** */ + +/* + * Windows widget support for event loop instrumentation. + * See toolkit/xre/EventTracer.cpp for more details. + */ + +#include +#include + +#include "mozilla/WidgetTraceEvent.h" +#include "nsAppShellCID.h" +#include "nsComponentManagerUtils.h" +#include "nsCOMPtr.h" +#include "nsIAppShellService.h" +#include "nsIBaseWindow.h" +#include "nsIDocShell.h" +#include "nsIWidget.h" +#include "nsIXULWindow.h" +#include "nsAutoPtr.h" +#include "nsServiceManagerUtils.h" +#include "nsThreadUtils.h" +#include "nsWindowDefs.h" + +namespace { + +// Used for signaling the background thread from the main thread. +HANDLE event_handle = NULL; + +// We need a runnable in order to find the hidden window on the main +// thread. +class HWNDGetter : public nsRunnable { +public: + HWNDGetter() : hidden_window_hwnd(NULL) {} + + HWND hidden_window_hwnd; + + NS_IMETHOD Run() { + // Jump through some hoops to locate the hidden window. + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + nsCOMPtr hiddenWindow; + + nsresult rv = appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow)); + if (NS_FAILED(rv)) { + return rv; + } + + nsCOMPtr docShell; + rv = hiddenWindow->GetDocShell(getter_AddRefs(docShell)); + if (NS_FAILED(rv) || !docShell) { + return rv; + } + + nsCOMPtr baseWindow(do_QueryInterface(docShell)); + + if (!baseWindow) + return NS_ERROR_FAILURE; + + nsCOMPtr widget; + baseWindow->GetMainWidget(getter_AddRefs(widget)); + + if (!widget) + return NS_ERROR_FAILURE; + + hidden_window_hwnd = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW); + + return NS_OK; + } +}; + +HWND GetHiddenWindowHWND() +{ + // Need to dispatch this to the main thread because plenty of + // the things it wants to access are main-thread-only. + nsRefPtr getter = new HWNDGetter(); + NS_DispatchToMainThread(getter, NS_DISPATCH_SYNC); + return getter->hidden_window_hwnd; +} + +} // namespace + +namespace mozilla { + +// This function is called from the main (UI) thread. +void SignalTracerThread() +{ + if (event_handle != NULL) + SetEvent(event_handle); +} + +// This function is called from the background tracer thread. +bool FireAndWaitForTracerEvent() +{ + // First, try to find the hidden window. + static HWND hidden_window = NULL; + if (hidden_window == NULL) { + hidden_window = GetHiddenWindowHWND(); + } + + if (hidden_window == NULL) + return false; + + if (event_handle == NULL) + event_handle = CreateEvent(NULL, FALSE, FALSE, NULL); + + // Post the tracer message into the hidden window's message queue, + // and then block until it's processed. + PostMessage(hidden_window, MOZ_WM_TRACE, 0, 0); + WaitForSingleObject(event_handle, INFINITE); + return true; +} + +} // namespace mozilla diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 4284ef3fd1ae..18c253a170f1 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -118,6 +118,7 @@ #include "prprf.h" #include "prmem.h" +#include "mozilla/WidgetTraceEvent.h" #include "nsIAppShell.h" #include "nsISupportsPrimitives.h" #include "nsIDOMNSUIEvent.h" @@ -4596,6 +4597,13 @@ LRESULT CALLBACK nsWindow::WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam } } + if (msg == MOZ_WM_TRACE) { + // This is a tracer event for measuring event loop latency. + // See WidgetTraceEvent.cpp for more details. + mozilla::SignalTracerThread(); + return 0; + } + // Get the window which caused the event and ask it to process the message nsWindow *someWindow = GetNSWindowPtr(hWnd); diff --git a/widget/src/windows/nsWindowDefs.h b/widget/src/windows/nsWindowDefs.h index 1dc97098a804..8856b47e4cef 100644 --- a/widget/src/windows/nsWindowDefs.h +++ b/widget/src/windows/nsWindowDefs.h @@ -56,6 +56,8 @@ // A magic APP message that can be sent to quit, sort of like a QUERYENDSESSION/ENDSESSION, // but without the query. #define MOZ_WM_APP_QUIT (WM_APP+0x0300) +// Used as a "tracer" event to probe event loop latency. +#define MOZ_WM_TRACE (WM_APP+0x0301) // GetWindowsVersion constants #define WIN2K_VERSION 0x500 From d1e7a921a412db161ef0d46664f9f9401649ae46 Mon Sep 17 00:00:00 2001 From: Ted Mielczarek Date: Thu, 3 Mar 2011 11:20:02 -0500 Subject: [PATCH 03/57] bug 606574 - Cocoa event loop instrumentation. r=smichaud --- configure.in | 1 + toolkit/xre/MacApplicationDelegate.mm | 6 +- widget/src/cocoa/CustomCocoaEvents.h | 51 +++++++++++++++ widget/src/cocoa/Makefile.in | 69 ++++++++++---------- widget/src/cocoa/WidgetTraceEvent.mm | 92 +++++++++++++++++++++++++++ widget/src/cocoa/nsAppShell.mm | 29 ++++++++- 6 files changed, 209 insertions(+), 39 deletions(-) create mode 100644 widget/src/cocoa/CustomCocoaEvents.h create mode 100644 widget/src/cocoa/WidgetTraceEvent.mm diff --git a/configure.in b/configure.in index a3e75682d8ea..7dc86741cd80 100644 --- a/configure.in +++ b/configure.in @@ -5281,6 +5281,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) diff --git a/toolkit/xre/MacApplicationDelegate.mm b/toolkit/xre/MacApplicationDelegate.mm index ea495d89f00c..1c431d7fe053 100644 --- a/toolkit/xre/MacApplicationDelegate.mm +++ b/toolkit/xre/MacApplicationDelegate.mm @@ -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 diff --git a/widget/src/cocoa/CustomCocoaEvents.h b/widget/src/cocoa/CustomCocoaEvents.h new file mode 100644 index 000000000000..f4ccf779f84a --- /dev/null +++ b/widget/src/cocoa/CustomCocoaEvents.h @@ -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 + * + * 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_ */ diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index d7965d21dfde..e5806ee0564a 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -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 diff --git a/widget/src/cocoa/WidgetTraceEvent.mm b/widget/src/cocoa/WidgetTraceEvent.mm new file mode 100644 index 000000000000..f904a147c261 --- /dev/null +++ b/widget/src/cocoa/WidgetTraceEvent.mm @@ -0,0 +1,92 @@ +/* ***** 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 + * + * 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 +#include "CustomCocoaEvents.h" +#include +#include +#include +#include "mozilla/WidgetTraceEvent.h" + +using mozilla::CondVar; +using mozilla::Mutex; +using mozilla::MutexAutoLock; + +namespace { + +Mutex sMutex("Event tracer thread mutex"); +CondVar sCondVar(sMutex, "Event tracer thread condvar"); +bool sTracerProcessed; + +} + +namespace mozilla { + +// 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() +{ + NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; + MutexAutoLock lock(sMutex); + sTracerProcessed = false; + // 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(); + [pool release]; + return true; +} + +} // namespace mozilla diff --git a/widget/src/cocoa/nsAppShell.mm b/widget/src/cocoa/nsAppShell.mm index 0491a8bef31f..f128e5acdd02 100644 --- a/widget/src/cocoa/nsAppShell.mm +++ b/widget/src/cocoa/nsAppShell.mm @@ -43,6 +43,8 @@ #import #include +#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]; From cb4acc863c165c22f5a860b1dff91970dca106e4 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Thu, 24 Mar 2011 18:03:14 -0400 Subject: [PATCH 04/57] Bug 619002 - When deleting text from edit fields the wrong text is reported through at-spi r=fernando,ginn.chen f=surkov --- accessible/src/atk/nsAccessNodeWrap.cpp | 4 ++++ accessible/src/atk/nsAccessNodeWrap.h | 7 +++++++ accessible/src/atk/nsAccessibleWrap.cpp | 23 ++++++++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/accessible/src/atk/nsAccessNodeWrap.cpp b/accessible/src/atk/nsAccessNodeWrap.cpp index 446cbfe6c4af..8c4b6463169a 100644 --- a/accessible/src/atk/nsAccessNodeWrap.cpp +++ b/accessible/src/atk/nsAccessNodeWrap.cpp @@ -38,6 +38,9 @@ #include "nsAccessNodeWrap.h" #include "nsApplicationAccessibleWrap.h" +#include "nsMaiInterfaceText.h" + +PRBool nsAccessNodeWrap::gHaveNewTextSignals = PR_FALSE; /* For documentation of the accessibility architecture, * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html @@ -68,6 +71,7 @@ nsAccessNodeWrap::~nsAccessNodeWrap() void nsAccessNodeWrap::InitAccessibility() { nsAccessNode::InitXPAccessibility(); + gHaveNewTextSignals = g_signal_lookup("text-insert", ATK_TYPE_TEXT); } void nsAccessNodeWrap::ShutdownAccessibility() diff --git a/accessible/src/atk/nsAccessNodeWrap.h b/accessible/src/atk/nsAccessNodeWrap.h index 22ceab81bb57..6ee2215a8505 100644 --- a/accessible/src/atk/nsAccessNodeWrap.h +++ b/accessible/src/atk/nsAccessNodeWrap.h @@ -53,6 +53,13 @@ public: // construction, destruction static void InitAccessibility(); static void ShutdownAccessibility(); + + /* + * do we have text-remove and text-insert signals if not we need to use + * text-changed see nsAccessibleWrap::FireAtkTextChangedEvent() and + * bug 619002 + */ + static PRBool gHaveNewTextSignals; }; #endif diff --git a/accessible/src/atk/nsAccessibleWrap.cpp b/accessible/src/atk/nsAccessibleWrap.cpp index e1137ff0139c..7473d71d2836 100644 --- a/accessible/src/atk/nsAccessibleWrap.cpp +++ b/accessible/src/atk/nsAccessibleWrap.cpp @@ -1361,14 +1361,27 @@ nsAccessibleWrap::FireAtkTextChangedEvent(AccEvent* aEvent, PRInt32 start = event->GetStartOffset(); PRUint32 length = event->GetLength(); PRBool isInserted = event->IsTextInserted(); - PRBool isFromUserInput = aEvent->IsFromUserInput(); + char* signal_name = nsnull; - char *signal_name = g_strconcat(isInserted ? "text_changed::insert" : "text_changed::delete", - isFromUserInput ? "" : kNonUserInputEvent, NULL); - g_signal_emit_by_name(aObject, signal_name, start, length); - g_free (signal_name); + if (gHaveNewTextSignals) { + nsAutoString text; + event->GetModifiedText(text); + signal_name = g_strconcat(isInserted ? "text-insert" : "text-remove", + isFromUserInput ? "" : "::system", NULL); + g_signal_emit_by_name(aObject, signal_name, start, length, + NS_ConvertUTF16toUTF8(text).get()); + } else { + // XXX remove this code and the gHaveNewTextSignals check when we can + // stop supporting old atk since it doesn't really work anyway + // see bug 619002 + signal_name = g_strconcat(isInserted ? "text_changed::insert" : + "text_changed::delete", + isFromUserInput ? "" : kNonUserInputEvent, NULL); + g_signal_emit_by_name(aObject, signal_name, start, length); + } + g_free(signal_name); return NS_OK; } From bcac02daf13c7ed52f72a5e3826104761698fde9 Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Tue, 12 Apr 2011 15:38:06 -0400 Subject: [PATCH 05/57] Bug 647453 - Removed serialized JS from omnijar, r=taras,khuey --- browser/installer/Makefile.in | 14 ++++++++++++-- browser/installer/precompile_cache.js | 25 ++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/browser/installer/Makefile.in b/browser/installer/Makefile.in index acea03715aa5..fcfd352c68e7 100644 --- a/browser/installer/Makefile.in +++ b/browser/installer/Makefile.in @@ -122,13 +122,23 @@ ifdef RUN_TEST_PROGRAM _ABS_RUN_TEST_PROGRAM = $(call core_abspath,$(RUN_TEST_PROGRAM)) endif +ifndef MOZ_DEBUG +# The precompile_cache.js script outputs a list of files that were +# serialized and do not need to be included in the omnijar anymore +STRIP_ORIGINAL_FILES = zip -d omni.jar `cat sc_log.txt` +else +STRIP_ORIGINAL_FILES = true +endif + GENERATE_CACHE = \ - $(_ABS_RUN_TEST_PROGRAM) $(_ABS_DIST)/bin/xpcshell$(BIN_SUFFIX) -g "$$PWD" -f $(topsrcdir)/browser/installer/precompile_cache.js -e 'populate_startupcache("omni.jar", "startupCache.zip");' && \ + $(_ABS_RUN_TEST_PROGRAM) $(_ABS_DIST)/bin/xpcshell$(BIN_SUFFIX) -g "$$PWD" -f $(topsrcdir)/browser/installer/precompile_cache.js -e 'populate_startupcache("omni.jar", "startupCache.zip", "sc_log.txt");' && \ rm -rf jsloader && \ $(UNZIP) startupCache.zip && \ rm startupCache.zip && \ find jsloader | xargs touch -t 201001010000 && \ - $(ZIP) -r9mX omni.jar jsloader + $(ZIP) -r9mX omni.jar jsloader && \ + $(STRIP_ORIGINAL_FILES) && \ + rm sc_log.txt endif include $(topsrcdir)/toolkit/mozapps/installer/packager.mk diff --git a/browser/installer/precompile_cache.js b/browser/installer/precompile_cache.js index ff3593255b84..942b4af5367b 100644 --- a/browser/installer/precompile_cache.js +++ b/browser/installer/precompile_cache.js @@ -43,6 +43,14 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; +const MODE_RDONLY = 0x01; +const MODE_WRONLY = 0x02; +const MODE_CREATE = 0x08; +const MODE_APPEND = 0x10; +const MODE_TRUNCATE = 0x20; + +var out; + function setenv(name, val) { try { var environment = Components.classes["@mozilla.org/process/environment;1"]. @@ -71,6 +79,7 @@ function load_entries(entries, prefix) { continue; if (c.indexOf("services-crypto") >= 0) continue; + out.writeString(c + "\n"); load(prefix + c); } } @@ -78,6 +87,7 @@ function load_entries(entries, prefix) { function load_custom_entries(entries, subst) { while (entries.hasMore()) { var c = entries.getNext(); + out.writeString(c + "\n"); load("resource://" + subst + "/" + c.replace("modules/" + subst + "/", "")); } } @@ -94,7 +104,7 @@ function openJar(file) { return zipreader; } -function populate_startupcache(omnijarName, startupcacheName) { +function populate_startupcache(omnijarName, startupcacheName, logName) { var file = getGreDir(); file.append(omnijarName); zipreader = openJar(file); @@ -103,6 +113,18 @@ function populate_startupcache(omnijarName, startupcacheName) { scFile.append(startupcacheName); setenv("MOZ_STARTUP_CACHE", scFile.path); + var logFile = getGreDir(); + logFile.append(logName); + var stream = Cc["@mozilla.org/network/file-output-stream;1"] + .createInstance(Ci.nsIFileOutputStream); + + stream.init(logFile, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, 0666, 0); + + out = Cc["@mozilla.org/intl/converter-output-stream;1"] + .createInstance(Ci.nsIConverterOutputStream); + + out.init(stream, "UTF-8", 0, 0); + // the sync part below doesn't work as smoothly let ioService = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); @@ -126,4 +148,5 @@ function populate_startupcache(omnijarName, startupcacheName) { load_entries(zipreader.findEntries("modules/*js"), "resource://gre/"); load_entries(zipreader.findEntries("modules/*jsm"), "resource://gre/"); zipreader.close(); + out.close(); } From 148bcf55fdc9981ba963fbb568f16ea517de6689 Mon Sep 17 00:00:00 2001 From: Oleg Romashin Date: Tue, 12 Apr 2011 15:39:50 -0400 Subject: [PATCH 06/57] Bug 647462 - Video layer should not be ARGB by default; r=chris.double --- layout/generic/nsVideoFrame.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/layout/generic/nsVideoFrame.cpp b/layout/generic/nsVideoFrame.cpp index e82ed168606a..ea936495f0e7 100644 --- a/layout/generic/nsVideoFrame.cpp +++ b/layout/generic/nsVideoFrame.cpp @@ -276,6 +276,7 @@ nsVideoFrame::BuildLayer(nsDisplayListBuilder* aBuilder, layer->SetContainer(container); layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this)); + layer->SetContentFlags(Layer::CONTENT_OPAQUE); // Set a transform on the layer to draw the video in the right place gfxMatrix transform; transform.Translate(r.pos); From 53789e73f2c0f98900e839867dc23918dcf41d79 Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Tue, 12 Apr 2011 15:45:24 -0400 Subject: [PATCH 07/57] Bug 624133 - Update libpng to version 1.4.7. r=joe --- modules/libimg/png/CHANGES | 187 +++++++++- modules/libimg/png/LICENSE | 6 +- modules/libimg/png/MOZCHANGES | 2 + modules/libimg/png/README | 12 +- modules/libimg/png/mozpngconf.h | 16 +- modules/libimg/png/png.c | 30 +- modules/libimg/png/png.h | 594 +++++++++++++++++--------------- modules/libimg/png/pngconf.h | 137 +++++--- modules/libimg/png/pngerror.c | 12 +- modules/libimg/png/pngget.c | 160 ++++----- modules/libimg/png/pngmem.c | 6 +- modules/libimg/png/pngpread.c | 121 +++---- modules/libimg/png/pngpriv.h | 37 +- modules/libimg/png/pngread.c | 85 ++--- modules/libimg/png/pngrio.c | 6 +- modules/libimg/png/pngrtran.c | 45 ++- modules/libimg/png/pngrutil.c | 251 ++++++++------ modules/libimg/png/pngset.c | 61 ++-- modules/libimg/png/pngtrans.c | 8 +- modules/libimg/png/pngwrite.c | 34 +- modules/libimg/png/pngwtran.c | 3 + modules/libimg/png/pngwutil.c | 86 +++-- 22 files changed, 1126 insertions(+), 773 deletions(-) diff --git a/modules/libimg/png/CHANGES b/modules/libimg/png/CHANGES index 0dff4892299f..6574a0bea482 100644 --- a/modules/libimg/png/CHANGES +++ b/modules/libimg/png/CHANGES @@ -1479,7 +1479,7 @@ version 1.2.9beta5 [March 4, 2006] Removed trailing blanks from source files. Put version and date of latest change in each source file, and changed copyright year accordingly. - More cleanup of configure.ac, Makefile.ac, and associated scripts. + More cleanup of configure.ac, Makefile.am, and associated scripts. Restored scripts/makefile.elf which was inadvertently deleted. version 1.2.9beta6 [March 6, 2006] @@ -2610,6 +2610,191 @@ version 1.4.3rc03 [June 23, 2010] version 1.4.3 [June 26, 2010] Updated some of the "last changed" dates. +version 1.4.4beta01 [July 12, 2010] + Removed extraneous new_push_process_row.c file. + Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5 + Removed some newly-added TAB characters from pngpread.c. + Fixed some indentation in pngpread.c and pngrutil.c + Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans) + Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {') + Put "#ifndef PNG_EXTERN, #endif" around "#define PNG_EXTERN" in pngpriv.h + +version 1.4.4beta02 [July 24, 2010] + Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2 + Moved the definition of png_snprintf() outside of the enclosing + #ifdef blocks in pngconf.h + Added a special case typedef of png_longjmp_ptr for WATCOM. + +version 1.4.4beta03 [July 24, 2010] + Removed reference to cbuilder5/* from Makefile.in and Makefile.am + Eliminated the new special case typedef of png_longjmp_ptr for WATCOM + and made a special case "#define PNGAPI" in pngconf.h instead. + +version 1.4.4beta04 [July 31, 2010] + Updated the read macros and functions from 1.5.0beta38. + +version 1.4.4beta05 [August 6, 2010] + Updated projects/visualc71 so it can find scripts/pnglibconf.h + Removed unused png_mem_* defines from pngconf.h. + Correct use of _WINDOWS_ in pngconf.h + +version 1.4.4beta06 [August 11, 2010] + Don't try to use version-script with cygwin/mingw. + Revised contrib/gregbook to work under cygwin/mingw. + +version 1.4.4beta07 [August 26, 2010] + Updated prebuilt aclocal.m4 and ltmain.sh + Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov) + Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for + installing libpng in /usr/lib64 (Funda Wang). + Revised CMakeLists.txt to put the man pages in share/man/man* not man/man* + Revised CMakeLists.txt to make symlinks instead of copies when installing. + Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman) + Moved "#include pngusr.h" ahead of PNG_USER_PRIVATEBUILD test in pngconf.h + Eliminated a deprecated reference to png_ptr->io_ptr in pngtest.c + Eliminated new unnecessary #if tests regarding the sCAL chunk from pngrutil.c + +version 1.4.4beta08 [September 2, 2010] + Updated the xcode project to work with libpng-1.4.x and added iOS targets + for simulator and device (Philippe Hausler). + +version 1.4.4rc01 [September 10, 2010] + No changes. + +version 1.4.4rc02 [September 13, 2010] + Revised CMakeLists.txt (Philip Lowman). + +version 1.4.4rc03 [September 14, 2010] + Removed an extraneous close-double-quote from CMakeLists.txt + Eliminated another deprecated reference to png_ptr->io_ptr in pngtest.c + +version 1.4.4rc04 [September 16, 2010] + Fixed indentation and removed debugging message from CMakeLists.txt + Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER, + $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE + +version 1.4.4rc05 [September 20, 2010] + Rebuilt configure scripts with automake-1.11.1 instead of automake-1.11. + Removed unused mkinstalldirs file. + +version 1.4.4 [September 23, 2010] + No changes. + +version 1.4.5beta01 [September 25, 2010] + Fixed possible configure.ac bug introduced in version 1.4.4rc05. + Rebuilt configure scripts with autoconf-2.68 instead of autoconf-2.65 + +version 1.4.5beta02 [October 5, 2010] + Reverted configure scripts to autoconf-2.65 + Fixed problem with symbols creation in Makefile.am which was assuming that + all versions of cpp write to standard output by default (Martin Banky). The + bug was introduced in libpng-1.2.9beta5. + +version 1.4.5beta03 [October 8, 2010] + Wrapped long lines in CMakeLists.txt and introduced ${libpng_public_hdrs} + Undid Makefile.am revision of 1.4.5beta02. + +version 1.4.5beta04 [November 8, 2010] + Check for out-of-range text compression mode in png_set_text(). + +version 1.4.5rc01 [November 19, 2010] + No changes. + +version 1.4.5beta05 [November 20, 2010] + Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin) + Moved reading of file signature into png_read_sig (Cosmin) + Fixed atomicity of chunk header serialization (Cosmin) + Added test for io_state in pngtest.c (Cosmin) + Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts. + +version 1.4.5beta06 [November 21, 2010] + Restored the parentheses in pngrutil.c; they are needed when the + png_get_*int_*() functions are compiled (i.e., when PNG_USE_READ_MACROS + is not defined). + Make the "png_get_uint_16" macro return a png_uint_32 in libpng-1.4 for API + compatibility. + Changes to remove gcc warnings (John Bowler) + Certain optional gcc warning flags resulted in warnings in libpng code. + With these changes only -Wconversion and -Wcast-qual cannot be turned on. + Changes are trivial rearrangements of code. -Wconversion is not possible + for pngrutil.c (because of the widespread use of += et al on variables + smaller than (int) or (unsigned int)) and -Wcast-qual is not possible + with pngwio.c and pngwutil.c because the 'write' callback and zlib + compression both fail to declare their input buffers with 'const'. + +version 1.4.5beta07 [November 25, 2010] + Reverted png_get_uint_16 macro to beta05 and added comment about the + potential API incompatibility. + +version 1.4.5rc02 [December 2, 2010] + No changes. + +version 1.4.5rc03 [December 3, 2010] + Added missing vstudio/*/*.vcxproj files to the zip and 7z distributions. + +version 1.4.5 [December 9, 2010] + Removed PNG_NO_WRITE_GAMMA from pngminim/encoder/pngusr.h + +version 1.4.6beta01 [December 29, 2010] + Fixed bug in background transformation handling in pngrtran.c (it was + looking for the flag in png_ptr->transformations instead of in + png_ptr->flags) (David Raymond). + +version 1.4.6beta02 [January 14, 2011] + Fixed misspelled macros in contrib/pngminim (Cosmin). + Updated CMakeLists.txt (Clifford Yapp). + +version 1.4.6beta03 [January 14, 2011] + Fixed some typecasts in png_debug statements (Cosmin). + +version 1.4.6beta04 [January 22, 2011] + Updated documentation of png_set|get_tRNS() (Thomas Klausner). + Added png_const_structp and png_const_infop types, and used them in + prototypes for most png_get_*() functions. + In the manual, describe the png_get_IHDR() arguments in the correct order. + Ported change in png_do_rgb_to_gray() from libpng-1.5.1, to make + it more robust against internal libpng coding errors. + +version 1.4.6beta05 [January 23, 2011] + + Updated the synopses in the manual to reflect recent changes. + Fixed a typo in the *.def files and deleted entries that are now + declared in pngpriv.h + +version 1.4.6beta06 [March 19, 2011] + Updated contrib/pngsuite/README to add the word "modify". + Added the private PNG_UNUSED() macro definition in pngconf.h. + +version 1.4.6beta07 [March 22, 2011] + ifdef out mask arrays in pngread.c when interlacing is not supported. + Added attribute definition (warnings) for MSC_VER >= 1300 in pngconf.h + Added -D_CRT_SECURE_NO_DEPRECATE to CFLAGS in makefile.vcwin32 + Fixed mistake in the descriptions of user read_transform and write_transform + function prototypes in the manual. The row_info struct is png_row_infop. + Added a request in the manual that applications do not use "png_" or + "PNG_" to begin any of their own symbols. + Fixed incorrect examples of callback prototypes in the manual, that were + introduced in libpng-1.0.0. + Removed "strip" from contrib/pngminim/*/makefile. + Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail + to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill) + +version 1.4.6rc01 [March 31, 2011] + No changes. + +version 1.4.6rc02 [April 6, 2011] + Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03). + +version 1.4.6 [April 8, 2011] + No changes. + +version 1.4.7rc01 [April 9, 2011] + Relocated misplaced new declarations in pngwutil.c. + +version 1.4.7 [April 10, 2011] + Disabled PNG_PEDANTIC_WARNINGS for all MSC versions as in libpng-1.4.5. + + Send comments/corrections/commendations to glennrp at users.sourceforge.net or to png-mng-implement at lists.sf.net (subscription required; visit https://lists.sourceforge.net/lists/listinfo/png-mng-implement). diff --git a/modules/libimg/png/LICENSE b/modules/libimg/png/LICENSE index dd89a6684784..4915b94409c0 100644 --- a/modules/libimg/png/LICENSE +++ b/modules/libimg/png/LICENSE @@ -10,8 +10,8 @@ this sentence. This code is released under the libpng license. -libpng versions 1.2.6, August 15, 2004, through 1.4.3, June 26, 2010, are -Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are +libpng versions 1.2.6, August 15, 2004, through 1.4.7, April 10, 2011, are +Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are distributed according to the same disclaimer and license as libpng-1.2.5 with the following individual added to the list of Contributing Authors @@ -108,4 +108,4 @@ certification mark of the Open Source Initiative. Glenn Randers-Pehrson glennrp at users.sourceforge.net -June 26, 2010 +April 10, 2011 diff --git a/modules/libimg/png/MOZCHANGES b/modules/libimg/png/MOZCHANGES index 5bb742bf917f..3772db631a54 100644 --- a/modules/libimg/png/MOZCHANGES +++ b/modules/libimg/png/MOZCHANGES @@ -1,6 +1,8 @@ Changes made to pristine png source by mozilla.org developers. +2011/04/08 -- Synced with libpng-1.4.7 (bug #624133). + 2010/06/30 -- Synced with libpng-1.4.3 (bug #564792). 2010/02/26 -- Synced with libpng-1.4.1 (bug #544747). diff --git a/modules/libimg/png/README b/modules/libimg/png/README index 799f3ebe0227..fe1b500e0699 100644 --- a/modules/libimg/png/README +++ b/modules/libimg/png/README @@ -1,4 +1,4 @@ -README for libpng version 1.4.3 - June 26, 2010 (shared library 14.0) +README for libpng version 1.4.7 - April 10, 2011 (shared library 14.0) See the note about version numbers near the top of png.h See INSTALL for instructions on how to install libpng. @@ -185,9 +185,9 @@ Files in this distribution: makefile.std => Generic UNIX makefile (cc, creates static libpng.a) makefile.elf => Linux/ELF makefile symbol versioning, - gcc, creates libpng14.so.14.1.4.3) + (gcc, creates libpng14.so.14.1.4.7) makefile.linux => Linux/ELF makefile - (gcc, creates libpng14.so.14.1.4.3) + (gcc, creates libpng14.so.14.1.4.7) makefile.gcc => Generic makefile (gcc, creates static libpng.a) makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr (Requires ansi2knr.c from @@ -209,12 +209,12 @@ Files in this distribution: makefile.openbsd => OpenBSD makefile makefile.sgi => Silicon Graphics IRIX (cc, creates static lib) makefile.sggcc => Silicon Graphics - (gcc, creates libpng14.so.14.1.4.3) + (gcc, creates libpng14.so.14.1.4.7) makefile.sunos => Sun makefile makefile.solaris => Solaris 2.X makefile - (gcc, creates libpng14.so.14.1.4.3) + (gcc, creates libpng14.so.14.1.4.7) makefile.so9 => Solaris 9 makefile - (gcc, creates libpng14.so.14.1.4.3) + (gcc, creates libpng14.so.14.1.4.7) makefile.32sunu => Sun Ultra 32-bit makefile makefile.64sunu => Sun Ultra 64-bit makefile makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc diff --git a/modules/libimg/png/mozpngconf.h b/modules/libimg/png/mozpngconf.h index efa24dbe72ef..b2f7de8f48c0 100644 --- a/modules/libimg/png/mozpngconf.h +++ b/modules/libimg/png/mozpngconf.h @@ -42,15 +42,23 @@ #define PNG_NO_GLOBAL_ARRAYS +#ifdef _MSC_VER +/* The PNG_PEDANTIC_WARNINGS (attributes) fail to build with some MSC + * compilers; we'll play it safe and disable them for all MSC compilers. + */ +#define PNG_NO_PEDANTIC_WARNINGS +#endif + #ifndef MOZ_PNG_READ #define PNG_NO_READ_SUPPORTED #endif +#define PNG_NO_READ_BGR #define PNG_NO_SET_USER_LIMITS #define PNG_NO_USER_LIMITS #define PNG_NO_ASSEMBLER_CODE #define PNG_NO_WARN_UNINITIALIZED_ROW #define PNG_NO_READ_BACKGROUND -#define PNG_NO_READ_DITHER +#define PNG_NO_READ_QUANTIZE #define PNG_NO_READ_INVERT #define PNG_NO_READ_SHIFT #define PNG_NO_READ_PACK @@ -61,8 +69,10 @@ #define PNG_NO_READ_INVERT_ALPHA #define PNG_NO_READ_RGB_TO_GRAY #define PNG_NO_READ_USER_TRANSFORM + #define PNG_NO_READ_bKGD #define PNG_NO_READ_hIST +#define PNG_NO_READ_oFFs #define PNG_NO_READ_pCAL #define PNG_NO_READ_pHYs #define PNG_NO_READ_sBIT @@ -75,7 +85,6 @@ #define PNG_NO_READ_EMPTY_PLTE #define PNG_NO_READ_OPT_PLTE #define PNG_NO_READ_STRIP_ALPHA -#define PNG_NO_READ_oFFs #define PNG_NO_SEQUENTIAL_READ_SUPPORTED #ifndef MOZ_PNG_WRITE @@ -118,6 +127,7 @@ #define PNG_NO_HANDLE_AS_UNKNOWN #define PNG_NO_INFO_IMAGE +#define PNG_NO_IO_STATE #define PNG_NO_USER_MEM #define PNG_NO_FIXED_POINT_SUPPORTED #define PNG_NO_MNG_FEATURES @@ -126,7 +136,7 @@ #define PNG_NO_ZALLOC_ZERO #define PNG_NO_ERROR_NUMBERS #define PNG_NO_EASY_ACCESS - +#define PNG_NO_TIME_RFC1123 /* Mangle names of exported libpng functions so different libpng versions can coexist. It is recommended that if you do this, you give your diff --git a/modules/libimg/png/png.c b/modules/libimg/png/png.c index dab4f36459dc..2316a8e25fda 100644 --- a/modules/libimg/png/png.c +++ b/modules/libimg/png/png.c @@ -1,8 +1,8 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.4.2 [May 6, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -17,11 +17,7 @@ #include "pngpriv.h" /* Generate a compiler error if there is an old png.h in the search path. */ -typedef version_1_4_3 Your_png_h_is_not_version_1_4_3; - -/* Version information for C files. This had better match the version - * string defined in png.h. - */ +typedef version_1_4_7 Your_png_h_is_not_version_1_4_7; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another @@ -543,21 +539,21 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */ png_charp PNGAPI -png_get_copyright(png_structp png_ptr) +png_get_copyright(png_const_structp png_ptr) { - png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ #ifdef PNG_STRING_COPYRIGHT return PNG_STRING_COPYRIGHT #else #ifdef __STDC__ return ((png_charp) PNG_STRING_NEWLINE \ - "libpng version 1.4.3 - June 26, 2010" PNG_STRING_NEWLINE \ + "libpng version 1.4.7 - April 10, 2011" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ PNG_STRING_NEWLINE); #else - return ((png_charp) "libpng version 1.4.3 - June 26, 2010\ + return ((png_charp) "libpng version 1.4.7 - April 10, 2011\ Copyright (c) 1998-2010 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."); @@ -574,23 +570,23 @@ png_get_copyright(png_structp png_ptr) * it is guaranteed that png.c uses the correct version of png.h. */ png_charp PNGAPI -png_get_libpng_ver(png_structp png_ptr) +png_get_libpng_ver(png_const_structp png_ptr) { /* Version of *.c files used when building libpng */ - png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ return ((png_charp) PNG_LIBPNG_VER_STRING); } png_charp PNGAPI -png_get_header_ver(png_structp png_ptr) +png_get_header_ver(png_const_structp png_ptr) { /* Version of *.h files used when building libpng */ - png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ + PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */ return ((png_charp) PNG_LIBPNG_VER_STRING); } png_charp PNGAPI -png_get_header_version(png_structp png_ptr) +png_get_header_version(png_const_structp png_ptr) { /* Returns longer string containing both version and date */ png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */ @@ -678,7 +674,7 @@ png_convert_size(size_t size) */ void /* PRIVATE */ -png_64bit_product (long v1, long v2, unsigned long *hi_product, +png_64bit_product(long v1, long v2, unsigned long *hi_product, unsigned long *lo_product) { int a, b, c, d; diff --git a/modules/libimg/png/png.h b/modules/libimg/png/png.h index 400d30db3e09..543af1399f47 100644 --- a/modules/libimg/png/png.h +++ b/modules/libimg/png/png.h @@ -1,8 +1,8 @@ /* png.h - header file for PNG reference library * - * libpng version 1.4.3 - June 26, 2010 - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * libpng version 1.4.7 - April 10, 2011 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -11,7 +11,7 @@ * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.4.3 - June 26, 2010: Glenn + * libpng versions 0.97, January 1998, through 1.4.7 - April 10, 2011: Glenn * See also "Contributing Authors", below. * * Note about libpng version numbers: @@ -145,6 +145,19 @@ * 1.4.3beta01-05 14 10403 14.so.14.3[.0] * 1.4.3rc01-03 14 10403 14.so.14.3[.0] * 1.4.3 14 10403 14.so.14.3[.0] + * 1.4.4beta01-08 14 10404 14.so.14.4[.0] + * 1.4.4rc01-05 14 10404 14.so.14.4[.0] + * 1.4.4 14 10404 14.so.14.4[.0] + * 1.4.5beta01-04 14 10405 14.so.14.5[.0] + * 1.4.5rc01 14 10405 14.so.14.5[.0] + * 1.4.5beta05-07 14 10405 14.so.14.5[.0] + * 1.4.5rc02-03 14 10405 14.so.14.5[.0] + * 1.4.5 14 10405 14.so.14.5[.0] + * 1.4.6beta01-07 14 10406 14.so.14.6[.0] + * 1.4.6rc01 14 10406 14.so.14.6[.0] + * 1.4.6 14 10406 14.so.14.6[.0] + * 1.4.7rc01 14 10407 14.so.14.7[.0] + * 1.4.7 14 10407 14.so.14.7[.0] * * Henceforth the source version will match the shared-library major * and minor numbers; the shared-library major version number will be @@ -176,7 +189,7 @@ * * This code is released under the libpng license. * - * libpng versions 1.2.6, August 15, 2004, through 1.4.3, June 26, 2010, are + * libpng versions 1.2.6, August 15, 2004, through 1.4.7, April 10, 2011, are * Copyright (c) 2004, 2006-2010 Glenn Randers-Pehrson, and are * distributed according to the same disclaimer and license as libpng-1.2.5 * with the following individual added to the list of Contributing Authors: @@ -288,13 +301,13 @@ * Y2K compliance in libpng: * ========================= * - * June 26, 2010 + * April 10, 2011 * * Since the PNG Development group is an ad-hoc body, we can't make * an official declaration. * * This is your unofficial assurance that libpng from version 0.71 and - * upward through 1.4.3 are Y2K compliant. It is my belief that earlier + * upward through 1.4.7 are Y2K compliant. It is my belief that earlier * versions were also Y2K compliant. * * Libpng only has three year fields. One is a 2-byte unsigned integer @@ -350,9 +363,9 @@ */ /* Version information for png.h - this should match the version in png.c */ -#define PNG_LIBPNG_VER_STRING "1.4.3" +#define PNG_LIBPNG_VER_STRING "1.4.7" #define PNG_HEADER_VERSION_STRING \ - " libpng version 1.4.3 - June 26, 2010\n" + " libpng version 1.4.7 - April 10, 2011\n" #define PNG_LIBPNG_VER_SONUM 14 #define PNG_LIBPNG_VER_DLLNUM 14 @@ -360,7 +373,7 @@ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ #define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MINOR 4 -#define PNG_LIBPNG_VER_RELEASE 3 +#define PNG_LIBPNG_VER_RELEASE 7 /* This should match the numeric part of the final component of * PNG_LIBPNG_VER_STRING, omitting any leading zero: */ @@ -390,7 +403,7 @@ * version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ -#define PNG_LIBPNG_VER 10403 /* 1.4.3 */ +#define PNG_LIBPNG_VER 10407 /* 1.4.7 */ #ifndef PNG_VERSION_INFO_ONLY /* Include the compression library's header */ @@ -910,6 +923,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) } png_info; typedef png_info FAR * png_infop; +typedef PNG_CONST png_info FAR * png_const_infop; typedef png_info FAR * FAR * png_infopp; /* Maximum positive integer used in PNG is (2^31)-1 */ @@ -1034,6 +1048,7 @@ typedef png_row_info FAR * FAR * png_row_infopp; */ typedef struct png_struct_def png_struct; typedef png_struct FAR * png_structp; +typedef PNG_CONST png_struct FAR * png_const_structp; typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp)); typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t)); @@ -1051,7 +1066,7 @@ typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep, png_uint_32, int)); #ifdef PNG_APNG_SUPPORTED -typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp, +typedef void (PNGAPI *png_progressive_frame_ptr) PNGARG((png_structp, png_uint_32)); #endif #endif @@ -1530,7 +1545,7 @@ struct png_struct_def /* This triggers a compiler error in png.c, if png.c and png.h * do not agree upon the version number. */ -typedef png_structp version_1_4_3; +typedef png_structp version_1_4_7; typedef png_struct FAR * FAR * png_structpp; @@ -1541,12 +1556,12 @@ typedef png_struct FAR * FAR * png_structpp; */ /* Returns the version number of the library */ -extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void)); +PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void)); /* Tell lib we have already handled the first magic bytes. * Handling more than 8 bytes from the beginning of the file is an error. */ -extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, int num_bytes)); /* Check sig[start] through sig[start + num_to_check - 1] to see if it's a @@ -1554,7 +1569,7 @@ extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr, * signature, and non-zero otherwise. Having num_to_check == 0 or * start > 7 will always fail (ie return non-zero). */ -extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, +PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, png_size_t num_to_check)); /* Simple signature checking function. This is the same as calling @@ -1563,19 +1578,19 @@ extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start, #define png_check_sig(sig,n) !png_sig_cmp((sig), 0, (n)) /* Allocate and initialize png_ptr struct for reading, and any other memory. */ -extern PNG_EXPORT(png_structp,png_create_read_struct) +PNG_EXPORT(png_structp,png_create_read_struct) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED; /* Allocate and initialize png_ptr struct for writing, and any other memory */ -extern PNG_EXPORT(png_structp,png_create_write_struct) +PNG_EXPORT(png_structp,png_create_write_struct) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)) PNG_ALLOCATED; -extern PNG_EXPORT(png_size_t,png_get_compression_buffer_size) - PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_size_t,png_get_compression_buffer_size) + PNGARG((png_const_structp png_ptr)); -extern PNG_EXPORT(void,png_set_compression_buffer_size) +PNG_EXPORT(void,png_set_compression_buffer_size) PNGARG((png_structp png_ptr, png_size_t size)); /* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp @@ -1589,7 +1604,7 @@ extern PNG_EXPORT(void,png_set_compression_buffer_size) * allocated by the library - the call will return NULL on a mismatch * indicating an ABI mismatch. */ -extern PNG_EXPORT(jmp_buf*, png_set_longjmp_fn) +PNG_EXPORT(jmp_buf*, png_set_longjmp_fn) PNGARG((png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)); # define png_jmpbuf(png_ptr) \ @@ -1601,170 +1616,170 @@ extern PNG_EXPORT(jmp_buf*, png_set_longjmp_fn) #ifdef PNG_READ_SUPPORTED /* Reset the compression stream */ -extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); +PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr)); #endif /* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */ #ifdef PNG_USER_MEM_SUPPORTED -extern PNG_EXPORT(png_structp,png_create_read_struct_2) +PNG_EXPORT(png_structp,png_create_read_struct_2) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)) PNG_ALLOCATED; -extern PNG_EXPORT(png_structp,png_create_write_struct_2) +PNG_EXPORT(png_structp,png_create_write_struct_2) PNGARG((png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)) PNG_ALLOCATED; #endif /* Write the PNG file signature. */ -extern PNG_EXPORT(void,png_write_sig) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_write_sig) PNGARG((png_structp png_ptr)); /* Write a PNG chunk - size, type, (optional) data, CRC. */ -extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr, png_bytep chunk_name, png_bytep data, png_size_t length)); /* Write the start of a PNG chunk - length and chunk name. */ -extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr, png_bytep chunk_name, png_uint_32 length)); /* Write the data of a PNG chunk started with png_write_chunk_start(). */ -extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr, png_bytep data, png_size_t length)); /* Finish a chunk started with png_write_chunk_start() (includes CRC). */ -extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr)); /* Allocate and initialize the info structure */ -extern PNG_EXPORT(png_infop,png_create_info_struct) +PNG_EXPORT(png_infop,png_create_info_struct) PNGARG((png_structp png_ptr)) PNG_ALLOCATED; -extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, +PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, png_size_t png_info_struct_size)); /* Writes all the PNG information before the image. */ -extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the information before the actual image data. */ -extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr, png_infop info_ptr)); #endif #ifdef PNG_TIME_RFC1123_SUPPORTED -extern PNG_EXPORT(png_charp,png_convert_to_rfc1123) +PNG_EXPORT(png_charp,png_convert_to_rfc1123) PNGARG((png_structp png_ptr, png_timep ptime)); #endif #ifdef PNG_CONVERT_tIME_SUPPORTED /* Convert from a struct tm to png_time */ -extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, +PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime, struct tm FAR * ttime)); /* Convert from time_t to png_time. Uses gmtime() */ -extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, +PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime, time_t ttime)); #endif /* PNG_CONVERT_tIME_SUPPORTED */ #ifdef PNG_READ_EXPAND_SUPPORTED /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ -extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp +PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) /* Use blue, green, red order for pixels. */ -extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr)); #endif #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED /* Expand the grayscale to 24-bit RGB if necessary. */ -extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr)); #endif #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED /* Reduce RGB to grayscale. */ #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr, int error_action, double red, double green )); #endif -extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr, int error_action, png_fixed_point red, png_fixed_point green )); -extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp +PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_const_structp png_ptr)); #endif -extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth, +PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth, png_colorp palette)); #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED -extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) -extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) -extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) /* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ -extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr, png_uint_32 filler, int flags)); /* The values of the PNG_FILLER_ defines should NOT be changed */ #define PNG_FILLER_BEFORE 0 #define PNG_FILLER_AFTER 1 /* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ -extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr, png_uint_32 filler, int flags)); #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */ #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) /* Swap bytes in 16-bit depth files. */ -extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) /* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */ -extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_PACKSWAP_SUPPORTED) || \ defined(PNG_WRITE_PACKSWAP_SUPPORTED) /* Swap packing order of pixels in bytes. */ -extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) /* Converts files to legal bit depths. */ -extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr, png_color_8p true_bits)); #endif #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ defined(PNG_WRITE_INTERLACING_SUPPORTED) /* Have the code handle the interlacing. Returns the number of passes. */ -extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr)); +PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr)); #endif #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) /* Invert monochrome files */ -extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr)); #endif #ifdef PNG_READ_BACKGROUND_SUPPORTED /* Handle alpha and tRNS by replacing with a background color. */ #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, png_color_16p background_color, int background_gamma_code, int need_expand, double background_gamma)); #endif @@ -1776,14 +1791,14 @@ extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr, #ifdef PNG_READ_16_TO_8_SUPPORTED /* Strip the second byte of information from a 16-bit depth file. */ -extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr)); #endif #ifdef PNG_READ_QUANTIZE_SUPPORTED /* Turn on quantizing, and reduce the palette to the number of colors * available. Prior to libpng-1.4.2, this was png_set_dither(). */ -extern PNG_EXPORT(void,png_set_quantize) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_quantize) PNGARG((png_structp png_ptr, png_colorp palette, int num_palette, int maximum_colors, png_uint_16p histogram, int full_quantize)); #endif @@ -1793,7 +1808,7 @@ extern PNG_EXPORT(void,png_set_quantize) PNGARG((png_structp png_ptr, #ifdef PNG_READ_GAMMA_SUPPORTED /* Handle gamma correction. Screen_gamma=(display_exponent) */ #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, double screen_gamma, double default_file_gamma)); #endif #endif @@ -1801,85 +1816,85 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr, #ifdef PNG_WRITE_FLUSH_SUPPORTED /* Set how many lines between output flushes - 0 for no flushing */ -extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows)); +PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows)); /* Flush the current PNG output buffer */ -extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr)); #endif /* Optional update palette with requested transformations */ -extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); +PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr)); /* Optional call to update the users info structure */ -extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read one or more rows of image data. */ -extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr, png_bytepp row, png_bytepp display_row, png_uint_32 num_rows)); #endif #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read a row of data. */ -extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr, png_bytep row, png_bytep display_row)); #endif #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the whole image into memory at once. */ -extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr, png_bytepp image)); #endif /* Write a row of image data */ -extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr, png_bytep row)); /* Write a few rows of image data */ -extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr, png_bytepp row, png_uint_32 num_rows)); /* Write the image data */ -extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr, png_bytepp image)); #ifdef PNG_WRITE_APNG_SUPPORTED extern PNG_EXPORT (void,png_write_frame_head) PNGARG((png_structp png_ptr, png_infop png_info, png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, - png_uint_32 x_offset, png_uint_32 y_offset, + png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op)); extern PNG_EXPORT (void,png_write_frame_tail) PNGARG((png_structp png_ptr, png_infop png_info)); #endif - + /* Write the end of the PNG file. */ -extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr, png_infop info_ptr)); #ifdef PNG_SEQUENTIAL_READ_SUPPORTED /* Read the end of the PNG file. */ -extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr, png_infop info_ptr)); #endif /* Free any memory associated with the png_info_struct */ -extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr, png_infopp info_ptr_ptr)); /* Free any memory associated with the png_struct and the png_info_structs */ -extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp +PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)); /* Free any memory associated with the png_struct and the png_info_structs */ -extern PNG_EXPORT(void,png_destroy_write_struct) +PNG_EXPORT(void,png_destroy_write_struct) PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)); /* Set the libpng method of handling chunk CRC errors */ -extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, int crit_action, int ancil_action)); /* Values for png_set_crc_action() to say how to handle CRC errors in @@ -1909,7 +1924,7 @@ extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr, /* Set the filtering method(s) used by libpng. Currently, the only valid * value for "method" is 0. */ -extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, +PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, int filters)); /* Flags for png_set_filter() to say which filters to use. The flags @@ -1966,7 +1981,7 @@ extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method, * to the UNWEIGHTED method, but with added encoding time/computation. */ #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, int heuristic_method, int num_weights, png_doublep filter_weights, png_doublep filter_costs)); #endif @@ -1987,19 +2002,19 @@ extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr, * for PNG images, and do considerably fewer caclulations. In the future, * these values may not correspond directly to the zlib compression levels. */ -extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr, int level)); -extern PNG_EXPORT(void,png_set_compression_mem_level) +PNG_EXPORT(void,png_set_compression_mem_level) PNGARG((png_structp png_ptr, int mem_level)); -extern PNG_EXPORT(void,png_set_compression_strategy) +PNG_EXPORT(void,png_set_compression_strategy) PNGARG((png_structp png_ptr, int strategy)); -extern PNG_EXPORT(void,png_set_compression_window_bits) +PNG_EXPORT(void,png_set_compression_window_bits) PNGARG((png_structp png_ptr, int window_bits)); -extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, int method)); /* These next functions are called for input/output, memory, and error @@ -2013,7 +2028,7 @@ extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr, #ifdef PNG_STDIO_SUPPORTED /* Initialize the input/output for the PNG file to the default functions. */ -extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp)); #endif @@ -2025,11 +2040,11 @@ extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, * default function will be used. */ -extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn)); /* Return the user pointer associated with the error functions */ -extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_const_structp png_ptr)); /* Replace the default data output functions with a user supplied one(s). * If buffered output is not used, then output_flush_fn can be set to NULL. @@ -2041,54 +2056,54 @@ extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr)); * default flush function, which uses the standard *FILE structure, will * be used. */ -extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)); /* Replace the default data input function with a user supplied one. */ -extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn)); /* Return the user pointer associated with the I/O functions */ -extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr, png_read_status_ptr read_row_fn)); -extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr, png_write_status_ptr write_row_fn)); #ifdef PNG_USER_MEM_SUPPORTED /* Replace the default memory allocation functions with user supplied one(s). */ -extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)); /* Return the user pointer associated with the memory functions */ -extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_const_structp png_ptr)); #endif #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED -extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp +PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp png_ptr, png_user_transform_ptr read_user_transform_fn)); #endif #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED -extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp +PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp png_ptr, png_user_transform_ptr write_user_transform_fn)); #endif #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) -extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp +PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp png_ptr, png_voidp user_transform_ptr, int user_transform_depth, int user_transform_channels)); /* Return the user pointer associated with the user transform functions */ -extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr) - PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_voidp,png_get_user_transform_ptr) + PNGARG((png_const_structp png_ptr)); #endif #ifdef PNG_USER_CHUNKS_SUPPORTED -extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr, png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn)); -extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp +PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_const_structp png_ptr)); #endif @@ -2096,50 +2111,52 @@ extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp /* Sets the function callbacks for the push reader, and a pointer to a * user-defined structure available to the callback functions. */ -extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr, png_voidp progressive_ptr, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn)); + #ifdef PNG_READ_APNG_SUPPORTED -extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp png_ptr, +extern PNG_EXPORT(void,png_set_progressive_frame_fn) PNGARG((png_structp + png_ptr, png_progressive_frame_ptr frame_info_fn, png_progressive_frame_ptr frame_end_fn)); #endif /* Returns the user pointer associated with the push read functions */ -extern PNG_EXPORT(png_voidp,png_get_progressive_ptr) - PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_voidp,png_get_progressive_ptr) + PNGARG((png_const_structp png_ptr)); /* Function to be called when data becomes available */ -extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr, png_infop info_ptr, png_bytep buffer, png_size_t buffer_size)); /* Function that combines rows. Not very much different than the * png_combine_row() call. Is this even used????? */ -extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr, png_bytep old_row, png_bytep new_row)); #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ -extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr, png_alloc_size_t size)) PNG_ALLOCATED; /* Added at libpng version 1.4.0 */ -extern PNG_EXPORT(png_voidp,png_calloc) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_voidp,png_calloc) PNGARG((png_structp png_ptr, png_alloc_size_t size)) PNG_ALLOCATED; /* Added at libpng version 1.2.4 */ -extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr, png_alloc_size_t size)) PNG_ALLOCATED; /* Frees a pointer allocated by png_malloc() */ -extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); +PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr)); /* Free data that was allocated internally */ -extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num)); /* Reassign responsibility for freeing existing data, whether allocated * by libpng or by the application */ -extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask)); /* Assignments for png_data_freer */ #define PNG_DESTROY_WILL_FREE_DATA 1 @@ -2161,45 +2178,45 @@ extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr, #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */ #ifdef PNG_USER_MEM_SUPPORTED -extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr, png_alloc_size_t size)) PNG_ALLOCATED; -extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr, png_voidp ptr)); #endif #ifndef PNG_NO_ERROR_TEXT /* Fatal error in PNG image of libpng - can't continue */ -extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr, png_const_charp error_message)) PNG_NORETURN; /* The same, but the chunk name is prepended to the error string. */ -extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr, png_const_charp error_message)) PNG_NORETURN; #else /* Fatal error in PNG image of libpng - can't continue */ -extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr)) PNG_NORETURN; +PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr)) PNG_NORETURN; #endif /* Non-fatal error in libpng. Can continue, but may have a problem. */ -extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr, png_const_charp warning_message)); /* Non-fatal error in libpng, chunk name is prepended to message. */ -extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr, png_const_charp warning_message)); #ifdef PNG_BENIGN_ERRORS_SUPPORTED /* Benign error in libpng. Can continue, but may have a problem. * User can choose whether to handle as a fatal error or as a warning. */ -extern PNG_EXPORT(void,png_benign_error) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_benign_error) PNGARG((png_structp png_ptr, png_const_charp warning_message)); /* Same, chunk name is prepended to message. */ -extern PNG_EXPORT(void,png_chunk_benign_error) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_chunk_benign_error) PNGARG((png_structp png_ptr, png_const_charp warning_message)); -extern PNG_EXPORT(void,png_set_benign_errors) PNGARG((png_structp +PNG_EXPORT(void,png_set_benign_errors) PNGARG((png_structp png_ptr, int allowed)); #endif @@ -2216,109 +2233,109 @@ extern PNG_EXPORT(void,png_set_benign_errors) PNGARG((png_structp * png_info_struct. */ /* Returns "flag" if chunk data is valid in info_ptr. */ -extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr, -png_infop info_ptr, png_uint_32 flag)); +PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 flag)); /* Returns number of bytes needed to hold a transformed row. */ -extern PNG_EXPORT(png_size_t,png_get_rowbytes) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_size_t,png_get_rowbytes) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* Returns row_pointers, which is an array of pointers to scanlines that was * returned from png_read_png(). */ -extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr)); /* Set row_pointers, which is an array of pointers to scanlines for use * by png_write_png(). */ -extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)); #endif /* Returns number of color channels in image. */ -extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_EASY_ACCESS_SUPPORTED /* Returns image width in pixels. */ -extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image height in pixels. */ -extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image bit_depth. */ -extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image color_type. */ -extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image filter_type. */ -extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image interlace_type. */ -extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image compression_type. */ -extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns image resolution in pixels per meter, from pHYs chunk data. */ -extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); /* Returns pixel aspect ratio, computed from pHYs chunk data. */ #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); #endif /* Returns image x, y offset in pixels or microns, from oFFs chunk data. */ -extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp -png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp -png_ptr, png_infop info_ptr)); +PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); +PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr)); #endif /* PNG_EASY_ACCESS_SUPPORTED */ /* Returns pointer to signature string read from PNG header */ -extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_const_structp png_ptr, + png_infop info_ptr)); #ifdef PNG_bKGD_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_const_structp png_ptr, png_infop info_ptr, png_color_16p *background)); #endif #ifdef PNG_bKGD_SUPPORTED -extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_16p background)); #endif #ifdef PNG_cHRM_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr, - png_infop info_ptr, double *white_x, double *white_y, double *red_x, +PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y)); #endif #ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point +PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y, png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point *int_blue_x, png_fixed_point *int_blue_y)); @@ -2327,12 +2344,12 @@ extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr, #ifdef PNG_cHRM_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr, png_infop info_ptr, double white_x, double white_y, double red_x, double red_y, double green_x, double green_y, double blue_x, double blue_y)); #endif #ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y, png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x, @@ -2342,132 +2359,132 @@ extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr, #ifdef PNG_gAMA_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr, - png_infop info_ptr, double *file_gamma)); +PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, double *file_gamma)); #endif -extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_fixed_point *int_file_gamma)); +PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_fixed_point *int_file_gamma)); #endif #ifdef PNG_gAMA_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr, png_infop info_ptr, double file_gamma)); #endif -extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr, png_infop info_ptr, png_fixed_point int_file_gamma)); #endif #ifdef PNG_hIST_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_16p *hist)); +PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_16p *hist)); #endif #ifdef PNG_hIST_SUPPORTED -extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)); #endif -extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method)); -extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_method, int compression_method, int filter_method)); #ifdef PNG_oFFs_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, +PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)); #endif #ifdef PNG_oFFs_SUPPORTED -extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr, png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y, int unit_type)); #endif #ifdef PNG_pCAL_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, +PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params)); #endif #ifdef PNG_pCAL_SUPPORTED -extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr, png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)); #endif #ifdef PNG_pHYs_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); #endif #ifdef PNG_pHYs_SUPPORTED -extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type)); #endif -extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_colorp *palette, int *num_palette)); +PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_colorp *palette, int *num_palette)); -extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr, png_infop info_ptr, png_colorp palette, int num_palette)); #ifdef PNG_sBIT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_const_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)); #endif #ifdef PNG_sBIT_SUPPORTED -extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_color_8p sig_bit)); #endif #ifdef PNG_sRGB_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *intent)); +PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, int *intent)); #endif #ifdef PNG_sRGB_SUPPORTED -extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr, png_infop info_ptr, int intent)); -extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr, png_infop info_ptr, int intent)); #endif #ifdef PNG_iCCP_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_charpp name, int *compression_type, +PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_charpp name, int *compression_type, png_charpp profile, png_uint_32 *proflen)); /* Note to maintainer: profile should be png_bytepp */ #endif #ifdef PNG_iCCP_SUPPORTED -extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr, png_infop info_ptr, png_charp name, int compression_type, png_charp profile, png_uint_32 proflen)); /* Note to maintainer: profile should be png_bytep */ #endif #ifdef PNG_sPLT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_sPLT_tpp entries)); +PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_sPLT_tpp entries)); #endif #ifdef PNG_sPLT_SUPPORTED -extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr, png_infop info_ptr, png_sPLT_tp entries, int nentries)); #endif #ifdef PNG_TEXT_SUPPORTED /* png_get_text also returns the number of text chunks in *num_text */ -extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, - png_infop info_ptr, png_textp *text_ptr, int *num_text)); +PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_textp *text_ptr, int *num_text)); #endif /* Note while png_set_text() will accept a structure whose text, @@ -2478,28 +2495,28 @@ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr, */ #ifdef PNG_TEXT_SUPPORTED -extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, int num_text)); #endif #ifdef PNG_tIME_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)); #endif #ifdef PNG_tIME_SUPPORTED -extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr, png_infop info_ptr, png_timep mod_time)); #endif #ifdef PNG_tRNS_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr, +PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)); #endif #ifdef PNG_tRNS_SUPPORTED -extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, png_infop info_ptr, png_bytep trans_alpha, int num_trans, png_color_16p trans_color)); #endif @@ -2509,23 +2526,23 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr, #ifdef PNG_sCAL_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *unit, double *width, double *height)); +PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, int *unit, double *width, double *height)); #else #ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr, - png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); +PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight)); #endif #endif #endif /* PNG_sCAL_SUPPORTED */ #ifdef PNG_sCAL_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, png_infop info_ptr, int unit, double width, double height)); #else #ifdef PNG_FIXED_POINT_SUPPORTED -extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, +PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); #endif #endif @@ -2534,21 +2551,21 @@ extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, #ifdef PNG_APNG_SUPPORTED extern PNG_EXPORT(png_uint_32,png_get_acTL) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays)); -extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr, +extern PNG_EXPORT(png_uint_32,png_set_acTL) PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); extern PNG_EXPORT(png_uint_32,png_get_num_frames) PNGARG((png_structp png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32,png_get_num_plays) +extern PNG_EXPORT(png_uint_32,png_get_num_plays) PNGARG((png_structp png_ptr, png_infop info_ptr)); -extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL) - PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, - png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, +extern PNG_EXPORT(png_uint_32,png_get_next_frame_fcTL) + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, + png_uint_32 *height, png_uint_32 *x_offset, png_uint_32 *y_offset, png_uint_16 *delay_num, png_uint_16 *delay_den, png_byte *dispose_op, png_byte *blend_op)); -extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL) - PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, - png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, +extern PNG_EXPORT(png_uint_32,png_set_next_frame_fcTL) + PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, + png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op)); extern PNG_EXPORT(void,png_ensure_fcTL_is_valid) @@ -2594,47 +2611,47 @@ extern PNG_EXPORT(void,png_read_frame_head) PNGARG((png_structp png_ptr, = 2: keep only if safe-to-copy = 3: keep even if unsafe-to-copy */ -extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp +PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp png_ptr, int keep, png_bytep chunk_list, int num_chunks)); PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep chunk_name)); #endif #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED -extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, +PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr, png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)); -extern PNG_EXPORT(void, png_set_unknown_chunk_location) +PNG_EXPORT(void, png_set_unknown_chunk_location) PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location)); -extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp - png_ptr, png_infop info_ptr, png_unknown_chunkpp entries)); +PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_const_structp + png_ptr, png_const_infop info_ptr, png_unknown_chunkpp entries)); #endif /* Png_free_data() will turn off the "valid" flag for anything it frees. * If you need to turn it off for a chunk that your application has freed, * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */ -extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr, +PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr, png_infop info_ptr, int mask)); #ifdef PNG_INFO_IMAGE_SUPPORTED /* The "params" pointer is currently not used and is for future expansion. */ -extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr, +PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr, png_infop info_ptr, int transforms, png_voidp params)); -extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, +PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr, png_infop info_ptr, int transforms, png_voidp params)); #endif -extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp +PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_const_structp png_ptr)); +PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_const_structp png_ptr)); +PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_const_structp png_ptr)); -extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_const_structp png_ptr)); #ifdef PNG_MNG_FEATURES_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp +PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp png_ptr, png_uint_32 mng_features_permitted)); #endif @@ -2648,57 +2665,58 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp * messages before passing them to the error or warning handler. */ #ifdef PNG_ERROR_NUMBERS_SUPPORTED -extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp +PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp png_ptr, png_uint_32 strip_mode)); #endif /* Added in libpng-1.2.6 */ #ifdef PNG_SET_USER_LIMITS_SUPPORTED -extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp +PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max)); -extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp +PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_const_structp png_ptr)); -extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp +PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_const_structp png_ptr)); /* Added in libpng-1.4.0 */ -extern PNG_EXPORT(void,png_set_chunk_cache_max) PNGARG((png_structp +PNG_EXPORT(void,png_set_chunk_cache_max) PNGARG((png_structp png_ptr, png_uint_32 user_chunk_cache_max)); -extern PNG_EXPORT(png_uint_32,png_get_chunk_cache_max) - PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_uint_32,png_get_chunk_cache_max) + PNGARG((png_const_structp png_ptr)); /* Added in libpng-1.4.1 */ -extern PNG_EXPORT(void,png_set_chunk_malloc_max) PNGARG((png_structp +PNG_EXPORT(void,png_set_chunk_malloc_max) PNGARG((png_structp png_ptr, png_alloc_size_t user_chunk_cache_max)); -extern PNG_EXPORT(png_alloc_size_t,png_get_chunk_malloc_max) - PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_alloc_size_t,png_get_chunk_malloc_max) + PNGARG((png_const_structp png_ptr)); #endif #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) -PNG_EXPORT(png_uint_32,png_get_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_uint_32,png_get_pixels_per_inch) + PNGARG((png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(png_uint_32,png_get_x_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_uint_32,png_get_x_pixels_per_inch) + PNGARG((png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(png_uint_32,png_get_y_pixels_per_inch) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(png_uint_32,png_get_y_pixels_per_inch) + PNGARG((png_const_structp png_ptr, png_const_infop info_ptr)); -PNG_EXPORT(float,png_get_x_offset_inches) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(float,png_get_x_offset_inches) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr)); -PNG_EXPORT(float,png_get_y_offset_inches) PNGARG((png_structp png_ptr, -png_infop info_ptr)); +PNG_EXPORT(float,png_get_y_offset_inches) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr)); #ifdef PNG_pHYs_SUPPORTED -PNG_EXPORT(png_uint_32,png_get_pHYs_dpi) PNGARG((png_structp png_ptr, -png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)); +PNG_EXPORT(png_uint_32,png_get_pHYs_dpi) PNGARG((png_const_structp png_ptr, + png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, + int *unit_type)); #endif /* PNG_pHYs_SUPPORTED */ #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */ /* Added in libpng-1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED -extern PNG_EXPORT(png_uint_32,png_get_io_state) PNGARG((png_structp png_ptr)); +PNG_EXPORT(png_uint_32,png_get_io_state) PNGARG((png_const_structp png_ptr)); -extern PNG_EXPORT(png_bytep,png_get_io_chunk_name) +PNG_EXPORT(png_bytep,png_get_io_chunk_name) PNGARG((png_structp png_ptr)); /* The flags returned by png_get_io_state() are the following: */ @@ -2764,44 +2782,52 @@ extern PNG_EXPORT(png_bytep,png_get_io_chunk_name) * The png_get_int_32() routine assumes we are using two's complement * format for negative values, which is almost certainly true. */ -/* We could make special-case BIG_ENDIAN macros that do direct reads here */ # define png_get_uint_32(buf) \ (((png_uint_32)(*(buf)) << 24) + \ ((png_uint_32)(*((buf) + 1)) << 16) + \ ((png_uint_32)(*((buf) + 2)) << 8) + \ ((png_uint_32)(*((buf) + 3)))) + + /* The following definition introduces an API incompatibility (but not + * an ABI incompatibility) with libpng-1.4.0 through 1.4.4. Prior to + * libpng-1.4.5 the macro, which is used by default, returned (incorrectly) + * a (png_uint_32), while the function, if used instead, correctly returned + * a (png_uint_16). + * + * Libpng versions 1.0.x and 1.2.x only used a function so are not affected + * by this potential API incompatibility between macros. + */ # define png_get_uint_16(buf) \ - (((png_uint_32)(*(buf)) << 8) + \ - ((png_uint_32)(*((buf) + 1)))) -#ifdef PNG_GET_INT_32_SUPPORTED + ((png_uint_16) \ + (((unsigned int)(*(buf)) << 8) + \ + ((unsigned int)(*((buf) + 1))))) + # define png_get_int_32(buf) \ - (((png_int_32)(*(buf)) << 24) + \ - ((png_int_32)(*((buf) + 1)) << 16) + \ - ((png_int_32)(*((buf) + 2)) << 8) + \ - ((png_int_32)(*((buf) + 3)))) -#endif + ((png_int_32)((*(buf) & 0x80) \ + ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ + : (png_int_32)png_get_uint_32(buf))) #else -extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf)); -extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf)); +PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf)); +PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf)); #ifdef PNG_GET_INT_32_SUPPORTED -extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf)); +PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf)); #endif #endif -extern PNG_EXPORT(png_uint_32,png_get_uint_31) +PNG_EXPORT(png_uint_32,png_get_uint_31) PNGARG((png_structp png_ptr, png_bytep buf)); /* No png_get_int_16 -- may be added if there's a real need for it. */ /* Place a 32-bit number into a buffer in PNG byte order (big-endian). */ -extern PNG_EXPORT(void,png_save_uint_32) +PNG_EXPORT(void,png_save_uint_32) PNGARG((png_bytep buf, png_uint_32 i)); -extern PNG_EXPORT(void,png_save_int_32) +PNG_EXPORT(void,png_save_int_32) PNGARG((png_bytep buf, png_int_32 i)); /* Place a 16-bit number into a buffer in PNG byte order. * The parameter is declared unsigned int, not png_uint_16, * just to avoid potential problems on pre-ANSI C compilers. */ -extern PNG_EXPORT(void,png_save_uint_16) +PNG_EXPORT(void,png_save_uint_16) PNGARG((png_bytep buf, unsigned int i)); /* No png_save_int_16 -- may be added if there's a real need for it. */ diff --git a/modules/libimg/png/pngconf.h b/modules/libimg/png/pngconf.h index 5e7be7ae6f39..7775bff9f7fb 100644 --- a/modules/libimg/png/pngconf.h +++ b/modules/libimg/png/pngconf.h @@ -1,9 +1,9 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.4.3 - June 26, 2010 + * libpng version 1.4.7 - April 10, 2011 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -46,14 +46,14 @@ * includes the resource compiler for Windows DLL configurations. */ #ifdef PNG_USER_CONFIG +# include "pngusr.h" # ifndef PNG_USER_PRIVATEBUILD # define PNG_USER_PRIVATEBUILD # endif -# include "pngusr.h" #endif /* - * If you create a private DLL you need to define in "pngusr.h" the followings: + * If you create a private DLL you should define in "pngusr.h" the following: * #define PNG_USER_PRIVATEBUILD * e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons." @@ -61,7 +61,7 @@ * distinguish your DLL from those of the official release. These * correspond to the trailing letters that come after the version * number and must match your private DLL name> - * e.g. // private DLL "libpng13gx.dll" + * e.g. // private DLL "libpng14gx.dll" * #define PNG_USER_DLLFNAME_POSTFIX "gx" * * The following macros are also at your disposal if you want to complete the @@ -86,6 +86,18 @@ /* End of material added to libpng-1.2.8 */ +/* Added at libpng-1.4.6 */ +#ifndef PNG_UNUSED +/* Unused formal parameter warnings are silenced using the following macro + * which is expected to have no bad effects on performance (optimizing + * compilers will probably remove it entirely). Note that if you replace + * it with something other than whitespace, you must include the terminating + * semicolon. + */ +# define PNG_UNUSED(param) (void)param; +#endif +/* End of material added to libpng-1.4.6 */ + #ifndef PNG_VERSION_INFO_ONLY /* This is the size of the compression buffer, and thus the size of @@ -271,11 +283,19 @@ * #define PNG_NO_STDIO */ +#ifdef _WIN32_WCE +# define PNG_NO_CONSOLE_IO +# define PNG_NO_STDIO +# define PNG_NO_TIME_RFC1123 +# ifdef PNG_DEBUG +# undef PNG_DEBUG +# endif +#endif + #if !defined(PNG_NO_STDIO) && !defined(PNG_STDIO_SUPPORTED) # define PNG_STDIO_SUPPORTED #endif - #ifdef PNG_BUILD_DLL # if !defined(PNG_CONSOLE_IO_SUPPORTED) && !defined(PNG_NO_CONSOLE_IO) # define PNG_NO_CONSOLE_IO @@ -441,7 +461,7 @@ /* The following uses const char * instead of char * for error * and warning message functions, so some compilers won't complain. - * If you do not want to use const, define PNG_NO_CONST here. + * If you do not want to use const, define PNG_NO_CONST. */ #ifndef PNG_CONST @@ -456,8 +476,10 @@ * library that you will not be using. I wish I could figure out how to * automate this, but I can't do that without making it seriously hard * on the users. So if you are not using an ability, change the #define - * to and #undef, and that part of the library will not be compiled. If - * your linker can't find a function, you may want to make sure the + * to an #undef, or pass in PNG_NO_feature and that part of the library + * will not be compiled. + + * If your linker can't find a function, you may want to make sure the * ability is defined here. Some of these depend upon some others being * defined. I haven't figured out all the interactions here, so you may * have to experiment awhile to get everything to compile. If you are @@ -1129,7 +1151,7 @@ typedef unsigned char png_byte; #else typedef size_t png_size_t; #endif -#define png_sizeof(x) sizeof(x) +#define png_sizeof(x) (sizeof (x)) /* The following is needed for medium model support. It cannot be in the * pngpriv.h header. Needs modification for other compilers besides @@ -1251,6 +1273,13 @@ typedef char FAR * FAR * FAR * png_charppp; # define PNG_DLL #endif +/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", + * you may get warnings regarding the linkage of png_zalloc and png_zfree. + * Don't ignore those warnings; you must also reset the default calling + * convention in your compiler to match your PNGAPI, and you must build + * zlib and your applications the same way you build libpng. + */ + #ifdef __CYGWIN__ # undef PNGAPI # define PNGAPI __cdecl @@ -1258,14 +1287,11 @@ typedef char FAR * FAR * FAR * png_charppp; # define PNG_IMPEXP #endif -#define PNG_USE_LOCAL_ARRAYS /* Not used in libpng, defined for legacy apps */ - -/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall", - * you may get warnings regarding the linkage of png_zalloc and png_zfree. - * Don't ignore those warnings; you must also reset the default calling - * convention in your compiler to match your PNGAPI, and you must build - * zlib and your applications the same way you build libpng. - */ +#ifdef __WATCOMC__ +# ifndef PNGAPI +# define PNGAPI +# endif +#endif #if defined(__MINGW32__) && !defined(PNG_MODULEDEF) # ifndef PNG_NO_MODULEDEF @@ -1350,6 +1376,8 @@ typedef char FAR * FAR * FAR * png_charppp; # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol #endif +#define PNG_USE_LOCAL_ARRAYS /* Not used in libpng, defined for legacy apps */ + /* Support for compiler specific function attributes. These are used * so that where compiler support is available incorrect use of API * functions in png.h will generate compiler warnings. @@ -1378,15 +1406,15 @@ typedef char FAR * FAR * FAR * png_charppp; # endif # ifndef PNG_ALLOCATED # define PNG_ALLOCATED __attribute__((__malloc__)) +# endif +# ifndef PNG_DEPRECATED +# define PNG_DEPRECATED __attribute__((__deprecated__)) # endif /* This specifically protects structure members that should only be * accessed from within the library, therefore should be empty during * a library build. */ -# ifndef PNG_DEPRECATED -# define PNG_DEPRECATED __attribute__((__deprecated__)) -# endif # ifndef PNG_DEPSTRUCT # define PNG_DEPSTRUCT __attribute__((__deprecated__)) # endif @@ -1427,7 +1455,7 @@ typedef char FAR * FAR * FAR * png_charppp; /* memory model/platform independent fns */ #ifndef PNG_ABORT -# ifdef _WINDOWS_ +# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) # define PNG_ABORT() ExitProcess(0) # else # define PNG_ABORT() abort() @@ -1448,7 +1476,8 @@ typedef char FAR * FAR * FAR * png_charppp; # define png_memset _fmemset # define png_sprintf sprintf #else -# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */ +# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) +# /* Favor Windows over C runtime fns */ # define CVT_PTR(ptr) (ptr) # define CVT_PTR_NOCHECK(ptr) (ptr) # define png_strcpy lstrcpyA @@ -1468,31 +1497,32 @@ typedef char FAR * FAR * FAR * png_charppp; # define png_memcpy memcpy # define png_memset memset # define png_sprintf sprintf -# ifndef PNG_NO_SNPRINTF -# ifdef _MSC_VER -# define png_snprintf _snprintf /* Added to v 1.2.19 */ -# define png_snprintf2 _snprintf -# define png_snprintf6 _snprintf -# else -# define png_snprintf snprintf /* Added to v 1.2.19 */ -# define png_snprintf2 snprintf -# define png_snprintf6 snprintf -# endif -# else - /* You don't have or don't want to use snprintf(). Caution: Using - * sprintf instead of snprintf exposes your application to accidental - * or malevolent buffer overflows. If you don't have snprintf() - * as a general rule you should provide one (you can get one from - * Portable OpenSSH). - */ -# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1) -# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2) -# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ - sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) -# endif # endif #endif +#ifndef PNG_NO_SNPRINTF +# ifdef _MSC_VER +# define png_snprintf _snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 _snprintf +# define png_snprintf6 _snprintf +# else +# define png_snprintf snprintf /* Added to v 1.2.19 */ +# define png_snprintf2 snprintf +# define png_snprintf6 snprintf +# endif +#else + /* You don't have or don't want to use snprintf(). Caution: Using + * sprintf instead of snprintf exposes your application to accidental + * or malevolent buffer overflows. If you don't have snprintf() + * as a general rule you should provide one (you can get one from + * Portable OpenSSH). + */ +# define png_snprintf(s1,n,fmt,x1) png_sprintf(s1,fmt,x1) +# define png_snprintf2(s1,n,fmt,x1,x2) png_sprintf(s1,fmt,x1,x2) +# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \ + png_sprintf(s1,fmt,x1,x2,x3,x4,x5,x6) +#endif + /* png_alloc_size_t is guaranteed to be no smaller than png_size_t, * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32 * to png_alloc_size_t are not necessary; in fact, it is recommended @@ -1503,22 +1533,19 @@ typedef char FAR * FAR * FAR * png_charppp; * to encounter practical situations that require such conversions. */ #if defined(__TURBOC__) && !defined(__FLAT__) -# define png_mem_alloc farmalloc -# define png_mem_free farfree typedef unsigned long png_alloc_size_t; #else # if defined(_MSC_VER) && defined(MAXSEG_64K) -# define png_mem_alloc(s) halloc(s, 1) -# define png_mem_free hfree typedef unsigned long png_alloc_size_t; # else -# if defined(_WINDOWS_) && (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) -# define png_mem_alloc(s) HeapAlloc(GetProcessHeap(), 0, s) -# define png_mem_free(p) HeapFree(GetProcessHeap(), 0, p) - typedef DWORD png_alloc_size_t; + /* This is an attempt to detect an old Windows system where (int) is + * actually 16 bits, in that case png_malloc must have an argument with a + * bigger size to accomodate the requirements of the library. + */ +# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \ + (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL) + typedef DWORD png_alloc_size_t; # else -# define png_mem_alloc malloc -# define png_mem_free free typedef png_size_t png_alloc_size_t; # endif # endif diff --git a/modules/libimg/png/pngerror.c b/modules/libimg/png/pngerror.c index 633eae29f9eb..c196b11ce049 100644 --- a/modules/libimg/png/pngerror.c +++ b/modules/libimg/png/pngerror.c @@ -1,8 +1,8 @@ /* pngerror.c - stub functions for i/o and memory allocation * - * Last changed in libpng 1.4.0 [January 3, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -306,7 +306,7 @@ png_default_error(png_structp png_ptr, png_const_charp error_message) /* Here if not setjmp support or if png_ptr is null. */ PNG_ABORT(); #ifndef PNG_CONSOLE_IO_SUPPORTED - error_message = error_message; /* Make compiler happy */ + PNG_UNUSED(error_message) /* Make compiler happy */ #endif } @@ -352,9 +352,9 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message) fprintf(stderr, PNG_STRING_NEWLINE); } #else - warning_message = warning_message; /* Make compiler happy */ + PNG_UNUSED(warning_message) /* Make compiler happy */ #endif - png_ptr = png_ptr; /* Make compiler happy */ + PNG_UNUSED(png_ptr) /* Make compiler happy */ } #endif /* PNG_WARNINGS_SUPPORTED */ @@ -380,7 +380,7 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_error_ptr(png_structp png_ptr) +png_get_error_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return NULL; diff --git a/modules/libimg/png/pngget.c b/modules/libimg/png/pngget.c index 32d4e4a7248e..6af81a8e6c84 100644 --- a/modules/libimg/png/pngget.c +++ b/modules/libimg/png/pngget.c @@ -1,8 +1,8 @@ /* pngget.c - retrieval of values from info struct * - * Last changed in libpng 1.4.2 [May 6, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [April 10, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -18,7 +18,8 @@ #include "pngpriv.h" png_uint_32 PNGAPI -png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) +png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_32 flag) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->valid & flag); @@ -28,7 +29,7 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) } png_size_t PNGAPI -png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) +png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->rowbytes); @@ -39,7 +40,7 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_INFO_IMAGE_SUPPORTED png_bytepp PNGAPI -png_get_rows(png_structp png_ptr, png_infop info_ptr) +png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->row_pointers); @@ -52,7 +53,7 @@ png_get_rows(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_EASY_ACCESS_SUPPORTED /* Easy access to info, added in libpng-0.99 */ png_uint_32 PNGAPI -png_get_image_width(png_structp png_ptr, png_infop info_ptr) +png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->width; @@ -61,7 +62,7 @@ png_get_image_width(png_structp png_ptr, png_infop info_ptr) } png_uint_32 PNGAPI -png_get_image_height(png_structp png_ptr, png_infop info_ptr) +png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->height; @@ -70,7 +71,7 @@ png_get_image_height(png_structp png_ptr, png_infop info_ptr) } png_byte PNGAPI -png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) +png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->bit_depth; @@ -79,7 +80,7 @@ png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) } png_byte PNGAPI -png_get_color_type(png_structp png_ptr, png_infop info_ptr) +png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->color_type; @@ -88,7 +89,7 @@ png_get_color_type(png_structp png_ptr, png_infop info_ptr) } png_byte PNGAPI -png_get_filter_type(png_structp png_ptr, png_infop info_ptr) +png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->filter_type; @@ -97,7 +98,7 @@ png_get_filter_type(png_structp png_ptr, png_infop info_ptr) } png_byte PNGAPI -png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) +png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->interlace_type; @@ -106,7 +107,7 @@ png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) } png_byte PNGAPI -png_get_compression_type(png_structp png_ptr, png_infop info_ptr) +png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return info_ptr->compression_type; @@ -115,7 +116,7 @@ png_get_compression_type(png_structp png_ptr, png_infop info_ptr) } png_uint_32 PNGAPI -png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) #ifdef PNG_pHYs_SUPPORTED @@ -136,7 +137,7 @@ png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) } png_uint_32 PNGAPI -png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) #ifdef PNG_pHYs_SUPPORTED @@ -157,7 +158,7 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) } png_uint_32 PNGAPI -png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) +png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) #ifdef PNG_pHYs_SUPPORTED @@ -180,7 +181,7 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_FLOATING_POINT_SUPPORTED float PNGAPI -png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) +png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) #ifdef PNG_pHYs_SUPPORTED @@ -204,7 +205,7 @@ png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) #endif png_int_32 PNGAPI -png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) #ifdef PNG_oFFs_SUPPORTED @@ -226,7 +227,7 @@ png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) } png_int_32 PNGAPI -png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) @@ -248,7 +249,7 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) } png_int_32 PNGAPI -png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) @@ -270,7 +271,7 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) } png_int_32 PNGAPI -png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) @@ -293,35 +294,35 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) png_uint_32 PNGAPI -png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) *.0254 +.5)); } png_uint_32 PNGAPI -png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) *.0254 +.5)); } png_uint_32 PNGAPI -png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) +png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr) { return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) *.0254 +.5)); } float PNGAPI -png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) +png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) { return ((float)png_get_x_offset_microns(png_ptr, info_ptr) *.00003937); } float PNGAPI -png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) +png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr) { return ((float)png_get_y_offset_microns(png_ptr, info_ptr) *.00003937); @@ -329,7 +330,7 @@ png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, +png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; @@ -369,7 +370,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, #endif /* PNG_EASY_ACCESS_SUPPORTED */ png_byte PNGAPI -png_get_channels(png_structp png_ptr, png_infop info_ptr) +png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->channels); @@ -378,7 +379,7 @@ png_get_channels(png_structp png_ptr, png_infop info_ptr) } png_bytep PNGAPI -png_get_signature(png_structp png_ptr, png_infop info_ptr) +png_get_signature(png_const_structp png_ptr, png_infop info_ptr) { if (png_ptr != NULL && info_ptr != NULL) return(info_ptr->signature); @@ -388,7 +389,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr) #ifdef PNG_bKGD_SUPPORTED png_uint_32 PNGAPI -png_get_bKGD(png_structp png_ptr, png_infop info_ptr, +png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr, png_color_16p *background) { if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) @@ -406,7 +407,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_cHRM_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM(png_structp png_ptr, png_infop info_ptr, +png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr, double *white_x, double *white_y, double *red_x, double *red_y, double *green_x, double *green_y, double *blue_x, double *blue_y) { @@ -437,7 +438,7 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr, #endif #ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, +png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *blue_x, png_fixed_point *blue_y) @@ -472,7 +473,7 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_gAMA_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) +png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr, double *file_gamma) { png_debug1(1, "in %s retrieval function", "gAMA"); @@ -487,7 +488,7 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) #endif #ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, +png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr, png_fixed_point *int_file_gamma) { png_debug1(1, "in %s retrieval function", "gAMA"); @@ -505,7 +506,8 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sRGB_SUPPORTED png_uint_32 PNGAPI -png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) +png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr, + int *file_srgb_intent) { png_debug1(1, "in %s retrieval function", "sRGB"); @@ -521,7 +523,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) #ifdef PNG_iCCP_SUPPORTED png_uint_32 PNGAPI -png_get_iCCP(png_structp png_ptr, png_infop info_ptr, +png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr, png_charpp name, int *compression_type, png_charpp profile, png_uint_32 *proflen) { @@ -545,7 +547,7 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sPLT_SUPPORTED png_uint_32 PNGAPI -png_get_sPLT(png_structp png_ptr, png_infop info_ptr, +png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr, png_sPLT_tpp spalettes) { if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) @@ -559,7 +561,8 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_hIST_SUPPORTED png_uint_32 PNGAPI -png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) +png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr, + png_uint_16p *hist) { png_debug1(1, "in %s retrieval function", "hIST"); @@ -614,7 +617,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_oFFs_SUPPORTED png_uint_32 PNGAPI -png_get_oFFs(png_structp png_ptr, png_infop info_ptr, +png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) { png_debug1(1, "in %s retrieval function", "oFFs"); @@ -633,7 +636,7 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_pCAL_SUPPORTED png_uint_32 PNGAPI -png_get_pCAL(png_structp png_ptr, png_infop info_ptr, +png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *units, png_charpp *params) { @@ -659,7 +662,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_sCAL_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_sCAL(png_structp png_ptr, png_infop info_ptr, +png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr, int *unit, double *width, double *height) { if (png_ptr != NULL && info_ptr != NULL && @@ -675,7 +678,7 @@ png_get_sCAL(png_structp png_ptr, png_infop info_ptr, #else #ifdef PNG_FIXED_POINT_SUPPORTED png_uint_32 PNGAPI -png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, +png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr, int *unit, png_charpp width, png_charpp height) { if (png_ptr != NULL && info_ptr != NULL && @@ -694,7 +697,7 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_pHYs_SUPPORTED png_uint_32 PNGAPI -png_get_pHYs(png_structp png_ptr, png_infop info_ptr, +png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) { png_uint_32 retval = 0; @@ -727,7 +730,8 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr, #endif png_uint_32 PNGAPI -png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, +png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr, + png_colorp *palette, int *num_palette) { png_debug1(1, "in %s retrieval function", "PLTE"); @@ -745,7 +749,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, #ifdef PNG_sBIT_SUPPORTED png_uint_32 PNGAPI -png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) +png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr, + png_color_8p *sig_bit) { png_debug1(1, "in %s retrieval function", "sBIT"); @@ -761,8 +766,8 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) #ifdef PNG_TEXT_SUPPORTED png_uint_32 PNGAPI -png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, - int *num_text) +png_get_text(png_const_structp png_ptr, png_const_infop info_ptr, + png_textp *text_ptr, int *num_text) { if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0) { @@ -786,7 +791,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, #ifdef PNG_tIME_SUPPORTED png_uint_32 PNGAPI -png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) +png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, + png_timep *mod_time) { png_debug1(1, "in %s retrieval function", "tIME"); @@ -802,7 +808,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) #ifdef PNG_tRNS_SUPPORTED png_uint_32 PNGAPI -png_get_tRNS(png_structp png_ptr, png_infop info_ptr, +png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color) { png_uint_32 retval = 0; @@ -848,7 +854,7 @@ png_get_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 *num_frames, png_uint_32 *num_plays) { png_debug1(1, "in %s retrieval function", "acTL"); - + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_acTL) && num_frames != NULL && num_plays != NULL) @@ -857,7 +863,7 @@ png_get_acTL(png_structp png_ptr, png_infop info_ptr, *num_plays = info_ptr->num_plays; return (1); } - + return (0); } @@ -865,7 +871,7 @@ png_uint_32 PNGAPI png_get_num_frames(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_num_frames()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->num_frames); return (0); @@ -875,7 +881,7 @@ png_uint_32 PNGAPI png_get_num_plays(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_num_plays()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->num_plays); return (0); @@ -889,11 +895,11 @@ png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, png_byte *dispose_op, png_byte *blend_op) { png_debug1(1, "in %s retrieval function", "fcTL"); - + if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_fcTL) && - width != NULL && height != NULL && - x_offset != NULL && x_offset != NULL && + width != NULL && height != NULL && + x_offset != NULL && x_offset != NULL && delay_num != NULL && delay_den != NULL && dispose_op != NULL && blend_op != NULL) { @@ -907,7 +913,7 @@ png_get_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, *blend_op = info_ptr->next_frame_blend_op; return (1); } - + return (0); } @@ -915,7 +921,7 @@ png_uint_32 PNGAPI png_get_next_frame_width(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_width()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_width); return (0); @@ -925,7 +931,7 @@ png_uint_32 PNGAPI png_get_next_frame_height(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_height()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_height); return (0); @@ -935,7 +941,7 @@ png_uint_32 PNGAPI png_get_next_frame_x_offset(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_x_offset()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_x_offset); return (0); @@ -945,7 +951,7 @@ png_uint_32 PNGAPI png_get_next_frame_y_offset(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_y_offset()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_y_offset); return (0); @@ -955,7 +961,7 @@ png_uint_16 PNGAPI png_get_next_frame_delay_num(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_delay_num()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_delay_num); return (0); @@ -965,7 +971,7 @@ png_uint_16 PNGAPI png_get_next_frame_delay_den(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_delay_den()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_delay_den); return (0); @@ -975,7 +981,7 @@ png_byte PNGAPI png_get_next_frame_dispose_op(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_dispose_op()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_dispose_op); return (0); @@ -985,7 +991,7 @@ png_byte PNGAPI png_get_next_frame_blend_op(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_get_next_frame_blend_op()"); - + if (png_ptr != NULL && info_ptr != NULL) return (info_ptr->next_frame_blend_op); return (0); @@ -995,16 +1001,17 @@ png_byte PNGAPI png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_first_frame_is_hidden()"); - + if (png_ptr != NULL) return (png_byte)(png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN); - + return 0; } #endif /* PNG_APNG_SUPPORTED */ + #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED png_uint_32 PNGAPI -png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, +png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr, png_unknown_chunkpp unknowns) { if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL) @@ -1018,7 +1025,7 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED png_byte PNGAPI -png_get_rgb_to_gray_status (png_structp png_ptr) +png_get_rgb_to_gray_status(png_const_structp png_ptr) { return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0); } @@ -1026,14 +1033,14 @@ png_get_rgb_to_gray_status (png_structp png_ptr) #ifdef PNG_USER_CHUNKS_SUPPORTED png_voidp PNGAPI -png_get_user_chunk_ptr(png_structp png_ptr) +png_get_user_chunk_ptr(png_const_structp png_ptr) { return (png_ptr? png_ptr->user_chunk_ptr : NULL); } #endif png_size_t PNGAPI -png_get_compression_buffer_size(png_structp png_ptr) +png_get_compression_buffer_size(png_const_structp png_ptr) { return (png_ptr ? png_ptr->zbuf_size : 0L); } @@ -1043,25 +1050,24 @@ png_get_compression_buffer_size(png_structp png_ptr) /* These functions were added to libpng 1.2.6 and were enabled * by default in libpng-1.4.0 */ png_uint_32 PNGAPI -png_get_user_width_max (png_structp png_ptr) +png_get_user_width_max(png_const_structp png_ptr) { return (png_ptr? png_ptr->user_width_max : 0); } png_uint_32 PNGAPI -png_get_user_height_max (png_structp png_ptr) +png_get_user_height_max(png_const_structp png_ptr) { return (png_ptr? png_ptr->user_height_max : 0); } - /* This function was added to libpng 1.4.0 */ png_uint_32 PNGAPI -png_get_chunk_cache_max (png_structp png_ptr) +png_get_chunk_cache_max(png_const_structp png_ptr) { return (png_ptr? png_ptr->user_chunk_cache_max : 0); } /* This function was added to libpng 1.4.1 */ png_alloc_size_t PNGAPI -png_get_chunk_malloc_max (png_structp png_ptr) +png_get_chunk_malloc_max(png_const_structp png_ptr) { return (png_ptr? png_ptr->user_chunk_malloc_max : 0); @@ -1071,13 +1077,13 @@ png_get_chunk_malloc_max (png_structp png_ptr) /* These functions were added to libpng 1.4.0 */ #ifdef PNG_IO_STATE_SUPPORTED png_uint_32 PNGAPI -png_get_io_state (png_structp png_ptr) +png_get_io_state(png_const_structp png_ptr) { return png_ptr->io_state; } png_bytep PNGAPI -png_get_io_chunk_name (png_structp png_ptr) +png_get_io_chunk_name(png_structp png_ptr) { return png_ptr->chunk_name; } diff --git a/modules/libimg/png/pngmem.c b/modules/libimg/png/pngmem.c index c8a3f6f59af1..911f36881ca6 100644 --- a/modules/libimg/png/pngmem.c +++ b/modules/libimg/png/pngmem.c @@ -1,8 +1,8 @@ /* pngmem.c - stub functions for memory allocation * - * Last changed in libpng 1.4.2 [May 6, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [April 10, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -601,7 +601,7 @@ png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr * pointer before png_write_destroy and png_read_destroy are called. */ png_voidp PNGAPI -png_get_mem_ptr(png_structp png_ptr) +png_get_mem_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); diff --git a/modules/libimg/png/pngpread.c b/modules/libimg/png/pngpread.c index 4af9b96b1b0a..391d75392e00 100644 --- a/modules/libimg/png/pngpread.c +++ b/modules/libimg/png/pngpread.c @@ -1,8 +1,8 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.4.3 [June 26, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -234,9 +234,9 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_check_chunk_name(png_ptr, png_ptr->chunk_name); png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; } - + #ifdef PNG_READ_APNG_SUPPORTED - if (png_ptr->num_frames_read > 0 && + if (png_ptr->num_frames_read > 0 && png_ptr->num_frames_read < info_ptr->num_frames) { if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) @@ -244,7 +244,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) /* Discard trailing IDATs for the first frame */ if (png_ptr->mode & PNG_HAVE_fcTL || png_ptr->num_frames_read > 1) png_error(png_ptr, "out of place IDAT"); - + if (png_ptr->push_length + 4 > png_ptr->buffer_size) { png_push_save_buffer(png_ptr); @@ -262,13 +262,13 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) return; } png_ensure_sequence_number(png_ptr, 4); - + if (!(png_ptr->mode & PNG_HAVE_fcTL)) { /* Discard trailing fdATs for frames other than the first */ if (png_ptr->num_frames_read < 2) png_error(png_ptr, "out of place fdAT"); - + if (png_ptr->push_length + 4 > png_ptr->buffer_size) { png_push_save_buffer(png_ptr); @@ -284,7 +284,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_ptr->idat_size = png_ptr->push_length - 4; png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->process_mode = PNG_READ_IDAT_MODE; - + return; } } @@ -295,23 +295,23 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - + png_read_reset(png_ptr); png_ptr->mode &= ~PNG_HAVE_fcTL; - + png_handle_fcTL(png_ptr, info_ptr, png_ptr->push_length); - + if (!(png_ptr->mode & PNG_HAVE_fcTL)) png_error(png_ptr, "missing required fcTL chunk"); - + png_read_reinit(png_ptr, info_ptr); png_progressive_read_reset(png_ptr); - + if (png_ptr->frame_info_fn != NULL) (*(png_ptr->frame_info_fn))(png_ptr, png_ptr->num_frames_read); - + png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; - + return; } else @@ -327,11 +327,11 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; return; } - + return; } #endif /* PNG_READ_APNG_SUPPORTED */ - + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (png_ptr->mode & PNG_AFTER_IDAT) png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; @@ -921,7 +921,7 @@ png_push_read_IDAT(png_structp png_ptr) return; } } - else + else #endif #ifdef PNG_READ_APNG_SUPPORTED if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4) @@ -942,7 +942,7 @@ png_push_read_IDAT(png_structp png_ptr) } png_ptr->idat_size = png_ptr->push_length; - + #ifdef PNG_READ_APNG_SUPPORTED if (png_ptr->num_frames_read > 0) { @@ -1032,7 +1032,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, * or the stream marked as finished. */ while (png_ptr->zstream.avail_in > 0 && - !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) + !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED)) { int ret; @@ -1061,49 +1061,49 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, /* Check for any failure before proceeding. */ if (ret != Z_OK && ret != Z_STREAM_END) { - /* Terminate the decompression. */ - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + /* Terminate the decompression. */ + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; /* This may be a truncated stream (missing or - * damaged end code). Treat that as a warning. - */ + * damaged end code). Treat that as a warning. + */ if (png_ptr->row_number >= png_ptr->num_rows || - png_ptr->pass > 6) - png_warning(png_ptr, "Truncated compressed data in IDAT"); - else - png_error(png_ptr, "Decompression error in IDAT"); + png_ptr->pass > 6) + png_warning(png_ptr, "Truncated compressed data in IDAT"); + else + png_error(png_ptr, "Decompression error in IDAT"); - /* Skip the check on unprocessed input */ + /* Skip the check on unprocessed input */ return; } /* Did inflate output any data? */ if (png_ptr->zstream.next_out != png_ptr->row_buf) { - /* Is this unexpected data after the last row? - * If it is, artificially terminate the LZ output - * here. - */ + /* Is this unexpected data after the last row? + * If it is, artificially terminate the LZ output + * here. + */ if (png_ptr->row_number >= png_ptr->num_rows || - png_ptr->pass > 6) + png_ptr->pass > 6) { - /* Extra data. */ - png_warning(png_ptr, "Extra compressed data in IDAT"); + /* Extra data. */ + png_warning(png_ptr, "Extra compressed data in IDAT"); png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; - /* Do no more processing; skip the unprocessed - * input check below. - */ + /* Do no more processing; skip the unprocessed + * input check below. + */ return; - } + } - /* Do we have a complete row? */ - if (png_ptr->zstream.avail_out == 0) - png_push_process_row(png_ptr); + /* Do we have a complete row? */ + if (png_ptr->zstream.avail_out == 0) + png_push_process_row(png_ptr); } /* And check for the end of the stream. */ if (ret == Z_STREAM_END) - png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; + png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; } /* All the data should have been processed, if anything @@ -1177,7 +1177,7 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->pass == 6 && png_ptr->height <= 4) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } @@ -1217,7 +1217,7 @@ png_push_process_row(png_structp png_ptr) for (i = 0; i < 4 && png_ptr->pass == 2; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } @@ -1267,13 +1267,13 @@ png_push_process_row(png_structp png_ptr) for (i = 0; i < 2 && png_ptr->pass == 4; i++) { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } if (png_ptr->pass == 6) /* Pass 5 might be empty */ { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } @@ -1292,12 +1292,14 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->pass == 6) /* Skip top generated row */ { - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } break; } + + default: case 6: { png_push_have_row(png_ptr, png_ptr->row_buf + 1); @@ -1306,7 +1308,7 @@ png_push_process_row(png_structp png_ptr) if (png_ptr->pass != 6) break; - png_push_have_row(png_ptr, NULL); + png_push_have_row(png_ptr, NULL); png_read_push_finish_row(png_ptr); } } @@ -1391,7 +1393,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { png_error(png_ptr, "Out of place tEXt"); - info_ptr = info_ptr; /* To quiet some compiler warnings */ + PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ } #ifdef PNG_MAX_MALLOC_64K @@ -1489,7 +1491,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { png_error(png_ptr, "Out of place zTXt"); - info_ptr = info_ptr; /* To quiet some compiler warnings */ + PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ } #ifdef PNG_MAX_MALLOC_64K @@ -1690,7 +1692,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND)) { png_error(png_ptr, "Out of place iTXt"); - info_ptr = info_ptr; /* To quiet some compiler warnings */ + PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ } #ifdef PNG_MAX_MALLOC_64K @@ -1817,15 +1819,14 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 { #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != - PNG_HANDLE_CHUNK_ALWAYS + PNG_HANDLE_CHUNK_ALWAYS #ifdef PNG_READ_USER_CHUNKS_SUPPORTED - && png_ptr->read_user_chunk_fn == NULL + && png_ptr->read_user_chunk_fn == NULL #endif - ) + ) #endif png_chunk_error(png_ptr, "unknown critical chunk"); - - info_ptr = info_ptr; /* To quiet some compiler warnings */ + PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */ } #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED @@ -1915,7 +1916,7 @@ png_push_have_row(png_structp png_ptr, png_bytep row) } void PNGAPI -png_progressive_combine_row (png_structp png_ptr, +png_progressive_combine_row(png_structp png_ptr, png_bytep old_row, png_bytep new_row) { PNG_CONST int FARDATA png_pass_dsp_mask[7] = @@ -1955,7 +1956,7 @@ png_set_progressive_frame_fn(png_structp png_ptr, #endif png_voidp PNGAPI -png_get_progressive_ptr(png_structp png_ptr) +png_get_progressive_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); diff --git a/modules/libimg/png/pngpriv.h b/modules/libimg/png/pngpriv.h index e73f1088e722..3406469a17c7 100644 --- a/modules/libimg/png/pngpriv.h +++ b/modules/libimg/png/pngpriv.h @@ -1,9 +1,9 @@ /* pngpriv.h - private declarations for use inside libpng * - * libpng version 1.4.3 - June 26, 2010 + * libpng version 1.4.7 - April 10, 2011 * For conditions of distribution and use, see copyright notice in png.h - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -28,14 +28,16 @@ #include +#ifndef PNG_EXTERN /* The functions exported by PNG_EXTERN are internal functions, which * aren't usually used outside the library (as far as I know), so it is * debatable if they should be exported at all. In the future, when it * is possible to have run-time registry of chunk-handling functions, * some of these will be made available again. -#define PNG_EXTERN extern +# define PNG_EXTERN extern */ -#define PNG_EXTERN +# define PNG_EXTERN +#endif /* Other defines specific to compilers can go here. Try to keep * them inside an appropriate ifdef/endif pair for portability. @@ -75,10 +77,6 @@ #if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \ defined(_WIN32) || defined(__WIN32__) # include /* defines _WINDOWS_ macro */ -/* I have no idea why is this necessary... */ -# ifdef _MSC_VER -# include -# endif #endif /* Various modes of operation. Note that after an init, mode is set to @@ -301,6 +299,9 @@ PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr)); PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data, png_size_t length)); +/* Read and check the PNG file signature */ +PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr)); + /* Read the chunk header (length + type name) */ PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr)); @@ -481,9 +482,9 @@ PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr, PNG_EXTERN void png_write_acTL PNGARG((png_structp png_ptr, png_uint_32 num_frames, png_uint_32 num_plays)); -PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr, - png_uint_32 width, png_uint_32 height, - png_uint_32 x_offset, png_uint_32 y_offset, +PNG_EXTERN void png_write_fcTL PNGARG((png_structp png_ptr, + png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op)); #endif @@ -550,7 +551,7 @@ PNG_EXTERN void png_progressive_read_reset PNGARG((png_structp png_ptr)); #ifdef PNG_WRITE_APNG_SUPPORTED /* Private, reset some things to become ready for writing next frame */ PNG_EXTERN void png_write_reset PNGARG((png_structp png_ptr)); -PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr, +PNG_EXTERN void png_write_reinit PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height)); #endif @@ -706,7 +707,7 @@ PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr, #endif #ifdef PNG_READ_iCCP_SUPPORTED -extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, +PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif /* PNG_READ_iCCP_SUPPORTED */ @@ -741,7 +742,7 @@ PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr, #endif #ifdef PNG_READ_sPLT_SUPPORTED -extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, +PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); #endif /* PNG_READ_sPLT_SUPPORTED */ @@ -778,7 +779,7 @@ PNG_EXTERN void png_handle_fcTL PNGARG((png_structp png_ptr, png_infop info_ptr, PNG_EXTERN void png_have_info PNGARG((png_structp png_ptr, png_infop info_ptr)); PNG_EXTERN void png_handle_fdAT PNGARG((png_structp png_ptr, png_infop info_ptr, png_uint_32 length)); -PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr, +PNG_EXTERN void png_ensure_sequence_number PNGARG((png_structp png_ptr, png_uint_32 length)); #endif @@ -874,14 +875,14 @@ PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr, int filter_type)); /* Free all memory used by the read (old method - NOT DLL EXPORTED) */ -extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr, +PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)); /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ -extern void png_write_destroy PNGARG((png_structp png_ptr)); +PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); #ifdef USE_FAR_KEYWORD /* memory model conversion function */ -extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, +PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr, int check)); #endif /* USE_FAR_KEYWORD */ diff --git a/modules/libimg/png/pngread.c b/modules/libimg/png/pngread.c index f614f7f7c32b..2f20550abd2f 100644 --- a/modules/libimg/png/pngread.c +++ b/modules/libimg/png/pngread.c @@ -1,8 +1,8 @@ /* pngread.c - read a PNG file * - * Last changed in libpng 1.4.1 [February 25, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -214,34 +214,12 @@ void PNGAPI png_read_info(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_read_info"); - + if (png_ptr == NULL || info_ptr == NULL) return; - - /* If we haven't checked all of the PNG signature bytes, do so now. */ - if (png_ptr->sig_bytes < 8) - { - png_size_t num_checked = png_ptr->sig_bytes, - num_to_check = 8 - num_checked; -#ifdef PNG_IO_STATE_SUPPORTED - png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; -#endif - - png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); - png_ptr->sig_bytes = 8; - - if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) - { - if (num_checked < 4 && - png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) - png_error(png_ptr, "Not a PNG file"); - else - png_error(png_ptr, "PNG file corrupted by ASCII conversion"); - } - if (num_checked < 3) - png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; - } + /* Read and check the PNG file signature. */ + png_read_sig(png_ptr, info_ptr); for (;;) { @@ -442,22 +420,22 @@ void PNGAPI png_read_frame_head(png_structp png_ptr, png_infop info_ptr) { png_byte have_chunk_after_DAT; /* after IDAT or after fdAT */ - + png_debug(0, "Reading frame head"); - + if (!(png_ptr->mode & PNG_HAVE_acTL)) png_error(png_ptr, "attempt to png_read_frame_head() but " "no acTL present"); - + /* do nothing for the main IDAT */ if (png_ptr->num_frames_read == 0) return; - + png_crc_finish(png_ptr, 0); /* CRC from last IDAT or fdAT chunk */ - + png_read_reset(png_ptr); png_ptr->mode &= ~PNG_HAVE_fcTL; - + have_chunk_after_DAT = 0; for (;;) { @@ -466,13 +444,13 @@ png_read_frame_head(png_structp png_ptr, png_infop info_ptr) PNG_fcTL; png_byte chunk_length[4]; png_uint_32 length; - + png_read_data(png_ptr, chunk_length, 4); length = png_get_uint_31(png_ptr, chunk_length); - + png_reset_crc(png_ptr); png_crc_read(png_ptr, png_ptr->chunk_name, 4); - + if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) { /* discard trailing IDATs for the first frame */ @@ -488,7 +466,7 @@ png_read_frame_head(png_structp png_ptr, png_infop info_ptr) else if (!png_memcmp(png_ptr->chunk_name, png_fdAT, 4)) { png_ensure_sequence_number(png_ptr, length); - + /* discard trailing fdATs for frames other than the first */ if (!have_chunk_after_DAT && png_ptr->num_frames_read > 1) png_crc_finish(png_ptr, length - 4); @@ -496,7 +474,7 @@ png_read_frame_head(png_structp png_ptr, png_infop info_ptr) { png_ptr->idat_size = length - 4; png_ptr->mode |= PNG_HAVE_IDAT; - + break; } else @@ -517,7 +495,7 @@ void PNGAPI png_read_update_info(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_read_update_info"); - + if (png_ptr == NULL) return; if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) @@ -539,7 +517,7 @@ void PNGAPI png_start_read_image(png_structp png_ptr) { png_debug(1, "in png_start_read_image"); - + if (png_ptr == NULL) return; if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) @@ -556,14 +534,16 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) PNG_fdAT; PNG_IEND; #endif +#ifdef PNG_READ_INTERLACING_SUPPORTED PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; int ret; - +#endif + if (png_ptr == NULL) return; - + png_debug2(1, "in png_read_row (row %lu, pass %d)", (unsigned long) png_ptr->row_number, png_ptr->pass); @@ -619,6 +599,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + case 1: if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) { @@ -629,6 +610,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + case 2: if ((png_ptr->row_number & 0x07) != 4) { @@ -639,6 +621,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + case 3: if ((png_ptr->row_number & 3) || png_ptr->width < 3) { @@ -649,6 +632,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + case 4: if ((png_ptr->row_number & 3) != 2) { @@ -659,6 +643,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + case 5: if ((png_ptr->row_number & 1) || png_ptr->width < 2) { @@ -669,6 +654,8 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) return; } break; + + default: case 6: if (!(png_ptr->row_number & 1)) { @@ -822,7 +809,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row, png_bytepp dp; png_debug(1, "in png_read_rows"); - + if (png_ptr == NULL) return; rp = row; @@ -873,7 +860,7 @@ png_read_image(png_structp png_ptr, png_bytepp image) png_bytepp rp; png_debug(1, "in png_read_image"); - + if (png_ptr == NULL) return; @@ -911,7 +898,7 @@ void PNGAPI png_read_end(png_structp png_ptr, png_infop info_ptr) { png_debug(1, "in png_read_end"); - + if (png_ptr == NULL) return; png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ @@ -1096,7 +1083,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, #endif png_debug(1, "in png_destroy_read_struct"); - + if (png_ptr_ptr != NULL) png_ptr = *png_ptr_ptr; if (png_ptr == NULL) @@ -1172,7 +1159,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, #endif png_debug(1, "in png_read_destroy"); - + if (info_ptr != NULL) png_info_destroy(png_ptr, info_ptr); @@ -1455,8 +1442,8 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ png_read_end(png_ptr, info_ptr); - transforms = transforms; /* Quiet compiler warnings */ - params = params; + PNG_UNUSED(transforms) /* Quiet compiler warnings */ + PNG_UNUSED(params) } #endif /* PNG_INFO_IMAGE_SUPPORTED */ diff --git a/modules/libimg/png/pngrio.c b/modules/libimg/png/pngrio.c index 59059caf6927..710f4f0f460c 100644 --- a/modules/libimg/png/pngrio.c +++ b/modules/libimg/png/pngrio.c @@ -1,8 +1,8 @@ /* pngrio.c - functions for data input * - * Last changed in libpng 1.4.1 [February 25, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [January 14, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -33,7 +33,7 @@ void /* PRIVATE */ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { png_debug1(4, "reading %d bytes", (int)length); - + if (png_ptr->read_data_fn != NULL) (*(png_ptr->read_data_fn))(png_ptr, data, length); else diff --git a/modules/libimg/png/pngrtran.c b/modules/libimg/png/pngrtran.c index b5e8f1a26f2b..8bb8c2b232fd 100644 --- a/modules/libimg/png/pngrtran.c +++ b/modules/libimg/png/pngrtran.c @@ -1,8 +1,8 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.4.2 [May 6, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [%RDATE%] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -26,7 +26,7 @@ void PNGAPI png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) { png_debug(1, "in png_set_crc_action"); - + if (png_ptr == NULL) return; @@ -98,7 +98,7 @@ png_set_background(png_structp png_ptr, int need_expand, double background_gamma) { png_debug(1, "in png_set_background"); - + if (png_ptr == NULL) return; if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) @@ -686,6 +686,11 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, break; case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; + break; + + default: + png_error(png_ptr, "invalid error action in png_set_rgb_to_gray"); + break; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) #ifdef PNG_READ_EXPAND_SUPPORTED @@ -828,6 +833,8 @@ png_init_read_transformations(png_structp png_ptr) } break; + default: + case 8: case 16: @@ -1001,7 +1008,7 @@ png_init_read_transformations(png_structp png_ptr) */ png_ptr->transformations &= ~PNG_BACKGROUND; png_ptr->transformations &= ~PNG_GAMMA; - png_ptr->transformations |= PNG_STRIP_ALPHA; + png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; } /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ else @@ -1028,6 +1035,9 @@ png_init_read_transformations(png_structp png_ptr) gs = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); break; + + default: + png_error(png_ptr, "invalid background gamma type"); } png_ptr->background_1.gray = (png_uint_16)(pow( @@ -1121,7 +1131,7 @@ png_init_read_transformations(png_structp png_ptr) /* Handled alpha, still need to strip the channel. */ png_ptr->transformations &= ~PNG_BACKGROUND; - png_ptr->transformations |= PNG_STRIP_ALPHA; + png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; } #endif /* PNG_READ_BACKGROUND_SUPPORTED */ @@ -1626,6 +1636,9 @@ png_do_unpack(png_row_infop row_info, png_bytep row) } break; } + + default: + break; } row_info->bit_depth = 8; row_info->pixel_depth = (png_byte)(8 * row_info->channels); @@ -1682,6 +1695,9 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) switch (row_info->bit_depth) { + default: + break; + case 2: { png_bytep bp; @@ -2274,7 +2290,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) png_debug(1, "in png_do_rgb_to_gray"); - if ( + if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) && (row_info->color_type & PNG_COLOR_MASK_COLOR)) { png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; @@ -2798,6 +2814,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } break; } @@ -3230,6 +3249,9 @@ png_do_background(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } if (row_info->color_type & PNG_COLOR_MASK_ALPHA) @@ -3428,6 +3450,9 @@ png_do_gamma(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } } } @@ -3522,6 +3547,9 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } row_info->bit_depth = 8; row_info->pixel_depth = 8; @@ -3672,6 +3700,9 @@ png_do_expand(png_row_infop row_info, png_bytep row, } break; } + + default: + break; } row_info->bit_depth = 8; diff --git a/modules/libimg/png/pngrutil.c b/modules/libimg/png/pngrutil.c index 6b5eb2b8ef7a..c540b94b67ab 100644 --- a/modules/libimg/png/pngrutil.c +++ b/modules/libimg/png/pngrutil.c @@ -1,8 +1,8 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.4.3 [June 26, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -23,50 +23,98 @@ png_uint_32 PNGAPI png_get_uint_31(png_structp png_ptr, png_bytep buf) { - png_uint_32 i = png_get_uint_32(buf); - if (i > PNG_UINT_31_MAX) - png_error(png_ptr, "PNG unsigned integer out of range"); - return (i); -} -#ifndef PNG_USE_READ_MACROS -/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ -png_uint_32 PNGAPI -png_get_uint_32(png_bytep buf) -{ - png_uint_32 i = ((png_uint_32)(*buf) << 24) + - ((png_uint_32)(*(buf + 1)) << 16) + - ((png_uint_32)(*(buf + 2)) << 8) + - (png_uint_32)(*(buf + 3)); + png_uint_32 val = png_get_uint_32(buf); - return (i); + if (val > PNG_UINT_31_MAX) + png_error(png_ptr, "PNG unsigned integer out of range"); + return (val); +} + +#ifndef PNG_USE_READ_MACROS +/* The parentheses around "PNGAPI function_name" in the following three + * functions are necessary because they allow the macros to co-exist with + * these (unused but exported) functions. + */ + +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ +png_uint_32 (PNGAPI +png_get_uint_32)(png_bytep buf) +{ + png_uint_32 uval = png_get_uint_32(buf); + if ((uval & 0x80000000L) == 0) /* non-negative */ + return uval; + + uval = (uval ^ 0xffffffffL) + 1; /* 2's complement: -x = ~x+1 */ + return -(png_int_32)uval; } /* Grab a signed 32-bit integer from a buffer in big-endian format. The - * data is stored in the PNG file in two's complement format, and it is - * assumed that the machine format for signed integers is the same. + * data is stored in the PNG file in two's complement format and there + * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore + * the following code does a two's complement to native conversion. */ -png_int_32 PNGAPI -png_get_int_32(png_bytep buf) +png_int_32 (PNGAPI +png_get_int_32)(png_bytep buf) { - png_int_32 i = ((png_int_32)(*buf) << 24) + - ((png_int_32)(*(buf + 1)) << 16) + - ((png_int_32)(*(buf + 2)) << 8) + - (png_int_32)(*(buf + 3)); + png_uint_32 uval = png_get_uint_32(buf); + if ((uval & 0x80000000L) == 0) /* non-negative */ + return uval; - return (i); + uval = (uval ^ 0xffffffffL) + 1; /* 2's complement: -x = ~x+1 */ + return -(png_int_32)uval; } /* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ -png_uint_16 PNGAPI -png_get_uint_16(png_bytep buf) +png_uint_16 (PNGAPI +png_get_uint_16)(png_bytep buf) { - png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) + - (png_uint_16)(*(buf + 1))); + /* ANSI-C requires an int value to accomodate at least 16 bits so this + * works and allows the compiler not to worry about possible narrowing + * on 32 bit systems. (Pre-ANSI systems did not make integers smaller + * than 16 bits either.) + */ + unsigned int val = + ((unsigned int)(*buf) << 8) + + ((unsigned int)(*(buf + 1))); - return (i); + return (png_uint_16)val; } #endif /* PNG_USE_READ_MACROS */ +/* Read and check the PNG file signature */ +void /* PRIVATE */ +png_read_sig(png_structp png_ptr, png_infop info_ptr) +{ + png_size_t num_checked, num_to_check; + + /* Exit if the user application does not expect a signature. */ + if (png_ptr->sig_bytes >= 8) + return; + + num_checked = png_ptr->sig_bytes; + num_to_check = 8 - num_checked; + +#ifdef PNG_IO_STATE_SUPPORTED + png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; +#endif + + /* The signature must be serialized in a single I/O call. */ + png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); + png_ptr->sig_bytes = 8; + + if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) + { + if (num_checked < 4 && + png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) + png_error(png_ptr, "Not a PNG file"); + + else + png_error(png_ptr, "PNG file corrupted by ASCII conversion"); + } + if (num_checked < 3) + png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; +} + /* Read the chunk header (length + type name). * Put the type name into png_ptr->chunk_name, and return the length. */ @@ -77,32 +125,31 @@ png_read_chunk_header(png_structp png_ptr) png_uint_32 length; #ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that the chunk header is being read. - * PNG_IO_CHUNK_HDR requires a single I/O call. - */ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR; #endif - /* Read the length and the chunk name */ + /* Read the length and the chunk name. + * This must be performed in a single I/O call. + */ png_read_data(png_ptr, buf, 8); length = png_get_uint_31(png_ptr, buf); - /* Put the chunk name into png_ptr->chunk_name */ + /* Put the chunk name into png_ptr->chunk_name. */ png_memcpy(png_ptr->chunk_name, buf + 4, 4); png_debug2(0, "Reading %s chunk, length = %lu", - png_ptr->chunk_name, length); + png_ptr->chunk_name, (unsigned long)length); - /* Reset the crc and run it over the chunk name */ + /* Reset the crc and run it over the chunk name. */ png_reset_crc(png_ptr); png_calculate_crc(png_ptr, png_ptr->chunk_name, 4); - /* Check to see if chunk name is valid */ + /* Check to see if chunk name is valid. */ png_check_chunk_name(png_ptr, png_ptr->chunk_name); #ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that chunk data will (possibly) be read. - * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls. + /* It is unspecified how many I/O calls will be performed + * during the serialization of the chunk data. */ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA; #endif @@ -116,6 +163,7 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) { if (png_ptr == NULL) return; + png_read_data(png_ptr, buf, length); png_calculate_crc(png_ptr, buf, length); } @@ -135,6 +183,7 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip) { png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); } + if (i) { png_crc_read(png_ptr, png_ptr->zbuf, i); @@ -149,11 +198,13 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip) { png_chunk_warning(png_ptr, "CRC error"); } + else { png_chunk_benign_error(png_ptr, "CRC error"); return (0); } + return (1); } @@ -176,6 +227,7 @@ png_crc_error(png_structp png_ptr) (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN)) need_crc = 0; } + else /* critical */ { if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) @@ -183,11 +235,10 @@ png_crc_error(png_structp png_ptr) } #ifdef PNG_IO_STATE_SUPPORTED - /* Inform the I/O callback that the chunk CRC is being read */ - /* PNG_IO_CHUNK_CRC requires the I/O to be done at once */ png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC; #endif + /* The chunk CRC must be serialized in a single I/O call. */ png_read_data(png_ptr, crc_bytes, 4); if (need_crc) @@ -195,6 +246,7 @@ png_crc_error(png_structp png_ptr) crc = png_get_uint_32(crc_bytes); return ((int)(crc != png_ptr->crc)); } + else return (0); } @@ -234,6 +286,7 @@ png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size, if (avail < copy) copy = avail; png_memcpy(output + count, png_ptr->zbuf, copy); } + count += avail; } @@ -267,9 +320,11 @@ png_inflate(png_structp png_ptr, const png_byte *data, png_size_t size, case Z_BUF_ERROR: msg = "Buffer error in compressed datastream in %s chunk"; break; + case Z_DATA_ERROR: msg = "Data error in compressed datastream in %s chunk"; break; + default: msg = "Incomplete compressed datastream in %s chunk"; break; @@ -369,6 +424,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type, png_warning(png_ptr, "png_inflate logic error"); png_free(png_ptr, text); } + else png_warning(png_ptr, "Not enough memory to decompress chunk"); } @@ -652,7 +708,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_crc_finish(png_ptr, length); - info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ + PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ } #ifdef PNG_READ_gAMA_SUPPORTED @@ -1165,9 +1221,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_bytep entry_start; png_sPLT_t new_palette; -#ifdef PNG_POINTER_INDEXING_SUPPORTED png_sPLT_entryp pp; -#endif int data_length, entry_size, i; png_uint_32 skip = 0; png_size_t slength; @@ -1306,7 +1360,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; } - pp->frequency = png_get_uint_16(entry_start); entry_start += 2; + pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2; } #endif @@ -1675,7 +1729,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)", - length + 1); + (unsigned long)(length + 1)); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) @@ -1813,7 +1867,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) } png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)", - length + 1); + (unsigned long)(length + 1)); png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1); if (png_ptr->chunkdata == NULL) { @@ -1880,9 +1934,6 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "malformed height string in sCAL chunk"); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; -#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) - png_free(png_ptr, swidth); -#endif return; } #else @@ -1893,9 +1944,7 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_warning(png_ptr, "Out of memory while processing sCAL chunk height"); png_free(png_ptr, png_ptr->chunkdata); png_ptr->chunkdata = NULL; -#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED) png_free(png_ptr, swidth); -#endif return; } png_memcpy(sheight, ep, png_strlen(ep)); @@ -2357,7 +2406,7 @@ png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_uint_32 num_frames; png_uint_32 num_plays; png_uint_32 didSet; - + png_debug(1, "in png_handle_acTL"); if (!(png_ptr->mode & PNG_HAVE_IHDR)) @@ -2382,13 +2431,13 @@ png_handle_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - + png_crc_read(png_ptr, data, 8); png_crc_finish(png_ptr, 0); - + num_frames = png_get_uint_31(png_ptr, data); num_plays = png_get_uint_31(png_ptr, data + 4); - + /* the set function will do error checking on num_frames */ didSet = png_set_acTL(png_ptr, info_ptr, num_frames, num_plays); if(didSet) @@ -2407,9 +2456,11 @@ png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_uint_16 delay_den; png_byte dispose_op; png_byte blend_op; - + png_debug(1, "in png_handle_fcTL"); - + + png_ensure_sequence_number(png_ptr, length); + if (!(png_ptr->mode & PNG_HAVE_IHDR)) { png_error(png_ptr, "Missing IHDR before fcTL"); @@ -2420,13 +2471,13 @@ png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) * but correct. PNG_HAVE_IDAT is unset before the frame head is read * i can't think of a better message */ png_warning(png_ptr, "Invalid fcTL after IDAT skipped"); - png_crc_finish(png_ptr, length); + png_crc_finish(png_ptr, length-4); return; } else if (png_ptr->mode & PNG_HAVE_fcTL) { png_warning(png_ptr, "Duplicate fcTL within one frame skipped"); - png_crc_finish(png_ptr, length); + png_crc_finish(png_ptr, length-4); return; } else if (length != 26) @@ -2435,12 +2486,10 @@ png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, length); return; } - - png_ensure_sequence_number(png_ptr, length); - + png_crc_read(png_ptr, data, 22); png_crc_finish(png_ptr, 0); - + width = png_get_uint_31(png_ptr, data); height = png_get_uint_31(png_ptr, data + 4); x_offset = png_get_uint_31(png_ptr, data + 8); @@ -2449,21 +2498,29 @@ png_handle_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) delay_den = png_get_uint_16(data + 18); dispose_op = data[20]; blend_op = data[21]; - + if (png_ptr->num_frames_read == 0 && (x_offset != 0 || y_offset != 0)) png_error(png_ptr, "fcTL for the first frame must have zero offset"); - if (png_ptr->num_frames_read == 0 && + if (png_ptr->num_frames_read == 0 && (width != info_ptr->width || height != info_ptr->height)) png_error(png_ptr, "size in first frame's fcTL must match " "the size in IHDR"); - - /* the set function will do more error checking */ - png_set_next_frame_fcTL(png_ptr, info_ptr, width, height, - x_offset, y_offset, delay_num, delay_den, - dispose_op, blend_op); - - png_read_reinit(png_ptr, info_ptr); - + + if (info_ptr != NULL) + { + if (png_ptr->num_frames_read == 0 && + (width != info_ptr->width || height != info_ptr->height)) + png_error(png_ptr, "size in first frame's fcTL must match " + "the size in IHDR"); + + /* the set function will do more error checking */ + png_set_next_frame_fcTL(png_ptr, info_ptr, width, height, + x_offset, y_offset, delay_num, delay_den, + dispose_op, blend_op); + + png_read_reinit(png_ptr, info_ptr); + } + png_ptr->mode |= PNG_HAVE_fcTL; } @@ -2481,8 +2538,8 @@ void /* PRIVATE */ png_handle_fdAT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) { png_ensure_sequence_number(png_ptr, length); - - /* This function is only called from png_read_end(), png_read_info(), + + /* This function is only called from png_read_end(), png_read_info(), * and png_push_read_chunk() which means that: * - the user doesn't want to read this frame * - or this is an out-of-place fdAT @@ -2496,17 +2553,17 @@ png_ensure_sequence_number(png_structp png_ptr, png_uint_32 length) { png_byte data[4]; png_uint_32 sequence_number; - + if (length < 4) png_error(png_ptr, "invalid fcTL or fdAT chunk found"); - + png_crc_read(png_ptr, data, 4); sequence_number = png_get_uint_31(png_ptr, data); - + if (sequence_number != png_ptr->next_seq_num) png_error(png_ptr, "fcTL or fdAT chunk with out-of-order sequence " "number found"); - + png_ptr->next_seq_num++; } #endif /* PNG_READ_APNG_SUPPORTED */ @@ -2621,7 +2678,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_crc_finish(png_ptr, skip); #ifndef PNG_READ_USER_CHUNKS_SUPPORTED - info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */ + PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */ #endif } @@ -3077,7 +3134,7 @@ png_do_read_interlace(png_structp png_ptr) row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); } #ifndef PNG_READ_PACKSWAP_SUPPORTED - transformations = transformations; /* Silence compiler warning */ + PNG_UNUSED(transformations) /* Silence compiler warning */ #endif } #endif /* PNG_READ_INTERLACING_SUPPORTED */ @@ -3087,7 +3144,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter) { png_debug(1, "in png_read_filter_row"); - png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter); + png_debug2(2, "row = %lu, filter = %d", + (unsigned long)png_ptr->row_number, filter); switch (filter) { case PNG_FILTER_VALUE_NONE: @@ -3278,17 +3336,10 @@ png_read_finish_row(png_structp png_ptr) { while (!png_ptr->idat_size) { - png_byte chunk_length[4]; - png_crc_finish(png_ptr, 0); - - png_read_data(png_ptr, chunk_length, 4); - png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length); - png_reset_crc(png_ptr); - png_crc_read(png_ptr, png_ptr->chunk_name, 4); + png_ptr->idat_size = png_read_chunk_header(png_ptr); if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) png_error(png_ptr, "Not enough image data"); - } png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; png_ptr->zstream.next_in = png_ptr->zbuf; @@ -3535,13 +3586,13 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); - png_debug1(3, "width = %lu,", png_ptr->width); - png_debug1(3, "height = %lu,", png_ptr->height); - png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); - png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); - png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); + png_debug1(3, "width = %lu,", (unsigned long)png_ptr->width); + png_debug1(3, "height = %lu,", (unsigned long)png_ptr->height); + png_debug1(3, "iwidth = %lu,", (unsigned long)png_ptr->iwidth); + png_debug1(3, "num_rows = %lu,", (unsigned long)png_ptr->num_rows); + png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes); png_debug1(3, "irowbytes = %lu", - PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); + (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1); png_ptr->flags |= PNG_FLAG_ROW_INIT; } @@ -3585,7 +3636,7 @@ png_progressive_read_reset(png_structp png_ptr) /* offset to next interlace block in the y direction */ const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; - + if (png_ptr->interlaced) { if (!(png_ptr->transformations & PNG_INTERLACE)) diff --git a/modules/libimg/png/pngset.c b/modules/libimg/png/pngset.c index 10bf08e01571..d1f53473197a 100644 --- a/modules/libimg/png/pngset.c +++ b/modules/libimg/png/pngset.c @@ -1,8 +1,8 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.4.1 [February 25, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [January 14, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -260,7 +260,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr, info_ptr->rowbytes = 0; else info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); - + #if defined(PNG_APNG_SUPPORTED) /* for non-animated png. this may be overwritten from an acTL chunk later */ info_ptr->num_frames = 1; @@ -695,6 +695,13 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, if (text_ptr[i].key == NULL) continue; + if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE || + text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST) + { + png_warning(png_ptr, "text compression mode is out of range"); + continue; + } + key_len = png_strlen(text_ptr[i].key); if (text_ptr[i].compression <= 0) @@ -939,49 +946,49 @@ png_set_sPLT(png_structp png_ptr, #if defined(PNG_APNG_SUPPORTED) png_uint_32 PNGAPI -png_set_acTL(png_structp png_ptr, png_infop info_ptr, +png_set_acTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 num_frames, png_uint_32 num_plays) { png_debug1(1, "in %s storage function", "acTL"); if (png_ptr == NULL || info_ptr == NULL) { - png_warning(png_ptr, + png_warning(png_ptr, "Call to png_set_acTL() with NULL png_ptr " "or info_ptr ignored"); return (0); } if (num_frames == 0) { - png_warning(png_ptr, + png_warning(png_ptr, "Ignoring attempt to set acTL with num_frames zero"); return (0); } if (num_frames > PNG_UINT_31_MAX) { - png_warning(png_ptr, + png_warning(png_ptr, "Ignoring attempt to set acTL with num_frames > 2^31-1"); return (0); } if (num_plays > PNG_UINT_31_MAX) { - png_warning(png_ptr, + png_warning(png_ptr, "Ignoring attempt to set acTL with num_plays " "> 2^31-1"); return (0); } - + info_ptr->num_frames = num_frames; info_ptr->num_plays = num_plays; - + info_ptr->valid |= PNG_INFO_acTL; - + return (1); } /* delay_num and delay_den can hold any 16-bit values including zero */ png_uint_32 PNGAPI -png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, +png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, @@ -991,15 +998,15 @@ png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, if (png_ptr == NULL || info_ptr == NULL) { - png_warning(png_ptr, + png_warning(png_ptr, "Call to png_set_fcTL() with NULL png_ptr or info_ptr " "ignored"); return (0); } - - png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, + + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, delay_num, delay_den, dispose_op, blend_op); - + /* For efficiency, ignore BLEND_OP_OVER when image is opaque. * See bug #441971 and #455140 */ @@ -1023,20 +1030,20 @@ png_set_next_frame_fcTL(png_structp png_ptr, png_infop info_ptr, info_ptr->next_frame_delay_den = delay_den; info_ptr->next_frame_dispose_op = dispose_op; info_ptr->next_frame_blend_op = blend_op; - + info_ptr->valid |= PNG_INFO_fcTL; - + return (1); } void /* PRIVATE */ -png_ensure_fcTL_is_valid(png_structp png_ptr, +png_ensure_fcTL_is_valid(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op) { - if (width + x_offset > png_ptr->first_frame_width || + if (width + x_offset > png_ptr->first_frame_width || height + y_offset > png_ptr->first_frame_height) png_error(png_ptr, "dimensions of a frame are greater than" "the ones in IHDR"); @@ -1064,15 +1071,15 @@ png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr, png_byte is_hidden) { png_debug(1, "in png_first_frame_is_hidden()"); - + if (png_ptr == NULL) return 0; - + if(is_hidden) png_ptr->apng_flags |= PNG_FIRST_FRAME_HIDDEN; else png_ptr->apng_flags &= ~PNG_FIRST_FRAME_HIDDEN; - + return 1; } #endif /* PNG_APNG_SUPPORTED */ @@ -1149,7 +1156,7 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, #ifdef PNG_MNG_FEATURES_SUPPORTED png_uint_32 PNGAPI -png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) +png_permit_mng_features(png_structp png_ptr, png_uint_32 mng_features) { png_debug(1, "in png_permit_mng_features"); @@ -1263,7 +1270,7 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) #ifdef PNG_SET_USER_LIMITS_SUPPORTED /* This function was added to libpng 1.2.6 */ void PNGAPI -png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, +png_set_user_limits(png_structp png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max) { /* Images with dimensions larger than these limits will be @@ -1278,7 +1285,7 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max, /* This function was added to libpng 1.4.0 */ void PNGAPI -png_set_chunk_cache_max (png_structp png_ptr, +png_set_chunk_cache_max(png_structp png_ptr, png_uint_32 user_chunk_cache_max) { if (png_ptr) @@ -1287,7 +1294,7 @@ png_set_chunk_cache_max (png_structp png_ptr, /* This function was added to libpng 1.4.1 */ void PNGAPI -png_set_chunk_malloc_max (png_structp png_ptr, +png_set_chunk_malloc_max(png_structp png_ptr, png_alloc_size_t user_chunk_malloc_max) { if (png_ptr) diff --git a/modules/libimg/png/pngtrans.c b/modules/libimg/png/pngtrans.c index f80679a19d18..05eb2d05a37e 100644 --- a/modules/libimg/png/pngtrans.c +++ b/modules/libimg/png/pngtrans.c @@ -1,8 +1,8 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.4.2 [April 29, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [April 10, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -662,7 +662,7 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp * are called. */ png_voidp PNGAPI -png_get_user_transform_ptr(png_structp png_ptr) +png_get_user_transform_ptr(png_const_structp png_ptr) { if (png_ptr == NULL) return (NULL); @@ -673,5 +673,5 @@ png_get_user_transform_ptr(png_structp png_ptr) #endif } #endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || - PNG_WRITE_USER_TRANSFORM_SUPPORTED */ + PNG_WRITE_USER_TRANSFORM_SUPPORTED */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ diff --git a/modules/libimg/png/pngwrite.c b/modules/libimg/png/pngwrite.c index 00dc2a904c83..f38132a51f63 100644 --- a/modules/libimg/png/pngwrite.c +++ b/modules/libimg/png/pngwrite.c @@ -1,8 +1,8 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.4.0 [January 3, 2010] - * Copyright (c) 1998-2010 Glenn Randers-Pehrson + * Last changed in libpng 1.4.6 [March 8, 2011] + * Copyright (c) 1998-2011 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -669,8 +669,8 @@ png_write_row(png_structp png_ptr, png_bytep row) if (png_ptr == NULL) return; - png_debug2(1, "in png_write_row (row %ld, pass %d)", - png_ptr->row_number, png_ptr->pass); + png_debug2(1, "in png_write_row (row %lu, pass %d)", + (unsigned long)png_ptr->row_number, png_ptr->pass); /* Initialize transformations and other stuff if first time */ if (png_ptr->row_number == 0 && png_ptr->pass == 0) @@ -786,7 +786,8 @@ png_write_row(png_structp png_ptr, png_bytep row) png_ptr->row_info.width); png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type); - png_debug1(3, "row_info->width = %lu", png_ptr->row_info.width); + png_debug1(3, "row_info->width = %lu", + (unsigned long)png_ptr->row_info.width); png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels); png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth); png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth); @@ -1458,33 +1459,33 @@ png_write_png(png_structp png_ptr, png_infop info_ptr, /* It is REQUIRED to call this to finish writing the rest of the file */ png_write_end(png_ptr, info_ptr); - transforms = transforms; /* Quiet compiler warnings */ - params = params; + PNG_UNUSED(transforms) /* Quiet compiler warnings */ + PNG_UNUSED(params) } #endif #if defined(PNG_WRITE_APNG_SUPPORTED) void PNGAPI png_write_frame_head(png_structp png_ptr, png_infop info_ptr, - png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, - png_uint_32 x_offset, png_uint_32 y_offset, + png_bytepp row_pointers, png_uint_32 width, png_uint_32 height, + png_uint_32 x_offset, png_uint_32 y_offset, png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op) { png_debug(1, "in png_write_frame_head"); - + /* there is a chance this has been set after png_write_info was called, * so it would be set but not written. is there a way to be sure? */ if (!(info_ptr->valid & PNG_INFO_acTL)) png_error(png_ptr, "png_write_frame_head(): acTL not set"); - + png_write_reset(png_ptr); - + png_write_reinit(png_ptr, info_ptr, width, height); - - if ( !(png_ptr->num_frames_written == 0 && + + if ( !(png_ptr->num_frames_written == 0 && (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) ) ) - png_write_fcTL(png_ptr, width, height, x_offset, y_offset, + png_write_fcTL(png_ptr, width, height, x_offset, y_offset, delay_num, delay_den, dispose_op, blend_op); } @@ -1492,9 +1493,8 @@ void PNGAPI png_write_frame_tail(png_structp png_ptr, png_infop png_info) { png_debug(1, "in png_write_frame_tail"); - + png_ptr->num_frames_written++; } #endif /* PNG_WRITE_APNG_SUPPORTED */ - #endif /* PNG_WRITE_SUPPORTED */ diff --git a/modules/libimg/png/pngwtran.c b/modules/libimg/png/pngwtran.c index 070caa544de1..2925a9337722 100644 --- a/modules/libimg/png/pngwtran.c +++ b/modules/libimg/png/pngwtran.c @@ -195,6 +195,9 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) *dp = (png_byte)v; break; } + + default: + break; } row_info->bit_depth = (png_byte)bit_depth; row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels); diff --git a/modules/libimg/png/pngwutil.c b/modules/libimg/png/pngwutil.c index 0e6fad915252..69598735cbcb 100644 --- a/modules/libimg/png/pngwutil.c +++ b/modules/libimg/png/pngwutil.c @@ -246,10 +246,12 @@ png_text_compress(png_structp png_ptr, */ /* Set up the compression buffers */ + /* TODO: the following cast hides a potential overflow problem. */ png_ptr->zstream.avail_in = (uInt)text_len; + /* NOTE: assume zlib doesn't overwrite the input */ png_ptr->zstream.next_in = (Bytef *)text; - png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; - png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; + png_ptr->zstream.avail_out = png_ptr->zbuf_size; + png_ptr->zstream.next_out = png_ptr->zbuf; /* This is the same compression loop as in png_write_row() */ do @@ -688,11 +690,29 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) if (length >= 2 && png_ptr->height < 16384 && png_ptr->width < 16384) { + unsigned int z_cinfo; + unsigned int half_z_window_size; + + /* Compute the maximum possible length of the datastream */ + + /* Number of pixels, plus for each row a filter byte and possible + * and possibly a padding byte, so increase the maximum + * size to account for these. + */ png_uint_32 uncompressed_idat_size = png_ptr->height * ((png_ptr->width * png_ptr->channels * png_ptr->bit_depth + 15) >> 3); - unsigned int z_cinfo = z_cmf >> 4; - unsigned int half_z_window_size = 1 << (z_cinfo + 7); + + /* If it's interlaced, each block of 8 rows is sent as up to + * 14 rows, i.e., 6 additional rows, each with a filter byte + * and possibly a padding byte + */ + if (png_ptr->interlaced) + uncompressed_idat_size += ((png_ptr->height + 7)/8) * + (png_ptr->bit_depth < 8 ? 12 : 6); + + z_cinfo = z_cmf >> 4; + half_z_window_size = 1 << (z_cinfo + 7); while (uncompressed_idat_size <= half_z_window_size && half_z_window_size >= 256) { @@ -721,16 +741,16 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) else { png_byte buf[4]; - + png_write_chunk_start(png_ptr, (png_bytep)png_fdAT, 4 + length); - + png_save_uint_32(buf, png_ptr->next_seq_num); png_write_chunk_data(png_ptr, buf, 4); - + png_write_chunk_data(png_ptr, data, length); - + png_write_chunk_end(png_ptr); - + png_ptr->next_seq_num++; } #endif @@ -1748,43 +1768,43 @@ png_write_acTL(png_structp png_ptr, { PNG_acTL; png_byte data[16]; - + png_debug(1, "in png_write_acTL"); - + png_ptr->num_frames_to_write = num_frames; - + if (png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) num_frames--; - + png_save_uint_32(data, num_frames); png_save_uint_32(data + 4, num_plays); - + png_write_chunk(png_ptr, (png_bytep)png_acTL, data, (png_size_t)8); } void /* PRIVATE */ -png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height, +png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_uint_32 x_offset, png_uint_32 y_offset, - png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, + png_uint_16 delay_num, png_uint_16 delay_den, png_byte dispose_op, png_byte blend_op) { PNG_fcTL; png_byte data[26]; - + png_debug(1, "in png_write_fcTL"); - + if (png_ptr->num_frames_written == 0 && (x_offset != 0 || y_offset != 0)) png_error(png_ptr, "x and/or y offset for the first frame aren't 0"); - if (png_ptr->num_frames_written == 0 && - (width != png_ptr->first_frame_width || + if (png_ptr->num_frames_written == 0 && + (width != png_ptr->first_frame_width || height != png_ptr->first_frame_height)) png_error(png_ptr, "width and/or height in the first frame's fcTL " "don't match the ones in IHDR"); - + /* more error checking */ - png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, + png_ensure_fcTL_is_valid(png_ptr, width, height, x_offset, y_offset, delay_num, delay_den, dispose_op, blend_op); - + png_save_uint_32(data, png_ptr->next_seq_num); png_save_uint_32(data + 4, width); png_save_uint_32(data + 8, height); @@ -1794,9 +1814,9 @@ png_write_fcTL(png_structp png_ptr, png_uint_32 width, png_uint_32 height, png_save_uint_16(data + 22, delay_den); data[24] = dispose_op; data[25] = blend_op; - + png_write_chunk(png_ptr, (png_bytep)png_fcTL, data, (png_size_t)26); - + png_ptr->next_seq_num++; } #endif /* PNG_WRITE_APNG_SUPPORTED */ @@ -2883,24 +2903,24 @@ png_write_reset(png_structp png_ptr) } void /* PRIVATE */ -png_write_reinit(png_structp png_ptr, png_infop info_ptr, +png_write_reinit(png_structp png_ptr, png_infop info_ptr, png_uint_32 width, png_uint_32 height) { - if (png_ptr->num_frames_written == 0 && - (width != png_ptr->first_frame_width || + if (png_ptr->num_frames_written == 0 && + (width != png_ptr->first_frame_width || height != png_ptr->first_frame_height)) png_error(png_ptr, "width and/or height in the first frame's fcTL " "don't match the ones in IHDR"); - if (width > png_ptr->first_frame_width || + if (width > png_ptr->first_frame_width || height > png_ptr->first_frame_height) png_error(png_ptr, "width and/or height for a frame greater than" "the ones in IHDR"); - - png_set_IHDR(png_ptr, info_ptr, width, height, - info_ptr->bit_depth, info_ptr->color_type, + + png_set_IHDR(png_ptr, info_ptr, width, height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, info_ptr->compression_type, info_ptr->filter_type); - + png_ptr->width = width; png_ptr->height = height; png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); From 1e7fb28afa9ff6626684e9412914f7d8fd4cff19 Mon Sep 17 00:00:00 2001 From: Raymond Lee Date: Mon, 11 Apr 2011 11:19:05 +0800 Subject: [PATCH 08/57] Bug 640062 - Panorama tabs-from-other-windows button displays   r=ian --- browser/base/content/tabview/search.js | 2 +- .../base/content/test/tabview/browser_tabview_bug595560.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/browser/base/content/tabview/search.js b/browser/base/content/tabview/search.js index e22bef0a2b09..b7d17ad62c3e 100644 --- a/browser/base/content/tabview/search.js +++ b/browser/base/content/tabview/search.js @@ -132,7 +132,7 @@ var TabUtils = { // of active Panoramas as well as for windows in which // Panorama has yet to be activated. We uses object sniffing to // determine the type of tab and then returns its name. - return tab.label != undefined ? tab.label : tab.$tabTitle[0].innerHTML; + return tab.label != undefined ? tab.label : tab.$tabTitle[0].textContent; }, // --------- diff --git a/browser/base/content/test/tabview/browser_tabview_bug595560.js b/browser/base/content/test/tabview/browser_tabview_bug595560.js index f85dc54c5b7b..85fdca91debf 100644 --- a/browser/base/content/test/tabview/browser_tabview_bug595560.js +++ b/browser/base/content/test/tabview/browser_tabview_bug595560.js @@ -25,8 +25,10 @@ function onTabViewWindowLoaded() { window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); ok(TabView.isVisible(), "Tab View is visible"); - let contentWindow = document.getElementById("tab-view").contentWindow; - testOne(contentWindow); + afterAllTabItemsUpdated(function() { + let contentWindow = document.getElementById("tab-view").contentWindow; + testOne(contentWindow); + }); } function testOne(contentWindow) { From cc9f69880a6a36caf3b10e68a73618c5a4e55300 Mon Sep 17 00:00:00 2001 From: Raymond Lee Date: Mon, 11 Apr 2011 16:15:38 +0800 Subject: [PATCH 09/57] Bug 601958 - TabView should directly call show and hide routines in the frame r=ian --- browser/base/content/browser-tabview.js | 11 ++++------- browser/base/content/tabview/ui.js | 9 --------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/browser/base/content/browser-tabview.js b/browser/base/content/browser-tabview.js index f4ce5ec1af46..9f44218680c2 100644 --- a/browser/base/content/browser-tabview.js +++ b/browser/base/content/browser-tabview.js @@ -171,11 +171,10 @@ let TabView = { show: function() { if (this.isVisible()) return; - + + let self = this; this._initFrame(function() { - let event = document.createEvent("Events"); - event.initEvent("tabviewshow", false, false); - dispatchEvent(event); + self._window.UI.showTabView(true); }); }, @@ -184,9 +183,7 @@ let TabView = { if (!this.isVisible()) return; - let event = document.createEvent("Events"); - event.initEvent("tabviewhide", false, false); - dispatchEvent(event); + this._window.UI.exit(); }, // ---------- diff --git a/browser/base/content/tabview/ui.js b/browser/base/content/tabview/ui.js index 7ed660e2b1a4..d7fb0fec6e44 100644 --- a/browser/base/content/tabview/ui.js +++ b/browser/base/content/tabview/ui.js @@ -163,11 +163,6 @@ let UI = { this._storageSanity(data); this._pageBounds = data.pageBounds; - // ___ hook into the browser - gWindow.addEventListener("tabviewshow", function() { - self.showTabView(true); - }, false); - // ___ currentTab this._currentTab = gBrowser.selectedTab; @@ -226,10 +221,6 @@ let UI = { self.uninit(); }); - gWindow.addEventListener("tabviewhide", function() { - self.exit(); - }, false); - // ___ setup key handlers this._setTabViewFrameKeyHandlers(); From e5fb9d7f1803a5e24ea387c7ee230352560fd001 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 12 Apr 2011 16:07:44 -0400 Subject: [PATCH 10/57] ts in browser/components/sessionstore/test/browser should use utility functions in head.js; r=zpao --- .../browser_586068-cascaded_restore.js | 3 -- .../test/browser/browser_590268.js | 5 -- .../test/browser/browser_600545.js | 50 +------------------ .../test/browser/browser_607016.js | 4 -- .../test/browser/browser_618151.js | 13 ----- 5 files changed, 2 insertions(+), 73 deletions(-) diff --git a/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js b/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js index ef6122bd1c2c..52037cb388c7 100644 --- a/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js +++ b/browser/components/sessionstore/test/browser/browser_586068-cascaded_restore.js @@ -760,6 +760,3 @@ function countTabs() { return [needsRestore, isRestoring, wasRestored]; } -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_590268.js b/browser/components/sessionstore/test/browser/browser_590268.js index a44666c49a9c..2ab3de505306 100644 --- a/browser/components/sessionstore/test/browser/browser_590268.js +++ b/browser/components/sessionstore/test/browser/browser_590268.js @@ -170,8 +170,3 @@ function test() { // Restore state ss.setBrowserState(JSON.stringify(state)); } - -// Helper function to create a random value -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_600545.js b/browser/components/sessionstore/test/browser/browser_600545.js index 780f1b5f5565..43b59a8879d2 100644 --- a/browser/components/sessionstore/test/browser/browser_600545.js +++ b/browser/components/sessionstore/test/browser/browser_600545.js @@ -50,54 +50,6 @@ function testBug600545() { // Set the pref to false to cause non-app tabs to be stripped out on a save Services.prefs.setBoolPref("browser.sessionstore.resume_from_crash", false); - // Need to wait for SessionStore's saveState function to be called - // so that non-pinned tabs will be stripped from non-active window - function waitForSaveState(aSaveStateCallback) { - let topic = "sessionstore-state-write"; - Services.obs.addObserver(function() { - Services.obs.removeObserver(arguments.callee, topic, false); - executeSoon(aSaveStateCallback); - }, topic, false); - }; - - // Need to wait for all tabs to be restored before reading browser state - function waitForBrowserState(aState, aSetStateCallback) { - let tabsRestored = 0; - let expectedTabs = getStateTabCount(aState); - - // We know that there are only 2 windows total, so just be specific - let newWin; - - // Used to determine when tabs have been restored - function onTabRestored(aEvent) { - if (++tabsRestored == expectedTabs) { - gBrowser.tabContainer.removeEventListener("SSTabRestored", onTabRestored, true); - newWin.gBrowser.tabContainer.removeEventListener("SSTabRestored", onTabRestored, true); - executeSoon(aSetStateCallback); - } - } - - // We also want to catch the 2nd window, so we need to observe domwindowopened - function windowObserver(aSubject, aTopic, aData) { - let theWin = aSubject.QueryInterface(Ci.nsIDOMWindow); - if (aTopic == "domwindowopened") { - theWin.addEventListener("load", function() { - theWin.removeEventListener("load", arguments.callee, false); - - // So we can remove the event listener in onTabRestored - newWin = theWin; - - Services.ww.unregisterNotification(windowObserver); - theWin.gBrowser.tabContainer.addEventListener("SSTabRestored", onTabRestored, true); - }, false); - } - } - - Services.ww.registerNotification(windowObserver); - gBrowser.tabContainer.addEventListener("SSTabRestored", onTabRestored, true); - ss.setBrowserState(JSON.stringify(aState)); - } - // This tests the following use case: // When multiple windows are open and browser.sessionstore.resume_from_crash // preference is false, tab session data for non-active window is stripped for @@ -124,6 +76,8 @@ function testBug600545() { ] }; waitForBrowserState(state, function() { + // Need to wait for SessionStore's saveState function to be called + // so that non-pinned tabs will be stripped from non-active window waitForSaveState(function () { let expectedNumberOfTabs = getStateTabCount(state); let retrievedState = JSON.parse(ss.getBrowserState()); diff --git a/browser/components/sessionstore/test/browser/browser_607016.js b/browser/components/sessionstore/test/browser/browser_607016.js index 7b2e93c0288a..e2c77d51b901 100644 --- a/browser/components/sessionstore/test/browser/browser_607016.js +++ b/browser/components/sessionstore/test/browser/browser_607016.js @@ -148,7 +148,3 @@ function test() { ss.setBrowserState(JSON.stringify(state)); } -// Helper function to create a random value -function r() { - return "" + Date.now() + Math.random(); -} diff --git a/browser/components/sessionstore/test/browser/browser_618151.js b/browser/components/sessionstore/test/browser/browser_618151.js index 8aa27e307d71..a6df99b495cd 100644 --- a/browser/components/sessionstore/test/browser/browser_618151.js +++ b/browser/components/sessionstore/test/browser/browser_618151.js @@ -80,19 +80,6 @@ function runNextTest() { } } -// helper, works only for single window -function waitForBrowserState(aState, aSetStateCallback) { - let tabsRestored = 0; - gBrowser.tabContainer.addEventListener("SSTabRestored", function() { - if (++tabsRestored == aState.windows[0].tabs.length) { - gBrowser.tabContainer.removeEventListener("SSTabRestored", arguments.callee, true); - executeSoon(aSetStateCallback); - } - }, true); - ss.setBrowserState(JSON.stringify(aState)); -} - - function test_setup() { function onSSTabRestored(aEvent) { gBrowser.tabContainer.removeEventListener("SSTabRestored", onSSTabRestored, false); From 26d983614cd572ba3ac17b4f0e4ca1ab25c5030b Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Tue, 12 Apr 2011 16:10:09 -0400 Subject: [PATCH 11/57] Bug 611953 - Part 1: GNOME 3.0 readiness; r=roc,karlt --- .../shell/src/nsGNOMEShellService.cpp | 45 ++++++++++++++++++- .../shell/src/nsGNOMEShellService.h | 4 +- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/browser/components/shell/src/nsGNOMEShellService.cpp b/browser/components/shell/src/nsGNOMEShellService.cpp index ca7043209925..580309ce1331 100644 --- a/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/browser/components/shell/src/nsGNOMEShellService.cpp @@ -120,6 +120,9 @@ nsGNOMEShellService::Init() // the locale encoding. If it's not set, they use UTF-8. mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nsnull; + if (GetAppPathFromLauncher()) + return NS_OK; + nsCOMPtr dirSvc (do_GetService("@mozilla.org/file/directory_service;1")); NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE); @@ -137,6 +140,34 @@ nsGNOMEShellService::Init() NS_IMPL_ISUPPORTS1(nsGNOMEShellService, nsIShellService) +PRBool +nsGNOMEShellService::GetAppPathFromLauncher() +{ + gchar *tmp; + + const char *launcher = PR_GetEnv("MOZ_APP_LAUNCHER"); + if (!launcher) + return PR_FALSE; + + if (g_path_is_absolute(launcher)) { + mAppPath = launcher; + tmp = g_path_get_basename(launcher); + gchar *fullpath = g_find_program_in_path(tmp); + if (fullpath && mAppPath.Equals(fullpath)) + mAppIsInPath = PR_TRUE; + g_free(fullpath); + } else { + tmp = g_find_program_in_path(launcher); + if (!tmp) + return PR_FALSE; + mAppPath = tmp; + mAppIsInPath = PR_TRUE; + } + + g_free(tmp); + return PR_TRUE; +} + PRBool nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const { @@ -215,8 +246,18 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); if (gconf) { - nsCAutoString appKeyValue(mAppPath); - appKeyValue.Append(" \"%s\""); + nsCAutoString appKeyValue; + if(mAppIsInPath) { + // mAppPath is in the users path, so use only the basename as the launcher + gchar *tmp = g_path_get_basename(mAppPath.get()); + appKeyValue = tmp; + g_free(tmp); + } else { + appKeyValue = mAppPath; + } + + appKeyValue.AppendLiteral(" %s"); + for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) { if (appProtocols[i].essential || aClaimAllTypes) { gconf->SetAppForProtocol(nsDependentCString(appProtocols[i].name), diff --git a/browser/components/shell/src/nsGNOMEShellService.h b/browser/components/shell/src/nsGNOMEShellService.h index 1fdbd0152b59..1f12252d79a9 100644 --- a/browser/components/shell/src/nsGNOMEShellService.h +++ b/browser/components/shell/src/nsGNOMEShellService.h @@ -43,7 +43,7 @@ class nsGNOMEShellService : public nsIShellService { public: - nsGNOMEShellService() : mCheckedThisSession(PR_FALSE) { } + nsGNOMEShellService() : mCheckedThisSession(PR_FALSE), mAppIsInPath(PR_FALSE) { } NS_DECL_ISUPPORTS NS_DECL_NSISHELLSERVICE @@ -55,9 +55,11 @@ private: NS_HIDDEN_(PRBool) KeyMatchesAppName(const char *aKeyValue) const; + NS_HIDDEN_(PRBool) GetAppPathFromLauncher(); PRPackedBool mCheckedThisSession; PRPackedBool mUseLocaleFilenames; nsCString mAppPath; + PRPackedBool mAppIsInPath; }; #endif // nsgnomeshellservice_h____ From 1065d8285063564e7a39990cc573224c17cf22b3 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Tue, 12 Apr 2011 16:10:51 -0400 Subject: [PATCH 12/57] Bug 611953 - Part 2: GNOME 3.0 readiness; r=roc,karlt --- toolkit/system/gnome/nsGIOService.cpp | 55 +++++++-------------------- 1 file changed, 13 insertions(+), 42 deletions(-) diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp index de1cf9c5ded4..a01df6bd3067 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -106,15 +106,15 @@ nsGIOMimeApp::GetCommand(nsACString& aCommand) { get_commandline_t g_app_info_get_commandline_ptr; - void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY); + void *libHandle = dlopen("libgio-2.0.so.0", RTLD_LAZY); if (!libHandle) { return NS_ERROR_FAILURE; } dlerror(); /* clear any existing error */ g_app_info_get_commandline_ptr = (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline"); - if (dlerror() != NULL) { - const char cmd = *g_app_info_get_commandline_ptr(mApp); + if (dlerror() == NULL) { + const char *cmd = g_app_info_get_commandline_ptr(mApp); if (!cmd) { dlclose(libHandle); return NS_ERROR_FAILURE; @@ -419,50 +419,23 @@ nsGIOService::CreateAppFromCommand(nsACString const& cmd, GAppInfo *app_info = NULL, *app_info_from_list = NULL; GList *apps = g_app_info_get_all(); GList *apps_p = apps; - get_commandline_t g_app_info_get_commandline_ptr; - - void *libHandle = dlopen("libgio-2.0.so", RTLD_LAZY); - if (!libHandle) { - return NS_ERROR_FAILURE; - } - dlerror(); /* clear any existing error */ - g_app_info_get_commandline_ptr = - (get_commandline_t) dlsym(libHandle, "g_app_info_get_commandline"); - if (dlerror() != NULL) { - g_app_info_get_commandline_ptr = NULL; - } // Try to find relevant and existing GAppInfo in all installed application + // We do this by comparing each GAppInfo's executable with out own while (apps_p) { app_info_from_list = (GAppInfo*) apps_p->data; - /* This is a silly test. It just compares app names but not - * commands. This is due to old version of Glib/Gio. The required - * function which allows to do a regular check of existence of desktop file - * is possible by using function g_app_info_get_commandline. This function - * has been introduced in Glib 2.20. */ - if (app_info_from_list && strcmp(g_app_info_get_name(app_info_from_list), - PromiseFlatCString(appName).get()) == 0 ) - { - if (g_app_info_get_commandline_ptr) - { - /* Following test is only possible with Glib >= 2.20. - * Compare path only by using strncmp */ - if (strncmp(g_app_info_get_commandline_ptr(app_info_from_list), - PromiseFlatCString(cmd).get(), - strlen(PromiseFlatCString(cmd).get())) == 0) - { - app_info = app_info_from_list; - break; - } else { - g_object_unref(app_info_from_list); - } - } else { + if (!app_info) { + // If the executable is not absolute, get it's full path + char *executable = g_find_program_in_path(g_app_info_get_executable(app_info_from_list)); + + if (executable && strcmp(executable, PromiseFlatCString(cmd).get()) == 0) { + g_object_ref (app_info_from_list); app_info = app_info_from_list; - break; } - } else { - g_object_unref(app_info_from_list); + g_free(executable); } + + g_object_unref(app_info_from_list); apps_p = apps_p->next; } g_list_free(apps); @@ -477,12 +450,10 @@ nsGIOService::CreateAppFromCommand(nsACString const& cmd, if (!app_info) { g_warning("Cannot create application info from command: %s", error->message); g_error_free(error); - dlclose(libHandle); return NS_ERROR_FAILURE; } nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info); NS_ENSURE_TRUE(mozApp, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(*appInfo = mozApp); - dlclose(libHandle); return NS_OK; } From 7dcfbfecdee89ad0cca552d9b10fbdd631d4c01f Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Tue, 12 Apr 2011 16:11:20 -0400 Subject: [PATCH 13/57] Bug 611953 - Part 3: GNOME 3.0 readiness; r=roc,karlt --- .../shell/src/nsGNOMEShellService.cpp | 141 ++++++++++++------ .../shell/src/nsGNOMEShellService.h | 1 + toolkit/system/gnome/nsGIOService.cpp | 44 ++++++ xpcom/system/nsIGIOService.idl | 8 +- 4 files changed, 146 insertions(+), 48 deletions(-) diff --git a/browser/components/shell/src/nsGNOMEShellService.cpp b/browser/components/shell/src/nsGNOMEShellService.cpp index 580309ce1331..2fde1ebe5876 100644 --- a/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/browser/components/shell/src/nsGNOMEShellService.cpp @@ -106,14 +106,14 @@ nsGNOMEShellService::Init() { nsresult rv; - // GConf _must_ be available, or we do not allow + // GConf or GIO _must_ be available, or we do not allow // CreateInstance to succeed. nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); - if (!gconf) + if (!gconf && !giovfs) return NS_ERROR_NOT_AVAILABLE; // Check G_BROKEN_FILENAMES. If it's set, then filenames in glib use @@ -194,6 +194,27 @@ nsGNOMEShellService::KeyMatchesAppName(const char *aKeyValue) const return matches; } +PRBool +nsGNOMEShellService::CheckHandlerMatchesAppName(const nsACString &handler) const +{ + gint argc; + gchar **argv; + nsCAutoString command(handler); + + // The string will be something of the form: [/path/to/]browser "%s" + // We want to remove all of the parameters and get just the binary name. + + if (g_shell_parse_argv(command.get(), &argc, &argv, NULL) && argc > 0) { + command.Assign(argv[0]); + g_strfreev(argv); + } + + if (!KeyMatchesAppName(command.get())) + return PR_FALSE; // the handler is set to another app + + return PR_TRUE; +} + NS_IMETHODIMP nsGNOMEShellService::IsDefaultBrowser(PRBool aStartupCheck, PRBool* aIsDefaultBrowser) @@ -203,31 +224,37 @@ nsGNOMEShellService::IsDefaultBrowser(PRBool aStartupCheck, mCheckedThisSession = PR_TRUE; nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); + nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); PRBool enabled; nsCAutoString handler; + nsCOMPtr gioApp; for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) { if (!appProtocols[i].essential) continue; - handler.Truncate(); - gconf->GetAppForProtocol(nsDependentCString(appProtocols[i].name), - &enabled, handler); + if (gconf) { + handler.Truncate(); + gconf->GetAppForProtocol(nsDependentCString(appProtocols[i].name), + &enabled, handler); - // The string will be something of the form: [/path/to/]browser "%s" - // We want to remove all of the parameters and get just the binary name. - - gint argc; - gchar **argv; - - if (g_shell_parse_argv(handler.get(), &argc, &argv, NULL) && argc > 0) { - handler.Assign(argv[0]); - g_strfreev(argv); + if (!CheckHandlerMatchesAppName(handler) || !enabled) + return NS_OK; // the handler is disabled or set to another app } - if (!KeyMatchesAppName(handler.get()) || !enabled) - return NS_OK; // the handler is disabled or set to another app + if (giovfs) { + handler.Truncate(); + giovfs->GetAppForURIScheme(nsDependentCString(appProtocols[i].name), + getter_AddRefs(gioApp)); + if (!gioApp) + return NS_OK; + + gioApp->GetCommand(handler); + + if (!CheckHandlerMatchesAppName(handler)) + return NS_OK; // the handler is set to another app + } } *aIsDefaultBrowser = PR_TRUE; @@ -245,9 +272,10 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, #endif nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); + nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); if (gconf) { nsCAutoString appKeyValue; - if(mAppIsInPath) { + if (mAppIsInPath) { // mAppPath is in the users path, so use only the basename as the launcher gchar *tmp = g_path_get_basename(mAppPath.get()); appKeyValue = tmp; @@ -266,13 +294,8 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, } } - // set handler for .html and xhtml files and MIME types: - if (aClaimAllTypes) { + if (giovfs) { nsresult rv; - nsCOMPtr giovfs = - do_GetService(NS_GIOSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv, NS_OK); - nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -295,10 +318,20 @@ nsGNOMEShellService::SetDefaultBrowser(PRBool aClaimAllTypes, getter_AddRefs(appInfo)); NS_ENSURE_SUCCESS(rv, rv); - // Add mime types for html, xhtml extension and set app to just created appinfo. - for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appTypes); ++i) { - appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType)); - appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions)); + // set handler for the protocols + for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appProtocols); ++i) { + if (appProtocols[i].essential || aClaimAllTypes) { + appInfo->SetAsDefaultForURIScheme(nsDependentCString(appProtocols[i].name)); + } + } + + // set handler for .html and xhtml files and MIME types: + if (aClaimAllTypes) { + // Add mime types for html, xhtml extension and set app to just created appinfo. + for (unsigned int i = 0; i < NS_ARRAY_LENGTH(appTypes); ++i) { + appInfo->SetAsDefaultForMimeType(nsDependentCString(appTypes[i].mimeType)); + appInfo->SetAsDefaultForFileExtensions(nsDependentCString(appTypes[i].extensions)); + } } } @@ -408,24 +441,26 @@ nsGNOMEShellService::SetDesktopBackground(nsIDOMElement* aElement, // if the file was written successfully, set it as the system wallpaper nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); - nsCAutoString options; - if (aPosition == BACKGROUND_TILE) - options.Assign("wallpaper"); - else if (aPosition == BACKGROUND_STRETCH) - options.Assign("stretched"); - else - options.Assign("centered"); + if (gconf) { + nsCAutoString options; + if (aPosition == BACKGROUND_TILE) + options.Assign("wallpaper"); + else if (aPosition == BACKGROUND_STRETCH) + options.Assign("stretched"); + else + options.Assign("centered"); - gconf->SetString(NS_LITERAL_CSTRING(kDesktopOptionsKey), options); + gconf->SetString(NS_LITERAL_CSTRING(kDesktopOptionsKey), options); - // Set the image to an empty string first to force a refresh - // (since we could be writing a new image on top of an existing - // Firefox_wallpaper.png and nautilus doesn't monitor the file for changes) - gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), - EmptyCString()); + // Set the image to an empty string first to force a refresh + // (since we could be writing a new image on top of an existing + // Firefox_wallpaper.png and nautilus doesn't monitor the file for changes) + gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), + EmptyCString()); - gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), filePath); - gconf->SetBool(NS_LITERAL_CSTRING(kDesktopDrawBGKey), PR_TRUE); + gconf->SetString(NS_LITERAL_CSTRING(kDesktopImageKey), filePath); + gconf->SetBool(NS_LITERAL_CSTRING(kDesktopDrawBGKey), PR_TRUE); + } return rv; } @@ -439,7 +474,9 @@ nsGNOMEShellService::GetDesktopBackgroundColor(PRUint32 *aColor) nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); nsCAutoString background; - gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background); + if (gconf) { + gconf->GetString(NS_LITERAL_CSTRING(kDesktopColorKey), background); + } if (background.IsEmpty()) { *aColor = 0; @@ -478,10 +515,12 @@ nsGNOMEShellService::SetDesktopBackgroundColor(PRUint32 aColor) NS_ASSERTION(aColor <= 0xffffff, "aColor has extra bits"); nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); - nsCAutoString colorString; - ColorToCString(aColor, colorString); + if (gconf) { + nsCAutoString colorString; + ColorToCString(aColor, colorString); - gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString); + gconf->SetString(NS_LITERAL_CSTRING(kDesktopColorKey), colorString); + } return NS_OK; } @@ -497,7 +536,17 @@ nsGNOMEShellService::OpenApplication(PRInt32 aApplication) else return NS_ERROR_NOT_AVAILABLE; + nsCOMPtr giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); + if (giovfs) { + nsCOMPtr gioApp; + giovfs->GetAppForURIScheme(scheme, getter_AddRefs(gioApp)); + if (gioApp) + return gioApp->Launch(EmptyCString()); + } + nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); + if (!gconf) + return NS_ERROR_FAILURE; PRBool enabled; nsCAutoString appCommand; diff --git a/browser/components/shell/src/nsGNOMEShellService.h b/browser/components/shell/src/nsGNOMEShellService.h index 1f12252d79a9..d5171b293702 100644 --- a/browser/components/shell/src/nsGNOMEShellService.h +++ b/browser/components/shell/src/nsGNOMEShellService.h @@ -54,6 +54,7 @@ private: ~nsGNOMEShellService() {} NS_HIDDEN_(PRBool) KeyMatchesAppName(const char *aKeyValue) const; + NS_HIDDEN_(PRBool) CheckHandlerMatchesAppName(const nsACString& handler) const; NS_HIDDEN_(PRBool) GetAppPathFromLauncher(); PRPackedBool mCheckedThisSession; diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp index a01df6bd3067..675ae397c1b3 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -282,6 +282,33 @@ nsGIOMimeApp::SetAsDefaultForFileExtensions(nsACString const& fileExts) return NS_OK; } +/** + * Set default application for URI's of a particular scheme + * @param aURIScheme string containing the URI scheme + * @return NS_OK when application was set as default for URI scheme, + * NS_ERROR_FAILURE otherwise + */ +NS_IMETHODIMP +nsGIOMimeApp::SetAsDefaultForURIScheme(nsACString const& aURIScheme) +{ + GError *error = NULL; + nsCAutoString contentType("x-scheme-handler/"); + contentType.Append(aURIScheme); + + g_app_info_set_as_default_for_type(mApp, + contentType.get(), + &error); + if (error) { + g_warning("Cannot set application as default for URI scheme (%s): %s", + PromiseFlatCString(aURIScheme).get(), + error->message); + g_error_free(error); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + nsresult nsGIOService::Init() { @@ -321,6 +348,23 @@ nsGIOService::GetMimeTypeFromExtension(const nsACString& aExtension, } // used in nsGNOMERegistry // ----------------------------------------------------------------------------- +NS_IMETHODIMP +nsGIOService::GetAppForURIScheme(const nsACString& aURIScheme, + nsIGIOMimeApp** aApp) +{ + *aApp = nsnull; + + GAppInfo *app_info = g_app_info_get_default_for_uri_scheme( + PromiseFlatCString(aURIScheme).get()); + if (app_info) { + nsGIOMimeApp *mozApp = new nsGIOMimeApp(app_info); + NS_ADDREF(*aApp = mozApp); + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + NS_IMETHODIMP nsGIOService::GetAppForMimeType(const nsACString& aMimeType, nsIGIOMimeApp** aApp) diff --git a/xpcom/system/nsIGIOService.idl b/xpcom/system/nsIGIOService.idl index b0489a660182..b5b320519d56 100644 --- a/xpcom/system/nsIGIOService.idl +++ b/xpcom/system/nsIGIOService.idl @@ -46,7 +46,7 @@ interface nsIURI; with nsIGIOService::GetAppForMimeType. */ // 66009894-9877-405b-9321-bf30420e34e6 prev uuid -[scriptable, uuid(e77021b4-4012-407d-b686-7a1f18050109)] +[scriptable, uuid(ca6bad0c-8a48-48ac-82c7-27bb8f510fbe)] interface nsIGIOMimeApp : nsISupports { const long EXPECTS_URIS = 0; @@ -62,6 +62,7 @@ interface nsIGIOMimeApp : nsISupports void launch(in AUTF8String uri); void setAsDefaultForMimeType(in AUTF8String mimeType); void setAsDefaultForFileExtensions(in AUTF8String extensions); + void setAsDefaultForURIScheme(in AUTF8String uriScheme); }; /* @@ -77,7 +78,7 @@ interface nsIGIOMimeApp : nsISupports */ // prev id dea20bf0-4e4d-48c5-b932-dc3e116dc64b -[scriptable, uuid(47e372c2-78bb-4899-8114-56aa7d9cdac5)] +[scriptable, uuid(eda22a30-84e1-4e16-9ca0-cd1553c2b34a)] interface nsIGIOService : nsISupports { @@ -87,6 +88,9 @@ interface nsIGIOService : nsISupports should not include a leading dot. */ AUTF8String getMimeTypeFromExtension(in AUTF8String extension); + /* Obtain the preferred application for opening a given URI scheme */ + nsIGIOMimeApp getAppForURIScheme(in AUTF8String aURIScheme); + /* Obtain the preferred application for opening a given MIME type */ nsIGIOMimeApp getAppForMimeType(in AUTF8String mimeType); From 8b8416dd20a6bd1af7d17e5e76c79dc28015806e Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Tue, 12 Apr 2011 16:12:02 -0400 Subject: [PATCH 14/57] Bug 438284 - Remove incorrect translation note from profileSelection.properties --- .../en-US/chrome/mozapps/profile/profileSelection.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties index a024daedad46..723e2f8c2f84 100644 --- a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties +++ b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties @@ -1,5 +1,3 @@ -# LOCALIZATION NOTE: Do not translate - restartTitle=Close %S restartMessageNoUnlocker=%S is already running, but is not responding. To open a new window, you must first close the existing %S process, or restart your system. restartMessageUnlocker=%S is already running, but is not responding. The old %S process must be closed to open a new window. From db3c6e19ee789103dc1b92a20a2f6adb5314788f Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 12 Apr 2011 16:26:32 -0400 Subject: [PATCH 15/57] Backout changeset 3b7b6b0bd9ef (bug 647453) because it breaks packaging --- browser/installer/Makefile.in | 14 ++------------ browser/installer/precompile_cache.js | 25 +------------------------ 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/browser/installer/Makefile.in b/browser/installer/Makefile.in index fcfd352c68e7..acea03715aa5 100644 --- a/browser/installer/Makefile.in +++ b/browser/installer/Makefile.in @@ -122,23 +122,13 @@ ifdef RUN_TEST_PROGRAM _ABS_RUN_TEST_PROGRAM = $(call core_abspath,$(RUN_TEST_PROGRAM)) endif -ifndef MOZ_DEBUG -# The precompile_cache.js script outputs a list of files that were -# serialized and do not need to be included in the omnijar anymore -STRIP_ORIGINAL_FILES = zip -d omni.jar `cat sc_log.txt` -else -STRIP_ORIGINAL_FILES = true -endif - GENERATE_CACHE = \ - $(_ABS_RUN_TEST_PROGRAM) $(_ABS_DIST)/bin/xpcshell$(BIN_SUFFIX) -g "$$PWD" -f $(topsrcdir)/browser/installer/precompile_cache.js -e 'populate_startupcache("omni.jar", "startupCache.zip", "sc_log.txt");' && \ + $(_ABS_RUN_TEST_PROGRAM) $(_ABS_DIST)/bin/xpcshell$(BIN_SUFFIX) -g "$$PWD" -f $(topsrcdir)/browser/installer/precompile_cache.js -e 'populate_startupcache("omni.jar", "startupCache.zip");' && \ rm -rf jsloader && \ $(UNZIP) startupCache.zip && \ rm startupCache.zip && \ find jsloader | xargs touch -t 201001010000 && \ - $(ZIP) -r9mX omni.jar jsloader && \ - $(STRIP_ORIGINAL_FILES) && \ - rm sc_log.txt + $(ZIP) -r9mX omni.jar jsloader endif include $(topsrcdir)/toolkit/mozapps/installer/packager.mk diff --git a/browser/installer/precompile_cache.js b/browser/installer/precompile_cache.js index 942b4af5367b..ff3593255b84 100644 --- a/browser/installer/precompile_cache.js +++ b/browser/installer/precompile_cache.js @@ -43,14 +43,6 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; -const MODE_RDONLY = 0x01; -const MODE_WRONLY = 0x02; -const MODE_CREATE = 0x08; -const MODE_APPEND = 0x10; -const MODE_TRUNCATE = 0x20; - -var out; - function setenv(name, val) { try { var environment = Components.classes["@mozilla.org/process/environment;1"]. @@ -79,7 +71,6 @@ function load_entries(entries, prefix) { continue; if (c.indexOf("services-crypto") >= 0) continue; - out.writeString(c + "\n"); load(prefix + c); } } @@ -87,7 +78,6 @@ function load_entries(entries, prefix) { function load_custom_entries(entries, subst) { while (entries.hasMore()) { var c = entries.getNext(); - out.writeString(c + "\n"); load("resource://" + subst + "/" + c.replace("modules/" + subst + "/", "")); } } @@ -104,7 +94,7 @@ function openJar(file) { return zipreader; } -function populate_startupcache(omnijarName, startupcacheName, logName) { +function populate_startupcache(omnijarName, startupcacheName) { var file = getGreDir(); file.append(omnijarName); zipreader = openJar(file); @@ -113,18 +103,6 @@ function populate_startupcache(omnijarName, startupcacheName, logName) { scFile.append(startupcacheName); setenv("MOZ_STARTUP_CACHE", scFile.path); - var logFile = getGreDir(); - logFile.append(logName); - var stream = Cc["@mozilla.org/network/file-output-stream;1"] - .createInstance(Ci.nsIFileOutputStream); - - stream.init(logFile, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, 0666, 0); - - out = Cc["@mozilla.org/intl/converter-output-stream;1"] - .createInstance(Ci.nsIConverterOutputStream); - - out.init(stream, "UTF-8", 0, 0); - // the sync part below doesn't work as smoothly let ioService = Cc["@mozilla.org/network/io-service;1"]. getService(Ci.nsIIOService); @@ -148,5 +126,4 @@ function populate_startupcache(omnijarName, startupcacheName, logName) { load_entries(zipreader.findEntries("modules/*js"), "resource://gre/"); load_entries(zipreader.findEntries("modules/*jsm"), "resource://gre/"); zipreader.close(); - out.close(); } From c1ef5ff2fe8d933738ac8c908a9b6a3d38b0a558 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 12 Apr 2011 18:42:23 -0400 Subject: [PATCH 16/57] Bug 649223 - Reftest for bug 366207 wastes two seconds, needlessly; r=bzbarsky --- layout/reftests/bugs/366207-1.xul | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/layout/reftests/bugs/366207-1.xul b/layout/reftests/bugs/366207-1.xul index 37bf1a331788..275c93df15fa 100644 --- a/layout/reftests/bugs/366207-1.xul +++ b/layout/reftests/bugs/366207-1.xul @@ -3,7 +3,7 @@ @@ -21,7 +21,10 @@ - window.setTimeout(finish, 1000); + window.setTimeout(function() { + document.documentElement.clientHeight; + window.setTimeout(finish, 0); + }, 0); @@ -29,6 +32,13 @@ + + diff --git a/layout/reftests/editor/selection_visibility_after_reframe-ref.html b/layout/reftests/editor/selection_visibility_after_reframe-ref.html new file mode 100644 index 000000000000..c227b39c8f70 --- /dev/null +++ b/layout/reftests/editor/selection_visibility_after_reframe-ref.html @@ -0,0 +1,6 @@ + + + + + + diff --git a/layout/reftests/editor/selection_visibility_after_reframe.html b/layout/reftests/editor/selection_visibility_after_reframe.html new file mode 100644 index 000000000000..b05f130a1372 --- /dev/null +++ b/layout/reftests/editor/selection_visibility_after_reframe.html @@ -0,0 +1,14 @@ + + + + + + + From 95cfe4523048e51109e70fcd7bea2815afdc373f Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Wed, 13 Apr 2011 10:16:36 -0700 Subject: [PATCH 21/57] Fix partial DOS line endings in nsRect.cpp, rs=khuey, no bug --HG-- extra : rebase_source : 0bf86cf3015a3eecb19282159277581656136734 --- gfx/src/nsRect.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gfx/src/nsRect.cpp b/gfx/src/nsRect.cpp index b33bfbf1045c..05ae2508c502 100644 --- a/gfx/src/nsRect.cpp +++ b/gfx/src/nsRect.cpp @@ -217,7 +217,7 @@ nsRect& nsRect::ExtendForScaling(float aXMult, float aYMult) NS_ASSERTION((IsFloatInteger(aXMult) || IsFloatInteger(1/aXMult)) && (IsFloatInteger(aYMult) || IsFloatInteger(1/aYMult)), "Multiplication factors must be integers or 1/integer"); - + // Scale rect by multiplier, snap outwards to integers and then unscale. // We round the results to the nearest integer to prevent floating point errors. if (aXMult < 1) { @@ -330,15 +330,14 @@ PRBool nsIntRect::UnionRect(const nsIntRect &aRect1, const nsIntRect &aRect2) return result; } -// scale the rect but round to smallest containing rect -nsIntRect& nsIntRect::ScaleRoundOut(float aXScale, float aYScale) -{ - nscoord right = NSToCoordCeil(float(XMost()) * aXScale); - nscoord bottom = NSToCoordCeil(float(YMost()) * aYScale); - x = NSToCoordFloor(float(x) * aXScale); - y = NSToCoordFloor(float(y) * aYScale); - width = (right - x); - height = (bottom - y); - return *this; +// scale the rect but round to smallest containing rect +nsIntRect& nsIntRect::ScaleRoundOut(float aXScale, float aYScale) +{ + nscoord right = NSToCoordCeil(float(XMost()) * aXScale); + nscoord bottom = NSToCoordCeil(float(YMost()) * aYScale); + x = NSToCoordFloor(float(x) * aXScale); + y = NSToCoordFloor(float(y) * aYScale); + width = (right - x); + height = (bottom - y); + return *this; } - From 8569b071886021da220888a783557ed12ba709d4 Mon Sep 17 00:00:00 2001 From: Benjamin Stover Date: Wed, 13 Apr 2011 10:45:00 -0700 Subject: [PATCH 22/57] Bug 649666 Do not create container layers for scrollboxes with (0, 0) scrollRange r=roc --- layout/generic/nsGfxScrollFrame.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index fa4dd392d6b8..8d97771df43d 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -1983,6 +1983,8 @@ nsGfxScrollFrameInner::BuildDisplayList(nsDisplayListBuilder* aBuilder, (XRE_GetProcessType() == GeckoProcessType_Content && (styles.mHorizontal != NS_STYLE_OVERFLOW_HIDDEN || styles.mVertical != NS_STYLE_OVERFLOW_HIDDEN) && + (scrollRange.width > 0 || + scrollRange.height > 0) && (!mIsRoot || !mOuter->PresContext()->IsRootContentDocument())); if (ShouldBuildLayer()) { From 1ebf912e9362d11b3fd835002efa16246d35863a Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Wed, 13 Apr 2011 13:53:24 -0400 Subject: [PATCH 23/57] Bug 462172, fix up preventDefault call in drag synthesis test and move to a chrome test --HG-- rename : testing/mochitest/tests/SimpleTest/tests/test_synthesizeDragStart.xul => testing/mochitest/chrome/test_synthesizeDragStart.xul rename : testing/mochitest/tests/SimpleTest/tests/test_synthesizeDrop.xul => testing/mochitest/chrome/test_synthesizeDrop.xul --- testing/mochitest/chrome/Makefile.in | 2 + .../test_synthesizeDragStart.xul | 0 .../tests => chrome}/test_synthesizeDrop.xul | 6 +-- .../mochitest/tests/SimpleTest/Makefile.in | 3 -- .../tests/SimpleTest/tests/Makefile.in | 49 ------------------- 5 files changed, 4 insertions(+), 56 deletions(-) rename testing/mochitest/{tests/SimpleTest/tests => chrome}/test_synthesizeDragStart.xul (100%) rename testing/mochitest/{tests/SimpleTest/tests => chrome}/test_synthesizeDrop.xul (95%) delete mode 100644 testing/mochitest/tests/SimpleTest/tests/Makefile.in diff --git a/testing/mochitest/chrome/Makefile.in b/testing/mochitest/chrome/Makefile.in index 4e7fad935572..c6b73a5c0b1e 100644 --- a/testing/mochitest/chrome/Makefile.in +++ b/testing/mochitest/chrome/Makefile.in @@ -45,6 +45,8 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk _STATIC_FILES = test_sample.xul \ + test_synthesizeDragStart.xul \ + test_synthesizeDrop.xul \ $(NULL) libs:: $(_STATIC_FILES) diff --git a/testing/mochitest/tests/SimpleTest/tests/test_synthesizeDragStart.xul b/testing/mochitest/chrome/test_synthesizeDragStart.xul similarity index 100% rename from testing/mochitest/tests/SimpleTest/tests/test_synthesizeDragStart.xul rename to testing/mochitest/chrome/test_synthesizeDragStart.xul diff --git a/testing/mochitest/tests/SimpleTest/tests/test_synthesizeDrop.xul b/testing/mochitest/chrome/test_synthesizeDrop.xul similarity index 95% rename from testing/mochitest/tests/SimpleTest/tests/test_synthesizeDrop.xul rename to testing/mochitest/chrome/test_synthesizeDrop.xul index d4b24bc4d675..0ffe88223e79 100644 --- a/testing/mochitest/tests/SimpleTest/tests/test_synthesizeDrop.xul +++ b/testing/mochitest/chrome/test_synthesizeDrop.xul @@ -41,8 +41,6 @@ * Assure EventUtils can perform synthesizeDrop as specified */ -_tests\testing\mochitest\chrome\testing\mochitest\tests\SimpleTest\tests\test_synthesizeDrop.xul - --> Date: Wed, 13 Apr 2011 13:53:24 -0400 Subject: [PATCH 24/57] Bug 590665, panels jump around when dragged across screens, so don't do flipping when moving one, r=roc --- layout/xul/base/src/nsMenuPopupFrame.cpp | 86 +++++++++---------- .../content/tests/chrome/window_largemenu.xul | 30 +++++-- 2 files changed, 65 insertions(+), 51 deletions(-) diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index d8558e53eeac..565ad1efdf9d 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -1235,52 +1235,50 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame, PRBool aIsMove) vFlip = FlipStyle_Outside; } - // if a panel is being moved, don't flip it. But always do this for content - // shells, so that the popup doesn't extend outside the containing frame. - if (aIsMove && mPopupType == ePopupTypePanel && !mInContentShell) { - hFlip = vFlip = FlipStyle_None; + // If a panel is being moved, don't constrain or flip it. But always do this for + // content shells, so that the popup doesn't extend outside the containing frame. + if (mInContentShell || !aIsMove || mPopupType != ePopupTypePanel) { + nsRect screenRect = GetConstraintRect(anchorRect, rootScreenRect); + + // ensure that anchorRect is on screen + if (!anchorRect.IntersectRect(anchorRect, screenRect)) { + anchorRect.width = anchorRect.height = 0; + // if the anchor isn't within the screen, move it to the edge of the screen. + if (anchorRect.x < screenRect.x) + anchorRect.x = screenRect.x; + if (anchorRect.XMost() > screenRect.XMost()) + anchorRect.x = screenRect.XMost(); + if (anchorRect.y < screenRect.y) + anchorRect.y = screenRect.y; + if (anchorRect.YMost() > screenRect.YMost()) + anchorRect.y = screenRect.YMost(); + } + + // shrink the the popup down if it is larger than the screen size + if (mRect.width > screenRect.width) + mRect.width = screenRect.width; + if (mRect.height > screenRect.height) + mRect.height = screenRect.height; + + // at this point the anchor (anchorRect) is within the available screen + // area (screenRect) and the popup is known to be no larger than the screen. + // Next, check if there is enough space to show the popup at full size when + // positioned at screenPoint. If not, flip the popups to the opposite side + // of their anchor point, or resize them as necessary. + mRect.width = FlipOrResize(screenPoint.x, mRect.width, screenRect.x, + screenRect.XMost(), anchorRect.x, anchorRect.XMost(), + margin.left, margin.right, offsetForContextMenu, hFlip, &mHFlip); + + mRect.height = FlipOrResize(screenPoint.y, mRect.height, screenRect.y, + screenRect.YMost(), anchorRect.y, anchorRect.YMost(), + margin.top, margin.bottom, offsetForContextMenu, vFlip, &mVFlip); + + NS_ASSERTION(screenPoint.x >= screenRect.x && screenPoint.y >= screenRect.y && + screenPoint.x + mRect.width <= screenRect.XMost() && + screenPoint.y + mRect.height <= screenRect.YMost(), + "Popup is offscreen"); } - nsRect screenRect = GetConstraintRect(anchorRect, rootScreenRect); - - // ensure that anchorRect is on screen - if (!anchorRect.IntersectRect(anchorRect, screenRect)) { - anchorRect.width = anchorRect.height = 0; - // if the anchor isn't within the screen, move it to the edge of the screen. - if (anchorRect.x < screenRect.x) - anchorRect.x = screenRect.x; - if (anchorRect.XMost() > screenRect.XMost()) - anchorRect.x = screenRect.XMost(); - if (anchorRect.y < screenRect.y) - anchorRect.y = screenRect.y; - if (anchorRect.YMost() > screenRect.YMost()) - anchorRect.y = screenRect.YMost(); - } - - // shrink the the popup down if it is larger than the screen size - if (mRect.width > screenRect.width) - mRect.width = screenRect.width; - if (mRect.height > screenRect.height) - mRect.height = screenRect.height; - - // at this point the anchor (anchorRect) is within the available screen - // area (screenRect) and the popup is known to be no larger than the screen. - // Next, check if there is enough space to show the popup at full size when - // positioned at screenPoint. If not, flip the popups to the opposite side - // of their anchor point, or resize them as necessary. - mRect.width = FlipOrResize(screenPoint.x, mRect.width, screenRect.x, - screenRect.XMost(), anchorRect.x, anchorRect.XMost(), - margin.left, margin.right, offsetForContextMenu, hFlip, &mHFlip); - - mRect.height = FlipOrResize(screenPoint.y, mRect.height, screenRect.y, - screenRect.YMost(), anchorRect.y, anchorRect.YMost(), - margin.top, margin.bottom, offsetForContextMenu, vFlip, &mVFlip); - - NS_ASSERTION(screenPoint.x >= screenRect.x && screenPoint.y >= screenRect.y && - screenPoint.x + mRect.width <= screenRect.XMost() && - screenPoint.y + mRect.height <= screenRect.YMost(), - "Popup is offscreen"); - // determine the x and y position of the view by subtracting the desired // screen position from the screen position of the root frame. nsPoint viewPoint = screenPoint - rootScreenRect.TopLeft(); diff --git a/toolkit/content/tests/chrome/window_largemenu.xul b/toolkit/content/tests/chrome/window_largemenu.xul index 49b975d6c05d..2cf5612e5889 100644 --- a/toolkit/content/tests/chrome/window_largemenu.xul +++ b/toolkit/content/tests/chrome/window_largemenu.xul @@ -264,7 +264,8 @@ function nextContextMenuTest(desiredHeight) function testPopupMovement() { var button = document.getElementById("label"); - var popup = document.getElementById((gTests[gTestIndex] == "panel movement") ? "panel" : "popup"); + var isPanelTest = (gTests[gTestIndex] == "panel movement"); + var popup = document.getElementById(isPanelTest ? "panel" : "popup"); var screenX, screenY, buttonScreenX, buttonScreenY; var rect = popup.getBoundingClientRect(); @@ -273,21 +274,36 @@ function testPopupMovement() popup.moveTo(1, 1); [screenX, screenY] = getScreenXY(popup); - var expectedx = overlapOSChrome ? 1 : (screen.availLeft < 1 ? 1 : screen.availLeft); - var expectedy = overlapOSChrome ? 1 : (screen.availTop < 1 ? 1 : screen.availTop); + var expectedx = 1, expectedy = 1; + if (!isPanelTest && !overlapOSChrome) { + if (screen.availLeft >= 1) expectedx = screen.availLeft; + if (screen.availTop >= 1) expectedy = screen.availTop; + } is(screenX, expectedx, gTests[gTestIndex] + " (1, 1) x"); is(screenY, expectedy, gTests[gTestIndex] + " (1, 1) y"); popup.moveTo(100, 8000); - var expectedy = (overlapOSChrome ? screen.height + screen.top : screen.availHeight + screen.availTop) - - Math.round(rect.height) - 3; + if (isPanelTest) { + expectedy = 8000; + } + else { + expectedy = (overlapOSChrome ? screen.height + screen.top : screen.availHeight + screen.availTop) - + Math.round(rect.height) - 3; + } + [screenX, screenY] = getScreenXY(popup); is(screenX, 100, gTests[gTestIndex] + " (100, 8000) x"); is(screenY, expectedy, gTests[gTestIndex] + " (100, 8000) y"); popup.moveTo(6000, 100); - expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) - - Math.round(rect.width) - 3; + + if (isPanelTest) { + expectedx = 6000; + } + else { + expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) - + Math.round(rect.width) - 3; + } [screenX, screenY] = getScreenXY(popup); is(screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x"); From 5fbfdbbb1cc94a80853d7f8339ec72abf81a4e22 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Wed, 13 Apr 2011 13:53:24 -0400 Subject: [PATCH 25/57] Bug 126189, pass modifiers on to command events in menus when enter was pressed, r=neil --- layout/xul/base/src/nsMenuBarFrame.cpp | 4 +- layout/xul/base/src/nsMenuBarFrame.h | 2 +- layout/xul/base/src/nsMenuFrame.cpp | 4 +- layout/xul/base/src/nsMenuFrame.h | 2 +- layout/xul/base/src/nsMenuPopupFrame.cpp | 4 +- layout/xul/base/src/nsMenuPopupFrame.h | 2 +- layout/xul/base/src/nsXULPopupManager.cpp | 15 ++++-- .../tests/widgets/test_menulist_keynav.xul | 47 ++++++++++++++++++- 8 files changed, 67 insertions(+), 13 deletions(-) diff --git a/layout/xul/base/src/nsMenuBarFrame.cpp b/layout/xul/base/src/nsMenuBarFrame.cpp index 02965e590a92..f1b80e536eb3 100644 --- a/layout/xul/base/src/nsMenuBarFrame.cpp +++ b/layout/xul/base/src/nsMenuBarFrame.cpp @@ -414,13 +414,13 @@ nsMenuBarFrame::ChangeMenuItem(nsMenuFrame* aMenuItem, } nsMenuFrame* -nsMenuBarFrame::Enter() +nsMenuBarFrame::Enter(nsGUIEvent* aEvent) { if (!mCurrentMenu) return nsnull; if (mCurrentMenu->IsOpen()) - return mCurrentMenu->Enter(); + return mCurrentMenu->Enter(aEvent); return mCurrentMenu; } diff --git a/layout/xul/base/src/nsMenuBarFrame.h b/layout/xul/base/src/nsMenuBarFrame.h index 34e131697507..67ad5cbb2091 100644 --- a/layout/xul/base/src/nsMenuBarFrame.h +++ b/layout/xul/base/src/nsMenuBarFrame.h @@ -112,7 +112,7 @@ public: // Called when Enter is pressed while the menubar is focused. If the current // menu is open, let the child handle the key. - nsMenuFrame* Enter(); + nsMenuFrame* Enter(nsGUIEvent* aEvent); // Used to handle ALT+key combos nsMenuFrame* FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent); diff --git a/layout/xul/base/src/nsMenuFrame.cpp b/layout/xul/base/src/nsMenuFrame.cpp index 828015ac3778..9eeae9d7bc8d 100644 --- a/layout/xul/base/src/nsMenuFrame.cpp +++ b/layout/xul/base/src/nsMenuFrame.cpp @@ -832,7 +832,7 @@ nsMenuFrame::SetDebug(nsBoxLayoutState& aState, nsIFrame* aList, PRBool aDebug) // In either case, do nothing if the item is disabled. // nsMenuFrame* -nsMenuFrame::Enter() +nsMenuFrame::Enter(nsGUIEvent *aEvent) { if (IsDisabled()) { #ifdef XP_WIN @@ -853,7 +853,7 @@ nsMenuFrame::Enter() if (!IsOpen()) { // The enter key press applies to us. if (!IsMenu() && mMenuParent) - Execute(0); // Execute our event handler + Execute(aEvent); // Execute our event handler else return this; } diff --git a/layout/xul/base/src/nsMenuFrame.h b/layout/xul/base/src/nsMenuFrame.h index 950fbc872e4d..d6a69ae0a4c8 100644 --- a/layout/xul/base/src/nsMenuFrame.h +++ b/layout/xul/base/src/nsMenuFrame.h @@ -174,7 +174,7 @@ public: // one in its parent popup. This will carry out the command attached to // the menuitem. If the menu should be opened, this frame will be returned, // otherwise null will be returned. - nsMenuFrame* Enter(); + nsMenuFrame* Enter(nsGUIEvent* aEvent); virtual void SetParent(nsIFrame* aParent); diff --git a/layout/xul/base/src/nsMenuPopupFrame.cpp b/layout/xul/base/src/nsMenuPopupFrame.cpp index 565ad1efdf9d..01ea5c398b63 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -1537,13 +1537,13 @@ nsMenuPopupFrame::ChangeMenuItem(nsMenuFrame* aMenuItem, } nsMenuFrame* -nsMenuPopupFrame::Enter() +nsMenuPopupFrame::Enter(nsGUIEvent* aEvent) { mIncrementalString.Truncate(); // Give it to the child. if (mCurrentMenu) - return mCurrentMenu->Enter(); + return mCurrentMenu->Enter(aEvent); return nsnull; } diff --git a/layout/xul/base/src/nsMenuPopupFrame.h b/layout/xul/base/src/nsMenuPopupFrame.h index 1ff8c27253e0..789d96954988 100644 --- a/layout/xul/base/src/nsMenuPopupFrame.h +++ b/layout/xul/base/src/nsMenuPopupFrame.h @@ -234,7 +234,7 @@ public: // that menu, or null if no menu should be opened. Also, calling Enter will // reset the current incremental search string, calculated in // FindMenuWithShortcut. - nsMenuFrame* Enter(); + nsMenuFrame* Enter(nsGUIEvent* aEvent); nsPopupType PopupType() const { return mPopupType; } PRBool IsMenu() { return mPopupType == ePopupTypeMenu; } diff --git a/layout/xul/base/src/nsXULPopupManager.cpp b/layout/xul/base/src/nsXULPopupManager.cpp index 4f17070d7d0b..2499cdeeb8b2 100644 --- a/layout/xul/base/src/nsXULPopupManager.cpp +++ b/layout/xul/base/src/nsXULPopupManager.cpp @@ -1731,6 +1731,13 @@ nsXULPopupManager::CancelMenuTimer(nsMenuParent* aMenuParent) } } +static nsGUIEvent* DOMKeyEventToGUIEvent(nsIDOMEvent* aEvent) +{ + nsCOMPtr privateEvent(do_QueryInterface(aEvent)); + nsEvent* evt = privateEvent ? privateEvent->GetInternalNSEvent() : nsnull; + return (evt->eventStructType == NS_KEY_EVENT) ? static_cast(evt) : nsnull; +} + PRBool nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, nsMenuPopupFrame* aFrame) @@ -1745,7 +1752,8 @@ nsXULPopupManager::HandleShortcutNavigation(nsIDOMKeyEvent* aKeyEvent, if (result) { aFrame->ChangeMenuItem(result, PR_FALSE); if (action) { - nsMenuFrame* menuToOpen = result->Enter(); + nsGUIEvent* evt = DOMKeyEventToGUIEvent(aKeyEvent); + nsMenuFrame* menuToOpen = result->Enter(evt); if (menuToOpen) { nsCOMPtr content = menuToOpen->GetContent(); ShowMenu(content, PR_TRUE, PR_FALSE); @@ -2178,10 +2186,11 @@ nsXULPopupManager::KeyPress(nsIDOMEvent* aKeyEvent) // Enter method will return a menu if one needs to be opened as a result. nsMenuFrame* menuToOpen = nsnull; nsMenuChainItem* item = GetTopVisibleMenu(); + nsGUIEvent* evt = DOMKeyEventToGUIEvent(aKeyEvent); if (item) - menuToOpen = item->Frame()->Enter(); + menuToOpen = item->Frame()->Enter(evt); else if (mActiveMenuBar) - menuToOpen = mActiveMenuBar->Enter(); + menuToOpen = mActiveMenuBar->Enter(evt); if (menuToOpen) { nsCOMPtr content = menuToOpen->GetContent(); ShowMenu(content, PR_TRUE, PR_FALSE); diff --git a/toolkit/content/tests/widgets/test_menulist_keynav.xul b/toolkit/content/tests/widgets/test_menulist_keynav.xul index 8bef77c5df08..404c6c29ca77 100644 --- a/toolkit/content/tests/widgets/test_menulist_keynav.xul +++ b/toolkit/content/tests/widgets/test_menulist_keynav.xul @@ -27,6 +27,7 @@ SimpleTest.waitForExplicitFinish(); var gShowPopup = false; +var gModifiers = 0; var iswin = (navigator.platform.indexOf("Win") == 0); @@ -112,7 +113,7 @@ function differentPressed() list.open = false; - SimpleTest.finish(); + checkEnter(); } function keyCheck(list, key, index, testname) @@ -122,6 +123,50 @@ function keyCheck(list, key, index, testname) is(list.selectedItem, item, testname + " selectedItem"); } +function checkModifiers(event) +{ + var expectedModifiers = (gModifiers == 1); + is(event.shiftKey, expectedModifiers, "shift key pressed"); + is(event.ctrlKey, expectedModifiers, "ctrl key pressed"); + is(event.altKey, expectedModifiers, "alt key pressed"); + is(event.metaKey, expectedModifiers, "meta key pressed"); + gModifiers++; +} + +function checkEnter() +{ + var list = $("list"); + list.addEventListener("popuphidden", checkEnterWithModifiers, false); + list.addEventListener("command", checkModifiers, false); + list.open = true; + synthesizeKey("VK_ENTER", { }); +} + +function checkEnterWithModifiers() +{ + is(gModifiers, 1, "modifiers checked when not set"); + + var list = $("list"); + ok(!list.open, "list closed on enter press"); + list.removeEventListener("popuphidden", checkEnterWithModifiers, false); + + list.addEventListener("popuphidden", done, false); + list.open = true; + + synthesizeKey("VK_ENTER", { shiftKey: true, ctrlKey: true, altKey: true, metaKey: true }); +} + +function done() +{ + is(gModifiers, 2, "modifiers checked when set"); + + var list = $("list"); + ok(!list.open, "list closed on enter press with modifiers"); + list.removeEventListener("popuphidden", done, false); + + SimpleTest.finish(); +} + SimpleTest.waitForFocus(runTests); ]]> From 112ca7daaa8b115edf1ad2202371fbf191e0d091 Mon Sep 17 00:00:00 2001 From: Neil Deakin Date: Wed, 13 Apr 2011 13:53:24 -0400 Subject: [PATCH 26/57] Bug 608603, properly handle adjusting the day in the grid datepicker when switching to a month with fewer days, and add displayed month and year properties to datepicker, which can differ from the selection, r=neil --- .../content/tests/widgets/test_datepicker.xul | 69 ++++++++++++++++++- toolkit/content/widgets/datetimepicker.xml | 65 +++++++++++++++-- 2 files changed, 129 insertions(+), 5 deletions(-) diff --git a/toolkit/content/tests/widgets/test_datepicker.xul b/toolkit/content/tests/widgets/test_datepicker.xul index a336e5fa1624..3f52f9ad022b 100644 --- a/toolkit/content/tests/widgets/test_datepicker.xul +++ b/toolkit/content/tests/widgets/test_datepicker.xul @@ -133,6 +133,22 @@ function testtag_datepicker(dp, type, testid) setDateField("value", "2000-a-19", true, 2002, 6, 15); setDateField("dateValue", "none", true, 2002, 6, 15); + // grid and popup types can display a different month than the current one + var isGridOrPopup = (type == "grid" || type == "popup"); + dp.displayedMonth = 3; + testtag_comparedate(dp, testid + "set displayedMonth", + 2002, isGridOrPopup ? 6 : 3, 15, 3); + + dp.displayedYear = 2009; + testtag_comparedate(dp, testid + "set displayedYear", + isGridOrPopup ? 2002 : 2009, isGridOrPopup ? 6 : 3, 15, 3, 2009); + + if (isGridOrPopup) { + dp.value = "2008-02-29"; + dp.displayedYear = 2009; + is(dp.displayedMonth, 1, "set displayedYear during leap year"); + } + is(dp.open, false, testid + "open false"); if (type != "popup") { dp.open = true; @@ -241,7 +257,56 @@ function testtag_datepicker_UI_grid(dp, type, testid) synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up"); is(dp.value, "2003-02-15", testid + "key page up"); + // check handling at the start and end of the month + dp.value = "2010-10-01"; + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up 2010-10-01"); + is(dp.displayedMonth, 8, testid + "key page up 2010-10-01 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-10-01 displayedYear"); + + dp.value = "2010-10-01"; + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, ktarget, "monthchange", testid + "key page down 2010-10-01"); + is(dp.displayedMonth, 10, testid + "key page down 2010-10-01 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page down 2010-10-01 displayedYear"); + + dp.value = "2010-10-31"; + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up 2010-10-31"); + is(dp.displayedMonth, 8, testid + "key page up 2010-10-31 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-10-01 displayedYear"); + dp.value = "2010-10-31"; + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, ktarget, "monthchange", testid + "key page down 2010-10-31"); + is(dp.displayedMonth, 10, testid + "key page down 2010-10-31 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-10-31 displayedYear"); + + // check handling at the end of february + dp.value = "2010-03-31"; + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up 2010-03-31"); + is(dp.displayedMonth, 1, testid + "key page up 2010-03-31 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-03-31 displayedYear"); + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up 2010-02-28"); + is(dp.displayedMonth, 0, testid + "key page up 2010-02-28 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-02-28 displayedYear"); + + dp.value = "2010-01-31"; + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, ktarget, "monthchange", testid + "key page down 2010-01-31"); + is(dp.displayedMonth, 1, testid + "key page down 2010-01-31 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-01-31 displayedYear"); + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, ktarget, "monthchange", testid + "key page down 2010-02-28"); + is(dp.displayedMonth, 2, testid + "key page down 2010-02-28 displayedMonth"); + is(dp.displayedYear, 2010, testid + "key page up 2010-02-28 displayedYear"); + + // check handling at the end of february during a leap year + dp.value = "2008-01-31"; + synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, ktarget, "monthchange", testid + "key page down 2008-01-31"); + is(dp.displayedMonth, 1, testid + "key page down 2008-01-31 displayedMonth"); + is(dp.displayedYear, 2008, testid + "key page up 2008-01-31 displayedYear"); + dp.value = "2008-03-31"; + synthesizeKeyExpectEvent("VK_PAGE_UP", { }, ktarget, "monthchange", testid + "key page up 2008-03-31"); + is(dp.displayedMonth, 1, testid + "key page up 2008-03-31 displayedMonth"); + is(dp.displayedYear, 2008, testid + "key page up 2008-03-31 displayedYear"); + // the value of a read only datepicker cannot be changed + dp.value = "2003-02-15"; + dp.readOnly = true; synthesizeKeyExpectEvent("VK_LEFT", { }, ktarget, "!change", testid + "key left read only"); is(dp.value, "2003-02-15", testid + "key left read only"); @@ -314,7 +379,7 @@ function testtag_getdatestring(year, month, date) return year + "-" + month + "-" + date; } -function testtag_comparedate(dp, testid, year, month, date) +function testtag_comparedate(dp, testid, year, month, date, displayedMonth, displayedYear) { is(dp.value, testtag_getdatestring(year, month, date), testid + " value"); if (testid.indexOf("initial") == -1) @@ -330,6 +395,8 @@ function testtag_comparedate(dp, testid, year, month, date) is(dp.year, year, testid + " year"); is(dp.month, month, testid + " month"); + is(dp.displayedMonth, displayedMonth ? displayedMonth : month, testid + " displayedMonth"); + is(dp.displayedYear, displayedYear ? displayedYear : year, testid + " displayedYear"); is(dp.date, date, testid + " date"); } diff --git a/toolkit/content/widgets/datetimepicker.xml b/toolkit/content/widgets/datetimepicker.xml index 40ec91a815a7..532269abe93a 100644 --- a/toolkit/content/widgets/datetimepicker.xml +++ b/toolkit/content/widgets/datetimepicker.xml @@ -20,7 +20,7 @@ - the Initial Developer. All Rights Reserved. - - Contributor(s): - - Neil Deakin (Original Author) + - Neil Deakin (Original Author) - - Alternatively, the contents of this file may be used under the terms of - either of the GNU General Public License Version 2 or later (the "GPL"), @@ -645,6 +645,11 @@ + + + @@ -989,6 +994,25 @@ + + + return this._displayedDate.getMonth(); + + + this._updateUI(this.monthField, val, true); + return val; + + + + + return this._displayedDate.getFullYear(); + + + this._updateUI(this.yearField, val, true); + return val; + + + - + + + + return document.getAnonymousElementByAttribute(this, "anonid", "grid").displayedMonth; + + + document.getAnonymousElementByAttribute(this, "anonid", "grid").displayedMonth = val; + return val; + + + + + return document.getAnonymousElementByAttribute(this, "anonid", "grid").displayedYear; + + + document.getAnonymousElementByAttribute(this, "anonid", "grid").displayedYear = val; + return val; + + From 1f6dacab440a97f50a02fe855d75fa9a5a71ae18 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 13 Apr 2011 14:08:43 -0400 Subject: [PATCH 27/57] Back out bug 606574 for leaking a Mutex and a CondVar in crashtests --- config/autoconf.mk.in | 2 - configure.in | 8 -- toolkit/xre/EventTracer.cpp | 182 ------------------------ toolkit/xre/EventTracer.h | 54 ------- toolkit/xre/MacApplicationDelegate.mm | 6 +- toolkit/xre/Makefile.in | 4 - toolkit/xre/nsAppRunner.cpp | 16 --- widget/public/Makefile.in | 7 +- widget/public/WidgetTraceEvent.h | 53 ------- widget/src/cocoa/CustomCocoaEvents.h | 51 ------- widget/src/cocoa/Makefile.in | 69 +++++---- widget/src/cocoa/WidgetTraceEvent.mm | 92 ------------ widget/src/cocoa/nsAppShell.mm | 29 +--- widget/src/gtk2/Makefile.in | 35 +++-- widget/src/gtk2/WidgetTraceEvent.cpp | 86 ----------- widget/src/windows/Makefile.in | 53 ++++--- widget/src/windows/WidgetTraceEvent.cpp | 148 ------------------- widget/src/windows/nsWindow.cpp | 8 -- widget/src/windows/nsWindowDefs.h | 2 - 19 files changed, 83 insertions(+), 822 deletions(-) delete mode 100644 toolkit/xre/EventTracer.cpp delete mode 100644 toolkit/xre/EventTracer.h delete mode 100644 widget/public/WidgetTraceEvent.h delete mode 100644 widget/src/cocoa/CustomCocoaEvents.h delete mode 100644 widget/src/cocoa/WidgetTraceEvent.mm delete mode 100644 widget/src/gtk2/WidgetTraceEvent.cpp delete mode 100644 widget/src/windows/WidgetTraceEvent.cpp diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 90868412620d..8b94e1e081eb 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -716,8 +716,6 @@ ANDROID_PACKAGE_NAME = @ANDROID_PACKAGE_NAME@ JS_SHARED_LIBRARY = @JS_SHARED_LIBRARY@ -MOZ_INSTRUMENT_EVENT_LOOP = @MOZ_INSTRUMENT_EVENT_LOOP@ - # We only want to do the pymake sanity on Windows, other os's can cope ifeq (,$(filter-out WINNT WINCE,$(HOST_OS_ARCH))) # Ensure invariants between GNU Make and pymake diff --git a/configure.in b/configure.in index 7dc86741cd80..8f667097278f 100644 --- a/configure.in +++ b/configure.in @@ -5203,7 +5203,6 @@ cairo-windows) ;; esac MOZ_PDF_PRINTING=1 - MOZ_INSTRUMENT_EVENT_LOOP=1 ;; cairo-gtk2|cairo-gtk2-x11) @@ -5221,7 +5220,6 @@ cairo-gtk2|cairo-gtk2-x11) TK_LIBS='$(MOZ_GTK2_LIBS)' AC_DEFINE(MOZ_WIDGET_GTK2) MOZ_PDF_PRINTING=1 - MOZ_INSTRUMENT_EVENT_LOOP=1 ;; cairo-gtk2-dfb) @@ -5281,7 +5279,6 @@ 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) @@ -5305,10 +5302,6 @@ if test "$MOZ_ENABLE_XREMOTE"; then AC_DEFINE(MOZ_ENABLE_XREMOTE) fi -if test "$MOZ_INSTRUMENT_EVENT_LOOP"; then - AC_DEFINE(MOZ_INSTRUMENT_EVENT_LOOP) -fi - if test "$COMPILE_ENVIRONMENT"; then if test "$MOZ_ENABLE_GTK2"; then if test "$MOZ_X11"; then @@ -9192,7 +9185,6 @@ AC_SUBST(VPX_AS_CONVERSION) AC_SUBST(VPX_ASM_SUFFIX) AC_SUBST(VPX_X86_ASM) AC_SUBST(VPX_ARM_ASM) -AC_SUBST(MOZ_INSTRUMENT_EVENT_LOOP) AC_SUBST(LIBJPEG_TURBO_AS) AC_SUBST(LIBJPEG_TURBO_ASFLAGS) AC_SUBST(LIBJPEG_TURBO_X86_ASM) diff --git a/toolkit/xre/EventTracer.cpp b/toolkit/xre/EventTracer.cpp deleted file mode 100644 index 46b89d2d92f2..000000000000 --- a/toolkit/xre/EventTracer.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* ***** 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 - * - * 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 ***** */ - -/* - * Event loop instrumentation. This code attempts to measure the - * latency of the UI-thread event loop by firing native events at it from - * a background thread, and measuring how long it takes for them - * to be serviced. The measurement interval (kMeasureInterval, below) - * is also used as the upper bound of acceptable response time. - * When an event takes longer than that interval to be serviced, - * a sample will be written to the log. - * - * Usage: - * - * Set MOZ_INSTRUMENT_EVENT_LOOP=1 in the environment to enable - * this instrumentation. Currently only the UI process is instrumented. - * - * Set MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT in the environment to a - * file path to contain the log output, the default is to log to stdout. - * - * All logged output lines start with MOZ_EVENT_TRACE. All timestamps - * output are milliseconds since the epoch (PRTime / 1000). - * - * On startup, a line of the form: - * MOZ_EVENT_TRACE start - * will be output. - * - * On shutdown, a line of the form: - * MOZ_EVENT_TRACE stop - * will be output. - * - * When an event servicing time exceeds the threshold, a line of the form: - * MOZ_EVENT_TRACE sample - * will be output, where is the number of milliseconds that - * it took for the event to be serviced. - */ - -#include "EventTracer.h" - -#include - -#include "mozilla/TimeStamp.h" -#include "mozilla/WidgetTraceEvent.h" -#include -#include -#include -#include - -using mozilla::TimeDuration; -using mozilla::TimeStamp; -using mozilla::FireAndWaitForTracerEvent; - -namespace { - -PRThread* sTracerThread = NULL; -bool sExit = false; - -/* - * The tracer thread fires events at the native event loop roughly - * every kMeasureInterval. It will sleep to attempt not to send them - * more quickly, but if the response time is longer than kMeasureInterval - * it will not send another event until the previous response is received. - * - * The output defaults to stdout, but can be redirected to a file by - * settting the environment variable MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT - * to the name of a file to use. - */ -void TracerThread(void *arg) -{ - // This should be set to the maximum latency we'd like to allow - // for responsiveness. - const PRIntervalTime kMeasureInterval = PR_MillisecondsToInterval(50); - - FILE* log = NULL; - char* envfile = PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP_OUTPUT"); - if (envfile) { - log = fopen(envfile, "w"); - } - if (log == NULL) - log = stdout; - - fprintf(log, "MOZ_EVENT_TRACE start %llu\n", PR_Now() / PR_USEC_PER_MSEC); - - while (!sExit) { - TimeStamp start(TimeStamp::Now()); - PRIntervalTime next_sleep = kMeasureInterval; - - //TODO: only wait up to a maximum of kMeasureInterval, return - // early if that threshold is exceeded and dump a stack trace - // or do something else useful. - if (FireAndWaitForTracerEvent()) { - TimeDuration duration = TimeStamp::Now() - start; - // Only report samples that exceed our measurement interval. - if (duration.ToMilliseconds() > kMeasureInterval) { - fprintf(log, "MOZ_EVENT_TRACE sample %llu %d\n", - PR_Now() / PR_USEC_PER_MSEC, - int(duration.ToSecondsSigDigits() * 1000)); - } - - if (next_sleep > duration.ToMilliseconds()) { - next_sleep -= int(duration.ToMilliseconds()); - } - else { - // Don't sleep at all if this event took longer than the measure - // interval to deliver. - next_sleep = 0; - } - } - - if (next_sleep != 0 && !sExit) { - PR_Sleep(next_sleep); - } - } - - fprintf(log, "MOZ_EVENT_TRACE stop %llu\n", PR_Now() / PR_USEC_PER_MSEC); - - if (log != stdout) - fclose(log); -} - -} // namespace - -namespace mozilla { - -bool InitEventTracing() -{ - // Create a thread that will fire events back at the - // main thread to measure responsiveness. - NS_ABORT_IF_FALSE(!sTracerThread, "Event tracing already initialized!"); - sTracerThread = PR_CreateThread(PR_USER_THREAD, - TracerThread, - NULL, - PR_PRIORITY_NORMAL, - PR_GLOBAL_THREAD, - PR_JOINABLE_THREAD, - 0); - return sTracerThread != NULL; -} - -void ShutdownEventTracing() -{ - sExit = true; - if (sTracerThread) - PR_JoinThread(sTracerThread); - sTracerThread = NULL; -} - -} // namespace mozilla diff --git a/toolkit/xre/EventTracer.h b/toolkit/xre/EventTracer.h deleted file mode 100644 index 2becc53c9e62..000000000000 --- a/toolkit/xre/EventTracer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* ***** 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 - * - * 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 ***** */ - -#ifndef XRE_EVENTTRACER_H_ -#define XRE_EVENTTRACER_H_ - -namespace mozilla { - -// Create a thread that will fire events back at the -// main thread to measure responsiveness. Return true -// if the thread was created successfully. -bool InitEventTracing(); - -// Signal the background thread to stop, and join it. -// Must be called from the same thread that called InitEventTracing. -void ShutdownEventTracing(); - -} // namespace mozilla - -#endif /* XRE_EVENTTRACER_H_ */ diff --git a/toolkit/xre/MacApplicationDelegate.mm b/toolkit/xre/MacApplicationDelegate.mm index 1c431d7fe053..ea495d89f00c 100644 --- a/toolkit/xre/MacApplicationDelegate.mm +++ b/toolkit/xre/MacApplicationDelegate.mm @@ -88,8 +88,6 @@ 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" @@ -99,7 +97,7 @@ EnsureUseCocoaDockAPI() { NS_OBJC_BEGIN_TRY_ABORT_BLOCK; - [GeckoNSApplication sharedApplication]; + [NSApplication sharedApplication]; NS_OBJC_END_TRY_ABORT_BLOCK; } @@ -114,7 +112,7 @@ SetupMacApplicationDelegate() AutoAutoreleasePool pool; // Ensure that ProcessPendingGetURLAppleEvents() doesn't regress bug 377166. - [GeckoNSApplication sharedApplication]; + [NSApplication 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 diff --git a/toolkit/xre/Makefile.in b/toolkit/xre/Makefile.in index 648b29476660..4507fc1eb0a4 100644 --- a/toolkit/xre/Makefile.in +++ b/toolkit/xre/Makefile.in @@ -66,10 +66,6 @@ CPPSRCS = \ nsSigHandlers.cpp \ $(NULL) -ifdef MOZ_INSTRUMENT_EVENT_LOOP -CPPSRCS += EventTracer.cpp -endif - ifdef MOZ_SPLASHSCREEN ifeq ($(OS_ARCH),WINCE) CPPSRCS += nsSplashScreenWin.cpp diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 8b4db05235f3..a47192f65001 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -62,10 +62,6 @@ using mozilla::dom::ContentParent; #include "nsAppRunner.h" #include "nsUpdateDriver.h" -#ifdef MOZ_INSTRUMENT_EVENT_LOOP -#include "EventTracer.h" -#endif - #ifdef XP_MACOSX #include "MacLaunchHelper.h" #include "MacApplicationDelegate.h" @@ -3748,13 +3744,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) nativeApp->Enable(); } -#ifdef MOZ_INSTRUMENT_EVENT_LOOP - bool event_tracing_running = false; - if (PR_GetEnv("MOZ_INSTRUMENT_EVENT_LOOP")) { - event_tracing_running = mozilla::InitEventTracing(); - } -#endif /* MOZ_INSTRUMENT_EVENT_LOOP */ - NS_TIME_FUNCTION_MARK("Next: Run"); NS_TIME_FUNCTION_MARK("appStartup->Run"); @@ -3774,11 +3763,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_TIME_FUNCTION_MARK("appStartup->Run done"); -#ifdef MOZ_INSTRUMENT_EVENT_LOOP - if (event_tracing_running) - mozilla::ShutdownEventTracing(); -#endif - // Check for an application initiated restart. This is one that // corresponds to nsIAppStartup.quit(eRestart) if (rv == NS_SUCCESS_RESTART_APP) diff --git a/widget/public/Makefile.in b/widget/public/Makefile.in index 92dd0bbbd746..30383b9e7a8b 100644 --- a/widget/public/Makefile.in +++ b/widget/public/Makefile.in @@ -46,17 +46,12 @@ MODULE = widget XPIDL_MODULE = widget GRE_MODULE = 1 -EXPORTS_NAMESPACES = IPC mozilla +EXPORTS_NAMESPACES = IPC EXPORTS_IPC = \ nsGUIEventIPC.h \ $(NULL) -ifdef MOZ_INSTRUMENT_EVENT_LOOP -EXPORTS_mozilla = \ - WidgetTraceEvent.h -endif - EXPORTS = \ nsIWidget.h \ nsGUIEvent.h \ diff --git a/widget/public/WidgetTraceEvent.h b/widget/public/WidgetTraceEvent.h deleted file mode 100644 index 80ca85b85a51..000000000000 --- a/widget/public/WidgetTraceEvent.h +++ /dev/null @@ -1,53 +0,0 @@ -/* ***** 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 - * - * 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 ***** */ - -#ifndef WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ -#define WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ - -namespace mozilla { - -// Fire a tracer event at the UI-thread event loop, and block until -// the event is processed. This should only be called by -// a thread that's not the UI thread. -bool FireAndWaitForTracerEvent(); - -// Signal that the event has been received by the event loop. -void SignalTracerThread(); - -} - -#endif // WIDGET_PUBLIC_WIDGETTRACEEVENT_H_ diff --git a/widget/src/cocoa/CustomCocoaEvents.h b/widget/src/cocoa/CustomCocoaEvents.h deleted file mode 100644 index f4ccf779f84a..000000000000 --- a/widget/src/cocoa/CustomCocoaEvents.h +++ /dev/null @@ -1,51 +0,0 @@ -/* ***** 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 - * - * 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_ */ diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index e5806ee0564a..d7965d21dfde 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -60,41 +60,40 @@ 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 \ - WidgetTraceEvent.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 \ + $(NULL) ifeq (x86_64,$(TARGET_CPU)) CMMSRCS += ComplexTextInputPanel.mm diff --git a/widget/src/cocoa/WidgetTraceEvent.mm b/widget/src/cocoa/WidgetTraceEvent.mm deleted file mode 100644 index f904a147c261..000000000000 --- a/widget/src/cocoa/WidgetTraceEvent.mm +++ /dev/null @@ -1,92 +0,0 @@ -/* ***** 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 - * - * 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 -#include "CustomCocoaEvents.h" -#include -#include -#include -#include "mozilla/WidgetTraceEvent.h" - -using mozilla::CondVar; -using mozilla::Mutex; -using mozilla::MutexAutoLock; - -namespace { - -Mutex sMutex("Event tracer thread mutex"); -CondVar sCondVar(sMutex, "Event tracer thread condvar"); -bool sTracerProcessed; - -} - -namespace mozilla { - -// 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() -{ - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - MutexAutoLock lock(sMutex); - sTracerProcessed = false; - // 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(); - [pool release]; - return true; -} - -} // namespace mozilla diff --git a/widget/src/cocoa/nsAppShell.mm b/widget/src/cocoa/nsAppShell.mm index f128e5acdd02..0491a8bef31f 100644 --- a/widget/src/cocoa/nsAppShell.mm +++ b/widget/src/cocoa/nsAppShell.mm @@ -43,8 +43,6 @@ #import #include -#include "CustomCocoaEvents.h" -#include "mozilla/WidgetTraceEvent.h" #include "nsAppShell.h" #include "nsCOMPtr.h" #include "nsIFile.h" @@ -171,27 +169,6 @@ 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 @@ -309,7 +286,7 @@ nsAppShell::Init() [NSBundle loadNibFile: [NSString stringWithUTF8String:(const char*)nibPath.get()] externalNameTable: - [NSDictionary dictionaryWithObject:[GeckoNSApplication sharedApplication] + [NSDictionary dictionaryWithObject:[NSApplication sharedApplication] forKey:@"NSOwner"] withZone:NSDefaultMallocZone()]; @@ -411,7 +388,7 @@ nsAppShell::ProcessGeckoEvents(void* aInfo) timestamp:0 windowNumber:0 context:NULL - subtype:kEventSubtypeNone + subtype:0 data1:0 data2:0] atStart:NO]; @@ -433,7 +410,7 @@ nsAppShell::ProcessGeckoEvents(void* aInfo) timestamp:0 windowNumber:0 context:NULL - subtype:kEventSubtypeNone + subtype:0 data1:0 data2:0] atStart:NO]; diff --git a/widget/src/gtk2/Makefile.in b/widget/src/gtk2/Makefile.in index ad75f29de139..a8351d8f9d84 100644 --- a/widget/src/gtk2/Makefile.in +++ b/widget/src/gtk2/Makefile.in @@ -62,24 +62,23 @@ ifdef ACCESSIBILITY CSRCS += maiRedundantObjectFactory.c endif -CPPSRCS = \ - nsWindow.cpp \ - nsAppShell.cpp \ - nsWidgetFactory.cpp \ - nsToolkit.cpp \ - nsBidiKeyboard.cpp \ - nsLookAndFeel.cpp \ - nsGtkKeyUtils.cpp \ - nsFilePicker.cpp \ - nsSound.cpp \ - nsNativeKeyBindings.cpp \ - nsScreenGtk.cpp \ - nsScreenManagerGtk.cpp \ - nsImageToPixbuf.cpp \ - nsAccessibilityHelper.cpp \ - nsGtkIMModule.cpp \ - WidgetTraceEvent.cpp \ - $(NULL) +CPPSRCS = \ + nsWindow.cpp \ + nsAppShell.cpp \ + nsWidgetFactory.cpp \ + nsToolkit.cpp \ + nsBidiKeyboard.cpp \ + nsLookAndFeel.cpp \ + nsGtkKeyUtils.cpp \ + nsFilePicker.cpp \ + nsSound.cpp \ + nsNativeKeyBindings.cpp \ + nsScreenGtk.cpp \ + nsScreenManagerGtk.cpp \ + nsImageToPixbuf.cpp \ + nsAccessibilityHelper.cpp \ + nsGtkIMModule.cpp \ + $(NULL) ifdef MOZ_X11 CPPSRCS += nsIdleServiceGTK.cpp diff --git a/widget/src/gtk2/WidgetTraceEvent.cpp b/widget/src/gtk2/WidgetTraceEvent.cpp deleted file mode 100644 index 95753ae3b230..000000000000 --- a/widget/src/gtk2/WidgetTraceEvent.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* ***** 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 - * - * 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 "mozilla/WidgetTraceEvent.h" - -#include -#include -#include -#include - -using mozilla::CondVar; -using mozilla::Mutex; -using mozilla::MutexAutoLock; - -namespace { - -Mutex sMutex("Event tracer thread mutex"); -CondVar sCondVar(sMutex, "Event tracer thread condvar"); -bool sTracerProcessed = false; - -// This function is called from the main (UI) thread. -gboolean TracerCallback(gpointer data) -{ - MutexAutoLock lock(sMutex); - NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong"); - sTracerProcessed = true; - sCondVar.Notify(); - return FALSE; -} - -} // namespace - -namespace mozilla { - -// This function is called from the background tracer thread. -bool FireAndWaitForTracerEvent() -{ - // Send a default-priority idle event through the - // event loop, and wait for it to finish. - MutexAutoLock lock(sMutex); - NS_ABORT_IF_FALSE(!sTracerProcessed, "Tracer synchronization state is wrong"); - g_idle_add_full(G_PRIORITY_DEFAULT, - TracerCallback, - NULL, - NULL); - while (!sTracerProcessed) - sCondVar.Wait(); - sTracerProcessed = false; - return true; -} - -} // namespace mozilla diff --git a/widget/src/windows/Makefile.in b/widget/src/windows/Makefile.in index ba09e342de5b..876fb6c165fe 100644 --- a/widget/src/windows/Makefile.in +++ b/widget/src/windows/Makefile.in @@ -47,33 +47,32 @@ LIBRARY_NAME = widget_windows LIBXUL_LIBRARY = 1 -CPPSRCS = \ - nsWindow.cpp \ - nsWindowGfx.cpp \ - nsWindowDbg.cpp \ - nsAppShell.cpp \ - nsToolkit.cpp \ - nsFilePicker.cpp \ - nsScreenWin.cpp \ - nsScreenManagerWin.cpp \ - nsLookAndFeel.cpp \ - nsUXThemeData.cpp \ - nsNativeThemeWin.cpp \ - nsWinGesture.cpp \ - nsIdleServiceWin.cpp \ - nsSound.cpp \ - nsIMM32Handler.cpp \ - WindowHook.cpp \ - WinTaskbar.cpp \ - TaskbarPreview.cpp \ - TaskbarTabPreview.cpp \ - TaskbarWindowPreview.cpp \ - TaskbarPreviewButton.cpp \ - JumpListBuilder.cpp \ - JumpListItem.cpp \ - GfxInfo.cpp \ - WidgetTraceEvent.cpp \ - $(NULL) +CPPSRCS = \ + nsWindow.cpp \ + nsWindowGfx.cpp \ + nsWindowDbg.cpp \ + nsAppShell.cpp \ + nsToolkit.cpp \ + nsFilePicker.cpp \ + nsScreenWin.cpp \ + nsScreenManagerWin.cpp \ + nsLookAndFeel.cpp \ + nsUXThemeData.cpp \ + nsNativeThemeWin.cpp \ + nsWinGesture.cpp \ + nsIdleServiceWin.cpp \ + nsSound.cpp \ + nsIMM32Handler.cpp \ + WindowHook.cpp \ + WinTaskbar.cpp \ + TaskbarPreview.cpp \ + TaskbarTabPreview.cpp \ + TaskbarWindowPreview.cpp \ + TaskbarPreviewButton.cpp \ + JumpListBuilder.cpp \ + JumpListItem.cpp \ + GfxInfo.cpp \ + $(NULL) ifdef MOZ_CRASHREPORTER CPPSRCS += LSPAnnotator.cpp diff --git a/widget/src/windows/WidgetTraceEvent.cpp b/widget/src/windows/WidgetTraceEvent.cpp deleted file mode 100644 index 0e2f629e180a..000000000000 --- a/widget/src/windows/WidgetTraceEvent.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* ***** 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 - * - * 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 ***** */ - -/* - * Windows widget support for event loop instrumentation. - * See toolkit/xre/EventTracer.cpp for more details. - */ - -#include -#include - -#include "mozilla/WidgetTraceEvent.h" -#include "nsAppShellCID.h" -#include "nsComponentManagerUtils.h" -#include "nsCOMPtr.h" -#include "nsIAppShellService.h" -#include "nsIBaseWindow.h" -#include "nsIDocShell.h" -#include "nsIWidget.h" -#include "nsIXULWindow.h" -#include "nsAutoPtr.h" -#include "nsServiceManagerUtils.h" -#include "nsThreadUtils.h" -#include "nsWindowDefs.h" - -namespace { - -// Used for signaling the background thread from the main thread. -HANDLE event_handle = NULL; - -// We need a runnable in order to find the hidden window on the main -// thread. -class HWNDGetter : public nsRunnable { -public: - HWNDGetter() : hidden_window_hwnd(NULL) {} - - HWND hidden_window_hwnd; - - NS_IMETHOD Run() { - // Jump through some hoops to locate the hidden window. - nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); - nsCOMPtr hiddenWindow; - - nsresult rv = appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow)); - if (NS_FAILED(rv)) { - return rv; - } - - nsCOMPtr docShell; - rv = hiddenWindow->GetDocShell(getter_AddRefs(docShell)); - if (NS_FAILED(rv) || !docShell) { - return rv; - } - - nsCOMPtr baseWindow(do_QueryInterface(docShell)); - - if (!baseWindow) - return NS_ERROR_FAILURE; - - nsCOMPtr widget; - baseWindow->GetMainWidget(getter_AddRefs(widget)); - - if (!widget) - return NS_ERROR_FAILURE; - - hidden_window_hwnd = (HWND)widget->GetNativeData(NS_NATIVE_WINDOW); - - return NS_OK; - } -}; - -HWND GetHiddenWindowHWND() -{ - // Need to dispatch this to the main thread because plenty of - // the things it wants to access are main-thread-only. - nsRefPtr getter = new HWNDGetter(); - NS_DispatchToMainThread(getter, NS_DISPATCH_SYNC); - return getter->hidden_window_hwnd; -} - -} // namespace - -namespace mozilla { - -// This function is called from the main (UI) thread. -void SignalTracerThread() -{ - if (event_handle != NULL) - SetEvent(event_handle); -} - -// This function is called from the background tracer thread. -bool FireAndWaitForTracerEvent() -{ - // First, try to find the hidden window. - static HWND hidden_window = NULL; - if (hidden_window == NULL) { - hidden_window = GetHiddenWindowHWND(); - } - - if (hidden_window == NULL) - return false; - - if (event_handle == NULL) - event_handle = CreateEvent(NULL, FALSE, FALSE, NULL); - - // Post the tracer message into the hidden window's message queue, - // and then block until it's processed. - PostMessage(hidden_window, MOZ_WM_TRACE, 0, 0); - WaitForSingleObject(event_handle, INFINITE); - return true; -} - -} // namespace mozilla diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 18c253a170f1..4284ef3fd1ae 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -118,7 +118,6 @@ #include "prprf.h" #include "prmem.h" -#include "mozilla/WidgetTraceEvent.h" #include "nsIAppShell.h" #include "nsISupportsPrimitives.h" #include "nsIDOMNSUIEvent.h" @@ -4597,13 +4596,6 @@ LRESULT CALLBACK nsWindow::WindowProcInternal(HWND hWnd, UINT msg, WPARAM wParam } } - if (msg == MOZ_WM_TRACE) { - // This is a tracer event for measuring event loop latency. - // See WidgetTraceEvent.cpp for more details. - mozilla::SignalTracerThread(); - return 0; - } - // Get the window which caused the event and ask it to process the message nsWindow *someWindow = GetNSWindowPtr(hWnd); diff --git a/widget/src/windows/nsWindowDefs.h b/widget/src/windows/nsWindowDefs.h index 8856b47e4cef..1dc97098a804 100644 --- a/widget/src/windows/nsWindowDefs.h +++ b/widget/src/windows/nsWindowDefs.h @@ -56,8 +56,6 @@ // A magic APP message that can be sent to quit, sort of like a QUERYENDSESSION/ENDSESSION, // but without the query. #define MOZ_WM_APP_QUIT (WM_APP+0x0300) -// Used as a "tracer" event to probe event loop latency. -#define MOZ_WM_TRACE (WM_APP+0x0301) // GetWindowsVersion constants #define WIN2K_VERSION 0x500 From 9144e54f54c034344a26cf14d2d96c4736f4ec00 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Wed, 2 Mar 2011 22:32:58 +0100 Subject: [PATCH 28/57] Bug 638143 - Internal html:input of XUL numberbox shouldn't have type='number'. r=enndeakin --- toolkit/content/widgets/numberbox.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolkit/content/widgets/numberbox.xml b/toolkit/content/widgets/numberbox.xml index 82c8e62079ef..fab66a345541 100644 --- a/toolkit/content/widgets/numberbox.xml +++ b/toolkit/content/widgets/numberbox.xml @@ -16,7 +16,7 @@ + xbl:inherits="onfocus,onblur,value,maxlength,disabled,size,readonly,placeholder,tabindex,accesskey"/> From da55dc6c2746c33e7c2d21f61933528fcb710d10 Mon Sep 17 00:00:00 2001 From: Klaus Ernst Date: Wed, 13 Apr 2011 12:57:46 -0700 Subject: [PATCH 29/57] Bug 640601: Allow Flash 10.2+ to load OOP on more Mac OS X machines. r=josh --- modules/plugin/base/src/nsNPAPIPlugin.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/plugin/base/src/nsNPAPIPlugin.cpp b/modules/plugin/base/src/nsNPAPIPlugin.cpp index 3ddb0e21bb3f..7ee47d0d5ee1 100644 --- a/modules/plugin/base/src/nsNPAPIPlugin.cpp +++ b/modules/plugin/base/src/nsNPAPIPlugin.cpp @@ -329,6 +329,7 @@ nsNPAPIPlugin::RunPluginOOP(const nsPluginTag *aPluginTag) // Blacklist Flash 10.0 or lower since it may try to negotiate Carbon/Quickdraw // which are not supported out of process. Also blacklist Flash 10.1 if this // machine has an Intel GMA9XX GPU because Flash will negotiate Quickdraw graphics. + // Never blacklist Flash >= 10.2. if (aPluginTag->mFileName.EqualsIgnoreCase("flash player.plugin")) { // If the first '.' is before position 2 or the version // starts with 10.0 then we are dealing with Flash 10 or less. @@ -341,12 +342,9 @@ nsNPAPIPlugin::RunPluginOOP(const nsPluginTag *aPluginTag) if (versionPrefix.EqualsASCII("10.0")) { return PR_FALSE; } - } - - // At this point we have Flash 10.1+ but now we also need to blacklist - // if the machine has a Intel GMA9XX GPU. - if (GMA9XXGraphics()) { - return PR_FALSE; + if (versionPrefix.EqualsASCII("10.1") && GMA9XXGraphics()) { + return PR_FALSE; + } } } #endif From 64b169ed5f6edbd132d99be3f6e587302be8e642 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Wed, 13 Apr 2011 21:25:58 +0100 Subject: [PATCH 30/57] bug 649678 - include the build date in About window for a# versions. r=dao --- browser/base/content/aboutDialog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/base/content/aboutDialog.js b/browser/base/content/aboutDialog.js index 4d00acca6be1..8ceb09ecfdd5 100644 --- a/browser/base/content/aboutDialog.js +++ b/browser/base/content/aboutDialog.js @@ -65,9 +65,9 @@ function init(aEvent) // Pref is unset } - // Include the build ID if this is a "pre" (i.e. non-release) build + // Include the build ID if this is an "a#" (nightly or aurora) build let version = Services.appinfo.version; - if (version.indexOf("pre") != -1) { + if (/a\d+$/.test(version)) { let buildID = Services.appinfo.appBuildID; let buildDate = buildID.slice(0,4) + "-" + buildID.slice(4,6) + "-" + buildID.slice(6,8); document.getElementById("version").value += " (" + buildDate + ")"; From be80ac146994c602e824a81fa70ca56ca6cd4e66 Mon Sep 17 00:00:00 2001 From: Robert Strong Date: Wed, 13 Apr 2011 13:52:55 -0700 Subject: [PATCH 31/57] Bug 649754 - update dialog no longer centered. r=mossop --- toolkit/mozapps/update/updater/progressui_win.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/toolkit/mozapps/update/updater/progressui_win.cpp b/toolkit/mozapps/update/updater/progressui_win.cpp index 84af536258de..d8a73a03930f 100644 --- a/toolkit/mozapps/update/updater/progressui_win.cpp +++ b/toolkit/mozapps/update/updater/progressui_win.cpp @@ -204,6 +204,8 @@ InitDialog(HWND hDlg) ReleaseDC(hWndInfo, hDCInfo); + CenterDialog(hDlg); // make dialog appear in the center of the screen + SetTimer(hDlg, TIMER_ID, TIMER_INTERVAL, NULL); } From 5dbc4242ca4b1be36695a8f4bc038d40999d091c Mon Sep 17 00:00:00 2001 From: Benjamin Stover Date: Wed, 13 Apr 2011 14:12:22 -0700 Subject: [PATCH 32/57] Bug 649583 Panning regression on google reader in 2011-04-12 nightly r=roc --- layout/base/FrameLayerBuilder.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/layout/base/FrameLayerBuilder.cpp b/layout/base/FrameLayerBuilder.cpp index 006ebfdb7a8e..3c46e9755cd2 100644 --- a/layout/base/FrameLayerBuilder.cpp +++ b/layout/base/FrameLayerBuilder.cpp @@ -1314,15 +1314,23 @@ ContainerState::ProcessDisplayItems(const nsDisplayList& aList, // Assign the item to a layer if (layerState == LAYER_ACTIVE_FORCE || + layerState == LAYER_ACTIVE_EMPTY || layerState == LAYER_ACTIVE && (aClip.mRoundedClipRects.IsEmpty() || // We can use the visible rect here only because the item has its own // layer, like the comment below. !aClip.IsRectClippedByRoundedCorner(item->GetVisibleRect()))) { + + // LAYER_ACTIVE_EMPTY means the layer is created just for its metadata. + // We should never see an empty layer with any visible content! + NS_ASSERTION(layerState != LAYER_ACTIVE_EMPTY || + itemVisibleRect.IsEmpty(), + "State is LAYER_ACTIVE_EMPTY but visible rect is not."); + // If the item would have its own layer but is invisible, just hide it. // Note that items without their own layers can't be skipped this // way, since their ThebesLayer may decide it wants to draw them // into its buffer even if they're currently covered. - if (itemVisibleRect.IsEmpty()) { + if (itemVisibleRect.IsEmpty() && layerState != LAYER_ACTIVE_EMPTY) { InvalidateForLayerChange(item, nsnull); continue; } From 6e8a05de6b59ea7af87cd7ab495597f36b75f232 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Wed, 13 Apr 2011 12:43:34 -0700 Subject: [PATCH 33/57] Bug 635749 - Don't assume we can press ENTER on an to submit a form. r=bz,smaug --HG-- extra : rebase_source : 85b73e61002ebc3c68cfff3363afb29b448c6121 --- .../html/content/src/nsHTMLInputElement.cpp | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index ae34a8572f89..09214bebe747 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -2310,8 +2310,7 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) } /* - * If this is input type=text, and the user hit enter, fire onChange - * and submit the form (if we are in one) + * For some input types, if the user hits enter, the form is submitted. * * Bug 99920, bug 109463 and bug 147850: * (a) if there is a submit control in the form, click the first @@ -2325,42 +2324,19 @@ nsHTMLInputElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor) if (aVisitor.mEvent->message == NS_KEY_PRESS && (keyEvent->keyCode == NS_VK_RETURN || keyEvent->keyCode == NS_VK_ENTER) && - (mType == NS_FORM_INPUT_TEXT || - mType == NS_FORM_INPUT_EMAIL || - mType == NS_FORM_INPUT_SEARCH || - mType == NS_FORM_INPUT_PASSWORD || - mType == NS_FORM_INPUT_TEL || - mType == NS_FORM_INPUT_URL || - mType == NS_FORM_INPUT_FILE)) { + IsSingleLineTextControl(PR_FALSE, mType)) { + nsIFrame* primaryFrame = GetPrimaryFrame(); + if (primaryFrame) { + nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame); - PRBool isButton = PR_FALSE; - // If this is an enter on the button of a file input, don't submit - // -- that's supposed to put up the filepicker - if (mType == NS_FORM_INPUT_FILE) { - nsCOMPtr maybeButton = - do_QueryInterface(aVisitor.mEvent->originalTarget); - if (maybeButton) { - isButton = maybeButton->AttrValueIs(kNameSpaceID_None, - nsGkAtoms::type, - nsGkAtoms::button, - eCaseMatters); + // Fire onChange (if necessary) + if (textFrame) { + textFrame->CheckFireOnChange(); } } - if (!isButton) { - nsIFrame* primaryFrame = GetPrimaryFrame(); - if (primaryFrame) { - nsITextControlFrame* textFrame = do_QueryFrame(primaryFrame); - - // Fire onChange (if necessary) - if (textFrame) { - textFrame->CheckFireOnChange(); - } - } - - rv = MaybeSubmitForm(aVisitor.mPresContext); - NS_ENSURE_SUCCESS(rv, rv); - } + rv = MaybeSubmitForm(aVisitor.mPresContext); + NS_ENSURE_SUCCESS(rv, rv); } } break; // NS_KEY_PRESS || NS_KEY_UP From 3815106388cf692d7cad21958183764b97b71f2d Mon Sep 17 00:00:00 2001 From: Jonas Sicking Date: Wed, 13 Apr 2011 14:34:36 -0700 Subject: [PATCH 34/57] Bug 649672: Make File.slice arguments match Array.slice and prefix File.slice. r=khuey --- content/base/public/nsDOMFile.h | 7 +- content/base/public/nsIDOMFile.idl | 14 +- content/base/src/nsDOMFile.cpp | 71 +++++++-- content/base/test/test_fileapi_slice.html | 169 ++++++++++------------ dom/base/nsDOMClassInfo.cpp | 2 + 5 files changed, 150 insertions(+), 113 deletions(-) diff --git a/content/base/public/nsDOMFile.h b/content/base/public/nsDOMFile.h index 3cc4c57621a6..c75915925dba 100644 --- a/content/base/public/nsDOMFile.h +++ b/content/base/public/nsDOMFile.h @@ -57,6 +57,7 @@ class nsIInputStream; class nsIClassInfo; class nsDOMFile : public nsIDOMFile, + public nsIDOMBlob_MOZILLA_2_0_BRANCH, public nsIXHRSendable, public nsICharsetDetectionObserver { @@ -64,6 +65,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIDOMBLOB NS_DECL_NSIDOMFILE + NS_DECL_NSIDOMBLOB_MOZILLA_2_0_BRANCH NS_DECL_NSIXHRSENDABLE nsDOMFile(nsIFile *aFile, const nsAString& aContentType) @@ -149,8 +151,9 @@ public: NS_IMETHOD GetSize(PRUint64*); NS_IMETHOD GetInternalStream(nsIInputStream**); NS_IMETHOD GetMozFullPathInternal(nsAString&); - NS_IMETHOD Slice(PRUint64 aStart, PRUint64 aLength, - const nsAString& aContentType, nsIDOMBlob **aBlob); + NS_IMETHOD MozSlice(PRInt64 aStart, PRInt64 aEnd, + const nsAString& aContentType, PRUint8 optional_argc, + nsIDOMBlob **aBlob); protected: friend class DataOwnerAdapter; // Needs to see DataOwner diff --git a/content/base/public/nsIDOMFile.idl b/content/base/public/nsIDOMFile.idl index 9cb5bdca0418..57506b6acf5a 100644 --- a/content/base/public/nsIDOMFile.idl +++ b/content/base/public/nsIDOMFile.idl @@ -49,9 +49,9 @@ interface nsIDOMBlob : nsISupports readonly attribute unsigned long long size; readonly attribute DOMString type; - nsIDOMBlob slice(in unsigned long long start, - in unsigned long long length, - [optional] in DOMString contentType); + [noscript] nsIDOMBlob slice(in unsigned long long start, + in unsigned long long length, + [optional] in DOMString contentType); [noscript] readonly attribute nsIInputStream internalStream; // The caller is responsible for releasing the internalUrl from the @@ -59,6 +59,14 @@ interface nsIDOMBlob : nsISupports [noscript] DOMString getInternalUrl(in nsIPrincipal principal); }; +[scriptable, uuid(cb5b4191-a555-4e57-b8d2-88091184b59f)] +interface nsIDOMBlob_MOZILLA_2_0_BRANCH : nsISupports +{ + [optional_argc] nsIDOMBlob mozSlice(in long long start, + [optional] in long long end, + [optional] in DOMString contentType); +}; + [scriptable, uuid(ae1405b0-e411-481e-9606-b29ec7982687)] interface nsIDOMFile : nsIDOMBlob { diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index d22f004826d3..62d5003f918a 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -139,6 +139,7 @@ DOMCI_DATA(Blob, nsDOMFile) NS_INTERFACE_MAP_BEGIN(nsDOMFile) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile) NS_INTERFACE_MAP_ENTRY(nsIDOMBlob) + NS_INTERFACE_MAP_ENTRY(nsIDOMBlob_MOZILLA_2_0_BRANCH) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, mIsFullFile) NS_INTERFACE_MAP_ENTRY(nsIXHRSendable) NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver) @@ -245,23 +246,54 @@ nsDOMFile::GetType(nsAString &aType) return NS_OK; } -// Makes sure that aStart and aStart + aLength is less then or equal to aSize +// Makes sure that aStart and aEnd is less then or equal to aSize and greater +// than 0 void -ClampToSize(PRUint64 aSize, PRUint64& aStart, PRUint64& aLength) +ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd) { - if (aStart > aSize) { - aStart = aLength = 0; + CheckedInt64 newStartOffset = aStart; + if (aStart < -aSize) { + newStartOffset = 0; } - CheckedUint64 endOffset = aStart; - endOffset += aLength; - if (!endOffset.valid() || endOffset.value() > aSize) { - aLength = aSize - aStart; + else if (aStart < 0) { + newStartOffset += aSize; + } + else if (aStart > aSize) { + newStartOffset = aSize; + } + + CheckedInt64 newEndOffset = aEnd; + if (aEnd < -aSize) { + newEndOffset = 0; + } + else if (aEnd < 0) { + newEndOffset += aSize; + } + else if (aEnd > aSize) { + newEndOffset = aSize; + } + + if (!newStartOffset.valid() || !newEndOffset.valid() || + newStartOffset.value() >= newEndOffset.value()) { + aStart = aEnd = 0; + } + else { + aStart = newStartOffset.value(); + aEnd = newEndOffset.value(); } } NS_IMETHODIMP nsDOMFile::Slice(PRUint64 aStart, PRUint64 aLength, const nsAString& aContentType, nsIDOMBlob **aBlob) +{ + return MozSlice(aStart, aStart + aLength, aContentType, 2, aBlob); +} + +NS_IMETHODIMP +nsDOMFile::MozSlice(PRInt64 aStart, PRInt64 aEnd, + const nsAString& aContentType, PRUint8 optional_argc, + nsIDOMBlob **aBlob) { *aBlob = nsnull; @@ -269,10 +301,15 @@ nsDOMFile::Slice(PRUint64 aStart, PRUint64 aLength, PRUint64 thisLength; nsresult rv = GetSize(&thisLength); NS_ENSURE_SUCCESS(rv, rv); - ClampToSize(thisLength, aStart, aLength); + + if (!optional_argc) { + aEnd = (PRInt64)thisLength; + } + + ParseSize((PRInt64)thisLength, aStart, aEnd); // Create the new file - NS_ADDREF(*aBlob = new nsDOMFile(this, aStart, aLength, aContentType)); + NS_ADDREF(*aBlob = new nsDOMFile(this, aStart, aEnd - aStart, aContentType)); return NS_OK; } @@ -627,16 +664,22 @@ nsDOMMemoryFile::GetSize(PRUint64 *aFileSize) } NS_IMETHODIMP -nsDOMMemoryFile::Slice(PRUint64 aStart, PRUint64 aLength, - const nsAString& aContentType, nsIDOMBlob **aBlob) +nsDOMMemoryFile::MozSlice(PRInt64 aStart, PRInt64 aEnd, + const nsAString& aContentType, PRUint8 optional_argc, + nsIDOMBlob **aBlob) { *aBlob = nsnull; + if (!optional_argc) { + aEnd = (PRInt64)mLength; + } + // Truncate aLength and aStart so that we stay within this file. - ClampToSize(mLength, aStart, aLength); + ParseSize((PRInt64)mLength, aStart, aEnd); // Create the new file - NS_ADDREF(*aBlob = new nsDOMMemoryFile(this, aStart, aLength, aContentType)); + NS_ADDREF(*aBlob = new nsDOMMemoryFile(this, aStart, aEnd - aStart, + aContentType)); return NS_OK; } diff --git a/content/base/test/test_fileapi_slice.html b/content/base/test/test_fileapi_slice.html index eedbec790d1f..e971927acfb0 100644 --- a/content/base/test/test_fileapi_slice.html +++ b/content/base/test/test_fileapi_slice.html @@ -69,104 +69,83 @@ ok(size > 65536, "test data sufficiently large"); // Test that basic properties work -function testBasics(file, size, type) { - is(file.type, type, "[B0] mozGetAsFile type"); - is(file.size, size, "[B0] file is correct size"); - ok(file instanceof File, "[B0] file is a File"); - ok(file instanceof Blob, "[B0] file is also a Blob"); +function testFile(file, size, type, contents, fileType) { + is(file.type, type, fileType + " file is correct type"); + is(file.size, size, fileType + " file is correct size"); + ok(file instanceof File, fileType + " file is a File"); + ok(file instanceof Blob, fileType + " file is also a Blob"); - var slice = file.slice(0, size); - is(slice.type, "", "[B1] full-size type"); - is(slice.size, size, "[B1] full-size size"); - ok(slice instanceof Blob, "[B1] slice is a Blob"); - ok(!(slice instanceof File), "[B1] slice is not a File"); + var slice = file.mozSlice(0, size); + ok(slice instanceof Blob, fileType + " fullsize slice is a Blob"); + ok(!(slice instanceof File), fileType + " fullsize slice is not a File"); - slice = file.slice(0, 1234); - is(slice.type, "", "[B2] sized type"); - is(slice.size, 1234, "[B2] sized size"); - ok(slice instanceof Blob, "[B2] slice is a Blob"); - ok(!(slice instanceof File), "[B2] slice is not a File"); + slice = file.mozSlice(0, 1234); + ok(slice instanceof Blob, fileType + " sized slice is a Blob"); + ok(!(slice instanceof File), fileType + " sized slice is not a File"); - slice = file.slice(size-500, 1000); - is(slice.type, "", "[B3] end-sized type"); - is(slice.size, 500, "[B3] end-sized size"); - - slice = file.slice(size+500, 1000); - is(slice.type, "", "[B4] sized type"); - is(slice.size, 0, "[B4] sized size"); + slice = file.mozSlice(0, size, "foo/bar"); + is(slice.type, "foo/bar", fileType + " fullsize slice foo/bar type"); - slice = file.slice(0, 0); - is(slice.type, "", "[B5] sized type"); - is(slice.size, 0, "[B5] sized size"); - - slice = file.slice(1000, 0); - is(slice.type, "", "[B6] sized type"); - is(slice.size, 0, "[B6] sized size"); + slice = file.mozSlice(0, 5432, "foo/bar"); + is(slice.type, "foo/bar", fileType + " sized slice foo/bar type"); - slice = file.slice(0, size, "foo/bar"); - is(slice.type, "foo/bar", "[B7] full-size foo/bar type"); - is(slice.size, size, "[B7] full-size foo/bar size"); + is(slice.mozSlice(0, 10).type, "", fileType + " slice-slice type"); + is(slice.mozSlice(0, 10).size, 10, fileType + " slice-slice size"); + is(slice.mozSlice(0, 10, "hello/world").type, "hello/world", fileType + " slice-slice hello/world type"); + is(slice.mozSlice(0, 10, "hello/world").size, 10, fileType + " slice-slice hello/world size"); - slice = file.slice(0, 5432, "foo/bar"); - is(slice.type, "foo/bar", "[B8] sized foo/bar type"); - is(slice.size, 5432, "[B8] sized foo/bar size"); + var indexes = [[0, size, size], + [0, 1234, 1234], + [size-500, size, 500], + [size-500, size+500, 500], + [size+500, size+1500, 0], + [0, 0, 0], + [1000, 1000, 0], + [size, size, 0], + [0, undefined, size], + [100, undefined, size-100], + [-100, undefined, 100], + [100, -100, size-200], + [-size-100, undefined, size], + [-2*size-100, 500, 500], + [0, -size-100, 0], + [100, -size-100, 0], + [50, -size+100, 50], + [0, 33000, 33000], + [1000, 34000, 33000], + ]; - is(slice.slice(0, 10).type, "", "[B9] slice-slice type"); - is(slice.slice(0, 10).size, 10, "[B9] slice-slice size"); - is(slice.slice(0, 10, "hello/world").type, "hello/world", "[B9] slice-slice hello/world type"); - is(slice.slice(0, 10, "hello/world").size, 10, "[B9] slice-slice hello/world type"); + for (var i = 0; i < indexes.length; ++i) { + var sliceContents; + var testName; + if (indexes[i][1] == undefined) { + slice = file.mozSlice(indexes[i][0]); + sliceContents = contents.slice(indexes[i][0]); + testName = fileType + " slice(" + indexes[i][0] + ")"; + } + else { + slice = file.mozSlice(indexes[i][0], indexes[i][1]); + sliceContents = contents.slice(indexes[i][0], indexes[i][1]); + testName = fileType + " slice(" + indexes[i][0] + ", " + indexes[i][1] + ")"; + } + is(slice.type, "", testName + " type"); + is(slice.size, indexes[i][2], testName + " size"); + is(sliceContents.length, indexes[i][2], testName + " data size"); + checkFileContents(slice, sliceContents, testName); + } + + // Slice of slice + var slice = file.mozSlice(0, 40000); + checkFileContents(slice.mozSlice(5000, 42000), contents.slice(5000, 40000), "file slice slice"); + + // ...of slice of slice + slice = slice.mozSlice(5000, 42000).mozSlice(400, 700); + gc(); + checkFileContents(slice, contents.slice(5400, 5700), "file slice slice slice"); } -testBasics(memFile, size, "image/png"); -testBasics(fileFile, size, ""); - - -// Test reading various slices - -// Full file -testFile(memFile, fileData, "mem file"); -testFile(fileFile, fileData, "file file"); - -// Simple slice -testFile(memFile.slice(0, 33000), fileData.substr(0, 33000), "mem file slice"); -testFile(fileFile.slice(0, 33000), fileData.substr(0, 33000), "file file slice"); - -// Simple slice not starting at beginning -testFile(memFile.slice(1000, 33000), fileData.substr(1000, 33000), "mem file slice starting at non-zero"); -testFile(fileFile.slice(1000, 33000), fileData.substr(1000, 33000), "file file slice starting at non-zero"); - -// Slice of slice -var memSlice = memFile.slice(0, 40000); -var fileSlice = fileFile.slice(0, 40000); -testFile(memSlice.slice(5000, 37000), fileData.substr(5000, 35000), "mem file slice slice"); -testFile(fileSlice.slice(5000, 37000), fileData.substr(5000, 35000), "file file slice slice"); - -// ...of slice of slice -memSlice = memSlice.slice(5000, 37000).slice(400, 300); -fileSlice = fileSlice.slice(5000, 37000).slice(400, 300); -gc(); -testFile(memSlice, fileData.substr(5400, 300), "mem file slice slice slice"); -testFile(fileSlice, fileData.substr(5400, 300), "file file slice slice slice"); - -// empty slice -testFile(memFile.slice(4711, 0), "", "mem file empty slice (1)"); -testFile(fileFile.slice(4711, 0), "", "file file empty slice (1)"); -testFile(memFile.slice(0, 0), "", "mem file empty slice (2)"); -testFile(fileFile.slice(0, 0), "", "file file empty slice (2)"); - -// slice at end -testFile(memFile.slice(size-1000, 1000), fileData.substr(size-1000, 1000), "mem file slice at end"); -testFile(fileFile.slice(size-1000, 1000), fileData.substr(size-1000, 1000), "file file slice at end"); - -// slice across end -testFile(memFile.slice(size-500, 1000), fileData.substr(size-500, 500), "mem file slice across end"); -testFile(fileFile.slice(size-500, 1000), fileData.substr(size-500, 500), "file file slice across end"); - -// slice past end -testFile(memFile.slice(size, 1000), "", "mem file slice past end (1)"); -testFile(fileFile.slice(size, 1000), "", "file file slice past end (1)"); -testFile(memFile.slice(size + 1000, 1000), "", "mem file slice past end (2)"); -testFile(fileFile.slice(size + 1000, 1000), "", "file file slice past end (2)"); +testFile(memFile, size, "image/png", fileData, "memFile"); +testFile(fileFile, size, "", fileData, "fileFile"); // Try loading directly from slice into an image @@ -202,7 +181,7 @@ function imageLoadHandler(event) { var imgfile = createFileWithData(testBinaryData + fileData + testBinaryData); is(imgfile.size, size + testBinaryData.length * 2, "correct file size (middle)"); var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size)); +img.src = URL.createObjectURL(imgfile.mozSlice(testBinaryData.length, testBinaryData.length + size)); img.onload = imageLoadHandler; expectedTestCount++; @@ -210,7 +189,7 @@ expectedTestCount++; var imgfile = createFileWithData(fileData + testBinaryData); is(imgfile.size, size + testBinaryData.length, "correct file size (start)"); var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(0, size)); +img.src = URL.createObjectURL(imgfile.mozSlice(0, size)); img.onload = imageLoadHandler; expectedTestCount++; @@ -218,7 +197,7 @@ expectedTestCount++; var imgfile = createFileWithData(testBinaryData + fileData); is(imgfile.size, size + testBinaryData.length, "correct file size (end)"); var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size)); +img.src = URL.createObjectURL(imgfile.mozSlice(testBinaryData.length, testBinaryData.length + size)); img.onload = imageLoadHandler; expectedTestCount++; @@ -226,13 +205,15 @@ expectedTestCount++; var imgfile = createFileWithData(testBinaryData + fileData); is(imgfile.size, size + testBinaryData.length, "correct file size (past end)"); var img = new Image; -img.src = URL.createObjectURL(imgfile.slice(testBinaryData.length, size + 1000)); +img.src = URL.createObjectURL(imgfile.mozSlice(testBinaryData.length, testBinaryData.length + size + 1000)); img.onload = imageLoadHandler; expectedTestCount++; // Utility functions -function testFile(file, contents, test) { +function checkFileContents(file, contents, test) { + SimpleTest.requestLongerTimeout(2); + // Load file using FileReader var r = new FileReader(); r.onload = getFileReaderLoadHandler(contents, contents.length, "FileReader.readAsBinaryString of " + test); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 15a5a8c0073d..ed094d25b4ee 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -3911,10 +3911,12 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_BEGIN(Blob, nsIDOMBlob) DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob_MOZILLA_2_0_BRANCH) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(File, nsIDOMFile) DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob_MOZILLA_2_0_BRANCH) DOM_CLASSINFO_MAP_ENTRY(nsIDOMFile) DOM_CLASSINFO_MAP_END From 5fe5cc8fd06c5fed5d91962e9df20718b2cdd326 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 14 Apr 2011 09:47:30 +1200 Subject: [PATCH 35/57] Bug 637207 - Make name & message on Error prototypes and message on Error instances not enumerable r=gal --- js/src/jsexn.cpp | 39 +++++-------------- js/src/tests/ecma_5/Exceptions/browser.js | 0 .../error-property-enumerability.js | 30 ++++++++++++++ js/src/tests/ecma_5/Exceptions/jstests.list | 2 + js/src/tests/ecma_5/Exceptions/shell.js | 0 js/src/tests/ecma_5/jstests.list | 1 + 6 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 js/src/tests/ecma_5/Exceptions/browser.js create mode 100644 js/src/tests/ecma_5/Exceptions/error-property-enumerability.js create mode 100644 js/src/tests/ecma_5/Exceptions/jstests.list create mode 100644 js/src/tests/ecma_5/Exceptions/shell.js diff --git a/js/src/jsexn.cpp b/js/src/jsexn.cpp index efca6b2b6f32..8524800ceb40 100644 --- a/js/src/jsexn.cpp +++ b/js/src/jsexn.cpp @@ -94,7 +94,7 @@ Class js_ErrorClass = { PropertyStub, /* delProperty */ PropertyStub, /* getProperty */ StrictPropertyStub, /* setProperty */ - exn_enumerate, + EnumerateStub, (JSResolveOp)exn_resolve, ConvertStub, exn_finalize, @@ -432,32 +432,6 @@ exn_finalize(JSContext *cx, JSObject *obj) } } -static JSBool -exn_enumerate(JSContext *cx, JSObject *obj) -{ - JSAtomState *atomState; - uintN i; - JSAtom *atom; - JSObject *pobj; - JSProperty *prop; - - JS_STATIC_ASSERT(sizeof(JSAtomState) <= (size_t)(uint16)-1); - static const uint16 offsets[] = { - (uint16)offsetof(JSAtomState, messageAtom), - (uint16)offsetof(JSAtomState, fileNameAtom), - (uint16)offsetof(JSAtomState, lineNumberAtom), - (uint16)offsetof(JSAtomState, stackAtom), - }; - - atomState = &cx->runtime->atomState; - for (i = 0; i != JS_ARRAY_LENGTH(offsets); ++i) { - atom = *(JSAtom **)((uint8 *)atomState + offsets[i]); - if (!js_LookupProperty(cx, obj, ATOM_TO_JSID(atom), &pobj, &prop)) - return JS_FALSE; - } - return JS_TRUE; -} - static JSBool exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSObject **objp) @@ -468,6 +442,7 @@ exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, JSString *stack; const char *prop; jsval v; + uintN attrs; *objp = NULL; priv = GetExnPrivate(cx, obj); @@ -487,6 +462,7 @@ exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, return true; v = STRING_TO_JSVAL(priv->message); + attrs = 0; goto define; } @@ -494,6 +470,7 @@ exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, if (str == atom) { prop = js_fileName_str; v = STRING_TO_JSVAL(priv->filename); + attrs = JSPROP_ENUMERATE; goto define; } @@ -501,6 +478,7 @@ exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, if (str == atom) { prop = js_lineNumber_str; v = INT_TO_JSVAL(priv->lineno); + attrs = JSPROP_ENUMERATE; goto define; } @@ -514,13 +492,14 @@ exn_resolve(JSContext *cx, JSObject *obj, jsid id, uintN flags, priv->stackDepth = 0; prop = js_stack_str; v = STRING_TO_JSVAL(stack); + attrs = JSPROP_ENUMERATE; goto define; } } return true; define: - if (!JS_DefineProperty(cx, obj, prop, v, NULL, NULL, JSPROP_ENUMERATE)) + if (!JS_DefineProperty(cx, obj, prop, v, NULL, NULL, attrs)) return false; *objp = obj; return true; @@ -1067,10 +1046,10 @@ js_InitExceptionClasses(JSContext *cx, JSObject *obj) JSAutoResolveFlags rf(cx, JSRESOLVE_QUALIFIED | JSRESOLVE_DECLARING); if (!js_DefineNativeProperty(cx, proto, nameId, StringValue(atom), PropertyStub, StrictPropertyStub, - JSPROP_ENUMERATE, 0, 0, NULL) || + 0, 0, 0, NULL) || !js_DefineNativeProperty(cx, proto, messageId, empty, PropertyStub, StrictPropertyStub, - JSPROP_ENUMERATE, 0, 0, NULL) || + 0, 0, 0, NULL) || !js_DefineNativeProperty(cx, proto, fileNameId, empty, PropertyStub, StrictPropertyStub, JSPROP_ENUMERATE, 0, 0, NULL) || diff --git a/js/src/tests/ecma_5/Exceptions/browser.js b/js/src/tests/ecma_5/Exceptions/browser.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/js/src/tests/ecma_5/Exceptions/error-property-enumerability.js b/js/src/tests/ecma_5/Exceptions/error-property-enumerability.js new file mode 100644 index 000000000000..c6674cfc572b --- /dev/null +++ b/js/src/tests/ecma_5/Exceptions/error-property-enumerability.js @@ -0,0 +1,30 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +var errors = ["Error", "EvalError", "RangeError", "ReferenceError", + "SyntaxError", "TypeError", "URIError"]; + +for (var i = 0; i < errors.length; i++) { + var error = this[errors[i]]; + + var desc = Object.getOwnPropertyDescriptor(error.prototype, "name"); + assertEq(!!desc, true, errors[i] + ".prototype.name should exist"); + assertEq((desc || {}).enumerable, false, errors[i] + ".prototype.name should not be enumerable"); + + desc = Object.getOwnPropertyDescriptor(error.prototype, "message"); + assertEq(!!desc, true, errors[i] + ".prototype.message should exist"); + assertEq((desc || {}).enumerable, false, errors[i] + ".prototype.message should not be enumerable"); + + var instance = new error; + desc = Object.getOwnPropertyDescriptor(instance, "message"); + assertEq(!!desc, false, "new " + errors[i] + ".message should not exist"); + + instance = new error("a message"); + desc = Object.getOwnPropertyDescriptor(instance, "message"); + assertEq(!!desc, true, "new " + errors[i] + "(...).message should exist"); + assertEq((desc || {}).enumerable, false, "new " + errors[i] + "(...).message should not be enumerable"); +} + +reportCompare(true, true); diff --git a/js/src/tests/ecma_5/Exceptions/jstests.list b/js/src/tests/ecma_5/Exceptions/jstests.list new file mode 100644 index 000000000000..016a46689cbe --- /dev/null +++ b/js/src/tests/ecma_5/Exceptions/jstests.list @@ -0,0 +1,2 @@ +url-prefix ../../jsreftest.html?test=ecma_5/Exceptions/ +script error-property-enumerability.js diff --git a/js/src/tests/ecma_5/Exceptions/shell.js b/js/src/tests/ecma_5/Exceptions/shell.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/js/src/tests/ecma_5/jstests.list b/js/src/tests/ecma_5/jstests.list index d1c8254ee125..db5e1425a96c 100644 --- a/js/src/tests/ecma_5/jstests.list +++ b/js/src/tests/ecma_5/jstests.list @@ -2,6 +2,7 @@ include Array/jstests.list include Boolean/jstests.list include Date/jstests.list include eval/jstests.list +include Exceptions/jstests.list include Expressions/jstests.list include Function/jstests.list include Global/jstests.list From 0a228e18f5ff71d948c70d4c317a1ac5387db712 Mon Sep 17 00:00:00 2001 From: Jonathan Protzenko Date: Thu, 14 Apr 2011 00:10:13 +0200 Subject: [PATCH 36/57] Bug 628669: Provide support for relative URLs in Components utils import (JSM, JS modules) r=bsmedberg r=mrbkap This patch allows a JS module to import another one with a relative path. For instance, if you have a set of modules you want to drop-in in any extension, and these modules depend on each other, you can import XPCOMUtils and then do XPCOMUtils.importRelative(this, "otherfile.jsm"). --- js/src/xpconnect/loader/XPCOMUtils.jsm | 15 ++++++++++++- .../xpconnect/loader/mozJSComponentLoader.cpp | 8 +++++++ .../xpcshell/example/unit/import_module.jsm | 21 ++++++++++++++++++- .../example/unit/import_sub_module.jsm | 6 ++++++ .../example/unit/test_import_module.js | 8 ++++++- 5 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 testing/xpcshell/example/unit/import_sub_module.jsm diff --git a/js/src/xpconnect/loader/XPCOMUtils.jsm b/js/src/xpconnect/loader/XPCOMUtils.jsm index d70342b94d61..42787ef847b7 100644 --- a/js/src/xpconnect/loader/XPCOMUtils.jsm +++ b/js/src/xpconnect/loader/XPCOMUtils.jsm @@ -258,7 +258,20 @@ var XPCOMUtils = { } } return factory; - } + }, + + /** + * Allows you to fake a relative import. Expects the global object from the + * module that's calling us, and the relative filename that we wish to import. + */ + importRelative: function XPCOMUtils__importRelative(that, path) { + if (!("__URI__" in that)) + throw Error("importRelative may only be used from a JSM, and its first argument "+ + "must be that JSM's global object (hint: use this)"); + let uri = that.__URI__; + let i = uri.lastIndexOf("/"); + Components.utils.import(uri.substring(0, i+1) + path, that); + }, }; /** diff --git a/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 934b99da0b91..28ab59f5c0f7 100644 --- a/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -1030,6 +1030,14 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile, NS_ENSURE_SUCCESS(rv, rv); #endif + // Expose the URI from which the script was imported through a special + // variable that we insert into the JSM. + JSString *exposedUri = JS_NewStringCopyN(cx, nativePath.get(), nativePath.Length()); + if (!JS_DefineProperty(cx, global, "__URI__", + STRING_TO_JSVAL(exposedUri), nsnull, nsnull, 0)) + return NS_ERROR_FAILURE; + + JSObject *scriptObj = nsnull; #ifdef MOZ_ENABLE_LIBXUL diff --git a/testing/xpcshell/example/unit/import_module.jsm b/testing/xpcshell/example/unit/import_module.jsm index b534a5f4aefb..48a71cccd4a2 100644 --- a/testing/xpcshell/example/unit/import_module.jsm +++ b/testing/xpcshell/example/unit/import_module.jsm @@ -1,5 +1,24 @@ // Module used by test_import_module.js -const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED" ]; +const EXPORTED_SYMBOLS = [ "MODULE_IMPORTED", "MODULE_URI", "SUBMODULE_IMPORTED", "same_scope" ]; const MODULE_IMPORTED = true; +const MODULE_URI = __URI__; + +// Will import SUBMODULE_IMPORTED into scope. +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +XPCOMUtils.importRelative(this, "import_sub_module.jsm"); + +// Prepare two scopes that we can import the submodule into. +var scope1 = { __URI__: __URI__ }; +var scope2 = { __URI__: __URI__ }; +// First one is the regular path. +XPCOMUtils.importRelative(scope1, "import_sub_module.jsm"); +scope1.test_obj.i++; +// Second one is with a different path (leads to the same file). +XPCOMUtils.importRelative(scope2, "duh/../import_sub_module.jsm"); +// test_obj belongs to import_sub_module.jsm and has a mutable field name i, if +// the two modules are actually the same, then they'll share the same value. +// We'll leave it up to test_import_module.js to check that this variable is +// true. +var same_scope = (scope1.test_obj.i == scope2.test_obj.i); diff --git a/testing/xpcshell/example/unit/import_sub_module.jsm b/testing/xpcshell/example/unit/import_sub_module.jsm new file mode 100644 index 000000000000..8ea346c8ba05 --- /dev/null +++ b/testing/xpcshell/example/unit/import_sub_module.jsm @@ -0,0 +1,6 @@ +// Module used by import_module.jsm + +var EXPORTED_SYMBOLS = [ "SUBMODULE_IMPORTED", "test_obj" ]; + +const SUBMODULE_IMPORTED = true; +var test_obj = { i: 0 }; diff --git a/testing/xpcshell/example/unit/test_import_module.js b/testing/xpcshell/example/unit/test_import_module.js index eb1fa4500191..aebad8016397 100644 --- a/testing/xpcshell/example/unit/test_import_module.js +++ b/testing/xpcshell/example/unit/test_import_module.js @@ -22,6 +22,7 @@ * * Contributor(s): * Marco Bonardo + * Jonathan Protzenko * * 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 @@ -44,6 +45,11 @@ function run_test() { do_check_true(typeof(this['MODULE_IMPORTED']) == "undefined"); - Components.utils.import("resource://test/import_module.jsm"); + do_check_true(typeof(this['MODULE_URI']) == "undefined"); + let uri = "resource://test/import_module.jsm"; + Components.utils.import(uri); + do_check_true(MODULE_URI == uri); do_check_true(MODULE_IMPORTED); + do_check_true(SUBMODULE_IMPORTED); + do_check_true(same_scope); } From 73310e4cd68a617ba382ca577fa8d3565e5ccae1 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Thu, 14 Apr 2011 10:12:23 +1200 Subject: [PATCH 37/57] Bug 641718 - Convert to using microseconds for internal video timestamps. r=kinetik --- .../html/content/src/nsHTMLMediaElement.cpp | 2 +- content/media/VideoUtils.cpp | 16 +- content/media/VideoUtils.h | 16 +- .../media/nsAudioAvailableEventManager.cpp | 6 +- content/media/nsAudioStream.cpp | 8 +- content/media/nsAudioStream.h | 2 +- content/media/nsBuiltinDecoder.cpp | 10 +- content/media/nsBuiltinDecoder.h | 7 +- content/media/nsBuiltinDecoderReader.h | 18 +-- .../media/nsBuiltinDecoderStateMachine.cpp | 152 +++++++++--------- content/media/nsBuiltinDecoderStateMachine.h | 60 +++---- content/media/nsMediaCache.cpp | 6 +- content/media/nsMediaDecoder.h | 4 +- content/media/nsMediaStream.cpp | 2 +- content/media/nsMediaStream.h | 4 +- content/media/ogg/nsOggCodecState.cpp | 53 +++--- content/media/ogg/nsOggCodecState.h | 11 +- content/media/ogg/nsOggReader.cpp | 29 ++-- content/media/ogg/nsOggReader.h | 18 +-- content/media/raw/nsRawReader.cpp | 12 +- content/media/test/test_seekLies.html | 2 +- content/media/wave/nsWaveReader.cpp | 41 ++--- content/media/wave/nsWaveReader.h | 6 +- content/media/webm/nsWebMBufferedParser.cpp | 1 - content/media/webm/nsWebMReader.cpp | 53 +++--- content/media/webm/nsWebMReader.h | 8 +- 26 files changed, 265 insertions(+), 282 deletions(-) diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp index 98b66ee16cd9..8e9bd2c17a37 100644 --- a/content/html/content/src/nsHTMLMediaElement.cpp +++ b/content/html/content/src/nsHTMLMediaElement.cpp @@ -1820,7 +1820,7 @@ nsresult nsHTMLMediaElement::InitializeDecoderAsClone(nsMediaDecoder* aOriginal) double duration = aOriginal->GetDuration(); if (duration >= 0) { - decoder->SetDuration(PRInt64(NS_round(duration * 1000))); + decoder->SetDuration(duration); decoder->SetSeekable(aOriginal->GetSeekable()); } diff --git a/content/media/VideoUtils.cpp b/content/media/VideoUtils.cpp index 88bbe0a9696f..76b8166eceb8 100644 --- a/content/media/VideoUtils.cpp +++ b/content/media/VideoUtils.cpp @@ -175,24 +175,24 @@ PRBool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult) { return PR_TRUE; } -// Converts from number of audio samples to milliseconds, given the specified +// Converts from number of audio samples to microseconds, given the specified // audio rate. -PRBool SamplesToMs(PRInt64 aSamples, PRUint32 aRate, PRInt64& aOutMs) +PRBool SamplesToUsecs(PRInt64 aSamples, PRUint32 aRate, PRInt64& aOutUsecs) { PRInt64 x; - if (!MulOverflow(aSamples, 1000, x)) + if (!MulOverflow(aSamples, USECS_PER_S, x)) return PR_FALSE; - aOutMs = x / aRate; + aOutUsecs = x / aRate; return PR_TRUE; } -// Converts from milliseconds to number of audio samples, given the specified +// Converts from microseconds to number of audio samples, given the specified // audio rate. -PRBool MsToSamples(PRInt64 aMs, PRUint32 aRate, PRInt64& aOutSamples) +PRBool UsecsToSamples(PRInt64 aUsecs, PRUint32 aRate, PRInt64& aOutSamples) { PRInt64 x; - if (!MulOverflow(aMs, aRate, x)) + if (!MulOverflow(aUsecs, aRate, x)) return PR_FALSE; - aOutSamples = x / 1000; + aOutSamples = x / USECS_PER_S; return PR_TRUE; } diff --git a/content/media/VideoUtils.h b/content/media/VideoUtils.h index 5dc0237fce77..497db6a6db16 100644 --- a/content/media/VideoUtils.h +++ b/content/media/VideoUtils.h @@ -126,16 +126,22 @@ PRBool AddOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult); // in an integer overflow. PRBool MulOverflow(PRInt64 a, PRInt64 b, PRInt64& aResult); -// Converts from number of audio samples (aSamples) to milliseconds, given -// the specified audio rate (aRate). Stores result in aOutMs. Returns PR_TRUE +// Converts from number of audio samples (aSamples) to microseconds, given +// the specified audio rate (aRate). Stores result in aOutUsecs. Returns PR_TRUE // if the operation succeeded, or PR_FALSE if there was an integer overflow // while calulating the conversion. -PRBool SamplesToMs(PRInt64 aSamples, PRUint32 aRate, PRInt64& aOutMs); +PRBool SamplesToUsecs(PRInt64 aSamples, PRUint32 aRate, PRInt64& aOutUsecs); -// Converts from milliseconds (aMs) to number of audio samples, given the +// Converts from microseconds (aUsecs) to number of audio samples, given the // specified audio rate (aRate). Stores the result in aOutSamples. Returns // PR_TRUE if the operation succeeded, or PR_FALSE if there was an integer // overflow while calulating the conversion. -PRBool MsToSamples(PRInt64 aMs, PRUint32 aRate, PRInt64& aOutSamples); +PRBool UsecsToSamples(PRInt64 aUsecs, PRUint32 aRate, PRInt64& aOutSamples); + +// Number of microseconds per second. 1e6. +#define USECS_PER_S 1000000 + +// Number of microseconds per millisecond. +#define USECS_PER_MS 1000 #endif diff --git a/content/media/nsAudioAvailableEventManager.cpp b/content/media/nsAudioAvailableEventManager.cpp index e3f75820d800..e6f4d2ebf715 100644 --- a/content/media/nsAudioAvailableEventManager.cpp +++ b/content/media/nsAudioAvailableEventManager.cpp @@ -39,8 +39,8 @@ #include "nsTArray.h" #include "nsAudioAvailableEventManager.h" +#include "VideoUtils.h" -#define MILLISECONDS_PER_SECOND 1000.0f #define MAX_PENDING_EVENTS 100 using namespace mozilla; @@ -107,7 +107,7 @@ void nsAudioAvailableEventManager::DispatchPendingEvents(PRUint64 aCurrentTime) while (mPendingEvents.Length() > 0) { nsAudioAvailableEventRunner* e = (nsAudioAvailableEventRunner*)mPendingEvents[0].get(); - if (e->mTime * MILLISECONDS_PER_SECOND > aCurrentTime) { + if (e->mTime * USECS_PER_S > aCurrentTime) { break; } nsCOMPtr event = mPendingEvents[0]; @@ -228,7 +228,7 @@ void nsAudioAvailableEventManager::Drain(PRUint64 aEndTime) (mSignalBufferLength - mSignalBufferPosition) * sizeof(float)); // Force this last event to go now. - float time = (aEndTime / MILLISECONDS_PER_SECOND) - + float time = (aEndTime / static_cast(USECS_PER_S)) - (mSignalBufferPosition / mSamplesPerSecond); nsCOMPtr lastEvent = new nsAudioAvailableEventRunner(mDecoder, mSignalBuffer.forget(), diff --git a/content/media/nsAudioStream.cpp b/content/media/nsAudioStream.cpp index 8eb6602084d6..624223c06d10 100644 --- a/content/media/nsAudioStream.cpp +++ b/content/media/nsAudioStream.cpp @@ -51,6 +51,7 @@ using namespace mozilla::dom; #include "nsAutoPtr.h" #include "nsAudioStream.h" #include "nsAlgorithm.h" +#include "VideoUtils.h" extern "C" { #include "sydneyaudio/sydney_audio.h" } @@ -74,7 +75,6 @@ PRLogModuleInfo* gAudioStreamLog = nsnull; #endif #define FAKE_BUFFER_SIZE 176400 -#define MILLISECONDS_PER_SECOND 1000 class nsAudioStreamLocal : public nsAudioStream { @@ -551,7 +551,7 @@ PRInt64 nsAudioStreamLocal::GetPosition() { PRInt64 sampleOffset = GetSampleOffset(); if (sampleOffset >= 0) { - return ((MILLISECONDS_PER_SECOND * sampleOffset) / mRate / mChannels); + return ((USECS_PER_S * sampleOffset) / mRate / mChannels); } return -1; } @@ -718,7 +718,7 @@ PRInt64 nsAudioStreamRemote::GetPosition() { PRInt64 sampleOffset = GetSampleOffset(); if (sampleOffset >= 0) { - return ((MILLISECONDS_PER_SECOND * sampleOffset) / mRate / mChannels); + return ((USECS_PER_S * sampleOffset) / mRate / mChannels); } return 0; } @@ -734,7 +734,7 @@ nsAudioStreamRemote::GetSampleOffset() return 0; PRInt64 time = mAudioChild->GetLastKnownSampleOffsetTime(); - PRInt64 result = offset + (mRate * mChannels * (PR_IntervalNow() - time) / MILLISECONDS_PER_SECOND); + PRInt64 result = offset + (mRate * mChannels * (PR_IntervalNow() - time) / USECS_PER_S); return result; } diff --git a/content/media/nsAudioStream.h b/content/media/nsAudioStream.h index de560a147be0..192dcc0f06eb 100644 --- a/content/media/nsAudioStream.h +++ b/content/media/nsAudioStream.h @@ -106,7 +106,7 @@ public: // Resume audio playback virtual void Resume() = 0; - // Return the position in milliseconds of the sample being played by the + // Return the position in microseconds of the sample being played by the // audio hardware. virtual PRInt64 GetPosition() = 0; diff --git a/content/media/nsBuiltinDecoder.cpp b/content/media/nsBuiltinDecoder.cpp index 353fe144b76e..f305f7a854c6 100644 --- a/content/media/nsBuiltinDecoder.cpp +++ b/content/media/nsBuiltinDecoder.cpp @@ -83,7 +83,7 @@ double nsBuiltinDecoder::GetDuration() { NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); if (mDuration >= 0) { - return static_cast(mDuration) / 1000.0; + return static_cast(mDuration) / static_cast(USECS_PER_S); } return std::numeric_limits::quiet_NaN(); } @@ -538,7 +538,7 @@ double nsBuiltinDecoder::ComputePlaybackRate(PRPackedBool* aReliable) PRInt64 length = mStream ? mStream->GetLength() : -1; if (mDuration >= 0 && length >= 0) { *aReliable = PR_TRUE; - return double(length)*1000.0/mDuration; + return length * static_cast(USECS_PER_S) / mDuration; } return mPlaybackStatistics.GetRateAtLastStop(aReliable); } @@ -814,15 +814,15 @@ void nsBuiltinDecoder::DurationChanged() UpdatePlaybackRate(); if (mElement && oldDuration != mDuration) { - LOG(PR_LOG_DEBUG, ("%p duration changed to %lldms", this, mDuration)); + LOG(PR_LOG_DEBUG, ("%p duration changed to %lld", this, mDuration)); mElement->DispatchEvent(NS_LITERAL_STRING("durationchange")); } } -void nsBuiltinDecoder::SetDuration(PRInt64 aDuration) +void nsBuiltinDecoder::SetDuration(double aDuration) { NS_ASSERTION(NS_IsMainThread(), "Should be on main thread."); - mDuration = aDuration; + mDuration = static_cast(NS_round(aDuration * static_cast(USECS_PER_S))); MonitorAutoEnter mon(mMonitor); if (mDecoderStateMachine) { diff --git a/content/media/nsBuiltinDecoder.h b/content/media/nsBuiltinDecoder.h index 7946eec9b956..bf15636cee31 100644 --- a/content/media/nsBuiltinDecoder.h +++ b/content/media/nsBuiltinDecoder.h @@ -250,13 +250,14 @@ public: virtual void Shutdown() = 0; // Called from the main thread to get the duration. The decoder monitor - // must be obtained before calling this. It is in units of milliseconds. + // must be obtained before calling this. It is in units of microseconds. virtual PRInt64 GetDuration() = 0; // Called from the main thread to set the duration of the media resource // if it is able to be obtained via HTTP headers. Called from the // state machine thread to set the duration if it is obtained from the // media metadata. The decoder monitor must be obtained before calling this. + // aDuration is in microseconds. virtual void SetDuration(PRInt64 aDuration) = 0; // Functions used by assertions to ensure we're calling things @@ -387,10 +388,10 @@ class nsBuiltinDecoder : public nsMediaDecoder // Call on the main thread only. virtual PRBool IsEnded() const; - // Set the duration of the media resource in units of milliseconds. + // Set the duration of the media resource in units of seconds. // This is called via a channel listener if it can pick up the duration // from a content header. Must be called from the main thread only. - virtual void SetDuration(PRInt64 aDuration); + virtual void SetDuration(double aDuration); // Set a flag indicating whether seeking is supported virtual void SetSeekable(PRBool aSeekable); diff --git a/content/media/nsBuiltinDecoderReader.h b/content/media/nsBuiltinDecoderReader.h index a9673d8abb8c..e7ce6732fcba 100644 --- a/content/media/nsBuiltinDecoderReader.h +++ b/content/media/nsBuiltinDecoderReader.h @@ -179,8 +179,8 @@ public: // chunk ends. const PRInt64 mOffset; - PRInt64 mTime; // Start time of samples in ms. - const PRInt64 mDuration; // In ms. + PRInt64 mTime; // Start time of samples in usecs. + const PRInt64 mDuration; // In usecs. const PRUint32 mSamples; const PRUint32 mChannels; nsAutoArrayPtr mAudioData; @@ -241,10 +241,10 @@ public: // Approximate byte offset of the end of the frame in the media. PRInt64 mOffset; - // Start time of frame in milliseconds. + // Start time of frame in microseconds. PRInt64 mTime; - // End time of frame in milliseconds; + // End time of frame in microseconds; PRInt64 mEndTime; // Codec specific internal time code. For Ogg based codecs this is the @@ -387,7 +387,7 @@ template class MediaQueue : private nsDeque { mEndOfStream = PR_TRUE; } - // Returns the approximate number of milliseconds of samples in the queue. + // Returns the approximate number of microseconds of samples in the queue. PRInt64 Duration() { MonitorAutoEnter mon(mMonitor); if (GetSize() < 2) { @@ -457,9 +457,9 @@ public: // This will not read past aEndOffset. Returns -1 on failure. virtual PRInt64 FindEndTime(PRInt64 aEndOffset); - // Moves the decode head to aTime milliseconds. aStartTime and aEndTime - // denote the start and end times of the media in ms, and aCurrentTime - // is the current playback position in ms. + // Moves the decode head to aTime microseconds. aStartTime and aEndTime + // denote the start and end times of the media in usecs, and aCurrentTime + // is the current playback position in microseconds. virtual nsresult Seek(PRInt64 aTime, PRInt64 aStartTime, PRInt64 aEndTime, @@ -485,7 +485,7 @@ public: protected: // Pumps the decode until we reach frames/samples required to play at - // time aTarget (ms). + // time aTarget (usecs). nsresult DecodeToTarget(PRInt64 aTarget); // Reader decode function. Matches DecodeVideoFrame() and diff --git a/content/media/nsBuiltinDecoderStateMachine.cpp b/content/media/nsBuiltinDecoderStateMachine.cpp index 5c7e4d673989..07767a549bb1 100644 --- a/content/media/nsBuiltinDecoderStateMachine.cpp +++ b/content/media/nsBuiltinDecoderStateMachine.cpp @@ -68,17 +68,17 @@ extern PRLogModuleInfo* gBuiltinDecoderLog; #define BUFFERING_MIN_RATE 50000 #define BUFFERING_RATE(x) ((x)< BUFFERING_MIN_RATE ? BUFFERING_MIN_RATE : (x)) -// If audio queue has less than this many ms of decoded audio, we won't risk +// If audio queue has less than this many usecs of decoded audio, we won't risk // trying to decode the video, we'll skip decoding video up to the next // keyframe. We may increase this value for an individual decoder if we // encounter video frames which take a long time to decode. -static const PRUint32 LOW_AUDIO_MS = 300; +static const PRUint32 LOW_AUDIO_USECS = 300000; -// If more than this many ms of decoded audio is queued, we'll hold off +// If more than this many usecs of decoded audio is queued, we'll hold off // decoding more audio. If we increase the low audio threshold (see -// LOW_AUDIO_MS above) we'll also increase this value to ensure it's not +// LOW_AUDIO_USECS above) we'll also increase this value to ensure it's not // less than the low audio threshold. -const PRInt64 AMPLE_AUDIO_MS = 1000; +const PRInt64 AMPLE_AUDIO_USECS = 1000000; // Maximum number of bytes we'll allocate and write at once to the audio // hardware when the audio stream contains missing samples and we're @@ -98,9 +98,9 @@ static const PRUint32 LOW_VIDEO_FRAMES = 1; static const PRUint32 AMPLE_VIDEO_FRAMES = 10; // Arbitrary "frame duration" when playing only audio. -static const int AUDIO_DURATION_MS = 40; +static const int AUDIO_DURATION_USECS = 40000; -// If we increase our "low audio threshold" (see LOW_AUDIO_MS above), we +// If we increase our "low audio threshold" (see LOW_AUDIO_USECS above), we // use this as a factor in all our calculations. Increasing this will cause // us to be more likely to increase our low audio threshold, and to // increase it by more. @@ -110,16 +110,16 @@ static const int THRESHOLD_FACTOR = 2; // ourselves to be running low on undecoded data. We determine how much // undecoded data we have remaining using the reader's GetBuffered() // implementation. -static const PRInt64 LOW_DATA_THRESHOLD_MS = 5000; +static const PRInt64 LOW_DATA_THRESHOLD_USECS = 5000000; -// LOW_DATA_THRESHOLD_MS needs to be greater than AMPLE_AUDIO_MS, otherwise +// LOW_DATA_THRESHOLD_USECS needs to be greater than AMPLE_AUDIO_USECS, otherwise // the skip-to-keyframe logic can activate when we're running low on data. -PR_STATIC_ASSERT(LOW_DATA_THRESHOLD_MS > AMPLE_AUDIO_MS); +PR_STATIC_ASSERT(LOW_DATA_THRESHOLD_USECS > AMPLE_AUDIO_USECS); -// Amount of excess ms of data to add in to the "should we buffer" calculation. -static const PRUint32 EXHAUSTED_DATA_MARGIN_MS = 60; +// Amount of excess usecs of data to add in to the "should we buffer" calculation. +static const PRUint32 EXHAUSTED_DATA_MARGIN_USECS = 60000; -// If we enter buffering within QUICK_BUFFER_THRESHOLD_MS seconds of starting +// If we enter buffering within QUICK_BUFFER_THRESHOLD_USECS seconds of starting // decoding, we'll enter "quick buffering" mode, which exits a lot sooner than // normal buffering mode. This exists so that if the decode-ahead exhausts the // downloaded data while decode/playback is just starting up (for example @@ -128,24 +128,24 @@ static const PRUint32 EXHAUSTED_DATA_MARGIN_MS = 60; // for buffering. We may actually be able to playback in this case, so exit // buffering early and try to play. If it turns out we can't play, we'll fall // back to buffering normally. -static const PRUint32 QUICK_BUFFER_THRESHOLD_MS = 2000; +static const PRUint32 QUICK_BUFFER_THRESHOLD_USECS = 2000000; // If we're quick buffering, we'll remain in buffering mode while we have less than -// QUICK_BUFFERING_LOW_DATA_MS of decoded data available. -static const PRUint32 QUICK_BUFFERING_LOW_DATA_MS = 1000; +// QUICK_BUFFERING_LOW_DATA_USECS of decoded data available. +static const PRUint32 QUICK_BUFFERING_LOW_DATA_USECS = 1000000; -// If QUICK_BUFFERING_LOW_DATA_MS is > AMPLE_AUDIO_MS, we won't exit +// If QUICK_BUFFERING_LOW_DATA_USECS is > AMPLE_AUDIO_USECS, we won't exit // quick buffering in a timely fashion, as the decode pauses when it -// reaches AMPLE_AUDIO_MS decoded data, and thus we'll never reach -// QUICK_BUFFERING_LOW_DATA_MS. -PR_STATIC_ASSERT(QUICK_BUFFERING_LOW_DATA_MS <= AMPLE_AUDIO_MS); +// reaches AMPLE_AUDIO_USECS decoded data, and thus we'll never reach +// QUICK_BUFFERING_LOW_DATA_USECS. +PR_STATIC_ASSERT(QUICK_BUFFERING_LOW_DATA_USECS <= AMPLE_AUDIO_USECS); -static TimeDuration MsToDuration(PRInt64 aMs) { - return TimeDuration::FromMilliseconds(static_cast(aMs)); +static TimeDuration UsecsToDuration(PRInt64 aUsecs) { + return TimeDuration::FromMilliseconds(static_cast(aUsecs) / USECS_PER_MS); } -static PRInt64 DurationToMs(TimeDuration aDuration) { - return static_cast(aDuration.ToSeconds() * 1000); +static PRInt64 DurationToUsecs(TimeDuration aDuration) { + return static_cast(aDuration.ToSeconds() * USECS_PER_S); } class nsAudioMetadataEventRunner : public nsRunnable @@ -212,7 +212,7 @@ PRBool nsBuiltinDecoderStateMachine::HasFutureAudio() const { // we've completely decoded all audio (but not finished playing it yet // as per 1). return !mAudioCompleted && - (AudioDecodedMs() > LOW_AUDIO_MS || mReader->mAudioQueue.IsFinished()); + (AudioDecodedUsecs() > LOW_AUDIO_USECS || mReader->mAudioQueue.IsFinished()); } PRBool nsBuiltinDecoderStateMachine::HaveNextFrameData() const { @@ -250,19 +250,19 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() // no longer be considered to be "pumping video". const unsigned videoPumpThreshold = AMPLE_VIDEO_FRAMES / 2; - // After the audio decode fills with more than audioPumpThresholdMs ms + // After the audio decode fills with more than audioPumpThreshold usecs // of decoded audio, we'll start to check whether the audio or video decode // is falling behind. - const unsigned audioPumpThresholdMs = LOW_AUDIO_MS * 2; + const unsigned audioPumpThreshold = LOW_AUDIO_USECS * 2; // Our local low audio threshold. We may increase this if we're slow to // decode video frames, in order to reduce the chance of audio underruns. - PRInt64 lowAudioThreshold = LOW_AUDIO_MS; + PRInt64 lowAudioThreshold = LOW_AUDIO_USECS; // Our local ample audio threshold. If we increase lowAudioThreshold, we'll // also increase this too appropriately (we don't want lowAudioThreshold to // be greater than ampleAudioThreshold, else we'd stop decoding!). - PRInt64 ampleAudioThreshold = AMPLE_AUDIO_MS; + PRInt64 ampleAudioThreshold = AMPLE_AUDIO_USECS; MediaQueue& videoQueue = mReader->mVideoQueue; MediaQueue& audioQueue = mReader->mAudioQueue; @@ -289,7 +289,7 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() // We don't want to consider skipping to the next keyframe if we've // only just started up the decode loop, so wait until we've decoded // some audio data before enabling the keyframe skip logic on audio. - if (audioPump && GetDecodedAudioDuration() >= audioPumpThresholdMs) { + if (audioPump && GetDecodedAudioDuration() >= audioPumpThreshold) { audioPump = PR_FALSE; } @@ -328,11 +328,11 @@ void nsBuiltinDecoderStateMachine::DecodeLoop() videoPlaying = mReader->DecodeVideoFrame(skipToNextKeyframe, currentTime); decodeTime = TimeStamp::Now() - start; } - if (THRESHOLD_FACTOR * DurationToMs(decodeTime) > lowAudioThreshold && + if (THRESHOLD_FACTOR * DurationToUsecs(decodeTime) > lowAudioThreshold && !HasLowUndecodedData()) { lowAudioThreshold = - NS_MIN(THRESHOLD_FACTOR * DurationToMs(decodeTime), AMPLE_AUDIO_MS); + NS_MIN(THRESHOLD_FACTOR * DurationToUsecs(decodeTime), AMPLE_AUDIO_USECS); ampleAudioThreshold = NS_MAX(THRESHOLD_FACTOR * lowAudioThreshold, ampleAudioThreshold); LOG(PR_LOG_DEBUG, @@ -474,7 +474,7 @@ void nsBuiltinDecoderStateMachine::AudioLoop() // Calculate the number of samples that have been pushed onto the audio // hardware. PRInt64 playedSamples = 0; - if (!MsToSamples(audioStartTime, rate, playedSamples)) { + if (!UsecsToSamples(audioStartTime, rate, playedSamples)) { NS_WARNING("Int overflow converting playedSamples"); break; } @@ -486,7 +486,7 @@ void nsBuiltinDecoderStateMachine::AudioLoop() // Calculate the timestamp of the next chunk of audio in numbers of // samples. PRInt64 sampleTime = 0; - if (!MsToSamples(s->mTime, rate, sampleTime)) { + if (!UsecsToSamples(s->mTime, rate, sampleTime)) { NS_WARNING("Int overflow converting sampleTime"); break; } @@ -509,18 +509,18 @@ void nsBuiltinDecoderStateMachine::AudioLoop() } { MonitorAutoEnter mon(mDecoder->GetMonitor()); - PRInt64 playedMs; - if (!SamplesToMs(audioDuration, rate, playedMs)) { - NS_WARNING("Int overflow calculating playedMs"); + PRInt64 playedUsecs; + if (!SamplesToUsecs(audioDuration, rate, playedUsecs)) { + NS_WARNING("Int overflow calculating playedUsecs"); break; } - if (!AddOverflow(audioStartTime, playedMs, mAudioEndTime)) { + if (!AddOverflow(audioStartTime, playedUsecs, mAudioEndTime)) { NS_WARNING("Int overflow calculating audio end time"); break; } PRInt64 audioAhead = mAudioEndTime - GetMediaTime(); - if (audioAhead > AMPLE_AUDIO_MS && + if (audioAhead > AMPLE_AUDIO_USECS && audioDuration - samplesAtLastSleep > minWriteSamples) { samplesAtLastSleep = audioDuration; @@ -528,7 +528,7 @@ void nsBuiltinDecoderStateMachine::AudioLoop() // significant amount ahead of the playback position. The decode // thread will be going to sleep, so we won't get any new samples // anyway, so sleep until we need to push to the hardware again. - Wait(AMPLE_AUDIO_MS / 2); + Wait(AMPLE_AUDIO_USECS / 2); // Kick the decode thread; since above we only do a NotifyAll when // we pop an audio chunk of the queue, the decoder won't wake up if // we've got no more decoded chunks to push to the hardware. We can @@ -559,8 +559,8 @@ void nsBuiltinDecoderStateMachine::AudioLoop() mState != DECODER_STATE_SEEKING && mState != DECODER_STATE_SHUTDOWN) { - const PRInt64 DRAIN_BLOCK_MS = 100; - Wait(NS_MIN(mAudioEndTime - position, DRAIN_BLOCK_MS)); + const PRInt64 DRAIN_BLOCK_USECS = 100000; + Wait(NS_MIN(mAudioEndTime - position, DRAIN_BLOCK_USECS)); oldPosition = position; position = GetMediaTime(); } @@ -683,7 +683,7 @@ void nsBuiltinDecoderStateMachine::StopPlayback(eStopMode aMode) // audio thread can block in the write, and we deadlock trying to acquire // the audio monitor upon resume playback. if (IsPlaying()) { - mPlayDuration += TimeStamp::Now() - mPlayStartTime; + mPlayDuration += DurationToUsecs(TimeStamp::Now() - mPlayStartTime); mPlayStartTime = TimeStamp(); } if (HasAudio()) { @@ -799,7 +799,7 @@ double nsBuiltinDecoderStateMachine::GetCurrentTime() const OnDecodeThread(), "Should be on main, decode, or state machine thread."); - return static_cast(mCurrentFrameTime) / 1000.0; + return static_cast(mCurrentFrameTime) / static_cast(USECS_PER_S); } PRInt64 nsBuiltinDecoderStateMachine::GetDuration() @@ -893,7 +893,7 @@ void nsBuiltinDecoderStateMachine::Seek(double aTime) "We shouldn't already be seeking"); NS_ASSERTION(mState >= DECODER_STATE_DECODING, "We should have loaded metadata"); - double t = aTime * 1000.0; + double t = aTime * static_cast(USECS_PER_S); if (t > PR_INT64_MAX) { // Prevent integer overflow. return; @@ -965,10 +965,10 @@ nsBuiltinDecoderStateMachine::StartDecodeThreads() return NS_OK; } -PRInt64 nsBuiltinDecoderStateMachine::AudioDecodedMs() const +PRInt64 nsBuiltinDecoderStateMachine::AudioDecodedUsecs() const { NS_ASSERTION(HasAudio(), - "Should only call AudioDecodedMs() when we have audio"); + "Should only call AudioDecodedUsecs() when we have audio"); // The amount of audio we have decoded is the amount of audio data we've // already decoded and pushed to the hardware, plus the amount of audio // data waiting to be pushed to the hardware. @@ -976,7 +976,7 @@ PRInt64 nsBuiltinDecoderStateMachine::AudioDecodedMs() const return pushed + mReader->mAudioQueue.Duration(); } -PRBool nsBuiltinDecoderStateMachine::HasLowDecodedData(PRInt64 aAudioMs) const +PRBool nsBuiltinDecoderStateMachine::HasLowDecodedData(PRInt64 aAudioUsecs) const { mDecoder->GetMonitor().AssertCurrentThreadIn(); // We consider ourselves low on decoded data if we're low on audio, @@ -985,7 +985,7 @@ PRBool nsBuiltinDecoderStateMachine::HasLowDecodedData(PRInt64 aAudioMs) const // we've not decoded to the end of the video stream. return ((HasAudio() && !mReader->mAudioQueue.IsFinished() && - AudioDecodedMs() < aAudioMs) + AudioDecodedUsecs() < aAudioUsecs) || (!HasAudio() && HasVideo() && @@ -995,7 +995,7 @@ PRBool nsBuiltinDecoderStateMachine::HasLowDecodedData(PRInt64 aAudioMs) const PRBool nsBuiltinDecoderStateMachine::HasLowUndecodedData() const { - return GetUndecodedData() < LOW_DATA_THRESHOLD_MS; + return GetUndecodedData() < LOW_DATA_THRESHOLD_USECS; } PRInt64 nsBuiltinDecoderStateMachine::GetUndecodedData() const @@ -1084,7 +1084,7 @@ nsresult nsBuiltinDecoderStateMachine::Run() !mSeekable || mEndTime != -1, "Active seekable media should have end time"); NS_ASSERTION(!mSeekable || GetDuration() != -1, "Seekable media should have duration"); - LOG(PR_LOG_DEBUG, ("%p Media goes from %lldms to %lldms (duration %lldms) seekable=%d", + LOG(PR_LOG_DEBUG, ("%p Media goes from %lld to %lld (duration %lld) seekable=%d", mDecoder, mStartTime, mEndTime, GetDuration(), mSeekable)); if (mState == DECODER_STATE_SHUTDOWN) @@ -1187,7 +1187,7 @@ nsresult nsBuiltinDecoderStateMachine::Run() "Seek target should lie inside the first audio block after seek"); PRInt64 startTime = (audio && audio->mTime < seekTime) ? audio->mTime : seekTime; mAudioStartTime = startTime; - mPlayDuration = MsToDuration(startTime - mStartTime); + mPlayDuration = startTime - mStartTime; if (HasVideo()) { nsAutoPtr video(mReader->mVideoQueue.PeekFront()); if (video) { @@ -1220,12 +1220,12 @@ nsresult nsBuiltinDecoderStateMachine::Run() nsCOMPtr stopEvent; if (GetMediaTime() == mEndTime) { - LOG(PR_LOG_DEBUG, ("%p Changed state from SEEKING (to %lldms) to COMPLETED", + LOG(PR_LOG_DEBUG, ("%p Changed state from SEEKING (to %lld) to COMPLETED", mDecoder, seekTime)); stopEvent = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::SeekingStoppedAtEnd); mState = DECODER_STATE_COMPLETED; } else { - LOG(PR_LOG_DEBUG, ("%p Changed state from SEEKING (to %lldms) to DECODING", + LOG(PR_LOG_DEBUG, ("%p Changed state from SEEKING (to %lld) to DECODING", mDecoder, seekTime)); stopEvent = NS_NewRunnableMethod(mDecoder, &nsBuiltinDecoder::SeekingStopped); StartDecoding(); @@ -1261,18 +1261,18 @@ nsresult nsBuiltinDecoderStateMachine::Run() PRBool isLiveStream = mDecoder->GetCurrentStream()->GetLength() == -1; if ((isLiveStream || !mDecoder->CanPlayThrough()) && elapsed < TimeDuration::FromSeconds(BUFFERING_WAIT) && - (mQuickBuffering ? HasLowDecodedData(QUICK_BUFFERING_LOW_DATA_MS) - : (GetUndecodedData() < BUFFERING_WAIT * 1000)) && + (mQuickBuffering ? HasLowDecodedData(QUICK_BUFFERING_LOW_DATA_USECS) + : (GetUndecodedData() < BUFFERING_WAIT * USECS_PER_S)) && !stream->IsDataCachedToEndOfStream(mDecoder->mDecoderPosition) && !stream->IsSuspended()) { LOG(PR_LOG_DEBUG, ("Buffering: %.3lfs/%ds, timeout in %.3lfs %s", - GetUndecodedData() / 1000.0, + GetUndecodedData() / static_cast(USECS_PER_S), BUFFERING_WAIT, BUFFERING_WAIT - elapsed.ToSeconds(), (mQuickBuffering ? "(quick exit)" : ""))); - Wait(1000); + Wait(USECS_PER_S); if (mState == DECODER_STATE_SHUTDOWN) continue; } else { @@ -1395,7 +1395,7 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() // audio clock. Just wait and then return, to give the audio clock time // to tick. This should really wait for a specific signal from the audio // thread rather than polling after a sleep. See bug 568431 comment 4. - Wait(AUDIO_DURATION_MS); + Wait(AUDIO_DURATION_USECS); return; } @@ -1404,18 +1404,18 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() // audio, or don't have audio, use the system clock. PRInt64 clock_time = -1; if (!IsPlaying()) { - clock_time = DurationToMs(mPlayDuration) + mStartTime; + clock_time = mPlayDuration + mStartTime; } else { PRInt64 audio_time = GetAudioClock(); if (HasAudio() && !mAudioCompleted && audio_time != -1) { clock_time = audio_time; // Resync against the audio clock, while we're trusting the // audio clock. This ensures no "drift", particularly on Linux. - mPlayDuration = MsToDuration(clock_time - mStartTime); + mPlayDuration = clock_time - mStartTime; mPlayStartTime = TimeStamp::Now(); } else { // Sound is disabled on this system. Sync to the system clock. - clock_time = DurationToMs(TimeStamp::Now() - mPlayStartTime + mPlayDuration); + clock_time = DurationToUsecs(TimeStamp::Now() - mPlayStartTime) + mPlayDuration; // Ensure the clock can never go backwards. NS_ASSERTION(mCurrentFrameTime <= clock_time, "Clock should go forwards"); clock_time = NS_MAX(mCurrentFrameTime, clock_time) + mStartTime; @@ -1424,7 +1424,7 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() // Skip frames up to the frame at the playback position, and figure out // the time remaining until it's time to display the next frame. - PRInt64 remainingTime = AUDIO_DURATION_MS; + PRInt64 remainingTime = AUDIO_DURATION_USECS; NS_ASSERTION(clock_time >= mStartTime, "Should have positive clock time."); nsAutoPtr currentFrame; if (mReader->mVideoQueue.GetSize() > 0) { @@ -1442,8 +1442,8 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() // present the next frame. if (frame && !currentFrame) { PRInt64 now = IsPlaying() - ? DurationToMs(TimeStamp::Now() - mPlayStartTime + mPlayDuration) - : DurationToMs(mPlayDuration); + ? (DurationToUsecs(TimeStamp::Now() - mPlayStartTime) + mPlayDuration) + : mPlayDuration; remainingTime = frame->mTime - mStartTime - now; } } @@ -1453,7 +1453,7 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() nsMediaStream* stream = mDecoder->GetCurrentStream(); if (mState == DECODER_STATE_DECODING && mDecoder->GetState() == nsBuiltinDecoder::PLAY_STATE_PLAYING && - HasLowDecodedData(remainingTime + EXHAUSTED_DATA_MARGIN_MS) && + HasLowDecodedData(remainingTime + EXHAUSTED_DATA_MARGIN_USECS) && !stream->IsDataCachedToEndOfStream(mDecoder->mDecoderPosition) && !stream->IsSuspended() && (JustExitedQuickBuffering() || HasLowUndecodedData())) @@ -1474,8 +1474,8 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() if (currentFrame) { // Decode one frame and display it. - TimeStamp presTime = mPlayStartTime - mPlayDuration + - MsToDuration(currentFrame->mTime - mStartTime); + TimeStamp presTime = mPlayStartTime - UsecsToDuration(mPlayDuration) + + UsecsToDuration(currentFrame->mTime - mStartTime); NS_ASSERTION(currentFrame->mTime >= mStartTime, "Should have positive frame time"); { nsIntSize display = mInfo.mDisplay; @@ -1488,7 +1488,7 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() } } mDecoder->GetFrameStatistics().NotifyPresentedFrame(); - PRInt64 now = DurationToMs(TimeStamp::Now() - mPlayStartTime + mPlayDuration); + PRInt64 now = DurationToUsecs(TimeStamp::Now() - mPlayStartTime) + mPlayDuration; remainingTime = currentFrame->mEndTime - mStartTime - now; currentFrame = nsnull; } @@ -1534,9 +1534,9 @@ void nsBuiltinDecoderStateMachine::AdvanceFrame() } } -void nsBuiltinDecoderStateMachine::Wait(PRInt64 aMs) { +void nsBuiltinDecoderStateMachine::Wait(PRInt64 aUsecs) { mDecoder->GetMonitor().AssertCurrentThreadIn(); - TimeStamp end = TimeStamp::Now() + MsToDuration(aMs); + TimeStamp end = TimeStamp::Now() + UsecsToDuration(aUsecs); TimeStamp now; while ((now = TimeStamp::Now()) < end && mState != DECODER_STATE_SHUTDOWN && @@ -1546,8 +1546,6 @@ void nsBuiltinDecoderStateMachine::Wait(PRInt64 aMs) { if (ms == 0 || ms > PR_UINT32_MAX) { break; } - NS_ASSERTION(ms <= aMs && ms > 0, - "nsBuiltinDecoderStateMachine::Wait interval very wrong!"); mDecoder->GetMonitor().Wait(PR_MillisecondsToInterval(static_cast(ms))); } } @@ -1579,7 +1577,7 @@ VideoData* nsBuiltinDecoderStateMachine::FindStartTime() // first acutal audio sample we have, we'll inject silence during playback // to ensure the audio starts at the correct time. mAudioStartTime = mStartTime; - LOG(PR_LOG_DEBUG, ("%p Media start time is %lldms", mDecoder, mStartTime)); + LOG(PR_LOG_DEBUG, ("%p Media start time is %lld", mDecoder, mStartTime)); return v; } @@ -1604,7 +1602,7 @@ void nsBuiltinDecoderStateMachine::FindEndTime() mEndTime = endTime; } - LOG(PR_LOG_DEBUG, ("%p Media end time is %lldms", mDecoder, mEndTime)); + LOG(PR_LOG_DEBUG, ("%p Media end time is %lld", mDecoder, mEndTime)); } void nsBuiltinDecoderStateMachine::UpdateReadyState() { @@ -1658,7 +1656,7 @@ PRBool nsBuiltinDecoderStateMachine::JustExitedQuickBuffering() { return !mDecodeStartTime.IsNull() && mQuickBuffering && - (TimeStamp::Now() - mDecodeStartTime) < TimeDuration::FromSeconds(QUICK_BUFFER_THRESHOLD_MS); + (TimeStamp::Now() - mDecodeStartTime) < TimeDuration::FromSeconds(QUICK_BUFFER_THRESHOLD_USECS); } void nsBuiltinDecoderStateMachine::StartBuffering() @@ -1671,7 +1669,7 @@ void nsBuiltinDecoderStateMachine::StartBuffering() // when the download speed is similar to the decode speed. mQuickBuffering = !JustExitedQuickBuffering() && - decodeDuration < TimeDuration::FromMilliseconds(QUICK_BUFFER_THRESHOLD_MS); + decodeDuration < UsecsToDuration(QUICK_BUFFER_THRESHOLD_USECS); mBufferingStart = TimeStamp::Now(); // We need to tell the element that buffering has started. diff --git a/content/media/nsBuiltinDecoderStateMachine.h b/content/media/nsBuiltinDecoderStateMachine.h index c168e8f57192..6421c58b4498 100644 --- a/content/media/nsBuiltinDecoderStateMachine.h +++ b/content/media/nsBuiltinDecoderStateMachine.h @@ -253,23 +253,23 @@ public: protected: - // Returns PR_TRUE if we'v got less than aAudioMs ms of decoded and playable - // data. The decoder monitor must be held. - PRBool HasLowDecodedData(PRInt64 aAudioMs) const; + // Returns PR_TRUE if we've got less than aAudioUsecs microseconds of decoded + // and playable data. The decoder monitor must be held. + PRBool HasLowDecodedData(PRInt64 aAudioUsecs) const; // Returns PR_TRUE if we're running low on data which is not yet decoded. // The decoder monitor must be held. PRBool HasLowUndecodedData() const; - // Returns the number of milliseconds of undecoded data available for + // Returns the number of microseconds of undecoded data available for // decoding. The decoder monitor must be held. PRInt64 GetUndecodedData() const; - // Returns the number of unplayed ms of audio we've got decoded and/or + // Returns the number of unplayed usecs of audio we've got decoded and/or // pushed to the hardware waiting to play. This is how much audio we can // play without having to run the audio decoder. The decoder monitor // must be held. - PRInt64 AudioDecodedMs() const; + PRInt64 AudioDecodedUsecs() const; // Returns PR_TRUE when there's decoded audio waiting to play. // The decoder monitor must be held. @@ -278,13 +278,13 @@ protected: // Returns PR_TRUE if we recently exited "quick buffering" mode. PRBool JustExitedQuickBuffering(); - // Waits on the decoder Monitor for aMs. If the decoder monitor is awoken - // by a Notify() call, we'll continue waiting, unless we've moved into - // shutdown state. This enables us to ensure that we wait for a specified - // time, and that the myriad of Notify()s we do an the decoder monitor - // don't cause the audio thread to be starved. The decoder monitor must - // be locked. - void Wait(PRInt64 aMs); + // Waits on the decoder Monitor for aUsecs microseconds. If the decoder + // monitor is awoken by a Notify() call, we'll continue waiting, unless + // we've moved into shutdown state. This enables us to ensure that we + // wait for a specified time, and that the myriad of Notify()s we do an + // the decoder monitor don't cause the audio thread to be starved. The + // decoder monitor must be locked. + void Wait(PRInt64 aUsecs); // Dispatches an asynchronous event to update the media element's ready state. void UpdateReadyState(); @@ -334,7 +334,8 @@ protected: // hardware. This ensures that the playback position advances smoothly, and // guarantees that we don't try to allocate an impossibly large chunk of // memory in order to play back silence. Called on the audio thread. - PRUint32 PlaySilence(PRUint32 aSamples, PRUint32 aChannels, + PRUint32 PlaySilence(PRUint32 aSamples, + PRUint32 aChannels, PRUint64 aSampleOffset); // Pops an audio chunk from the front of the audio queue, and pushes its @@ -392,9 +393,9 @@ protected: return mStartTime + mCurrentFrameTime; } - // Returns an upper bound on the number of milliseconds of audio that is - // decoded and playable. This is the sum of the number of ms of audio which - // is decoded and in the reader's audio queue, and the ms of unplayed audio + // Returns an upper bound on the number of microseconds of audio that is + // decoded and playable. This is the sum of the number of usecs of audio which + // is decoded and in the reader's audio queue, and the usecs of unplayed audio // which has been pushed to the audio hardware for playback. Note that after // calling this, the audio hardware may play some of the audio pushed to // hardware, so this can only be used as a upper bound. The decoder monitor @@ -430,25 +431,25 @@ protected: // playback position is therefore |Now() - mPlayStartTime + // mPlayDuration|, which must be adjusted by mStartTime if used with media // timestamps. Accessed only via the state machine thread. - TimeDuration mPlayDuration; + PRInt64 mPlayDuration; // Time that buffering started. Used for buffering timeout and only // accessed on the state machine thread. This is null while we're not // buffering. TimeStamp mBufferingStart; - // Start time of the media, in milliseconds. This is the presentation + // Start time of the media, in microseconds. This is the presentation // time of the first sample decoded from the media, and is used to calculate // duration and as a bounds for seeking. Accessed on state machine and // main thread. Access controlled by decoder monitor. PRInt64 mStartTime; - // Time of the last page in the media, in milliseconds. This is the + // Time of the last page in the media, in microseconds. This is the // end time of the last sample in the media. Accessed on state // machine and main thread. Access controlled by decoder monitor. PRInt64 mEndTime; - // Position to seek to in milliseconds when the seek state transition occurs. + // Position to seek to in microseconds when the seek state transition occurs. // The decoder monitor lock must be obtained before reading or writing // this value. Accessed on main and state machine thread. PRInt64 mSeekTime; @@ -463,24 +464,25 @@ protected: // in the play state machine's destructor. nsAutoPtr mReader; - // The time of the current frame in milliseconds. This is referenced from + // The time of the current frame in microseconds. This is referenced from // 0 which is the initial playback position. Set by the state machine // thread, and read-only from the main thread to get the current // time value. Synchronised via decoder monitor. PRInt64 mCurrentFrameTime; - // The presentation time of the first audio sample that was played. We can - // add this to the audio stream position to determine the current audio time. - // Accessed on audio and state machine thread. Synchronized by decoder monitor. + // The presentation time of the first audio sample that was played in + // microseconds. We can add this to the audio stream position to determine + // the current audio time. Accessed on audio and state machine thread. + // Synchronized by decoder monitor. PRInt64 mAudioStartTime; // The end time of the last audio sample that's been pushed onto the audio - // hardware. This will approximately be the end time of the audio stream, - // unless another sample is pushed to the hardware. + // hardware in microseconds. This will approximately be the end time of the + // audio stream, unless another sample is pushed to the hardware. PRInt64 mAudioEndTime; - // The presentation end time of the last video frame which has been displayed. - // Accessed from the state machine thread. + // The presentation end time of the last video frame which has been displayed + // in microseconds. Accessed from the state machine thread. PRInt64 mVideoFrameEndTime; // Volume of playback. 0.0 = muted. 1.0 = full volume. Read/Written diff --git a/content/media/nsMediaCache.cpp b/content/media/nsMediaCache.cpp index 19c53790df1b..0d04abb0077d 100644 --- a/content/media/nsMediaCache.cpp +++ b/content/media/nsMediaCache.cpp @@ -740,7 +740,7 @@ static PRInt32 GetMaxBlocks() // to the pref are applied. // Cache size is in KB PRInt32 cacheSize = nsContentUtils::GetIntPref("media.cache_size", 500*1024); - PRInt64 maxBlocks = PRInt64(cacheSize)*1024/nsMediaCache::BLOCK_SIZE; + PRInt64 maxBlocks = static_cast(cacheSize)*1024/nsMediaCache::BLOCK_SIZE; maxBlocks = PR_MAX(maxBlocks, 1); return PRInt32(PR_MIN(maxBlocks, PR_INT32_MAX)); } @@ -1032,7 +1032,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock) case PLAYED_BLOCK: // This block should be managed in LRU mode, and we should impose // a "replay delay" to reflect the likelihood of replay happening - NS_ASSERTION(PRInt64(bo->mStreamBlock)*BLOCK_SIZE < + NS_ASSERTION(static_cast(bo->mStreamBlock)*BLOCK_SIZE < bo->mStream->mStreamOffset, "Played block after the current stream position?"); prediction = aNow - bo->mLastUseTime + @@ -1040,7 +1040,7 @@ nsMediaCache::PredictNextUse(TimeStamp aNow, PRInt32 aBlock) break; case READAHEAD_BLOCK: { PRInt64 bytesAhead = - PRInt64(bo->mStreamBlock)*BLOCK_SIZE - bo->mStream->mStreamOffset; + static_cast(bo->mStreamBlock)*BLOCK_SIZE - bo->mStream->mStreamOffset; NS_ASSERTION(bytesAhead >= 0, "Readahead block before the current stream position?"); PRInt64 millisecondsAhead = diff --git a/content/media/nsMediaDecoder.h b/content/media/nsMediaDecoder.h index 6e2d7cefdb9c..7187c35a1e69 100644 --- a/content/media/nsMediaDecoder.h +++ b/content/media/nsMediaDecoder.h @@ -282,10 +282,10 @@ public: // Return the frame decode/paint related statistics. FrameStatistics& GetFrameStatistics() { return mFrameStats; } - // Set the duration of the media resource in units of milliseconds. + // Set the duration of the media resource in units of seconds. // This is called via a channel listener if it can pick up the duration // from a content header. Must be called from the main thread only. - virtual void SetDuration(PRInt64 aDuration) = 0; + virtual void SetDuration(double aDuration) = 0; // Set a flag indicating whether seeking is supported virtual void SetSeekable(PRBool aSeekable) = 0; diff --git a/content/media/nsMediaStream.cpp b/content/media/nsMediaStream.cpp index ba434354fb60..04f7da0ad55d 100644 --- a/content/media/nsMediaStream.cpp +++ b/content/media/nsMediaStream.cpp @@ -222,7 +222,7 @@ nsMediaChannelStream::OnStartRequest(nsIRequest* aRequest) if (NS_SUCCEEDED(rv)) { double duration = durationText.ToDouble(&ec); if (ec == NS_OK && duration >= 0) { - mDecoder->SetDuration(PRInt64(NS_round(duration*1000))); + mDecoder->SetDuration(duration); } } } diff --git a/content/media/nsMediaStream.h b/content/media/nsMediaStream.h index 0f0b7be893e9..544461ed0cbd 100644 --- a/content/media/nsMediaStream.h +++ b/content/media/nsMediaStream.h @@ -107,7 +107,7 @@ public: *aReliable = seconds >= 1.0; if (seconds <= 0.0) return 0.0; - return double(mAccumulatedBytes)/seconds; + return static_cast(mAccumulatedBytes)/seconds; } double GetRate(TimeStamp aNow, PRPackedBool* aReliable) { TimeDuration time = mAccumulatedTime; @@ -118,7 +118,7 @@ public: *aReliable = seconds >= 3.0; if (seconds <= 0.0) return 0.0; - return double(mAccumulatedBytes)/seconds; + return static_cast(mAccumulatedBytes)/seconds; } private: PRInt64 mAccumulatedBytes; diff --git a/content/media/ogg/nsOggCodecState.cpp b/content/media/ogg/nsOggCodecState.cpp index 02c27ab0a409..ef62b915ab0d 100644 --- a/content/media/ogg/nsOggCodecState.cpp +++ b/content/media/ogg/nsOggCodecState.cpp @@ -126,7 +126,6 @@ nsTheoraState::nsTheoraState(ogg_page* aBosPage) : nsOggCodecState(aBosPage), mSetup(0), mCtx(0), - mFrameDuration(0), mPixelAspectRatio(0) { MOZ_COUNT_CTOR(nsTheoraState); @@ -146,22 +145,9 @@ PRBool nsTheoraState::Init() { if (!mActive) return PR_FALSE; - PRInt64 n = mInfo.fps_numerator; - PRInt64 d = mInfo.fps_denominator; + PRInt64 n = mInfo.aspect_numerator; + PRInt64 d = mInfo.aspect_denominator; - PRInt64 f; - if (!MulOverflow(1000, d, f)) { - return mActive = PR_FALSE; - } - f /= n; - if (f > PR_UINT32_MAX) { - return mActive = PR_FALSE; - } - mFrameDuration = static_cast(f); - - n = mInfo.aspect_numerator; - - d = mInfo.aspect_denominator; mPixelAspectRatio = (n == 0 || d == 0) ? 1.0f : static_cast(n) / static_cast(d); @@ -244,7 +230,7 @@ PRInt64 nsTheoraState::Time(th_info* aInfo, PRInt64 aGranulepos) PRInt64 frameno = iframe + pframe - TH_VERSION_CHECK(aInfo, 3, 2, 1); if (!AddOverflow(frameno, 1, t)) return -1; - if (!MulOverflow(t, 1000, t)) + if (!MulOverflow(t, USECS_PER_S, t)) return -1; if (!MulOverflow(t, aInfo->fps_denominator, t)) return -1; @@ -257,7 +243,7 @@ PRInt64 nsTheoraState::StartTime(PRInt64 granulepos) { } PRInt64 t = 0; PRInt64 frameno = th_granule_frame(mCtx, granulepos); - if (!MulOverflow(frameno, 1000, t)) + if (!MulOverflow(frameno, USECS_PER_S, t)) return -1; if (!MulOverflow(t, mInfo.fps_denominator, t)) return -1; @@ -267,25 +253,22 @@ PRInt64 nsTheoraState::StartTime(PRInt64 granulepos) { PRInt64 nsTheoraState::MaxKeyframeOffset() { - // Determine the maximum time in milliseconds by which a key frame could + // Determine the maximum time in microseconds by which a key frame could // offset for the theora bitstream. Theora granulepos encode time as: // ((key_frame_number << granule_shift) + frame_offset). // Therefore the maximum possible time by which any frame could be offset // from a keyframe is the duration of (1 << granule_shift) - 1) frames. PRInt64 frameDuration; - PRInt64 keyframeDiff; - - PRInt64 shift = mInfo.keyframe_granule_shift; - + // Max number of frames keyframe could possibly be offset. - keyframeDiff = (1 << shift) - 1; + PRInt64 keyframeDiff = (1 << mInfo.keyframe_granule_shift) - 1; - // Length of frame in ms. + // Length of frame in usecs. PRInt64 d = 0; // d will be 0 if multiplication overflows. - MulOverflow(1000, mInfo.fps_denominator, d); + MulOverflow(USECS_PER_S, mInfo.fps_denominator, d); frameDuration = d / mInfo.fps_numerator; - // Total time in ms keyframe can be offset from any given frame. + // Total time in usecs keyframe can be offset from any given frame. return frameDuration * keyframeDiff; } @@ -390,7 +373,7 @@ PRInt64 nsVorbisState::Time(vorbis_info* aInfo, PRInt64 aGranulepos) return -1; } PRInt64 t = 0; - MulOverflow(1000, aGranulepos, t); + MulOverflow(USECS_PER_S, aGranulepos, t); return t / aInfo->rate; } @@ -522,7 +505,7 @@ PRBool nsSkeletonState::DecodeIndex(ogg_packet* aPacket) // Extract the start time. n = LEInt64(p + INDEX_FIRST_NUMER_OFFSET); PRInt64 t; - if (!MulOverflow(n, 1000, t)) { + if (!MulOverflow(n, USECS_PER_S, t)) { return (mActive = PR_FALSE); } else { startTime = t / timeDenom; @@ -530,7 +513,7 @@ PRBool nsSkeletonState::DecodeIndex(ogg_packet* aPacket) // Extract the end time. n = LEInt64(p + INDEX_LAST_NUMER_OFFSET); - if (!MulOverflow(n, 1000, t)) { + if (!MulOverflow(n, USECS_PER_S, t)) { return (mActive = PR_FALSE); } else { endTime = t / timeDenom; @@ -590,11 +573,11 @@ PRBool nsSkeletonState::DecodeIndex(ogg_packet* aPacket) { return (mActive = PR_FALSE); } - PRInt64 timeMs = 0; - if (!MulOverflow(time, 1000, timeMs)) + PRInt64 timeUsecs = 0; + if (!MulOverflow(time, USECS_PER_S, timeUsecs)) return mActive = PR_FALSE; - timeMs /= timeDenom; - keyPoints->Add(offset, timeMs); + timeUsecs /= timeDenom; + keyPoints->Add(offset, timeUsecs); numKeyPointsRead++; } @@ -713,7 +696,7 @@ PRBool nsSkeletonState::DecodeHeader(ogg_packet* aPacket) // presentation time exists in all versions. PRInt64 n = LEInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_NUMERATOR_OFFSET); PRInt64 d = LEInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_DENOMINATOR_OFFSET); - mPresentationTime = d == 0 ? 0 : (static_cast(n) / static_cast(d)) * 1000; + mPresentationTime = d == 0 ? 0 : (static_cast(n) / static_cast(d)) * USECS_PER_S; mVersion = SKELETON_VERSION(verMajor, verMinor); if (mVersion < SKELETON_VERSION(4,0) || diff --git a/content/media/ogg/nsOggCodecState.h b/content/media/ogg/nsOggCodecState.h index e45ff33eb559..20121cec57da 100644 --- a/content/media/ogg/nsOggCodecState.h +++ b/content/media/ogg/nsOggCodecState.h @@ -183,7 +183,7 @@ public: virtual PRInt64 StartTime(PRInt64 granulepos); virtual PRBool Init(); - // Returns the maximum number of milliseconds which a keyframe can be offset + // Returns the maximum number of microseconds which a keyframe can be offset // from any given interframe. PRInt64 MaxKeyframeOffset(); @@ -195,9 +195,6 @@ public: th_setup_info *mSetup; th_dec_ctx* mCtx; - // Frame duration in ms. - PRUint32 mFrameDuration; - float mPixelAspectRatio; }; @@ -233,7 +230,7 @@ public: // Offset from start of segment/link-in-the-chain in bytes. PRInt64 mOffset; - // Presentation time in ms. + // Presentation time in usecs. PRInt64 mTime; PRBool IsNull() { @@ -320,10 +317,10 @@ private: return mKeyPoints.Length(); } - // Presentation time of the first sample in this stream in ms. + // Presentation time of the first sample in this stream in usecs. const PRInt64 mStartTime; - // End time of the last sample in this stream in ms. + // End time of the last sample in this stream in usecs. const PRInt64 mEndTime; private: diff --git a/content/media/ogg/nsOggReader.cpp b/content/media/ogg/nsOggReader.cpp index e7eddc23b0a4..34cb78b15dfe 100644 --- a/content/media/ogg/nsOggReader.cpp +++ b/content/media/ogg/nsOggReader.cpp @@ -68,15 +68,15 @@ extern PRLogModuleInfo* gBuiltinDecoderLog; // position, we'll just decode forwards rather than performing a bisection // search. If we have Theora video we use the maximum keyframe interval as // this value, rather than SEEK_DECODE_MARGIN. This makes small seeks faster. -#define SEEK_DECODE_MARGIN 2000 +#define SEEK_DECODE_MARGIN 2000000 -// The number of milliseconds of "fuzz" we use in a bisection search over +// The number of microseconds of "fuzz" we use in a bisection search over // HTTP. When we're seeking with fuzz, we'll stop the search if a bisection -// lands between the seek target and SEEK_FUZZ_MS milliseconds before the +// lands between the seek target and SEEK_FUZZ_USECS microseconds before the // seek target. This is becaue it's usually quicker to just keep downloading // from an exisiting connection than to do another bisection inside that // small range, which would open a new HTTP connetion. -#define SEEK_FUZZ_MS 500 +#define SEEK_FUZZ_USECS 500000 enum PageSyncResult { PAGE_SYNC_ERROR = 1, @@ -390,8 +390,7 @@ nsresult nsOggReader::DecodeVorbis(nsTArray >& aChunks, } PRInt64 duration = mVorbisState->Time((PRInt64)samples); - PRInt64 startTime = (mVorbisGranulepos != -1) ? - mVorbisState->Time(mVorbisGranulepos) : -1; + PRInt64 startTime = mVorbisState->Time(mVorbisGranulepos); SoundData* s = new SoundData(mPageOffset, startTime, duration, @@ -544,9 +543,8 @@ nsresult nsOggReader::DecodeTheora(nsTArray >& aFrames, if (ret != 0 && ret != TH_DUPFRAME) { return NS_ERROR_FAILURE; } - PRInt64 time = (aPacket->granulepos != -1) - ? mTheoraState->StartTime(aPacket->granulepos) : -1; - PRInt64 endTime = time != -1 ? time + mTheoraState->mFrameDuration : -1; + PRInt64 time = mTheoraState->StartTime(aPacket->granulepos); + PRInt64 endTime = mTheoraState->Time(aPacket->granulepos); if (ret == TH_DUPFRAME) { VideoData* v = VideoData::CreateDuplicate(mPageOffset, time, @@ -704,7 +702,7 @@ PRBool nsOggReader::DecodeVideoFrame(PRBool &aKeyframeSkip, "Granulepos calculation is incorrect!"); frames[i]->mTime = mTheoraState->StartTime(granulepos); - frames[i]->mEndTime = frames[i]->mTime + mTheoraState->mFrameDuration; + frames[i]->mEndTime = mTheoraState->Time(granulepos); NS_ASSERTION(frames[i]->mEndTime >= frames[i]->mTime, "Frame must start before it ends."); frames[i]->mTimecode = granulepos; } @@ -1257,7 +1255,7 @@ nsresult nsOggReader::SeekInBufferedRange(PRInt64 aTarget, aStartTime, aEndTime, PR_FALSE); - res = SeekBisection(keyframeTime, k, SEEK_FUZZ_MS); + res = SeekBisection(keyframeTime, k, SEEK_FUZZ_USECS); NS_ASSERTION(mTheoraGranulepos == -1, "SeekBisection must reset Theora decode"); NS_ASSERTION(mVorbisGranulepos == -1, "SeekBisection must reset Vorbis decode"); } @@ -1283,7 +1281,7 @@ nsresult nsOggReader::SeekInUnbuffered(PRInt64 aTarget, LOG(PR_LOG_DEBUG, ("%p Seeking in unbuffered data to %lldms using bisection search", mDecoder, aTarget)); // If we've got an active Theora bitstream, determine the maximum possible - // time in ms which a keyframe could be before a given interframe. We + // time in usecs which a keyframe could be before a given interframe. We // subtract this from our seek target, seek to the new target, and then // will decode forward to the original seek target. We should encounter a // keyframe in that interval. This prevents us from needing to run two @@ -1302,7 +1300,7 @@ nsresult nsOggReader::SeekInUnbuffered(PRInt64 aTarget, // Minimize the bisection search space using the known timestamps from the // buffered ranges. SeekRange k = SelectSeekRange(aRanges, seekTarget, aStartTime, aEndTime, PR_FALSE); - nsresult res = SeekBisection(seekTarget, k, SEEK_FUZZ_MS); + nsresult res = SeekBisection(seekTarget, k, SEEK_FUZZ_USECS); NS_ASSERTION(mTheoraGranulepos == -1, "SeekBisection must reset Theora decode"); NS_ASSERTION(mVorbisGranulepos == -1, "SeekBisection must reset Vorbis decode"); return res; @@ -1786,9 +1784,8 @@ nsresult nsOggReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime) // find an end time. PRInt64 endTime = FindEndTime(startOffset, endOffset, PR_TRUE, &state); if (endTime != -1) { - endTime -= aStartTime; - aBuffered->Add(static_cast(startTime) / 1000.0, - static_cast(endTime) / 1000.0); + aBuffered->Add(startTime / static_cast(USECS_PER_S), + (endTime - aStartTime) / static_cast(USECS_PER_S)); } } } diff --git a/content/media/ogg/nsOggReader.h b/content/media/ogg/nsOggReader.h index ae412c0085d5..725f02db2633 100644 --- a/content/media/ogg/nsOggReader.h +++ b/content/media/ogg/nsOggReader.h @@ -104,8 +104,8 @@ private: // Returns PR_TRUE if we should decode up to the seek target rather than // seeking to the target using a bisection search or index-assisted seek. - // We should do this if the seek target (aTarget, in ms), lies not too far - // ahead of the current playback position (aCurrentTime, in ms). + // We should do this if the seek target (aTarget, in usecs), lies not too far + // ahead of the current playback position (aCurrentTime, in usecs). PRBool CanDecodeToTarget(PRInt64 aTarget, PRInt64 aCurrentTime); @@ -152,10 +152,10 @@ private: } PRInt64 mOffsetStart, mOffsetEnd; // in bytes. - PRInt64 mTimeStart, mTimeEnd; // in ms. + PRInt64 mTimeStart, mTimeEnd; // in usecs. }; - // Seeks to aTarget ms in the buffered range aRange using bisection search, + // Seeks to aTarget usecs in the buffered range aRange using bisection search, // or to the keyframe prior to aTarget if we have video. aStartTime must be // the presentation time at the start of media, and aEndTime the time at // end of media. aRanges must be the time/byte ranges buffered in the media @@ -166,7 +166,7 @@ private: const nsTArray& aRanges, const SeekRange& aRange); - // Seeks to before aTarget ms in media using bisection search. If the media + // Seeks to before aTarget usecs in media using bisection search. If the media // has video, this will seek to before the keyframe required to render the // media at aTarget. Will use aRanges in order to narrow the bisection // search space. aStartTime must be the presentation time at the start of @@ -208,11 +208,11 @@ private: PRBool ReadOggPacket(nsOggCodecState* aCodecState, ogg_packet* aPacket); // Performs a seek bisection to move the media stream's read cursor to the - // last ogg page boundary which has end time before aTarget ms on both the + // last ogg page boundary which has end time before aTarget usecs on both the // Theora and Vorbis bitstreams. Limits its search to data inside aRange; // i.e. it will only read inside of the aRange's start and end offsets. - // aFuzz is the number of ms of leniency we'll allow; we'll terminate the - // seek when we land in the range (aTime - aFuzz, aTime) ms. + // aFuzz is the number of usecs of leniency we'll allow; we'll terminate the + // seek when we land in the range (aTime - aFuzz, aTime) usecs. nsresult SeekBisection(PRInt64 aTarget, const SeekRange& aRange, PRUint32 aFuzz); @@ -228,7 +228,7 @@ private: nsresult GetSeekRanges(nsTArray& aRanges); // Returns the range in which you should perform a seek bisection if - // you wish to seek to aTarget ms, given the known (buffered) byte ranges + // you wish to seek to aTarget usecs, given the known (buffered) byte ranges // in aRanges. If aExact is PR_TRUE, we only return an exact copy of a // range in which aTarget lies, or a null range if aTarget isn't contained // in any of the (buffered) ranges. Otherwise, when aExact is PR_FALSE, diff --git a/content/media/raw/nsRawReader.cpp b/content/media/raw/nsRawReader.cpp index 02db528b0b6d..a662dad6bb94 100644 --- a/content/media/raw/nsRawReader.cpp +++ b/content/media/raw/nsRawReader.cpp @@ -129,7 +129,7 @@ nsresult nsRawReader::ReadMetadata(nsVideoInfo* aInfo) if (length != -1) { mozilla::MonitorAutoExit autoExitMonitor(mMonitor); mozilla::MonitorAutoEnter autoMonitor(mDecoder->GetMonitor()); - mDecoder->GetStateMachine()->SetDuration(1000 * + mDecoder->GetStateMachine()->SetDuration(USECS_PER_S * (length - sizeof(nsRawVideoHeader)) / (mFrameSize * mFrameRate)); } @@ -184,7 +184,7 @@ PRBool nsRawReader::DecodeVideoFrame(PRBool &aKeyframeSkip, if (!mFrameSize) return PR_FALSE; // Metadata read failed. We should refuse to play. - PRInt64 currentFrameTime = 1000 * mCurrentFrame / mFrameRate; + PRInt64 currentFrameTime = USECS_PER_S * mCurrentFrame / mFrameRate; PRUint32 length = mFrameSize - sizeof(nsRawPacketHeader); nsAutoArrayPtr buffer(new PRUint8[length]); @@ -212,7 +212,7 @@ PRBool nsRawReader::DecodeVideoFrame(PRBool &aKeyframeSkip, break; mCurrentFrame++; - currentFrameTime += 1000.0 / mFrameRate; + currentFrameTime += static_cast(USECS_PER_S) / mFrameRate; } VideoData::YCbCrBuffer b; @@ -237,7 +237,7 @@ PRBool nsRawReader::DecodeVideoFrame(PRBool &aKeyframeSkip, mDecoder->GetImageContainer(), -1, currentFrameTime, - currentFrameTime + (1000 / mFrameRate), + currentFrameTime + (USECS_PER_S / mFrameRate), b, 1, // In raw video every frame is a keyframe -1); @@ -247,7 +247,7 @@ PRBool nsRawReader::DecodeVideoFrame(PRBool &aKeyframeSkip, mVideoQueue.Push(v); mCurrentFrame++; decoded++; - currentFrameTime += 1000 / mFrameRate; + currentFrameTime += USECS_PER_S / mFrameRate; return PR_TRUE; } @@ -264,7 +264,7 @@ nsresult nsRawReader::Seek(PRInt64 aTime, PRInt64 aStartTime, PRInt64 aEndTime, PRUint32 frame = mCurrentFrame; if (aTime >= UINT_MAX) return NS_ERROR_FAILURE; - mCurrentFrame = aTime * mFrameRate / 1000; + mCurrentFrame = aTime * mFrameRate / USECS_PER_S; PRUint32 offset; if (!MulOverflow32(mCurrentFrame, mFrameSize, offset)) diff --git a/content/media/test/test_seekLies.html b/content/media/test/test_seekLies.html index 8c30ddd1feaa..13447cb499d9 100644 --- a/content/media/test/test_seekLies.html +++ b/content/media/test/test_seekLies.html @@ -13,7 +13,7 @@ function on_metadataloaded() { var v = document.getElementById('v'); var d = Math.round(v.duration*1000); - ok(d == 3999, "Checking duration: " + d); + ok(d == 4000, "Checking duration: " + d); SimpleTest.finish(); } diff --git a/content/media/wave/nsWaveReader.cpp b/content/media/wave/nsWaveReader.cpp index d7b384fe79b8..d4fceec68e91 100644 --- a/content/media/wave/nsWaveReader.cpp +++ b/content/media/wave/nsWaveReader.cpp @@ -171,9 +171,8 @@ nsresult nsWaveReader::ReadMetadata(nsVideoInfo* aInfo) MonitorAutoExit exitReaderMon(mMonitor); MonitorAutoEnter decoderMon(mDecoder->GetMonitor()); - float d = floorf(BytesToTime(GetDataLength() * 1000)); - NS_ASSERTION(d <= PR_INT64_MAX, "Duration overflow"); - mDecoder->GetStateMachine()->SetDuration(static_cast(d)); + mDecoder->GetStateMachine()->SetDuration( + static_cast(BytesToTime(GetDataLength()) * USECS_PER_S)); return NS_OK; } @@ -229,16 +228,18 @@ PRBool nsWaveReader::DecodeAudioData() } } - float posTime = BytesToTime(pos); - float readSizeTime = BytesToTime(readSize); - NS_ASSERTION(posTime <= PR_INT64_MAX / 1000, "posTime overflow"); - NS_ASSERTION(readSizeTime <= PR_INT64_MAX / 1000, "readSizeTime overflow"); + double posTime = BytesToTime(pos); + double readSizeTime = BytesToTime(readSize); + NS_ASSERTION(posTime <= PR_INT64_MAX / USECS_PER_S, "posTime overflow"); + NS_ASSERTION(readSizeTime <= PR_INT64_MAX / USECS_PER_S, "readSizeTime overflow"); NS_ASSERTION(samples < PR_INT32_MAX, "samples overflow"); - mAudioQueue.Push(new SoundData(pos, static_cast(posTime * 1000), - static_cast(readSizeTime * 1000), + mAudioQueue.Push(new SoundData(pos, + static_cast(posTime * USECS_PER_S), + static_cast(readSizeTime * USECS_PER_S), static_cast(samples), - sampleBuffer.forget(), mChannels)); + sampleBuffer.forget(), + mChannels)); return PR_TRUE; } @@ -258,15 +259,15 @@ nsresult nsWaveReader::Seek(PRInt64 aTarget, PRInt64 aStartTime, PRInt64 aEndTim MonitorAutoEnter mon(mMonitor); NS_ASSERTION(mDecoder->OnStateMachineThread(), "Should be on state machine thread."); - LOG(PR_LOG_DEBUG, ("%p About to seek to %lldms", mDecoder, aTarget)); + LOG(PR_LOG_DEBUG, ("%p About to seek to %lld", mDecoder, aTarget)); if (NS_FAILED(ResetDecode())) { return NS_ERROR_FAILURE; } - float d = BytesToTime(GetDataLength()); - NS_ASSERTION(d < PR_INT64_MAX / 1000, "Duration overflow"); - PRInt64 duration = static_cast(d) * 1000; - PRInt64 seekTime = NS_MIN(aTarget, duration); - PRInt64 position = RoundDownToSample(static_cast(TimeToBytes(seekTime) / 1000.f)); + double d = BytesToTime(GetDataLength()); + NS_ASSERTION(d < PR_INT64_MAX / USECS_PER_S, "Duration overflow"); + PRInt64 duration = static_cast(d * USECS_PER_S); + double seekTime = NS_MIN(aTarget, duration) / static_cast(USECS_PER_S); + PRInt64 position = RoundDownToSample(static_cast(TimeToBytes(seekTime))); NS_ASSERTION(PR_INT64_MAX - mWavePCMOffset > position, "Integer overflow during wave seek"); position += mWavePCMOffset; return mDecoder->GetCurrentStream()->Seek(nsISeekableStream::NS_SEEK_SET, position); @@ -281,8 +282,8 @@ nsresult nsWaveReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime) NS_ASSERTION(startOffset >= mWavePCMOffset, "Integer underflow in GetBuffered"); NS_ASSERTION(endOffset >= mWavePCMOffset, "Integer underflow in GetBuffered"); - aBuffered->Add(floorf(BytesToTime(startOffset - mWavePCMOffset) * 1000.f) / 1000.0, - floorf(BytesToTime(endOffset - mWavePCMOffset) * 1000.f) / 1000.0); + aBuffered->Add(BytesToTime(startOffset - mWavePCMOffset), + BytesToTime(endOffset - mWavePCMOffset)); startOffset = mDecoder->GetCurrentStream()->GetNextCachedData(endOffset); } return NS_OK; @@ -508,7 +509,7 @@ nsWaveReader::FindDataOffset() return PR_TRUE; } -float +double nsWaveReader::BytesToTime(PRInt64 aBytes) const { NS_ABORT_IF_FALSE(aBytes >= 0, "Must be >= 0"); @@ -516,7 +517,7 @@ nsWaveReader::BytesToTime(PRInt64 aBytes) const } PRInt64 -nsWaveReader::TimeToBytes(float aTime) const +nsWaveReader::TimeToBytes(double aTime) const { NS_ABORT_IF_FALSE(aTime >= 0.0f, "Must be >= 0"); return RoundDownToSample(PRInt64(aTime * mSampleRate * mSampleSize)); diff --git a/content/media/wave/nsWaveReader.h b/content/media/wave/nsWaveReader.h index a5a9a6e07651..fbf615b7506a 100644 --- a/content/media/wave/nsWaveReader.h +++ b/content/media/wave/nsWaveReader.h @@ -76,13 +76,13 @@ private: // Returns the number of seconds that aBytes represents based on the // current audio parameters. e.g. 176400 bytes is 1 second at 16-bit - // stereo 44.1kHz. The time is rounded to the nearest millisecond. - float BytesToTime(PRInt64 aBytes) const; + // stereo 44.1kHz. The time is rounded to the nearest microsecond. + double BytesToTime(PRInt64 aBytes) const; // Returns the number of bytes that aTime represents based on the current // audio parameters. e.g. 1 second is 176400 bytes at 16-bit stereo // 44.1kHz. - PRInt64 TimeToBytes(float aTime) const; + PRInt64 TimeToBytes(double aTime) const; // Rounds aBytes down to the nearest complete sample. Assumes beginning // of byte range is already sample aligned by caller. diff --git a/content/media/webm/nsWebMBufferedParser.cpp b/content/media/webm/nsWebMBufferedParser.cpp index 02349080d75d..0f724e37ecb6 100644 --- a/content/media/webm/nsWebMBufferedParser.cpp +++ b/content/media/webm/nsWebMBufferedParser.cpp @@ -44,7 +44,6 @@ using mozilla::MonitorAutoEnter; static const double NS_PER_S = 1e9; -static const double MS_PER_S = 1e3; static PRUint32 VIntLength(unsigned char aFirstByte, PRUint32* aMask) diff --git a/content/media/webm/nsWebMReader.cpp b/content/media/webm/nsWebMReader.cpp index 9a62ac531d21..06742f702306 100644 --- a/content/media/webm/nsWebMReader.cpp +++ b/content/media/webm/nsWebMReader.cpp @@ -65,14 +65,13 @@ extern PRLogModuleInfo* gBuiltinDecoderLog; #define SEEK_LOG(type, msg) #endif -static const unsigned NS_PER_MS = 1000000; +static const unsigned NS_PER_USEC = 1000; static const double NS_PER_S = 1e9; -static const double MS_PER_S = 1e3; -// If a seek request is within SEEK_DECODE_MARGIN milliseconds of the +// If a seek request is within SEEK_DECODE_MARGIN microseconds of the // current time, decode ahead from the current frame rather than performing // a full seek. -static const int SEEK_DECODE_MARGIN = 250; +static const int SEEK_DECODE_MARGIN = 250000; NS_SPECIALIZE_TEMPLATE class nsAutoRefTraits : public nsPointerRefTraits @@ -136,7 +135,7 @@ nsWebMReader::nsWebMReader(nsBuiltinDecoder* aDecoder) mChannels(0), mVideoTrack(0), mAudioTrack(0), - mAudioStartMs(-1), + mAudioStartUsec(-1), mAudioSamples(0), mHasVideo(PR_FALSE), mHasAudio(PR_FALSE) @@ -184,7 +183,7 @@ nsresult nsWebMReader::Init(nsBuiltinDecoderReader* aCloneDonor) nsresult nsWebMReader::ResetDecode() { mAudioSamples = 0; - mAudioStartMs = -1; + mAudioStartUsec = -1; nsresult res = NS_OK; if (NS_FAILED(nsBuiltinDecoderReader::ResetDecode())) { res = NS_ERROR_FAILURE; @@ -229,7 +228,7 @@ nsresult nsWebMReader::ReadMetadata(nsVideoInfo* aInfo) if (r == 0) { MonitorAutoExit exitReaderMon(mMonitor); MonitorAutoEnter decoderMon(mDecoder->GetMonitor()); - mDecoder->GetStateMachine()->SetDuration(duration / NS_PER_MS); + mDecoder->GetStateMachine()->SetDuration(duration / NS_PER_USEC); } unsigned int ntracks = 0; @@ -435,23 +434,23 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset) } const PRUint32 rate = mVorbisDsp.vi->rate; - PRUint64 tstamp_ms = tstamp / NS_PER_MS; - if (mAudioStartMs == -1) { + PRUint64 tstamp_usecs = tstamp / NS_PER_USEC; + if (mAudioStartUsec == -1) { // This is the first audio chunk. Assume the start time of our decode // is the start of this chunk. - mAudioStartMs = tstamp_ms; + mAudioStartUsec = tstamp_usecs; } // If there's a gap between the start of this sound chunk and the end of // the previous sound chunk, we need to increment the packet count so that // the vorbis decode doesn't use data from before the gap to help decode // from after the gap. PRInt64 tstamp_samples = 0; - if (!MsToSamples(tstamp_ms, rate, tstamp_samples)) { + if (!UsecsToSamples(tstamp_usecs, rate, tstamp_samples)) { NS_WARNING("Int overflow converting WebM timestamp to samples"); return PR_FALSE; } PRInt64 decoded_samples = 0; - if (!MsToSamples(mAudioStartMs, rate, decoded_samples)) { + if (!UsecsToSamples(mAudioStartUsec, rate, decoded_samples)) { NS_WARNING("Int overflow converting WebM start time to samples"); return PR_FALSE; } @@ -461,13 +460,13 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset) } if (tstamp_samples > decoded_samples) { #ifdef DEBUG - PRInt64 ms = 0; - LOG(PR_LOG_DEBUG, ("WebMReader detected gap of %lldms, %lld samples, in audio stream\n", - SamplesToMs(tstamp_samples - decoded_samples, rate, ms) ? ms: -1, + PRInt64 usecs = 0; + LOG(PR_LOG_DEBUG, ("WebMReader detected gap of %lld, %lld samples, in audio stream\n", + SamplesToUsecs(tstamp_samples - decoded_samples, rate, usecs) ? usecs: -1, tstamp_samples - decoded_samples)); #endif mPacketCount++; - mAudioStartMs = tstamp_ms; + mAudioStartUsec = tstamp_usecs; mAudioSamples = 0; } @@ -503,17 +502,17 @@ PRBool nsWebMReader::DecodeAudioPacket(nestegg_packet* aPacket, PRInt64 aOffset) } PRInt64 duration = 0; - if (!SamplesToMs(samples, rate, duration)) { + if (!SamplesToUsecs(samples, rate, duration)) { NS_WARNING("Int overflow converting WebM audio duration"); return PR_FALSE; } PRInt64 total_duration = 0; - if (!SamplesToMs(total_samples, rate, total_duration)) { + if (!SamplesToUsecs(total_samples, rate, total_duration)) { NS_WARNING("Int overflow converting WebM audio total_duration"); return PR_FALSE; } - PRInt64 time = tstamp_ms + total_duration; + PRInt64 time = tstamp_usecs + total_duration; total_samples += samples; SoundData* s = new SoundData(aOffset, time, @@ -668,11 +667,11 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip, if (endTime == -1) { return PR_FALSE; } - next_tstamp = endTime * NS_PER_MS; + next_tstamp = endTime * NS_PER_USEC; } } - PRInt64 tstamp_ms = tstamp / NS_PER_MS; + PRInt64 tstamp_usecs = tstamp / NS_PER_USEC; for (PRUint32 i = 0; i < count; ++i) { unsigned char* data; size_t length; @@ -685,7 +684,7 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip, memset(&si, 0, sizeof(si)); si.sz = sizeof(si); vpx_codec_peek_stream_info(&vpx_codec_vp8_dx_algo, data, length, &si); - if (aKeyframeSkip && (!si.is_kf || tstamp_ms < aTimeThreshold)) { + if (aKeyframeSkip && (!si.is_kf || tstamp_usecs < aTimeThreshold)) { // Skipping to next keyframe... parsed++; // Assume 1 frame per chunk. continue; @@ -702,7 +701,7 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip, // If the timestamp of the video frame is less than // the time threshold required then it is not added // to the video queue and won't be displayed. - if (tstamp_ms < aTimeThreshold) { + if (tstamp_usecs < aTimeThreshold) { parsed++; // Assume 1 frame per chunk. continue; } @@ -733,8 +732,8 @@ PRBool nsWebMReader::DecodeVideoFrame(PRBool &aKeyframeSkip, VideoData *v = VideoData::Create(mInfo, mDecoder->GetImageContainer(), holder->mOffset, - tstamp_ms, - next_tstamp / NS_PER_MS, + tstamp_usecs, + next_tstamp / NS_PER_USEC, b, si.is_kf, -1); @@ -774,7 +773,7 @@ nsresult nsWebMReader::Seek(PRInt64 aTarget, PRInt64 aStartTime, PRInt64 aEndTim return NS_ERROR_FAILURE; } PRUint32 trackToSeek = mHasVideo ? mVideoTrack : mAudioTrack; - int r = nestegg_track_seek(mContext, trackToSeek, aTarget * NS_PER_MS); + int r = nestegg_track_seek(mContext, trackToSeek, aTarget * NS_PER_USEC); if (r != 0) { return NS_ERROR_FAILURE; } @@ -803,7 +802,7 @@ nsresult nsWebMReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime) nsresult res = stream->GetCachedRanges(ranges); NS_ENSURE_SUCCESS(res, res); - PRInt64 startTimeOffsetNS = aStartTime * NS_PER_MS; + PRInt64 startTimeOffsetNS = aStartTime * NS_PER_USEC; for (PRUint32 index = 0; index < ranges.Length(); index++) { mBufferedState->CalculateBufferedForRange(aBuffered, ranges[index].mStart, diff --git a/content/media/webm/nsWebMReader.h b/content/media/webm/nsWebMReader.h index 37a99dd06f9c..e08ab1a81e57 100644 --- a/content/media/webm/nsWebMReader.h +++ b/content/media/webm/nsWebMReader.h @@ -192,8 +192,8 @@ private: // Returns PR_TRUE if we should decode up to the seek target rather than // seeking to the target using an index-assisted seek. We should do this - // if the seek target (aTarget, in ms), lies not too far ahead of the - // current playback position (aCurrentTime, in ms). + // if the seek target (aTarget, in usecs), lies not too far ahead of the + // current playback position (aCurrentTime, in usecs). PRBool CanDecodeToTarget(PRInt64 aTarget, PRInt64 aCurrentTime); private: @@ -221,8 +221,8 @@ private: PRUint32 mVideoTrack; PRUint32 mAudioTrack; - // Time in ms of the start of the first audio sample we've decoded. - PRInt64 mAudioStartMs; + // Time in microseconds of the start of the first audio sample we've decoded. + PRInt64 mAudioStartUsec; // Number of samples we've decoded since decoding began at mAudioStartMs. PRUint64 mAudioSamples; From db70e38a67cd715ca910b1075c1152ffa30ba9cc Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Thu, 14 Apr 2011 10:12:23 +1200 Subject: [PATCH 38/57] Bug 641718 - Round nsWaveReader's buffered ranges times to usecs. r=kinetik --- content/media/test/Makefile.in | 1 + content/media/test/audio.wav | Bin 0 -> 1422 bytes content/media/test/manifest.js | 1 + content/media/wave/nsWaveReader.cpp | 11 +++++++++-- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 content/media/test/audio.wav diff --git a/content/media/test/Makefile.in b/content/media/test/Makefile.in index e9f317bd4ac8..a538b7550a00 100644 --- a/content/media/test/Makefile.in +++ b/content/media/test/Makefile.in @@ -231,6 +231,7 @@ _TEST_FILES += \ r16000_u8_c1_list.wav \ wavedata_u8.wav \ wavedata_s16.wav \ + audio.wav \ $(NULL) # Other files diff --git a/content/media/test/audio.wav b/content/media/test/audio.wav new file mode 100644 index 0000000000000000000000000000000000000000..c6fd5cb869351be1b0fd2ccbdac51eb77066f464 GIT binary patch literal 1422 zcmYk6drVVj7{==#%h=rFoVu|v)QKLmI4)8YALjoQrbfAH+rKj zEwly7r3C@Yog#O%(0VCa&~7o&Y%ZEPqw%^Jr~bS5v|Hxyh`d^m2jZ$|l@%3K zYB>UxT2V=>VlY{?oI0LBB$YR)G&+OHY-w$`b#!*y?G6OHy}P@!!`9wvH8-1@^g4}7 zsgOyFeogx0v*5xtPbUrcsE5f)hDe z=)(v1r=@y*^AeFqL5L1!Mz&BNl0OUo!!dNqs76G|1T zMuXAZYU^_J_B)56=G4sG!s2=N(z3_n^?E&??b|&GvC%uWMuczK zv~j}+>)#6tdlw<>{q-Mi*tj`7Vq4UgyOUDV4yI>g@Fl0{ES^+luyphej!!Rod~3hl z{O!)Y2aliq_2T8L*KgjudHw3|moJ__ee~eZySH!M2>5+o_x$w4h_lbp*#^ey!B_}4 zGH5Vq0CYbHj2$Gep37!28T5*BGO?r>k2`_MJ)WJFnSo9}8YDd(jn2r-{4p#0cuww5 zm^_F97KbY+z~c)c2t~yJfpGFSXRt38aJ2u#7Z*S47B)nQW zr39aM41H){YI0&+Ow{(si11IhY~J)Suxay_Pr^Toh}<3(6T3SxIpw?k2ajZA5|RwY62h-+%S$m6a8r@A9RK z7d*>LZiw9c-0bw!Sr<%AaA^8M_FK)SCY@F(mk4=WRyD1hTuLa!=H+B(9z`O!H#H?W zDRFn~u9)bZJHFVqb!%kg=LnIJ+jd0ljE>nApYT<3%HHn}{D96nj=>Q~<@B05kwVjC zu{j1tCTGukeg43WTet80asT0?Cr_U}2cA8B^7!HXdv|~T_2!Mh>dHlrdtqjBY}nb? W(`{?BwwMe$tyGetCurrentStream()->Seek(nsISeekableStream::NS_SEEK_SET, position); } +static double RoundToUsecs(double aSeconds) { + return floor(aSeconds * USECS_PER_S) / USECS_PER_S; +} + nsresult nsWaveReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime) { PRInt64 startOffset = mDecoder->GetCurrentStream()->GetNextCachedData(mWavePCMOffset); @@ -282,8 +286,11 @@ nsresult nsWaveReader::GetBuffered(nsTimeRanges* aBuffered, PRInt64 aStartTime) NS_ASSERTION(startOffset >= mWavePCMOffset, "Integer underflow in GetBuffered"); NS_ASSERTION(endOffset >= mWavePCMOffset, "Integer underflow in GetBuffered"); - aBuffered->Add(BytesToTime(startOffset - mWavePCMOffset), - BytesToTime(endOffset - mWavePCMOffset)); + // We need to round the buffered ranges' times to microseconds so that they + // have the same precision as the currentTime and duration attribute on + // the media element. + aBuffered->Add(RoundToUsecs(BytesToTime(startOffset - mWavePCMOffset)), + RoundToUsecs(BytesToTime(endOffset - mWavePCMOffset))); startOffset = mDecoder->GetCurrentStream()->GetNextCachedData(endOffset); } return NS_OK; From b7751008fa2d986cd5677302721e4306097d33de Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 13 Apr 2011 19:41:33 -0700 Subject: [PATCH 39/57] Bug 593629: Only check for ARM SIMD and NEON when the CPU_ARCH is ARM. r=ted --- configure.in | 61 ++++++++++++++++++++++++--------------------- js/src/configure.in | 53 ++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/configure.in b/configure.in index 8f667097278f..e0da9a9f62c8 100644 --- a/configure.in +++ b/configure.in @@ -3589,36 +3589,39 @@ AC_SUBST(XEXT_LIBS) AC_SUBST(XT_LIBS) AC_SUBST(XSS_LIBS) -AC_MSG_CHECKING(for ARM SIMD support in compiler) -# We try to link so that this also fails when -# building with LTO. -AC_TRY_LINK([], - [asm("uqadd8 r1, r1, r2");], - result="yes", result="no") -AC_MSG_RESULT("$result") -if test "$result" = "yes"; then - AC_DEFINE(HAVE_ARM_SIMD) - HAVE_ARM_SIMD=1 -fi -AC_SUBST(HAVE_ARM_SIMD) +if test "$CPU_ARCH" = "arm"; then + AC_MSG_CHECKING(for ARM SIMD support in compiler) + # We try to link so that this also fails when + # building with LTO. + AC_TRY_LINK([], + [asm("uqadd8 r1, r1, r2");], + result="yes", result="no") + AC_MSG_RESULT("$result") + if test "$result" = "yes"; then + AC_DEFINE(HAVE_ARM_SIMD) + HAVE_ARM_SIMD=1 + fi -AC_MSG_CHECKING(for ARM NEON support in compiler) -_SAVE_CFLAGS="$CFLAGS" -if test "$GNU_CC"; then - # gcc needs -mfpu=neon to recognize NEON instructions - CFLAGS="$CFLAGS -mfpu=neon -mfloat-abi=softfp" -fi -# We try to link so that this also fails when -# building with LTO. -AC_TRY_LINK([], - [asm("vadd.i8 d0, d0, d0");], - result="yes", result="no") -AC_MSG_RESULT("$result") -if test "$result" = "yes"; then - AC_DEFINE(HAVE_ARM_NEON) - HAVE_ARM_NEON=1 -fi -CFLAGS="$_SAVE_CFLAGS" + AC_MSG_CHECKING(for ARM NEON support in compiler) + _SAVE_CFLAGS="$CFLAGS" + if test "$GNU_CC"; then + # gcc needs -mfpu=neon to recognize NEON instructions + CFLAGS="$CFLAGS -mfpu=neon -mfloat-abi=softfp" + fi + # We try to link so that this also fails when + # building with LTO. + AC_TRY_LINK([], + [asm("vadd.i8 d0, d0, d0");], + result="yes", result="no") + AC_MSG_RESULT("$result") + if test "$result" = "yes"; then + AC_DEFINE(HAVE_ARM_NEON) + HAVE_ARM_NEON=1 + fi + CFLAGS="$_SAVE_CFLAGS" +fi # CPU_ARCH = arm + +AC_SUBST(HAVE_ARM_SIMD) AC_SUBST(HAVE_ARM_NEON) dnl ======================================================== diff --git a/js/src/configure.in b/js/src/configure.in index 346009182530..cb955826e2e4 100644 --- a/js/src/configure.in +++ b/js/src/configure.in @@ -1,5 +1,5 @@ dnl -*- Mode: Autoconf; tab-width: 4; indent-tabs-mode: nil; -*- -dnl vi: set tabstop=4 shiftwidth=4 expandtab: +dnl vi: set tabstop=4 shiftwidth=4 expandtab syntax=m4: dnl ***** BEGIN LICENSE BLOCK ***** dnl Version: MPL 1.1/GPL 2.0/LGPL 2.1 dnl @@ -3455,32 +3455,35 @@ case $target in AC_CHECK_LIB(socket, socket) esac -AC_MSG_CHECKING(for ARM SIMD support in compiler) -AC_TRY_COMPILE([], - [asm("uqadd8 r1, r1, r2");], - result="yes", result="no") -AC_MSG_RESULT("$result") -if test "$result" = "yes"; then - AC_DEFINE(HAVE_ARM_SIMD) - HAVE_ARM_SIMD=1 -fi -AC_SUBST(HAVE_ARM_SIMD) +if test "$CPU_ARCH" = "arm"; then + AC_MSG_CHECKING(for ARM SIMD support in compiler) + AC_TRY_COMPILE([], + [asm("uqadd8 r1, r1, r2");], + result="yes", result="no") + AC_MSG_RESULT("$result") + if test "$result" = "yes"; then + AC_DEFINE(HAVE_ARM_SIMD) + HAVE_ARM_SIMD=1 + fi -AC_MSG_CHECKING(for ARM NEON support in compiler) -_SAVE_CFLAGS="$CFLAGS" -if test "$GNU_CC"; then - # gcc needs -mfpu=neon to recognize NEON instructions - CFLAGS="$CFLAGS -mfpu=neon -mfloat-abi=softfp" + AC_MSG_CHECKING(for ARM NEON support in compiler) + _SAVE_CFLAGS="$CFLAGS" + if test "$GNU_CC"; then + # gcc needs -mfpu=neon to recognize NEON instructions + CFLAGS="$CFLAGS -mfpu=neon -mfloat-abi=softfp" + fi + AC_TRY_COMPILE([], + [asm("vadd.i8 d0, d0, d0");], + result="yes", result="no") + AC_MSG_RESULT("$result") + if test "$result" = "yes"; then + AC_DEFINE(HAVE_ARM_NEON) + HAVE_ARM_NEON=1 + fi + CFLAGS="$_SAVE_CFLAGS" fi -AC_TRY_COMPILE([], - [asm("vadd.i8 d0, d0, d0");], - result="yes", result="no") -AC_MSG_RESULT("$result") -if test "$result" = "yes"; then - AC_DEFINE(HAVE_ARM_NEON) - HAVE_ARM_NEON=1 -fi -CFLAGS="$_SAVE_CFLAGS" + +AC_SUBST(HAVE_ARM_SIMD) AC_SUBST(HAVE_ARM_NEON) dnl ======================================================== From b8748273e731e05d06e546ac66962c8bab95536e Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Wed, 13 Apr 2011 19:41:34 -0700 Subject: [PATCH 40/57] Bug 607114: Expose a File constructor to chrome script. r=sicking --HG-- rename : content/canvas/test/image_yellow.png => content/base/test/chrome/fileconstructor_file.png --- content/base/public/nsDOMFile.h | 15 +++- content/base/src/nsDOMFile.cpp | 52 +++++++++++++ content/base/test/chrome/Makefile.in | 2 + .../base/test/chrome/fileconstructor_file.png | Bin 0 -> 95 bytes .../base/test/chrome/test_fileconstructor.xul | 70 ++++++++++++++++++ content/base/test/test_fileapi.html | 9 +++ dom/base/nsDOMClassInfo.cpp | 1 + 7 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 content/base/test/chrome/fileconstructor_file.png create mode 100644 content/base/test/chrome/test_fileconstructor.xul diff --git a/content/base/public/nsDOMFile.h b/content/base/public/nsDOMFile.h index c75915925dba..f0fd79c7cad8 100644 --- a/content/base/public/nsDOMFile.h +++ b/content/base/public/nsDOMFile.h @@ -44,6 +44,7 @@ #include "nsIDOMFileList.h" #include "nsIDOMFileError.h" #include "nsIInputStream.h" +#include "nsIJSNativeInitializer.h" #include "nsCOMArray.h" #include "nsCOMPtr.h" #include "mozilla/AutoRestore.h" @@ -59,7 +60,8 @@ class nsIClassInfo; class nsDOMFile : public nsIDOMFile, public nsIDOMBlob_MOZILLA_2_0_BRANCH, public nsIXHRSendable, - public nsICharsetDetectionObserver + public nsICharsetDetectionObserver, + public nsIJSNativeInitializer { public: NS_DECL_ISUPPORTS @@ -98,6 +100,17 @@ public: // from nsICharsetDetectionObserver NS_IMETHOD Notify(const char *aCharset, nsDetectionConfident aConf); + // nsIJSNativeInitializer + NS_IMETHOD Initialize(nsISupports* aOwner, + JSContext* aCx, + JSObject* aObj, + PRUint32 aArgc, + jsval* aArgv); + + // DOMClassInfo constructor (for File("foo")) + static nsresult + NewFile(nsISupports* *aNewObject); + protected: nsCOMPtr mFile; diff --git a/content/base/src/nsDOMFile.cpp b/content/base/src/nsDOMFile.cpp index 62d5003f918a..ee0103fc1085 100644 --- a/content/base/src/nsDOMFile.cpp +++ b/content/base/src/nsDOMFile.cpp @@ -64,6 +64,7 @@ #include "nsFileDataProtocolHandler.h" #include "nsStringStream.h" #include "CheckedInt.h" +#include "nsJSUtils.h" #include "plbase64.h" #include "prmem.h" @@ -143,6 +144,7 @@ NS_INTERFACE_MAP_BEGIN(nsDOMFile) NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, mIsFullFile) NS_INTERFACE_MAP_ENTRY(nsIXHRSendable) NS_INTERFACE_MAP_ENTRY(nsICharsetDetectionObserver) + NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(File, mIsFullFile) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(Blob, !mIsFullFile) NS_INTERFACE_MAP_END @@ -164,6 +166,14 @@ DOMFileResult(nsresult rv) return rv; } +/* static */ nsresult +nsDOMFile::NewFile(nsISupports* *aNewObject) +{ + nsCOMPtr file = do_QueryObject(new nsDOMFile(nsnull)); + file.forget(aNewObject); + return NS_OK; +} + NS_IMETHODIMP nsDOMFile::GetFileName(nsAString &aFileName) { @@ -611,6 +621,48 @@ nsDOMFile::Notify(const char* aCharset, nsDetectionConfident aConf) return NS_OK; } +NS_IMETHODIMP +nsDOMFile::Initialize(nsISupports* aOwner, + JSContext* aCx, + JSObject* aObj, + PRUint32 aArgc, + jsval* aArgv) +{ + if (!nsContentUtils::IsCallerChrome()) { + return NS_ERROR_DOM_SECURITY_ERR; // Real short trip + } + + NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED); + + // We expect to get a path to represent as a File object + if (!JSVAL_IS_STRING(aArgv[0])) + return NS_ERROR_UNEXPECTED; + + JSString* str = JS_ValueToString(aCx, aArgv[0]); + NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS); + + nsDependentJSString xpcomStr; + if (!xpcomStr.init(aCx, str)) { + return NS_ERROR_XPC_BAD_CONVERT_JS; + } + + nsCOMPtr localFile; + nsresult rv = NS_NewLocalFile(xpcomStr, + PR_FALSE, getter_AddRefs(localFile)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr file = do_QueryInterface(localFile, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool exists; + rv = file->Exists(&exists); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND); + + mFile = file; + return NS_OK; +} + nsresult nsDOMFile::ConvertStream(nsIInputStream *aStream, const char *aCharset, diff --git a/content/base/test/chrome/Makefile.in b/content/base/test/chrome/Makefile.in index 89365034dac1..7e48f254ecb2 100644 --- a/content/base/test/chrome/Makefile.in +++ b/content/base/test/chrome/Makefile.in @@ -60,6 +60,8 @@ _CHROME_FILES = \ test_bug616841.xul \ file_bug616841.xul \ test_bug635835.xul \ + test_fileconstructor.xul \ + fileconstructor_file.png \ $(NULL) libs:: $(_TEST_FILES) diff --git a/content/base/test/chrome/fileconstructor_file.png b/content/base/test/chrome/fileconstructor_file.png new file mode 100644 index 0000000000000000000000000000000000000000..51e8aaf38c1b3a105fc6038c93b5648a4bf9efd4 GIT binary patch literal 95 zcmeAS@N?(olHy`uVBq!ia0vp^DL`z*$P6SW{C@KnNHGWagt-3y&(L-3iz|>T?&;zf qQW5v|03$Du=V0(R_;h0NA~Qy&Jq(P_g*_*Mf()LnelF{r5}E*PXBuY! literal 0 HcmV?d00001 diff --git a/content/base/test/chrome/test_fileconstructor.xul b/content/base/test/chrome/test_fileconstructor.xul new file mode 100644 index 000000000000..9fe58716241f --- /dev/null +++ b/content/base/test/chrome/test_fileconstructor.xul @@ -0,0 +1,70 @@ + + + + + + + Test for Bug 607114 + + + + + + Mozilla Bug 607114 +

+ +
+
+ + + + +
diff --git a/content/base/test/test_fileapi.html b/content/base/test/test_fileapi.html index 8cfbb0df5002..29d48333fc67 100644 --- a/content/base/test/test_fileapi.html +++ b/content/base/test/test_fileapi.html @@ -20,6 +20,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=414796