michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GLSHAREDHANDLEHELPERS_H_ michael@0: #define GLSHAREDHANDLEHELPERS_H_ michael@0: michael@0: #include "GLContextTypes.h" michael@0: #include "mozilla/gfx/Types.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gl { michael@0: michael@0: /** michael@0: * Create a new shared GLContext content handle, using the passed buffer as a source. michael@0: * Must be released by ReleaseSharedHandle. michael@0: */ michael@0: SharedTextureHandle CreateSharedHandle(GLContext* gl, michael@0: SharedTextureShareType shareType, michael@0: void* buffer, michael@0: SharedTextureBufferType bufferType); michael@0: michael@0: /** michael@0: * - It is better to call ReleaseSharedHandle before original GLContext destroyed, michael@0: * otherwise warning will be thrown on attempt to destroy Texture associated with SharedHandle, depends on backend implementation. michael@0: * - It does not require to be called on context where it was created, michael@0: * because SharedHandle suppose to keep Context reference internally, michael@0: * or don't require specific context at all, for example IPC SharedHandle. michael@0: * - Not recommended to call this between AttachSharedHandle and Draw Target call. michael@0: * if it is really required for some special backend, then DetachSharedHandle API must be added with related implementation. michael@0: * - It is recommended to stop any possible access to SharedHandle (Attachments, pending GL calls) before calling Release, michael@0: * otherwise some artifacts might appear or even crash if API backend implementation does not expect that. michael@0: * SharedHandle (currently EGLImage) does not require GLContext because it is EGL call, and can be destroyed michael@0: * at any time, unless EGLImage have siblings (which are not expected with current API). michael@0: */ michael@0: void ReleaseSharedHandle(GLContext* gl, michael@0: SharedTextureShareType shareType, michael@0: SharedTextureHandle sharedHandle); michael@0: michael@0: michael@0: typedef struct { michael@0: GLenum mTarget; michael@0: gfx::SurfaceFormat mTextureFormat; michael@0: gfx::Matrix4x4 mTextureTransform; michael@0: } SharedHandleDetails; michael@0: michael@0: /** michael@0: * Returns information necessary for rendering a shared handle. michael@0: * These values change depending on what sharing mechanism is in use michael@0: */ michael@0: bool GetSharedHandleDetails(GLContext* gl, michael@0: SharedTextureShareType shareType, michael@0: SharedTextureHandle sharedHandle, michael@0: SharedHandleDetails& details); michael@0: /** michael@0: * Attach Shared GL Handle to GL_TEXTURE_2D target michael@0: * GLContext must be current before this call michael@0: */ michael@0: bool AttachSharedHandle(GLContext* gl, michael@0: SharedTextureShareType shareType, michael@0: SharedTextureHandle sharedHandle); michael@0: michael@0: /** michael@0: * Detach Shared GL Handle from GL_TEXTURE_2D target michael@0: */ michael@0: void DetachSharedHandle(GLContext* gl, michael@0: SharedTextureShareType shareType, michael@0: SharedTextureHandle sharedHandle); michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif