Title: [99222] trunk/Source
Revision
99222
Author
jer.no...@apple.com
Date
2011-11-03 11:05:15 -0700 (Thu, 03 Nov 2011)

Log Message

Add Clock class and platform-specific implementations.
https://bugs.webkit.org/show_bug.cgi?id=71341

Reviewed by Sam Weinig.

Source/_javascript_Core:

Add WTF_USE_COREAUDIO macro for use by PlatformClockCA.

* wtf/Platform.h:

Source/WebCore:

No new tests; these classes will be used and tested by the MediaController feature.

Adds a abstract Clock class and two concrete, platform-specific subclasses.

Clock provides a basic interface for starting, stopping, and querying a generic timeline.
PlatformClockCA implements this interface using a CoreAudio CAClock object, which uses
the default audio device's hardware clock as a timing source. PlatformClockPOSIX
implements this interface using gettimeofday() as its timing source.

* WebCore.xcodeproj/project.pbxproj:
* platform/Clock.cpp: Added.
(Clock::create): Creates a platform-specific clock.
* platform/Clock.h: Added.
(WebCore::Clock::~Clock):
(WebCore::Clock::Clock):
* platform/mac/PlatformClockCA.cpp: Added.
(PlatformClockCA::PlatformClockCA):
(PlatformClockCA::~PlatformClockCA):
(PlatformClockCA::setCurrentTime):
(PlatformClockCA::currentTime):
(PlatformClockCA::setPlayRate):
(PlatformClockCA::PlatformClockCA::playRate):
(PlatformClockCA::start):
(PlatformClockCA::stop):
* platform/mac/PlatformClockCA.h: Added.
(WebCore::PlatformClockCA::isRunning):
* platform/posix/PlatformClockPOSIX.cpp: Added.
(timevalToFloat):
(timevalDelta):
(PlatformClockPOSIX::PlatformClockPOSIX):
(PlatformClockPOSIX::setCurrentTime):
(PlatformClockPOSIX::currentTime):
(PlatformClockPOSIX::setPlayRate):
(PlatformClockPOSIX::PlatformClockPOSIX::playRate):
(PlatformClockPOSIX::start):
(PlatformClockPOSIX::stop):
(PlatformClockPOSIX::now):
* platform/posix/PlatformClockPOSIX.h: Added.
(WebCore::PlatformClockPOSIX::isRunning):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (99221 => 99222)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-03 17:57:40 UTC (rev 99221)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-03 18:05:15 UTC (rev 99222)
@@ -1,3 +1,14 @@
+2011-11-02  Jer Noble  <jer.no...@apple.com>
+
+        Add Clock class and platform-specific implementations.
+        https://bugs.webkit.org/show_bug.cgi?id=71341
+
+        Reviewed by Sam Weinig.
+
+        Add WTF_USE_COREAUDIO macro for use by PlatformClockCA.
+
+        * wtf/Platform.h:
+
 2011-11-03  Pavel Feldman  <pfeld...@chromium.org>
 
         Not reviewed: fixing win build. step2.

Modified: trunk/Source/_javascript_Core/wtf/Platform.h (99221 => 99222)


--- trunk/Source/_javascript_Core/wtf/Platform.h	2011-11-03 17:57:40 UTC (rev 99221)
+++ trunk/Source/_javascript_Core/wtf/Platform.h	2011-11-03 18:05:15 UTC (rev 99222)
@@ -1104,4 +1104,8 @@
 #define HAVE_INVERTED_WHEEL_EVENTS 1
 #endif
 
+#if PLATFORM(MAC) || (PLATFORM(WIN) && !OS(WINCE) && !PLATFORM(WIN_CAIRO))
+#define WTF_USE_COREAUDIO 1
+#endif
+
 #endif /* WTF_Platform_h */

Modified: trunk/Source/WebCore/ChangeLog (99221 => 99222)


