2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2013-06-11 00:00:35 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WEBGLTYPES_H_
|
|
|
|
#define WEBGLTYPES_H_
|
|
|
|
|
2019-03-07 03:41:16 +03:00
|
|
|
#include <limits>
|
2020-01-09 01:19:16 +03:00
|
|
|
#include <type_traits>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
2019-03-07 03:41:16 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
#include "GLDefs.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "ImageContainer.h"
|
2019-04-02 20:00:41 +03:00
|
|
|
#include "mozilla/Casting.h"
|
2020-01-09 01:19:16 +03:00
|
|
|
#include "mozilla/CheckedInt.h"
|
2020-11-23 22:54:41 +03:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2020-01-09 01:19:16 +03:00
|
|
|
#include "mozilla/Range.h"
|
|
|
|
#include "mozilla/RefCounted.h"
|
2020-11-23 18:49:14 +03:00
|
|
|
#include "mozilla/ResultVariant.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2020-08-23 09:09:33 +03:00
|
|
|
#include "mozilla/gfx/BuildConstants.h"
|
2020-02-11 04:23:37 +03:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2020-07-22 01:56:52 +03:00
|
|
|
#include "mozilla/ipc/Shmem.h"
|
2021-01-14 04:23:06 +03:00
|
|
|
#include "mozilla/layers/LayersSurfaces.h"
|
2020-01-09 01:19:14 +03:00
|
|
|
#include "gfxTypes.h"
|
|
|
|
|
|
|
|
#include "nsTArray.h"
|
2020-01-09 01:19:23 +03:00
|
|
|
#include "nsString.h"
|
2020-01-09 01:19:14 +03:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
|
|
|
#include "mozilla/ipc/SharedMemoryBasic.h"
|
2013-09-04 16:14:44 +04:00
|
|
|
|
|
|
|
// Manual reflection of WebIDL typedefs that are different from their
|
|
|
|
// OpenGL counterparts.
|
2013-06-11 00:00:35 +04:00
|
|
|
typedef int64_t WebGLsizeiptr;
|
|
|
|
typedef int64_t WebGLintptr;
|
|
|
|
typedef bool WebGLboolean;
|
|
|
|
|
2019-03-07 03:41:16 +03:00
|
|
|
// -
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
namespace mozilla {
|
2016-07-22 09:25:41 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLContext; // This is going to be needed a lot.
|
|
|
|
} // namespace gl
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2019-03-07 03:41:16 +03:00
|
|
|
// -
|
2019-03-30 09:42:18 +03:00
|
|
|
// Prevent implicit conversions into calloc and malloc. (mozilla namespace
|
|
|
|
// only!)
|
2019-03-07 03:41:16 +03:00
|
|
|
|
2019-03-30 09:42:18 +03:00
|
|
|
template <typename DestT>
|
|
|
|
class ForbidNarrowing final {
|
2019-03-07 03:41:16 +03:00
|
|
|
DestT mVal;
|
|
|
|
|
2019-03-30 09:42:18 +03:00
|
|
|
public:
|
|
|
|
template <typename SrcT>
|
2019-03-07 03:41:16 +03:00
|
|
|
MOZ_IMPLICIT ForbidNarrowing(SrcT val) : mVal(val) {
|
2019-03-30 09:42:18 +03:00
|
|
|
static_assert(
|
|
|
|
std::numeric_limits<SrcT>::min() >= std::numeric_limits<DestT>::min(),
|
|
|
|
"SrcT must be narrower than DestT.");
|
|
|
|
static_assert(
|
|
|
|
std::numeric_limits<SrcT>::max() <= std::numeric_limits<DestT>::max(),
|
|
|
|
"SrcT must be narrower than DestT.");
|
2019-03-07 03:41:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator DestT() const { return mVal; }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void* malloc(const ForbidNarrowing<size_t> s) {
|
|
|
|
return ::malloc(size_t(s));
|
|
|
|
}
|
|
|
|
|
2019-03-30 09:42:18 +03:00
|
|
|
inline void* calloc(const ForbidNarrowing<size_t> n,
|
|
|
|
const ForbidNarrowing<size_t> size) {
|
2019-03-07 03:41:16 +03:00
|
|
|
return ::calloc(size_t(n), size_t(size));
|
|
|
|
}
|
|
|
|
|
2019-04-02 20:00:41 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
template <typename From>
|
|
|
|
class AutoAssertCastT final {
|
|
|
|
const From mVal;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit AutoAssertCastT(const From val) : mVal(val) {}
|
|
|
|
|
|
|
|
template <typename To>
|
|
|
|
operator To() const {
|
|
|
|
return AssertedCast<To>(mVal);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
template <typename From>
|
|
|
|
inline auto AutoAssertCast(const From val) {
|
|
|
|
return detail::AutoAssertCastT<From>(val);
|
|
|
|
}
|
|
|
|
|
2020-05-01 01:22:52 +03:00
|
|
|
namespace webgl {
|
2020-01-09 01:19:14 +03:00
|
|
|
template <typename T>
|
2020-05-01 01:21:45 +03:00
|
|
|
struct QueueParamTraits;
|
2020-01-09 01:19:14 +03:00
|
|
|
class TexUnpackBytes;
|
|
|
|
class TexUnpackImage;
|
|
|
|
class TexUnpackSurface;
|
|
|
|
} // namespace webgl
|
|
|
|
|
|
|
|
class ClientWebGLContext;
|
|
|
|
struct WebGLTexPboOffset;
|
|
|
|
class WebGLTexture;
|
|
|
|
class WebGLBuffer;
|
|
|
|
class WebGLFramebuffer;
|
|
|
|
class WebGLProgram;
|
|
|
|
class WebGLQuery;
|
|
|
|
class WebGLRenderbuffer;
|
|
|
|
class WebGLSampler;
|
|
|
|
class WebGLShader;
|
|
|
|
class WebGLSync;
|
|
|
|
class WebGLTexture;
|
|
|
|
class WebGLTransformFeedback;
|
|
|
|
class WebGLVertexArray;
|
2020-01-09 01:19:16 +03:00
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
class VRefCounted : public RefCounted<VRefCounted> {
|
|
|
|
public:
|
|
|
|
virtual ~VRefCounted() = default;
|
|
|
|
|
|
|
|
#ifdef MOZ_REFCOUNTED_LEAK_CHECKING
|
|
|
|
virtual const char* typeName() const = 0;
|
|
|
|
virtual size_t typeSize() const = 0;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2013-10-11 17:16:43 +04:00
|
|
|
/*
|
|
|
|
* Implementing WebGL (or OpenGL ES 2.0) on top of desktop OpenGL requires
|
|
|
|
* emulating the vertex attrib 0 array when it's not enabled. Indeed,
|
|
|
|
* OpenGL ES 2.0 allows drawing without vertex attrib 0 array enabled, but
|
|
|
|
* desktop OpenGL does not allow that.
|
|
|
|
*/
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLVertexAttrib0Status : uint8_t {
|
2013-10-11 17:16:43 +04:00
|
|
|
Default, // default status - no emulation needed
|
|
|
|
EmulatedUninitializedArray, // need an artificial attrib 0 array, but
|
|
|
|
// contents may be left uninitialized
|
|
|
|
EmulatedInitializedArray // need an artificial attrib 0 array, and contents
|
|
|
|
// must be initialized
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-06-11 00:00:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The formats that may participate, either as source or destination formats,
|
|
|
|
* in WebGL texture conversions. This includes:
|
|
|
|
* - all the formats accepted by WebGL.texImage2D, e.g. RGBA4444
|
|
|
|
* - additional formats provided by extensions, e.g. RGB32F
|
|
|
|
* - additional source formats, depending on browser details, used when
|
|
|
|
* uploading textures from DOM elements. See gfxImageSurface::Format().
|
|
|
|
*/
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexelFormat : uint8_t {
|
2013-11-24 06:20:48 +04:00
|
|
|
// returned by SurfaceFromElementResultToImageSurface to indicate absence of
|
|
|
|
// image data
|
|
|
|
None,
|
2014-10-10 00:07:07 +04:00
|
|
|
// common value for formats for which format conversions are not supported
|
|
|
|
FormatNotSupportingAnyConversion,
|
2013-06-11 00:00:35 +04:00
|
|
|
// dummy pseudo-format meaning "use the other format".
|
|
|
|
// For example, if SrcFormat=Auto and DstFormat=RGB8, then the source
|
|
|
|
// is implicitly treated as being RGB8 itself.
|
|
|
|
Auto,
|
|
|
|
// 1-channel formats
|
|
|
|
A8,
|
2014-01-24 01:47:37 +04:00
|
|
|
A16F, // OES_texture_half_float
|
|
|
|
A32F, // OES_texture_float
|
2015-12-22 21:59:00 +03:00
|
|
|
R8,
|
|
|
|
R16F, // OES_texture_half_float
|
|
|
|
R32F, // OES_texture_float
|
2013-06-11 00:00:35 +04:00
|
|
|
// 2-channel formats
|
|
|
|
RA8,
|
2014-01-24 01:47:37 +04:00
|
|
|
RA16F, // OES_texture_half_float
|
|
|
|
RA32F, // OES_texture_float
|
2015-12-22 23:56:00 +03:00
|
|
|
RG8,
|
2015-12-22 23:57:00 +03:00
|
|
|
RG16F,
|
2015-12-23 00:01:00 +03:00
|
|
|
RG32F,
|
2013-06-11 00:00:35 +04:00
|
|
|
// 3-channel formats
|
|
|
|
RGB8,
|
|
|
|
RGB565,
|
2015-12-23 00:02:00 +03:00
|
|
|
RGB11F11F10F,
|
2014-01-24 01:47:37 +04:00
|
|
|
RGB16F, // OES_texture_half_float
|
|
|
|
RGB32F, // OES_texture_float
|
2013-06-11 00:00:35 +04:00
|
|
|
// 4-channel formats
|
|
|
|
RGBA8,
|
|
|
|
RGBA5551,
|
|
|
|
RGBA4444,
|
2014-01-24 01:47:37 +04:00
|
|
|
RGBA16F, // OES_texture_half_float
|
2015-12-22 21:59:00 +03:00
|
|
|
RGBA32F, // OES_texture_float
|
|
|
|
// DOM element source only formats.
|
|
|
|
RGBX8,
|
|
|
|
BGRX8,
|
|
|
|
BGRA8
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2013-06-11 00:00:35 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexImageFunc : uint8_t {
|
2014-02-21 05:20:28 +04:00
|
|
|
TexImage,
|
|
|
|
TexSubImage,
|
|
|
|
CopyTexImage,
|
|
|
|
CopyTexSubImage,
|
|
|
|
CompTexImage,
|
|
|
|
CompTexSubImage,
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-02-21 05:20:28 +04:00
|
|
|
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLTexDimensions : uint8_t { Tex2D, Tex3D };
|
2014-10-14 03:42:15 +04:00
|
|
|
|
2014-04-26 06:34:07 +04:00
|
|
|
// Please keep extensions in alphabetic order.
|
2015-01-26 01:22:07 +03:00
|
|
|
enum class WebGLExtensionID : uint8_t {
|
2014-04-26 06:34:07 +04:00
|
|
|
ANGLE_instanced_arrays,
|
2014-06-14 20:07:53 +04:00
|
|
|
EXT_blend_minmax,
|
2016-05-05 02:39:02 +03:00
|
|
|
EXT_color_buffer_float,
|
2014-04-26 06:34:07 +04:00
|
|
|
EXT_color_buffer_half_float,
|
2019-02-01 02:39:12 +03:00
|
|
|
EXT_disjoint_timer_query,
|
|
|
|
EXT_float_blend,
|
2014-04-26 06:34:07 +04:00
|
|
|
EXT_frag_depth,
|
2014-07-24 19:58:43 +04:00
|
|
|
EXT_shader_texture_lod,
|
2019-02-01 02:39:12 +03:00
|
|
|
EXT_sRGB,
|
|
|
|
EXT_texture_compression_bptc,
|
|
|
|
EXT_texture_compression_rgtc,
|
2014-04-26 06:34:07 +04:00
|
|
|
EXT_texture_filter_anisotropic,
|
2020-08-12 18:19:17 +03:00
|
|
|
EXT_texture_norm16,
|
2017-04-11 11:50:59 +03:00
|
|
|
MOZ_debug,
|
2014-04-26 06:34:07 +04:00
|
|
|
OES_element_index_uint,
|
2019-02-22 22:25:20 +03:00
|
|
|
OES_fbo_render_mipmap,
|
2014-04-26 06:34:07 +04:00
|
|
|
OES_standard_derivatives,
|
|
|
|
OES_texture_float,
|
|
|
|
OES_texture_float_linear,
|
|
|
|
OES_texture_half_float,
|
|
|
|
OES_texture_half_float_linear,
|
|
|
|
OES_vertex_array_object,
|
2019-05-23 23:48:21 +03:00
|
|
|
OVR_multiview2,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_color_buffer_float,
|
2016-11-23 05:59:35 +03:00
|
|
|
WEBGL_compressed_texture_astc,
|
2016-11-11 03:37:03 +03:00
|
|
|
WEBGL_compressed_texture_etc,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_compressed_texture_etc1,
|
|
|
|
WEBGL_compressed_texture_pvrtc,
|
|
|
|
WEBGL_compressed_texture_s3tc,
|
2017-05-30 18:21:33 +03:00
|
|
|
WEBGL_compressed_texture_s3tc_srgb,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_debug_renderer_info,
|
|
|
|
WEBGL_debug_shaders,
|
|
|
|
WEBGL_depth_texture,
|
|
|
|
WEBGL_draw_buffers,
|
2019-06-25 22:48:24 +03:00
|
|
|
WEBGL_explicit_present,
|
2014-04-26 06:34:07 +04:00
|
|
|
WEBGL_lose_context,
|
2019-02-05 06:34:49 +03:00
|
|
|
Max
|
2015-01-26 01:22:07 +03:00
|
|
|
};
|
2014-04-26 06:34:07 +04:00
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
class UniqueBuffer {
|
|
|
|
// Like UniquePtr<>, but for void* and malloc/calloc/free.
|
|
|
|
void* mBuffer;
|
|
|
|
|
|
|
|
public:
|
2020-07-22 01:56:52 +03:00
|
|
|
static inline UniqueBuffer Alloc(const size_t byteSize) {
|
|
|
|
return {malloc(byteSize)};
|
|
|
|
}
|
|
|
|
|
2017-02-10 07:32:58 +03:00
|
|
|
UniqueBuffer() : mBuffer(nullptr) {}
|
|
|
|
|
|
|
|
MOZ_IMPLICIT UniqueBuffer(void* buffer) : mBuffer(buffer) {}
|
|
|
|
|
|
|
|
~UniqueBuffer() { free(mBuffer); }
|
|
|
|
|
|
|
|
UniqueBuffer(UniqueBuffer&& other) {
|
|
|
|
this->mBuffer = other.mBuffer;
|
|
|
|
other.mBuffer = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniqueBuffer& operator=(UniqueBuffer&& other) {
|
|
|
|
free(this->mBuffer);
|
|
|
|
this->mBuffer = other.mBuffer;
|
|
|
|
other.mBuffer = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
UniqueBuffer& operator=(void* newBuffer) {
|
|
|
|
free(this->mBuffer);
|
|
|
|
this->mBuffer = newBuffer;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit operator bool() const { return bool(mBuffer); }
|
|
|
|
|
|
|
|
void* get() const { return mBuffer; }
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
explicit UniqueBuffer(const UniqueBuffer& other) =
|
2018-05-30 22:15:35 +03:00
|
|
|
delete; // construct using std::move()!
|
2020-07-22 01:57:01 +03:00
|
|
|
UniqueBuffer& operator=(const UniqueBuffer& other) =
|
2018-05-30 22:15:35 +03:00
|
|
|
delete; // assign using std::move()!
|
2017-02-10 07:32:58 +03:00
|
|
|
};
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
namespace webgl {
|
|
|
|
struct FormatUsageInfo;
|
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
static constexpr GLenum kErrorPerfWarning = 0x10001;
|
|
|
|
|
2018-10-17 07:18:15 +03:00
|
|
|
struct SampleableInfo final {
|
|
|
|
const char* incompleteReason = nullptr;
|
|
|
|
uint32_t levels = 0;
|
|
|
|
const webgl::FormatUsageInfo* usage = nullptr;
|
|
|
|
bool isDepthTexCompare = false;
|
|
|
|
|
|
|
|
bool IsComplete() const { return bool(levels); }
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class AttribBaseType : uint8_t {
|
2018-11-10 00:38:31 +03:00
|
|
|
Boolean, // Can convert from anything.
|
2020-01-09 01:19:16 +03:00
|
|
|
Float, // Also includes NormU?Int
|
|
|
|
Int,
|
|
|
|
Uint,
|
2018-10-17 07:18:15 +03:00
|
|
|
};
|
2020-01-09 01:19:16 +03:00
|
|
|
webgl::AttribBaseType ToAttribBaseType(GLenum);
|
2018-10-17 07:18:15 +03:00
|
|
|
const char* ToString(AttribBaseType);
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
enum class UniformBaseType : uint8_t {
|
|
|
|
Float,
|
|
|
|
Int,
|
|
|
|
Uint,
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
2020-01-09 01:19:16 +03:00
|
|
|
const char* ToString(UniformBaseType);
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
typedef uint64_t ObjectId;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
enum class BufferKind : uint8_t {
|
|
|
|
Undefined,
|
|
|
|
Index,
|
|
|
|
NonIndex,
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
} // namespace webgl
|
|
|
|
|
|
|
|
// -
|
2020-01-09 01:19:14 +03:00
|
|
|
|
|
|
|
struct FloatOrInt final // For TexParameter[fi] and friends.
|
|
|
|
{
|
|
|
|
const bool isFloat;
|
|
|
|
const GLfloat f;
|
|
|
|
const GLint i;
|
|
|
|
|
|
|
|
explicit FloatOrInt(GLint x = 0) : isFloat(false), f(x), i(x) {}
|
|
|
|
|
|
|
|
explicit FloatOrInt(GLfloat x) : isFloat(true), f(x), i(roundf(x)) {}
|
|
|
|
|
|
|
|
FloatOrInt& operator=(const FloatOrInt& x) {
|
|
|
|
memcpy(this, &x, sizeof(x));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using WebGLTexUnpackVariant =
|
|
|
|
Variant<UniquePtr<webgl::TexUnpackBytes>,
|
|
|
|
UniquePtr<webgl::TexUnpackSurface>,
|
|
|
|
UniquePtr<webgl::TexUnpackImage>, WebGLTexPboOffset>;
|
|
|
|
|
|
|
|
using MaybeWebGLTexUnpackVariant = Maybe<WebGLTexUnpackVariant>;
|
|
|
|
|
|
|
|
struct WebGLContextOptions {
|
|
|
|
bool alpha = true;
|
|
|
|
bool depth = true;
|
|
|
|
bool stencil = false;
|
|
|
|
bool premultipliedAlpha = true;
|
|
|
|
bool antialias = true;
|
|
|
|
bool preserveDrawingBuffer = false;
|
|
|
|
bool failIfMajorPerformanceCaveat = false;
|
|
|
|
bool xrCompatible = false;
|
|
|
|
dom::WebGLPowerPreference powerPreference =
|
|
|
|
dom::WebGLPowerPreference::Default;
|
|
|
|
bool shouldResistFingerprinting = true;
|
|
|
|
bool enableDebugRendererInfo = false;
|
|
|
|
|
|
|
|
WebGLContextOptions();
|
2020-01-09 01:19:16 +03:00
|
|
|
WebGLContextOptions(const WebGLContextOptions&) = default;
|
|
|
|
|
2020-01-09 01:19:14 +03:00
|
|
|
bool operator==(const WebGLContextOptions&) const;
|
2020-01-09 01:19:16 +03:00
|
|
|
bool operator!=(const WebGLContextOptions& rhs) const {
|
|
|
|
return !(*this == rhs);
|
|
|
|
}
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
|
|
|
|
2020-11-23 22:54:41 +03:00
|
|
|
template <typename _T>
|
2020-01-09 01:19:16 +03:00
|
|
|
struct avec2 {
|
2020-11-23 22:54:41 +03:00
|
|
|
using T = _T;
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
T x = T();
|
|
|
|
T y = T();
|
|
|
|
|
|
|
|
template <typename U, typename V>
|
|
|
|
static Maybe<avec2> From(const U _x, const V _y) {
|
|
|
|
const auto x = CheckedInt<T>(_x);
|
|
|
|
const auto y = CheckedInt<T>(_y);
|
|
|
|
if (!x.isValid() || !y.isValid()) return {};
|
|
|
|
return Some(avec2(x.value(), y.value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
static auto From(const U& val) {
|
|
|
|
return From(val.x, val.y);
|
|
|
|
}
|
2020-01-09 01:19:26 +03:00
|
|
|
template <typename U>
|
|
|
|
static auto FromSize(const U& val) {
|
2020-01-09 01:19:16 +03:00
|
|
|
return From(val.width, val.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
avec2() = default;
|
|
|
|
avec2(const T _x, const T _y) : x(_x), y(_y) {}
|
|
|
|
|
|
|
|
bool operator==(const avec2& rhs) const { return x == rhs.x && y == rhs.y; }
|
|
|
|
bool operator!=(const avec2& rhs) const { return !(*this == rhs); }
|
2020-11-23 22:54:41 +03:00
|
|
|
|
|
|
|
#define _(OP) \
|
|
|
|
avec2 operator OP(const avec2& rhs) const { \
|
|
|
|
return {x OP rhs.x, y OP rhs.y}; \
|
|
|
|
} \
|
|
|
|
avec2 operator OP(const T rhs) const { return {x OP rhs, y OP rhs}; }
|
|
|
|
|
|
|
|
_(+)
|
|
|
|
_(-)
|
|
|
|
_(*)
|
|
|
|
_(/)
|
|
|
|
|
|
|
|
#undef _
|
|
|
|
|
|
|
|
avec2 Clamp(const avec2& min, const avec2& max) const {
|
|
|
|
return {mozilla::Clamp(x, min.x, max.x), mozilla::Clamp(y, min.y, max.y)};
|
|
|
|
}
|
|
|
|
|
|
|
|
// mozilla::Clamp doesn't work on floats, so be clear that this is a min+max
|
|
|
|
// helper.
|
|
|
|
avec2 ClampMinMax(const avec2& min, const avec2& max) const {
|
|
|
|
const auto ClampScalar = [](const T v, const T min, const T max) {
|
|
|
|
return std::max(min, std::min(v, max));
|
|
|
|
};
|
|
|
|
return {ClampScalar(x, min.x, max.x), ClampScalar(y, min.y, max.y)};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
U StaticCast() const {
|
|
|
|
return {static_cast<typename U::T>(x), static_cast<typename U::T>(y)};
|
|
|
|
}
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2020-12-07 13:17:57 +03:00
|
|
|
template <typename T>
|
2020-11-23 22:54:41 +03:00
|
|
|
avec2<T> MinExtents(const avec2<T>& a, const avec2<T>& b) {
|
|
|
|
return {std::min(a.x, b.x), std::min(a.y, b.y)};
|
|
|
|
}
|
|
|
|
|
2020-12-07 13:17:57 +03:00
|
|
|
template <typename T>
|
2020-11-23 22:54:41 +03:00
|
|
|
avec2<T> MaxExtents(const avec2<T>& a, const avec2<T>& b) {
|
|
|
|
return {std::max(a.x, b.x), std::max(a.y, b.y)};
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
template <typename _T>
|
2020-01-09 01:19:16 +03:00
|
|
|
struct avec3 {
|
2020-11-23 22:54:41 +03:00
|
|
|
using T = _T;
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
T x = T();
|
|
|
|
T y = T();
|
|
|
|
T z = T();
|
|
|
|
|
|
|
|
template <typename U, typename V>
|
|
|
|
static Maybe<avec3> From(const U _x, const V _y, const V _z) {
|
|
|
|
const auto x = CheckedInt<T>(_x);
|
|
|
|
const auto y = CheckedInt<T>(_y);
|
|
|
|
const auto z = CheckedInt<T>(_z);
|
|
|
|
if (!x.isValid() || !y.isValid() || !z.isValid()) return {};
|
|
|
|
return Some(avec3(x.value(), y.value(), z.value()));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename U>
|
|
|
|
static auto From(const U& val) {
|
|
|
|
return From(val.x, val.y, val.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
avec3() = default;
|
|
|
|
avec3(const T _x, const T _y, const T _z) : x(_x), y(_y), z(_z) {}
|
|
|
|
|
|
|
|
bool operator==(const avec3& rhs) const {
|
|
|
|
return x == rhs.x && y == rhs.y && z == rhs.z;
|
|
|
|
}
|
|
|
|
bool operator!=(const avec3& rhs) const { return !(*this == rhs); }
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
typedef avec2<int32_t> ivec2;
|
|
|
|
typedef avec3<int32_t> ivec3;
|
|
|
|
typedef avec2<uint32_t> uvec2;
|
|
|
|
typedef avec3<uint32_t> uvec3;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-11-23 22:54:41 +03:00
|
|
|
inline ivec2 AsVec(const gfx::IntSize& s) { return {s.width, s.height}; }
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
namespace webgl {
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-02-21 06:12:41 +03:00
|
|
|
struct PackingInfo final {
|
|
|
|
GLenum format = 0;
|
|
|
|
GLenum type = 0;
|
|
|
|
|
|
|
|
bool operator<(const PackingInfo& x) const {
|
|
|
|
if (format != x.format) return format < x.format;
|
|
|
|
|
|
|
|
return type < x.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const PackingInfo& x) const {
|
|
|
|
return (format == x.format && type == x.type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DriverUnpackInfo final {
|
|
|
|
GLenum internalFormat = 0;
|
|
|
|
GLenum unpackFormat = 0;
|
|
|
|
GLenum unpackType = 0;
|
|
|
|
|
|
|
|
PackingInfo ToPacking() const { return {unpackFormat, unpackType}; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PixelPackState final {
|
|
|
|
uint32_t alignment = 4;
|
|
|
|
uint32_t rowLength = 0;
|
|
|
|
uint32_t skipRows = 0;
|
|
|
|
uint32_t skipPixels = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReadPixelsDesc final {
|
|
|
|
ivec2 srcOffset;
|
|
|
|
uvec2 size;
|
|
|
|
PackingInfo pi = {LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE};
|
|
|
|
PixelPackState packState;
|
|
|
|
};
|
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
template <typename E>
|
|
|
|
class EnumMask {
|
|
|
|
public:
|
2020-01-09 01:19:16 +03:00
|
|
|
uint64_t mBits = 0;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
private:
|
2020-01-09 01:19:16 +03:00
|
|
|
struct BitRef final {
|
2021-01-14 04:23:06 +03:00
|
|
|
EnumMask& bits;
|
2020-01-09 01:19:16 +03:00
|
|
|
const uint64_t mask;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
explicit operator bool() const { return bits.mBits & mask; }
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
auto& operator=(const bool val) {
|
|
|
|
if (val) {
|
|
|
|
bits.mBits |= mask;
|
|
|
|
} else {
|
|
|
|
bits.mBits &= ~mask;
|
|
|
|
}
|
|
|
|
return *this;
|
2020-01-09 01:19:14 +03:00
|
|
|
}
|
2020-01-09 01:19:16 +03:00
|
|
|
};
|
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
uint64_t Mask(const E i) const {
|
2020-01-09 01:19:16 +03:00
|
|
|
return uint64_t{1} << static_cast<uint64_t>(i);
|
2020-01-09 01:19:14 +03:00
|
|
|
}
|
2020-01-09 01:19:16 +03:00
|
|
|
|
|
|
|
public:
|
2021-01-14 04:23:06 +03:00
|
|
|
BitRef operator[](const E i) { return {*this, Mask(i)}; }
|
|
|
|
bool operator[](const E i) const { return mBits & Mask(i); }
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
class ExtensionBits : public EnumMask<WebGLExtensionID> {};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
enum class ContextLossReason : uint8_t {
|
|
|
|
None,
|
|
|
|
Manual,
|
|
|
|
Guilty,
|
|
|
|
};
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
inline bool ReadContextLossReason(const uint8_t val,
|
|
|
|
ContextLossReason* const out) {
|
|
|
|
if (val > static_cast<uint8_t>(ContextLossReason::Guilty)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*out = static_cast<ContextLossReason>(val);
|
|
|
|
return true;
|
2020-01-09 01:19:14 +03:00
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
struct InitContextDesc final {
|
|
|
|
bool isWebgl2 = false;
|
|
|
|
bool resistFingerprinting = false;
|
|
|
|
uvec2 size = {};
|
|
|
|
WebGLContextOptions options;
|
2020-01-09 01:19:23 +03:00
|
|
|
uint32_t principalKey = 0;
|
2020-01-09 01:19:16 +03:00
|
|
|
};
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2021-06-15 00:27:08 +03:00
|
|
|
constexpr uint32_t kMaxTransformFeedbackSeparateAttribs = 4;
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
struct Limits final {
|
|
|
|
ExtensionBits supportedExtensions;
|
|
|
|
|
|
|
|
// WebGL 1
|
|
|
|
uint32_t maxTexUnits = 0;
|
|
|
|
uint32_t maxTex2dSize = 0;
|
|
|
|
uint32_t maxTexCubeSize = 0;
|
|
|
|
uint32_t maxVertexAttribs = 0;
|
2021-06-15 00:27:08 +03:00
|
|
|
uint32_t maxViewportDim = 0;
|
2020-01-09 01:19:26 +03:00
|
|
|
std::array<float, 2> pointSizeRange = {{1, 1}};
|
|
|
|
std::array<float, 2> lineWidthRange = {{1, 1}};
|
2020-01-09 01:19:16 +03:00
|
|
|
|
|
|
|
// WebGL 2
|
|
|
|
uint32_t maxTexArrayLayers = 0;
|
|
|
|
uint32_t maxTex3dSize = 0;
|
|
|
|
uint32_t maxUniformBufferBindings = 0;
|
|
|
|
uint32_t uniformBufferOffsetAlignment = 0;
|
|
|
|
|
|
|
|
// Exts
|
|
|
|
bool astcHdr = false;
|
|
|
|
uint32_t maxColorDrawBuffers = 1;
|
|
|
|
uint64_t queryCounterBitsTimeElapsed = 0;
|
|
|
|
uint64_t queryCounterBitsTimestamp = 0;
|
|
|
|
uint32_t maxMultiviewLayers = 0;
|
|
|
|
};
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
struct InitContextResult final {
|
|
|
|
std::string error;
|
|
|
|
WebGLContextOptions options;
|
|
|
|
webgl::Limits limits;
|
2021-01-14 04:23:06 +03:00
|
|
|
EnumMask<layers::SurfaceDescriptor::Type> uploadableSdTypes;
|
2020-01-09 01:19:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
struct ErrorInfo final {
|
|
|
|
GLenum type;
|
|
|
|
std::string info;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderPrecisionFormat final {
|
|
|
|
GLint rangeMin = 0;
|
|
|
|
GLint rangeMax = 0;
|
|
|
|
GLint precision = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
enum class LossStatus {
|
|
|
|
Ready,
|
|
|
|
|
|
|
|
Lost,
|
|
|
|
LostForever,
|
|
|
|
LostManually,
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
struct CompileResult final {
|
|
|
|
bool pending = true;
|
2020-07-22 01:56:52 +03:00
|
|
|
nsCString log;
|
|
|
|
nsCString translatedSource;
|
2020-01-09 01:19:16 +03:00
|
|
|
bool success = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
struct OpaqueFramebufferOptions final {
|
2020-04-07 21:48:13 +03:00
|
|
|
bool depthStencil = true;
|
|
|
|
bool antialias = true;
|
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
struct ActiveInfo {
|
|
|
|
GLenum elemType = 0; // `type`
|
|
|
|
uint32_t elemCount = 0; // `size`
|
|
|
|
std::string name;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ActiveAttribInfo final : public ActiveInfo {
|
|
|
|
int32_t location = -1;
|
2020-02-26 03:44:26 +03:00
|
|
|
AttribBaseType baseType = AttribBaseType::Float;
|
2020-01-09 01:19:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ActiveUniformInfo final : public ActiveInfo {
|
|
|
|
std::unordered_map<uint32_t, uint32_t>
|
|
|
|
locByIndex; // Uniform array locations are sparse.
|
|
|
|
int32_t block_index = -1;
|
|
|
|
int32_t block_offset = -1; // In block, offset.
|
|
|
|
int32_t block_arrayStride = -1;
|
|
|
|
int32_t block_matrixStride = -1;
|
|
|
|
bool block_isRowMajor = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ActiveUniformBlockInfo final {
|
|
|
|
std::string name;
|
|
|
|
// BLOCK_BINDING is dynamic state
|
|
|
|
uint32_t dataSize = 0;
|
|
|
|
std::vector<uint32_t> activeUniformIndices;
|
|
|
|
bool referencedByVertexShader = false;
|
|
|
|
bool referencedByFragmentShader = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkActiveInfo final {
|
|
|
|
std::vector<ActiveAttribInfo> activeAttribs;
|
|
|
|
std::vector<ActiveUniformInfo> activeUniforms;
|
|
|
|
std::vector<ActiveUniformBlockInfo> activeUniformBlocks;
|
|
|
|
std::vector<ActiveInfo> activeTfVaryings;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinkResult final {
|
|
|
|
bool pending = true;
|
2020-07-22 01:56:52 +03:00
|
|
|
nsCString log;
|
2020-01-09 01:19:16 +03:00
|
|
|
bool success = false;
|
|
|
|
LinkActiveInfo active;
|
|
|
|
GLenum tfBufferMode = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
/// 4x32-bit primitives, with a type tag.
|
|
|
|
struct TypedQuad final {
|
|
|
|
alignas(alignof(float)) uint8_t data[4 * sizeof(float)] = {};
|
|
|
|
webgl::AttribBaseType type = webgl::AttribBaseType::Float;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// [1-16]x32-bit primitives, with a type tag.
|
|
|
|
struct GetUniformData final {
|
|
|
|
alignas(alignof(float)) uint8_t data[4 * 4 * sizeof(float)] = {};
|
|
|
|
GLenum type = 0;
|
|
|
|
};
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
struct FrontBufferSnapshotIpc final {
|
|
|
|
uvec2 surfSize = {};
|
2020-07-22 01:57:01 +03:00
|
|
|
mozilla::ipc::Shmem shmem = {};
|
2020-07-22 01:56:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ReadPixelsResult {
|
|
|
|
gfx::IntRect subrect = {};
|
|
|
|
size_t byteStride = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReadPixelsResultIpc final : public ReadPixelsResult {
|
|
|
|
mozilla::ipc::Shmem shmem = {};
|
|
|
|
};
|
|
|
|
|
2020-02-26 03:44:26 +03:00
|
|
|
struct VertAttribPointerDesc final {
|
|
|
|
bool intFunc = false;
|
|
|
|
uint8_t channels = 4;
|
|
|
|
bool normalized = false;
|
|
|
|
uint8_t byteStrideOrZero = 0;
|
|
|
|
GLenum type = LOCAL_GL_FLOAT;
|
|
|
|
uint64_t byteOffset = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct VertAttribPointerCalculated final {
|
|
|
|
uint8_t byteSize = 4 * 4;
|
|
|
|
uint8_t byteStride = 4 * 4; // at-most 255
|
|
|
|
webgl::AttribBaseType baseType = webgl::AttribBaseType::Float;
|
|
|
|
};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
} // namespace webgl
|
|
|
|
|
|
|
|
// return value for the InitializeCanvasRenderer message
|
|
|
|
struct ICRData {
|
|
|
|
gfx::IntSize size;
|
|
|
|
bool hasAlpha;
|
|
|
|
bool isPremultAlpha;
|
|
|
|
};
|
2020-01-09 01:19:14 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a block of memory that it may or may not own. The
|
2020-07-22 01:56:52 +03:00
|
|
|
* inner data type must be trivially copyable by memcpy.
|
2020-01-09 01:19:14 +03:00
|
|
|
*/
|
2020-07-22 01:56:52 +03:00
|
|
|
template <typename T = uint8_t>
|
2020-07-22 01:57:01 +03:00
|
|
|
class RawBuffer final {
|
2020-07-22 01:56:52 +03:00
|
|
|
const T* mBegin = nullptr;
|
|
|
|
size_t mLen = 0;
|
|
|
|
UniqueBuffer mOwned;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
using ElementType = T;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If aTakeData is true, RawBuffer will delete[] the memory when destroyed.
|
|
|
|
*/
|
2020-07-22 01:56:52 +03:00
|
|
|
explicit RawBuffer(const Range<const T>& data, UniqueBuffer&& owned = {})
|
|
|
|
: mBegin(data.begin().get()),
|
|
|
|
mLen(data.length()),
|
|
|
|
mOwned(std::move(owned)) {}
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-08-20 03:33:52 +03:00
|
|
|
explicit RawBuffer(const size_t len) : mLen(len) {}
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
~RawBuffer() = default;
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
Range<const T> Data() const { return {mBegin, mLen}; }
|
2020-08-20 03:33:52 +03:00
|
|
|
const auto& begin() const { return mBegin; }
|
|
|
|
const auto& size() const { return mLen; }
|
2020-01-09 01:19:14 +03:00
|
|
|
|
2020-11-14 02:24:13 +03:00
|
|
|
void Shrink(const size_t newLen) {
|
|
|
|
if (mLen <= newLen) return;
|
|
|
|
mLen = newLen;
|
|
|
|
}
|
|
|
|
|
2020-02-19 00:08:00 +03:00
|
|
|
RawBuffer() = default;
|
2020-07-22 01:56:52 +03:00
|
|
|
|
2020-01-09 01:19:14 +03:00
|
|
|
RawBuffer(const RawBuffer&) = delete;
|
|
|
|
RawBuffer& operator=(const RawBuffer&) = delete;
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
RawBuffer(RawBuffer&&) = default;
|
|
|
|
RawBuffer& operator=(RawBuffer&&) = default;
|
2020-01-09 01:19:14 +03:00
|
|
|
};
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
struct CopyableRange final : public Range<const uint8_t> {};
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// clang-format off
|
|
|
|
|
|
|
|
#define FOREACH_ID(X) \
|
|
|
|
X(FuncScopeIdError) \
|
|
|
|
X(compressedTexImage2D) \
|
|
|
|
X(compressedTexImage3D) \
|
|
|
|
X(compressedTexSubImage2D) \
|
|
|
|
X(compressedTexSubImage3D) \
|
|
|
|
X(copyTexSubImage2D) \
|
|
|
|
X(copyTexSubImage3D) \
|
|
|
|
X(drawArrays) \
|
|
|
|
X(drawArraysInstanced) \
|
|
|
|
X(drawElements) \
|
|
|
|
X(drawElementsInstanced) \
|
|
|
|
X(drawRangeElements) \
|
|
|
|
X(renderbufferStorage) \
|
|
|
|
X(renderbufferStorageMultisample) \
|
|
|
|
X(texImage2D) \
|
|
|
|
X(texImage3D) \
|
|
|
|
X(TexStorage2D) \
|
|
|
|
X(TexStorage3D) \
|
|
|
|
X(texSubImage2D) \
|
|
|
|
X(texSubImage3D) \
|
|
|
|
X(vertexAttrib1f) \
|
|
|
|
X(vertexAttrib1fv) \
|
|
|
|
X(vertexAttrib2f) \
|
|
|
|
X(vertexAttrib2fv) \
|
|
|
|
X(vertexAttrib3f) \
|
|
|
|
X(vertexAttrib3fv) \
|
|
|
|
X(vertexAttrib4f) \
|
|
|
|
X(vertexAttrib4fv) \
|
|
|
|
X(vertexAttribI4i) \
|
|
|
|
X(vertexAttribI4iv) \
|
|
|
|
X(vertexAttribI4ui) \
|
|
|
|
X(vertexAttribI4uiv) \
|
|
|
|
X(vertexAttribIPointer) \
|
|
|
|
X(vertexAttribPointer)
|
|
|
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
enum class FuncScopeId {
|
|
|
|
#define _(X) X,
|
|
|
|
FOREACH_ID(_)
|
|
|
|
#undef _
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr const char* const FUNCSCOPE_NAME_BY_ID[] = {
|
|
|
|
#define _(X) #X,
|
|
|
|
FOREACH_ID(_)
|
|
|
|
#undef _
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef FOREACH_ID
|
|
|
|
|
|
|
|
inline auto GetFuncScopeName(const FuncScopeId id) {
|
|
|
|
return FUNCSCOPE_NAME_BY_ID[static_cast<size_t>(id)];
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
template <typename C, typename K>
|
|
|
|
inline auto MaybeFind(C& container, const K& key)
|
|
|
|
-> decltype(&(container.find(key)->second)) {
|
|
|
|
const auto itr = container.find(key);
|
|
|
|
if (itr == container.end()) return nullptr;
|
|
|
|
return &(itr->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename C, typename K>
|
|
|
|
inline typename C::mapped_type Find(
|
|
|
|
const C& container, const K& key,
|
|
|
|
const typename C::mapped_type notFound = {}) {
|
|
|
|
const auto itr = container.find(key);
|
|
|
|
if (itr == container.end()) return notFound;
|
|
|
|
return itr->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2020-02-26 03:44:26 +03:00
|
|
|
template <typename T, typename U>
|
|
|
|
inline Maybe<T> MaybeAs(const U val) {
|
|
|
|
const auto checked = CheckedInt<T>(val);
|
|
|
|
if (!checked.isValid()) return {};
|
|
|
|
return Some(checked.value());
|
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
inline GLenum ImageToTexTarget(const GLenum imageTarget) {
|
|
|
|
switch (imageTarget) {
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_X:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
|
|
|
|
case LOCAL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
|
|
|
|
return LOCAL_GL_TEXTURE_CUBE_MAP;
|
|
|
|
default:
|
|
|
|
return imageTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
inline bool IsTexTarget3D(const GLenum texTarget) {
|
|
|
|
switch (texTarget) {
|
|
|
|
case LOCAL_GL_TEXTURE_2D_ARRAY:
|
|
|
|
case LOCAL_GL_TEXTURE_3D:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
namespace dom {
|
2020-02-11 04:23:37 +03:00
|
|
|
class Element;
|
2020-01-09 01:19:16 +03:00
|
|
|
class ImageBitmap;
|
|
|
|
class ImageData;
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
struct TexImageSource {
|
|
|
|
const dom::ArrayBufferView* mView = nullptr;
|
|
|
|
GLuint mViewElemOffset = 0;
|
|
|
|
GLuint mViewElemLengthOverride = 0;
|
|
|
|
|
|
|
|
const WebGLintptr* mPboOffset = nullptr;
|
|
|
|
|
|
|
|
const dom::ImageBitmap* mImageBitmap = nullptr;
|
|
|
|
const dom::ImageData* mImageData = nullptr;
|
|
|
|
|
|
|
|
const dom::Element* mDomElem = nullptr;
|
|
|
|
ErrorResult* mOut_error = nullptr;
|
|
|
|
};
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
struct WebGLPixelStore final {
|
|
|
|
uint32_t mUnpackImageHeight = 0;
|
|
|
|
uint32_t mUnpackSkipImages = 0;
|
|
|
|
uint32_t mUnpackRowLength = 0;
|
|
|
|
uint32_t mUnpackSkipRows = 0;
|
|
|
|
uint32_t mUnpackSkipPixels = 0;
|
|
|
|
uint32_t mUnpackAlignment = 4;
|
|
|
|
GLenum mColorspaceConversion =
|
|
|
|
dom::WebGLRenderingContext_Binding::BROWSER_DEFAULT_WEBGL;
|
|
|
|
bool mFlipY = false;
|
|
|
|
bool mPremultiplyAlpha = false;
|
|
|
|
bool mRequireFastPath = false;
|
2020-01-09 01:19:16 +03:00
|
|
|
|
2020-08-23 09:09:33 +03:00
|
|
|
static void AssertDefault(gl::GLContext& gl, const bool isWebgl2) {
|
|
|
|
WebGLPixelStore expected;
|
|
|
|
MOZ_ASSERT(expected.AssertCurrent(gl, isWebgl2));
|
|
|
|
Unused << expected;
|
|
|
|
}
|
|
|
|
|
2020-07-22 01:57:01 +03:00
|
|
|
void Apply(gl::GLContext&, bool isWebgl2, const uvec3& uploadSize) const;
|
2020-08-23 09:09:33 +03:00
|
|
|
bool AssertCurrent(gl::GLContext&, bool isWebgl2) const;
|
2020-07-22 01:56:52 +03:00
|
|
|
|
2021-01-14 04:23:06 +03:00
|
|
|
WebGLPixelStore ForUseWith(const GLenum target, const uvec3& uploadSize,
|
|
|
|
const Maybe<uvec2>& structuredSrcSize) const {
|
2020-07-22 01:57:01 +03:00
|
|
|
auto ret = *this;
|
|
|
|
|
|
|
|
if (!IsTexTarget3D(target)) {
|
|
|
|
ret.mUnpackSkipImages = 0;
|
|
|
|
ret.mUnpackImageHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (structuredSrcSize) {
|
2021-01-14 04:23:06 +03:00
|
|
|
ret.mUnpackRowLength = structuredSrcSize->x;
|
2020-07-22 01:57:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret.mUnpackRowLength) {
|
|
|
|
ret.mUnpackRowLength = uploadSize.x;
|
|
|
|
}
|
|
|
|
if (!ret.mUnpackImageHeight) {
|
|
|
|
ret.mUnpackImageHeight = uploadSize.y;
|
2020-11-14 02:24:13 +03:00
|
|
|
|
|
|
|
if (!IsTexTarget3D(target)) {
|
|
|
|
// 2D targets don't enforce skipRows+height<=imageHeight.
|
|
|
|
ret.mUnpackImageHeight += ret.mUnpackSkipRows;
|
|
|
|
}
|
2020-07-22 01:57:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2020-11-14 02:24:13 +03:00
|
|
|
|
|
|
|
CheckedInt<size_t> UsedPixelsPerRow(const uvec3& size) const {
|
|
|
|
if (!size.x || !size.y || !size.z) return 0;
|
|
|
|
return CheckedInt<size_t>(mUnpackSkipPixels) + size.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckedInt<size_t> FullRowsNeeded(const uvec3& size) const {
|
|
|
|
if (!size.x || !size.y || !size.z) return 0;
|
|
|
|
|
|
|
|
// The spec guarantees:
|
|
|
|
// * SKIP_PIXELS + width <= ROW_LENGTH.
|
|
|
|
// * SKIP_ROWS + height <= IMAGE_HEIGHT.
|
|
|
|
MOZ_ASSERT(mUnpackImageHeight);
|
|
|
|
auto skipFullRows =
|
|
|
|
CheckedInt<size_t>(mUnpackSkipImages) * mUnpackImageHeight;
|
|
|
|
skipFullRows += mUnpackSkipRows;
|
|
|
|
|
|
|
|
// Full rows in the final image, excluding the tail.
|
|
|
|
auto usedFullRows = CheckedInt<size_t>(size.z - 1) * mUnpackImageHeight;
|
|
|
|
usedFullRows += size.y - 1;
|
|
|
|
|
|
|
|
return skipFullRows + usedFullRows;
|
|
|
|
}
|
2020-07-22 01:57:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct TexImageData final {
|
|
|
|
WebGLPixelStore unpackState;
|
|
|
|
|
|
|
|
Maybe<uint64_t> pboOffset;
|
|
|
|
|
|
|
|
RawBuffer<> data;
|
|
|
|
|
|
|
|
const dom::Element* domElem = nullptr;
|
|
|
|
ErrorResult* out_domElemError = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace webgl {
|
|
|
|
|
|
|
|
struct TexUnpackBlobDesc final {
|
|
|
|
GLenum imageTarget = LOCAL_GL_TEXTURE_2D;
|
|
|
|
uvec3 size;
|
|
|
|
gfxAlphaType srcAlphaType = gfxAlphaType::NonPremult;
|
|
|
|
|
|
|
|
Maybe<RawBuffer<>> cpuData;
|
|
|
|
Maybe<uint64_t> pboOffset;
|
2021-01-14 04:23:06 +03:00
|
|
|
|
|
|
|
uvec2 imageSize;
|
2020-07-22 01:57:01 +03:00
|
|
|
RefPtr<layers::Image> image;
|
2021-01-14 04:23:06 +03:00
|
|
|
Maybe<layers::SurfaceDescriptor> sd;
|
|
|
|
RefPtr<gfx::DataSourceSurface> dataSurf;
|
2020-07-22 01:57:01 +03:00
|
|
|
|
|
|
|
WebGLPixelStore unpacking;
|
2020-11-14 02:24:13 +03:00
|
|
|
|
|
|
|
void Shrink(const webgl::PackingInfo&);
|
2020-07-22 01:57:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace webgl
|
|
|
|
|
|
|
|
// ---------------------------------------
|
|
|
|
// MakeRange
|
2020-07-22 01:56:52 +03:00
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
template <typename T, size_t N>
|
|
|
|
inline Range<const T> MakeRange(T (&arr)[N]) {
|
|
|
|
return {arr, N};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline Range<const T> MakeRange(const dom::Sequence<T>& seq) {
|
|
|
|
return {seq.Elements(), seq.Length()};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline Range<const T> MakeRange(const RawBuffer<T>& from) {
|
2020-07-22 01:56:52 +03:00
|
|
|
return from.Data();
|
2020-01-09 01:19:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// abv = ArrayBufferView
|
|
|
|
template <typename T>
|
|
|
|
inline auto MakeRangeAbv(const T& abv)
|
|
|
|
-> Range<const typename T::element_type> {
|
2020-01-23 06:22:06 +03:00
|
|
|
abv.ComputeState();
|
2020-01-22 16:09:49 +03:00
|
|
|
return {abv.Data(), abv.Length()};
|
2020-01-09 01:19:16 +03:00
|
|
|
}
|
|
|
|
|
2020-09-16 10:16:48 +03:00
|
|
|
// -
|
|
|
|
|
|
|
|
constexpr auto kUniversalAlignment = alignof(std::max_align_t);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline size_t AlignmentOffset(const size_t alignment, const T posOrPtr) {
|
|
|
|
MOZ_ASSERT(alignment);
|
|
|
|
const auto begin = reinterpret_cast<uintptr_t>(posOrPtr);
|
|
|
|
const auto wholeMultiples = (begin + (alignment - 1)) / alignment;
|
|
|
|
const auto aligned = wholeMultiples * alignment;
|
|
|
|
return aligned - begin;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline size_t ByteSize(const Range<T>& range) {
|
|
|
|
return range.length() * sizeof(T);
|
|
|
|
}
|
|
|
|
|
2020-01-09 01:19:16 +03:00
|
|
|
Maybe<Range<const uint8_t>> GetRangeFromView(const dom::ArrayBufferView& view,
|
|
|
|
GLuint elemOffset,
|
|
|
|
GLuint elemCountOverride);
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
RawBuffer<T> RawBufferView(const Range<T>& range) {
|
2020-07-22 01:56:52 +03:00
|
|
|
return RawBuffer<T>{range};
|
2020-01-09 01:19:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// -
|
|
|
|
|
|
|
|
Maybe<webgl::ErrorInfo> CheckBindBufferRange(
|
|
|
|
const GLenum target, const GLuint index, const bool isBuffer,
|
|
|
|
const uint64_t offset, const uint64_t size, const webgl::Limits& limits);
|
|
|
|
|
|
|
|
Maybe<webgl::ErrorInfo> CheckFramebufferAttach(const GLenum bindImageTarget,
|
|
|
|
const GLenum curTexTarget,
|
|
|
|
const uint32_t mipLevel,
|
|
|
|
const uint32_t zLayerBase,
|
|
|
|
const uint32_t zLayerCount,
|
|
|
|
const webgl::Limits& limits);
|
|
|
|
|
2020-02-26 03:44:26 +03:00
|
|
|
Result<webgl::VertAttribPointerCalculated, webgl::ErrorInfo>
|
|
|
|
CheckVertexAttribPointer(bool isWebgl2, const webgl::VertAttribPointerDesc&);
|
2020-01-09 01:19:16 +03:00
|
|
|
|
|
|
|
uint8_t ElemTypeComponents(GLenum elemType);
|
|
|
|
|
2020-01-09 01:19:23 +03:00
|
|
|
inline std::string ToString(const nsACString& text) {
|
|
|
|
return {text.BeginReading(), text.Length()};
|
|
|
|
}
|
|
|
|
|
2020-07-22 01:56:52 +03:00
|
|
|
inline void Memcpy(const RangedPtr<uint8_t>& destBytes,
|
|
|
|
const RangedPtr<const uint8_t>& srcBytes,
|
|
|
|
const size_t byteSize) {
|
|
|
|
// Trigger range asserts
|
|
|
|
(void)(srcBytes + byteSize);
|
|
|
|
(void)(destBytes + byteSize);
|
|
|
|
|
|
|
|
memcpy(destBytes.get(), srcBytes.get(), byteSize);
|
|
|
|
}
|
|
|
|
|
2020-06-15 21:25:55 +03:00
|
|
|
// -
|
|
|
|
|
2013-06-11 00:00:35 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|