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 GFX_OGLSHADERCONFIG_H
8 #define GFX_OGLSHADERCONFIG_H
11 #include "ImageTypes.h"
12 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
13 #include "mozilla/RefPtr.h" // for RefPtr
14 #include "mozilla/gfx/Matrix.h" // for Matrix4x4
15 #include "mozilla/gfx/Rect.h" // for Rect
16 #include "mozilla/gfx/Types.h"
17 #include "nsDebug.h" // for NS_ASSERTION
18 #include "nsPoint.h" // for nsIntPoint
19 #include "nsTArray.h" // for nsTArray
20 #include "mozilla/layers/CompositorTypes.h"
26 ENABLE_RENDER_COLOR
= 0x01,
27 ENABLE_TEXTURE_RECT
= 0x02,
28 ENABLE_TEXTURE_EXTERNAL
= 0x04,
29 ENABLE_TEXTURE_YCBCR
= 0x08,
30 ENABLE_TEXTURE_NV12
= 0x10,
31 ENABLE_TEXTURE_COMPONENT_ALPHA
= 0x20,
32 ENABLE_TEXTURE_NO_ALPHA
= 0x40,
33 ENABLE_TEXTURE_RB_SWAP
= 0x80,
34 ENABLE_OPACITY
= 0x100,
36 ENABLE_COLOR_MATRIX
= 0x400,
38 ENABLE_NO_PREMUL_ALPHA
= 0x1000,
40 ENABLE_DYNAMIC_GEOMETRY
= 0x4000,
41 ENABLE_MASK_TEXTURE_RECT
= 0x8000,
42 ENABLE_TEXTURE_NV12_GA_SWITCH
= 0x10000,
47 // this needs to be kept in sync with strings in 'AddUniforms'
48 enum KnownUniformName
{
49 NotAKnownUniform
= -1,
52 LayerTransformInverse
,
67 CbCrTexCoordMultiplier
,
78 mName
= NotAKnownUniform
;
79 mNameString
= nullptr;
81 memset(&mValue
, 0, sizeof(mValue
));
84 bool UpdateUniform(int32_t i1
) {
85 if (mLocation
== -1) return false;
86 if (mValue
.i1
!= i1
) {
93 bool UpdateUniform(float f1
) {
94 if (mLocation
== -1) return false;
95 if (mValue
.f1
!= f1
) {
102 bool UpdateUniform(float f1
, float f2
) {
103 if (mLocation
== -1) return false;
104 if (mValue
.f16v
[0] != f1
|| mValue
.f16v
[1] != f2
) {
112 bool UpdateUniform(float f1
, float f2
, float f3
, float f4
) {
113 if (mLocation
== -1) return false;
114 if (mValue
.f16v
[0] != f1
|| mValue
.f16v
[1] != f2
|| mValue
.f16v
[2] != f3
||
115 mValue
.f16v
[3] != f4
) {
125 bool UpdateUniform(int cnt
, const float* fp
) {
126 if (mLocation
== -1) return false;
134 if (memcmp(mValue
.f16v
, fp
, sizeof(float) * cnt
) != 0) {
135 memcpy(mValue
.f16v
, fp
, sizeof(float) * cnt
);
141 MOZ_ASSERT_UNREACHABLE("cnt must be 1 2 3 4 9 or 16");
145 bool UpdateArrayUniform(int cnt
, const float* fp
) {
146 if (mLocation
== -1) return false;
151 if (memcmp(mValue
.f16v
, fp
, sizeof(float) * cnt
) != 0) {
152 memcpy(mValue
.f16v
, fp
, sizeof(float) * cnt
);
158 bool UpdateArrayUniform(int cnt
, const gfx::Point3D
* points
) {
159 if (mLocation
== -1) return false;
166 for (int i
= 0; i
< cnt
; i
++) {
167 // Note: Do not want to make assumptions about .x, .y, .z member packing.
168 // If gfx::Point3D is updated to make this guarantee, SIMD optimizations
175 if (memcmp(mValue
.f16v
, fp
, sizeof(float) * cnt
* 3) != 0) {
176 memcpy(mValue
.f16v
, fp
, sizeof(float) * cnt
* 3);
182 KnownUniformName mName
;
183 const char* mNameString
;
193 class ShaderConfigOGL
{
198 mCompositionOp(gfx::CompositionOp::OP_OVER
) {}
200 void SetRenderColor(bool aEnabled
);
201 void SetTextureTarget(GLenum aTarget
);
202 void SetMaskTextureTarget(GLenum aTarget
);
203 void SetRBSwap(bool aEnabled
);
204 void SetNoAlpha(bool aEnabled
);
205 void SetOpacity(bool aEnabled
);
206 void SetYCbCr(bool aEnabled
);
207 void SetNV12(bool aEnabled
);
208 void SetComponentAlpha(bool aEnabled
);
209 void SetColorMatrix(bool aEnabled
);
210 void SetBlur(bool aEnabled
);
211 void SetMask(bool aEnabled
);
212 void SetDEAA(bool aEnabled
);
213 void SetCompositionOp(gfx::CompositionOp aOp
);
214 void SetNoPremultipliedAlpha();
215 void SetDynamicGeometry(bool aEnabled
);
216 void SetColorMultiplier(uint32_t aMultiplier
);
218 bool operator<(const ShaderConfigOGL
& other
) const {
219 return mFeatures
< other
.mFeatures
||
220 (mFeatures
== other
.mFeatures
&&
221 (int)mCompositionOp
< (int)other
.mCompositionOp
) ||
222 (mFeatures
== other
.mFeatures
&&
223 (int)mCompositionOp
== (int)other
.mCompositionOp
&&
224 mMultiplier
< other
.mMultiplier
);
228 void SetFeature(int aBitmask
, bool aState
) {
230 mFeatures
|= aBitmask
;
232 mFeatures
&= (~aBitmask
);
236 uint32_t mMultiplier
;
237 gfx::CompositionOp mCompositionOp
;
240 static inline ShaderConfigOGL
ShaderConfigFromTargetAndFormat(
241 GLenum aTarget
, gfx::SurfaceFormat aFormat
) {
242 ShaderConfigOGL config
;
243 config
.SetTextureTarget(aTarget
);
244 config
.SetRBSwap(aFormat
== gfx::SurfaceFormat::B8G8R8A8
||
245 aFormat
== gfx::SurfaceFormat::B8G8R8X8
);
246 config
.SetNoAlpha(aFormat
== gfx::SurfaceFormat::B8G8R8X8
||
247 aFormat
== gfx::SurfaceFormat::R8G8B8X8
||
248 aFormat
== gfx::SurfaceFormat::R5G6B5_UINT16
);
252 } // namespace layers
253 } // namespace mozilla
255 #endif // GFX_OGLSHADERCONFIG_H