1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/gl/GLSharedHandleHelpers.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef GLSHAREDHANDLEHELPERS_H_ 1.9 +#define GLSHAREDHANDLEHELPERS_H_ 1.10 + 1.11 +#include "GLContextTypes.h" 1.12 +#include "mozilla/gfx/Types.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace gl { 1.16 + 1.17 +/** 1.18 + * Create a new shared GLContext content handle, using the passed buffer as a source. 1.19 + * Must be released by ReleaseSharedHandle. 1.20 + */ 1.21 +SharedTextureHandle CreateSharedHandle(GLContext* gl, 1.22 + SharedTextureShareType shareType, 1.23 + void* buffer, 1.24 + SharedTextureBufferType bufferType); 1.25 + 1.26 +/** 1.27 + * - It is better to call ReleaseSharedHandle before original GLContext destroyed, 1.28 + * otherwise warning will be thrown on attempt to destroy Texture associated with SharedHandle, depends on backend implementation. 1.29 + * - It does not require to be called on context where it was created, 1.30 + * because SharedHandle suppose to keep Context reference internally, 1.31 + * or don't require specific context at all, for example IPC SharedHandle. 1.32 + * - Not recommended to call this between AttachSharedHandle and Draw Target call. 1.33 + * if it is really required for some special backend, then DetachSharedHandle API must be added with related implementation. 1.34 + * - It is recommended to stop any possible access to SharedHandle (Attachments, pending GL calls) before calling Release, 1.35 + * otherwise some artifacts might appear or even crash if API backend implementation does not expect that. 1.36 + * SharedHandle (currently EGLImage) does not require GLContext because it is EGL call, and can be destroyed 1.37 + * at any time, unless EGLImage have siblings (which are not expected with current API). 1.38 + */ 1.39 +void ReleaseSharedHandle(GLContext* gl, 1.40 + SharedTextureShareType shareType, 1.41 + SharedTextureHandle sharedHandle); 1.42 + 1.43 + 1.44 +typedef struct { 1.45 + GLenum mTarget; 1.46 + gfx::SurfaceFormat mTextureFormat; 1.47 + gfx::Matrix4x4 mTextureTransform; 1.48 +} SharedHandleDetails; 1.49 + 1.50 +/** 1.51 + * Returns information necessary for rendering a shared handle. 1.52 + * These values change depending on what sharing mechanism is in use 1.53 + */ 1.54 +bool GetSharedHandleDetails(GLContext* gl, 1.55 + SharedTextureShareType shareType, 1.56 + SharedTextureHandle sharedHandle, 1.57 + SharedHandleDetails& details); 1.58 +/** 1.59 + * Attach Shared GL Handle to GL_TEXTURE_2D target 1.60 + * GLContext must be current before this call 1.61 + */ 1.62 +bool AttachSharedHandle(GLContext* gl, 1.63 + SharedTextureShareType shareType, 1.64 + SharedTextureHandle sharedHandle); 1.65 + 1.66 +/** 1.67 + * Detach Shared GL Handle from GL_TEXTURE_2D target 1.68 + */ 1.69 +void DetachSharedHandle(GLContext* gl, 1.70 + SharedTextureShareType shareType, 1.71 + SharedTextureHandle sharedHandle); 1.72 + 1.73 +} 1.74 +} 1.75 + 1.76 +#endif