content/canvas/src/WebGLContextLossTimer.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLContextLossTimer.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "WebGLContext.h"
    1.10 +
    1.11 +using namespace mozilla;
    1.12 +
    1.13 +/* static */ void
    1.14 +WebGLContext::RobustnessTimerCallbackStatic(nsITimer* timer, void *thisPointer) {
    1.15 +    static_cast<WebGLContext*>(thisPointer)->RobustnessTimerCallback(timer);
    1.16 +}
    1.17 +
    1.18 +void
    1.19 +WebGLContext::SetupContextLossTimer() {
    1.20 +    // If the timer was already running, don't restart it here. Instead,
    1.21 +    // wait until the previous call is done, then fire it one more time.
    1.22 +    // This is an optimization to prevent unnecessary cross-communication
    1.23 +    // between threads.
    1.24 +    if (mContextLossTimerRunning) {
    1.25 +        mDrawSinceContextLossTimerSet = true;
    1.26 +        return;
    1.27 +    }
    1.28 +
    1.29 +    mContextRestorer->InitWithFuncCallback(RobustnessTimerCallbackStatic,
    1.30 +                                            static_cast<void*>(this),
    1.31 +                                            1000,
    1.32 +                                            nsITimer::TYPE_ONE_SHOT);
    1.33 +    mContextLossTimerRunning = true;
    1.34 +    mDrawSinceContextLossTimerSet = false;
    1.35 +}
    1.36 +
    1.37 +void
    1.38 +WebGLContext::TerminateContextLossTimer() {
    1.39 +    if (mContextLossTimerRunning) {
    1.40 +        mContextRestorer->Cancel();
    1.41 +        mContextLossTimerRunning = false;
    1.42 +    }
    1.43 +}

mercurial