Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / canvas / WebGL2ContextQueries.cpp
blob17a1a462f0adcb93f9acfd6bddf90429a0e7735d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "WebGL2Context.h"
7 #include "GLContext.h"
8 #include "WebGLQuery.h"
9 #include "nsThreadUtils.h"
11 namespace mozilla {
14 * We fake ANY_SAMPLES_PASSED and ANY_SAMPLES_PASSED_CONSERVATIVE with
15 * SAMPLES_PASSED on desktop.
17 * OpenGL ES 3.0 spec 4.1.6:
18 * If the target of the query is ANY_SAMPLES_PASSED_CONSERVATIVE, an
19 * implementation may choose to use a less precise version of the test which
20 * can additionally set the samples-boolean state to TRUE in some other
21 * implementation-dependent cases.
24 RefPtr<WebGLQuery>* WebGLContext::ValidateQuerySlotByTarget(GLenum target) {
25 if (IsWebGL2()) {
26 switch (target) {
27 case LOCAL_GL_ANY_SAMPLES_PASSED:
28 case LOCAL_GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
29 return &mQuerySlot_SamplesPassed;
31 case LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
32 return &mQuerySlot_TFPrimsWritten;
34 default:
35 break;
39 if (IsExtensionEnabled(WebGLExtensionID::EXT_disjoint_timer_query)) {
40 switch (target) {
41 case LOCAL_GL_TIME_ELAPSED_EXT:
42 return &mQuerySlot_TimeElapsed;
44 default:
45 break;
49 ErrorInvalidEnumInfo("target", target);
50 return nullptr;
53 // -------------------------------------------------------------------------
54 // Query Objects
56 RefPtr<WebGLQuery> WebGLContext::CreateQuery() {
57 const FuncScope funcScope(*this, "createQuery");
58 if (IsContextLost()) return nullptr;
60 return new WebGLQuery(this);
63 void WebGLContext::BeginQuery(GLenum target, WebGLQuery& query) {
64 FuncScope funcScope(*this, "beginQuery");
65 if (IsContextLost()) return;
66 funcScope.mBindFailureGuard = true;
68 const auto& slot = ValidateQuerySlotByTarget(target);
69 if (!slot) return;
71 if (*slot) return ErrorInvalidOperation("Query target already active.");
73 const auto& curTarget = query.Target();
74 if (curTarget && target != curTarget) {
75 ErrorInvalidOperation("Queries cannot change targets.");
76 return;
79 ////
81 query.BeginQuery(target, *slot);
83 funcScope.mBindFailureGuard = false;
86 void WebGLContext::EndQuery(GLenum target) {
87 FuncScope funcScope(*this, "endQuery");
88 if (IsContextLost()) return;
89 funcScope.mBindFailureGuard = true;
91 const auto& slot = ValidateQuerySlotByTarget(target);
92 if (!slot) return;
94 const auto query = *slot; // Grab a strong reference.
95 if (!query) return ErrorInvalidOperation("Query target not active.");
97 query->EndQuery();
99 funcScope.mBindFailureGuard = false;
102 Maybe<double> WebGLContext::GetQueryParameter(const WebGLQuery& query,
103 GLenum pname) const {
104 const FuncScope funcScope(*this, "getQueryParameter");
105 if (IsContextLost()) return Nothing();
107 return query.GetQueryParameter(pname);
110 // disjoint_timer_queries
112 void WebGLContext::QueryCounter(WebGLQuery& query) const {
113 const WebGLContext::FuncScope funcScope(*this, "queryCounterEXT");
114 if (IsContextLost()) return;
116 query.QueryCounter();
119 } // namespace mozilla