Bug 1305540 - Lazily bind PBO targets. - r=ethlin

MozReview-Commit-ID: B9WiCNfNsfY
This commit is contained in:
Jeff Gilbert (:jgilbert) 2016-09-26 13:38:56 -07:00
Родитель cdccbe2abb
Коммит d74696d42b
7 изменённых файлов: 68 добавлений и 3 удалений

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

@ -395,15 +395,16 @@ TexUnpackBytes::TexOrSubImage(bool isSubImage, bool needsRespec, const char* fun
if (!isSubImage) {
// Alloc first to catch OOMs.
gl->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
AssertUintParamCorrect(gl, LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
*out_error = DoTexOrSubImage(false, gl, target, level, dui, xOffset, yOffset,
zOffset, mWidth, mHeight, mDepth, nullptr);
gl->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER,
webgl->mBoundPixelUnpackBuffer->mGLName);
if (*out_error)
return false;
}
const ScopedLazyBind bindPBO(gl, LOCAL_GL_PIXEL_UNPACK_BUFFER,
webgl->mBoundPixelUnpackBuffer);
//////
// Make our sometimes-implicit values explicit. Also this keeps them constant when we

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

@ -85,6 +85,8 @@ WebGL2Context::CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
}
gl->MakeCurrent();
const ScopedLazyBind readBind(gl, readTarget, readBuffer);
const ScopedLazyBind writeBind(gl, writeTarget, writeBuffer);
gl->fCopyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
}
@ -143,6 +145,7 @@ WebGL2Context::GetBufferSubData(GLenum target, GLintptr offset,
////
gl->MakeCurrent();
const ScopedLazyBind readBind(gl, target, buffer);
const auto ptr = gl->fMapBufferRange(target, offset, data.LengthAllowShared(),
LOCAL_GL_MAP_READ_BIT);

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

@ -114,6 +114,7 @@ WebGLBuffer::BufferData(GLenum target, size_t size, const void* data, GLenum usa
const auto& gl = mContext->gl;
gl->MakeCurrent();
const ScopedLazyBind lazyBind(gl, target, this);
mContext->InvalidateBufferFetching();
#ifdef XP_MACOSX

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

@ -2159,6 +2159,39 @@ ScopedFBRebinder::UnwrapImpl()
}
}
////////////////////
static GLenum
TargetIfLazy(GLenum target)
{
switch (target) {
case LOCAL_GL_PIXEL_PACK_BUFFER:
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
return target;
default:
return 0;
}
}
ScopedLazyBind::ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf)
: ScopedGLWrapper<ScopedLazyBind>(gl)
, mTarget(buf ? TargetIfLazy(target) : 0)
, mBuf(buf)
{
if (mTarget) {
mGL->fBindBuffer(mTarget, mBuf->mGLName);
}
}
void
ScopedLazyBind::UnwrapImpl()
{
if (mTarget) {
mGL->fBindBuffer(mTarget, 0);
}
}
////////////////////////////////////////
void

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

@ -1834,6 +1834,21 @@ private:
void UnwrapImpl();
};
class ScopedLazyBind final
: public gl::ScopedGLWrapper<ScopedLazyBind>
{
friend struct gl::ScopedGLWrapper<ScopedLazyBind>;
const GLenum mTarget;
const WebGLBuffer* const mBuf;
public:
ScopedLazyBind(gl::GLContext* gl, GLenum target, const WebGLBuffer* buf);
private:
void UnwrapImpl();
};
void
ComputeLengthAndData(const dom::ArrayBufferViewOrSharedArrayBufferView& view,
void** const out_data, size_t* const out_length,

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

@ -137,6 +137,13 @@ WebGLContext::BindBuffer(GLenum target, WebGLBuffer* buffer)
if (buffer) {
buffer->SetContentAfterBind(target);
}
switch (target) {
case LOCAL_GL_PIXEL_PACK_BUFFER:
case LOCAL_GL_PIXEL_UNPACK_BUFFER:
gl->fBindBuffer(target, 0);
break;
}
}
////////////////////////////////////////
@ -429,6 +436,8 @@ WebGLContext::BufferSubDataT(GLenum target,
}
MakeContextCurrent();
const ScopedLazyBind lazyBind(gl, target, buffer);
// Warning: Possibly shared memory. See bug 1225033.
gl->fBufferSubData(target, byteOffset, data.LengthAllowShared(),
data.DataAllowShared());

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

@ -1528,6 +1528,9 @@ WebGL2Context::ReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenu
bytesAfterOffset = checkedBytesAfterOffset.value();
}
gl->MakeCurrent();
const ScopedLazyBind lazyBind(gl, LOCAL_GL_PIXEL_PACK_BUFFER, mBoundPixelPackBuffer);
ReadPixelsImpl(x, y, width, height, format, type, (void*)offset, bytesAfterOffset);
}