2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-11-29 00:57:19 +04:00
|
|
|
/* 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"
|
2017-07-18 05:17:41 +03:00
|
|
|
#include "ipc/IPCMessageUtils.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"
|
2017-07-21 05:18:50 +03:00
|
|
|
#include "../layers/ImageTypes.h"
|
2013-11-29 00:57:19 +04:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2013-11-29 00:57:19 +04:00
|
|
|
namespace mozilla {
|
2014-07-08 22:52:00 +04:00
|
|
|
|
|
|
|
namespace layers {
|
2019-04-10 23:54:57 +03:00
|
|
|
class D3D11ShareHandleImage;
|
2017-07-18 05:17:41 +03:00
|
|
|
class D3D11YCbCrImage;
|
2014-07-08 22:52:00 +04:00
|
|
|
class Image;
|
2017-07-18 05:17:41 +03:00
|
|
|
class GPUVideoImage;
|
2014-07-08 22:52:00 +04:00
|
|
|
class PlanarYCbCrImage;
|
2014-10-21 17:53:02 +04:00
|
|
|
class SurfaceTextureImage;
|
2015-08-14 18:50:48 +03:00
|
|
|
class MacIOSurfaceImage;
|
2017-07-18 05:17:41 +03:00
|
|
|
class SurfaceDescriptorD3D10;
|
|
|
|
class SurfaceDescriptorDXGIYCbCr;
|
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 {
|
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
class BindAnglePlanes;
|
2013-11-29 00:57:19 +04:00
|
|
|
class GLContext;
|
2017-11-01 03:25:40 +03:00
|
|
|
class GLBlitHelper;
|
2013-11-29 00:57:19 +04:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
bool GuessDivisors(const gfx::IntSize& ySize, const gfx::IntSize& uvSize,
|
|
|
|
gfx::IntSize* const out_divisors);
|
|
|
|
|
2017-09-29 05:07:46 +03:00
|
|
|
template <uint8_t N>
|
|
|
|
struct Mat {
|
|
|
|
float m[N * N]; // column-major, for GL
|
|
|
|
|
|
|
|
float& at(const uint8_t x, const uint8_t y) { return m[N * x + y]; }
|
|
|
|
|
|
|
|
static Mat<N> Zero();
|
|
|
|
static Mat<N> I();
|
|
|
|
|
|
|
|
Mat<N> operator*(const Mat<N>& r) const;
|
|
|
|
};
|
|
|
|
typedef Mat<3> Mat3;
|
|
|
|
|
|
|
|
Mat3 SubRectMat3(float x, float y, float w, float h);
|
|
|
|
Mat3 SubRectMat3(const gfx::IntRect& subrect, const gfx::IntSize& size);
|
|
|
|
Mat3 SubRectMat3(const gfx::IntRect& bigSubrect, const gfx::IntSize& smallSize,
|
|
|
|
const gfx::IntSize& divisors);
|
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
class DrawBlitProg final {
|
2017-07-21 05:18:50 +03:00
|
|
|
const GLBlitHelper& mParent;
|
2017-07-18 05:17:41 +03:00
|
|
|
const GLuint mProg;
|
2017-09-29 05:07:46 +03:00
|
|
|
const GLint mLoc_uDestMatrix;
|
|
|
|
const GLint mLoc_uTexMatrix0;
|
|
|
|
const GLint mLoc_uTexMatrix1;
|
2017-07-18 05:17:41 +03:00
|
|
|
const GLint mLoc_uColorMatrix;
|
2018-08-18 01:21:26 +03:00
|
|
|
GLenum mType_uColorMatrix = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
public:
|
2017-07-21 05:18:50 +03:00
|
|
|
struct Key final {
|
2017-09-29 05:07:46 +03:00
|
|
|
const char* const fragHeader;
|
|
|
|
const char* const fragBody;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-21 05:18:50 +03:00
|
|
|
bool operator<(const Key& x) const {
|
|
|
|
if (fragHeader != x.fragHeader) return fragHeader < x.fragHeader;
|
|
|
|
return fragBody < x.fragBody;
|
|
|
|
}
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-21 05:18:50 +03:00
|
|
|
DrawBlitProg(const GLBlitHelper* parent, GLuint prog);
|
2017-07-18 05:17:41 +03:00
|
|
|
~DrawBlitProg();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
struct BaseArgs final {
|
2017-09-29 05:07:46 +03:00
|
|
|
Mat3 texMatrix0;
|
2017-07-18 05:17:41 +03:00
|
|
|
bool yFlip;
|
2017-09-29 05:07:46 +03:00
|
|
|
gfx::IntSize
|
|
|
|
destSize; // Always needed for (at least) setting the viewport.
|
|
|
|
Maybe<gfx::IntRect> destRect;
|
2017-07-18 05:17:41 +03:00
|
|
|
};
|
|
|
|
struct YUVArgs final {
|
2017-09-29 05:07:46 +03:00
|
|
|
Mat3 texMatrix1;
|
2019-04-11 15:41:33 +03:00
|
|
|
gfx::YUVColorSpace colorSpace;
|
2017-07-18 05:17:41 +03:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
void Draw(const BaseArgs& args, const YUVArgs* argsYUV = nullptr) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScopedSaveMultiTex final {
|
|
|
|
GLContext& mGL;
|
|
|
|
const uint8_t mTexCount;
|
|
|
|
const GLenum mTexTarget;
|
|
|
|
const GLuint mOldTexUnit;
|
|
|
|
GLuint mOldTexSampler[3];
|
|
|
|
GLuint mOldTex[3];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
public:
|
|
|
|
ScopedSaveMultiTex(GLContext* gl, uint8_t texCount, GLenum texTarget);
|
|
|
|
~ScopedSaveMultiTex();
|
|
|
|
};
|
|
|
|
|
2013-12-06 19:36:13 +04:00
|
|
|
/** Buffer blitting helper */
|
2015-03-21 19:28:04 +03:00
|
|
|
class GLBlitHelper final {
|
2017-07-18 05:17:41 +03:00
|
|
|
friend class BindAnglePlanes;
|
|
|
|
friend class DrawBlitProg;
|
|
|
|
friend class GLContext;
|
2014-07-08 22:52:00 +04:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
GLContext* const mGL;
|
2017-07-21 05:18:50 +03:00
|
|
|
mutable std::map<DrawBlitProg::Key, const DrawBlitProg*> mDrawBlitProgs;
|
2017-07-18 05:17:41 +03:00
|
|
|
|
2018-08-18 01:21:26 +03:00
|
|
|
GLuint mQuadVAO = 0;
|
|
|
|
GLuint mQuadVBO = 0;
|
2017-07-21 05:18:50 +03:00
|
|
|
nsCString mDrawBlitProg_VersionLine;
|
|
|
|
const GLuint mDrawBlitProg_VertShader;
|
2017-07-18 05:17:41 +03:00
|
|
|
|
2018-08-18 01:21:26 +03:00
|
|
|
GLuint mYuvUploads[3] = {};
|
|
|
|
gfx::IntSize mYuvUploads_YSize = {0, 0};
|
|
|
|
gfx::IntSize mYuvUploads_UVSize = {0, 0};
|
2017-07-18 05:17:41 +03:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
mutable RefPtr<ID3D11Device> mD3D11;
|
|
|
|
|
|
|
|
ID3D11Device* GetD3D11() const;
|
|
|
|
#endif
|
|
|
|
|
2017-07-21 05:18:50 +03:00
|
|
|
const DrawBlitProg* GetDrawBlitProg(const DrawBlitProg::Key& key) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-21 05:18:50 +03:00
|
|
|
private:
|
|
|
|
const DrawBlitProg* CreateDrawBlitProg(const DrawBlitProg::Key& key) const;
|
2017-07-18 05:17:41 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2017-07-18 05:17:41 +03:00
|
|
|
bool BlitImage(layers::PlanarYCbCrImage* yuvImage,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin);
|
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.
|
2017-08-23 05:56:42 +03:00
|
|
|
bool BlitImage(layers::SurfaceTextureImage* stImage,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2014-10-21 17:53:02 +04:00
|
|
|
#endif
|
2015-08-14 18:50:48 +03:00
|
|
|
#ifdef XP_MACOSX
|
2017-07-21 05:18:50 +03:00
|
|
|
bool BlitImage(layers::MacIOSurfaceImage* srcImage,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2015-08-14 18:50:48 +03:00
|
|
|
#endif
|
2013-11-29 00:57:19 +04:00
|
|
|
|
2014-08-08 05:17:30 +04:00
|
|
|
explicit GLBlitHelper(GLContext* gl);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-04-21 03:49:25 +03:00
|
|
|
public:
|
2013-11-29 00:57:19 +04:00
|
|
|
~GLBlitHelper();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-08-31 04:30:53 +03:00
|
|
|
void BlitFramebuffer(const gfx::IntRect& srcRect,
|
|
|
|
const gfx::IntRect& destRect,
|
2018-04-12 22:28:26 +03:00
|
|
|
GLuint filter = LOCAL_GL_NEAREST) const;
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitFramebufferToFramebuffer(GLuint srcFB, GLuint destFB,
|
2019-08-31 04:30:53 +03:00
|
|
|
const gfx::IntRect& srcRect,
|
|
|
|
const gfx::IntRect& destRect,
|
2018-04-12 22:28:26 +03:00
|
|
|
GLuint filter = LOCAL_GL_NEAREST) const;
|
2017-07-18 05:17:41 +03:00
|
|
|
void BlitFramebufferToTexture(GLuint destTex, const gfx::IntSize& srcSize,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& destSize,
|
2017-07-18 05:17:41 +03:00
|
|
|
GLenum destTarget = LOCAL_GL_TEXTURE_2D) const;
|
|
|
|
void BlitTextureToFramebuffer(GLuint srcTex, const gfx::IntSize& srcSize,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& destSize,
|
2017-07-18 05:17:41 +03:00
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D) const;
|
2013-11-29 00:57:19 +04:00
|
|
|
void BlitTextureToTexture(GLuint srcTex, GLuint destTex,
|
2017-07-18 05:17:41 +03:00
|
|
|
const gfx::IntSize& srcSize,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& destSize,
|
2013-11-29 00:57:19 +04:00
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D,
|
2017-07-18 05:17:41 +03:00
|
|
|
GLenum destTarget = LOCAL_GL_TEXTURE_2D) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
void DrawBlitTextureToFramebuffer(
|
2013-12-10 20:11:58 +04:00
|
|
|
GLuint srcTex, const gfx::IntSize& srcSize, const gfx::IntSize& destSize,
|
2017-07-18 05:17:41 +03:00
|
|
|
GLenum srcTarget = LOCAL_GL_TEXTURE_2D) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-10-21 17:53:02 +04:00
|
|
|
bool BlitImageToFramebuffer(layers::Image* srcImage,
|
2013-12-10 20:11:58 +04:00
|
|
|
const gfx::IntSize& destSize,
|
2017-07-18 05:17:41 +03:00
|
|
|
OriginPos destOrigin);
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef XP_WIN
|
|
|
|
// GLBlitHelperD3D.cpp:
|
|
|
|
bool BlitImage(layers::GPUVideoImage* srcImage, const gfx::IntSize& destSize,
|
|
|
|
OriginPos destOrigin) const;
|
2019-04-10 23:54:57 +03:00
|
|
|
bool BlitImage(layers::D3D11ShareHandleImage* srcImage,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2017-07-18 05:17:41 +03:00
|
|
|
bool BlitImage(layers::D3D11YCbCrImage* srcImage,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
bool BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
|
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
bool BlitAngleYCbCr(const WindowsHandle (&handleList)[3],
|
|
|
|
const gfx::IntRect& clipRect, const gfx::IntSize& ySize,
|
2017-09-29 05:07:46 +03:00
|
|
|
const gfx::IntSize& uvSize,
|
2019-04-11 15:41:33 +03:00
|
|
|
const gfx::YUVColorSpace colorSpace,
|
2017-09-29 05:07:46 +03:00
|
|
|
const gfx::IntSize& destSize, OriginPos destOrigin) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
bool BlitAnglePlanes(uint8_t numPlanes,
|
|
|
|
const RefPtr<ID3D11Texture2D>* texD3DList,
|
|
|
|
const DrawBlitProg* prog,
|
|
|
|
const DrawBlitProg::BaseArgs& baseArgs,
|
|
|
|
const DrawBlitProg::YUVArgs* const yuvArgs) const;
|
|
|
|
#endif
|
2013-11-29 00:57:19 +04:00
|
|
|
};
|
|
|
|
|
2017-08-23 02:13:14 +03:00
|
|
|
extern const char* const kFragHeader_Tex2D;
|
|
|
|
extern const char* const kFragHeader_Tex2DRect;
|
|
|
|
extern const char* const kFragHeader_TexExt;
|
|
|
|
extern const char* const kFragBody_RGBA;
|
|
|
|
extern const char* const kFragBody_CrYCb;
|
|
|
|
extern const char* const kFragBody_NV12;
|
|
|
|
extern const char* const kFragBody_PlanarYUV;
|
|
|
|
|
2014-11-18 04:02:19 +03:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
2013-11-29 00:57:19 +04:00
|
|
|
|
|
|
|
#endif // GLBLITHELPER_H_
|