Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "WebGLExtensions.h"
8 :
9 : #include "gfxPrefs.h"
10 : #include "GLContext.h"
11 : #include "mozilla/dom/ToJSValue.h"
12 : #include "mozilla/dom/WebGLRenderingContextBinding.h"
13 : #include "mozilla/dom/BindingUtils.h"
14 : #include "WebGLContext.h"
15 : #include "WebGLQuery.h"
16 :
17 : namespace mozilla {
18 :
19 0 : WebGLExtensionDisjointTimerQuery::WebGLExtensionDisjointTimerQuery(WebGLContext* webgl)
20 0 : : WebGLExtensionBase(webgl)
21 : {
22 0 : MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported.");
23 0 : }
24 :
25 0 : WebGLExtensionDisjointTimerQuery::~WebGLExtensionDisjointTimerQuery()
26 : {
27 0 : }
28 :
29 : already_AddRefed<WebGLQuery>
30 0 : WebGLExtensionDisjointTimerQuery::CreateQueryEXT() const
31 : {
32 0 : const char funcName[] = "createQueryEXT";
33 0 : if (mIsLost)
34 0 : return nullptr;
35 :
36 0 : return mContext->CreateQuery(funcName);
37 : }
38 :
39 : void
40 0 : WebGLExtensionDisjointTimerQuery::DeleteQueryEXT(WebGLQuery* query) const
41 : {
42 0 : const char funcName[] = "deleteQueryEXT";
43 0 : if (mIsLost)
44 0 : return;
45 :
46 0 : mContext->DeleteQuery(query, funcName);
47 : }
48 :
49 : bool
50 0 : WebGLExtensionDisjointTimerQuery::IsQueryEXT(const WebGLQuery* query) const
51 : {
52 0 : const char funcName[] = "isQueryEXT";
53 0 : if (mIsLost)
54 0 : return false;
55 :
56 0 : return mContext->IsQuery(query, funcName);
57 : }
58 :
59 : void
60 0 : WebGLExtensionDisjointTimerQuery::BeginQueryEXT(GLenum target, WebGLQuery& query) const
61 : {
62 0 : const char funcName[] = "beginQueryEXT";
63 0 : if (mIsLost)
64 0 : return;
65 :
66 0 : mContext->BeginQuery(target, query, funcName);
67 : }
68 :
69 : void
70 0 : WebGLExtensionDisjointTimerQuery::EndQueryEXT(GLenum target) const
71 : {
72 0 : const char funcName[] = "endQueryEXT";
73 0 : if (mIsLost)
74 0 : return;
75 :
76 0 : mContext->EndQuery(target, funcName);
77 : }
78 :
79 : void
80 0 : WebGLExtensionDisjointTimerQuery::QueryCounterEXT(WebGLQuery& query, GLenum target) const
81 : {
82 0 : const char funcName[] = "queryCounterEXT";
83 0 : if (mIsLost)
84 0 : return;
85 :
86 0 : if (!mContext->ValidateObject(funcName, query))
87 0 : return;
88 :
89 0 : query.QueryCounter(funcName, target);
90 : }
91 :
92 : void
93 0 : WebGLExtensionDisjointTimerQuery::GetQueryEXT(JSContext* cx, GLenum target, GLenum pname,
94 : JS::MutableHandleValue retval) const
95 : {
96 0 : const char funcName[] = "getQueryEXT";
97 0 : retval.setNull();
98 0 : if (mIsLost)
99 0 : return;
100 :
101 0 : mContext->GetQuery(cx, target, pname, retval, funcName);
102 : }
103 :
104 : void
105 0 : WebGLExtensionDisjointTimerQuery::GetQueryObjectEXT(JSContext* cx,
106 : const WebGLQuery& query, GLenum pname,
107 : JS::MutableHandleValue retval) const
108 : {
109 0 : const char funcName[] = "getQueryObjectEXT";
110 0 : retval.setNull();
111 0 : if (mIsLost)
112 0 : return;
113 :
114 0 : mContext->GetQueryParameter(cx, query, pname, retval, funcName);
115 : }
116 :
117 : bool
118 0 : WebGLExtensionDisjointTimerQuery::IsSupported(const WebGLContext* webgl)
119 : {
120 0 : webgl->MakeContextCurrent();
121 0 : gl::GLContext* gl = webgl->GL();
122 0 : return gl->IsSupported(gl::GLFeature::query_objects) &&
123 0 : gl->IsSupported(gl::GLFeature::get_query_object_i64v) &&
124 0 : gl->IsSupported(gl::GLFeature::query_counter); // provides GL_TIMESTAMP
125 : }
126 :
127 0 : IMPL_WEBGL_EXTENSION_GOOP(WebGLExtensionDisjointTimerQuery, EXT_disjoint_timer_query)
128 :
129 : } // namespace mozilla
|