Bug 1666648 [wpt PR 25683] - Fix #23969: Use inexact test type for DUPLICATE-BASENAME...
[gecko.git] / gfx / gl / GLBlitHelper.h
blobbb7cd1cd5a7a85f107eedc708be82d943b67f6aa
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"
11 #include "GLConsts.h"
12 #include "nsSize.h"
13 #include "ipc/IPCMessageUtils.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/gfx/Point.h"
16 #include "../layers/ImageTypes.h"
18 #ifdef XP_WIN
19 # include <windows.h>
20 #endif
22 namespace mozilla {
24 namespace layers {
25 class D3D11ShareHandleImage;
26 class D3D11YCbCrImage;
27 class Image;
28 class GPUVideoImage;
29 class PlanarYCbCrImage;
30 class SurfaceTextureImage;
31 class MacIOSurfaceImage;
32 class SurfaceDescriptorD3D10;
33 class SurfaceDescriptorDXGIYCbCr;
34 } // namespace layers
36 namespace gl {
38 class BindAnglePlanes;
39 class GLContext;
40 class GLBlitHelper;
42 bool GuessDivisors(const gfx::IntSize& ySize, const gfx::IntSize& uvSize,
43 gfx::IntSize* const out_divisors);
45 template <uint8_t N>
46 struct Mat {
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]; }
51 static Mat<N> Zero();
52 static Mat<N> I();
54 Mat<N> operator*(const Mat<N>& r) const;
56 typedef Mat<3> Mat3;
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;
65 const GLuint mProg;
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;
72 public:
73 struct Key final {
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);
84 ~DrawBlitProg();
86 struct BaseArgs final {
87 Mat3 texMatrix0;
88 bool yFlip;
89 gfx::IntSize
90 destSize; // Always needed for (at least) setting the viewport.
91 Maybe<gfx::IntRect> destRect;
93 struct YUVArgs final {
94 Mat3 texMatrix1;
95 gfx::YUVColorSpace colorSpace;
98 void Draw(const BaseArgs& args, const YUVArgs* argsYUV = nullptr) const;
101 class ScopedSaveMultiTex final {
102 GLContext& mGL;
103 const uint8_t mTexCount;
104 const GLenum mTexTarget;
105 const GLuint mOldTexUnit;
106 GLuint mOldTexSampler[3];
107 GLuint mOldTex[3];
109 public:
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;
123 GLuint mQuadVAO = 0;
124 GLuint mQuadVBO = 0;
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};
132 #ifdef XP_WIN
133 mutable RefPtr<ID3D11Device> mD3D11;
135 ID3D11Device* GetD3D11() const;
136 #endif
138 const DrawBlitProg* GetDrawBlitProg(const DrawBlitProg::Key& key) const;
140 private:
141 const DrawBlitProg* CreateDrawBlitProg(const DrawBlitProg::Key& key) const;
143 public:
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;
150 #endif
151 #ifdef XP_MACOSX
152 bool BlitImage(layers::MacIOSurfaceImage* srcImage,
153 const gfx::IntSize& destSize, OriginPos destOrigin) const;
154 #endif
156 explicit GLBlitHelper(GLContext* gl);
158 public:
159 ~GLBlitHelper();
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);
188 private:
189 #ifdef XP_WIN
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;
212 #endif
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;
223 } // namespace gl
224 } // namespace mozilla
226 #endif // GLBLITHELPER_H_