15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission. 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef Player_h 3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define Player_h 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "core/animation/TimedItem.h" 3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "wtf/RefPtr.h" 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class DocumentTimeline; 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class Player FINAL : public RefCounted<Player> { 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public: 4483750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch ~Player(); 45f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) static PassRefPtr<Player> create(DocumentTimeline&, TimedItem*); 4693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 4793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Returns whether this player is still current or in effect. 48bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // timeToEffectChange returns: 49bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // infinity - if this player is no longer in effect 50bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // 0 - if this player requires an update on the next frame 51bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // n - if this player requires an update after 'n' units of time 5219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) bool update(double* timeToEffectChange = 0, bool* didTriggerStyleRecalc = 0); 53f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles) void cancel(); 5451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double currentTime() const; 5693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setCurrentTime(double); 5751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 58f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool paused() const { return !m_isPausedForTesting && pausedInternal(); } 5993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setPaused(bool); 6051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 6193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double playbackRate() const { return m_playbackRate; } 6293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setPlaybackRate(double); 6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double timeDrift() const; 64f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) DocumentTimeline& timeline() { return m_timeline; } 6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 6651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool hasStartTime() const { return !isNull(m_startTime); } 6751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) double startTime() const { return m_startTime; } 6851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void setStartTime(double); 6951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) TimedItem* source() { return m_content.get(); } 7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 72f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // Pausing via this method is not reflected in the value returned by 73f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) // paused() and must never overlap with pausing via setPaused(). 74f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) void pauseForTesting(); 75f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool maybeStartAnimationOnCompositor(); 7751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void cancelAnimationOnCompositor(); 7851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool hasActiveAnimationsOnCompositor(); 7951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 8093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)private: 81f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) Player(DocumentTimeline&, TimedItem*); 8293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) inline double pausedTimeDrift() const; 8393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) inline double currentTimeBeforeDrift() const; 8493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 86f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) void setPausedImpl(bool); 87a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) // Reflects all pausing, including via pauseForTesting(). 88a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) bool pausedInternal() const { return !isNull(m_pauseStartTime); } 89f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) 9093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double m_pauseStartTime; 9193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double m_playbackRate; 9293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) double m_timeDrift; 9351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) double m_startTime; 9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) RefPtr<TimedItem> m_content; 96f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) DocumentTimeline& m_timeline; 97f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) bool m_isPausedForTesting; 9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)}; 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 10081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)} // namespace 10193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif 103