Bug 1325516 - Misc fixes. - r=daoshengmu
MozReview-Commit-ID: 9jtwfoEgbSr
--- a/dom/canvas/WebGL2ContextFramebuffers.cpp
+++ b/dom/canvas/WebGL2ContextFramebuffers.cpp
@@ -127,33 +127,37 @@ ValidateBackbufferAttachmentEnum(WebGLCo
return false;
}
}
static bool
ValidateFramebufferAttachmentEnum(WebGLContext* webgl, const char* funcName,
GLenum attachment)
{
- if (attachment >= LOCAL_GL_COLOR_ATTACHMENT0 &&
- attachment <= webgl->LastColorAttachmentEnum())
- {
- return true;
- }
-
switch (attachment) {
case LOCAL_GL_DEPTH_ATTACHMENT:
case LOCAL_GL_STENCIL_ATTACHMENT:
case LOCAL_GL_DEPTH_STENCIL_ATTACHMENT:
return true;
+ }
- default:
+ if (attachment < LOCAL_GL_COLOR_ATTACHMENT0) {
webgl->ErrorInvalidEnum("%s: attachment: invalid enum value 0x%x.",
funcName, attachment);
return false;
}
+
+ if (attachment > webgl->LastColorAttachmentEnum()) {
+ // That these errors have different types is ridiculous.
+ webgl->ErrorInvalidOperation("%s: Too-large LOCAL_GL_COLOR_ATTACHMENTn.",
+ funcName);
+ return false;
+ }
+
+ return true;
}
bool
WebGLContext::ValidateInvalidateFramebuffer(const char* funcName, GLenum target,
const dom::Sequence<GLenum>& attachments,
ErrorResult* const out_rv,
std::vector<GLenum>* const scopedVector,
GLsizei* const out_glNumAttachments,
--- a/dom/canvas/WebGLContextBuffers.cpp
+++ b/dom/canvas/WebGLContextBuffers.cpp
@@ -98,17 +98,17 @@ WebGLContext::ValidateIndexedBufferSlot(
break;
default:
ErrorInvalidEnum("%s: Bad `target`: 0x%04x", funcName, target);
return nullptr;
}
if (index >= bindings->size()) {
- ErrorInvalidOperation("%s: `index` >= %s.", funcName, maxIndexEnum);
+ ErrorInvalidValue("%s: `index` >= %s.", funcName, maxIndexEnum);
return nullptr;
}
return &(*bindings)[index];
}
////////////////////////////////////////
@@ -243,16 +243,21 @@ WebGLContext::BindBufferRange(GLenum tar
&indexedBinding))
{
return;
}
if (buffer && !buffer->ValidateCanBindToTarget(funcName, target))
return;
+ if (buffer && !size) {
+ ErrorInvalidValue("%s: size must be non-zero for non-null buffer.", funcName);
+ return;
+ }
+
////
gl->MakeCurrent();
switch (target) {
case LOCAL_GL_TRANSFORM_FEEDBACK_BUFFER:
if (offset % 4 != 0 || size % 4 != 0) {
ErrorInvalidValue("%s: For %s, `offset` and `size` must be multiples of 4.",
--- a/dom/canvas/WebGLFramebuffer.cpp
+++ b/dom/canvas/WebGLFramebuffer.cpp
@@ -922,16 +922,22 @@ WebGLFramebuffer::ValidateForRead(const
}
if (!mColorReadBuffer->IsDefined()) {
mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is not defined.",
funcName);
return false;
}
+ if (mColorReadBuffer->Samples()) {
+ mContext->ErrorInvalidOperation("%s: The READ_BUFFER attachment is multisampled.",
+ funcName);
+ return false;
+ }
+
*out_format = mColorReadBuffer->Format();
mColorReadBuffer->Size(out_width, out_height);
return true;
}
////////////////////////////////////////////////////////////////////////////////
// Resolution and caching
@@ -1245,16 +1251,22 @@ WebGLFramebuffer::RefreshReadBuffer() co
driverBuffer = mColorReadBuffer->mAttachmentPoint;
}
gl->fReadBuffer(driverBuffer);
}
////
+static bool
+IsDrawBufferEnum(const WebGLContext* webgl, GLenum val)
+{
+
+}
+
void
WebGLFramebuffer::DrawBuffers(const char* funcName, const dom::Sequence<GLenum>& buffers)
{
if (buffers.Length() > mContext->mImplMaxDrawBuffers) {
// "An INVALID_VALUE error is generated if `n` is greater than MAX_DRAW_BUFFERS."
mContext->ErrorInvalidValue("%s: `buffers` must have a length <="
" MAX_DRAW_BUFFERS.", funcName);
return;
@@ -1274,16 +1286,25 @@ WebGLFramebuffer::DrawBuffers(const char
// equal to that of the MAX_DRAW_BUFFERS_WEBGL parameter."
// This means that if buffers.Length() isn't larger than MaxDrawBuffers, it won't
// be larger than MaxColorAttachments.
const auto& cur = buffers[i];
if (cur == LOCAL_GL_COLOR_ATTACHMENT0 + i) {
const auto& attach = mColorAttachments[i];
newColorDrawBuffers.push_back(&attach);
} else if (cur != LOCAL_GL_NONE) {
+ const bool isColorEnum = (cur >= LOCAL_GL_COLOR_ATTACHMENT0 &&
+ cur < mContext->LastColorAttachmentEnum());
+ if (cur != LOCAL_GL_BACK &&
+ !isColorEnum)
+ {
+ mContext->ErrorInvalidEnum("%s: Unexpected enum in buffers.", funcName);
+ return;
+ }
+
mContext->ErrorInvalidOperation("%s: `buffers[i]` must be NONE or"
" COLOR_ATTACHMENTi.",
funcName);
return;
}
}
////
--- a/dom/canvas/WebGLRenderbuffer.cpp
+++ b/dom/canvas/WebGLRenderbuffer.cpp
@@ -200,17 +200,17 @@ WebGLRenderbuffer::RenderbufferStorage(c
mContext->MakeContextCurrent();
if (!usage->maxSamplesKnown) {
const_cast<webgl::FormatUsageInfo*>(usage)->ResolveMaxSamples(mContext->gl);
}
MOZ_ASSERT(usage->maxSamplesKnown);
if (samples > usage->maxSamples) {
- mContext->ErrorInvalidValue("%s: `samples` is out of the valid range.", funcName);
+ mContext->ErrorInvalidOperation("%s: `samples` is out of the valid range.", funcName);
return;
}
// Validation complete.
const GLenum error = DoRenderbufferStorage(samples, usage, width, height);
if (error) {
const char* errorName = mContext->ErrorName(error);