content/canvas/src/WebGL2Context.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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 "mozilla/dom/WebGL2RenderingContextBinding.h"
     9 #include "mozilla/Preferences.h"
    10 #include "mozilla/Telemetry.h"
    12 using namespace mozilla;
    13 using namespace mozilla::gl;
    15 // -----------------------------------------------------------------------------
    16 // CONSTRUCTOR & DESTRUCTOR
    18 WebGL2Context::WebGL2Context()
    19     : WebGLContext()
    20 {
    21     MOZ_ASSERT(IsSupported(), "not supposed to create a WebGL2Context"
    22                               "context when not supported");
    23 }
    25 WebGL2Context::~WebGL2Context()
    26 {
    28 }
    31 // -----------------------------------------------------------------------------
    32 // STATIC FUNCTIONS
    34 bool
    35 WebGL2Context::IsSupported()
    36 {
    37     return Preferences::GetBool("webgl.enable-prototype-webgl2", false);
    38 }
    40 WebGL2Context*
    41 WebGL2Context::Create()
    42 {
    43     return new WebGL2Context();
    44 }
    47 // -----------------------------------------------------------------------------
    48 // IMPLEMENT nsWrapperCache
    50 JSObject*
    51 WebGL2Context::WrapObject(JSContext *cx)
    52 {
    53     return dom::WebGL2RenderingContextBinding::Wrap(cx, this);
    54 }
    57 // -----------------------------------------------------------------------------
    58 // WebGL 2 initialisation
    60 bool
    61 WebGLContext::InitWebGL2()
    62 {
    63     MOZ_ASSERT(IsWebGL2(), "WebGLContext is not a WebGL 2 context!");
    65     const WebGLExtensionID sExtensionNativelySupportedArr[] = {
    66         WebGLExtensionID::ANGLE_instanced_arrays,
    67         WebGLExtensionID::OES_element_index_uint,
    68         WebGLExtensionID::OES_standard_derivatives,
    69         WebGLExtensionID::OES_texture_float,
    70         WebGLExtensionID::OES_texture_float_linear,
    71         WebGLExtensionID::OES_vertex_array_object,
    72         WebGLExtensionID::WEBGL_depth_texture,
    73         WebGLExtensionID::WEBGL_draw_buffers
    74     };
    75     const GLFeature sFeatureRequiredArr[] = {
    76         GLFeature::blend_minmax,
    77         GLFeature::instanced_non_arrays,
    78         GLFeature::transform_feedback
    79     };
    81     // check WebGL extensions that are supposed to be natively supported
    82     for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++)
    83     {
    84         WebGLExtensionID extension = sExtensionNativelySupportedArr[i];
    86         if (!IsExtensionSupported(extension)) {
    87             GenerateWarning("WebGL 2 requires %s!", GetExtensionString(extension));
    88             return false;
    89         }
    90     }
    92     // check required OpenGL extensions
    93     if (!gl->IsExtensionSupported(GLContext::EXT_gpu_shader4)) {
    94         GenerateWarning("WebGL 2 requires GL_EXT_gpu_shader4!");
    95         return false;
    96     }
    98     // check OpenGL features
    99     if (!gl->IsSupported(GLFeature::occlusion_query) &&
   100         !gl->IsSupported(GLFeature::occlusion_query_boolean))
   101     {
   102         /*
   103          * on desktop, we fake occlusion_query_boolean with occlusion_query if
   104          * necessary. See WebGLContextAsyncQueries.cpp.
   105          */
   106         GenerateWarning("WebGL 2 requires occlusion queries!");
   107         return false;
   108     }
   110     for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sFeatureRequiredArr)); i++)
   111     {
   112         if (!gl->IsSupported(sFeatureRequiredArr[i])) {
   113             GenerateWarning("WebGL 2 requires GLFeature::%s!", GLContext::GetFeatureName(sFeatureRequiredArr[i]));
   114             return false;
   115         }
   116     }
   118     // ok WebGL 2 is compatible, we can enable natively supported extensions.
   119     for (size_t i = 0; i < size_t(MOZ_ARRAY_LENGTH(sExtensionNativelySupportedArr)); i++) {
   120         EnableExtension(sExtensionNativelySupportedArr[i]);
   122         MOZ_ASSERT(IsExtensionEnabled(sExtensionNativelySupportedArr[i]));
   123     }
   125     // we initialise WebGL 2 related stuff.
   126     gl->GetUIntegerv(LOCAL_GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, &mGLMaxTransformFeedbackSeparateAttribs);
   128     return true;
   129 }

mercurial