void GLBlitHelper::BlitFramebufferToTexture(GLuint srcFB, GLuint destTex, const gfxIntSize& srcSize, const gfxIntSize& destSize, GLenum destTarget) { MOZ_ASSERT(!srcFB || mGL->fIsFramebuffer(srcFB)); MOZ_ASSERT(mGL->fIsTexture(destTex)); if (mGL->IsSupported(GLFeature::framebuffer_blit)) { ScopedFramebufferForTexture destWrapper(mGL, destTex, destTarget); BlitFramebufferToFramebuffer(srcFB, destWrapper.FB(), srcSize, destSize); return; } ScopedBindTexture autoTex(mGL, destTex, destTarget); ScopedBindFramebuffer boundFB(mGL, srcFB); ScopedGLState scissor(mGL, LOCAL_GL_SCISSOR_TEST, false); mGL->fCopyTexSubImage2D(destTarget, 0, 0, 0, 0, 0, srcSize.width, srcSize.height); }
/*static*/ void SharedSurface::ProdCopy(SharedSurface* src, SharedSurface* dest, SurfaceFactory* factory) { GLContext* gl = src->mGL; // If `src` begins locked, it must end locked, though we may // temporarily unlock it if we need to. MOZ_ASSERT((src == gl->GetLockedSurface()) == src->IsLocked()); gl->MakeCurrent(); if (src->mAttachType == AttachmentType::Screen && dest->mAttachType == AttachmentType::Screen) { // Here, we actually need to blit through a temp surface, so let's make one. nsAutoPtr<SharedSurface_GLTexture> tempSurf; tempSurf = SharedSurface_GLTexture::Create(gl, gl, factory->mFormats, src->mSize, factory->mCaps.alpha); ProdCopy(src, tempSurf, factory); ProdCopy(tempSurf, dest, factory); return; } if (src->mAttachType == AttachmentType::Screen) { SharedSurface* origLocked = gl->GetLockedSurface(); bool srcNeedsUnlock = false; bool origNeedsRelock = false; if (origLocked != src) { if (origLocked) { origLocked->UnlockProd(); origNeedsRelock = true; } src->LockProd(); srcNeedsUnlock = true; } if (dest->mAttachType == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitFramebufferToTexture(0, destTex, src->mSize, dest->mSize, destTarget); } else if (dest->mAttachType == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(0, destWrapper.FB(), src->mSize, dest->mSize); } else { MOZ_CRASH("Unhandled dest->mAttachType."); } if (srcNeedsUnlock) src->UnlockProd(); if (origNeedsRelock) origLocked->LockProd(); return; } if (dest->mAttachType == AttachmentType::Screen) { SharedSurface* origLocked = gl->GetLockedSurface(); bool destNeedsUnlock = false; bool origNeedsRelock = false; if (origLocked != dest) { if (origLocked) { origLocked->UnlockProd(); origNeedsRelock = true; } dest->LockProd(); destNeedsUnlock = true; } if (src->mAttachType == AttachmentType::GLTexture) { GLuint srcTex = src->ProdTexture(); GLenum srcTarget = src->ProdTextureTarget(); gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, 0, src->mSize, dest->mSize, srcTarget); } else if (src->mAttachType == AttachmentType::GLRenderbuffer) { GLuint srcRB = src->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(srcWrapper.FB(), 0, src->mSize, dest->mSize); } else { MOZ_CRASH("Unhandled src->mAttachType."); } if (destNeedsUnlock) dest->UnlockProd(); if (origNeedsRelock) origLocked->LockProd(); return; } // Alright, done with cases involving Screen types. // Only {src,dest}x{texture,renderbuffer} left. if (src->mAttachType == AttachmentType::GLTexture) { GLuint srcTex = src->ProdTexture(); GLenum srcTarget = src->ProdTextureTarget(); if (dest->mAttachType == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitTextureToTexture(srcTex, destTex, src->mSize, dest->mSize, srcTarget, destTarget); return; } if (dest->mAttachType == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, destWrapper.FB(), src->mSize, dest->mSize, srcTarget); return; } MOZ_CRASH("Unhandled dest->mAttachType."); } if (src->mAttachType == AttachmentType::GLRenderbuffer) { GLuint srcRB = src->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB); if (dest->mAttachType == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitFramebufferToTexture(srcWrapper.FB(), destTex, src->mSize, dest->mSize, destTarget); return; } if (dest->mAttachType == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(srcWrapper.FB(), destWrapper.FB(), src->mSize, dest->mSize); return; } MOZ_CRASH("Unhandled dest->mAttachType."); } MOZ_CRASH("Unhandled src->mAttachType."); }
// |src| must begin and end locked, though we may // temporarily unlock it if we need to. void SharedSurface_GL::ProdCopy(SharedSurface_GL* src, SharedSurface_GL* dest, SurfaceFactory_GL* factory) { GLContext* gl = src->GL(); gl->MakeCurrent(); if (src->AttachType() == AttachmentType::Screen && dest->AttachType() == AttachmentType::Screen) { // Here, we actually need to blit through a temp surface, so let's make one. nsAutoPtr<SharedSurface_GLTexture> tempSurf( SharedSurface_GLTexture::Create(gl, gl, factory->Formats(), src->Size(), factory->Caps().alpha)); ProdCopy(src, tempSurf, factory); ProdCopy(tempSurf, dest, factory); return; } if (src->AttachType() == AttachmentType::Screen) { SharedSurface_GL* origLocked = gl->GetLockedSurface(); bool srcNeedsUnlock = false; bool origNeedsRelock = false; if (origLocked != src) { if (origLocked) { origLocked->UnlockProd(); origNeedsRelock = true; } src->LockProd(); srcNeedsUnlock = true; } if (dest->AttachType() == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitFramebufferToTexture(0, destTex, src->Size(), dest->Size(), destTarget); } else if (dest->AttachType() == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(0, destWrapper.FB(), src->Size(), dest->Size()); } else { MOZ_CRASH("Unhandled dest->AttachType()."); } if (srcNeedsUnlock) src->UnlockProd(); if (origNeedsRelock) origLocked->LockProd(); return; } if (dest->AttachType() == AttachmentType::Screen) { SharedSurface_GL* origLocked = gl->GetLockedSurface(); bool destNeedsUnlock = false; bool origNeedsRelock = false; if (origLocked != dest) { if (origLocked) { origLocked->UnlockProd(); origNeedsRelock = true; } dest->LockProd(); destNeedsUnlock = true; } if (src->AttachType() == AttachmentType::GLTexture) { GLuint srcTex = src->ProdTexture(); GLenum srcTarget = src->ProdTextureTarget(); gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, 0, src->Size(), dest->Size(), srcTarget); } else if (src->AttachType() == AttachmentType::GLRenderbuffer) { GLuint srcRB = src->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(srcWrapper.FB(), 0, src->Size(), dest->Size()); } else { MOZ_CRASH("Unhandled src->AttachType()."); } if (destNeedsUnlock) dest->UnlockProd(); if (origNeedsRelock) origLocked->LockProd(); return; } // Alright, done with cases involving Screen types. // Only {src,dest}x{texture,renderbuffer} left. if (src->AttachType() == AttachmentType::GLTexture) { GLuint srcTex = src->ProdTexture(); GLenum srcTarget = src->ProdTextureTarget(); if (dest->AttachType() == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitTextureToTexture(srcTex, destTex, src->Size(), dest->Size(), srcTarget, destTarget); return; } if (dest->AttachType() == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitTextureToFramebuffer(srcTex, destWrapper.FB(), src->Size(), dest->Size(), srcTarget); return; } MOZ_CRASH("Unhandled dest->AttachType()."); } if (src->AttachType() == AttachmentType::GLRenderbuffer) { GLuint srcRB = src->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer srcWrapper(gl, srcRB); if (dest->AttachType() == AttachmentType::GLTexture) { GLuint destTex = dest->ProdTexture(); GLenum destTarget = dest->ProdTextureTarget(); gl->BlitHelper()->BlitFramebufferToTexture(srcWrapper.FB(), destTex, src->Size(), dest->Size(), destTarget); return; } if (dest->AttachType() == AttachmentType::GLRenderbuffer) { GLuint destRB = dest->ProdRenderbuffer(); ScopedFramebufferForRenderbuffer destWrapper(gl, destRB); gl->BlitHelper()->BlitFramebufferToFramebuffer(srcWrapper.FB(), destWrapper.FB(), src->Size(), dest->Size()); return; } MOZ_CRASH("Unhandled dest->AttachType()."); } MOZ_CRASH("Unhandled src->AttachType()."); }