2010-05-24 23:35:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2013-11-26 14:15:17 -08:00
|
|
|
#ifndef GFX_OGLSHADERPROGRAM_H
|
|
|
|
#define GFX_OGLSHADERPROGRAM_H
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2014-01-29 14:53:38 -08:00
|
|
|
#include "GLContext.h" // for fast inlines of glUniform*
|
2013-09-24 13:45:14 -07:00
|
|
|
#include "gfxTypes.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
|
|
#include "mozilla/RefPtr.h" // for RefPtr
|
|
|
|
#include "mozilla/gfx/Matrix.h" // for Matrix4x4
|
|
|
|
#include "mozilla/gfx/Rect.h" // for Rect
|
|
|
|
#include "mozilla/gfx/Types.h"
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsPoint.h" // for nsIntPoint
|
|
|
|
#include "nsTArray.h" // for nsTArray
|
2013-07-04 14:48:33 -07:00
|
|
|
#include "mozilla/layers/CompositorTypes.h"
|
2013-08-11 16:17:23 -07:00
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
#include <string>
|
|
|
|
|
2013-08-11 16:17:23 -07:00
|
|
|
struct gfxRGBA;
|
2013-09-06 19:15:49 -07:00
|
|
|
struct nsIntRect;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-07-18 09:31:40 -07:00
|
|
|
class Layer;
|
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
enum ShaderFeatures {
|
|
|
|
ENABLE_RENDER_COLOR=0x01,
|
|
|
|
ENABLE_TEXTURE_RECT=0x02,
|
|
|
|
ENABLE_TEXTURE_EXTERNAL=0x04,
|
|
|
|
ENABLE_TEXTURE_YCBCR=0x08,
|
|
|
|
ENABLE_TEXTURE_COMPONENT_ALPHA=0x10,
|
|
|
|
ENABLE_TEXTURE_NO_ALPHA=0x20,
|
|
|
|
ENABLE_TEXTURE_RB_SWAP=0x40,
|
|
|
|
ENABLE_OPACITY=0x80,
|
|
|
|
ENABLE_BLUR=0x100,
|
|
|
|
ENABLE_COLOR_MATRIX=0x200,
|
|
|
|
ENABLE_MASK_2D=0x400,
|
2014-05-09 03:06:18 -07:00
|
|
|
ENABLE_MASK_3D=0x800,
|
|
|
|
ENABLE_PREMULTIPLY=0x1000
|
2013-07-04 10:25:50 -07:00
|
|
|
};
|
|
|
|
|
2014-01-29 14:53:37 -08:00
|
|
|
class KnownUniform {
|
|
|
|
public:
|
2014-08-01 10:26:46 -07:00
|
|
|
// this needs to be kept in sync with strings in 'AddUniforms'
|
2014-01-29 14:53:37 -08:00
|
|
|
enum KnownUniformName {
|
|
|
|
NotAKnownUniform = -1,
|
|
|
|
|
|
|
|
LayerTransform = 0,
|
2014-05-22 03:29:54 -07:00
|
|
|
MaskTransform,
|
2014-05-28 07:15:31 -07:00
|
|
|
LayerRects,
|
2014-01-29 14:53:37 -08:00
|
|
|
MatrixProj,
|
|
|
|
TextureTransform,
|
2014-05-28 07:15:31 -07:00
|
|
|
TextureRects,
|
2014-01-29 14:53:37 -08:00
|
|
|
RenderTargetOffset,
|
|
|
|
LayerOpacity,
|
|
|
|
Texture,
|
|
|
|
YTexture,
|
|
|
|
CbTexture,
|
|
|
|
CrTexture,
|
|
|
|
BlackTexture,
|
|
|
|
WhiteTexture,
|
|
|
|
MaskTexture,
|
|
|
|
RenderColor,
|
|
|
|
TexCoordMultiplier,
|
2013-11-07 22:22:05 -08:00
|
|
|
TexturePass2,
|
2014-08-07 14:44:08 -07:00
|
|
|
ColorMatrix,
|
|
|
|
ColorMatrixVector,
|
2014-09-02 05:09:26 -07:00
|
|
|
BlurRadius,
|
|
|
|
BlurOffset,
|
|
|
|
BlurAlpha,
|
|
|
|
BlurGaussianKernel,
|
2014-01-29 14:53:37 -08:00
|
|
|
|
|
|
|
KnownUniformCount
|
|
|
|
};
|
|
|
|
|
|
|
|
KnownUniform()
|
|
|
|
{
|
|
|
|
mName = NotAKnownUniform;
|
|
|
|
mNameString = nullptr;
|
|
|
|
mLocation = -1;
|
|
|
|
memset(&mValue, 0, sizeof(mValue));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateUniform(int32_t i1) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
if (mValue.i1 != i1) {
|
|
|
|
mValue.i1 = i1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateUniform(float f1) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
if (mValue.f1 != f1) {
|
|
|
|
mValue.f1 = f1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateUniform(float f1, float f2) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
if (mValue.f16v[0] != f1 ||
|
|
|
|
mValue.f16v[1] != f2)
|
|
|
|
{
|
|
|
|
mValue.f16v[0] = f1;
|
|
|
|
mValue.f16v[1] = f2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateUniform(float f1, float f2, float f3, float f4) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
if (mValue.f16v[0] != f1 ||
|
|
|
|
mValue.f16v[1] != f2 ||
|
|
|
|
mValue.f16v[2] != f3 ||
|
|
|
|
mValue.f16v[3] != f4)
|
|
|
|
{
|
|
|
|
mValue.f16v[0] = f1;
|
|
|
|
mValue.f16v[1] = f2;
|
|
|
|
mValue.f16v[2] = f3;
|
|
|
|
mValue.f16v[3] = f4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool UpdateUniform(int cnt, const float *fp) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
switch (cnt) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 16:
|
|
|
|
if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
|
|
|
|
memcpy(mValue.f16v, fp, sizeof(float) * cnt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("cnt must be 1 2 3 4 or 16");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-02 05:09:26 -07:00
|
|
|
bool UpdateArrayUniform(int cnt, const float *fp) {
|
|
|
|
if (mLocation == -1) return false;
|
|
|
|
if (cnt > 16) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
|
|
|
|
memcpy(mValue.f16v, fp, sizeof(float) * cnt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:53:37 -08:00
|
|
|
KnownUniformName mName;
|
|
|
|
const char *mNameString;
|
|
|
|
int32_t mLocation;
|
|
|
|
|
|
|
|
union {
|
|
|
|
int i1;
|
|
|
|
float f1;
|
|
|
|
float f16v[16];
|
|
|
|
} mValue;
|
|
|
|
};
|
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
class ShaderConfigOGL
|
2013-07-04 10:25:50 -07:00
|
|
|
{
|
2013-11-07 22:22:05 -08:00
|
|
|
public:
|
|
|
|
ShaderConfigOGL() :
|
|
|
|
mFeatures(0) {}
|
2013-07-04 10:25:50 -07:00
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
void SetRenderColor(bool aEnabled);
|
|
|
|
void SetTextureTarget(GLenum aTarget);
|
|
|
|
void SetRBSwap(bool aEnabled);
|
|
|
|
void SetNoAlpha(bool aEnabled);
|
|
|
|
void SetOpacity(bool aEnabled);
|
|
|
|
void SetYCbCr(bool aEnabled);
|
|
|
|
void SetComponentAlpha(bool aEnabled);
|
|
|
|
void SetColorMatrix(bool aEnabled);
|
|
|
|
void SetBlur(bool aEnabled);
|
|
|
|
void SetMask2D(bool aEnabled);
|
|
|
|
void SetMask3D(bool aEnabled);
|
2014-05-09 03:06:18 -07:00
|
|
|
void SetPremultiply(bool aEnabled);
|
2013-11-07 22:22:05 -08:00
|
|
|
|
|
|
|
bool operator< (const ShaderConfigOGL& other) const {
|
|
|
|
return mFeatures < other.mFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
void SetFeature(int aBitmask, bool aState) {
|
|
|
|
if (aState)
|
|
|
|
mFeatures |= aBitmask;
|
|
|
|
else
|
|
|
|
mFeatures &= (~aBitmask);
|
2013-07-04 10:25:50 -07:00
|
|
|
}
|
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
int mFeatures;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline ShaderConfigOGL
|
|
|
|
ShaderConfigFromTargetAndFormat(GLenum aTarget,
|
|
|
|
gfx::SurfaceFormat aFormat)
|
2013-07-04 10:25:50 -07:00
|
|
|
{
|
2013-11-07 22:22:05 -08:00
|
|
|
ShaderConfigOGL config;
|
|
|
|
config.SetTextureTarget(aTarget);
|
|
|
|
config.SetRBSwap(aFormat == gfx::SurfaceFormat::B8G8R8A8 ||
|
|
|
|
aFormat == gfx::SurfaceFormat::B8G8R8X8);
|
|
|
|
config.SetNoAlpha(aFormat == gfx::SurfaceFormat::B8G8R8X8 ||
|
|
|
|
aFormat == gfx::SurfaceFormat::R8G8B8X8 ||
|
|
|
|
aFormat == gfx::SurfaceFormat::R5G6B5);
|
|
|
|
return config;
|
2013-07-04 10:25:50 -07:00
|
|
|
}
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
/**
|
|
|
|
* 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
|
2013-11-07 22:22:05 -08:00
|
|
|
* ShaderConfigOGL
|
2012-03-18 13:07:25 -07:00
|
|
|
*/
|
2013-11-07 22:22:05 -08:00
|
|
|
static ProgramProfileOGL GetProfileFor(ShaderConfigOGL aConfig);
|
2012-03-18 13:07:25 -07:00
|
|
|
|
|
|
|
// the source code for the program's shaders
|
2013-11-07 22:22:05 -08:00
|
|
|
std::string mVertexShaderString;
|
|
|
|
std::string mFragmentShaderString;
|
2012-03-18 13:07:25 -07:00
|
|
|
|
2014-01-29 14:53:37 -08:00
|
|
|
KnownUniform mUniforms[KnownUniform::KnownUniformCount];
|
2013-11-07 22:22:05 -08:00
|
|
|
nsTArray<const char *> mDefines;
|
2014-05-29 07:19:37 -07:00
|
|
|
size_t mTextureCount;
|
2013-11-07 22:22:05 -08:00
|
|
|
|
2013-11-01 08:51:32 -07:00
|
|
|
ProgramProfileOGL() :
|
2013-11-07 22:22:05 -08:00
|
|
|
mTextureCount(0)
|
|
|
|
{}
|
2012-03-18 13:07:25 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-23 09:54:47 -07:00
|
|
|
#if defined(DEBUG)
|
2011-01-07 12:32:42 -08:00
|
|
|
#define CHECK_CURRENT_PROGRAM 1
|
2010-05-24 23:35:35 -07:00
|
|
|
#define ASSERT_THIS_PROGRAM \
|
|
|
|
do { \
|
2013-12-06 07:23:16 -08:00
|
|
|
GLuint currentProgram; \
|
|
|
|
mGL->GetUIntegerv(LOCAL_GL_CURRENT_PROGRAM, ¤tProgram); \
|
|
|
|
NS_ASSERTION(currentProgram == mProgram, \
|
2010-05-24 23:35:35 -07:00
|
|
|
"SetUniform with wrong program active!"); \
|
|
|
|
} while (0)
|
2011-01-07 12:32:42 -08:00
|
|
|
#else
|
2013-12-06 07:23:16 -08:00
|
|
|
#define ASSERT_THIS_PROGRAM \
|
|
|
|
do { } while (0)
|
2011-01-07 12:32:42 -08:00
|
|
|
#endif
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
/**
|
|
|
|
* Represents an OGL shader program. The details of a program are represented
|
|
|
|
* by a ProgramProfileOGL
|
|
|
|
*/
|
|
|
|
class ShaderProgramOGL
|
|
|
|
{
|
2010-05-24 23:35:35 -07:00
|
|
|
public:
|
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
ShaderProgramOGL(GLContext* aGL, const ProgramProfileOGL& aProfile);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
~ShaderProgramOGL();
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-05-01 19:54:40 -07:00
|
|
|
bool HasInitialized() {
|
|
|
|
NS_ASSERTION(mProgramState != STATE_OK || mProgram > 0, "Inconsistent program state");
|
|
|
|
return mProgramState == STATE_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
void Activate();
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
bool Initialize();
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
GLint CreateShader(GLenum aShaderType, const char *aShaderSource);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
/**
|
|
|
|
* Creates a program and stores its id.
|
|
|
|
*/
|
2010-05-24 23:35:35 -07:00
|
|
|
bool CreateProgram(const char *aVertexShaderString,
|
2012-03-18 13:07:25 -07:00
|
|
|
const char *aFragmentShaderString);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
void SetLayerTransform(const gfx::Matrix4x4& aMatrix) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetMatrixUniform(KnownUniform::LayerTransform, aMatrix);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetMaskLayerTransform(const gfx::Matrix4x4& aMatrix) {
|
2014-05-22 03:29:54 -07:00
|
|
|
SetMatrixUniform(KnownUniform::MaskTransform, aMatrix);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 07:15:31 -07:00
|
|
|
void SetLayerRects(const gfx::Rect* aRects) {
|
|
|
|
float vals[16] = { aRects[0].x, aRects[0].y, aRects[0].width, aRects[0].height,
|
|
|
|
aRects[1].x, aRects[1].y, aRects[1].width, aRects[1].height,
|
|
|
|
aRects[2].x, aRects[2].y, aRects[2].width, aRects[2].height,
|
|
|
|
aRects[3].x, aRects[3].y, aRects[3].width, aRects[3].height };
|
|
|
|
SetUniform(KnownUniform::LayerRects, 16, vals);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
2014-01-27 12:25:20 -08:00
|
|
|
void SetProjectionMatrix(const gfx::Matrix4x4& aMatrix) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetMatrixUniform(KnownUniform::MatrixProj, aMatrix);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
// sets this program's texture transform, if it uses one
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
void SetTextureTransform(const gfx::Matrix4x4& aMatrix) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetMatrixUniform(KnownUniform::TextureTransform, aMatrix);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 07:15:31 -07:00
|
|
|
void SetTextureRects(const gfx::Rect* aRects) {
|
|
|
|
float vals[16] = { aRects[0].x, aRects[0].y, aRects[0].width, aRects[0].height,
|
|
|
|
aRects[1].x, aRects[1].y, aRects[1].width, aRects[1].height,
|
|
|
|
aRects[2].x, aRects[2].y, aRects[2].width, aRects[2].height,
|
|
|
|
aRects[3].x, aRects[3].y, aRects[3].width, aRects[3].height };
|
|
|
|
SetUniform(KnownUniform::TextureRects, 16, vals);
|
2014-05-22 03:29:54 -07:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
void SetRenderOffset(const nsIntPoint& aOffset) {
|
|
|
|
float vals[4] = { float(aOffset.x), float(aOffset.y), 0.0f, 0.0f };
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::RenderTargetOffset, 4, vals);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetRenderOffset(float aX, float aY) {
|
|
|
|
float vals[4] = { aX, aY, 0.0f, 0.0f };
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::RenderTargetOffset, 4, vals);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetLayerOpacity(float aOpacity) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::LayerOpacity, aOpacity);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::Texture, aUnit);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
void SetYTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::YTexture, aUnit);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCbTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::CbTexture, aUnit);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCrTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::CrTexture, aUnit);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetYCbCrTextureUnits(GLint aYUnit, GLint aCbUnit, GLint aCrUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::YTexture, aYUnit);
|
|
|
|
SetUniform(KnownUniform::CbTexture, aCbUnit);
|
|
|
|
SetUniform(KnownUniform::CrTexture, aCrUnit);
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetBlackTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::BlackTexture, aUnit);
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetWhiteTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::WhiteTexture, aUnit);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
void SetMaskTextureUnit(GLint aUnit) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::MaskTexture, aUnit);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
void SetRenderColor(const gfxRGBA& aColor) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::RenderColor, aColor);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
void SetRenderColor(const gfx::Color& aColor) {
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::RenderColor, aColor);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 14:44:08 -07:00
|
|
|
void SetColorMatrix(const gfx::Matrix5x4& aColorMatrix)
|
|
|
|
{
|
|
|
|
SetMatrixUniform(KnownUniform::ColorMatrix, &aColorMatrix._11);
|
|
|
|
SetUniform(KnownUniform::ColorMatrixVector, 4, &aColorMatrix._51);
|
|
|
|
}
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
void SetTexCoordMultiplier(float aWidth, float aHeight) {
|
|
|
|
float f[] = {aWidth, aHeight};
|
2014-01-29 14:53:37 -08:00
|
|
|
SetUniform(KnownUniform::TexCoordMultiplier, 2, f);
|
2012-03-18 13:07:25 -07:00
|
|
|
}
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
// Set whether we want the component alpha shader to return the color
|
|
|
|
// vector (pass 1, false) or the alpha vector (pass2, true). With support
|
|
|
|
// for multiple render targets we wouldn't need two passes here.
|
|
|
|
void SetTexturePass2(bool aFlag) {
|
|
|
|
SetUniform(KnownUniform::TexturePass2, aFlag ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2014-09-02 05:09:26 -07:00
|
|
|
void SetBlurRadius(float aRX, float aRY);
|
|
|
|
|
|
|
|
void SetBlurAlpha(float aAlpha) {
|
|
|
|
SetUniform(KnownUniform::BlurAlpha, aAlpha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBlurOffset(float aOffsetX, float aOffsetY) {
|
|
|
|
float f[] = {aOffsetX, aOffsetY};
|
|
|
|
SetUniform(KnownUniform::BlurOffset, 2, f);
|
|
|
|
}
|
|
|
|
|
2014-05-29 07:19:37 -07:00
|
|
|
size_t GetTextureCount() const {
|
|
|
|
return mProfile.mTextureCount;
|
|
|
|
}
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
protected:
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
RefPtr<GLContext> mGL;
|
|
|
|
// the OpenGL id of the program
|
2012-03-18 13:07:25 -07:00
|
|
|
GLuint mProgram;
|
|
|
|
ProgramProfileOGL mProfile;
|
2012-05-01 19:54:40 -07:00
|
|
|
enum {
|
|
|
|
STATE_NEW,
|
|
|
|
STATE_OK,
|
|
|
|
STATE_ERROR
|
|
|
|
} mProgramState;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2013-11-07 22:22:05 -08:00
|
|
|
#ifdef CHECK_CURRENT_PROGRAM
|
|
|
|
static int sCurrentProgramKey;
|
|
|
|
#endif
|
|
|
|
|
2014-01-29 14:53:38 -08:00
|
|
|
void SetUniform(KnownUniform::KnownUniformName aKnownUniform, float aFloatValue)
|
|
|
|
{
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(aFloatValue)) {
|
|
|
|
mGL->fUniform1f(ku.mLocation, aFloatValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUniform(KnownUniform::KnownUniformName aKnownUniform, const gfxRGBA& aColor)
|
|
|
|
{
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(aColor.r, aColor.g, aColor.b, aColor.a)) {
|
|
|
|
mGL->fUniform4fv(ku.mLocation, 1, ku.mValue.f16v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUniform(KnownUniform::KnownUniformName aKnownUniform, const gfx::Color& aColor) {
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(aColor.r, aColor.g, aColor.b, aColor.a)) {
|
|
|
|
mGL->fUniform4fv(ku.mLocation, 1, ku.mValue.f16v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 14:44:08 -07:00
|
|
|
void SetUniform(KnownUniform::KnownUniformName aKnownUniform, int aLength, const float *aFloatValues)
|
2014-01-29 14:53:38 -08:00
|
|
|
{
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(aLength, aFloatValues)) {
|
|
|
|
switch (aLength) {
|
|
|
|
case 1: mGL->fUniform1fv(ku.mLocation, 1, ku.mValue.f16v); break;
|
|
|
|
case 2: mGL->fUniform2fv(ku.mLocation, 1, ku.mValue.f16v); break;
|
|
|
|
case 3: mGL->fUniform3fv(ku.mLocation, 1, ku.mValue.f16v); break;
|
|
|
|
case 4: mGL->fUniform4fv(ku.mLocation, 1, ku.mValue.f16v); break;
|
2014-05-28 07:15:31 -07:00
|
|
|
case 16: mGL->fUniform4fv(ku.mLocation, 4, ku.mValue.f16v); break;
|
2014-01-29 14:53:38 -08:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Bogus aLength param");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-02 05:09:26 -07:00
|
|
|
void SetArrayUniform(KnownUniform::KnownUniformName aKnownUniform, int aLength, float *aFloatValues)
|
|
|
|
{
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateArrayUniform(aLength, aFloatValues)) {
|
|
|
|
mGL->fUniform1fv(ku.mLocation, aLength, ku.mValue.f16v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:53:38 -08:00
|
|
|
void SetUniform(KnownUniform::KnownUniformName aKnownUniform, GLint aIntValue) {
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(aIntValue)) {
|
|
|
|
mGL->fUniform1i(ku.mLocation, aIntValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMatrixUniform(KnownUniform::KnownUniformName aKnownUniform, const float *aFloatValues) {
|
|
|
|
ASSERT_THIS_PROGRAM;
|
|
|
|
NS_ASSERTION(aKnownUniform >= 0 && aKnownUniform < KnownUniform::KnownUniformCount, "Invalid known uniform");
|
|
|
|
|
|
|
|
KnownUniform& ku(mProfile.mUniforms[aKnownUniform]);
|
|
|
|
if (ku.UpdateUniform(16, aFloatValues)) {
|
|
|
|
mGL->fUniformMatrix4fv(ku.mLocation, 1, false, ku.mValue.f16v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-29 14:53:37 -08:00
|
|
|
void SetMatrixUniform(KnownUniform::KnownUniformName aKnownUniform, const gfx::Matrix4x4& aMatrix) {
|
|
|
|
SetMatrixUniform(aKnownUniform, &aMatrix._11);
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
}
|
2010-05-24 23:35:35 -07:00
|
|
|
};
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
|
2013-11-26 14:15:17 -08:00
|
|
|
#endif /* GFX_OGLSHADERPROGRAM_H */
|