EGLImage CopySurface(layers::Image* img) { mGLContext->MakeCurrent(); GLuint tex = CreateTextureForOffscreen(mGLContext, mGLContext->GetGLFormats(), img->GetSize()); auto helper = mGLContext->BlitHelper(); const gl::OriginPos destOrigin = gl::OriginPos::TopLeft; if (!helper->BlitImageToTexture(img, img->GetSize(), tex, LOCAL_GL_TEXTURE_2D, destOrigin)) { mGLContext->fDeleteTextures(1, &tex); return nullptr; } EGLint attribs[] = { LOCAL_EGL_IMAGE_PRESERVED_KHR, LOCAL_EGL_TRUE, LOCAL_EGL_NONE, LOCAL_EGL_NONE }; EGLContext eglContext = static_cast<GLContextEGL*>(mGLContext.get())->GetEGLContext(); EGLImage eglImage = sEGLLibrary.fCreateImage(EGL_DISPLAY(), eglContext, LOCAL_EGL_GL_TEXTURE_2D_KHR, (EGLClientBuffer)tex, attribs); mGLContext->fDeleteTextures(1, &tex); return eglImage; }
static bool CreateTexturePipe(GLLibraryEGL* const egl, GLContext* const gl, const GLFormats& formats, const gfx::IntSize& size, GLuint* const out_tex, EGLImage* const out_image) { MOZ_ASSERT(out_tex && out_image); *out_tex = 0; *out_image = 0; GLuint tex = CreateTextureForOffscreen(gl, formats, size); if (!tex) return false; EGLContext context = GLContextEGL::Cast(gl)->GetEGLContext(); MOZ_ASSERT(context); EGLClientBuffer buffer = reinterpret_cast<EGLClientBuffer>(tex); EGLImage image = egl->fCreateImage(egl->Display(), context, LOCAL_EGL_GL_TEXTURE_2D, buffer, nullptr); if (!image) { gl->fDeleteTextures(1, &tex); return false; } // Success. *out_tex = tex; *out_image = image; return true; }
SharedSurface_EGLImage* SharedSurface_EGLImage::Create(GLContext* prodGL, const GLFormats& formats, const gfx::IntSize& size, bool hasAlpha, EGLContext context) { GLLibraryEGL* egl = &sEGLLibrary; MOZ_ASSERT(egl); MOZ_ASSERT(context); if (!HasExtensions(egl, prodGL)) { return nullptr; } MOZ_ALWAYS_TRUE(prodGL->MakeCurrent()); GLuint prodTex = CreateTextureForOffscreen(prodGL, formats, size); if (!prodTex) { return nullptr; } EGLClientBuffer buffer = reinterpret_cast<EGLClientBuffer>(prodTex); EGLImage image = egl->fCreateImage(egl->Display(), context, LOCAL_EGL_GL_TEXTURE_2D, buffer, nullptr); if (!image) { prodGL->fDeleteTextures(1, &prodTex); return nullptr; } return new SharedSurface_EGLImage(prodGL, egl, size, hasAlpha, formats, prodTex, image); }
SharedSurface_EGLImage* SharedSurface_EGLImage::Create(GLContext* prodGL, const GLFormats& formats, const gfx::IntSize& size, bool hasAlpha, EGLContext context) { GLLibraryEGL* egl = &sEGLLibrary; MOZ_ASSERT(egl); if (!HasExtensions(egl, prodGL)) return nullptr; MOZ_ALWAYS_TRUE(prodGL->MakeCurrent()); GLuint prodTex = CreateTextureForOffscreen(prodGL, formats, size); if (!prodTex) return nullptr; return new SharedSurface_EGLImage(prodGL, egl, size, hasAlpha, formats, prodTex); }
SharedSurface_GLTexture* SharedSurface_GLTexture::Create(GLContext* prodGL, GLContext* consGL, const GLFormats& formats, const gfx::IntSize& size, bool hasAlpha, GLuint texture) { MOZ_ASSERT(prodGL); MOZ_ASSERT(!consGL || prodGL->SharesWith(consGL)); prodGL->MakeCurrent(); GLuint tex = texture; bool ownsTex = false; if (!tex) { tex = CreateTextureForOffscreen(prodGL, formats, size); ownsTex = true; } return new SharedSurface_GLTexture(prodGL, consGL, size, hasAlpha, tex, ownsTex); }