Bug 1313541 - Texture impl. - r=ethlin

MozReview-Commit-ID: GEYMTnqC9Q3
This commit is contained in:
Jeff Gilbert (:jgilbert) 2016-10-11 18:54:59 -07:00
parent 73c6137df9
commit ab4d2d1cc5
5 changed files with 135 additions and 61 deletions

View File

@ -92,14 +92,44 @@ public:
void TexStorage3D(GLenum target, GLsizei levels, GLenum internalFormat, GLsizei width,
GLsizei height, GLsizei depth);
////
private:
void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
GLenum unpackType, const dom::Nullable<dom::ArrayBufferView>& data);
GLenum unpackType, const dom::ArrayBufferView* srcView,
GLuint srcElemOffset);
public:
void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeSrc)
{
const dom::ArrayBufferView* srcView = nullptr;
if (!maybeSrc.IsNull()) {
srcView = &maybeSrc.Value();
}
TexImage3D(target, level, internalFormat, width, height, depth, border,
unpackFormat, unpackType, srcView, 0);
}
void TexImage3D(GLenum target, GLint level, GLenum internalFormat, GLsizei width,
GLsizei height, GLsizei depth, GLint border, GLenum unpackFormat,
GLenum unpackType, const dom::ArrayBufferView& srcView,
GLuint srcElemOffset)
{
TexImage3D(target, level, internalFormat, width, height, depth, border,
unpackFormat, unpackType, &srcView, srcElemOffset);
}
////
void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
GLenum unpackFormat, GLenum unpackType,
const dom::ArrayBufferView& data, ErrorResult&);
const dom::ArrayBufferView& srcView, GLuint srcElemOffset,
ErrorResult&);
void TexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
GLint zOffset, GLenum unpackFormat, GLenum unpackType,
const dom::ImageData& data, ErrorResult&);
@ -107,16 +137,22 @@ public:
GLint zOffset, GLenum unpackFormat, GLenum unpackType,
const dom::Element& elem, ErrorResult& out_error);
////
void CopyTexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
GLint zOffset, GLint x, GLint y, GLsizei width,
GLsizei height);
////
void CompressedTexImage3D(GLenum target, GLint level, GLenum internalFormat,
GLsizei width, GLsizei height, GLsizei depth,
GLint border, const dom::ArrayBufferView& data);
GLsizei width, GLsizei height, GLsizei depth, GLint border,
const dom::ArrayBufferView& srcView, GLuint srcElemOffset);
void CompressedTexSubImage3D(GLenum target, GLint level, GLint xOffset, GLint yOffset,
GLint zOffset, GLsizei width, GLsizei height,
GLsizei depth, GLenum sizedUnpackFormat,
const dom::ArrayBufferView& data);
const dom::ArrayBufferView& srcView,
GLuint srcElemOffset);
////////////////
// Texture PBOs

View File

