dom/canvas/WebGLTimerQuery.cpp
author Jeff Gilbert <jgilbert@mozilla.com>
Thu, 21 Jul 2016 23:38:31 -0700
changeset 391215 36673ebb956b1e54d5ddac6b650fe81a34863315
parent 375424 53de33ce847f9e5e9b77b6ed08027813a325f95f
child 391216 17a88ce695956d75c290afa35f6e30c37fbfd491
permissions -rw-r--r--
Bug 1288643 - Delete on Detach. - r=jerry MozReview-Commit-ID: 7nI0SYFqf1

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "WebGLTimerQuery.h"

#include "GLContext.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "nsContentUtils.h"
#include "WebGLContext.h"
#include "nsThreadUtils.h"

namespace mozilla {

JSObject*
WebGLTimerQuery::WrapObject(JSContext* cx, JS::Handle<JSObject*> givenProto)
{
  return dom::WebGLTimerQueryEXTBinding::Wrap(cx, this, givenProto);
}

WebGLTimerQuery::WebGLTimerQuery(WebGLContext* webgl, GLuint name)
  : WebGLContextBoundObject(webgl)
  , mGLName(name)
  , mTarget(LOCAL_GL_NONE)
  , mCanBeAvailable(false)
{
  mContext->mTimerQueries.insertBack(this);
}

WebGLTimerQuery::~WebGLTimerQuery()
{
  DetachOnce();
}

WebGLTimerQuery*
WebGLTimerQuery::Create(WebGLContext* webgl)
{
  GLuint name = 0;
  webgl->MakeContextCurrent();
  webgl->gl->fGenQueries(1, &name);
  return new WebGLTimerQuery(webgl, name);
}

void
WebGLTimerQuery::Delete()
{
  gl::GLContext* gl = mContext->GL();

  gl->MakeCurrent();
  gl->fDeleteQueries(1, &mGLName);

  LinkedListElement<WebGLTimerQuery>::removeFrom(mContext->mTimerQueries);
}

WebGLContext*
WebGLTimerQuery::GetParentObject() const
{
  return mContext;
}

void
WebGLTimerQuery::QueueAvailablity()
{
  RefPtr<WebGLTimerQuery> self = this;
  NS_DispatchToCurrentThread(NS_NewRunnableFunction([self] { self->mCanBeAvailable = true; }));
}

NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLTimerQuery)

NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLTimerQuery, AddRef)
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLTimerQuery, Release)

} // namespace mozilla