--- trunk/Source/WebCore/ChangeLog	2011-11-03 17:57:40 UTC (rev 99221)
+++ trunk/Source/WebCore/ChangeLog	2011-11-03 18:05:15 UTC (rev 99222)
@@ -1,3 +1,50 @@
+2011-11-02  Jer Noble  <jer.no...@apple.com>
+
+        Add Clock class and platform-specific implementations.
+        https://bugs.webkit.org/show_bug.cgi?id=71341
+
+        Reviewed by Sam Weinig.
+
+        No new tests; these classes will be used and tested by the MediaController feature.
+
+        Adds a abstract Clock class and two concrete, platform-specific subclasses.
+
+        Clock provides a basic interface for starting, stopping, and querying a generic timeline.
+        PlatformClockCA implements this interface using a CoreAudio CAClock object, which uses
+        the default audio device's hardware clock as a timing source. PlatformClockPOSIX 
+        implements this interface using gettimeofday() as its timing source.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/Clock.cpp: Added.
+        (Clock::create): Creates a platform-specific clock.
+        * platform/Clock.h: Added.
+        (WebCore::Clock::~Clock):
+        (WebCore::Clock::Clock):
+        * platform/mac/PlatformClockCA.cpp: Added.
+        (PlatformClockCA::PlatformClockCA):
+        (PlatformClockCA::~PlatformClockCA):
+        (PlatformClockCA::setCurrentTime):
+        (PlatformClockCA::currentTime):
+        (PlatformClockCA::setPlayRate):
+        (PlatformClockCA::PlatformClockCA::playRate):
+        (PlatformClockCA::start):
+        (PlatformClockCA::stop):
+        * platform/mac/PlatformClockCA.h: Added.
+        (WebCore::PlatformClockCA::isRunning):
+        * platform/posix/PlatformClockPOSIX.cpp: Added.
+        (timevalToFloat):
+        (timevalDelta):
+        (PlatformClockPOSIX::PlatformClockPOSIX):
+        (PlatformClockPOSIX::setCurrentTime):
+        (PlatformClockPOSIX::currentTime):
+        (PlatformClockPOSIX::setPlayRate):
+        (PlatformClockPOSIX::PlatformClockPOSIX::playRate):
+        (PlatformClockPOSIX::start):
+        (PlatformClockPOSIX::stop):
+        (PlatformClockPOSIX::now):
+        * platform/posix/PlatformClockPOSIX.h: Added.
+        (WebCore::PlatformClockPOSIX::isRunning):
+
 2011-11-03  Joshua Bell  <jsb...@chromium.org>
 
         IndexedDB: Object stores not persisting between sessions

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (99221 => 99222)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-11-03 17:57:40 UTC (rev 99221)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-11-03 18:05:15 UTC (rev 99222)
@@ -5701,6 +5701,9 @@
 		CD82030D1395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD8203091395AB6A00F956C6 /* WebVideoFullscreenHUDWindowController.mm */; };
 		CD8203101395ACE700F956C6 /* WebWindowAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = CD82030E1395ACE700F956C6 /* WebWindowAnimation.h */; };
 		CD8203111395ACE700F956C6 /* WebWindowAnimation.mm in Sources */ = {isa = PBXBuildFile; fileRef = CD82030F1395ACE700F956C6 /* WebWindowAnimation.mm */; };
