Files
palemoon27/dom/canvas/WebGLContextVertices.cpp
T
roytam1 9e110c81ee import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1171796: Add sandbox rule for child process NSPR log file on Windows. r=bbondy (1393c5eed4)
- Bug 1171994: Separate RIL I/O interfaces, r=htsai (eb62c398f9)
- Bug 1171994: Store an instance of |RilWorker| for each RIL connection, r=htsai (6f85151cfe)
- Bug 1171464 - Check that socket isn't already closed before closing it, r=kmachulis (05a6ecd79c)
- Bug 1156352: Remove |UnixSocketRawData| from RIL interfaces, r=htsai (4c2c066809)
- Bug 1171994: Use |RilSocket| to handle RIL messages on the RIL worker, r=htsai (cdbc7a3868)
- Bug 1171994: Cleanup JSAPI code of |RilConsumer|, r=htsai (eaf9623f2c)
- Bug 1207539 - Remove !JS_IsRunning(aCx) assertion from RilConsumer::ConnectWorkerToRIL; r=mrbkap (f5d20f6d75)
- missing bit of Bug 1138293 - Use malloc/free/realloc/calloc (3cdb9ee5d6)
- Bug 1140261 - Fix compiler error comparison of unsigned expression >= 0 is always true. r=hchang (f808fc5f09)
- Bug 1158896 - prevent dead code from being generated in lower.py; r=bent (8ebbd3109d)
- Bug 1169382 - Don't generate commented out NS_INTERFACE_CLASS or NS_ABSTRACT_CLASS in IPDL. r=billm (20fc4894c0)
- Bug 1219537 - Simplify a couple of PresContext() gets on nsIFrame/nsStyleContext. r=dholbert (cff7f8aa43)
- Bug 1223258 - Fix -Wunreachable-code warnings in widget. r=masayuki (8682636334)
- bit of Add an nsIGfxInfo function to query monitors. (bug 1175005 partart 1) (36bb03dfb2)
- Bug 1210086 - Fix warnings caused by toolbar buttons in gtk2. r=karl (0e7f0aaba2)
- Bug 1176109 - Don't attach menu popups to menubars on GTK3. r=karlt (1cbdd6798f)
- Bug 1188138 - Prevent default buttons from being drawn twice on GTK3. r=karlt (24d3b48643)
- Bug 1189028 - Draw a toplevel popup behind popup menus on GTK3. r=karlt (6dcb65f4af)
- Bug 1160154 - Decrease padding between icons in the personal toolbar with Gtk3 by using "image-button" css style class. r=karlt (50254fd1ce)
- Bug 1073117 - Fixed Theme issues with GTK 3.14 - GtkButtons - use border style (cde1375eec)
- Bug 1168578 - Use widget state in GTK3 toggles' style context. r=karlt (2889392859)
- Bug 1198613 - Use GTK style padding for dropdown boxes in HTML. r=karlt (5e97b42105)
- Bug 1216582 - [gtk3] Scrollbar buttons not drawn correctly. r=karlt (4a7ca51f14)
- Bug 1174248 - Workaround unico theme engine resizer bug on GTK3. r=karlt (ca55b44a4a)
- Bug 1173907 - Don't use gtk_render_activity for drawing progress chunks on GTK versions above 3.13.7. r=karlt (57e97d2d55)
- Bug 1218008 - Fix progress bar rendering on the Ambiance GTK3 theme. r=karlt (5dcfff5ab5)
- Bug 1171011 - Use only document padding for MOZ_GTK_ENTRY in XUL. r=karlt (3d164c219e)
- Bug 1187385 - Use GTK style padding for entry widgets. r=karlt (f44fffb148)
- Bug 1176929 - Disable Ctrl-K in GtkEntry unless custom key bindings are (46c9b03899)
- Bug 1120490 - Take the 'GetRotateForLandscape' gfxASurface configuration into account when creating printing surfaces. r=jwatt (b259f7006a)
- Bug 1228216 - Event::GetScreenCoords incorrectly converts the coords to a CSSPoint when the widget is null r=tnikkel (9e58f9f640)
- Bug 1226872 - Stop keeping a copy of the resolution in the root scrollframe. r=roc (c168509f4d)
- Bug 1224015 - Part 1: nsLayoutUtils functions do not account for nsPresShell resolution r=tnikkel (c6a1cca145)
- Bug 1224015 - Part 2: Have nsDisplayResolution items adjust event coordinates for hit testing and dispatching to content r=tnikkel (09fad089ce)
- Bug 1224015 - Part 3: ifdef changes to C++APZ so that they only apply to single process APZ. r=tnikkel (340b30205d)
- Bug 1228597 - Remove the MOZ_SINGLE_PROCESS_APZ define. r=tn (6733cf7b4b)
- Bug 1177406, don't rely on owner to be set only on main thread, r=khuey (a31d3ee5fe)
- Bug 1221822 - Finish the WebGL texture refactor. r=kamidphish,mattwoodrow,bz (9df451d68f)
- bug 1214953 set GDK_VERSION_MIN_REQUIRED/MAX_ALLOWED to specify the GTK/GDK API and suppress irrelevant deprecated warnings r=glandium (e9161dc6f4)
- Bug 1160666 - Allow per-product b2g branding. r=fabrice (8d95dfa1ea)
- Fix due to backport (900ffc0c50)
- Bug 1224490 - Don't set NSS_LIBS in the non-native NSS case. r=mshal We never use the variable in that case. Bug 1224490 - Kill LIBXUL_DIST. r=mshal (bf53e3e930)
- Bug 1175555 - Build flag to exclude hyphenation dictionaries from Android builds. r=nalexander (eb94fae1dd)
- Bug 1141534 - fix mulet nightly mozconfigs; r=bhearsum We don't want uploadsymbols or update-packaging for nightly mulet builds, but these were being set by the underlying browser mozconfigs. (1a9e4cb294)
- Bug 1137000 - Enable SDK building on nightlies; r=glandium (c28e4f9cae)
- Bug 1181040 - Include mozconfig.cache after mozconfig.common.override. r=mshal (610364f8ae)
- bug 1182519 - Put mozconfigs for cross-mac builds in tree. r=mshal (0c3768b90a)
- bug 935237 - add genisoimage+dmg binaries to tooltool manifest, use them in cross-mac mozconfig. r=gps (d0252cb263)
- bug 1203689 - Use tooltool gcc as host compiler for cross-mac builds. r=dustin (2597df48cd)
- Bug 1204068 - Update the clang used for OSX cross compiles to the latest that we use on Linux64; r=ted (0323202013)
- Bug 1204763 - Enable cross compiling the clang plugin for OS X on Linux; r=glandium (2813897f8b)
- Bug 1208787 - Enable static analysis checks by default on OSX cross builds; r=ted (9aa48ddb43)
- bug 543111 - enable Breakpad for cross-mac builds. r=glandium (1a2be876d8)
- bug 1190522 - Rewrite pkg-dmg as a Python script. r=gps (796e8ef8e1)
- bug 935237 - use libdmg-hfsplus to create DMG files during packaging on Linux. r=gps (d676c7eb8f)
- bug 543111 - add support for alternate dsymutil paths to configure, add to cross-mozconfig. r=glandium (401ec2b3a4)
2023-02-16 10:14:13 +08:00

