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_
13 #include "GLContextTypes.h"
17 #include "nsTString.h"
18 #include "mozilla/ipc/IPCTypes.h"
19 #include "mozilla/Attributes.h"
20 #include "mozilla/Maybe.h"
21 #include "mozilla/gfx/Point.h"
22 #include "mozilla/gfx/Rect.h"
23 #include "mozilla/gfx/Types.h"
29 # include "mozilla/RefPtr.h"
30 # include "mozilla/ipc/IPCTypes.h"
32 struct ID3D11Texture2D
;
39 #ifdef MOZ_WIDGET_ANDROID
40 # include "mozilla/java/GeckoSurfaceTextureWrappers.h"
52 struct PlanarYCbCrData
;
53 class PlanarYCbCrImage
;
54 class SurfaceDescriptor
;
55 class SurfaceDescriptorBuffer
;
58 class D3D11ShareHandleImage
;
59 class D3D11TextureIMFSampleImage
;
60 class D3D11YCbCrImage
;
61 class SurfaceDescriptorD3D10
;
62 class SurfaceDescriptorDXGIYCbCr
;
65 #ifdef MOZ_WIDGET_ANDROID
66 class SurfaceTextureDescriptor
;
70 class MacIOSurfaceImage
;
74 class DMABUFSurfaceImage
;
80 class BindAnglePlanes
;
84 bool GuessDivisors(const gfx::IntSize
& ySize
, const gfx::IntSize
& uvSize
,
85 gfx::IntSize
* const out_divisors
);
89 float m
[N
* N
]; // column-major, for GL
91 float& at(const uint8_t x
, const uint8_t y
) { return m
[N
* x
+ y
]; }
96 Mat
<N
> operator*(const Mat
<N
>& r
) const;
100 Mat3
SubRectMat3(float x
, float y
, float w
, float h
);
101 Mat3
SubRectMat3(const gfx::IntRect
& subrect
, const gfx::IntSize
& size
);
102 Mat3
SubRectMat3(const gfx::IntRect
& bigSubrect
, const gfx::IntSize
& smallSize
,
103 const gfx::IntSize
& divisors
);
105 class DrawBlitProg final
{
106 const GLBlitHelper
& mParent
;
108 const GLint mLoc_uDestMatrix
;
109 const GLint mLoc_uTexMatrix0
;
110 const GLint mLoc_uTexMatrix1
;
111 const GLint mLoc_uColorMatrix
;
112 GLenum mType_uColorMatrix
= 0;
116 const char* const fragHeader
;
117 const char* const fragBody
;
119 bool operator<(const Key
& x
) const {
120 if (fragHeader
!= x
.fragHeader
) return fragHeader
< x
.fragHeader
;
121 return fragBody
< x
.fragBody
;
125 DrawBlitProg(const GLBlitHelper
* parent
, GLuint prog
);
128 struct BaseArgs final
{
132 destSize
; // Always needed for (at least) setting the viewport.
133 Maybe
<gfx::IntRect
> destRect
;
135 struct YUVArgs final
{
137 gfx::YUVColorSpace colorSpace
;
140 void Draw(const BaseArgs
& args
, const YUVArgs
* argsYUV
= nullptr) const;
143 class ScopedSaveMultiTex final
{
145 const uint8_t mTexCount
;
146 const GLenum mTexTarget
;
147 const GLuint mOldTexUnit
;
148 GLuint mOldTexSampler
[3];
152 ScopedSaveMultiTex(GLContext
* gl
, uint8_t texCount
, GLenum texTarget
);
153 ~ScopedSaveMultiTex();
156 /** Buffer blitting helper */
157 class GLBlitHelper final
{
158 friend class BindAnglePlanes
;
159 friend class DrawBlitProg
;
160 friend class GLContext
;
162 GLContext
* const mGL
;
163 mutable std::map
<DrawBlitProg::Key
, const DrawBlitProg
*> mDrawBlitProgs
;
167 nsCString mDrawBlitProg_VersionLine
;
168 const GLuint mDrawBlitProg_VertShader
;
170 GLuint mYuvUploads
[3] = {};
171 gfx::IntSize mYuvUploads_YSize
= {0, 0};
172 gfx::IntSize mYuvUploads_UVSize
= {0, 0};
175 mutable RefPtr
<ID3D11Device
> mD3D11
;
177 ID3D11Device
* GetD3D11() const;
180 const DrawBlitProg
* GetDrawBlitProg(const DrawBlitProg::Key
& key
) const;
183 const DrawBlitProg
* CreateDrawBlitProg(const DrawBlitProg::Key
& key
) const;
186 bool BlitPlanarYCbCr(const layers::PlanarYCbCrData
&,
187 const gfx::IntSize
& destSize
, OriginPos destOrigin
);
188 #ifdef MOZ_WIDGET_ANDROID
189 bool Blit(const java::GeckoSurfaceTexture::Ref
& surfaceTexture
,
190 const gfx::IntSize
& destSize
, const OriginPos destOrigin
) const;
193 bool BlitImage(layers::MacIOSurfaceImage
* srcImage
,
194 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
197 bool Blit(DMABufSurface
* surface
, const gfx::IntSize
& destSize
,
198 OriginPos destOrigin
) const;
199 bool BlitImage(layers::DMABUFSurfaceImage
* srcImage
,
200 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
203 explicit GLBlitHelper(GLContext
* gl
);
208 void BlitFramebuffer(const gfx::IntRect
& srcRect
,
209 const gfx::IntRect
& destRect
,
210 GLuint filter
= LOCAL_GL_NEAREST
) const;
211 void BlitFramebufferToFramebuffer(GLuint srcFB
, GLuint destFB
,
212 const gfx::IntRect
& srcRect
,
213 const gfx::IntRect
& destRect
,
214 GLuint filter
= LOCAL_GL_NEAREST
) const;
215 void BlitFramebufferToTexture(GLuint destTex
, const gfx::IntSize
& srcSize
,
216 const gfx::IntSize
& destSize
,
217 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
218 void BlitTextureToFramebuffer(GLuint srcTex
, const gfx::IntSize
& srcSize
,
219 const gfx::IntSize
& destSize
,
220 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
) const;
221 void BlitTextureToTexture(GLuint srcTex
, GLuint destTex
,
222 const gfx::IntSize
& srcSize
,
223 const gfx::IntSize
& destSize
,
224 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
225 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
227 void DrawBlitTextureToFramebuffer(GLuint srcTex
, const gfx::IntSize
& srcSize
,
228 const gfx::IntSize
& destSize
,
229 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
230 bool srcIsBGRA
= false) const;
232 bool BlitImageToFramebuffer(layers::Image
* srcImage
,
233 const gfx::IntSize
& destSize
,
234 OriginPos destOrigin
);
235 bool BlitSdToFramebuffer(const layers::SurfaceDescriptor
&,
236 const gfx::IntSize
& destSize
, OriginPos destOrigin
);
239 bool BlitImage(layers::GPUVideoImage
* srcImage
, const gfx::IntSize
& destSize
,
240 OriginPos destOrigin
) const;
242 bool BlitImage(MacIOSurface
* const iosurf
, const gfx::IntSize
& destSize
,
243 OriginPos destOrigin
) const;
246 // GLBlitHelperD3D.cpp:
247 bool BlitImage(layers::D3D11ShareHandleImage
* srcImage
,
248 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
249 bool BlitImage(layers::D3D11TextureIMFSampleImage
* srcImage
,
250 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
251 bool BlitImage(layers::D3D11YCbCrImage
* srcImage
,
252 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
254 bool BlitDescriptor(const layers::SurfaceDescriptorD3D10
& desc
,
255 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
256 bool BlitDescriptor(const layers::SurfaceDescriptorDXGIYCbCr
& desc
,
257 const gfx::IntSize
& destSize
,
258 const OriginPos destOrigin
) const;
259 bool BlitAngleYCbCr(const WindowsHandle (&handleList
)[3],
260 const gfx::IntRect
& clipRect
, const gfx::IntSize
& ySize
,
261 const gfx::IntSize
& uvSize
,
262 const gfx::YUVColorSpace colorSpace
,
263 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
265 bool BlitAnglePlanes(uint8_t numPlanes
,
266 const RefPtr
<ID3D11Texture2D
>* texD3DList
,
267 const DrawBlitProg
* prog
,
268 const DrawBlitProg::BaseArgs
& baseArgs
,
269 const DrawBlitProg::YUVArgs
* const yuvArgs
) const;
273 extern const char* const kFragHeader_Tex2D
;
274 extern const char* const kFragHeader_Tex2DRect
;
275 extern const char* const kFragHeader_TexExt
;
276 extern const char* const kFragBody_RGBA
;
277 extern const char* const kFragBody_CrYCb
;
278 extern const char* const kFragBody_NV12
;
279 extern const char* const kFragBody_PlanarYUV
;
282 } // namespace mozilla
284 #endif // GLBLITHELPER_H_