/usr/include/thunderbird/LayerManagerOGLProgram.h is in thunderbird-dev 1:24.4.0+build1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GFX_LAYERMANAGEROGLPROGRAM_H
#define GFX_LAYERMANAGEROGLPROGRAM_H
#include <string.h>
#include "prenv.h"
#include "nsString.h"
#include "nsTArray.h"
#include "GLContextTypes.h"
#include "gfx3DMatrix.h"
#include "mozilla/layers/LayersTypes.h"
#include "gfxColor.h"
#include "mozilla/gfx/Matrix.h"
#include "mozilla/RefPtr.h"
namespace mozilla {
namespace gl {
class GLContext;
}
namespace layers {
class Layer;
/**
* This struct represents the shaders that make up a program and the uniform
* and attribute parmeters that those shaders take.
* It is used by ShaderProgramOGL.
* Use the factory method GetProfileFor to create instances.
*/
struct ProgramProfileOGL
{
/**
* Factory method; creates an instance of this class for the given
* ShaderProgramType
*/
static ProgramProfileOGL GetProfileFor(gl::ShaderProgramType aType,
MaskType aMask);
/**
* returns true if such a shader program exists
*/
static bool ProgramExists(gl::ShaderProgramType aType, MaskType aMask)
{
if (aType < 0 ||
aType >= gl::NumProgramTypes)
return false;
if (aMask < MaskNone ||
aMask >= NumMaskTypes)
return false;
if (aMask == Mask2d &&
(aType == gl::Copy2DProgramType ||
aType == gl::Copy2DRectProgramType))
return false;
return aMask != Mask3d ||
aType == gl::RGBARectLayerProgramType ||
aType == gl::RGBALayerProgramType;
}
/**
* These two methods lookup the location of a uniform and attribute,
* respectively. Returns -1 if the named uniform/attribute does not
* have a location for the shaders represented by this profile.
*/
GLint LookupUniformLocation(const char* aName)
{
for (uint32_t i = 0; i < mUniforms.Length(); ++i) {
if (strcmp(mUniforms[i].mName, aName) == 0) {
return mUniforms[i].mLocation;
}
}
return -1;
}
GLint LookupAttributeLocation(const char* aName)
{
for (uint32_t i = 0; i < mAttributes.Length(); ++i) {
if (strcmp(mAttributes[i].mName, aName) == 0) {
return mAttributes[i].mLocation;
}
}
return -1;
}
// represents the name and location of a uniform or attribute
struct Argument
{
Argument(const char* aName) :
mName(aName) {}
const char* mName;
GLint mLocation;
};
// the source code for the program's shaders
const char *mVertexShaderString;
const char *mFragmentShaderString;
nsTArray<Argument> mUniforms;
nsTArray<Argument> mAttributes;
uint32_t mTextureCount;
bool mHasMatrixProj;
bool mHasTextureTransform;
private:
ProgramProfileOGL() :
mTextureCount(0),
mHasMatrixProj(false),
mHasTextureTransform(false) {}
};
#if defined(DEBUG)
#define CHECK_CURRENT_PROGRAM 1
#define ASSERT_THIS_PROGRAM \
do { \
NS_ASSERTION(mGL->GetUserData(&sCurrentProgramKey) == this, \
"SetUniform with wrong program active!"); \
} while (0)
#else
#define ASSERT_THIS_PROGRAM
#endif
/**
* Represents an OGL shader program. The details of a program are represented
* by a ProgramProfileOGL
*/
class ShaderProgramOGL
{
public:
typedef mozilla::gl::GLContext GLContext;
ShaderProgramOGL(GLContext* aGL, const ProgramProfileOGL& aProfile);
~ShaderProgramOGL();
bool HasInitialized() {
NS_ASSERTION(mProgramState != STATE_OK || mProgram > 0, "Inconsistent program state");
return mProgramState == STATE_OK;
}
void Activate();
bool Initialize();
GLint CreateShader(GLenum aShaderType, const char *aShaderSource);
/**
* Creates a program and stores its id.
*/
bool CreateProgram(const char *aVertexShaderString,
const char *aFragmentShaderString);
/**
* Lookup the location of an attribute
*/
GLint AttribLocation(const char* aName) {
return mProfile.LookupAttributeLocation(aName);
}
GLint GetTexCoordMultiplierUniformLocation() {
return mTexCoordMultiplierUniformLocation;
}
/**
* aLayer is the mask layer to use for rendering, or null, if there is no
* mask layer.
* If aLayer is non-null, then the result of rendering aLayer is stored as
* as a texture to be used by the shader. It is stored in the next available
* texture unit, as determined by the texture unit requirements for the
* shader.
* Any other features of the mask layer required by the shader are also
* loaded to graphics memory. In particular the transform used to move from
* the layer's coordinates to the mask's coordinates is loaded; this must be
* a 2D transform.
*/
bool LoadMask(Layer* aLayer);
/**
* The following set of methods set a uniform argument to the shader program.
* Not all uniforms may be set for all programs, and such uses will throw
* an assertion.
*/
void SetLayerTransform(const gfx3DMatrix& aMatrix) {
SetMatrixUniform(mProfile.LookupUniformLocation("uLayerTransform"), aMatrix);
}
void SetLayerTransform(const gfx::Matrix4x4& aMatrix) {
SetMatrixUniform(mProfile.LookupUniformLocation("uLayerTransform"), aMatrix);
}
void SetMaskLayerTransform(const gfx::Matrix4x4& aMatrix) {
SetMatrixUniform(mProfile.LookupUniformLocation("uMaskQuadTransform"), aMatrix);
}
void SetLayerQuadRect(const nsIntRect& aRect) {
gfx3DMatrix m;
m._11 = float(aRect.width);
m._22 = float(aRect.height);
m._41 = float(aRect.x);
m._42 = float(aRect.y);
SetMatrixUniform(mProfile.LookupUniformLocation("uLayerQuadTransform"), m);
}
void SetLayerQuadRect(const gfx::Rect& aRect) {
gfx3DMatrix m;
m._11 = aRect.width;
m._22 = aRect.height;
m._41 = aRect.x;
m._42 = aRect.y;
SetMatrixUniform(mProfile.LookupUniformLocation("uLayerQuadTransform"), m);
}
// activates this program and sets its projection matrix, if the program uses one
void CheckAndSetProjectionMatrix(const gfx3DMatrix& aMatrix)
{
if (mProfile.mHasMatrixProj) {
mIsProjectionMatrixStale = true;
mProjectionMatrix = aMatrix;
}
}
void SetProjectionMatrix(const gfx3DMatrix& aMatrix) {
SetMatrixUniform(mProfile.LookupUniformLocation("uMatrixProj"), aMatrix);
mIsProjectionMatrixStale = false;
}
// sets this program's texture transform, if it uses one
void SetTextureTransform(const gfx3DMatrix& aMatrix) {
if (mProfile.mHasTextureTransform)
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
}
void SetTextureTransform(const gfx::Matrix4x4& aMatrix) {
if (mProfile.mHasTextureTransform)
SetMatrixUniform(mProfile.LookupUniformLocation("uTextureTransform"), aMatrix);
}
void SetRenderOffset(const nsIntPoint& aOffset) {
float vals[4] = { float(aOffset.x), float(aOffset.y), 0.0f, 0.0f };
SetUniform(mProfile.LookupUniformLocation("uRenderTargetOffset"), 4, vals);
}
void SetRenderOffset(float aX, float aY) {
float vals[4] = { aX, aY, 0.0f, 0.0f };
SetUniform(mProfile.LookupUniformLocation("uRenderTargetOffset"), 4, vals);
}
void SetLayerOpacity(float aOpacity) {
SetUniform(mProfile.LookupUniformLocation("uLayerOpacity"), aOpacity);
}
void SetTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uTexture"), aUnit);
}
void SetYTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uYTexture"), aUnit);
}
void SetCbTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uCbTexture"), aUnit);
}
void SetCrTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uCrTexture"), aUnit);
}
void SetYCbCrTextureUnits(GLint aYUnit, GLint aCbUnit, GLint aCrUnit) {
SetUniform(mProfile.LookupUniformLocation("uYTexture"), aYUnit);
SetUniform(mProfile.LookupUniformLocation("uCbTexture"), aCbUnit);
SetUniform(mProfile.LookupUniformLocation("uCrTexture"), aCrUnit);
}
void SetBlackTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uBlackTexture"), aUnit);
}
void SetWhiteTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uWhiteTexture"), aUnit);
}
void SetMaskTextureUnit(GLint aUnit) {
SetUniform(mProfile.LookupUniformLocation("uMaskTexture"), aUnit);
}
void SetRenderColor(const gfxRGBA& aColor) {
SetUniform(mProfile.LookupUniformLocation("uRenderColor"), aColor);
}
void SetRenderColor(const gfx::Color& aColor) {
SetUniform(mProfile.LookupUniformLocation("uRenderColor"), aColor);
}
void SetTexCoordMultiplier(float aWidth, float aHeight) {
float f[] = {aWidth, aHeight};
SetUniform(mTexCoordMultiplierUniformLocation, 2, f);
}
// the names of attributes
static const char* const VertexCoordAttrib;
static const char* const TexCoordAttrib;
protected:
gfx3DMatrix mProjectionMatrix;
// true if the projection matrix needs setting
bool mIsProjectionMatrixStale;
RefPtr<GLContext> mGL;
// the OpenGL id of the program
GLuint mProgram;
ProgramProfileOGL mProfile;
enum {
STATE_NEW,
STATE_OK,
STATE_ERROR
} mProgramState;
GLint mTexCoordMultiplierUniformLocation;
#ifdef CHECK_CURRENT_PROGRAM
static int sCurrentProgramKey;
#endif
void SetUniform(GLint aLocation, float aFloatValue);
void SetUniform(GLint aLocation, const gfxRGBA& aColor);
void SetUniform(GLint aLocation, int aLength, float *aFloatValues);
void SetUniform(GLint aLocation, GLint aIntValue);
void SetMatrixUniform(GLint aLocation, const gfx3DMatrix& aMatrix);
void SetMatrixUniform(GLint aLocation, const float *aFloatValues);
void SetUniform(GLint aLocation, const gfx::Color& aColor);
void SetMatrixUniform(GLint aLocation, const gfx::Matrix4x4& aMatrix) {
SetMatrixUniform(aLocation, &aMatrix._11);
}
};
} /* layers */
} /* mozilla */
#endif /* GFX_LAYERMANAGEROGLPROGRAM_H */
|