LCOV - code coverage report
Current view: top level - dom/canvas - WebGLTypes.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 20 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; 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/. */
       5             : 
       6             : #ifndef WEBGLTYPES_H_
       7             : #define WEBGLTYPES_H_
       8             : 
       9             : // Most WebIDL typedefs are identical to their OpenGL counterparts.
      10             : #include "GLTypes.h"
      11             : 
      12             : // Manual reflection of WebIDL typedefs that are different from their
      13             : // OpenGL counterparts.
      14             : typedef int64_t WebGLsizeiptr;
      15             : typedef int64_t WebGLintptr;
      16             : typedef bool WebGLboolean;
      17             : 
      18             : namespace mozilla {
      19             : namespace gl {
      20             : class GLContext; // This is going to be needed a lot.
      21             : } // namespace gl
      22             : 
      23             : /*
      24             :  * WebGLTextureFakeBlackStatus is an enum to track what needs to use a dummy 1x1 black
      25             :  * texture, which we refer to as a 'fake black' texture.
      26             :  *
      27             :  * There are two things that can cause us to use such 'fake black' textures:
      28             :  *
      29             :  *   (1) OpenGL ES rules on sampling incomplete textures specify that they
      30             :  *       must be sampled as RGBA(0, 0, 0, 1) (opaque black). We have to implement these rules
      31             :  *       ourselves, if only because we do not always run on OpenGL ES, and also
      32             :  *       because this is dangerously close to the kind of case where we don't
      33             :  *       want to trust the driver with corner cases of texture memory accesses.
      34             :  *
      35             :  *   (2) OpenGL has cases where a renderbuffer, or a texture image, can contain
      36             :  *       uninitialized image data. See below the comment about WebGLImageDataStatus.
      37             :  *       WebGL must never have access to uninitialized image data. The WebGL 1 spec,
      38             :  *       section 4.1 'Resource Restrictions', specifies that in any such case, the
      39             :  *       uninitialized image data must be exposed to WebGL as if it were filled
      40             :  *       with zero bytes, which means it's either opaque or transparent black
      41             :  *       depending on whether the image format has alpha.
      42             :  */
      43             : 
      44             : enum class FakeBlackType : uint8_t {
      45             :     None,
      46             :     RGBA0001, // Incomplete textures and uninitialized no-alpha color textures.
      47             :     RGBA0000, // Uninitialized with-alpha color textures.
      48             : };
      49             : 
      50             : /*
      51             :  * Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
      52             :  * emulating the vertex attrib 0 array when it's not enabled. Indeed,
      53             :  * OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
      54             :  * desktop OpenGL does not allow that.
      55             :  */
      56             : enum class WebGLVertexAttrib0Status : uint8_t {
      57             :     Default, // default status - no emulation needed
      58             :     EmulatedUninitializedArray, // need an artificial attrib 0 array, but contents may be left uninitialized
      59             :     EmulatedInitializedArray // need an artificial attrib 0 array, and contents must be initialized
      60             : };
      61             : 
      62             : /*
      63             :  * Enum to track the status of image data (renderbuffer or texture image) presence
      64             :  * and initialization.
      65             :  *
      66             :  * - NoImageData is the initial state before any image data is allocated.
      67             :  * - InitializedImageData is the state after image data is allocated and initialized.
      68             :  * - UninitializedImageData is an intermediate state where data is allocated but not
      69             :  *   initialized. It is the state that renderbuffers are in after a renderbufferStorage call,
      70             :  *   and it is the state that texture images are in after a texImage2D call with null data.
      71             :  */
      72             : enum class WebGLImageDataStatus : uint8_t {
      73             :     NoImageData,
      74             :     UninitializedImageData,
      75             :     InitializedImageData
      76             : };
      77             : 
      78             : /*
      79             :  * The formats that may participate, either as source or destination formats,
      80             :  * in WebGL texture conversions. This includes:
      81             :  *  - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
      82             :  *  - additional formats provided by extensions, e.g. RGB32F
      83             :  *  - additional source formats, depending on browser details, used when uploading
      84             :  *    textures from DOM elements. See gfxImageSurface::Format().
      85             :  */
      86             : enum class WebGLTexelFormat : uint8_t {
      87             :     // returned by SurfaceFromElementResultToImageSurface to indicate absence of image data
      88             :     None,
      89             :     // common value for formats for which format conversions are not supported
      90             :     FormatNotSupportingAnyConversion,
      91             :     // dummy pseudo-format meaning "use the other format".
      92             :     // For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
      93             :     // is implicitly treated as being RGB8 itself.
      94             :     Auto,
      95             :     // 1-channel formats
      96             :     A8,
      97             :     A16F, // OES_texture_half_float
      98             :     A32F, // OES_texture_float
      99             :     R8,
     100             :     R16F, // OES_texture_half_float
     101             :     R32F, // OES_texture_float
     102             :     // 2-channel formats
     103             :     RA8,
     104             :     RA16F, // OES_texture_half_float
     105             :     RA32F, // OES_texture_float
     106             :     RG8,
     107             :     RG16F,
     108             :     RG32F,
     109             :     // 3-channel formats
     110             :     RGB8,
     111             :     RGB565,
     112             :     RGB11F11F10F,
     113             :     RGB16F, // OES_texture_half_float
     114             :     RGB32F, // OES_texture_float
     115             :     // 4-channel formats
     116             :     RGBA8,
     117             :     RGBA5551,
     118             :     RGBA4444,
     119             :     RGBA16F, // OES_texture_half_float
     120             :     RGBA32F, // OES_texture_float
     121             :     // DOM element source only formats.
     122             :     RGBX8,
     123             :     BGRX8,
     124             :     BGRA8
     125             : };
     126             : 
     127             : enum class WebGLTexImageFunc : uint8_t {
     128             :     TexImage,
     129             :     TexSubImage,
     130             :     CopyTexImage,
     131             :     CopyTexSubImage,
     132             :     CompTexImage,
     133             :     CompTexSubImage,
     134             : };
     135             : 
     136             : enum class WebGLTexDimensions : uint8_t {
     137             :     Tex2D,
     138             :     Tex3D
     139             : };
     140             : 
     141             : // Please keep extensions in alphabetic order.
     142             : enum class WebGLExtensionID : uint8_t {
     143             :     ANGLE_instanced_arrays,
     144             :     EXT_blend_minmax,
     145             :     EXT_color_buffer_float,
     146             :     EXT_color_buffer_half_float,
     147             :     EXT_frag_depth,
     148             :     EXT_sRGB,
     149             :     EXT_shader_texture_lod,
     150             :     EXT_texture_filter_anisotropic,
     151             :     EXT_disjoint_timer_query,
     152             :     MOZ_debug,
     153             :     OES_element_index_uint,
     154             :     OES_standard_derivatives,
     155             :     OES_texture_float,
     156             :     OES_texture_float_linear,
     157             :     OES_texture_half_float,
     158             :     OES_texture_half_float_linear,
     159             :     OES_vertex_array_object,
     160             :     WEBGL_color_buffer_float,
     161             :     WEBGL_compressed_texture_astc,
     162             :     WEBGL_compressed_texture_atc,
     163             :     WEBGL_compressed_texture_etc,
     164             :     WEBGL_compressed_texture_etc1,
     165             :     WEBGL_compressed_texture_pvrtc,
     166             :     WEBGL_compressed_texture_s3tc,
     167             :     WEBGL_compressed_texture_s3tc_srgb,
     168             :     WEBGL_debug_renderer_info,
     169             :     WEBGL_debug_shaders,
     170             :     WEBGL_depth_texture,
     171             :     WEBGL_draw_buffers,
     172             :     WEBGL_lose_context,
     173             :     Max,
     174             :     Unknown
     175             : };
     176             : 
     177             : class UniqueBuffer
     178             : {
     179             :     // Like UniquePtr<>, but for void* and malloc/calloc/free.
     180             :     void* mBuffer;
     181             : 
     182             : public:
     183           0 :     UniqueBuffer()
     184           0 :         : mBuffer(nullptr)
     185           0 :     { }
     186             : 
     187           0 :     MOZ_IMPLICIT UniqueBuffer(void* buffer)
     188           0 :         : mBuffer(buffer)
     189           0 :     { }
     190             : 
     191           0 :     ~UniqueBuffer() {
     192           0 :         free(mBuffer);
     193           0 :     }
     194             : 
     195             :     UniqueBuffer(UniqueBuffer&& other) {
     196             :         this->mBuffer = other.mBuffer;
     197             :         other.mBuffer = nullptr;
     198             :     }
     199             : 
     200           0 :     UniqueBuffer& operator =(UniqueBuffer&& other) {
     201           0 :         free(this->mBuffer);
     202           0 :         this->mBuffer = other.mBuffer;
     203           0 :         other.mBuffer = nullptr;
     204           0 :         return *this;
     205             :     }
     206             : 
     207           0 :     UniqueBuffer& operator =(void* newBuffer) {
     208           0 :         free(this->mBuffer);
     209           0 :         this->mBuffer = newBuffer;
     210           0 :         return *this;
     211             :     }
     212             : 
     213           0 :     explicit operator bool() const { return bool(mBuffer); }
     214             : 
     215           0 :     void* get() const { return mBuffer; }
     216             : 
     217             :     UniqueBuffer(const UniqueBuffer& other) = delete; // construct using Move()!
     218             :     void operator =(const UniqueBuffer& other) = delete; // assign using Move()!
     219             : };
     220             : 
     221             : } // namespace mozilla
     222             : 
     223             : #endif

Generated by: LCOV version 1.13