+		CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */; };
+		CDEA76341460B56F008B31F1 /* PlatformClockPOSIX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76321460AE29008B31F1 /* PlatformClockPOSIX.cpp */; };
+		CDEA76351460B71A008B31F1 /* Clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76331460B462008B31F1 /* Clock.cpp */; };
 		CDEA7C841276230400B846DD /* RenderFullScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = CDEA7C821276230400B846DD /* RenderFullScreen.h */; };
 		CDEA7C851276230400B846DD /* RenderFullScreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA7C831276230400B846DD /* RenderFullScreen.cpp */; };
 		CE02F0C411E83ADD00C6684A /* ScriptControllerBase.h in Headers */ = {isa = PBXBuildFile; fileRef = CE02F0C311E83ADD00C6684A /* ScriptControllerBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -12983,6 +12986,12 @@
 		CD82030E1395ACE700F956C6 /* WebWindowAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebWindowAnimation.h; sourceTree = "<group>"; };
 		CD82030F1395ACE700F956C6 /* WebWindowAnimation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebWindowAnimation.mm; sourceTree = "<group>"; };
 		CDBD93BA1333BD4B002570E3 /* fullscreenQuickTime.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreenQuickTime.css; sourceTree = "<group>"; };
+		CDEA762C14608224008B31F1 /* Clock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clock.h; sourceTree = "<group>"; };
+		CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformClockCA.cpp; sourceTree = "<group>"; };
+		CDEA762F146084EE008B31F1 /* PlatformClockCA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockCA.h; sourceTree = "<group>"; };
+		CDEA76311460AE1B008B31F1 /* PlatformClockPOSIX.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockPOSIX.h; sourceTree = "<group>"; };
+		CDEA76321460AE29008B31F1 /* PlatformClockPOSIX.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformClockPOSIX.cpp; sourceTree = "<group>"; };
+		CDEA76331460B462008B31F1 /* Clock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Clock.cpp; sourceTree = "<group>"; };
 		CDEA7C821276230400B846DD /* RenderFullScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderFullScreen.h; sourceTree = "<group>"; };
 		CDEA7C831276230400B846DD /* RenderFullScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFullScreen.cpp; sourceTree = "<group>"; };
 		CE02F0C311E83ADD00C6684A /* ScriptControllerBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptControllerBase.h; sourceTree = "<group>"; };
@@ -15017,6 +15026,8 @@
 			isa = PBXGroup;
 			children = (
 				5160300A0CC4251200C8AC25 /* FileSystemPOSIX.cpp */,
+				CDEA76311460AE1B008B31F1 /* PlatformClockPOSIX.h */,
+				CDEA76321460AE29008B31F1 /* PlatformClockPOSIX.cpp */,
 			);
 			path = posix;
 			sourceTree = "<group>";
@@ -15394,6 +15405,8 @@
 				CD82030F1395ACE700F956C6 /* WebWindowAnimation.mm */,
 				935C477209AC4D7700A6AAB4 /* WheelEventMac.mm */,
 				9380F47709A11ACC001FDB34 /* WidgetMac.mm */,
+				CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */,
+				CDEA762F146084EE008B31F1 /* PlatformClockCA.h */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -20043,6 +20056,8 @@
 				9380F47109A11AB4001FDB34 /* Widget.cpp */,
 				9380F47209A11AB4001FDB34 /* Widget.h */,
 				E1E1BEFF115FF6FB006F52CA /* WindowsKeyboardCodes.h */,
+				CDEA762C14608224008B31F1 /* Clock.h */,
+				CDEA76331460B462008B31F1 /* Clock.cpp */,
 			);
 			path = platform;
 			sourceTree = "<group>";
@@ -27391,6 +27406,9 @@
 				A0EE0DF7144F825500F80B0D /* WebGLDebugShaders.cpp in Sources */,
 				A3BB59F31457A40D00AC56FE /* DocumentEventQueue.cpp in Sources */,
 				2D8FEBDC143E3EF70072502B /* CSSCrossfadeValue.cpp in Sources */,
