| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp* now, co
nst CVTimeStamp* outputTime, CVOptionFlags, CVOptionFlags*, void* data) | 38 static CVReturn displayLinkCallback(CVDisplayLinkRef, const CVTimeStamp* now, co
nst CVTimeStamp* outputTime, CVOptionFlags, CVOptionFlags*, void* data) |
| 39 { | 39 { |
| 40 DisplayRefreshMonitor* monitor = static_cast<DisplayRefreshMonitor*>(data); | 40 DisplayRefreshMonitor* monitor = static_cast<DisplayRefreshMonitor*>(data); |
| 41 | 41 |
| 42 double nowSeconds = static_cast<double>(now->videoTime) / static_cast<double
>(now->videoTimeScale); | 42 double nowSeconds = static_cast<double>(now->videoTime) / static_cast<double
>(now->videoTimeScale); |
| 43 double outputTimeSeconds = static_cast<double>(outputTime->videoTime) / stat
ic_cast<double>(outputTime->videoTimeScale); | 43 double outputTimeSeconds = static_cast<double>(outputTime->videoTime) / stat
ic_cast<double>(outputTime->videoTimeScale); |
| 44 monitor->displayLinkFired(nowSeconds, outputTimeSeconds); | 44 monitor->displayLinkFired(nowSeconds, outputTimeSeconds); |
| 45 | 45 |
| 46 return kCVReturnSuccess; | 46 return kCVReturnSuccess; |
| 47 } | 47 } |
| 48 | 48 |
| 49 DisplayRefreshMonitor::~DisplayRefreshMonitor() | 49 DisplayRefreshMonitor::~DisplayRefreshMonitor() |
| 50 { | 50 { |
| 51 if (m_displayLink) { | 51 if (m_displayLink) { |
| 52 CVDisplayLinkStop(m_displayLink); | 52 CVDisplayLinkStop(m_displayLink); |
| 53 CVDisplayLinkRelease(m_displayLink); | 53 CVDisplayLinkRelease(m_displayLink); |
| 54 m_displayLink = 0; | 54 m_displayLink = 0; |
| 55 } | 55 } |
| 56 | 56 |
| 57 cancelCallOnMainThread(DisplayRefreshMonitor::refreshDisplayOnMainThread, th
is); | 57 cancelCallOnMainThread(DisplayRefreshMonitor::refreshDisplayOnMainThread, th
is); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool DisplayRefreshMonitor::requestRefreshCallback() | 60 bool DisplayRefreshMonitor::requestRefreshCallback() |
| 61 { | 61 { |
| 62 if (!m_active) | 62 if (!m_active) |
| 63 return false; | 63 return false; |
| 64 | 64 |
| 65 if (!m_displayLink) { | 65 if (!m_displayLink) { |
| 66 m_active = false; | 66 m_active = false; |
| 67 CVReturn error = CVDisplayLinkCreateWithCGDisplay(m_displayID, &m_displa
yLink); | 67 CVReturn error = CVDisplayLinkCreateWithCGDisplay(m_displayID, &m_displa
yLink); |
| 68 if (error) | 68 if (error) |
| 69 return false; | 69 return false; |
| 70 | 70 |
| 71 error = CVDisplayLinkSetOutputCallback(m_displayLink, displayLinkCallbac
k, this); | 71 error = CVDisplayLinkSetOutputCallback(m_displayLink, displayLinkCallbac
k, this); |
| 72 if (error) | 72 if (error) |
| 73 return false; | 73 return false; |
| 74 | 74 |
| 75 error = CVDisplayLinkStart(m_displayLink); | 75 error = CVDisplayLinkStart(m_displayLink); |
| 76 if (error) | 76 if (error) |
| 77 return false; | 77 return false; |
| 78 | 78 |
| 79 m_active = true; | 79 m_active = true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 MutexLocker lock(m_mutex); | 82 MutexLocker lock(m_mutex); |
| 83 m_scheduled = true; | 83 m_scheduled = true; |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void DisplayRefreshMonitor::displayLinkFired(double nowSeconds, double outputTim
eSeconds) | 87 void DisplayRefreshMonitor::displayLinkFired(double nowSeconds, double outputTim
eSeconds) |
| 88 { | 88 { |
| 89 MutexLocker lock(m_mutex); | 89 MutexLocker lock(m_mutex); |
| 90 if (!m_scheduled || !m_previousFrameDone) | 90 if (!m_scheduled || !m_previousFrameDone) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 m_previousFrameDone = false; | 93 m_previousFrameDone = false; |
| 94 | 94 |
| 95 double webKitMonotonicNow = monotonicallyIncreasingTime(); | 95 double webKitNow = currentTime(); |
| 96 double timeUntilOutput = outputTimeSeconds - nowSeconds; | 96 m_timestamp = webKitNow - nowSeconds + outputTimeSeconds; |
| 97 // FIXME: Should this be using webKitMonotonicNow? | 97 |
| 98 m_monotonicAnimationStartTime = webKitMonotonicNow + timeUntilOutput; | |
| 99 | |
| 100 callOnMainThread(refreshDisplayOnMainThread, this); | 98 callOnMainThread(refreshDisplayOnMainThread, this); |
| 101 } | 99 } |
| 102 | 100 |
| 103 } | 101 } |
| 104 | 102 |
| 105 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 103 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| OLD | NEW |