mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 560147: Use the new Unified OpenGL Wrapper for OpenGL layers, and remove wrapper code from layers. r=vlad
This commit is contained in:
parent
bc05313947
commit
c7f958ebfc
@ -63,7 +63,6 @@ EXPORTS = \
|
||||
CPPSRCS = \
|
||||
BasicImages.cpp \
|
||||
BasicLayers.cpp \
|
||||
glWrapper.cpp \
|
||||
LayerManagerOGL.cpp \
|
||||
ThebesLayerOGL.cpp \
|
||||
ContainerLayerOGL.cpp \
|
||||
|
@ -37,13 +37,12 @@
|
||||
|
||||
#include "ContainerLayerOGL.h"
|
||||
|
||||
#include "glWrapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
ContainerLayerOGL::ContainerLayerOGL(LayerManager *aManager)
|
||||
ContainerLayerOGL::ContainerLayerOGL(LayerManagerOGL *aManager)
|
||||
: ContainerLayer(aManager, NULL)
|
||||
, LayerOGL(aManager)
|
||||
{
|
||||
mImplData = static_cast<LayerOGL*>(this);
|
||||
}
|
||||
@ -139,9 +138,9 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
static_cast<LayerManagerOGL*>(mManager)->GetYCbCrLayerProgram();
|
||||
|
||||
if (GetOpacity() != 1.0) {
|
||||
sglWrapper.GenTextures(1, &containerSurface);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
gl()->fGenTextures(1, &containerSurface);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
|
||||
gl()->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
mVisibleRect.width,
|
||||
@ -150,23 +149,23 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
|
||||
/**
|
||||
* Create the framebuffer and bind it to make our content render into our
|
||||
* framebuffer.
|
||||
*/
|
||||
sglWrapper.GenFramebuffersEXT(1, &frameBuffer);
|
||||
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, frameBuffer);
|
||||
sglWrapper.FramebufferTexture2DEXT(LOCAL_GL_FRAMEBUFFER_EXT,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0_EXT,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
containerSurface,
|
||||
0);
|
||||
gl()->fGenFramebuffers(1, &frameBuffer);
|
||||
gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, frameBuffer);
|
||||
gl()->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
containerSurface,
|
||||
0);
|
||||
|
||||
NS_ASSERTION(
|
||||
sglWrapper.CheckFramebufferStatusEXT(LOCAL_GL_FRAMEBUFFER_EXT) ==
|
||||
gl()->fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER) ==
|
||||
LOCAL_GL_FRAMEBUFFER_COMPLETE, "Error setting up framebuffer.");
|
||||
|
||||
/**
|
||||
@ -191,12 +190,12 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
while (layerToRender) {
|
||||
const nsIntRect *clipRect = layerToRender->GetLayer()->GetClipRect();
|
||||
if (clipRect) {
|
||||
sglWrapper.Scissor(clipRect->x - GetVisibleRect().x,
|
||||
clipRect->y - GetVisibleRect().y,
|
||||
clipRect->width,
|
||||
clipRect->height);
|
||||
gl()->fScissor(clipRect->x - GetVisibleRect().x,
|
||||
clipRect->y - GetVisibleRect().y,
|
||||
clipRect->width,
|
||||
clipRect->height);
|
||||
} else {
|
||||
sglWrapper.Scissor(0, 0, GetVisibleRect().width, GetVisibleRect().height);
|
||||
gl()->fScissor(0, 0, GetVisibleRect().width, GetVisibleRect().height);
|
||||
}
|
||||
|
||||
layerToRender->RenderLayer(frameBuffer);
|
||||
@ -205,8 +204,8 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
|
||||
if (GetOpacity() != 1.0) {
|
||||
// Unbind the current framebuffer and rebind the previous one.
|
||||
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, aPreviousFrameBuffer);
|
||||
sglWrapper.DeleteFramebuffersEXT(1, &frameBuffer);
|
||||
gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer);
|
||||
gl()->fDeleteFramebuffers(1, &frameBuffer);
|
||||
|
||||
// Restore old shader program variables.
|
||||
yCbCrProgram->Activate();
|
||||
@ -233,16 +232,16 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
|
||||
rgbProgram->SetLayerQuadTransform(&quadTransform[0][0]);
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
|
||||
|
||||
rgbProgram->SetLayerOpacity(GetOpacity());
|
||||
rgbProgram->SetLayerTransform(&mTransform._11);
|
||||
rgbProgram->Apply();
|
||||
|
||||
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl()->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
// Clean up resources.
|
||||
sglWrapper.DeleteTextures(1, &containerSurface);
|
||||
gl()->fDeleteTextures(1, &containerSurface);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class ContainerLayerOGL : public ContainerLayer,
|
||||
public LayerOGL
|
||||
{
|
||||
public:
|
||||
ContainerLayerOGL(LayerManager *aManager);
|
||||
ContainerLayerOGL(LayerManagerOGL *aManager);
|
||||
|
||||
const nsIntRect &GetVisibleRect();
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
|
||||
#include "ImageLayerOGL.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "glWrapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
@ -137,21 +136,21 @@ ImageLayerOGL::RenderLayer(int)
|
||||
|
||||
program->SetLayerQuadTransform(&quadTransform[0][0]);
|
||||
|
||||
sglWrapper.ActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[0]);
|
||||
sglWrapper.ActiveTexture(LOCAL_GL_TEXTURE1);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[1]);
|
||||
sglWrapper.ActiveTexture(LOCAL_GL_TEXTURE2);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[2]);
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[0]);
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE1);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[1]);
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE2);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[2]);
|
||||
|
||||
program->SetLayerOpacity(GetOpacity());
|
||||
program->SetLayerTransform(&mTransform._11);
|
||||
program->Apply();
|
||||
|
||||
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl()->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
yuvImage->FreeTextures();
|
||||
sglWrapper.ActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
|
||||
} else if (image->GetFormat() == Image::CAIRO_SURFACE) {
|
||||
CairoImageOGL *cairoImage =
|
||||
@ -172,13 +171,13 @@ ImageLayerOGL::RenderLayer(int)
|
||||
|
||||
program->SetLayerQuadTransform(&quadTransform[0][0]);
|
||||
|
||||
sglWrapper.ActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, cairoImage->mTexture);
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, cairoImage->mTexture);
|
||||
program->SetLayerOpacity(GetOpacity());
|
||||
program->SetLayerTransform(&mTransform._11);
|
||||
program->Apply();
|
||||
|
||||
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl()->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +257,9 @@ void
|
||||
PlanarYCbCrImageOGL::AllocateTextures()
|
||||
{
|
||||
mManager->MakeCurrent();
|
||||
sglWrapper.GenTextures(3, mTextures);
|
||||
|
||||
mozilla::gl::GLContext *gl = mManager->gl();
|
||||
gl->fGenTextures(3, mTextures);
|
||||
|
||||
GLint alignment;
|
||||
|
||||
@ -273,24 +274,24 @@ PlanarYCbCrImageOGL::AllocateTextures()
|
||||
}
|
||||
|
||||
// Set texture alignment for Y plane.
|
||||
sglWrapper.PixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
|
||||
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTextures[0]);
|
||||
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[0]);
|
||||
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mYChannel);
|
||||
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mYChannel);
|
||||
|
||||
if (!((ptrdiff_t)mData.mCbCrStride & 0x7) &&
|
||||
!((ptrdiff_t)mData.mCbChannel & 0x7) &&
|
||||
@ -305,44 +306,44 @@ PlanarYCbCrImageOGL::AllocateTextures()
|
||||
}
|
||||
|
||||
// Set texture alignment for Cb/Cr plane
|
||||
sglWrapper.PixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
|
||||
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTextures[1]);
|
||||
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[1]);
|
||||
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mData.mCbCrSize.width,
|
||||
mData.mCbCrSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mCbChannel);
|
||||
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mData.mCbCrSize.width,
|
||||
mData.mCbCrSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mCbChannel);
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTextures[2]);
|
||||
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[2]);
|
||||
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mData.mCbCrSize.width,
|
||||
mData.mCbCrSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mCrChannel);
|
||||
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
mData.mCbCrSize.width,
|
||||
mData.mCbCrSize.height,
|
||||
0,
|
||||
LOCAL_GL_LUMINANCE,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
mData.mCrChannel);
|
||||
|
||||
// Reset alignment to default
|
||||
sglWrapper.PixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
|
||||
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
|
||||
}
|
||||
|
||||
void
|
||||
@ -350,7 +351,7 @@ PlanarYCbCrImageOGL::FreeTextures()
|
||||
{
|
||||
static_cast<LayerManagerOGL*>(mManager)->MakeCurrent();
|
||||
if (mTextures[0]) {
|
||||
sglWrapper.DeleteTextures(3, mTextures);
|
||||
mManager->gl()->fDeleteTextures(3, mTextures);
|
||||
}
|
||||
}
|
||||
|
||||
@ -358,7 +359,7 @@ CairoImageOGL::~CairoImageOGL()
|
||||
{
|
||||
static_cast<LayerManagerOGL*>(mManager)->MakeCurrent();
|
||||
if (mTexture) {
|
||||
sglWrapper.DeleteTextures(1, &mTexture);
|
||||
mManager->gl()->fDeleteTextures(1, &mTexture);
|
||||
}
|
||||
}
|
||||
|
||||
@ -367,6 +368,7 @@ CairoImageOGL::SetData(const CairoImage::Data &aData)
|
||||
{
|
||||
mSize = aData.mSize;
|
||||
mManager->MakeCurrent();
|
||||
mozilla::gl::GLContext *gl = mManager->gl();
|
||||
|
||||
nsRefPtr<gfxImageSurface> imageSurface =
|
||||
new gfxImageSurface(aData.mSize, gfxASurface::ImageFormatARGB32);
|
||||
@ -376,24 +378,24 @@ CairoImageOGL::SetData(const CairoImage::Data &aData)
|
||||
context->SetSource(aData.mSurface);
|
||||
context->Paint();
|
||||
|
||||
sglWrapper.GenTextures(1, &mTexture);
|
||||
gl->fGenTextures(1, &mTexture);
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
0,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
imageSurface->Data());
|
||||
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
mSize.width,
|
||||
mSize.height,
|
||||
0,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
imageSurface->Data());
|
||||
}
|
||||
|
||||
} /* layers */
|
||||
|
@ -73,6 +73,7 @@ class THEBES_API ImageLayerOGL : public ImageLayer,
|
||||
public:
|
||||
ImageLayerOGL(LayerManagerOGL *aManager)
|
||||
: ImageLayer(aManager, NULL)
|
||||
, LayerOGL(aManager)
|
||||
{
|
||||
mImplData = static_cast<LayerOGL*>(this);
|
||||
}
|
||||
|
@ -44,7 +44,8 @@
|
||||
#include "gfxContext.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
#include "glWrapper.h"
|
||||
#include "GLContext.h"
|
||||
#include "GLContextProvider.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIConsoleService.h"
|
||||
@ -54,6 +55,8 @@ static const GLint VERTEX_ATTRIB_LOCATION = 0;
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
using namespace mozilla::gl;
|
||||
|
||||
/**
|
||||
* LayerManagerOGL
|
||||
*/
|
||||
@ -71,97 +74,85 @@ LayerManagerOGL::LayerManagerOGL(nsIWidget *aWidget)
|
||||
|
||||
LayerManagerOGL::~LayerManagerOGL()
|
||||
{
|
||||
MakeCurrent();
|
||||
mGLContext->MakeCurrent();
|
||||
delete mRGBLayerProgram;
|
||||
delete mYCbCrLayerProgram;
|
||||
#ifdef XP_WIN
|
||||
BOOL deleted = sglWrapper.wDeleteContext(mContext);
|
||||
NS_ASSERTION(deleted, "Error deleting OpenGL context!");
|
||||
::ReleaseDC((HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW), mDC);
|
||||
#endif
|
||||
}
|
||||
|
||||
PRBool
|
||||
LayerManagerOGL::Initialize()
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
mDC = (HDC)mWidget->GetNativeData(NS_NATIVE_GRAPHIC);
|
||||
mGLContext = sGLContextProvider.CreateForWindow(mWidget);
|
||||
|
||||
mContext = sglWrapper.wCreateContext(mDC);
|
||||
|
||||
if (!mContext) {
|
||||
if (!mGLContext) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
#else
|
||||
// Don't know how to initialize on this platform!
|
||||
return PR_FALSE;
|
||||
#endif
|
||||
|
||||
MakeCurrent();
|
||||
|
||||
sglWrapper.BlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE);
|
||||
sglWrapper.Enable(LOCAL_GL_BLEND);
|
||||
sglWrapper.Enable(LOCAL_GL_TEXTURE_2D);
|
||||
sglWrapper.Enable(LOCAL_GL_SCISSOR_TEST);
|
||||
mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE);
|
||||
mGLContext->fEnable(LOCAL_GL_BLEND);
|
||||
mGLContext->fEnable(LOCAL_GL_TEXTURE_2D);
|
||||
mGLContext->fEnable(LOCAL_GL_SCISSOR_TEST);
|
||||
|
||||
mVertexShader = sglWrapper.CreateShader(LOCAL_GL_VERTEX_SHADER);
|
||||
mRGBShader = sglWrapper.CreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
mYUVShader = sglWrapper.CreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
mVertexShader = mGLContext->fCreateShader(LOCAL_GL_VERTEX_SHADER);
|
||||
mRGBShader = mGLContext->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
mYUVShader = mGLContext->fCreateShader(LOCAL_GL_FRAGMENT_SHADER);
|
||||
|
||||
sglWrapper.ShaderSource(mVertexShader, 1, (const GLchar**)&sVertexShader, NULL);
|
||||
sglWrapper.ShaderSource(mRGBShader, 1, (const GLchar**)&sRGBLayerPS, NULL);
|
||||
sglWrapper.ShaderSource(mYUVShader, 1, (const GLchar**)&sYUVLayerPS, NULL);
|
||||
mGLContext->fShaderSource(mVertexShader, 1, (const GLchar**)&sVertexShader, NULL);
|
||||
mGLContext->fShaderSource(mRGBShader, 1, (const GLchar**)&sRGBLayerPS, NULL);
|
||||
mGLContext->fShaderSource(mYUVShader, 1, (const GLchar**)&sYUVLayerPS, NULL);
|
||||
|
||||
sglWrapper.CompileShader(mVertexShader);
|
||||
sglWrapper.CompileShader(mRGBShader);
|
||||
sglWrapper.CompileShader(mYUVShader);
|
||||
mGLContext->fCompileShader(mVertexShader);
|
||||
mGLContext->fCompileShader(mRGBShader);
|
||||
mGLContext->fCompileShader(mYUVShader);
|
||||
|
||||
GLint status;
|
||||
sglWrapper.GetShaderiv(mVertexShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
mGLContext->fGetShaderiv(mVertexShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sglWrapper.GetShaderiv(mRGBShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
mGLContext->fGetShaderiv(mRGBShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sglWrapper.GetShaderiv(mYUVShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
mGLContext->fGetShaderiv(mYUVShader, LOCAL_GL_COMPILE_STATUS, &status);
|
||||
|
||||
if (!status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mRGBLayerProgram = new RGBLayerProgram();
|
||||
if (!mRGBLayerProgram->Initialize(mVertexShader, mRGBShader)) {
|
||||
if (!mRGBLayerProgram->Initialize(mVertexShader, mRGBShader, mGLContext)) {
|
||||
return false;
|
||||
}
|
||||
mYCbCrLayerProgram = new YCbCrLayerProgram();
|
||||
if (!mYCbCrLayerProgram->Initialize(mVertexShader, mYUVShader)) {
|
||||
if (!mYCbCrLayerProgram->Initialize(mVertexShader, mYUVShader, mGLContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mRGBLayerProgram->UpdateLocations();
|
||||
mYCbCrLayerProgram->UpdateLocations();
|
||||
|
||||
sglWrapper.GenBuffers(1, &mVBO);
|
||||
sglWrapper.BindBuffer(LOCAL_GL_ARRAY_BUFFER, mVBO);
|
||||
sglWrapper.EnableClientState(LOCAL_GL_VERTEX_ARRAY);
|
||||
sglWrapper.EnableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
mGLContext->fGenBuffers(1, &mVBO);
|
||||
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mVBO);
|
||||
mGLContext->fEnableClientState(LOCAL_GL_VERTEX_ARRAY);
|
||||
mGLContext->fEnableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
|
||||
GLfloat vertices[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f };
|
||||
sglWrapper.BufferData(LOCAL_GL_ARRAY_BUFFER, sizeof(vertices), vertices, LOCAL_GL_STATIC_DRAW);
|
||||
mGLContext->fBufferData(LOCAL_GL_ARRAY_BUFFER, sizeof(vertices), vertices, LOCAL_GL_STATIC_DRAW);
|
||||
|
||||
mRGBLayerProgram->Activate();
|
||||
sglWrapper.VertexAttribPointer(VERTEX_ATTRIB_LOCATION,
|
||||
mGLContext->fVertexAttribPointer(VERTEX_ATTRIB_LOCATION,
|
||||
2,
|
||||
LOCAL_GL_FLOAT,
|
||||
LOCAL_GL_FALSE,
|
||||
0,
|
||||
0);
|
||||
mYCbCrLayerProgram->Activate();
|
||||
sglWrapper.VertexAttribPointer(VERTEX_ATTRIB_LOCATION,
|
||||
mGLContext->fVertexAttribPointer(VERTEX_ATTRIB_LOCATION,
|
||||
2,
|
||||
LOCAL_GL_FLOAT,
|
||||
LOCAL_GL_FALSE,
|
||||
@ -182,13 +173,13 @@ LayerManagerOGL::Initialize()
|
||||
msg +=
|
||||
NS_LITERAL_STRING("OpenGL LayerManager Initialized Succesfully.\nVersion: ");
|
||||
msg += NS_ConvertUTF8toUTF16(
|
||||
nsDependentCString((const char*)sglWrapper.GetString(LOCAL_GL_VERSION)));
|
||||
nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_VERSION)));
|
||||
msg += NS_LITERAL_STRING("\nVendor: ");
|
||||
msg += NS_ConvertUTF8toUTF16(
|
||||
nsDependentCString((const char*)sglWrapper.GetString(LOCAL_GL_VENDOR)));
|
||||
nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_VENDOR)));
|
||||
msg += NS_LITERAL_STRING("\nRenderer: ");
|
||||
msg += NS_ConvertUTF8toUTF16(
|
||||
nsDependentCString((const char*)sglWrapper.GetString(LOCAL_GL_RENDERER)));
|
||||
nsDependentCString((const char*)mGLContext->fGetString(LOCAL_GL_RENDERER)));
|
||||
console->LogStringMessage(msg.get());
|
||||
}
|
||||
|
||||
@ -262,19 +253,16 @@ void
|
||||
LayerManagerOGL::SetClippingEnabled(PRBool aEnabled)
|
||||
{
|
||||
if (aEnabled) {
|
||||
sglWrapper.Enable(LOCAL_GL_SCISSOR_TEST);
|
||||
mGLContext->fEnable(LOCAL_GL_SCISSOR_TEST);
|
||||
} else {
|
||||
sglWrapper.Disable(LOCAL_GL_SCISSOR_TEST);
|
||||
mGLContext->fDisable(LOCAL_GL_SCISSOR_TEST);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
LayerManagerOGL::MakeCurrent()
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
BOOL succeeded = sglWrapper.wMakeCurrent(mDC, mContext);
|
||||
NS_ASSERTION(succeeded, "Failed to make GL context current!");
|
||||
#endif
|
||||
mGLContext->MakeCurrent();
|
||||
}
|
||||
|
||||
void
|
||||
@ -288,10 +276,10 @@ LayerManagerOGL::Render()
|
||||
MakeCurrent();
|
||||
SetupBackBuffer();
|
||||
|
||||
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, mFrameBuffer);
|
||||
sglWrapper.BlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE);
|
||||
sglWrapper.ClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
sglWrapper.Clear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
|
||||
mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFrameBuffer);
|
||||
mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA, LOCAL_GL_ONE, LOCAL_GL_ONE);
|
||||
mGLContext->fClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
mGLContext->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
SetupPipeline();
|
||||
SetClippingEnabled(PR_FALSE);
|
||||
@ -299,9 +287,9 @@ LayerManagerOGL::Render()
|
||||
if (mRootLayer) {
|
||||
const nsIntRect *clipRect = mRootLayer->GetLayer()->GetClipRect();
|
||||
if (clipRect) {
|
||||
sglWrapper.Scissor(clipRect->x, clipRect->y, clipRect->width, clipRect->height);
|
||||
mGLContext->fScissor(clipRect->x, clipRect->y, clipRect->width, clipRect->height);
|
||||
} else {
|
||||
sglWrapper.Scissor(0, 0, width, height);
|
||||
mGLContext->fScissor(0, 0, width, height);
|
||||
}
|
||||
|
||||
mRootLayer->RenderLayer(mFrameBuffer);
|
||||
@ -315,18 +303,18 @@ LayerManagerOGL::Render()
|
||||
* shaders. We're fine with just calculating the viewport coordinates
|
||||
* in software. And nothing special is required for the texture sampling.
|
||||
*/
|
||||
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, 0);
|
||||
sglWrapper.UseProgram(0);
|
||||
sglWrapper.DisableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
sglWrapper.BindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
|
||||
sglWrapper.EnableClientState(LOCAL_GL_VERTEX_ARRAY);
|
||||
sglWrapper.EnableClientState(LOCAL_GL_TEXTURE_COORD_ARRAY);
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mBackBuffer);
|
||||
mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, 0);
|
||||
mGLContext->fUseProgram(0);
|
||||
mGLContext->fDisableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
|
||||
mGLContext->fEnableClientState(LOCAL_GL_VERTEX_ARRAY);
|
||||
mGLContext->fEnableClientState(LOCAL_GL_TEXTURE_COORD_ARRAY);
|
||||
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mBackBuffer);
|
||||
|
||||
const nsIntRect *r;
|
||||
for (nsIntRegionRectIterator iter(mClippingRegion);
|
||||
(r = iter.Next()) != nsnull;) {
|
||||
sglWrapper.BlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ZERO, LOCAL_GL_ONE, LOCAL_GL_ZERO);
|
||||
mGLContext->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ZERO, LOCAL_GL_ONE, LOCAL_GL_ZERO);
|
||||
float left = (GLfloat)r->x / width;
|
||||
float right = (GLfloat)r->XMost() / width;
|
||||
float top = (GLfloat)r->y / height;
|
||||
@ -342,16 +330,16 @@ LayerManagerOGL::Render()
|
||||
-(bottom * 2.0f - 1.0f) };
|
||||
float coords[] = { left, top, right, top, left, bottom, right, bottom };
|
||||
|
||||
sglWrapper.VertexPointer(2, LOCAL_GL_FLOAT, 0, vertices);
|
||||
sglWrapper.TexCoordPointer(2, LOCAL_GL_FLOAT, 0, coords);
|
||||
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
mGLContext->fVertexPointer(2, LOCAL_GL_FLOAT, 0, vertices);
|
||||
mGLContext->fTexCoordPointer(2, LOCAL_GL_FLOAT, 0, coords);
|
||||
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
sglWrapper.BindBuffer(LOCAL_GL_ARRAY_BUFFER, mVBO);
|
||||
sglWrapper.EnableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
sglWrapper.DisableClientState(LOCAL_GL_TEXTURE_COORD_ARRAY);
|
||||
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mVBO);
|
||||
mGLContext->fEnableVertexAttribArray(VERTEX_ATTRIB_LOCATION);
|
||||
mGLContext->fDisableClientState(LOCAL_GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
|
||||
sglWrapper.Finish();
|
||||
mGLContext->fFinish();
|
||||
}
|
||||
|
||||
void
|
||||
@ -360,7 +348,7 @@ LayerManagerOGL::SetupPipeline()
|
||||
nsIntRect rect;
|
||||
mWidget->GetBounds(rect);
|
||||
|
||||
sglWrapper.Viewport(0, 0, rect.width, rect.height);
|
||||
mGLContext->fViewport(0, 0, rect.width, rect.height);
|
||||
|
||||
float viewMatrix[4][4];
|
||||
/**
|
||||
@ -395,17 +383,17 @@ LayerManagerOGL::SetupBackBuffer()
|
||||
}
|
||||
|
||||
if (!mBackBuffer) {
|
||||
sglWrapper.GenTextures(1, &mBackBuffer);
|
||||
mGLContext->fGenTextures(1, &mBackBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the texture used as the backbuffer.
|
||||
*/
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mBackBuffer);
|
||||
sglWrapper.TexEnvf(LOCAL_GL_TEXTURE_ENV, LOCAL_GL_TEXTURE_ENV_MODE, LOCAL_GL_MODULATE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_NEAREST);
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mBackBuffer);
|
||||
mGLContext->fTexEnvf(LOCAL_GL_TEXTURE_ENV, LOCAL_GL_TEXTURE_ENV_MODE, LOCAL_GL_MODULATE);
|
||||
mGLContext->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST);
|
||||
mGLContext->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_NEAREST);
|
||||
mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
width,
|
||||
@ -420,15 +408,15 @@ LayerManagerOGL::SetupBackBuffer()
|
||||
* framebuffer.
|
||||
*/
|
||||
if (!mFrameBuffer) {
|
||||
sglWrapper.GenFramebuffersEXT(1, &mFrameBuffer);
|
||||
mGLContext->fGenFramebuffers(1, &mFrameBuffer);
|
||||
}
|
||||
|
||||
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, mFrameBuffer);
|
||||
sglWrapper.FramebufferTexture2DEXT(LOCAL_GL_FRAMEBUFFER_EXT,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0_EXT,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
mBackBuffer,
|
||||
0);
|
||||
mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mFrameBuffer);
|
||||
mGLContext->fFramebufferTexture2D(LOCAL_GL_FRAMEBUFFER,
|
||||
LOCAL_GL_COLOR_ATTACHMENT0,
|
||||
LOCAL_GL_TEXTURE_2D,
|
||||
mBackBuffer,
|
||||
0);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
@ -450,19 +438,19 @@ LayerManagerOGL::CopyToTarget()
|
||||
new gfxImageSurface(gfxIntSize(width, height),
|
||||
gfxASurface::ImageFormatARGB32);
|
||||
|
||||
sglWrapper.ReadBuffer(LOCAL_GL_COLOR_ATTACHMENT0_EXT);
|
||||
mGLContext->fReadBuffer(LOCAL_GL_COLOR_ATTACHMENT0);
|
||||
|
||||
if (imageSurface->Stride() != width * 4) {
|
||||
char *tmpData = new char[width * height * 4];
|
||||
|
||||
sglWrapper.ReadPixels(0,
|
||||
mGLContext->fReadPixels(0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
tmpData);
|
||||
sglWrapper.Finish();
|
||||
mGLContext->fFinish();
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
memcpy(imageSurface->Data() + imageSurface->Stride() * y,
|
||||
@ -471,14 +459,14 @@ LayerManagerOGL::CopyToTarget()
|
||||
}
|
||||
delete [] tmpData;
|
||||
} else {
|
||||
sglWrapper.ReadPixels(0,
|
||||
mGLContext->fReadPixels(0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
imageSurface->Data());
|
||||
sglWrapper.Finish();
|
||||
mGLContext->fFinish();
|
||||
}
|
||||
|
||||
mTarget->SetOperator(gfxContext::OPERATOR_OVER);
|
||||
@ -486,8 +474,9 @@ LayerManagerOGL::CopyToTarget()
|
||||
mTarget->Paint();
|
||||
}
|
||||
|
||||
LayerOGL::LayerOGL()
|
||||
: mNextSibling(NULL)
|
||||
LayerOGL::LayerOGL(LayerManagerOGL *aManager)
|
||||
: mOGLManager(aManager)
|
||||
, mNextSibling(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -507,28 +496,33 @@ LayerOGL::SetNextSibling(LayerOGL *aNextSibling)
|
||||
* LayerProgram Helpers
|
||||
*/
|
||||
LayerProgram::LayerProgram()
|
||||
: mProgram(0)
|
||||
: mGLContext(NULL)
|
||||
, mProgram(0)
|
||||
{
|
||||
}
|
||||
|
||||
LayerProgram::~LayerProgram()
|
||||
{
|
||||
sglWrapper.DeleteProgram(mProgram);
|
||||
mGLContext->fDeleteProgram(mProgram);
|
||||
}
|
||||
|
||||
PRBool
|
||||
LayerProgram::Initialize(GLuint aVertexShader, GLuint aFragmentShader)
|
||||
LayerProgram::Initialize(GLuint aVertexShader,
|
||||
GLuint aFragmentShader,
|
||||
mozilla::gl::GLContext *aContext)
|
||||
{
|
||||
mProgram = sglWrapper.CreateProgram();
|
||||
sglWrapper.AttachShader(mProgram, aVertexShader);
|
||||
sglWrapper.AttachShader(mProgram, aFragmentShader);
|
||||
mGLContext = aContext;
|
||||
|
||||
sglWrapper.BindAttribLocation(mProgram, VERTEX_ATTRIB_LOCATION, "aVertex");
|
||||
mProgram = mGLContext->fCreateProgram();
|
||||
mGLContext->fAttachShader(mProgram, aVertexShader);
|
||||
mGLContext->fAttachShader(mProgram, aFragmentShader);
|
||||
|
||||
mGLContext->fBindAttribLocation(mProgram, VERTEX_ATTRIB_LOCATION, "aVertex");
|
||||
|
||||
sglWrapper.LinkProgram(mProgram);
|
||||
mGLContext->fLinkProgram(mProgram);
|
||||
|
||||
GLint status;
|
||||
sglWrapper.GetProgramiv(mProgram, LOCAL_GL_LINK_STATUS, &status);
|
||||
mGLContext->fGetProgramiv(mProgram, LOCAL_GL_LINK_STATUS, &status);
|
||||
|
||||
if (!status) {
|
||||
return false;
|
||||
@ -539,37 +533,37 @@ LayerProgram::Initialize(GLuint aVertexShader, GLuint aFragmentShader)
|
||||
void
|
||||
LayerProgram::Activate()
|
||||
{
|
||||
sglWrapper.UseProgram(mProgram);
|
||||
mGLContext->fUseProgram(mProgram);
|
||||
}
|
||||
|
||||
void
|
||||
LayerProgram::UpdateLocations()
|
||||
{
|
||||
mMatrixProjLocation = sglWrapper.GetUniformLocation(mProgram, "uMatrixProj");
|
||||
mMatrixProjLocation = mGLContext->fGetUniformLocation(mProgram, "uMatrixProj");
|
||||
mLayerQuadTransformLocation =
|
||||
sglWrapper.GetUniformLocation(mProgram, "uLayerQuadTransform");
|
||||
mLayerTransformLocation = sglWrapper.GetUniformLocation(mProgram, "uLayerTransform");
|
||||
mGLContext->fGetUniformLocation(mProgram, "uLayerQuadTransform");
|
||||
mLayerTransformLocation = mGLContext->fGetUniformLocation(mProgram, "uLayerTransform");
|
||||
mRenderTargetOffsetLocation =
|
||||
sglWrapper.GetUniformLocation(mProgram, "uRenderTargetOffset");
|
||||
mLayerOpacityLocation = sglWrapper.GetUniformLocation(mProgram, "uLayerOpacity");
|
||||
mGLContext->fGetUniformLocation(mProgram, "uRenderTargetOffset");
|
||||
mLayerOpacityLocation = mGLContext->fGetUniformLocation(mProgram, "uLayerOpacity");
|
||||
}
|
||||
|
||||
void
|
||||
LayerProgram::SetMatrixUniform(GLint aLocation, const GLfloat *aValue)
|
||||
{
|
||||
sglWrapper.UniformMatrix4fv(aLocation, 1, false, aValue);
|
||||
mGLContext->fUniformMatrix4fv(aLocation, 1, false, aValue);
|
||||
}
|
||||
|
||||
void
|
||||
LayerProgram::SetInt(GLint aLocation, GLint aValue)
|
||||
{
|
||||
sglWrapper.Uniform1i(aLocation, aValue);
|
||||
mGLContext->fUniform1i(aLocation, aValue);
|
||||
}
|
||||
|
||||
void
|
||||
LayerProgram::SetLayerOpacity(GLfloat aValue)
|
||||
{
|
||||
sglWrapper.Uniform1f(mLayerOpacityLocation, aValue);
|
||||
mGLContext->fUniform1f(mLayerOpacityLocation, aValue);
|
||||
}
|
||||
|
||||
void
|
||||
@ -592,11 +586,11 @@ void
|
||||
LayerProgram::Apply()
|
||||
{
|
||||
if (!mRenderTargetOffsetStack.Length()) {
|
||||
sglWrapper.Uniform4f(mRenderTargetOffsetLocation, 0, 0, 0, 0);
|
||||
mGLContext->fUniform4f(mRenderTargetOffsetLocation, 0, 0, 0, 0);
|
||||
} else {
|
||||
GLvec2 vector =
|
||||
mRenderTargetOffsetStack[mRenderTargetOffsetStack.Length() - 1];
|
||||
sglWrapper.Uniform4f(mRenderTargetOffsetLocation, vector.mX, vector.mY, 0, 0);
|
||||
mGLContext->fUniform4f(mRenderTargetOffsetLocation, vector.mX, vector.mY, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -605,7 +599,7 @@ RGBLayerProgram::UpdateLocations()
|
||||
{
|
||||
LayerProgram::UpdateLocations();
|
||||
|
||||
mLayerTextureLocation = sglWrapper.GetUniformLocation(mProgram, "uLayerTexture");
|
||||
mLayerTextureLocation = mGLContext->fGetUniformLocation(mProgram, "uLayerTexture");
|
||||
}
|
||||
|
||||
void
|
||||
@ -613,9 +607,9 @@ YCbCrLayerProgram::UpdateLocations()
|
||||
{
|
||||
LayerProgram::UpdateLocations();
|
||||
|
||||
mYTextureLocation = sglWrapper.GetUniformLocation(mProgram, "uYTexture");
|
||||
mCbTextureLocation = sglWrapper.GetUniformLocation(mProgram, "uCbTexture");
|
||||
mCrTextureLocation = sglWrapper.GetUniformLocation(mProgram, "uCrTexture");
|
||||
mYTextureLocation = mGLContext->fGetUniformLocation(mProgram, "uYTexture");
|
||||
mCbTextureLocation = mGLContext->fGetUniformLocation(mProgram, "uCbTexture");
|
||||
mCrTextureLocation = mGLContext->fGetUniformLocation(mProgram, "uCrTexture");
|
||||
}
|
||||
|
||||
} /* layers */
|
||||
|
@ -53,6 +53,7 @@ typedef char GLchar;
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "GLContext.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
@ -74,7 +75,9 @@ public:
|
||||
LayerProgram();
|
||||
virtual ~LayerProgram();
|
||||
|
||||
PRBool Initialize(GLuint aVertexShader, GLuint aFragmentShader);
|
||||
PRBool Initialize(GLuint aVertexShader,
|
||||
GLuint aFragmentShader,
|
||||
mozilla::gl::GLContext *aContext);
|
||||
|
||||
virtual void UpdateLocations();
|
||||
|
||||
@ -106,6 +109,8 @@ public:
|
||||
void Apply();
|
||||
|
||||
protected:
|
||||
mozilla::gl::GLContext *mGLContext;
|
||||
|
||||
GLuint mProgram;
|
||||
GLint mMatrixProjLocation;
|
||||
GLint mLayerQuadTransformLocation;
|
||||
@ -215,6 +220,10 @@ public:
|
||||
RGBLayerProgram *GetRGBLayerProgram() { return mRGBLayerProgram; }
|
||||
YCbCrLayerProgram *GetYCbCrLayerProgram() { return mYCbCrLayerProgram; }
|
||||
|
||||
typedef mozilla::gl::GLContext GLContext;
|
||||
|
||||
GLContext *gl() const { return mGLContext; }
|
||||
|
||||
private:
|
||||
/** Widget associated with this layer manager */
|
||||
nsIWidget *mWidget;
|
||||
@ -223,13 +232,7 @@ private:
|
||||
*/
|
||||
nsRefPtr<gfxContext> mTarget;
|
||||
|
||||
#ifdef XP_WIN
|
||||
/** Windows Device Context */
|
||||
HDC mDC;
|
||||
|
||||
/** OpenGL Context */
|
||||
HGLRC mContext;
|
||||
#endif
|
||||
nsRefPtr<GLContext> mGLContext;
|
||||
|
||||
/** Backbuffer */
|
||||
GLuint mBackBuffer;
|
||||
@ -282,7 +285,7 @@ private:
|
||||
class LayerOGL
|
||||
{
|
||||
public:
|
||||
LayerOGL();
|
||||
LayerOGL(LayerManagerOGL *aManager);
|
||||
|
||||
enum LayerType { TYPE_THEBES, TYPE_CONTAINER, TYPE_IMAGE };
|
||||
|
||||
@ -298,7 +301,11 @@ public:
|
||||
|
||||
virtual void RenderLayer(int aPreviousFrameBuffer) = 0;
|
||||
|
||||
typedef mozilla::gl::GLContext GLContext;
|
||||
|
||||
GLContext *gl() const { return mOGLManager->gl(); }
|
||||
protected:
|
||||
LayerManagerOGL *mOGLManager;
|
||||
LayerOGL *mNextSibling;
|
||||
};
|
||||
|
||||
|
@ -43,8 +43,6 @@
|
||||
#include "gfxWindowsSurface.h"
|
||||
#endif
|
||||
|
||||
#include "glWrapper.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
@ -71,8 +69,9 @@ UseOpaqueSurface(Layer* aLayer)
|
||||
}
|
||||
|
||||
|
||||
ThebesLayerOGL::ThebesLayerOGL(LayerManager *aManager)
|
||||
ThebesLayerOGL::ThebesLayerOGL(LayerManagerOGL *aManager)
|
||||
: ThebesLayer(aManager, NULL)
|
||||
, LayerOGL(aManager)
|
||||
, mTexture(0)
|
||||
{
|
||||
mImplData = static_cast<LayerOGL*>(this);
|
||||
@ -82,7 +81,7 @@ ThebesLayerOGL::~ThebesLayerOGL()
|
||||
{
|
||||
static_cast<LayerManagerOGL*>(mManager)->MakeCurrent();
|
||||
if (mTexture) {
|
||||
sglWrapper.DeleteTextures(1, &mTexture);
|
||||
gl()->fDeleteTextures(1, &mTexture);
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,27 +96,27 @@ ThebesLayerOGL::SetVisibleRegion(const nsIntRegion &aRegion)
|
||||
static_cast<LayerManagerOGL*>(mManager)->MakeCurrent();
|
||||
|
||||
if (!mTexture) {
|
||||
sglWrapper.GenTextures(1, &mTexture);
|
||||
gl()->fGenTextures(1, &mTexture);
|
||||
}
|
||||
|
||||
mInvalidatedRect = mVisibleRect;
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
|
||||
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
mVisibleRect.width,
|
||||
mVisibleRect.height,
|
||||
0,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
gl()->fTexImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
LOCAL_GL_RGBA,
|
||||
mVisibleRect.width,
|
||||
mVisibleRect.height,
|
||||
0,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -204,16 +203,16 @@ ThebesLayerOGL::EndDrawing()
|
||||
break;
|
||||
}
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
sglWrapper.TexSubImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
mInvalidatedRect.x - mVisibleRect.x,
|
||||
mInvalidatedRect.y - mVisibleRect.y,
|
||||
mInvalidatedRect.width,
|
||||
mInvalidatedRect.height,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
imageSurface->Data());
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
gl()->fTexSubImage2D(LOCAL_GL_TEXTURE_2D,
|
||||
0,
|
||||
mInvalidatedRect.x - mVisibleRect.x,
|
||||
mInvalidatedRect.y - mVisibleRect.y,
|
||||
mInvalidatedRect.width,
|
||||
mInvalidatedRect.height,
|
||||
LOCAL_GL_BGRA,
|
||||
LOCAL_GL_UNSIGNED_BYTE,
|
||||
imageSurface->Data());
|
||||
|
||||
mDestinationSurface = NULL;
|
||||
mContext = NULL;
|
||||
@ -268,9 +267,9 @@ ThebesLayerOGL::RenderLayer(int aPreviousFrameBuffer)
|
||||
program->SetLayerTransform(&mTransform._11);
|
||||
program->Apply();
|
||||
|
||||
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
|
||||
|
||||
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
gl()->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
const nsIntRect&
|
||||
|
@ -50,7 +50,7 @@ class ThebesLayerOGL : public ThebesLayer,
|
||||
public LayerOGL
|
||||
{
|
||||
public:
|
||||
ThebesLayerOGL(LayerManager *aManager);
|
||||
ThebesLayerOGL(LayerManagerOGL *aManager);
|
||||
virtual ~ThebesLayerOGL();
|
||||
|
||||
/** Layer implementation */
|
||||
|
@ -1,234 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bas Schouten <bschouten@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "glWrapper.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#define glGetProcAddress wGetProcAddress
|
||||
#else
|
||||
// We do not know how to glGetProcAddress on this platform.
|
||||
PRFuncPtr glGetProcAddress(const char *)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
glWrapper sglWrapper;
|
||||
|
||||
struct OGLFunction {
|
||||
PRFuncPtr *functor;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
glWrapper::glWrapper()
|
||||
: mIsInitialized(PR_FALSE)
|
||||
, mOGLLibrary(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
#ifdef XP_WIN
|
||||
HGLRC
|
||||
glWrapper::wCreateContext(HDC aDC)
|
||||
{
|
||||
if (!wCreateContextInternal) {
|
||||
if (!mOGLLibrary) {
|
||||
#ifdef XP_WIN
|
||||
mOGLLibrary = PR_LoadLibrary("Opengl32.dll");
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
if (!mOGLLibrary) {
|
||||
NS_WARNING("Couldn't load OpenGL DLL.");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wCreateContextInternal = (PFNWGLCREATECONTEXTPROC)
|
||||
PR_FindFunctionSymbol(mOGLLibrary, "wglCreateContext");
|
||||
wDeleteContext = (PFNWGLDELETECONTEXTPROC)
|
||||
PR_FindFunctionSymbol(mOGLLibrary, "wglDeleteContext");
|
||||
wMakeCurrent = (PFNWGLMAKECURRENTPROC)
|
||||
PR_FindFunctionSymbol(mOGLLibrary, "wglMakeCurrent");
|
||||
wGetProcAddress = (PFNWGLGETPROCADDRESSPROC)
|
||||
PR_FindFunctionSymbol(mOGLLibrary, "wglGetProcAddress");
|
||||
}
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
ZeroMemory(&pfd, sizeof(pfd));
|
||||
|
||||
pfd.nSize = sizeof(pfd);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 0;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
int iFormat = ChoosePixelFormat(aDC, &pfd);
|
||||
|
||||
/**
|
||||
* We need to make sure we call SetPixelFormat -after- loading the OGL
|
||||
* library, otherwise it can load/unload the dll and wglCreateContext
|
||||
* will fail.
|
||||
*/
|
||||
SetPixelFormat(aDC, iFormat, &pfd);
|
||||
HGLRC retval = wCreateContextInternal(aDC);
|
||||
|
||||
if (!retval) {
|
||||
return retval;
|
||||
}
|
||||
wMakeCurrent(aDC, retval);
|
||||
|
||||
if (!EnsureInitialized()) {
|
||||
NS_WARNING("Failed to initialize OpenGL wrapper.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRBool
|
||||
glWrapper::LoadSymbols(OGLFunction *functions)
|
||||
{
|
||||
for (int i = 0; functions[i].functor; i++) {
|
||||
*functions[i].functor =
|
||||
PR_FindFunctionSymbol(mOGLLibrary, functions[i].name);
|
||||
|
||||
if (*functions[i].functor) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!glGetProcAddress) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
*functions[i].functor = (PRFuncPtr)glGetProcAddress(functions[i].name);
|
||||
if (!*functions[i].functor) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
glWrapper::EnsureInitialized()
|
||||
{
|
||||
if (mIsInitialized) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
OGLFunction functions[] = {
|
||||
|
||||
{ (PRFuncPtr*) &BlendFuncSeparate, "glBlendFuncSeparate" },
|
||||
|
||||
{ (PRFuncPtr*) &Enable, "glEnable" },
|
||||
{ (PRFuncPtr*) &EnableClientState, "glEnableClientState" },
|
||||
{ (PRFuncPtr*) &EnableVertexAttribArray, "glEnableVertexAttribArray" },
|
||||
{ (PRFuncPtr*) &Disable, "glDisable" },
|
||||
{ (PRFuncPtr*) &DisableClientState, "glDisableClientState" },
|
||||
{ (PRFuncPtr*) &DisableVertexAttribArray, "glDisableVertexAttribArray" },
|
||||
|
||||
{ (PRFuncPtr*) &DrawArrays, "glDrawArrays" },
|
||||
|
||||
{ (PRFuncPtr*) &Finish, "glFinish" },
|
||||
{ (PRFuncPtr*) &Clear, "glClear" },
|
||||
{ (PRFuncPtr*) &Scissor, "glScissor" },
|
||||
{ (PRFuncPtr*) &Viewport, "glViewport" },
|
||||
{ (PRFuncPtr*) &ClearColor, "glClearColor" },
|
||||
{ (PRFuncPtr*) &ReadBuffer, "glReadBuffer" },
|
||||
{ (PRFuncPtr*) &ReadPixels, "glReadPixels" },
|
||||
|
||||
{ (PRFuncPtr*) &TexEnvf, "glTexEnvf" },
|
||||
{ (PRFuncPtr*) &TexParameteri, "glTexParameteri" },
|
||||
{ (PRFuncPtr*) &ActiveTexture, "glActiveTexture" },
|
||||
{ (PRFuncPtr*) &PixelStorei, "glPixelStorei" },
|
||||
|
||||
{ (PRFuncPtr*) &GenTextures, "glGenTextures" },
|
||||
{ (PRFuncPtr*) &GenBuffers, "glGenBuffers" },
|
||||
{ (PRFuncPtr*) &GenFramebuffersEXT, "glGenFramebuffersEXT" },
|
||||
{ (PRFuncPtr*) &DeleteTextures, "glDeleteTextures" },
|
||||
{ (PRFuncPtr*) &DeleteFramebuffersEXT, "glDeleteFramebuffersEXT" },
|
||||
|
||||
{ (PRFuncPtr*) &BindTexture, "glBindTexture" },
|
||||
{ (PRFuncPtr*) &BindBuffer, "glBindBuffer" },
|
||||
{ (PRFuncPtr*) &BindFramebufferEXT, "glBindFramebufferEXT" },
|
||||
|
||||
{ (PRFuncPtr*) &FramebufferTexture2DEXT, "glFramebufferTexture2DEXT" },
|
||||
{ (PRFuncPtr*) &CheckFramebufferStatusEXT, "glCheckFramebufferStatusEXT" },
|
||||
|
||||
{ (PRFuncPtr*) &BufferData, "glBufferData" },
|
||||
|
||||
{ (PRFuncPtr*) &VertexPointer, "glVertexPointer" },
|
||||
{ (PRFuncPtr*) &TexCoordPointer, "glTexCoordPointer" },
|
||||
|
||||
{ (PRFuncPtr*) &TexImage2D, "glTexImage2D" },
|
||||
{ (PRFuncPtr*) &TexSubImage2D, "glTexSubImage2D" },
|
||||
|
||||
{ (PRFuncPtr*) &CreateShader, "glCreateShader" },
|
||||
{ (PRFuncPtr*) &CreateProgram, "glCreateProgram" },
|
||||
{ (PRFuncPtr*) &DeleteProgram, "glDeleteProgram" },
|
||||
{ (PRFuncPtr*) &UseProgram, "glUseProgram" },
|
||||
{ (PRFuncPtr*) &ShaderSource, "glShaderSource" },
|
||||
{ (PRFuncPtr*) &CompileShader, "glCompileShader" },
|
||||
{ (PRFuncPtr*) &AttachShader, "glAttachShader" },
|
||||
{ (PRFuncPtr*) &LinkProgram, "glLinkProgram" },
|
||||
{ (PRFuncPtr*) &GetProgramiv, "glGetProgramiv" },
|
||||
{ (PRFuncPtr*) &GetShaderiv, "glGetShaderiv" },
|
||||
|
||||
{ (PRFuncPtr*) &BindAttribLocation, "glBindAttribLocation" },
|
||||
{ (PRFuncPtr*) &VertexAttribPointer, "glVertexAttribPointer" },
|
||||
|
||||
{ (PRFuncPtr*) &Uniform1i, "glUniform1i" },
|
||||
{ (PRFuncPtr*) &Uniform1f, "glUniform1f" },
|
||||
{ (PRFuncPtr*) &Uniform4f, "glUniform4f" },
|
||||
{ (PRFuncPtr*) &UniformMatrix4fv, "glUniformMatrix4fv" },
|
||||
{ (PRFuncPtr*) &GetUniformLocation, "glGetUniformLocation" },
|
||||
|
||||
{ (PRFuncPtr*) &GetString, "glGetString" },
|
||||
|
||||
{ NULL, NULL }
|
||||
|
||||
};
|
||||
|
||||
if (!LoadSymbols(functions)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
mIsInitialized = PR_TRUE;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
@ -1,280 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bas Schouten <bschouten@mozilla.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef GFX_GLWRAPPER_H
|
||||
#define GFX_GLWRAPPER_H
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include "prlink.h"
|
||||
|
||||
#include "glDefs.h"
|
||||
|
||||
struct OGLFunction;
|
||||
|
||||
class glWrapper
|
||||
{
|
||||
public:
|
||||
glWrapper();
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLBLENDFUNCSEPARATEPROC) (GLenum,
|
||||
GLenum,
|
||||
GLenum,
|
||||
GLenum);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLENABLEPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLENABLECLIENTSTATEPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLDISABLEPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLDISABLECLIENTSTATEPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLDRAWARRAYSPROC) (GLenum, GLint, GLsizei);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLFINISHPROC) (void);
|
||||
typedef void (GLAPIENTRY * PFNGLCLEARPROC) (GLbitfield);
|
||||
typedef void (GLAPIENTRY * PFNGLSCISSORPROC) (GLint, GLint, GLsizei, GLsizei);
|
||||
typedef void (GLAPIENTRY * PFNGLVIEWPORTPROC) (GLint, GLint, GLsizei, GLsizei);
|
||||
typedef void (GLAPIENTRY * PFNGLCLEARCOLORPROC) (GLclampf,
|
||||
GLclampf,
|
||||
GLclampf,
|
||||
GLclampf);
|
||||
typedef void (GLAPIENTRY * PFNGLREADBUFFERPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLREADPIXELSPROC) (GLint,
|
||||
GLint,
|
||||
GLsizei,
|
||||
GLsizei,
|
||||
GLenum,
|
||||
GLenum,
|
||||
GLvoid *);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLTEXENVFPROC) (GLenum, GLenum, GLfloat);
|
||||
typedef void (GLAPIENTRY * PFNGLTEXPARAMETERIPROC) (GLenum, GLenum, GLint);
|
||||
typedef void (GLAPIENTRY * PFNGLACTIVETEXTUREPROC) (GLenum);
|
||||
typedef void (GLAPIENTRY * PFNGLPIXELSTOREIPROC) (GLenum, GLint);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLGENTEXTURESPROC) (GLsizei, GLuint *);
|
||||
typedef void (GLAPIENTRY * PFNGLGENBUFFERSPROC) (GLsizei, GLuint *);
|
||||
typedef void (GLAPIENTRY * PFNGLGENFRAMEBUFFERSEXTPROC) (GLsizei, GLuint *);
|
||||
typedef void (GLAPIENTRY * PFNGLDELETETEXTURESPROC) (GLsizei, const GLuint *);
|
||||
typedef void (GLAPIENTRY * PFNGLDELETEFRAMEBUFFERSEXTPROC) (GLsizei,
|
||||
const GLuint *);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLBINDTEXTUREPROC) (GLenum, GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLBINDBUFFERPROC) (GLenum, GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLBINDFRAMEBUFFEREXTPROC) (GLenum, GLuint);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) (GLenum,
|
||||
GLenum,
|
||||
GLenum,
|
||||
GLuint,
|
||||
GLint);
|
||||
typedef GLenum (GLAPIENTRY * PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) (GLenum);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLBUFFERDATAPROC) (GLenum,
|
||||
GLsizeiptr,
|
||||
const GLvoid *,
|
||||
GLenum);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLVERTEXPOINTERPROC) (GLint,
|
||||
GLenum,
|
||||
GLsizei,
|
||||
const GLvoid *);
|
||||
typedef void (GLAPIENTRY * PFNGLTEXCOORDPOINTERPROC) (GLint,
|
||||
GLenum,
|
||||
GLsizei,
|
||||
const GLvoid *);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLTEXIMAGE2DPROC) (GLenum,
|
||||
GLint,
|
||||
GLint,
|
||||
GLsizei,
|
||||
GLsizei,
|
||||
GLint,
|
||||
GLenum,
|
||||
GLenum,
|
||||
const GLvoid *);
|
||||
typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE2DPROC) (GLenum,
|
||||
GLint,
|
||||
GLint,
|
||||
GLint,
|
||||
GLsizei,
|
||||
GLsizei,
|
||||
GLenum,
|
||||
GLenum,
|
||||
const GLvoid *);
|
||||
|
||||
typedef GLuint (GLAPIENTRY * PFNGLCREATESHADERPROC) (GLenum);
|
||||
typedef GLuint (GLAPIENTRY * PFNGLCREATEPROGRAMPROC) (void);
|
||||
typedef void (GLAPIENTRY * PFNGLDELETEPROGRAMPROC) (GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLUSEPROGRAMPROC) (GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLSHADERSOURCEPROC) (GLuint,
|
||||
GLsizei,
|
||||
const GLchar **,
|
||||
const GLint *);
|
||||
typedef void (GLAPIENTRY * PFNGLCOMPILESHADERPROC) (GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLATTACHSHADERPROC) (GLuint, GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLLINKPROGRAMPROC) (GLuint);
|
||||
typedef void (GLAPIENTRY * PFNGLGETPROGRAMIVPROC) (GLuint, GLenum, GLint *);
|
||||
typedef void (GLAPIENTRY * PFNGLGETSHADERIVPROC) (GLuint, GLenum, GLint *);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint,
|
||||
GLuint,
|
||||
const GLchar *);
|
||||
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint,
|
||||
GLint,
|
||||
GLenum,
|
||||
GLboolean,
|
||||
GLsizei,
|
||||
const GLvoid *);
|
||||
|
||||
typedef void (GLAPIENTRY * PFNGLUNIFORM1IPROC) (GLint, GLint);
|
||||
typedef void (GLAPIENTRY * PFNGLUNIFORM1FPROC) (GLint, GLfloat);
|
||||
typedef void (GLAPIENTRY * PFNGLUNIFORM4FPROC) (GLint,
|
||||
GLfloat,
|
||||
GLfloat,
|
||||
GLfloat,
|
||||
GLfloat);
|
||||
typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX4FVPROC) (GLint,
|
||||
GLsizei,
|
||||
GLboolean,
|
||||
const GLfloat *);
|
||||
typedef GLint (GLAPIENTRY * PFNGLGETUNIFORMLOCATIONPROC) (GLuint,
|
||||
const GLchar *);
|
||||
|
||||
typedef GLubyte* (GLAPIENTRY * PFNGLGETSTRINGPROC) (GLenum);
|
||||
|
||||
#ifdef XP_WIN
|
||||
typedef HGLRC (GLAPIENTRY * PFNWGLCREATECONTEXTPROC) (HDC);
|
||||
typedef BOOL (GLAPIENTRY * PFNWGLDELETECONTEXTPROC) (HGLRC);
|
||||
typedef BOOL (GLAPIENTRY * PFNWGLMAKECURRENTPROC) (HDC, HGLRC);
|
||||
typedef PROC (GLAPIENTRY * PFNWGLGETPROCADDRESSPROC) (LPCSTR);
|
||||
#endif
|
||||
|
||||
PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
|
||||
|
||||
PFNGLENABLEPROC Enable;
|
||||
PFNGLENABLECLIENTSTATEPROC EnableClientState;
|
||||
PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
|
||||
PFNGLDISABLEPROC Disable;
|
||||
PFNGLDISABLECLIENTSTATEPROC DisableClientState;
|
||||
PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
|
||||
|
||||
PFNGLDRAWARRAYSPROC DrawArrays;
|
||||
|
||||
PFNGLFINISHPROC Finish;
|
||||
PFNGLCLEARPROC Clear;
|
||||
PFNGLSCISSORPROC Scissor;
|
||||
PFNGLVIEWPORTPROC Viewport;
|
||||
PFNGLCLEARCOLORPROC ClearColor;
|
||||
PFNGLREADBUFFERPROC ReadBuffer;
|
||||
PFNGLREADPIXELSPROC ReadPixels;
|
||||
|
||||
PFNGLTEXENVFPROC TexEnvf;
|
||||
PFNGLTEXPARAMETERIPROC TexParameteri;
|
||||
PFNGLACTIVETEXTUREPROC ActiveTexture;
|
||||
PFNGLPIXELSTOREIPROC PixelStorei;
|
||||
|
||||
PFNGLGENTEXTURESPROC GenTextures;
|
||||
PFNGLGENBUFFERSPROC GenBuffers;
|
||||
PFNGLGENFRAMEBUFFERSEXTPROC GenFramebuffersEXT;
|
||||
PFNGLDELETETEXTURESPROC DeleteTextures;
|
||||
PFNGLDELETEFRAMEBUFFERSEXTPROC DeleteFramebuffersEXT;
|
||||
|
||||
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC CheckFramebufferStatusEXT;
|
||||
|
||||
PFNGLBINDTEXTUREPROC BindTexture;
|
||||
PFNGLBINDBUFFERPROC BindBuffer;
|
||||
PFNGLBINDFRAMEBUFFEREXTPROC BindFramebufferEXT;
|
||||
|
||||
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC FramebufferTexture2DEXT;
|
||||
|
||||
PFNGLBUFFERDATAPROC BufferData;
|
||||
|
||||
PFNGLVERTEXPOINTERPROC VertexPointer;
|
||||
PFNGLTEXCOORDPOINTERPROC TexCoordPointer;
|
||||
|
||||
PFNGLTEXIMAGE2DPROC TexImage2D;
|
||||
PFNGLTEXSUBIMAGE2DPROC TexSubImage2D;
|
||||
|
||||
PFNGLCREATESHADERPROC CreateShader;
|
||||
PFNGLCREATEPROGRAMPROC CreateProgram;
|
||||
PFNGLDELETEPROGRAMPROC DeleteProgram;
|
||||
PFNGLUSEPROGRAMPROC UseProgram;
|
||||
PFNGLSHADERSOURCEPROC ShaderSource;
|
||||
PFNGLCOMPILESHADERPROC CompileShader;
|
||||
PFNGLATTACHSHADERPROC AttachShader;
|
||||
PFNGLLINKPROGRAMPROC LinkProgram;
|
||||
PFNGLGETPROGRAMIVPROC GetProgramiv;
|
||||
PFNGLGETSHADERIVPROC GetShaderiv;
|
||||
|
||||
PFNGLBINDATTRIBLOCATIONPROC BindAttribLocation;
|
||||
PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
|
||||
|
||||
PFNGLUNIFORM1IPROC Uniform1i;
|
||||
PFNGLUNIFORM1FPROC Uniform1f;
|
||||
PFNGLUNIFORM4FPROC Uniform4f;
|
||||
PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
|
||||
PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
|
||||
|
||||
PFNGLGETSTRINGPROC GetString;
|
||||
|
||||
#ifdef XP_WIN
|
||||
/**
|
||||
* We intercept this call and do some stuff (like load the wglCreateContext
|
||||
* and ensure our other function pointers are initialized.
|
||||
*/
|
||||
HGLRC wCreateContext(HDC aDC);
|
||||
PFNWGLCREATECONTEXTPROC wCreateContextInternal;
|
||||
PFNWGLDELETECONTEXTPROC wDeleteContext;
|
||||
PFNWGLMAKECURRENTPROC wMakeCurrent;
|
||||
PFNWGLGETPROCADDRESSPROC wGetProcAddress;
|
||||
#endif
|
||||
|
||||
private:
|
||||
PRBool EnsureInitialized();
|
||||
|
||||
PRBool LoadSymbols(OGLFunction *functions);
|
||||
|
||||
PRBool mIsInitialized;
|
||||
PRLibrary *mOGLLibrary;
|
||||
};
|
||||
|
||||
extern glWrapper sglWrapper;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user