Bug 1045955 - Fix compositing for screen-based WebGL ShSurfs. - r=kamidphish

This commit is contained in:
Jeff Gilbert 2014-07-30 10:03:07 -07:00
parent 457db03869
commit d90bab70f8
4 changed files with 66 additions and 26 deletions

View File

@ -1477,9 +1477,13 @@ WebGLContext::GetSurfaceSnapshot(bool* aPremultAlpha)
if (!gl)
return nullptr;
RefPtr<DataSourceSurface> surf = Factory::CreateDataSourceSurfaceWithStride(IntSize(mWidth, mHeight),
SurfaceFormat::B8G8R8A8,
mWidth * 4);
bool hasAlpha = mOptions.alpha;
SurfaceFormat surfFormat = hasAlpha ? SurfaceFormat::B8G8R8A8
: SurfaceFormat::B8G8R8X8;
RefPtr<DataSourceSurface> surf;
surf = Factory::CreateDataSourceSurfaceWithStride(IntSize(mWidth, mHeight),
surfFormat,
mWidth * 4);
if (!surf) {
return nullptr;
}

View File

@ -546,7 +546,8 @@ GLBlitHelper::DeleteTexBlitProgram()
void
GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize)
const gfx::IntSize& destSize,
bool internalFBs)
{
MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
@ -556,8 +557,13 @@ GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
ScopedBindFramebuffer boundFB(mGL);
ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false);
mGL->BindReadFB(srcFB);
mGL->BindDrawFB(destFB);
if (internalFBs) {
mGL->Screen()->BindReadFB_Internal(srcFB);
mGL->Screen()->BindDrawFB_Internal(destFB);
} else {
mGL->BindReadFB(srcFB);
mGL->BindDrawFB(destFB);
}
mGL->fBlitFramebuffer(0, 0, srcSize.width, srcSize.height,
0, 0, destSize.width, destSize.height,
@ -569,22 +575,24 @@ void
GLBlitHelper::BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
const GLFormats& srcFormats)
const GLFormats& srcFormats,
bool internalFBs)
{
MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
if (mGL->IsSupported(GLFeature::framebuffer_blit)) {
BlitFramebufferToFramebuffer(srcFB, destFB,
srcSize, destSize);
srcSize, destSize,
internalFBs);
return;
}
GLuint tex = CreateTextureForOffscreen(mGL, srcFormats, srcSize);
MOZ_ASSERT(tex);
BlitFramebufferToTexture(srcFB, tex, srcSize, srcSize);
BlitTextureToFramebuffer(tex, destFB, srcSize, destSize);
BlitFramebufferToTexture(srcFB, tex, srcSize, srcSize, internalFBs);
BlitTextureToFramebuffer(tex, destFB, srcSize, destSize, internalFBs);
mGL->fDeleteTextures(1, &tex);
}
@ -782,7 +790,8 @@ void
GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
GLenum srcTarget)
GLenum srcTarget,
bool internalFBs)
{
MOZ_ASSERT(mGL->fIsTexture(srcTex));
MOZ_ASSERT(!destFB || mGL->fIsFramebuffer(destFB));
@ -792,7 +801,8 @@ GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
MOZ_ASSERT(srcWrapper.IsComplete());
BlitFramebufferToFramebuffer(srcWrapper.FB(), destFB,
srcSize, destSize);
srcSize, destSize,
internalFBs);
return;
}
@ -813,6 +823,12 @@ GLBlitHelper::BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
ScopedGLDrawState autoStates(mGL);
if (internalFBs) {
mGL->Screen()->BindDrawFB_Internal(destFB);
} else {
mGL->BindDrawFB(destFB);
}
// Does destructive things to (only!) what we just saved above.
bool good = UseTexQuadProgram(type, srcSize);
if (!good) {
@ -828,7 +844,8 @@ void
GLBlitHelper::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
GLenum destTarget)
GLenum destTarget,
bool internalFBs)
{
MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB));
MOZ_ASSERT(mGL->fIsTexture(destTex));
@ -837,14 +854,20 @@ GLBlitHelper::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
ScopedFramebufferForTexture destWrapper(mGL, destTex, destTarget);
BlitFramebufferToFramebuffer(srcFB, destWrapper.FB(),
srcSize, destSize);
srcSize, destSize, internalFBs);
return;
}
ScopedBindTexture autoTex(mGL, destTex, destTarget);
ScopedBindFramebuffer boundFB(mGL, srcFB);
ScopedBindFramebuffer boundFB(mGL);
ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false);
if (internalFBs) {
mGL->Screen()->BindReadFB_Internal(srcFB);
} else {
mGL->BindReadFB(srcFB);
}
mGL->fCopyTexSubImage2D(destTarget, 0,
0, 0,
0, 0,

View File

@ -153,27 +153,34 @@ public:
// the first BlitFramebufferToFramebuffer.
void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize);
const gfx::IntSize& destSize,
bool internalFBs = false);
void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
const GLFormats& srcFormats);
const GLFormats& srcFormats,
bool internalFBs = false);
void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
GLenum srcTarget = LOCAL_GL_TEXTURE_2D);
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
bool internalFBs = false);
void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
GLenum destTarget = LOCAL_GL_TEXTURE_2D);
GLenum destTarget = LOCAL_GL_TEXTURE_2D,
bool internalFBs = false);
void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
const gfx::IntSize& srcSize,
const gfx::IntSize& destSize,
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
GLenum destTarget = LOCAL_GL_TEXTURE_2D);
bool BlitImageToTexture(layers::Image* srcImage, const gfx::IntSize& destSize,
GLuint destTex, GLenum destTarget, bool yFlip = false, GLuint xoffset = 0,
GLuint yoffset = 0, GLuint width = 0, GLuint height = 0);
bool BlitImageToTexture(layers::Image* srcImage,
const gfx::IntSize& destSize,
GLuint destTex, GLenum destTarget,
bool yFlip = false,
GLuint xoffset = 0, GLuint yoffset = 0,
GLuint width = 0, GLuint height = 0);
};
}

