Skip to content

Commit

Permalink
Bug 1528394 - Reduce includes of GLContext.h. r=lsalzman
Browse files Browse the repository at this point in the history
Splitting part of OGLShaderProgram.h out into OGLShaderConfig.h makes it
easier to keep GLContext.h included in OGLShaderProgram.h for inlining
purposes.

Differential Revision: https://phabricator.services.mozilla.com/D20017
  • Loading branch information
kdashg committed Feb 19, 2019
1 parent d8f2508 commit a0fa59c
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 292 deletions.
1 change: 1 addition & 0 deletions gfx/layers/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ EXPORTS += [
'LayersTypes.h',
'LayerTreeInvalidation.h',
'LayerUserData.h',
'opengl/OGLShaderConfig.h',
'opengl/OGLShaderProgram.h',
'protobuf/LayerScopePacket.pb.h',
'ReadbackLayer.h',
Expand Down
7 changes: 7 additions & 0 deletions gfx/layers/opengl/CompositorOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "nsRect.h" // for mozilla::gfx::IntRect
#include "nsServiceManagerUtils.h" // for do_GetService
#include "nsString.h" // for nsString, nsAutoCString, etc
#include "OGLShaderProgram.h" // for ShaderProgramOGL, etc
#include "ScopedGLHelpers.h"
#include "GLReadTexImageHelper.h"
#include "GLBlitTextureImageHelper.h"
Expand Down Expand Up @@ -152,6 +153,12 @@ bool AsyncReadbackBufferOGL::MapAndCopyInto(DataSourceSurface* aSurface,
return true;
}

PerUnitTexturePoolOGL::PerUnitTexturePoolOGL(gl::GLContext* aGL)
: mTextureTarget(0), // zero is never a valid texture target
mGL(aGL) {}

PerUnitTexturePoolOGL::~PerUnitTexturePoolOGL() { DestroyTextures(); }

static void BindMaskForProgram(ShaderProgramOGL* aProgram,
TextureSourceOGL* aSourceMask, GLenum aTexUnit,
const gfx::Matrix4x4& aTransform) {
Expand Down
12 changes: 5 additions & 7 deletions gfx/layers/opengl/CompositorOGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#ifndef MOZILLA_GFX_COMPOSITOROGL_H
#define MOZILLA_GFX_COMPOSITOROGL_H

#include <map>
#include <unordered_set>

#include "gfx2DGlue.h"
#include "GLContextTypes.h" // for GLContext, etc
#include "GLDefs.h" // for GLuint, LOCAL_GL_TEXTURE_2D, etc
#include "OGLShaderProgram.h" // for ShaderProgramOGL, etc
#include "OGLShaderConfig.h" // for ShaderConfigOGL
#include "Units.h" // for ScreenPoint
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Attributes.h" // for override, final
Expand Down Expand Up @@ -45,6 +46,7 @@ class CompositingRenderTarget;
class CompositingRenderTargetOGL;
class DataTextureSource;
class GLManagerCompositor;
class ShaderProgramOGL;
class TextureSource;
class TextureSourceOGL;
class BufferTextureHost;
Expand Down Expand Up @@ -81,12 +83,8 @@ class CompositorTexturePoolOGL {
*/
class PerUnitTexturePoolOGL : public CompositorTexturePoolOGL {
public:
explicit PerUnitTexturePoolOGL(gl::GLContext* aGL)
: mTextureTarget(0) // zero is never a valid texture target
,
mGL(aGL) {}

virtual ~PerUnitTexturePoolOGL() { DestroyTextures(); }
explicit PerUnitTexturePoolOGL(gl::GLContext* aGL);
virtual ~PerUnitTexturePoolOGL();

virtual void Clear() override { DestroyTextures(); }

Expand Down
5 changes: 3 additions & 2 deletions gfx/layers/opengl/GLManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "GLManager.h"
#include "CompositorOGL.h" // for CompositorOGL
#include "GLContext.h" // for GLContext
#include "CompositorOGL.h" // for CompositorOGL
#include "GLContext.h" // for GLContext
#include "OGLShaderProgram.h"
#include "mozilla/Attributes.h" // for override
#include "mozilla/RefPtr.h" // for RefPtr
#include "mozilla/layers/Compositor.h" // for Compositor
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/opengl/GLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define MOZILLA_GFX_GLMANAGER_H

#include "mozilla/gfx/Types.h" // for SurfaceFormat
#include "OGLShaderProgram.h"

namespace mozilla {
namespace gl {
Expand All @@ -18,6 +17,7 @@ class GLContext;
namespace layers {

class LayerManagerComposite;
class ShaderProgramOGL;

/**
* Minimal interface to allow widgets to draw using OpenGL. Abstracts
Expand Down
266 changes: 266 additions & 0 deletions gfx/layers/opengl/OGLShaderConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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_OGLSHADERCONFIG_H
#define GFX_OGLSHADERCONFIG_H

#include "gfxTypes.h"
#include "ImageTypes.h"
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/Pair.h" // for Pair
#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
#include "mozilla/layers/CompositorTypes.h"

namespace mozilla {
namespace layers {

enum ShaderFeatures {
ENABLE_RENDER_COLOR = 0x01,
ENABLE_TEXTURE_RECT = 0x02,
ENABLE_TEXTURE_EXTERNAL = 0x04,
ENABLE_TEXTURE_YCBCR = 0x08,
ENABLE_TEXTURE_NV12 = 0x10,
ENABLE_TEXTURE_COMPONENT_ALPHA = 0x20,
ENABLE_TEXTURE_NO_ALPHA = 0x40,
ENABLE_TEXTURE_RB_SWAP = 0x80,
ENABLE_OPACITY = 0x100,
ENABLE_BLUR = 0x200,
ENABLE_COLOR_MATRIX = 0x400,
ENABLE_MASK = 0x800,
ENABLE_NO_PREMUL_ALPHA = 0x1000,
ENABLE_DEAA = 0x2000,
ENABLE_DYNAMIC_GEOMETRY = 0x4000,
ENABLE_MASK_TEXTURE_RECT = 0x8000,
};

class KnownUniform {
public:
// this needs to be kept in sync with strings in 'AddUniforms'
enum KnownUniformName {
NotAKnownUniform = -1,

LayerTransform = 0,
LayerTransformInverse,
MaskTransform,
BackdropTransform,
LayerRects,
MatrixProj,
TextureTransform,
TextureRects,
RenderTargetOffset,
LayerOpacity,
Texture,
YTexture,
CbTexture,
CrTexture,
BlackTexture,
WhiteTexture,
MaskTexture,
BackdropTexture,
RenderColor,
TexCoordMultiplier,
CbCrTexCoordMultiplier,
MaskCoordMultiplier,
TexturePass2,
ColorMatrix,
ColorMatrixVector,
BlurRadius,
BlurOffset,
BlurAlpha,
BlurGaussianKernel,
SSEdges,
ViewportSize,
VisibleCenter,
YuvColorMatrix,

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 9:
case 16:
if (memcmp(mValue.f16v, fp, sizeof(float) * cnt) != 0) {
memcpy(mValue.f16v, fp, sizeof(float) * cnt);
return true;
}
return false;
}

MOZ_ASSERT_UNREACHABLE("cnt must be 1 2 3 4 9 or 16");
return false;
}

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;
}

bool UpdateArrayUniform(int cnt, const gfx::Point3D* points) {
if (mLocation == -1) return false;
if (cnt > 4) {
return false;
}

float fp[12];
float* d = fp;
for (int i = 0; i < cnt; i++) {
// Note: Do not want to make assumptions about .x, .y, .z member packing.
// If gfx::Point3D is updated to make this guarantee, SIMD optimizations
// may be possible
*d++ = points[i].x;
*d++ = points[i].y;
*d++ = points[i].z;
}

if (memcmp(mValue.f16v, fp, sizeof(float) * cnt * 3) != 0) {
memcpy(mValue.f16v, fp, sizeof(float) * cnt * 3);
return true;
}
return false;
}

KnownUniformName mName;
const char* mNameString;
int32_t mLocation;

union {
int i1;
float f1;
float f16v[16];
} mValue;
};

class ShaderConfigOGL {
public:
ShaderConfigOGL()
: mFeatures(0),
mMultiplier(1),
mCompositionOp(gfx::CompositionOp::OP_OVER) {}

void SetRenderColor(bool aEnabled);
void SetTextureTarget(GLenum aTarget);
void SetMaskTextureTarget(GLenum aTarget);
void SetRBSwap(bool aEnabled);
void SetNoAlpha(bool aEnabled);
void SetOpacity(bool aEnabled);
void SetYCbCr(bool aEnabled);
void SetNV12(bool aEnabled);
void SetComponentAlpha(bool aEnabled);
void SetColorMatrix(bool aEnabled);
void SetBlur(bool aEnabled);
void SetMask(bool aEnabled);
void SetDEAA(bool aEnabled);
void SetCompositionOp(gfx::CompositionOp aOp);
void SetNoPremultipliedAlpha();
void SetDynamicGeometry(bool aEnabled);
void SetColorMultiplier(uint32_t aMultiplier);

bool operator<(const ShaderConfigOGL& other) const {
return mFeatures < other.mFeatures ||
(mFeatures == other.mFeatures &&
(int)mCompositionOp < (int)other.mCompositionOp) ||
(mFeatures == other.mFeatures &&
(int)mCompositionOp == (int)other.mCompositionOp &&
mMultiplier < other.mMultiplier);
}

public:
void SetFeature(int aBitmask, bool aState) {
if (aState)
mFeatures |= aBitmask;
else
mFeatures &= (~aBitmask);
}

int mFeatures;
uint32_t mMultiplier;
gfx::CompositionOp mCompositionOp;
};

static inline ShaderConfigOGL ShaderConfigFromTargetAndFormat(
GLenum aTarget, gfx::SurfaceFormat aFormat) {
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_UINT16);
return config;
}

} // namespace layers
} // namespace mozilla

#endif // GFX_OGLSHADERCONFIG_H
1 change: 1 addition & 0 deletions gfx/layers/opengl/OGLShaderProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "OGLShaderProgram.h"

#include <stdint.h> // for uint32_t
#include <sstream> // for ostringstream
#include "gfxEnv.h"
Expand Down
Loading

0 comments on commit a0fa59c

Please sign in to comment.