Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(642)

Side by Side Diff: Source/modules/webgl/EXTDisjointTimerQuery.cpp

Issue 1325453007: Added support for EXTDisjointTimerQuery on the Blink side. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Switch to use HeapHashMap instead Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "modules/webgl/EXTDisjointTimerQuery.h"
8
9 #include "bindings/modules/v8/WebGLAny.h"
10 #include "modules/webgl/WebGLRenderingContextBase.h"
11 #include "modules/webgl/WebGLTimerQueryEXT.h"
12
13 namespace blink {
14
15 EXTDisjointTimerQuery::~EXTDisjointTimerQuery()
16 {
17 }
18
19 WebGLExtensionName EXTDisjointTimerQuery::name() const
20 {
21 return EXTDisjointTimerQueryName;
22 }
23
24 EXTDisjointTimerQuery* EXTDisjointTimerQuery::create(WebGLRenderingContextBase* context)
25 {
26 EXTDisjointTimerQuery* o = new EXTDisjointTimerQuery(context);
27 return o;
28 }
29
30 bool EXTDisjointTimerQuery::supported(WebGLRenderingContextBase* context)
31 {
32 return context->extensionsUtil()->supportsExtension("GL_EXT_disjoint_timer_q uery");
33 }
34
35 const char* EXTDisjointTimerQuery::extensionName()
36 {
37 return "EXT_disjoint_timer_query";
38 }
39
40 WebGLTimerQueryEXT* EXTDisjointTimerQuery::createQueryEXT()
41 {
42 WebGLExtensionScopedContext scoped(this);
43 if (scoped.isLost())
44 return nullptr;
45
46 WebGLTimerQueryEXT* o = WebGLTimerQueryEXT::create(scoped.context());
47 m_timerQueryMap.set(o->object(), o);
48 scoped.context()->addContextObject(o);
49 return o;
50 }
51
52 void EXTDisjointTimerQuery::deleteQueryEXT(WebGLTimerQueryEXT* query)
53 {
54 WebGLExtensionScopedContext scoped(this);
55 if (!query || scoped.isLost())
56 return;
57 query->deleteObject(scoped.context()->webContext());
58 }
59
60 GLboolean EXTDisjointTimerQuery::isQueryEXT(WebGLTimerQueryEXT* query)
61 {
62 WebGLExtensionScopedContext scoped(this);
63 if (!query || scoped.isLost() || query->isDeleted() || !query->validate(0, s coped.context())) {
64 return false;
65 }
66
67 return scoped.context()->webContext()->isQueryEXT(query->object());
68 }
69
70 void EXTDisjointTimerQuery::beginQueryEXT(GLenum target, WebGLTimerQueryEXT* que ry)
71 {
72 WebGLExtensionScopedContext scoped(this);
73 if (scoped.isLost())
74 return;
75
76 if (!query || query->isDeleted() || !query->validate(0, scoped.context())) {
77 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_OPERATION);
78 return;
79 }
80
81 if (target != GL_TIME_ELAPSED_EXT) {
82 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_ENUM);
83 return;
84 }
85
86 scoped.context()->webContext()->beginQueryEXT(target, query->object());
87 }
88
89 void EXTDisjointTimerQuery::endQueryEXT(GLenum target)
90 {
91 WebGLExtensionScopedContext scoped(this);
92 if (scoped.isLost())
93 return;
94
95 if (target != GL_TIME_ELAPSED_EXT) {
96 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_ENUM);
97 return;
98 }
99
100 scoped.context()->webContext()->endQueryEXT(target);
101 }
102
103 void EXTDisjointTimerQuery::queryCounterEXT(WebGLTimerQueryEXT* query, GLenum ta rget)
104 {
105 WebGLExtensionScopedContext scoped(this);
106 if (scoped.isLost())
107 return;
108
109 if (!query || query->isDeleted() || !query->validate(0, scoped.context())) {
110 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_OPERATION);
111 return;
112 }
113
114 if (target != GL_TIMESTAMP_EXT) {
115 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_ENUM);
116 return;
117 }
118
119 scoped.context()->webContext()->queryCounterEXT(query->object(), target);
120 }
121
122 ScriptValue EXTDisjointTimerQuery::getQueryEXT(ScriptState* scriptState, GLenum target, GLenum pname)
123 {
124 WebGLExtensionScopedContext scoped(this);
125 if (scoped.isLost())
126 return ScriptValue::createNull(scriptState);
127
128 if (target == GL_TIMESTAMP_EXT || target == GL_TIME_ELAPSED_EXT) {
129 switch (pname) {
130 case GL_CURRENT_QUERY_EXT: {
131 GLint queryId = 0;
132 scoped.context()->webContext()->getQueryivEXT(target, pname, &queryI d);
133 if (queryId) {
134 auto iter = m_timerQueryMap.find(queryId);
135 if (iter != m_timerQueryMap.end()) {
136 return WebGLAny(scriptState, iter->value.get());
137 }
138 }
139 return ScriptValue::createNull(scriptState);
140 }
141 case GL_QUERY_COUNTER_BITS_EXT: {
142 GLint value = 0;
143 scoped.context()->webContext()->getQueryivEXT(target, pname, &value) ;
144 return WebGLAny(scriptState, value);
145 }
146 default:
147 break;
148 }
149 }
150
151 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_ENUM);
152 return ScriptValue::createNull(scriptState);
153 }
154
155 ScriptValue EXTDisjointTimerQuery::getQueryObjectEXT(ScriptState* scriptState, W ebGLTimerQueryEXT* query, GLenum pname)
156 {
157 WebGLExtensionScopedContext scoped(this);
158 if (scoped.isLost())
159 return ScriptValue::createNull(scriptState);
160
161 if (!query || query->isDeleted() || !query->validate(0, scoped.context())) {
162 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_OPERATION);
163 return ScriptValue::createNull(scriptState);
164 }
165
166 switch (pname) {
167 case GL_QUERY_RESULT_EXT: {
168 GLuint64 result = 0;
169 scoped.context()->webContext()->getQueryObjectui64vEXT(query->object(), pname, &result);
170 return WebGLAny(scriptState, result);
171 }
172 case GL_QUERY_RESULT_AVAILABLE_EXT: {
173 GLuint available = 0;
174 scoped.context()->webContext()->getQueryObjectuivEXT(query->object(), pn ame, &available);
175 return WebGLAny(scriptState, !!available);
176 }
177 default:
178 scoped.context()->webContext()->synthesizeGLError(GL_INVALID_ENUM);
179 break;
180 }
181
182 return ScriptValue::createNull(scriptState);
183 }
184
185 DEFINE_TRACE(EXTDisjointTimerQuery)
186 {
187 visitor->trace(m_timerQueryMap);
188 WebGLExtension::trace(visitor);
189 }
190
191 EXTDisjointTimerQuery::EXTDisjointTimerQuery(WebGLRenderingContextBase* context)
192 : WebGLExtension(context)
193 {
194 context->extensionsUtil()->ensureExtensionEnabled("GL_EXT_disjoint_timer_que ry");
195 }
196
197 void EXTDisjointTimerQuery::OnQueryDeleted(GLuint queryId)
198 {
199 m_timerQueryMap.remove(queryId);
200 }
201
202 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698