2013-11-29 00:57:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef GLBLITHELPER_H_
|
|
|
|
#define GLBLITHELPER_H_
|
|
|
|
|
|
|
|
#include "GLContextTypes.h"
|
|
|
|
#include "GLConsts.h"
|
2013-12-06 19:36:13 +04:00
|
|
|
#include "nsSize.h"
|
2013-11-29 00:57:19 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-12-10 20:11:58 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2013-11-29 00:57:19 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-07-08 22:52:00 +04:00
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
class Image;
|
|
|
|
class PlanarYCbCrImage;
|
|
|
|
class GrallocImage;
|
2014-10-21 17:53:02 +04:00
|
|
|
class SurfaceTextureImage;
|
2015-08-14 18:50:48 +03:00
|
|
|
class MacIOSurfaceImage;
|
2014-11-27 00:16:08 +03:00
|
|
|
class EGLImageImage;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2014-07-08 22:52:00 +04:00
|
|
|
|
2013-11-29 00:57:19 +04:00
|
|
|
namespace gl {
|
|
|
|
|
|
|
|
class GLContext;
|
|
|
|
|
2013-12-06 19:36:13 +04:00
|
|
|
/** Buffer blitting helper */
|
2015-03-21 19:28:04 +03:00
|
|
|
class GLBlitHelper final
|
2013-11-29 00:57:19 +04:00
|
|
|
{
|
2014-07-08 22:52:00 +04:00
|
|
|
enum Channel
|
|
|
|
{
|
|
|
|
Channel_Y = 0,
|
|
|
|
Channel_Cb,
|
|
|
|
Channel_Cr,
|
|
|
|
Channel_Max,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BlitTex2D is used to copy blit the content of a GL_TEXTURE_2D object,
|
|
|
|
* BlitTexRect is used to copy blit the content of a GL_TEXTURE_RECT object,
|
|
|
|
* The difference between BlitTex2D and BlitTexRect is the texture type, which affect
|
|
|
|
* the fragment shader a bit.
|
|
|
|
*
|
|
|
|
* ConvertGralloc is used to color convert copy blit the GrallocImage into a
|
|
|
|
* normal RGB texture by egl_image_external extension
|
|
|
|
* ConvertPlnarYcbCr is used to color convert copy blit the PlanarYCbCrImage
|
|
|
|
* into a normal RGB texture by create textures of each color channel, and
|
|
|
|
* convert it in GPU.
|
|
|
|
* Convert type is created for canvas.
|
|
|
|
*/
|
|
|
|
enum BlitType
|
|
|
|
{
|
|
|
|
BlitTex2D,
|
|
|
|
BlitTexRect,
|
|
|
|
ConvertGralloc,
|
|
|
|
ConvertPlanarYCbCr,
|
2014-11-27 00:16:08 +03:00
|
|
|
ConvertSurfaceTexture,
|
2015-08-14 18:50:48 +03:00
|
|
|
ConvertEGLImage,
|
|
|
|
ConvertMacIOSurfaceImage
|
2014-07-08 22:52:00 +04:00
|
|
|
};
|
2013-11-29 00:57:19 +04:00
|
|
|
// The GLContext is the sole owner of the GLBlitHelper.
|
|
|
|
GLContext* mGL;
|
|
|
|
|
|
|
|
GLuint mTexBlit_Buffer;
|
|
|
|
GLuint mTexBlit_VertShader;
|
|
|
|
GLuint mTex2DBlit_FragShader;
|
|
|
|
GLuint mTex2DRectBlit_FragShader;
|
|
|
|
GLuint mTex2DBlit_Program;
|
|
|
|
GLuint mTex2DRectBlit_Program;
|
|
|
|
|
2014-07-08 22:52:00 +04:00
|
|
|
GLint mYFlipLoc;
|
|
|
|
|
2014-10-21 17:53:02 +04:00
|
|
|
GLint mTextureTransformLoc;
|
|
|
|
|
2014-07-08 22:52:00 +04:00
|
|
|
// Data for image blit path
|
|
|
|
GLuint mTexExternalBlit_FragShader;
|
|
|
|
GLuint mTexYUVPlanarBlit_FragShader;
|
2015-08-14 18:50:48 +03:00
|
|
|
GLuint mTexNV12PlanarBlit_FragShader;
|
2014-07-08 22:52:00 +04:00
|
|
|
GLuint mTexExternalBlit_Program;
|
|
|
|
GLuint mTexYUVPlanarBlit_Program;
|
2015-08-14 18:50:48 +03:00
|
|
|
GLuint mTexNV12PlanarBlit_Program;
|
2014-07-08 22:52:00 +04:00
|
|
|
GLuint mFBO;
|
|
|
|
GLuint mSrcTexY;
|
|
|
|
GLuint mSrcTexCb;
|
|
|
|
GLuint mSrcTexCr;
|
|
|
|
GLuint mSrcTexEGL;
|
|
|
|
GLint mYTexScaleLoc;
|
|
|
|
GLint mCbCrTexScaleLoc;
|
|
|
|
int mTexWidth;
|
|
|
|
int mTexHeight;
|
|
|
|
|
|
|
|
// Cache some uniform values
|
|
|
|
float mCurYScale;
|
|
|
|
float mCurCbCrScale;
|
|
|
|
|
2013-11-29 00:57:19 +04:00
|
|
|
void UseBlitProgram();
|
|
|
|
void SetBlitFramebufferForDestTexture(GLuint aTexture);
|
|
|
|
|
2014-07-08 22:52:00 +04:00
|
|
|
bool UseTexQuadProgram(BlitType target, const gfx::IntSize& srcSize);
|
|
|
|
bool InitTexQuadProgram(BlitType target = BlitTex2D);
|
2013-11-29 00:57:19 +04:00
|
|
|
void DeleteTexBlitProgram();
|
2014-07-08 22:52:00 +04:00
|
|
|
void BindAndUploadYUVTexture(Channel which, uint32_t width, uint32_t height, void* data, bool allocation);
|
2014-11-27 00:16:08 +03:00
|
|
|
void BindAndUploadEGLImage(EGLImage image, GLuint target);
|
2014-07-08 22:52:00 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-04-21 03:49:25 +03:00
|
|
|
bool BlitGrallocImage(layers::GrallocImage* grallocImage);
|
2014-07-08 22:52:00 +04:00
|
|
|
#endif
|
2015-04-21 03:49:25 +03:00
|
|
|
bool BlitPlanarYCbCrImage(layers::PlanarYCbCrImage* yuvImage);
|
2014-10-21 17:53:02 +04:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2014-11-18 04:02:19 +03:00
|
|
|
// Blit onto the current FB.
|
2015-04-21 03:49:25 +03:00
|
|
|
bool BlitSurfaceTextureImage(layers::SurfaceTextureImage* stImage);
|
|
|
|
bool BlitEGLImageImage(layers::EGLImageImage* eglImage);
|
2014-10-21 17:53:02 +04:00
|
|
|
#endif
|
2015-08-14 18:50:48 +03:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
bool BlitMacIOSurfaceImage(layers::MacIOSurfaceImage* ioImage);
|
|
|
|
#endif
|
2013-11-29 00:57:19 +04:00
|
|
|
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit GLBlitHelper(GLContext* gl);
|
2015-04-21 03:49:25 +03:00
|
|
|
|
|
|
|
friend class GLContext;
|
|
|
|
|
|
|
|
public:
|
2013-11-29 00:57:19 +04:00
|
|
|
~GLBlitHelper();
|
|
|
|
|
|
|
|
// If you don't have |srcFormats| for the 2nd definition,
|
|
|
|
// then you'll need the framebuffer_blit extensions to use
|
|
|
|
// the first BlitFramebufferToFramebuffer.
|
|
|
|
void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& srcSize,
|
2014-08-08 06:03:25 +04:00
|
|
|
const gfx::IntSize& destSize,
|
|
|
|
bool internalFBs = false);
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& srcSize,
|
|
|
|
const gfx::IntSize& destSize,
|
2014-08-08 06:03:25 +04:00
|
|
|
const GLFormats& srcFormats,
|
|
|
|
bool internalFBs = false);
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& srcSize,
|
|
|
|
const gfx::IntSize& destSize,
|
2014-08-08 06:03:25 +04:00
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
|
|
|
|
bool internalFBs = false);
|
2015-11-25 07:15:29 +03:00
|
|
|
void DrawBlitTextureToFramebuffer(GLuint srcTex, GLuint destFB,
|
|
|
|
const gfx::IntSize& srcSize,
|
|
|
|
const gfx::IntSize& destSize,
|
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
|
|
|
|
bool internalFBs = false);
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitFramebufferToTexture(GLuint srcFB, GLuint destTex,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& srcSize,
|
|
|
|
const gfx::IntSize& destSize,
|
2014-08-08 06:03:25 +04:00
|
|
|
GLenum destTarget = LOCAL_GL_TEXTURE_2D,
|
|
|
|
bool internalFBs = false);
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& srcSize,
|
|
|
|
const gfx::IntSize& destSize,
|
2013-11-29 00:57:19 +04:00
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
|
|
|
|
GLenum destTarget = LOCAL_GL_TEXTURE_2D);
|
2014-10-21 17:53:02 +04:00
|
|
|
bool BlitImageToFramebuffer(layers::Image* srcImage, const gfx::IntSize& destSize,
|
2015-04-21 03:49:25 +03:00
|
|
|
GLuint destFB, OriginPos destOrigin);
|
2014-07-08 22:52:00 +04:00
|
|
|
bool BlitImageToTexture(layers::Image* srcImage, const gfx::IntSize& destSize,
|
2015-04-21 03:49:25 +03:00
|
|
|
GLuint destTex, GLenum destTarget, OriginPos destOrigin);
|
2013-11-29 00:57:19 +04:00
|
|
|
};
|
|
|
|
|
2014-11-18 04:02:19 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-11-29 00:57:19 +04:00
|
|
|
|
|
|
|
#endif // GLBLITHELPER_H_
|