jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All Rights Reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 17 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #ifndef ScriptedAnimationController_h |
| 27 | #define ScriptedAnimationController_h |
| 28 | |
kevino@webkit.org | 4e26c27 | 2011-02-17 20:24:52 +0000 | [diff] [blame] | 29 | #if ENABLE(REQUEST_ANIMATION_FRAME) |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 30 | #include "DOMTimeStamp.h" |
cmarrin@apple.com | d9dca74 | 2011-09-10 14:21:01 +0000 | [diff] [blame] | 31 | #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 32 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 33 | #include "DisplayRefreshMonitor.h" |
| 34 | #endif |
cmarrin@apple.com | d9dca74 | 2011-09-10 14:21:01 +0000 | [diff] [blame] | 35 | #include "Timer.h" |
| 36 | #endif |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 37 | #include "PlatformScreen.h" |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 38 | #include <wtf/RefCounted.h> |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 39 | #include <wtf/RefPtr.h> |
| 40 | #include <wtf/Vector.h> |
| 41 | |
| 42 | namespace WebCore { |
| 43 | |
| 44 | class Document; |
| 45 | class Element; |
| 46 | class RequestAnimationFrameCallback; |
| 47 | |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 48 | class ScriptedAnimationController : public RefCounted<ScriptedAnimationController> |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 49 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 50 | , public DisplayRefreshMonitorClient |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 51 | #endif |
| 52 | { |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 53 | public: |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 54 | static PassRefPtr<ScriptedAnimationController> create(Document* document, PlatformDisplayID displayID) |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 55 | { |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 56 | return adoptRef(new ScriptedAnimationController(document, displayID)); |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 57 | } |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 58 | ~ScriptedAnimationController(); |
| 59 | void clearDocumentPointer() { m_document = 0; } |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 60 | |
| 61 | typedef int CallbackId; |
| 62 | |
| 63 | CallbackId registerCallback(PassRefPtr<RequestAnimationFrameCallback>, Element*); |
| 64 | void cancelCallback(CallbackId); |
| 65 | void serviceScriptedAnimations(DOMTimeStamp); |
| 66 | |
| 67 | void suspend(); |
| 68 | void resume(); |
| 69 | |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 70 | void windowScreenDidChange(PlatformDisplayID); |
| 71 | |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 72 | private: |
jamesr@google.com | a5d3c9e | 2011-12-09 01:33:41 +0000 | [diff] [blame] | 73 | ScriptedAnimationController(Document*, PlatformDisplayID); |
cmarrin@apple.com | d9dca74 | 2011-09-10 14:21:01 +0000 | [diff] [blame] | 74 | |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 75 | typedef Vector<RefPtr<RequestAnimationFrameCallback> > CallbackList; |
| 76 | CallbackList m_callbacks; |
| 77 | |
| 78 | Document* m_document; |
| 79 | CallbackId m_nextCallbackId; |
| 80 | int m_suspendCount; |
cmarrin@apple.com | d9dca74 | 2011-09-10 14:21:01 +0000 | [diff] [blame] | 81 | |
| 82 | void scheduleAnimation(); |
| 83 | |
| 84 | #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
| 85 | void animationTimerFired(Timer<ScriptedAnimationController>*); |
| 86 | Timer<ScriptedAnimationController> m_animationTimer; |
| 87 | double m_lastAnimationFrameTime; |
cmarrin@apple.com | 4386e02 | 2011-10-13 21:59:25 +0000 | [diff] [blame] | 88 | |
| 89 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 90 | // Override for DisplayRefreshMonitorClient |
| 91 | virtual void displayRefreshFired(double timestamp) { serviceScriptedAnimations(convertSecondsToDOMTimeStamp(timestamp)); } |
| 92 | |
| 93 | bool m_useTimer; |
| 94 | #endif |
cmarrin@apple.com | d9dca74 | 2011-09-10 14:21:01 +0000 | [diff] [blame] | 95 | #endif |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } |
| 99 | |
kevino@webkit.org | 4e26c27 | 2011-02-17 20:24:52 +0000 | [diff] [blame] | 100 | #endif // ENABLE(REQUEST_ANIMATION_FRAME) |
| 101 | |
jamesr@google.com | 9f8b52b | 2011-02-16 00:53:36 +0000 | [diff] [blame] | 102 | #endif // ScriptedAnimationController_h |
| 103 | |