Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef GFX_OGLSHADERPROGRAM_H
7 : #define GFX_OGLSHADERPROGRAM_H
8 :
9 : #include "GLContext.h" // for fast inlines of glUniform*
10 : #include "gfxTypes.h"
11 : #include "ImageTypes.h"
12 : #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
13 : #include "mozilla/Pair.h" // for Pair
14 : #include "mozilla/RefPtr.h" // for RefPtr
15 : #include "mozilla/gfx/Matrix.h" // for Matrix4x4
16 : #include "mozilla/gfx/Rect.h" // for Rect
17 : #include "mozilla/gfx/Types.h"
18 : #include "nsDebug.h" // for NS_ASSERTION
19 : #include "nsPoint.h" // for nsIntPoint
20 : #include "nsTArray.h" // for nsTArray
21 : #include "mozilla/layers/CompositorTypes.h"
22 :
23 : #include <string>
24 :
25 : namespace mozilla {
26 : namespace layers {
27 :
28 : class Layer;
29 :
30 : enum ShaderFeatures {
31 : ENABLE_RENDER_COLOR=0x01,
32 : ENABLE_TEXTURE_RECT=0x02,
33 : ENABLE_TEXTURE_EXTERNAL=0x04,
34 : ENABLE_TEXTURE_YCBCR=0x08,
35 : ENABLE_TEXTURE_NV12=0x10,
36 : ENABLE_TEXTURE_COMPONENT_ALPHA=0x20,
37 : ENABLE_TEXTURE_NO_ALPHA=0x40,
38 : ENABLE_TEXTURE_RB_SWAP=0x80,
39 : ENABLE_OPACITY=0x100,
40 : ENABLE_BLUR=0x200,
41 : ENABLE_COLOR_MATRIX=0x400,
42 : ENABLE_MASK=0x800,
43 : ENABLE_NO_PREMUL_ALPHA=0x1000,
44 : ENABLE_DEAA=0x2000,
45 : ENABLE_DYNAMIC_GEOMETRY=0x4000
46 : };
47 :
48 : class KnownUniform {
49 : public:
50 : // this needs to be kept in sync with strings in 'AddUniforms'
51 : enum KnownUniformName {
52 : NotAKnownUniform = -1,
53 :
54 : LayerTransform = 0,
55 : LayerTransformInverse,
56 : MaskTransform,
57 : BackdropTransform,
58 : LayerRects,
59 : MatrixProj,
60 : TextureTransform,
61 : TextureRects,
62 : RenderTargetOffset,
63 : LayerOpacity,
64 : Texture,
65 : YTexture,
66 : CbTexture,
67 : CrTexture,
68 : BlackTexture,
69 : WhiteTexture,
70 : MaskTexture,
71 : BackdropTexture,
72 : RenderColor,
73 : TexCoordMultiplier,
74 : CbCrTexCoordMultiplier,
75 : TexturePass2,
76 : ColorMatrix,
77 : ColorMatrixVector,
78 : BlurRadius,
79 : BlurOffset,
80 : BlurAlpha,
81 : BlurGaussianKernel,
82 : SSEdges,
83 : ViewportSize,
84 : VisibleCenter,
85 : YuvColorMatrix,
86 :
87 : KnownUniformCount
88 : };
89 :
90 0 : KnownUniform()
91 0 : {
92 0 : mName = NotAKnownUniform;
93 0 : mNameString = nullptr;
94 0 : mLocation = -1;
95 0 : memset(&mValue, 0, sizeof(mValue));
96 0 : }
97 :
98 0 : bool UpdateUniform(int32_t i1) {
99 0 : if (mLocation == -1) return false;
100 0 : if (mValue.i1 != i1) {
101 0 : mValue.i1 = i1;
102 0 : return true;
103 : }
104 0 : return false;
105 : }
106 :
107 0 : bool UpdateUniform(float f1) {
108 0 : if (mLocation == -1) return false;
109 0 : if (mValue.f1 != f1) {
110 0 : mValue.f1 = f1;
111 0 : return true;
112 : }
113 0 : return false;
114 : }
115 :
116 : bool UpdateUniform(float f1, float f2) {
117 : if (mLocation == -1) return false;
118 : if (mValue.f16v[0] != f1 ||
119 : mValue.f16v[1] != f2)
120 : {
121 : mValue.f16v[0] = f1;
122 : mValue.f16v[1] = f2;
123 : return true;
124 : }
125 : return false;
126 : }
127 :
128 0 : bool UpdateUniform(float f1, float f2, float f3, float f4) {
129 0 : if (mLocation == -1) return false;
130 0 : if (mValue.f16v[0] != f1 ||
131 0 : mValue.f16v[1] != f2 ||
132 0 : mValue.f16v[2] != f3 ||
133 0 : mValue.f16v[3] != f4)
134 : {
135 0 : mValue.f16v[0] = f1;
136 0 : mValue.f16v[1] = f2;
137 0 : mValue.f16v[2] = f3;
138 0 : mValue.f16v[3] = f4;
139 0 : return true;
140 : }
141 0 : return false;
142 : }
143 :
144 0 : bool UpdateUniform(int cnt, const float *fp) {
145 0 : if (mLocation == -1) return false;
146 0 : switch (cnt) {
147 : case 1:
148 : case 2:
149 : case 3:
150 : case 4:
151 : case 9:
152 : case 16:
153 0 : if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
154 0 : memcpy(mValue.f16v, fp, sizeof(float) * cnt);
155 0 : return true;
156 : }
157 0 : return false;
158 : }
159 :
160 0 : NS_NOTREACHED("cnt must be 1 2 3 4 9 or 16");
161 0 : return false;
162 : }
163 :
164 0 : bool UpdateArrayUniform(int cnt, const float *fp) {
165 0 : if (mLocation == -1) return false;
166 0 : if (cnt > 16) {
167 0 : return false;
168 : }
169 :
170 0 : if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
171 0 : memcpy(mValue.f16v, fp, sizeof(float) * cnt);
172 0 : return true;
173 : }
174 0 : return false;
175 : }
176 :
177 0 : bool UpdateArrayUniform(int cnt, const gfx::Point3D* points) {
178 0 : if (mLocation == -1) return false;
179 0 : if (cnt > 4) {
180 0 : return false;
181 : }
182 :
183 : float fp[12];
184 0 : float *d = fp;
185 0 : for(int i=0; i < cnt; i++) {
186 : // Note: Do not want to make assumptions about .x, .y, .z member packing.
187 : // If gfx::Point3D is updated to make this guarantee, SIMD optimizations
188 : // may be possible
189 0 : *d++ = points[i].x;
190 0 : *d++ = points[i].y;
191 0 : *d++ = points[i].z;
192 : }
193 :
194 0 : if (memcmp(mValue.f16v, fp, sizeof(float) * cnt * 3) != 0) {
195 0 : memcpy(mValue.f16v, fp, sizeof(float) * cnt * 3);
196 0 : return true;
197 : }
198 0 : return false;
199 : }
200 :
201 : KnownUniformName mName;
202 : const char *mNameString;
203 : int32_t mLocation;
204 :
205 : union {
206 : int i1;
207 : float f1;
208 : float f16v[16];
209 : } mValue;
210 : };
211 :
212 : class ShaderConfigOGL
213 : {
214 : public:
215 0 : ShaderConfigOGL() :
216 : mFeatures(0),
217 0 : mCompositionOp(gfx::CompositionOp::OP_OVER)
218 0 : {}
219 :
220 : void SetRenderColor(bool aEnabled);
221 : void SetTextureTarget(GLenum aTarget);
222 : void SetRBSwap(bool aEnabled);
223 : void SetNoAlpha(bool aEnabled);
224 : void SetOpacity(bool aEnabled);
225 : void SetYCbCr(bool aEnabled);
226 : void SetNV12(bool aEnabled);
227 : void SetComponentAlpha(bool aEnabled);
228 : void SetColorMatrix(bool aEnabled);
229 : void SetBlur(bool aEnabled);
230 : void SetMask(bool aEnabled);
231 : void SetDEAA(bool aEnabled);
232 : void SetCompositionOp(gfx::CompositionOp aOp);
233 : void SetNoPremultipliedAlpha();
234 : void SetDynamicGeometry(bool aEnabled);
235 :
236 0 : bool operator< (const ShaderConfigOGL& other) const {
237 0 : return mFeatures < other.mFeatures ||
238 0 : (mFeatures == other.mFeatures &&
239 0 : (int)mCompositionOp < (int)other.mCompositionOp);
240 : }
241 :
242 : public:
243 0 : void SetFeature(int aBitmask, bool aState) {
244 0 : if (aState)
245 0 : mFeatures |= aBitmask;
246 : else
247 0 : mFeatures &= (~aBitmask);
248 0 : }
249 :
250 : int mFeatures;
251 : gfx::CompositionOp mCompositionOp;
252 : };
253 :
254 : static inline ShaderConfigOGL
255 0 : ShaderConfigFromTargetAndFormat(GLenum aTarget,
256 : gfx::SurfaceFormat aFormat)
257 : {
258 0 : ShaderConfigOGL config;
259 0 : config.SetTextureTarget(aTarget);
260 0 : config.SetRBSwap(aFormat == gfx::SurfaceFormat::B8G8R8A8 ||
261 0 : aFormat == gfx::SurfaceFormat::B8G8R8X8);
262 0 : config.SetNoAlpha(aFormat == gfx::SurfaceFormat::B8G8R8X8 ||
263 0 : aFormat == gfx::SurfaceFormat::R8G8B8X8 ||
264 0 : aFormat == gfx::SurfaceFormat::R5G6B5_UINT16);
265 0 : return config;
266 : }
267 :
268 : /**
269 : * This struct represents the shaders that make up a program and the uniform
270 : * and attribute parmeters that those shaders take.
271 : * It is used by ShaderProgramOGL.
272 : * Use the factory method GetProfileFor to create instances.
273 : */
274 0 : struct ProgramProfileOGL
275 : {
276 : /**
277 : * Factory method; creates an instance of this class for the given
278 : * ShaderConfigOGL
279 : */
280 : static ProgramProfileOGL GetProfileFor(ShaderConfigOGL aConfig);
281 :
282 : // the source code for the program's shaders
283 : std::string mVertexShaderString;
284 : std::string mFragmentShaderString;
285 :
286 : // the vertex attributes
287 : nsTArray<Pair<nsCString, GLuint>> mAttributes;
288 :
289 : KnownUniform mUniforms[KnownUniform::KnownUniformCount];
290 : nsTArray<const char *> mDefines;
291 : size_t mTextureCount;
292 :
293 0 : ProgramProfileOGL() :
294 0 : mTextureCount(0)
295 0 : {}
296 :
297 : private:
298 : static void BuildMixBlender(const ShaderConfigOGL& aConfig, std::ostringstream& fs);
299 : };
300 :
301 :
302 : #if defined(DEBUG)
303 : #define CHECK_CURRENT_PROGRAM 1
304 : #define ASSERT_THIS_PROGRAM \
305 : do { \
306 : GLuint currentProgram; \
307 : mGL->GetUIntegerv(LOCAL_GL_CURRENT_PROGRAM, ¤tProgram); \
308 : MOZ_ASSERT(currentProgram == mProgram, \
309 : "SetUniform with wrong program active!"); \
310 : } while (0)
311 : #else
312 : #define ASSERT_THIS_PROGRAM \
313 : do { } while (0)
314 : #endif
315 :
316 : /**
317 : * Represents an OGL shader program. The details of a program are represented
318 : * by a ProgramProfileOGL
319 : */
320 : class ShaderProgramOGL
321 : {
322 : public:
323 : typedef mozilla::gl::GLContext GLContext;
324 :
325 : ShaderProgramOGL(GLContext* aGL, const ProgramProfileOGL& aProfile);
326 :
327 : ~ShaderProgramOGL();
328 :
329 0 : bool HasInitialized() {
330 0 : NS_ASSERTION(mProgramState != STATE_OK || mProgram > 0, "Inconsistent program state");
331 0 : return mProgramState == STATE_OK;
332 : }
333 :
334 : GLuint GetProgram();
335 :
336 : bool Initialize();
337 :
338 : GLint CreateShader(GLenum aShaderType, const char *aShaderSource);
339 :
340 : /**
341 : * Creates a program and stores its id.
342 : */
343 : bool CreateProgram(const char *aVertexShaderString,
344 : const char *aFragmentShaderString);
345 :
346 : /**
347 : * The following set of methods set a uniform argument to the shader program.
348 : * Not all uniforms may be set for all programs, and such uses will throw
349 : * an assertion.
350 : */
351 0 : void SetLayerTransform(const gfx::Matrix4x4& aMatrix) {
352 0 : SetMatrixUniform(KnownUniform::LayerTransform, aMatrix);
353 0 : }
354 :
355 0 : void SetLayerTransformInverse(const gfx::Matrix4x4& aMatrix) {
356 0 : SetMatrixUniform(KnownUniform::LayerTransformInverse, aMatrix);
357 0 : }
358 :
359 0 : void SetMaskLayerTransform(const gfx::Matrix4x4& aMatrix) {
360 0 : SetMatrixUniform(KnownUniform::MaskTransform, aMatrix);
361 0 : }
362 :
363 0 : void SetBackdropTransform(const gfx::Matrix4x4& aMatrix) {
364 0 : SetMatrixUniform(KnownUniform::BackdropTransform, aMatrix);
365 0 : }
366 :
367 0 : void SetDEAAEdges(const gfx::Point3D* aEdges) {
368 0 : SetArrayUniform(KnownUniform::SSEdges, 4, aEdges);
369 0 : }
370 :
371 0 : void SetViewportSize(const gfx::IntSize& aSize) {
372 0 : float vals[2] = { (float)aSize.width, (float)aSize.height };
373 0 : SetUniform(KnownUniform::ViewportSize, 2, vals);
374 0 : }
375 :
376 0 : void SetVisibleCenter(const gfx::Point& aVisibleCenter) {
377 0 : float vals[2] = { aVisibleCenter.x, aVisibleCenter.y };
378 0 : SetUniform(KnownUniform::VisibleCenter, 2, vals);
379 0 : }
380 :
381 0 : void SetLayerRects(const gfx::Rect* aRects) {
382 0 : float vals[16] = { aRects[0].x, aRects[0].y, aRects[0].width, aRects[0].height,
383 0 : aRects[1].x, aRects[1].y, aRects[1].width, aRects[1].height,
384 0 : aRects[2].x, aRects[2].y, aRects[2].width, aRects[2].height,
385 0 : aRects[3].x, aRects[3].y, aRects[3].width, aRects[3].height };
386 0 : SetUniform(KnownUniform::LayerRects, 16, vals);
387 0 : }
388 :
389 0 : void SetProjectionMatrix(const gfx::Matrix4x4& aMatrix) {
390 0 : SetMatrixUniform(KnownUniform::MatrixProj, aMatrix);
391 0 : }
392 :
393 : // sets this program's texture transform, if it uses one
394 0 : void SetTextureTransform(const gfx::Matrix4x4& aMatrix) {
395 0 : SetMatrixUniform(KnownUniform::TextureTransform, aMatrix);
396 0 : }
397 :
398 0 : void SetTextureRects(const gfx::Rect* aRects) {
399 0 : float vals[16] = { aRects[0].x, aRects[0].y, aRects[0].width, aRects[0].height,
400 0 : aRects[1].x, aRects[1].y, aRects[1].width, aRects[1].height,
401 0 : aRects[2].x, aRects[2].y, aRects[2].width, aRects[2].height,
402 0 : aRects[3].x, aRects[3].y, aRects[3].width, aRects[3].height };
403 0 : SetUniform(KnownUniform::TextureRects, 16, vals);
404 0 : }
405 :
406 : void SetRenderOffset(const nsIntPoint& aOffset) {
407 : float vals[4] = { float(aOffset.x), float(aOffset.y) };
408 : SetUniform(KnownUniform::RenderTargetOffset, 2, vals);
409 : }
410 :
411 0 : void SetRenderOffset(float aX, float aY) {
412 0 : float vals[2] = { aX, aY };
413 0 : SetUniform(KnownUniform::RenderTargetOffset, 2, vals);
414 0 : }
415 :
416 0 : void SetLayerOpacity(float aOpacity) {
417 0 : SetUniform(KnownUniform::LayerOpacity, aOpacity);
418 0 : }
419 :
420 0 : void SetTextureUnit(GLint aUnit) {
421 0 : SetUniform(KnownUniform::Texture, aUnit);
422 0 : }
423 : void SetYTextureUnit(GLint aUnit) {
424 : SetUniform(KnownUniform::YTexture, aUnit);
425 : }
426 :
427 : void SetCbTextureUnit(GLint aUnit) {
428 : SetUniform(KnownUniform::CbTexture, aUnit);
429 : }
430 :
431 : void SetCrTextureUnit(GLint aUnit) {
432 : SetUniform(KnownUniform::CrTexture, aUnit);
433 : }
434 :
435 0 : void SetYCbCrTextureUnits(GLint aYUnit, GLint aCbUnit, GLint aCrUnit) {
436 0 : SetUniform(KnownUniform::YTexture, aYUnit);
437 0 : SetUniform(KnownUniform::CbTexture, aCbUnit);
438 0 : SetUniform(KnownUniform::CrTexture, aCrUnit);
439 0 : }
440 :
441 0 : void SetNV12TextureUnits(GLint aYUnit, GLint aCbCrUnit) {
442 0 : SetUniform(KnownUniform::YTexture, aYUnit);
443 0 : SetUniform(KnownUniform::CbTexture, aCbCrUnit);
444 0 : }
445 :
446 0 : void SetBlackTextureUnit(GLint aUnit) {
447 0 : SetUniform(KnownUniform::BlackTexture, aUnit);
448 0 : }
449 :
450 0 : void SetWhiteTextureUnit(GLint aUnit) {
451 0 : SetUniform(KnownUniform::WhiteTexture, aUnit);
452 0 : }
453 :
454 0 : void SetMaskTextureUnit(GLint aUnit) {
455 0 : SetUniform(KnownUniform::MaskTexture, aUnit);
456 0 : }
457 :
458 0 : void SetBackdropTextureUnit(GLint aUnit) {
459 0 : SetUniform(KnownUniform::BackdropTexture, aUnit);
460 0 : }
461 :
462 0 : void SetRenderColor(const gfx::Color& aColor) {
463 0 : SetUniform(KnownUniform::RenderColor, aColor);
464 0 : }
465 :
466 0 : void SetColorMatrix(const gfx::Matrix5x4& aColorMatrix)
467 : {
468 0 : SetMatrixUniform(KnownUniform::ColorMatrix, &aColorMatrix._11);
469 0 : SetUniform(KnownUniform::ColorMatrixVector, 4, &aColorMatrix._51);
470 0 : }
471 :
472 0 : void SetTexCoordMultiplier(float aWidth, float aHeight) {
473 0 : float f[] = {aWidth, aHeight};
474 0 : SetUniform(KnownUniform::TexCoordMultiplier, 2, f);
475 0 : }
476 :
477 0 : void SetCbCrTexCoordMultiplier(float aWidth, float aHeight) {
478 0 : float f[] = {aWidth, aHeight};
479 0 : SetUniform(KnownUniform::CbCrTexCoordMultiplier, 2, f);
480 0 : }
481 :
482 : void SetYUVColorSpace(YUVColorSpace aYUVColorSpace);
483 :
484 : // Set whether we want the component alpha shader to return the color
485 : // vector (pass 1, false) or the alpha vector (pass2, true). With support
486 : // for multiple render targets we wouldn't need two passes here.
487 0 : void SetTexturePass2(bool aFlag) {
488 0 : SetUniform(KnownUniform::TexturePass2, aFlag ? 1 : 0);
489 0 : }
490 :
491 : void SetBlurRadius(float aRX, float aRY);
492 :
493 : void SetBlurAlpha(float aAlpha) {
494 : SetUniform(KnownUniform::BlurAlpha, aAlpha);
495 : }
496 :
497 : void SetBlurOffset(float aOffsetX, float aOffsetY) {
498 : float f[] = {aOffsetX, aOffsetY};
499 : SetUniform(KnownUniform::BlurOffset, 2, f);
500 : }
501 :
502 0 : size_t GetTextureCount() const {
503 0 : return mProfile.mTextureCount;
504 : }
505 :
506 : protected:
507 : RefPtr<GLContext> mGL;
508 : // the OpenGL id of the program
509 : GLuint mProgram;
510 : ProgramProfileOGL mProfile;
511 : enum {
512 : STATE_NEW,
513 : STATE_OK,
514 : STATE_ERROR
515 : } mProgramState;
516 :
517 : #ifdef CHECK_CURRENT_PROGRAM
518 : static int sCurrentProgramKey;
519 : #endif
520 :
521 0 : void SetUniform(KnownUniform::KnownUniformName aKnownUniform, float aFloatValue)
522 : {
523 0 : ASSERT_THIS_PROGRAM;
524 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
525 :
526 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
527 0 : if (ku.UpdateUniform(aFloatValue)) {
528 0 : mGL->fUniform1f(ku.mLocation, aFloatValue);
529 : }
530 0 : }
531 :
532 0 : void SetUniform(KnownUniform::KnownUniformName aKnownUniform, const gfx::Color& aColor) {
533 0 : ASSERT_THIS_PROGRAM;
534 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
535 :
536 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
537 0 : if (ku.UpdateUniform(aColor.r, aColor.g, aColor.b, aColor.a)) {
538 0 : mGL->fUniform4fv(ku.mLocation, 1, ku.mValue.f16v);
539 : }
540 0 : }
541 :
542 0 : void SetUniform(KnownUniform::KnownUniformName aKnownUniform, int aLength, const float *aFloatValues)
543 : {
544 0 : ASSERT_THIS_PROGRAM;
545 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
546 :
547 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
548 0 : if (ku.UpdateUniform(aLength, aFloatValues)) {
549 0 : switch (aLength) {
550 0 : case 1: mGL->fUniform1fv(ku.mLocation, 1, ku.mValue.f16v); break;
551 0 : case 2: mGL->fUniform2fv(ku.mLocation, 1, ku.mValue.f16v); break;
552 0 : case 3: mGL->fUniform3fv(ku.mLocation, 1, ku.mValue.f16v); break;
553 0 : case 4: mGL->fUniform4fv(ku.mLocation, 1, ku.mValue.f16v); break;
554 0 : case 16: mGL->fUniform4fv(ku.mLocation, 4, ku.mValue.f16v); break;
555 : default:
556 0 : NS_NOTREACHED("Bogus aLength param");
557 : }
558 : }
559 0 : }
560 :
561 0 : void SetArrayUniform(KnownUniform::KnownUniformName aKnownUniform, int aLength, float *aFloatValues)
562 : {
563 0 : ASSERT_THIS_PROGRAM;
564 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
565 :
566 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
567 0 : if (ku.UpdateArrayUniform(aLength, aFloatValues)) {
568 0 : mGL->fUniform1fv(ku.mLocation, aLength, ku.mValue.f16v);
569 : }
570 0 : }
571 :
572 0 : void SetArrayUniform(KnownUniform::KnownUniformName aKnownUniform, int aLength, const gfx::Point3D *aPointValues)
573 : {
574 0 : ASSERT_THIS_PROGRAM;
575 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
576 :
577 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
578 0 : if (ku.UpdateArrayUniform(aLength, aPointValues)) {
579 0 : mGL->fUniform3fv(ku.mLocation, aLength, ku.mValue.f16v);
580 : }
581 0 : }
582 :
583 0 : void SetUniform(KnownUniform::KnownUniformName aKnownUniform, GLint aIntValue) {
584 0 : ASSERT_THIS_PROGRAM;
585 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
586 :
587 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
588 0 : if (ku.UpdateUniform(aIntValue)) {
589 0 : mGL->fUniform1i(ku.mLocation, aIntValue);
590 : }
591 0 : }
592 :
593 0 : void SetMatrixUniform(KnownUniform::KnownUniformName aKnownUniform, const float *aFloatValues) {
594 0 : ASSERT_THIS_PROGRAM;
595 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
596 :
597 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
598 0 : if (ku.UpdateUniform(16, aFloatValues)) {
599 0 : mGL->fUniformMatrix4fv(ku.mLocation, 1, false, ku.mValue.f16v);
600 : }
601 0 : }
602 :
603 0 : void SetMatrix3fvUniform(KnownUniform::KnownUniformName aKnownUniform, const float *aFloatValues) {
604 0 : ASSERT_THIS_PROGRAM;
605 0 : NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
606 :
607 0 : KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
608 0 : if (ku.UpdateUniform(9, aFloatValues)) {
609 0 : mGL->fUniformMatrix3fv(ku.mLocation, 1, false, ku.mValue.f16v);
610 : }
611 0 : }
612 :
613 0 : void SetMatrixUniform(KnownUniform::KnownUniformName aKnownUniform, const gfx::Matrix4x4& aMatrix) {
614 0 : SetMatrixUniform(aKnownUniform, &aMatrix._11);
615 0 : }
616 : };
617 :
618 : } // namespace layers
619 : } // namespace mozilla
620 :
621 : #endif /* GFX_OGLSHADERPROGRAM_H */
|