|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
|
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/. */ |
|
5 |
|
6 #include "WebGLContext.h" |
|
7 #include "GLContext.h" |
|
8 #include "WebGLQuery.h" |
|
9 #include "mozilla/dom/WebGL2RenderingContextBinding.h" |
|
10 #include "nsContentUtils.h" |
|
11 |
|
12 using namespace mozilla; |
|
13 |
|
14 JSObject* |
|
15 WebGLQuery::WrapObject(JSContext *cx) { |
|
16 return dom::WebGLQueryBinding::Wrap(cx, this); |
|
17 } |
|
18 |
|
19 WebGLQuery::WebGLQuery(WebGLContext* context) |
|
20 : WebGLContextBoundObject(context) |
|
21 , mGLName(0) |
|
22 , mType(0) |
|
23 { |
|
24 SetIsDOMBinding(); |
|
25 mContext->mQueries.insertBack(this); |
|
26 |
|
27 mContext->MakeContextCurrent(); |
|
28 mContext->gl->fGenQueries(1, &mGLName); |
|
29 } |
|
30 |
|
31 void WebGLQuery::Delete() { |
|
32 mContext->MakeContextCurrent(); |
|
33 mContext->gl->fDeleteQueries(1, &mGLName); |
|
34 LinkedListElement<WebGLQuery>::removeFrom(mContext->mQueries); |
|
35 } |
|
36 |
|
37 bool WebGLQuery::IsActive() const |
|
38 { |
|
39 WebGLRefPtr<WebGLQuery>* targetSlot = mContext->GetQueryTargetSlot(mType, "WebGLQuery::IsActive()"); |
|
40 |
|
41 MOZ_ASSERT(targetSlot, "unknown query object's type"); |
|
42 |
|
43 return targetSlot && *targetSlot == this; |
|
44 } |
|
45 |
|
46 |
|
47 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLQuery) |
|
48 |
|
49 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLQuery, AddRef) |
|
50 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLQuery, Release) |