1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim: set ts=8 sts=4 et sw=4 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GLBLITHELPER_H_
8 #define GLBLITHELPER_H_
10 #include "GLContextTypes.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/gfx/Point.h"
20 class PlanarYCbCrImage
;
22 class SurfaceTextureImage
;
30 * Helper function that creates a 2D texture aSize.width x aSize.height with
31 * storage type specified by aFormats. Returns GL texture object id.
33 * See mozilla::gl::CreateTexture.
35 GLuint
CreateTextureForOffscreen(GLContext
* aGL
, const GLFormats
& aFormats
,
36 const gfx::IntSize
& aSize
);
39 * Helper function that creates a 2D texture aSize.width x aSize.height with
40 * storage type aInternalFormat. Returns GL texture object id.
42 * Initialize textyre parameters to:
43 * GL_TEXTURE_MIN_FILTER = GL_LINEAR
44 * GL_TEXTURE_MAG_FILTER = GL_LINEAR
45 * GL_TEXTURE_WRAP_S = GL_CLAMP_TO_EDGE
46 * GL_TEXTURE_WRAP_T = GL_CLAMP_TO_EDGE
48 GLuint
CreateTexture(GLContext
* aGL
, GLenum aInternalFormat
, GLenum aFormat
,
49 GLenum aType
, const gfx::IntSize
& aSize
, bool linear
= true);
52 * Helper function to create, potentially, multisample render buffers suitable
53 * for offscreen rendering. Buffers of size aSize.width x aSize.height with
54 * storage specified by aFormat. returns GL render buffer object id.
56 GLuint
CreateRenderbuffer(GLContext
* aGL
, GLenum aFormat
, GLsizei aSamples
,
57 const gfx::IntSize
& aSize
);
60 * Helper function to create, potentially, multisample render buffers suitable
61 * for offscreen rendering. Buffers of size aSize.width x aSize.height with
62 * storage specified by aFormats. GL render buffer object ids are returned via
63 * aColorMSRB, aDepthRB, and aStencilRB
65 void CreateRenderbuffersForOffscreen(GLContext
* aGL
, const GLFormats
& aFormats
,
66 const gfx::IntSize
& aSize
, bool aMultisample
,
67 GLuint
* aColorMSRB
, GLuint
* aDepthRB
,
71 /** Buffer blitting helper */
72 class GLBlitHelper MOZ_FINAL
83 * BlitTex2D is used to copy blit the content of a GL_TEXTURE_2D object,
84 * BlitTexRect is used to copy blit the content of a GL_TEXTURE_RECT object,
85 * The difference between BlitTex2D and BlitTexRect is the texture type, which affect
86 * the fragment shader a bit.
88 * ConvertGralloc is used to color convert copy blit the GrallocImage into a
89 * normal RGB texture by egl_image_external extension
90 * ConvertPlnarYcbCr is used to color convert copy blit the PlanarYCbCrImage
91 * into a normal RGB texture by create textures of each color channel, and
93 * Convert type is created for canvas.
101 ConvertSurfaceTexture
103 // The GLContext is the sole owner of the GLBlitHelper.
106 GLuint mTexBlit_Buffer
;
107 GLuint mTexBlit_VertShader
;
108 GLuint mTex2DBlit_FragShader
;
109 GLuint mTex2DRectBlit_FragShader
;
110 GLuint mTex2DBlit_Program
;
111 GLuint mTex2DRectBlit_Program
;
115 GLint mTextureTransformLoc
;
117 // Data for image blit path
118 GLuint mTexExternalBlit_FragShader
;
119 GLuint mTexYUVPlanarBlit_FragShader
;
120 GLuint mTexExternalBlit_Program
;
121 GLuint mTexYUVPlanarBlit_Program
;
128 GLint mCbCrTexScaleLoc
;
132 // Cache some uniform values
136 void UseBlitProgram();
137 void SetBlitFramebufferForDestTexture(GLuint aTexture
);
139 bool UseTexQuadProgram(BlitType target
, const gfx::IntSize
& srcSize
);
140 bool InitTexQuadProgram(BlitType target
= BlitTex2D
);
141 void DeleteTexBlitProgram();
142 void BindAndUploadYUVTexture(Channel which
, uint32_t width
, uint32_t height
, void* data
, bool allocation
);
144 #ifdef MOZ_WIDGET_GONK
145 void BindAndUploadExternalTexture(EGLImage image
);
146 bool BlitGrallocImage(layers::GrallocImage
* grallocImage
, bool yFlip
= false);
148 bool BlitPlanarYCbCrImage(layers::PlanarYCbCrImage
* yuvImage
, bool yFlip
= false);
149 #ifdef MOZ_WIDGET_ANDROID
150 bool BlitSurfaceTextureImage(layers::SurfaceTextureImage
* stImage
);
155 explicit GLBlitHelper(GLContext
* gl
);
158 // If you don't have |srcFormats| for the 2nd definition,
159 // then you'll need the framebuffer_blit extensions to use
160 // the first BlitFramebufferToFramebuffer.
161 void BlitFramebufferToFramebuffer(GLuint srcFB
, GLuint destFB
,
162 const gfx::IntSize
& srcSize
,
163 const gfx::IntSize
& destSize
,
164 bool internalFBs
= false);
165 void BlitFramebufferToFramebuffer(GLuint srcFB
, GLuint destFB
,
166 const gfx::IntSize
& srcSize
,
167 const gfx::IntSize
& destSize
,
168 const GLFormats
& srcFormats
,
169 bool internalFBs
= false);
170 void BlitTextureToFramebuffer(GLuint srcTex
, GLuint destFB
,
171 const gfx::IntSize
& srcSize
,
172 const gfx::IntSize
& destSize
,
173 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
174 bool internalFBs
= false);
175 void BlitFramebufferToTexture(GLuint srcFB
, GLuint destTex
,
176 const gfx::IntSize
& srcSize
,
177 const gfx::IntSize
& destSize
,
178 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
,
179 bool internalFBs
= false);
180 void BlitTextureToTexture(GLuint srcTex
, GLuint destTex
,
181 const gfx::IntSize
& srcSize
,
182 const gfx::IntSize
& destSize
,
183 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
184 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
);
185 bool BlitImageToFramebuffer(layers::Image
* srcImage
, const gfx::IntSize
& destSize
,
186 GLuint destFB
, bool yFlip
= false, GLuint xoffset
= 0,
187 GLuint yoffset
= 0, GLuint width
= 0, GLuint height
= 0);
188 bool BlitImageToTexture(layers::Image
* srcImage
, const gfx::IntSize
& destSize
,
189 GLuint destTex
, GLenum destTarget
, bool yFlip
= false, GLuint xoffset
= 0,
190 GLuint yoffset
= 0, GLuint width
= 0, GLuint height
= 0);
196 #endif // GLBLITHELPER_H_