Fix refcounted lambda captures, and fix implicit_color_buffer_float.
draft
Fix refcounted lambda captures, and fix implicit_color_buffer_float.
--- a/dom/canvas/WebGLExtensionCompressedTextureATC.cpp
+++ b/dom/canvas/WebGLExtensionCompressedTextureATC.cpp
@@ -12,17 +12,17 @@
#endif
namespace mozilla {
WebGLExtensionCompressedTextureATC::WebGLExtensionCompressedTextureATC(WebGLContext* webgl)
: WebGLExtensionBase(webgl)
{
RefPtr<WebGLContext> webgl_ = webgl; // Bug 1201275
- const auto fnAdd = [webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
+ const auto fnAdd = [&webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
auto& fua = webgl_->mFormatUsage;
auto usage = fua->EditUsage(effFormat);
fua->AddSizedTexFormat(sizedFormat, usage);
webgl_->mCompressedTextureFormats.AppendElement(sizedFormat);
};
--- a/dom/canvas/WebGLExtensionCompressedTextureETC1.cpp
+++ b/dom/canvas/WebGLExtensionCompressedTextureETC1.cpp
@@ -11,23 +11,24 @@
#error FOO is already defined! We use FOO() macros to keep things succinct in this file.
#endif
namespace mozilla {
WebGLExtensionCompressedTextureETC1::WebGLExtensionCompressedTextureETC1(WebGLContext* webgl)
: WebGLExtensionBase(webgl)
{
- const auto fnAdd = [&webgl](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
- auto& fua = webgl->mFormatUsage;
+ RefPtr<WebGLContext> webgl_ = webgl; // Bug 1201275
+ const auto fnAdd = [&webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
+ auto& fua = webgl_->mFormatUsage;
auto usage = fua->EditUsage(effFormat);
fua->AddSizedTexFormat(sizedFormat, usage);
- webgl->mCompressedTextureFormats.AppendElement(sizedFormat);
+ webgl_->mCompressedTextureFormats.AppendElement(sizedFormat);
};
#define FOO(x) LOCAL_GL_ ## x, webgl::EffectiveFormat::x
fnAdd(FOO(ETC1_RGB8_OES));
#undef FOO
}
--- a/dom/canvas/WebGLExtensionCompressedTexturePVRTC.cpp
+++ b/dom/canvas/WebGLExtensionCompressedTexturePVRTC.cpp
@@ -11,23 +11,24 @@
#error FOO is already defined! We use FOO() macros to keep things succinct in this file.
#endif
namespace mozilla {
WebGLExtensionCompressedTexturePVRTC::WebGLExtensionCompressedTexturePVRTC(WebGLContext* webgl)
: WebGLExtensionBase(webgl)
{
- const auto fnAdd = [&webgl](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
- auto& fua = webgl->mFormatUsage;
+ RefPtr<WebGLContext> webgl_ = webgl; // Bug 1201275
+ const auto fnAdd = [&webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
+ auto& fua = webgl_->mFormatUsage;
auto usage = fua->EditUsage(effFormat);
fua->AddSizedTexFormat(sizedFormat, usage);
- webgl->mCompressedTextureFormats.AppendElement(sizedFormat);
+ webgl_->mCompressedTextureFormats.AppendElement(sizedFormat);
};
#define FOO(x) LOCAL_GL_ ## x, webgl::EffectiveFormat::x
fnAdd(FOO(COMPRESSED_RGB_PVRTC_4BPPV1));
fnAdd(FOO(COMPRESSED_RGB_PVRTC_2BPPV1));
fnAdd(FOO(COMPRESSED_RGBA_PVRTC_4BPPV1));
fnAdd(FOO(COMPRESSED_RGBA_PVRTC_2BPPV1));
--- a/dom/canvas/WebGLExtensionCompressedTextureS3TC.cpp
+++ b/dom/canvas/WebGLExtensionCompressedTextureS3TC.cpp
@@ -11,23 +11,24 @@
#error FOO is already defined! We use FOO() macros to keep things succinct in this file.
#endif
namespace mozilla {
WebGLExtensionCompressedTextureS3TC::WebGLExtensionCompressedTextureS3TC(WebGLContext* webgl)
: WebGLExtensionBase(webgl)
{
- const auto fnAdd = [&webgl](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
- auto& fua = webgl->mFormatUsage;
+ RefPtr<WebGLContext> webgl_ = webgl; // Bug 1201275
+ const auto fnAdd = [&webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) {
+ auto& fua = webgl_->mFormatUsage;
auto usage = fua->EditUsage(effFormat);
fua->AddSizedTexFormat(sizedFormat, usage);
- webgl->mCompressedTextureFormats.AppendElement(sizedFormat);
+ webgl_->mCompressedTextureFormats.AppendElement(sizedFormat);
};
#define FOO(x) LOCAL_GL_ ## x, webgl::EffectiveFormat::x
fnAdd(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT));
fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT));
fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT));
fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT));
--- a/dom/canvas/WebGLExtensionSRGB.cpp
+++ b/dom/canvas/WebGLExtensionSRGB.cpp
@@ -22,26 +22,27 @@ WebGLExtensionSRGB::WebGLExtensionSRGB(W
// Desktop OpenGL requires the following to be enabled in order to
// support sRGB operations on framebuffers.
gl->MakeCurrent();
gl->fEnable(LOCAL_GL_FRAMEBUFFER_SRGB_EXT);
}
auto& fua = webgl->mFormatUsage;
- const auto fnAdd = [&fua, gl](webgl::EffectiveFormat effFormat, GLenum format,
- GLenum desktopUnpackFormat)
+ RefPtr<gl::GLContext> gl_ = gl; // Bug 1201275
+ const auto fnAdd = [&fua, &gl_](webgl::EffectiveFormat effFormat, GLenum format,
+ GLenum desktopUnpackFormat)
{
auto usage = fua->EditUsage(effFormat);
usage->isFilterable = true;
webgl::DriverUnpackInfo dui = {format, format, LOCAL_GL_UNSIGNED_BYTE};
const auto pi = dui.ToPacking();
- if (!gl->IsGLES())
+ if (!gl_->IsGLES())
dui.unpackFormat = desktopUnpackFormat;
fua->AddUnsizedTexFormat(pi, usage);
usage->AddUnpack(pi, dui);
};
fnAdd(webgl::EffectiveFormat::SRGB8, LOCAL_GL_SRGB, LOCAL_GL_RGB);
fnAdd(webgl::EffectiveFormat::SRGB8_ALPHA8, LOCAL_GL_SRGB_ALPHA, LOCAL_GL_RGBA);
--- a/dom/canvas/WebGLFramebuffer.cpp
+++ b/dom/canvas/WebGLFramebuffer.cpp
@@ -495,21 +495,22 @@ WebGLFramebuffer::FramebufferRenderbuffe
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
if (!mContext->ValidateObjectAllowNull("framebufferRenderbuffer: renderbuffer", rb))
return;
// `attachPointEnum` is validated by ValidateFramebufferAttachment().
- const auto fnAttach = [this, rb](GLenum attachment) {
+ RefPtr<WebGLRenderbuffer> rb_ = rb; // Bug 1201275
+ const auto fnAttach = [this, &rb_](GLenum attachment) {
const auto attachPoint = this->GetAttachPoint(attachment);
MOZ_ASSERT(attachPoint);
- attachPoint->SetRenderbuffer(rb);
+ attachPoint->SetRenderbuffer(rb_);
};
if (mContext->IsWebGL2() && attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
fnAttach(LOCAL_GL_DEPTH_ATTACHMENT);
fnAttach(LOCAL_GL_STENCIL_ATTACHMENT);
} else {
fnAttach(attachment);
}
@@ -532,21 +533,22 @@ WebGLFramebuffer::FramebufferTexture2D(G
bool isTexTarget2D = texImageTarget == LOCAL_GL_TEXTURE_2D;
if (isTexture2D != isTexTarget2D) {
mContext->ErrorInvalidOperation("framebufferTexture2D: Mismatched"
" texture and texture target.");
return;
}
}
- const auto fnAttach = [this, tex, texImageTarget, level](GLenum attachment) {
+ RefPtr<WebGLTexture> tex_ = tex; // Bug 1201275
+ const auto fnAttach = [this, &tex_, texImageTarget, level](GLenum attachment) {
const auto attachPoint = this->GetAttachPoint(attachment);
MOZ_ASSERT(attachPoint);
- attachPoint->SetTexImage(tex, texImageTarget, level);
+ attachPoint->SetTexImage(tex_, texImageTarget, level);
};
if (mContext->IsWebGL2() && attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
fnAttach(LOCAL_GL_DEPTH_ATTACHMENT);
fnAttach(LOCAL_GL_STENCIL_ATTACHMENT);
} else {
fnAttach(attachment);
}
@@ -559,21 +561,22 @@ WebGLFramebuffer::FramebufferTextureLaye
GLint level, GLint layer)
{
MOZ_ASSERT(mContext->mBoundDrawFramebuffer == this ||
mContext->mBoundReadFramebuffer == this);
const TexImageTarget texImageTarget = (tex ? tex->Target().get()
: LOCAL_GL_TEXTURE_2D);
- const auto fnAttach = [this, tex, texImageTarget, level, layer](GLenum attachment) {
+ RefPtr<WebGLTexture> tex_ = tex; // Bug 1201275
+ const auto fnAttach = [this, &tex_, texImageTarget, level, layer](GLenum attachment) {
const auto attachPoint = this->GetAttachPoint(attachment);
MOZ_ASSERT(attachPoint);
- attachPoint->SetTexImageLayer(tex, texImageTarget, level, layer);
+ attachPoint->SetTexImageLayer(tex_, texImageTarget, level, layer);
};
if (mContext->IsWebGL2() && attachment == LOCAL_GL_DEPTH_STENCIL_ATTACHMENT) {
fnAttach(LOCAL_GL_DEPTH_ATTACHMENT);
fnAttach(LOCAL_GL_STENCIL_ATTACHMENT);
} else {
fnAttach(attachment);
}
@@ -885,24 +888,22 @@ WebGLFramebuffer::CheckAndInitializeAtta
if (mStencilAttachment.HasUninitializedImageData() ||
mDepthStencilAttachment.HasUninitializedImageData())
{
clearBits |= LOCAL_GL_STENCIL_BUFFER_BIT;
}
mContext->MakeContextCurrent();
- gl::GLContext* gl = mContext->gl;
-
- const auto fnDrawBuffers = [&gl](const std::vector<GLenum>& list) {
+ const auto fnDrawBuffers = [this](const std::vector<GLenum>& list) {
const GLenum* ptr = nullptr;
if (list.size()) {
ptr = &(list[0]);
}
- gl->fDrawBuffers(list.size(), ptr);
+ this->mContext->gl->fDrawBuffers(list.size(), ptr);
};
const auto drawBufferExt = WebGLExtensionID::WEBGL_draw_buffers;
const bool hasDrawBuffers = (mContext->IsWebGL2() ||
mContext->IsExtensionEnabled(drawBufferExt));
if (hasDrawBuffers) {
fnDrawBuffers(tempDrawBuffers);
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -492,23 +492,24 @@ ValidateCompressedTexUnpack(WebGLContext
const webgl::FormatInfo* format, size_t dataSize)
{
auto compression = format->compression;
auto bytesPerBlock = compression->bytesPerBlock;
auto blockWidth = compression->blockWidth;
auto blockHeight = compression->blockHeight;
- CheckedUint32 widthInBlocks = (width % blockWidth) ? width / blockWidth + 1
- : width / blockWidth;
- CheckedUint32 heightInBlocks = (height % blockHeight) ? height / blockHeight + 1
- : height / blockHeight;
- CheckedUint32 blocksPerImage = widthInBlocks * heightInBlocks;
- CheckedUint32 bytesPerImage = bytesPerBlock * blocksPerImage;
- CheckedUint32 bytesNeeded = bytesPerImage * depth;
+ auto widthInBlocks = CheckedUint32(width) / blockWidth;
+ auto heightInBlocks = CheckedUint32(height) / blockHeight;
+ if (width % blockWidth) widthInBlocks += 1;
+ if (height % blockHeight) heightInBlocks += 1;
+
+ const CheckedUint32 blocksPerImage = widthInBlocks * heightInBlocks;
+ const CheckedUint32 bytesPerImage = bytesPerBlock * blocksPerImage;
+ const CheckedUint32 bytesNeeded = bytesPerImage * depth;
if (!bytesNeeded.isValid()) {
webgl->ErrorOutOfMemory("%s: Overflow while computing the needed buffer size.",
funcName);
return false;
}
if (dataSize != bytesNeeded.value()) {
--- a/dom/canvas/test/webgl-mochitest/test_implicit_color_buffer_float.html
+++ b/dom/canvas/test/webgl-mochitest/test_implicit_color_buffer_float.html
@@ -30,35 +30,35 @@ function IsFormatValidForRB(gl, format)
function IsFormatValidForTex(gl, format, type) {
ok(!gl.getError(), 'Should have no errors here.');
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, format, 4, 4, 0, format, type, null);
var error = gl.getError();
- if (error == gl.INVALID_ENUM)
+ if (error == gl.INVALID_ENUM || error == gl.INVALID_OPERATION)
return false;
- ok(error == gl.NO_ERROR, 'Error should be INVALID_ENUM or NO_ERROR.');
+ ok(error == gl.NO_ERROR, 'Error should be INVALID_{ENUM,OPERATION} or NO_ERROR.');
return error == gl.NO_ERROR;
}
function IsFormatValidForTexFB(gl, format, type) {
ok(!gl.getError(), 'Should have no errors here.');
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, format, 4, 4, 0, format, type, null);
var error = gl.getError();
- if (error == gl.INVALID_ENUM)
+ if (error == gl.INVALID_ENUM || error == gl.INVALID_OPERATION)
return false;
- ok(error == gl.NO_ERROR, 'Error should be INVALID_ENUM or NO_ERROR.');
+ ok(error == gl.NO_ERROR, 'Error should be INVALID_{ENUM,OPERATION} or NO_ERROR.');
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
tex, 0);
error = gl.getError();
ok(error == gl.NO_ERROR, 'Error should be NO_ERROR.');
@@ -70,20 +70,20 @@ function IsFormatValidForTexFBRead(gl, t
ok(!gl.getError(), 'Should have no errors here.');
var tex = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texImage2D(gl.TEXTURE_2D, 0, texFormat, 4, 4, 0, texFormat, texType,
null);
var error = gl.getError();
- if (error == gl.INVALID_ENUM)
+ if (error == gl.INVALID_ENUM || error == gl.INVALID_OPERATION)
return false;
- ok(error == gl.NO_ERROR, 'Error should be INVALID_ENUM or NO_ERROR.');
+ ok(error == gl.NO_ERROR, 'Error should be INVALID_{ENUM,OPERATION} or NO_ERROR.');
var fb = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
tex, 0);
error = gl.getError();
ok(error == gl.NO_ERROR, 'Error should be NO_ERROR.');