tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebGL2ContextQueries.cpp (3295B)


      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/. */
      5 
      6 #include "GLContext.h"
      7 #include "WebGL2Context.h"
      8 #include "WebGLQuery.h"
      9 #include "nsThreadUtils.h"
     10 
     11 namespace mozilla {
     12 
     13 /*
     14 * We fake ANY_SAMPLES_PASSED and ANY_SAMPLES_PASSED_CONSERVATIVE with
     15 * SAMPLES_PASSED on desktop.
     16 *
     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.
     22 */
     23 
     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;
     30 
     31      case LOCAL_GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
     32        return &mQuerySlot_TFPrimsWritten;
     33 
     34      default:
     35        break;
     36    }
     37  }
     38 
     39  if (IsExtensionEnabled(WebGLExtensionID::EXT_disjoint_timer_query)) {
     40    switch (target) {
     41      case LOCAL_GL_TIME_ELAPSED_EXT:
     42        return &mQuerySlot_TimeElapsed;
     43 
     44      default:
     45        break;
     46    }
     47  }
     48 
     49  ErrorInvalidEnumInfo("target", target);
     50  return nullptr;
     51 }
     52 
     53 // -------------------------------------------------------------------------
     54 // Query Objects
     55 
     56 RefPtr<WebGLQuery> WebGLContext::CreateQuery() {
     57  const FuncScope funcScope(*this, "createQuery");
     58  if (IsContextLost()) return nullptr;
     59 
     60  return new WebGLQuery(this);
     61 }
     62 
     63 void WebGLContext::BeginQuery(GLenum target, WebGLQuery& query) {
     64  FuncScope funcScope(*this, "beginQuery");
     65  if (IsContextLost()) return;
     66  funcScope.mBindFailureGuard = true;
     67 
     68  const auto& slot = ValidateQuerySlotByTarget(target);
     69  if (!slot) return;
     70 
     71  if (*slot) return ErrorInvalidOperation("Query target already active.");
     72 
     73  const auto& curTarget = query.Target();
     74  if (curTarget && target != curTarget) {
     75    ErrorInvalidOperation("Queries cannot change targets.");
     76    return;
     77  }
     78 
     79  ////
     80 
     81  query.BeginQuery(target, *slot);
     82 
     83  funcScope.mBindFailureGuard = false;
     84 }
     85 
     86 void WebGLContext::EndQuery(GLenum target) {
     87  FuncScope funcScope(*this, "endQuery");
     88  if (IsContextLost()) return;
     89  funcScope.mBindFailureGuard = true;
     90 
     91  const auto& slot = ValidateQuerySlotByTarget(target);
     92  if (!slot) return;
     93 
     94  const auto query = *slot;  // Grab a strong reference.
     95  if (!query) return ErrorInvalidOperation("Query target not active.");
     96 
     97  query->EndQuery();
     98 
     99  funcScope.mBindFailureGuard = false;
    100 }
    101 
    102 Maybe<double> WebGLContext::GetQueryParameter(const WebGLQuery& query,
    103                                              GLenum pname) const {
    104  const FuncScope funcScope(*this, "getQueryParameter");
    105  if (IsContextLost()) return Nothing();
    106 
    107  return query.GetQueryParameter(pname);
    108 }
    109 
    110 // disjoint_timer_queries
    111 
    112 void WebGLContext::QueryCounter(WebGLQuery& query) const {
    113  const WebGLContext::FuncScope funcScope(*this, "queryCounterEXT");
    114  if (IsContextLost()) return;
    115 
    116  query.QueryCounter();
    117 }
    118 
    119 }  // namespace mozilla