@ -45,7 +45,7 @@ void
WebGL2Context::TexImage3D(GLenum rawTexImageTarget, GLint level, GLenum internalFormat,
GLsizei width, GLsizei height, GLsizei depth, GLint border,
GLenum unpackFormat, GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeView)
const dom::ArrayBufferView>* srcView, GLuint srcElemOffset)
{
const char funcName[] = "texImage3D";
const uint8_t funcDims = 3;
@ -58,25 +58,21 @@ WebGL2Context::TexImage3D(GLenum rawTexImageTarget, GLint level, GLenum internal
return;
}
const dom::ArrayBufferView* view = nullptr;
if (!maybeView.IsNull()) {
view = &maybeView.Value();
}
const bool isSubImage = false;
const GLint xOffset = 0;
const GLint yOffset = 0;
const GLint zOffset = 0;
tex->TexOrSubImage(isSubImage, funcName, target, level, internalFormat, xOffset,
yOffset, zOffset, width, height, depth, border, unpackFormat,
unpackType, view);
unpackType, view, srcElemOffset);
}
void
WebGL2Context::TexSubImage3D(GLenum rawTexImageTarget, GLint level, GLint xOffset,
GLint yOffset, GLint zOffset, GLsizei width, GLsizei height,
GLsizei depth, GLenum unpackFormat, GLenum unpackType,
const dom::ArrayBufferView& view, ErrorResult&)
const dom::ArrayBufferView& srcView, GLuint srcElemOffset,
ErrorResult&)
{
const char funcName[] = "texSubImage3D";
const uint8_t funcDims = 3;
@ -94,7 +90,7 @@ WebGL2Context::TexSubImage3D(GLenum rawTexImageTarget, GLint level, GLint xOffse
const GLint border = 0;
tex->TexOrSubImage(isSubImage, funcName, target, level, internalFormat, xOffset,
yOffset, zOffset, width, height, depth, border, unpackFormat,
unpackType, &view);
unpackType, &srcView, srcElemOffset);
}
void
@ -147,7 +143,8 @@ void
WebGL2Context::CompressedTexImage3D(GLenum rawTexImageTarget, GLint level,
GLenum internalFormat, GLsizei width, GLsizei height,
GLsizei depth, GLint border,
const dom::ArrayBufferView& view)
const dom::ArrayBufferView& srcView,
GLuint srcElemOffset)
{
const char funcName[] = "compressedTexImage3D";
const uint8_t funcDims = 3;
@ -161,7 +158,7 @@ WebGL2Context::CompressedTexImage3D(GLenum rawTexImageTarget, GLint level,
}
tex->CompressedTexImage(funcName, target, level, internalFormat, width, height, depth,
border, view);
border, view, srcElemOffset);
}
void
@ -169,7 +166,8 @@ WebGL2Context::CompressedTexSubImage3D(GLenum rawTexImageTarget, GLint level,
GLint xOffset, GLint yOffset, GLint zOffset,
GLsizei width, GLsizei height, GLsizei depth,
GLenum sizedUnpackFormat,
const dom::ArrayBufferView& view)
const dom::ArrayBufferView& srcView,
GLuint srcElemOffset)
{
const char funcName[] = "compressedTexSubImage3D";
const uint8_t funcDims = 3;
@ -183,7 +181,7 @@ WebGL2Context::CompressedTexSubImage3D(GLenum rawTexImageTarget, GLint level,
}
tex->CompressedTexSubImage(funcName, target, level, xOffset, yOffset, zOffset, width,
height, depth, sizedUnpackFormat, view);
height, depth, sizedUnpackFormat, view, srcElemOffset);
}
void

View File

@ -887,7 +887,21 @@ public:
GLsizei width, GLsizei height, GLint border, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeView,
ErrorResult&);
ErrorResult& out_error)
{
if (IsContextLost())
return;
TexImage2D(texImageTarget, level, internalFormat, width, height, border,
unpackFormat, unpackType, maybeView, 0, out_error);
}
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLsizei width, GLsizei height, GLint border, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeSrc,
GLuint srcElemOffset, ErrorResult&);
protected:
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLenum unpackFormat, GLenum unpackType,
@ -912,35 +926,23 @@ public:
ErrorResult& out_error);
////////////////
// Pseudo-nullable WebGL1 entrypoints
// dom::ImageData
void TexImage2D(GLenum texImageTarget, GLint level, GLenum internalFormat,
GLenum unpackFormat, GLenum unpackType,
const dom::ImageData* imageData, ErrorResult& out_error)
{
const char funcName[] = "texImage2D";
if (!imageData) {
ErrorInvalidValue("%s: `data` must not be null.", funcName);
if (IsContextLost())
return;
}
if (!imageData)
return ErrorInvalidValue("%s: `data` must not be null.", funcName);
TexImage2D(texImageTarget, level, internalFormat, unpackFormat, unpackType,
*imageData, out_error);
}
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLsizei width, GLsizei height, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeView, ErrorResult&)
{
const char funcName[] = "texSubImage2D";
if (maybeView.IsNull()) {
ErrorInvalidValue("%s: `data` must not be null.", funcName);
return;
}
TexSubImage2D(texImageTarget, level, xOffset, yOffset, width, height,
unpackFormat, unpackType, maybeView.Value());
}
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLenum unpackFormat, GLenum unpackType,
const dom::ImageData* imageData, ErrorResult& out_error)
@ -954,6 +956,32 @@ public:
*imageData, out_error);
}
////
// ArrayBufferView
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLsizei width, GLsizei height, GLenum unpackFormat,
GLenum unpackType,
const dom::Nullable<dom::ArrayBufferView>& maybeSrc,
ErrorResult& out_error)
{
const char funcName[] = "texSubImage2D";
if (IsContextLost())
return;
if (maybeSrc.IsNull())
return ErrorInvalidValue("%s: `data` must not be null.", funcName);
TexSubImage2D(texImageTarget, level, xOffset, yOffset, width, height,
unpackFormat, unpackType, maybeView.Value(), 0, out_error);
}
void TexSubImage2D(GLenum texImageTarget, GLint level, GLint xOffset, GLint yOffset,
GLsizei width, GLsizei height, GLenum unpackFormat,
GLenum unpackType,
const dom::ArrayBufferView& srcView, GLuint srcElemOffset,
ErrorResult&);
//////
// WebGLTextureUpload.cpp
public:

