1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLContextLossHandler.h"
7 #include "WebGLContext.h"
9 #include "base/message_loop.h"
13 WebGLContextLossHandler::WebGLContextLossHandler(WebGLContext
* const webgl
)
14 : mTimerIsScheduled(false) {
15 const auto weak
= WeakPtr
<WebGLContext
>(webgl
);
16 mRunnable
= NS_NewRunnableFunction("WebGLContextLossHandler", [weak
]() {
17 const auto strong
= RefPtr
<WebGLContext
>(weak
);
21 strong
->CheckForContextLoss();
25 WebGLContextLossHandler::~WebGLContextLossHandler() = default;
29 void WebGLContextLossHandler::RunTimer() {
30 const uint32_t kDelayMS
= 1000;
31 MOZ_ASSERT(GetCurrentSerialEventTarget());
32 // Only create a new task if one isn't already queued.
33 if (mTimerIsScheduled
.compareExchange(false, true)) {
34 GetCurrentSerialEventTarget()->DelayedDispatch(do_AddRef(mRunnable
),
39 void WebGLContextLossHandler::ClearTimer() { mTimerIsScheduled
= false; }
41 } // namespace mozilla