1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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 "ipc/IPCMessageUtils.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/gfx/Point.h"
16 #include "../layers/ImageTypes.h"
25 class D3D11ShareHandleImage
;
26 class D3D11YCbCrImage
;
29 class PlanarYCbCrImage
;
30 class SurfaceTextureImage
;
31 class MacIOSurfaceImage
;
32 class SurfaceDescriptorD3D10
;
33 class SurfaceDescriptorDXGIYCbCr
;
38 class BindAnglePlanes
;
42 bool GuessDivisors(const gfx::IntSize
& ySize
, const gfx::IntSize
& uvSize
,
43 gfx::IntSize
* const out_divisors
);
47 float m
[N
* N
]; // column-major, for GL
49 float& at(const uint8_t x
, const uint8_t y
) { return m
[N
* x
+ y
]; }
54 Mat
<N
> operator*(const Mat
<N
>& r
) const;
58 Mat3
SubRectMat3(float x
, float y
, float w
, float h
);
59 Mat3
SubRectMat3(const gfx::IntRect
& subrect
, const gfx::IntSize
& size
);
60 Mat3
SubRectMat3(const gfx::IntRect
& bigSubrect
, const gfx::IntSize
& smallSize
,
61 const gfx::IntSize
& divisors
);
63 class DrawBlitProg final
{
64 const GLBlitHelper
& mParent
;
66 const GLint mLoc_uDestMatrix
;
67 const GLint mLoc_uTexMatrix0
;
68 const GLint mLoc_uTexMatrix1
;
69 const GLint mLoc_uColorMatrix
;
70 GLenum mType_uColorMatrix
= 0;
74 const char* const fragHeader
;
75 const char* const fragBody
;
77 bool operator<(const Key
& x
) const {
78 if (fragHeader
!= x
.fragHeader
) return fragHeader
< x
.fragHeader
;
79 return fragBody
< x
.fragBody
;
83 DrawBlitProg(const GLBlitHelper
* parent
, GLuint prog
);
86 struct BaseArgs final
{
90 destSize
; // Always needed for (at least) setting the viewport.
91 Maybe
<gfx::IntRect
> destRect
;
93 struct YUVArgs final
{
95 gfx::YUVColorSpace colorSpace
;
98 void Draw(const BaseArgs
& args
, const YUVArgs
* argsYUV
= nullptr) const;
101 class ScopedSaveMultiTex final
{
103 const uint8_t mTexCount
;
104 const GLenum mTexTarget
;
105 const GLuint mOldTexUnit
;
106 GLuint mOldTexSampler
[3];
110 ScopedSaveMultiTex(GLContext
* gl
, uint8_t texCount
, GLenum texTarget
);
111 ~ScopedSaveMultiTex();
114 /** Buffer blitting helper */
115 class GLBlitHelper final
{
116 friend class BindAnglePlanes
;
117 friend class DrawBlitProg
;
118 friend class GLContext
;
120 GLContext
* const mGL
;
121 mutable std::map
<DrawBlitProg::Key
, const DrawBlitProg
*> mDrawBlitProgs
;
125 nsCString mDrawBlitProg_VersionLine
;
126 const GLuint mDrawBlitProg_VertShader
;
128 GLuint mYuvUploads
[3] = {};
129 gfx::IntSize mYuvUploads_YSize
= {0, 0};
130 gfx::IntSize mYuvUploads_UVSize
= {0, 0};
133 mutable RefPtr
<ID3D11Device
> mD3D11
;
135 ID3D11Device
* GetD3D11() const;
138 const DrawBlitProg
* GetDrawBlitProg(const DrawBlitProg::Key
& key
) const;
141 const DrawBlitProg
* CreateDrawBlitProg(const DrawBlitProg::Key
& key
) const;
144 bool BlitImage(layers::PlanarYCbCrImage
* yuvImage
,
145 const gfx::IntSize
& destSize
, OriginPos destOrigin
);
146 #ifdef MOZ_WIDGET_ANDROID
147 // Blit onto the current FB.
148 bool BlitImage(layers::SurfaceTextureImage
* stImage
,
149 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
152 bool BlitImage(layers::MacIOSurfaceImage
* srcImage
,
153 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
156 explicit GLBlitHelper(GLContext
* gl
);
161 void BlitFramebuffer(const gfx::IntRect
& srcRect
,
162 const gfx::IntRect
& destRect
,
163 GLuint filter
= LOCAL_GL_NEAREST
) const;
164 void BlitFramebufferToFramebuffer(GLuint srcFB
, GLuint destFB
,
165 const gfx::IntRect
& srcRect
,
166 const gfx::IntRect
& destRect
,
167 GLuint filter
= LOCAL_GL_NEAREST
) const;
168 void BlitFramebufferToTexture(GLuint destTex
, const gfx::IntSize
& srcSize
,
169 const gfx::IntSize
& destSize
,
170 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
171 void BlitTextureToFramebuffer(GLuint srcTex
, const gfx::IntSize
& srcSize
,
172 const gfx::IntSize
& destSize
,
173 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
) const;
174 void BlitTextureToTexture(GLuint srcTex
, GLuint destTex
,
175 const gfx::IntSize
& srcSize
,
176 const gfx::IntSize
& destSize
,
177 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
178 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
180 void DrawBlitTextureToFramebuffer(
181 GLuint srcTex
, const gfx::IntSize
& srcSize
, const gfx::IntSize
& destSize
,
182 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
) const;
184 bool BlitImageToFramebuffer(layers::Image
* srcImage
,
185 const gfx::IntSize
& destSize
,
186 OriginPos destOrigin
);
190 // GLBlitHelperD3D.cpp:
191 bool BlitImage(layers::GPUVideoImage
* srcImage
, const gfx::IntSize
& destSize
,
192 OriginPos destOrigin
) const;
193 bool BlitImage(layers::D3D11ShareHandleImage
* srcImage
,
194 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
195 bool BlitImage(layers::D3D11YCbCrImage
* srcImage
,
196 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
198 bool BlitDescriptor(const layers::SurfaceDescriptorD3D10
& desc
,
199 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
201 bool BlitAngleYCbCr(const WindowsHandle (&handleList
)[3],
202 const gfx::IntRect
& clipRect
, const gfx::IntSize
& ySize
,
203 const gfx::IntSize
& uvSize
,
204 const gfx::YUVColorSpace colorSpace
,
205 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
207 bool BlitAnglePlanes(uint8_t numPlanes
,
208 const RefPtr
<ID3D11Texture2D
>* texD3DList
,
209 const DrawBlitProg
* prog
,
210 const DrawBlitProg::BaseArgs
& baseArgs
,
211 const DrawBlitProg::YUVArgs
* const yuvArgs
) const;
215 extern const char* const kFragHeader_Tex2D
;
216 extern const char* const kFragHeader_Tex2DRect
;
217 extern const char* const kFragHeader_TexExt
;
218 extern const char* const kFragBody_RGBA
;
219 extern const char* const kFragBody_CrYCb
;
220 extern const char* const kFragBody_NV12
;
221 extern const char* const kFragBody_PlanarYUV
;
224 } // namespace mozilla
226 #endif // GLBLITHELPER_H_