Bug 1259696 - Check read buffer mode when doing CopyTexImage. r=jgilbert

MozReview-Commit-ID: FYMiMaiRhii

--HG--
extra : rebase_source : 9f71a99d40df8430543d90f1eb64cda01d060b88
This commit is contained in:
Ethan Lin 2016-03-31 23:06:33 -07:00
Родитель 9c327300bf
Коммит d1268b5e73
8 изменённых файлов: 46 добавлений и 8 удалений

Просмотреть файл

@ -556,6 +556,7 @@ WebGL2Context::ReadBuffer(GLenum mode)
}
MakeContextCurrent();
mBoundReadFramebuffer->SetReadBufferMode(mode);
gl->fReadBuffer(mode);
return;
}

Просмотреть файл

@ -1803,7 +1803,8 @@ WebGLContext::DidRefresh()
bool
WebGLContext::ValidateCurFBForRead(const char* funcName,
const webgl::FormatUsageInfo** const out_format,
uint32_t* const out_width, uint32_t* const out_height)
uint32_t* const out_width, uint32_t* const out_height,
GLenum* const out_mode)
{
if (!mBoundReadFramebuffer) {
ClearBackbufferIfNeeded();
@ -1819,11 +1820,12 @@ WebGLContext::ValidateCurFBForRead(const char* funcName,
*out_width = mWidth;
*out_height = mHeight;
*out_mode = gl->Screen()->GetReadBufferMode();
return true;
}
return mBoundReadFramebuffer->ValidateForRead(funcName, out_format, out_width,
out_height);
out_height, out_mode);
}
////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -1287,7 +1287,8 @@ protected:
bool ValidateCurFBForRead(const char* funcName,
const webgl::FormatUsageInfo** const out_format,
uint32_t* const out_width, uint32_t* const out_height);
uint32_t* const out_width, uint32_t* const out_height,
GLenum* const out_mode);
void Invalidate();
void DestroyResourcesAndContext();

Просмотреть файл

@ -1571,7 +1571,8 @@ WebGLContext::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum
const webgl::FormatUsageInfo* srcFormat;
uint32_t srcWidth;
uint32_t srcHeight;
if (!ValidateCurFBForRead("readPixels", &srcFormat, &srcWidth, &srcHeight))
GLenum srcMode;
if (!ValidateCurFBForRead("readPixels", &srcFormat, &srcWidth, &srcHeight, &srcMode))
return;
// Check the format and type params to assure they are an acceptable pair (as per spec)

Просмотреть файл

@ -1146,7 +1146,8 @@ WebGLFramebuffer::FinalizeAttachments() const
bool
WebGLFramebuffer::ValidateForRead(const char* funcName,
const webgl::FormatUsageInfo** const out_format,
uint32_t* const out_width, uint32_t* const out_height)
uint32_t* const out_width, uint32_t* const out_height,
GLenum* const out_mode)
{
if (!ValidateAndInitAttachments(funcName))
return false;
@ -1164,6 +1165,7 @@ WebGLFramebuffer::ValidateForRead(const char* funcName,
return false;
}
*out_mode = mReadBufferMode;
*out_format = attachPoint->Format();
attachPoint->Size(out_width, out_height);
return true;

Просмотреть файл

@ -253,6 +253,10 @@ public:
return mDepthStencilAttachment;
}
void SetReadBufferMode(GLenum readBufferMode) {
mReadBufferMode = readBufferMode;
}
protected:
WebGLFBAttachPoint* GetAttachPoint(GLenum attachment); // Fallible
@ -280,7 +284,8 @@ public:
bool ValidateForRead(const char* info,
const webgl::FormatUsageInfo** const out_format,
uint32_t* const out_width, uint32_t* const out_height);
uint32_t* const out_width, uint32_t* const out_height,
GLenum* const out_mode);
JS::Value GetAttachmentParameter(const char* funcName, JSContext* cx, GLenum target,
GLenum attachment, GLenum pname,

Просмотреть файл

@ -1719,10 +1719,21 @@ WebGLTexture::CopyTexImage2D(TexImageTarget target, GLint level, GLenum internal
const webgl::FormatUsageInfo* srcUsage;
uint32_t srcWidth;
uint32_t srcHeight;
if (!mContext->ValidateCurFBForRead(funcName, &srcUsage, &srcWidth, &srcHeight))
GLenum srcMode;
if (!mContext->ValidateCurFBForRead(funcName, &srcUsage, &srcWidth, &srcHeight,
&srcMode))
return;
auto srcFormat = srcUsage->format;
// GLES 3.0.4 p145:
// "Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an
// INVALID_OPERATION error if any of the following conditions is true: READ_BUFFER
// is NONE"
if (srcMode == LOCAL_GL_NONE) {
mContext->ErrorInvalidOperation("%s: READ_BUFFER is NONE. ", funcName);
return;
}
////////////////////////////////////
// Check that source and dest info are compatible
@ -1869,10 +1880,21 @@ WebGLTexture::CopyTexSubImage(const char* funcName, TexImageTarget target, GLint
const webgl::FormatUsageInfo* srcUsage;
uint32_t srcWidth;
uint32_t srcHeight;
if (!mContext->ValidateCurFBForRead(funcName, &srcUsage, &srcWidth, &srcHeight))
GLenum srcMode;
if (!mContext->ValidateCurFBForRead(funcName, &srcUsage, &srcWidth, &srcHeight,
&srcMode))
return;
auto srcFormat = srcUsage->format;
// GLES 3.0.4 p145:
// "Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an
// INVALID_OPERATION error if any of the following conditions is true: READ_BUFFER
// is NONE"
if (srcMode == LOCAL_GL_NONE) {
mContext->ErrorInvalidOperation("%s: READ_BUFFER is NONE. ", funcName);
return;
}
////////////////////////////////////
// Check that source and dest info are compatible

Просмотреть файл

@ -232,6 +232,10 @@ public:
void SetReadBuffer(GLenum userMode);
void SetDrawBuffer(GLenum userMode);
GLenum GetReadBufferMode() const {
return mUserReadBufferMode;
}
/**
* Attempts to read pixels from the current bound framebuffer, if
* it is backed by a SharedSurface.