1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/webgl/ext_disjoint_timer_query.h"
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/blink/renderer/bindings/modules/v8/webgl_any.h"
#include "third_party/blink/renderer/modules/webgl/webgl_rendering_context_base.h"
#include "third_party/blink/renderer/modules/webgl/webgl_timer_query_ext.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
namespace blink {
WebGLExtensionName EXTDisjointTimerQuery::GetName() const {
return kEXTDisjointTimerQueryName;
}
bool EXTDisjointTimerQuery::Supported(WebGLRenderingContextBase* context) {
return context->ExtensionsUtil()->SupportsExtension(
"GL_EXT_disjoint_timer_query");
}
const char* EXTDisjointTimerQuery::ExtensionName() {
return "EXT_disjoint_timer_query";
}
WebGLTimerQueryEXT* EXTDisjointTimerQuery::createQueryEXT() {
WebGLExtensionScopedContext scoped(this);
// Object creation must be infallible even if the context is lost.
return MakeGarbageCollected<WebGLTimerQueryEXT>(scoped.Context());
}
void EXTDisjointTimerQuery::deleteQueryEXT(WebGLTimerQueryEXT* query) {
WebGLExtensionScopedContext scoped(this);
if (!query || scoped.IsLost())
return;
if (!query->Validate(scoped.Context())) {
scoped.Context()->SynthesizeGLError(
GL_INVALID_OPERATION, "delete",
"object does not belong to this context");
return;
}
if (query->MarkedForDeletion()) {
// Specified to be a no-op.
return;
}
if (query == current_elapsed_query_) {
scoped.Context()->ContextGL()->EndQueryEXT(query->Target());
current_elapsed_query_.Clear();
}
query->DeleteObject(scoped.Context()->ContextGL());
}
bool EXTDisjointTimerQuery::isQueryEXT(WebGLTimerQueryEXT* query) {
WebGLExtensionScopedContext scoped(this);
if (!query || scoped.IsLost() || query->MarkedForDeletion() ||
!query->Validate(scoped.Context())) {
return false;
}
return scoped.Context()->ContextGL()->IsQueryEXT(query->Object());
}
void EXTDisjointTimerQuery::beginQueryEXT(GLenum target,
WebGLTimerQueryEXT* query) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost())
return;
if (!scoped.Context()->ValidateWebGLObject("beginQueryEXT", query))
return;
if (target != GL_TIME_ELAPSED_EXT) {
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "beginQueryEXT",
"invalid target");
return;
}
if (current_elapsed_query_) {
scoped.Context()->SynthesizeGLError(GL_INVALID_OPERATION, "beginQueryEXT",
"a query is already active for target");
return;
}
if (query->HasTarget() && query->Target() != target) {
scoped.Context()->SynthesizeGLError(GL_INVALID_OPERATION, "beginQueryEXT",
"target does not match query");
return;
}
scoped.Context()->ContextGL()->BeginQueryEXT(target, query->Object());
query->SetTarget(target);
current_elapsed_query_ = query;
}
void EXTDisjointTimerQuery::endQueryEXT(GLenum target) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost())
return;
if (target != GL_TIME_ELAPSED_EXT) {
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "endQueryEXT",
"invalid target");
return;
}
if (!current_elapsed_query_) {
scoped.Context()->SynthesizeGLError(GL_INVALID_OPERATION, "endQueryEXT",
"no current query");
return;
}
scoped.Context()->ContextGL()->EndQueryEXT(target);
current_elapsed_query_->ResetCachedResult();
current_elapsed_query_.Clear();
}
void EXTDisjointTimerQuery::queryCounterEXT(WebGLTimerQueryEXT* query,
GLenum target) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost())
return;
if (!scoped.Context()->ValidateWebGLObject("queryCounterEXT", query))
return;
if (target != GL_TIMESTAMP_EXT) {
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "queryCounterEXT",
"invalid target");
return;
}
if (query->HasTarget() && query->Target() != target) {
scoped.Context()->SynthesizeGLError(GL_INVALID_OPERATION, "queryCounterEXT",
"target does not match query");
return;
}
scoped.Context()->ContextGL()->QueryCounterEXT(query->Object(), target);
query->SetTarget(target);
query->ResetCachedResult();
}
ScriptValue EXTDisjointTimerQuery::getQueryEXT(ScriptState* script_state,
GLenum target,
GLenum pname) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
if (pname == GL_QUERY_COUNTER_BITS_EXT) {
if (target == GL_TIMESTAMP_EXT || target == GL_TIME_ELAPSED_EXT) {
GLint value = 0;
scoped.Context()->ContextGL()->GetQueryivEXT(target, pname, &value);
return WebGLAny(script_state, value);
}
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "getQuery",
"invalid target/pname combination");
return ScriptValue::CreateNull(script_state->GetIsolate());
}
if (target == GL_TIME_ELAPSED_EXT && pname == GL_CURRENT_QUERY) {
return current_elapsed_query_
? WebGLAny(script_state, current_elapsed_query_)
: ScriptValue::CreateNull(script_state->GetIsolate());
}
if (target == GL_TIMESTAMP_EXT && pname == GL_CURRENT_QUERY) {
return ScriptValue::CreateNull(script_state->GetIsolate());
}
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "getQuery",
"invalid target/pname combination");
return ScriptValue::CreateNull(script_state->GetIsolate());
}
ScriptValue EXTDisjointTimerQuery::getQueryObjectEXT(ScriptState* script_state,
WebGLTimerQueryEXT* query,
GLenum pname) {
WebGLExtensionScopedContext scoped(this);
if (scoped.IsLost())
return ScriptValue::CreateNull(script_state->GetIsolate());
if (!scoped.Context()->ValidateWebGLObject("getQueryObjectEXT", query))
return ScriptValue::CreateNull(script_state->GetIsolate());
if (current_elapsed_query_ == query) {
scoped.Context()->SynthesizeGLError(
GL_INVALID_OPERATION, "getQueryObjectEXT", "query is currently active");
return ScriptValue::CreateNull(script_state->GetIsolate());
}
switch (pname) {
case GL_QUERY_RESULT_EXT: {
query->UpdateCachedResult(scoped.Context()->ContextGL());
return WebGLAny(script_state, query->GetQueryResult());
}
case GL_QUERY_RESULT_AVAILABLE_EXT: {
query->UpdateCachedResult(scoped.Context()->ContextGL());
return WebGLAny(script_state, query->IsQueryResultAvailable());
}
default:
scoped.Context()->SynthesizeGLError(GL_INVALID_ENUM, "getQueryObjectEXT",
"invalid pname");
break;
}
return ScriptValue::CreateNull(script_state->GetIsolate());
}
void EXTDisjointTimerQuery::Trace(Visitor* visitor) const {
visitor->Trace(current_elapsed_query_);
WebGLExtension::Trace(visitor);
}
EXTDisjointTimerQuery::EXTDisjointTimerQuery(WebGLRenderingContextBase* context)
: WebGLExtension(context) {
context->ExtensionsUtil()->EnsureExtensionEnabled(
"GL_EXT_disjoint_timer_query");
}
} // namespace blink
|