Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / canvas / WebGLContextLossHandler.cpp
blobb21f59c1b7957e52e281b901c68ca17bd8244ec0
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"
11 namespace mozilla {
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);
18 if (!strong) {
19 return;
21 strong->CheckForContextLoss();
22 });
25 WebGLContextLossHandler::~WebGLContextLossHandler() = default;
27 ////////////////////
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),
35 kDelayMS);
39 void WebGLContextLossHandler::ClearTimer() { mTimerIsScheduled = false; }
41 } // namespace mozilla