485 lines
13 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#include "WebGLContext.h"
#include "GLContext.h"
#include "mozilla/CheckedInt.h"
#include "WebGLBuffer.h"
#include "WebGLFramebuffer.h"
#include "WebGLProgram.h"
#include "WebGLRenderbuffer.h"
#include "WebGLShader.h"
#include "WebGLTexture.h"
#include "WebGLVertexArray.h"
#include "WebGLVertexAttribData.h"
#include "mozilla/Casting.h"
namespace mozilla {
void
WebGLContext::GetVertexAttribFloat(GLuint index, GLfloat* out_result)
{
if (index) {
gl->fGetVertexAttribfv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
} else {
out_result[0] = mVertexAttrib0Vector[0];
out_result[1] = mVertexAttrib0Vector[1];
out_result[2] = mVertexAttrib0Vector[2];
out_result[3] = mVertexAttrib0Vector[3];
}
}
void
WebGLContext::GetVertexAttribInt(GLuint index, GLint* out_result)
{
if (index) {
gl->fGetVertexAttribIiv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
} else {
out_result[0] = BitwiseCast<GLint>(mVertexAttrib0Vector[0]);
out_result[1] = BitwiseCast<GLint>(mVertexAttrib0Vector[1]);
out_result[2] = BitwiseCast<GLint>(mVertexAttrib0Vector[2]);
out_result[3] = BitwiseCast<GLint>(mVertexAttrib0Vector[3]);
}
}
void
WebGLContext::GetVertexAttribUint(GLuint index, GLuint* out_result)
{
if (index) {
gl->fGetVertexAttribIuiv(index, LOCAL_GL_CURRENT_VERTEX_ATTRIB, out_result);
} else {
out_result[0] = BitwiseCast<GLuint>(mVertexAttrib0Vector[0]);
out_result[1] = BitwiseCast<GLuint>(mVertexAttrib0Vector[1]);
out_result[2] = BitwiseCast<GLuint>(mVertexAttrib0Vector[2]);
out_result[3] = BitwiseCast<GLuint>(mVertexAttrib0Vector[3]);
}
}
JSObject*
WebGLContext::GetVertexAttribFloat32Array(JSContext* cx, GLuint index)
{
GLfloat attrib[4];
GetVertexAttribFloat(index, &attrib[0]);
return dom::Float32Array::Create(cx, this, 4, attrib);
}
JSObject*
WebGLContext::GetVertexAttribInt32Array(JSContext* cx, GLuint index)
{
GLint attrib[4];
GetVertexAttribInt(index, &attrib[0]);
return dom::Int32Array::Create(cx, this, 4, attrib);
}
JSObject*
WebGLContext::GetVertexAttribUint32Array(JSContext* cx, GLuint index) {
GLuint attrib[4];
GetVertexAttribUint(index, &attrib[0]);
return dom::Uint32Array::Create(cx, this, 4, attrib);
}
void
WebGLContext::VertexAttrib1f(GLuint index, GLfloat x0)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttrib1f"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib1f(index, x0);
} else {
mVertexAttrib0Vector[0] = x0;
mVertexAttrib0Vector[1] = 0;
mVertexAttrib0Vector[2] = 0;
mVertexAttrib0Vector[3] = 1;
if (gl->IsGLES())
gl->fVertexAttrib1f(index, x0);
}
}
void
WebGLContext::VertexAttrib2f(GLuint index, GLfloat x0, GLfloat x1)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttrib2f"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib2f(index, x0, x1);
} else {
mVertexAttrib0Vector[0] = x0;
mVertexAttrib0Vector[1] = x1;
mVertexAttrib0Vector[2] = 0;
mVertexAttrib0Vector[3] = 1;
if (gl->IsGLES())
gl->fVertexAttrib2f(index, x0, x1);
}
}
void
WebGLContext::VertexAttrib3f(GLuint index, GLfloat x0, GLfloat x1, GLfloat x2)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttrib3f"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib3f(index, x0, x1, x2);
} else {
mVertexAttrib0Vector[0] = x0;
mVertexAttrib0Vector[1] = x1;
mVertexAttrib0Vector[2] = x2;
mVertexAttrib0Vector[3] = 1;
if (gl->IsGLES())
gl->fVertexAttrib3f(index, x0, x1, x2);
}
}
void
WebGLContext::VertexAttrib4f(GLuint index, GLfloat x0, GLfloat x1,
GLfloat x2, GLfloat x3)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttrib4f"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
} else {
mVertexAttrib0Vector[0] = x0;
mVertexAttrib0Vector[1] = x1;
mVertexAttrib0Vector[2] = x2;
mVertexAttrib0Vector[3] = x3;
if (gl->IsGLES())
gl->fVertexAttrib4f(index, x0, x1, x2, x3);
}
}
void
WebGLContext::VertexAttrib1fv_base(GLuint index, uint32_t arrayLength,
const GLfloat* ptr)
{
if (!ValidateAttribArraySetter("VertexAttrib1fv", 1, arrayLength))
return;
if (!ValidateAttribIndex(index, "vertexAttrib1fv"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib1fv(index, ptr);
} else {
mVertexAttrib0Vector[0] = ptr[0];
mVertexAttrib0Vector[1] = GLfloat(0);
mVertexAttrib0Vector[2] = GLfloat(0);
mVertexAttrib0Vector[3] = GLfloat(1);
if (gl->IsGLES())
gl->fVertexAttrib1fv(index, ptr);
}
}
void
WebGLContext::VertexAttrib2fv_base(GLuint index, uint32_t arrayLength,
const GLfloat* ptr)
{
if (!ValidateAttribArraySetter("VertexAttrib2fv", 2, arrayLength))
return;
if (!ValidateAttribIndex(index, "vertexAttrib2fv"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib2fv(index, ptr);
} else {
mVertexAttrib0Vector[0] = ptr[0];
mVertexAttrib0Vector[1] = ptr[1];
mVertexAttrib0Vector[2] = GLfloat(0);
mVertexAttrib0Vector[3] = GLfloat(1);
if (gl->IsGLES())
gl->fVertexAttrib2fv(index, ptr);
}
}
void
WebGLContext::VertexAttrib3fv_base(GLuint index, uint32_t arrayLength,
const GLfloat* ptr)
{
if (!ValidateAttribArraySetter("VertexAttrib3fv", 3, arrayLength))
return;
if (!ValidateAttribIndex(index, "vertexAttrib3fv"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib3fv(index, ptr);
} else {
mVertexAttrib0Vector[0] = ptr[0];
mVertexAttrib0Vector[1] = ptr[1];
mVertexAttrib0Vector[2] = ptr[2];
mVertexAttrib0Vector[3] = GLfloat(1);
if (gl->IsGLES())
gl->fVertexAttrib3fv(index, ptr);
}
}
void
WebGLContext::VertexAttrib4fv_base(GLuint index, uint32_t arrayLength,
const GLfloat* ptr)
{
if (!ValidateAttribArraySetter("VertexAttrib4fv", 4, arrayLength))
return;
if (!ValidateAttribIndex(index, "vertexAttrib4fv"))
return;
mVertexAttribType[index] = LOCAL_GL_FLOAT;
MakeContextCurrent();
if (index) {
gl->fVertexAttrib4fv(index, ptr);
} else {
mVertexAttrib0Vector[0] = ptr[0];
mVertexAttrib0Vector[1] = ptr[1];
mVertexAttrib0Vector[2] = ptr[2];
mVertexAttrib0Vector[3] = ptr[3];
if (gl->IsGLES())
gl->fVertexAttrib4fv(index, ptr);
}
}
void
WebGLContext::EnableVertexAttribArray(GLuint index)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "enableVertexAttribArray"))
return;
MakeContextCurrent();
InvalidateBufferFetching();
gl->fEnableVertexAttribArray(index);
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
mBoundVertexArray->mAttribs[index].enabled = true;
}
void
WebGLContext::DisableVertexAttribArray(GLuint index)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "disableVertexAttribArray"))
return;
MakeContextCurrent();
InvalidateBufferFetching();
if (index || gl->IsGLES())
gl->fDisableVertexAttribArray(index);
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
mBoundVertexArray->mAttribs[index].enabled = false;
}
JS::Value
WebGLContext::GetVertexAttrib(JSContext* cx, GLuint index, GLenum pname,
ErrorResult& rv)
{
if (IsContextLost())
return JS::NullValue();
if (!ValidateAttribIndex(index, "getVertexAttrib"))
return JS::NullValue();
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
MakeContextCurrent();
switch (pname) {
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
return WebGLObjectAsJSValue(cx, mBoundVertexArray->mAttribs[index].buf.get(), rv);
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_STRIDE:
return JS::Int32Value(mBoundVertexArray->mAttribs[index].stride);
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_SIZE:
if (!mBoundVertexArray->mAttribs[index].enabled)
return JS::Int32Value(4);
return JS::Int32Value(mBoundVertexArray->mAttribs[index].size);
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_TYPE:
if (!mBoundVertexArray->mAttribs[index].enabled)
return JS::NumberValue(uint32_t(LOCAL_GL_FLOAT));
return JS::NumberValue(uint32_t(mBoundVertexArray->mAttribs[index].type));
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
if (IsWebGL2() ||
IsExtensionEnabled(WebGLExtensionID::ANGLE_instanced_arrays))
{
return JS::Int32Value(mBoundVertexArray->mAttribs[index].divisor);
}
break;
case LOCAL_GL_CURRENT_VERTEX_ATTRIB:
{
JS::RootedObject obj(cx);
switch (mVertexAttribType[index]) {
case LOCAL_GL_FLOAT:
obj = GetVertexAttribFloat32Array(cx, index);
break;
case LOCAL_GL_INT:
obj = GetVertexAttribInt32Array(cx, index);
break;
case LOCAL_GL_UNSIGNED_INT:
obj = GetVertexAttribUint32Array(cx, index);
break;
}
if (!obj)
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
return JS::ObjectOrNullValue(obj);
}
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_ENABLED:
return JS::BooleanValue(mBoundVertexArray->mAttribs[index].enabled);
case LOCAL_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
return JS::BooleanValue(mBoundVertexArray->mAttribs[index].normalized);
default:
break;
}
ErrorInvalidEnumInfo("getVertexAttrib: parameter", pname);
return JS::NullValue();
}
WebGLsizeiptr
WebGLContext::GetVertexAttribOffset(GLuint index, GLenum pname)
{
if (IsContextLost())
return 0;
if (!ValidateAttribIndex(index, "getVertexAttribOffset"))
return 0;
if (pname != LOCAL_GL_VERTEX_ATTRIB_ARRAY_POINTER) {
ErrorInvalidEnum("getVertexAttribOffset: bad parameter");
return 0;
}
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
return mBoundVertexArray->mAttribs[index].byteOffset;
}
void
WebGLContext::VertexAttribPointer(GLuint index, GLint size, GLenum type,
WebGLboolean normalized, GLsizei stride,
WebGLintptr byteOffset)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttribPointer"))
return;
if (!ValidateAttribPointer(false, index, size, type, normalized, stride, byteOffset, "vertexAttribPointer"))
return;
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
InvalidateBufferFetching();
/* XXX make work with bufferSubData & heterogeneous types
if (type != mBoundArrayBuffer->GLType())
return ErrorInvalidOperation("vertexAttribPointer: type must match bound VBO type: %d != %d", type, mBoundArrayBuffer->GLType());
*/
WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
vd.buf = mBoundArrayBuffer;
vd.stride = stride;
vd.size = size;
vd.byteOffset = byteOffset;
vd.type = type;
vd.normalized = normalized;
vd.integer = false;
MakeContextCurrent();
gl->fVertexAttribPointer(index, size, type, normalized, stride,
reinterpret_cast<void*>(byteOffset));
}
void
WebGLContext::VertexAttribDivisor(GLuint index, GLuint divisor)
{
if (IsContextLost())
return;
if (!ValidateAttribIndex(index, "vertexAttribDivisor"))
return;
MOZ_ASSERT(mBoundVertexArray);
mBoundVertexArray->EnsureAttrib(index);
WebGLVertexAttribData& vd = mBoundVertexArray->mAttribs[index];
vd.divisor = divisor;
InvalidateBufferFetching();
MakeContextCurrent();
gl->fVertexAttribDivisor(index, divisor);
}
} // namespace mozilla