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
;
44 class PlanarYCbCrImage
;
45 class SurfaceDescriptor
;
48 class D3D11ShareHandleImage
;
49 class D3D11YCbCrImage
;
50 class SurfaceDescriptorD3D10
;
51 class SurfaceDescriptorDXGIYCbCr
;
54 #ifdef MOZ_WIDGET_ANDROID
55 class SurfaceTextureImage
;
59 class MacIOSurfaceImage
;
63 class DMABUFSurfaceImage
;
69 class BindAnglePlanes
;
73 bool GuessDivisors(const gfx::IntSize
& ySize
, const gfx::IntSize
& uvSize
,
74 gfx::IntSize
* const out_divisors
);
78 float m
[N
* N
]; // column-major, for GL
80 float& at(const uint8_t x
, const uint8_t y
) { return m
[N
* x
+ y
]; }
85 Mat
<N
> operator*(const Mat
<N
>& r
) const;
89 Mat3
SubRectMat3(float x
, float y
, float w
, float h
);
90 Mat3
SubRectMat3(const gfx::IntRect
& subrect
, const gfx::IntSize
& size
);
91 Mat3
SubRectMat3(const gfx::IntRect
& bigSubrect
, const gfx::IntSize
& smallSize
,
92 const gfx::IntSize
& divisors
);
94 class DrawBlitProg final
{
95 const GLBlitHelper
& mParent
;
97 const GLint mLoc_uDestMatrix
;
98 const GLint mLoc_uTexMatrix0
;
99 const GLint mLoc_uTexMatrix1
;
100 const GLint mLoc_uColorMatrix
;
101 GLenum mType_uColorMatrix
= 0;
105 const char* const fragHeader
;
106 const char* const fragBody
;
108 bool operator<(const Key
& x
) const {
109 if (fragHeader
!= x
.fragHeader
) return fragHeader
< x
.fragHeader
;
110 return fragBody
< x
.fragBody
;
114 DrawBlitProg(const GLBlitHelper
* parent
, GLuint prog
);
117 struct BaseArgs final
{
121 destSize
; // Always needed for (at least) setting the viewport.
122 Maybe
<gfx::IntRect
> destRect
;
124 struct YUVArgs final
{
126 gfx::YUVColorSpace colorSpace
;
129 void Draw(const BaseArgs
& args
, const YUVArgs
* argsYUV
= nullptr) const;
132 class ScopedSaveMultiTex final
{
134 const uint8_t mTexCount
;
135 const GLenum mTexTarget
;
136 const GLuint mOldTexUnit
;
137 GLuint mOldTexSampler
[3];
141 ScopedSaveMultiTex(GLContext
* gl
, uint8_t texCount
, GLenum texTarget
);
142 ~ScopedSaveMultiTex();
145 /** Buffer blitting helper */
146 class GLBlitHelper final
{
147 friend class BindAnglePlanes
;
148 friend class DrawBlitProg
;
149 friend class GLContext
;
151 GLContext
* const mGL
;
152 mutable std::map
<DrawBlitProg::Key
, const DrawBlitProg
*> mDrawBlitProgs
;
156 nsCString mDrawBlitProg_VersionLine
;
157 const GLuint mDrawBlitProg_VertShader
;
159 GLuint mYuvUploads
[3] = {};
160 gfx::IntSize mYuvUploads_YSize
= {0, 0};
161 gfx::IntSize mYuvUploads_UVSize
= {0, 0};
164 mutable RefPtr
<ID3D11Device
> mD3D11
;
166 ID3D11Device
* GetD3D11() const;
169 const DrawBlitProg
* GetDrawBlitProg(const DrawBlitProg::Key
& key
) const;
172 const DrawBlitProg
* CreateDrawBlitProg(const DrawBlitProg::Key
& key
) const;
175 bool BlitImage(layers::PlanarYCbCrImage
* yuvImage
,
176 const gfx::IntSize
& destSize
, OriginPos destOrigin
);
177 #ifdef MOZ_WIDGET_ANDROID
178 // Blit onto the current FB.
179 bool BlitImage(layers::SurfaceTextureImage
* stImage
,
180 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
183 bool BlitImage(layers::MacIOSurfaceImage
* srcImage
,
184 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
187 bool BlitImage(layers::DMABUFSurfaceImage
* srcImage
,
188 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
191 explicit GLBlitHelper(GLContext
* gl
);
196 void BlitFramebuffer(const gfx::IntRect
& srcRect
,
197 const gfx::IntRect
& destRect
,
198 GLuint filter
= LOCAL_GL_NEAREST
) const;
199 void BlitFramebufferToFramebuffer(GLuint srcFB
, GLuint destFB
,
200 const gfx::IntRect
& srcRect
,
201 const gfx::IntRect
& destRect
,
202 GLuint filter
= LOCAL_GL_NEAREST
) const;
203 void BlitFramebufferToTexture(GLuint destTex
, const gfx::IntSize
& srcSize
,
204 const gfx::IntSize
& destSize
,
205 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
206 void BlitTextureToFramebuffer(GLuint srcTex
, const gfx::IntSize
& srcSize
,
207 const gfx::IntSize
& destSize
,
208 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
) const;
209 void BlitTextureToTexture(GLuint srcTex
, GLuint destTex
,
210 const gfx::IntSize
& srcSize
,
211 const gfx::IntSize
& destSize
,
212 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
,
213 GLenum destTarget
= LOCAL_GL_TEXTURE_2D
) const;
215 void DrawBlitTextureToFramebuffer(
216 GLuint srcTex
, const gfx::IntSize
& srcSize
, const gfx::IntSize
& destSize
,
217 GLenum srcTarget
= LOCAL_GL_TEXTURE_2D
) const;
219 bool BlitImageToFramebuffer(layers::Image
* srcImage
,
220 const gfx::IntSize
& destSize
,
221 OriginPos destOrigin
);
222 bool BlitSdToFramebuffer(const layers::SurfaceDescriptor
&,
223 const gfx::IntSize
& destSize
, OriginPos destOrigin
);
226 bool BlitImage(layers::GPUVideoImage
* srcImage
, const gfx::IntSize
& destSize
,
227 OriginPos destOrigin
) const;
229 bool BlitImage(MacIOSurface
* const iosurf
, const gfx::IntSize
& destSize
,
230 OriginPos destOrigin
) const;
233 // GLBlitHelperD3D.cpp:
234 bool BlitImage(layers::D3D11ShareHandleImage
* srcImage
,
235 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
236 bool BlitImage(layers::D3D11YCbCrImage
* srcImage
,
237 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
239 bool BlitDescriptor(const layers::SurfaceDescriptorD3D10
& desc
,
240 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
241 bool BlitDescriptor(const layers::SurfaceDescriptorDXGIYCbCr
& desc
,
242 const gfx::IntSize
& destSize
,
243 const OriginPos destOrigin
) const;
244 bool BlitAngleYCbCr(const WindowsHandle (&handleList
)[3],
245 const gfx::IntRect
& clipRect
, const gfx::IntSize
& ySize
,
246 const gfx::IntSize
& uvSize
,
247 const gfx::YUVColorSpace colorSpace
,
248 const gfx::IntSize
& destSize
, OriginPos destOrigin
) const;
250 bool BlitAnglePlanes(uint8_t numPlanes
,
251 const RefPtr
<ID3D11Texture2D
>* texD3DList
,
252 const DrawBlitProg
* prog
,
253 const DrawBlitProg::BaseArgs
& baseArgs
,
254 const DrawBlitProg::YUVArgs
* const yuvArgs
) const;
258 extern const char* const kFragHeader_Tex2D
;
259 extern const char* const kFragHeader_Tex2DRect
;
260 extern const char* const kFragHeader_TexExt
;
261 extern const char* const kFragBody_RGBA
;
262 extern const char* const kFragBody_CrYCb
;
263 extern const char* const kFragBody_NV12
;
264 extern const char* const kFragBody_PlanarYUV
;
267 } // namespace mozilla
269 #endif // GLBLITHELPER_H_