+				CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */,
+				CDEA76341460B56F008B31F1 /* PlatformClockPOSIX.cpp in Sources */,
+				CDEA76351460B71A008B31F1 /* Clock.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Source/WebCore/platform/Clock.cpp (0 => 99222)


--- trunk/Source/WebCore/platform/Clock.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/Clock.cpp	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "Clock.h"
+
+#if USE(COREAUDIO)
+    #include "PlatformClockCA.h"
+#else
+    #include "PlatformClockPOSIX.h"
+#endif
+
+using namespace WebCore;
+
+PassRefPtr<Clock> Clock::create()
+{
+#if USE(COREAUDIO)
+    return adoptRef(new PlatformClockCA());
+#else
+    return adoptRef(new PlatformClockPOSIX());
+#endif
+}

Added: trunk/Source/WebCore/platform/Clock.h (0 => 99222)


--- trunk/Source/WebCore/platform/Clock.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/Clock.h	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef Clock_h
+#define Clock_h
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class Clock : public RefCounted<Clock> {
+public:
+    static PassRefPtr<Clock> create();
+    virtual ~Clock() { }
+
+    virtual void setCurrentTime(float) = 0;
+    virtual float currentTime() const = 0;
+
+    virtual void setPlayRate(float) = 0;
+    virtual float playRate() const = 0;
+
+    virtual void start() = 0;
+    virtual void stop() = 0;
+    virtual bool isRunning() const = 0;
+
+protected:
+    Clock() { }
+};
+
+}
+
+#endif

Added: trunk/Source/WebCore/platform/mac/PlatformClockCA.cpp (0 => 99222)


--- trunk/Source/WebCore/platform/mac/PlatformClockCA.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/PlatformClockCA.cpp	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(COREAUDIO)
+
+#include "PlatformClockCA.h"
+
+#include "FloatConversion.h"
+#include <AudioToolbox/CoreAudioClock.h>
+#include <CoreAudio/AudioHardware.h>
+
+using namespace WebCore;
+
+PlatformClockCA::PlatformClockCA()
+    : m_clock(0)
+    , m_running(false)
+{
+    CAClockNew(0, &m_clock);
+    UInt32 timebase = kCAClockTimebase_AudioDevice;
+    UInt32 timebaseSize = sizeof(timebase);
+    CAClockSetProperty(m_clock, kCAClockProperty_InternalTimebase, timebaseSize, &timebase);
+
+    AudioObjectID defaultAudioOutput = 0;
+    UInt32 defaultAudioOutputSize = sizeof(defaultAudioOutput);
+
+    AudioObjectPropertyAddress address;
+    address.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
+    address.mScope    = kAudioObjectPropertyScopeGlobal;
+    address.mElement  = kAudioObjectPropertyElementMaster;
+
+    AudioObjectGetPropertyData(kAudioObjectSystemObject, &address, 0, 0, &defaultAudioOutputSize, &defaultAudioOutput);
+    CAClockSetProperty(m_clock, kCAClockProperty_TimebaseSource, defaultAudioOutputSize, &defaultAudioOutput);
+}
+
+PlatformClockCA::~PlatformClockCA()
+{
+    CAClockDispose(m_clock);
+}
+
+void PlatformClockCA::setCurrentTime(float time)
+{
+    CAClockTime caTime;
+    caTime.format = kCAClockTimeFormat_Seconds;
+    caTime.time.seconds = time;
+    CAClockSetCurrentTime(m_clock, &caTime);
+}
+
+float PlatformClockCA::currentTime() const
+{
+    CAClockTime caTime;
+
+    // CAClock does not return the correct current time when stopped. Instead, query for
+    // what is the start time, i.e. what the current time will be when started.
+    if (m_running) {
+        if (CAClockGetCurrentTime(m_clock, kCAClockTimeFormat_Seconds, &caTime) == noErr)
+            return narrowPrecisionToFloat(caTime.time.seconds);
+    } else {
+        if (CAClockGetStartTime(m_clock, kCAClockTimeFormat_Seconds, &caTime) == noErr)
+            return narrowPrecisionToFloat(caTime.time.seconds);
+    }
+    return 0;
+}
+
+void PlatformClockCA::setPlayRate(float rate)
+{
+    CAClockSetPlayRate(m_clock, rate);
+}
+
+float PlatformClockCA::PlatformClockCA::playRate() const
+{
+    double rate = 0;
+    if (CAClockGetPlayRate(m_clock, &rate) == noErr)
+        return narrowPrecisionToFloat(rate);
+    return 0;
+}
+
+void PlatformClockCA::start()
+{
+    if (m_running)
+        return;
+    m_running = true;
+    CAClockStart(m_clock);
+}
+
+void PlatformClockCA::stop()
+{
+    if (!m_running)
+        return;
+    m_running = false;
+    CAClockStop(m_clock);
+}
+
+
+#endif

Added: trunk/Source/WebCore/platform/mac/PlatformClockCA.h (0 => 99222)


--- trunk/Source/WebCore/platform/mac/PlatformClockCA.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/mac/PlatformClockCA.h	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PlatformClockCA_h
+#define PlatformClockCA_h
+
+#if USE(COREAUDIO)
+
+#include "Clock.h"
+
+typedef struct OpaqueCAClock *CAClockRef;
+
+namespace WebCore {
+
+class PlatformClockCA : public Clock {
+public:
+    PlatformClockCA();
+    virtual ~PlatformClockCA();
+
+private:
+    virtual void setCurrentTime(float);
+    virtual float currentTime() const;
+
+    virtual void setPlayRate(float);
+    virtual float playRate() const;
+
+    virtual void start();
+    virtual void stop();
+    virtual bool isRunning() const { return m_running; }
+
+    CAClockRef m_clock;
+    bool m_running;
+};
+
+}
+
+#endif
+
+#endif

Added: trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.cpp (0 => 99222)


--- trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.cpp	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#include "config.h"
+#include "PlatformClockPOSIX.h"
+
+#include "FloatConversion.h"
+
+using namespace WebCore;
+
+static const int32_t usecPerSec = 1e6;
+
+static float timevalToFloat(timeval val)
+{
+    return val.tv_sec + (val.tv_usec / static_cast<float>(usecPerSec));
+}
+
+static timeval timevalDelta(timeval first, timeval second)
+{
+    timeval delta;
+    delta.tv_sec = first.tv_sec - second.tv_sec;
+    delta.tv_usec = first.tv_usec - second.tv_usec;
+    while (delta.tv_usec < 0) {
+        delta.tv_usec += usecPerSec;
+        delta.tv_sec--;
+    }
+    return delta;
+}
+
+PlatformClockPOSIX::PlatformClockPOSIX()
+    : m_running(false)
+    , m_rate(1)
+    , m_offset(0)
+{
+    m_startTime = m_lastTime = now();
+}
+
+void PlatformClockPOSIX::setCurrentTime(float time)
+{
+    m_startTime = m_lastTime = now();
+    m_offset = time;
+}
+
+float PlatformClockPOSIX::currentTime() const
+{
+    if (m_running)
+        m_lastTime = now();
+    float time = (timevalToFloat(timevalDelta(m_lastTime, m_startTime)) * m_rate) + m_offset;
+    return time;
+}
+
+void PlatformClockPOSIX::setPlayRate(float rate)
+{
+    m_offset = currentTime();
+    m_lastTime = m_startTime = now();
+    m_rate = rate;
+}
+
+void PlatformClockPOSIX::start()
+{
+    if (m_running)
+        return;
+
+    m_lastTime = m_startTime = now();
+    m_running = true;
+}
+
+void PlatformClockPOSIX::stop()
+{
+    if (!m_running)
+        return;
+
+    m_offset = currentTime();
+    m_lastTime = m_startTime = now();
+    m_running = false;
+}
+
+timeval PlatformClockPOSIX::now() const
+{
+    timeval val;
+    gettimeofday(&val, 0);
+    return val;
+}

Added: trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.h (0 => 99222)


--- trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/posix/PlatformClockPOSIX.h	2011-11-03 18:05:15 UTC (rev 99222)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PlatformClockPOSIX_h
+#define PlatformClockPOSIX_h
+
+#include "Clock.h"
+#include <time.h>
+
+namespace WebCore {
+
+class PlatformClockPOSIX : public Clock {
+public:
+    PlatformClockPOSIX();
+
+private:
+    virtual void setCurrentTime(float);
+    virtual float currentTime() const;
+
+    virtual void setPlayRate(float);
+    virtual float playRate() const { return m_rate; }
+
+    virtual void start();
+    virtual void stop();
+    virtual bool isRunning() const { return m_running; }
+
+    timeval now() const;
+
+    bool m_running;
+    float m_rate;
+    float m_offset;
+    timeval m_startTime;
+    mutable timeval m_lastTime;
+};
+
+}
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to