View File

@ -59,13 +59,16 @@ SharedSurface::ProdCopy(SharedSurface* src, SharedSurface* dest,
GLuint destTex = dest->ProdTexture();
GLenum destTarget = dest->ProdTextureTarget();
gl->BlitHelper()->BlitFramebufferToTexture(0, destTex, src->mSize, dest->mSize, destTarget);
gl->BlitHelper()->BlitFramebufferToTexture(0, destTex,
src->mSize, dest->mSize,
destTarget, true);
} else if (dest->mAttachType == AttachmentType::GLRenderbuffer) {
GLuint destRB = dest->ProdRenderbuffer();
ScopedFramebufferForRenderbuffer destWrapper(gl, destRB);
gl->BlitHelper()->BlitFramebufferToFramebuffer(0, destWrapper.FB(),
src->mSize, dest->mSize);
src->mSize, dest->mSize,
true);
} else {
MOZ_CRASH("Unhandled dest->mAttachType.");
}
@ -97,13 +100,16 @@ SharedSurface::ProdCopy(SharedSurface* src, SharedSurface* dest,
GLuint srcTex = src->ProdTexture();
GLenum srcTarget = src->ProdTextureTarget();
gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, 0, src->mSize, dest->mSize, srcTarget);
gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, 0,
src->mSize, dest->mSize,
srcTarget, true);
} else if (src->mAttachType == AttachmentType::GLRenderbuffer) {
GLuint srcRB = src->ProdRenderbuffer();
ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB);
gl->BlitHelper()->BlitFramebufferToFramebuffer(srcWrapper.FB(), 0,
src->mSize, dest->mSize);
src->mSize, dest->mSize,
true);
} else {
MOZ_CRASH("Unhandled src->mAttachType.");
}