View File

@ -236,7 +236,7 @@ public:
GLint level, GLenum internalFormat, GLint xOffset, GLint yOffset,
GLint zOffset, GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum unpackFormat, GLenum unpackType,
const dom::ArrayBufferView* view);
const dom::ArrayBufferView* srcView, GLuint srcElemOffset);
void TexOrSubImage(bool isSubImage, const char* funcName, TexImageTarget target,
GLint level, GLenum internalFormat, GLint xOffset, GLint yOffset,
@ -288,11 +288,11 @@ public:
void CompressedTexImage(const char* funcName, TexImageTarget target, GLint level,
GLenum internalFormat, GLsizei width, GLsizei height,
GLsizei depth, GLint border,
const dom::ArrayBufferView& view);
const dom::ArrayBufferView& srcView, GLuint srcElemOffset);
void CompressedTexSubImage(const char* funcName, TexImageTarget target, GLint level,
GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width,
GLsizei height, GLsizei depth, GLenum sizedUnpackFormat,
const dom::ArrayBufferView& view);
const dom::ArrayBufferView& srcView, GLuint srcElemOffset);
void CopyTexImage2D(TexImageTarget target, GLint level, GLenum internalFormat,
GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
void CopyTexSubImage(const char* funcName, TexImageTarget target, GLint level,

View File

@ -183,7 +183,7 @@ WebGLContext::ValidateUnpackPixels(const char* funcName, uint32_t fullRows,
static bool
ValidateUnpackBytes(WebGLContext* webgl, const char* funcName, uint32_t width,
uint32_t height, uint32_t depth, const webgl::PackingInfo& pi,
uint32_t byteCount, webgl::TexUnpackBlob* blob)
size_t byteCount, webgl::TexUnpackBlob* blob)
{
if (!width || !height || !depth)
return true;
@ -240,7 +240,7 @@ WebGLTexture::TexOrSubImage(bool isSubImage, const char* funcName, TexImageTarge
GLint yOffset, GLint zOffset, GLsizei rawWidth,
GLsizei rawHeight, GLsizei rawDepth, GLint border,
GLenum unpackFormat, GLenum unpackType,
const dom::ArrayBufferView* view)
const dom::ArrayBufferView* srcView, GLuint srcElemOffset)
{
uint32_t width, height, depth;
if (!ValidateExtents(mContext, funcName, rawWidth, rawHeight, rawDepth, border,
@ -257,19 +257,21 @@ WebGLTexture::TexOrSubImage(bool isSubImage, const char* funcName, TexImageTarge
////
const uint8_t* bytes = nullptr;
uint32_t byteCount = 0;
size_t byteCount = 0;
if (view) {
view->ComputeLengthAndData();
bytes = view->DataAllowShared();
byteCount = view->LengthAllowShared();
const auto& jsType = view->Type();
if (srcView) {
const auto& jsType = srcView->Type();
if (!DoesJSTypeMatchUnpackType(pi.type, jsType)) {
mContext->ErrorInvalidOperation("%s: `pixels` not compatible with `type`.",
funcName);
return;
}
if (!mContext->ValidateArrayBufferView(funcName, *srcView, srcElemOffset, 0,
&bytes, &byteCount))
{
return;
}
} else if (isSubImage) {
mContext->ErrorInvalidValue("%s: `pixels` must not be null.", funcName);
return;
@ -1451,7 +1453,8 @@ void
WebGLTexture::CompressedTexImage(const char* funcName, TexImageTarget target, GLint level,
GLenum internalFormat, GLsizei rawWidth,
GLsizei rawHeight, GLsizei rawDepth, GLint border,
const dom::ArrayBufferView& view)
const dom::ArrayBufferView& srcView,
GLuint srcElemOffset)
{
uint32_t width, height, depth;
if (!ValidateExtents(mContext, funcName, rawWidth, rawHeight, rawDepth, border,
@ -1491,12 +1494,16 @@ WebGLTexture::CompressedTexImage(const char* funcName, TexImageTarget target, GL
////////////////////////////////////
// Get source info
view.ComputeLengthAndData();
const void* data = view.DataAllowShared();
size_t dataSize = view.LengthAllowShared();
uint8_t* bytes;
size_t byteLen;
if (!mContext->ValidateArrayBufferView(funcName, srcView, srcElemOffset, 0, &bytes,
&byteLen))
{
return;
}
if (!ValidateCompressedTexUnpack(mContext, funcName, width, height, depth, format,
dataSize))
byteLen))
{
return;
}
@ -1517,7 +1524,7 @@ WebGLTexture::CompressedTexImage(const char* funcName, TexImageTarget target, GL
// Warning: Possibly shared memory. See bug 1225033.
GLenum error = DoCompressedTexImage(mContext->gl, target, level, internalFormat,
width, height, depth, dataSize, data);
width, height, depth, byteLen, bytes);
if (error == LOCAL_GL_OUT_OF_MEMORY) {
mContext->ErrorOutOfMemory("%s: Ran out of memory during upload.", funcName);
return;
@ -1564,7 +1571,8 @@ WebGLTexture::CompressedTexSubImage(const char* funcName, TexImageTarget target,
GLint level, GLint xOffset, GLint yOffset,
GLint zOffset, GLsizei rawWidth, GLsizei rawHeight,
GLsizei rawDepth, GLenum sizedUnpackFormat,
const dom::ArrayBufferView& view)
const dom::ArrayBufferView& srcView,
GLuint srcElemOffset)
{
uint32_t width, height, depth;
if (!ValidateExtents(mContext, funcName, rawWidth, rawHeight, rawDepth, 0, &width,
@ -1590,9 +1598,13 @@ WebGLTexture::CompressedTexSubImage(const char* funcName, TexImageTarget target,
////////////////////////////////////
// Get source info
view.ComputeLengthAndData();
size_t dataSize = view.LengthAllowShared();
const void* data = view.DataAllowShared();
uint8_t* bytes;
size_t byteLen;
if (!mContext->ValidateArrayBufferView(funcName, srcView, srcElemOffset, 0, &bytes,
&byteLen))
{
return;
}
auto srcUsage = mContext->mFormatUsage->GetSizedTexUsage(sizedUnpackFormat);
if (!srcUsage->format->compression) {
@ -1610,7 +1622,7 @@ WebGLTexture::CompressedTexSubImage(const char* funcName, TexImageTarget target,
auto format = srcUsage->format;
MOZ_ASSERT(format == dstFormat);
if (!ValidateCompressedTexUnpack(mContext, funcName, width, height, depth, format,
dataSize))
byteLen))
{
return;
}
@ -1669,7 +1681,7 @@ WebGLTexture::CompressedTexSubImage(const char* funcName, TexImageTarget target,
// Warning: Possibly shared memory. See bug 1225033.
GLenum error = DoCompressedTexSubImage(mContext->gl, target, level, xOffset, yOffset,
zOffset, width, height, depth,
sizedUnpackFormat, dataSize, data);
sizedUnpackFormat, byteLen, bytes);
if (error == LOCAL_GL_OUT_OF_MEMORY) {
mContext->ErrorOutOfMemory("%s: Ran out of memory during upload.", funcName);
return;