b=575032; make GL Context providers static, allow for multiple providers; r=bas

This commit is contained in:
Vladimir Vukicevic 2010-07-18 22:01:14 -07:00
Родитель 978b4e3454
Коммит 061fa66851
14 изменённых файлов: 190 добавлений и 143 удалений

Просмотреть файл

@ -166,11 +166,11 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
}
}
GLContextProvider::ContextFormat format(GLContextProvider::ContextFormat::BasicRGBA32);
gl::ContextFormat format(gl::ContextFormat::BasicRGBA32);
format.depth = 16;
format.minDepth = 1;
gl = gl::sGLContextProvider.CreatePBuffer(gfxIntSize(width, height), format);
gl = gl::GLContextProvider::CreatePBuffer(gfxIntSize(width, height), format);
#ifdef USE_GLES2
// On native GLES2, no need to validate, the compiler will do it

Просмотреть файл

@ -74,7 +74,7 @@ CanvasLayerOGL::Initialize(const Data& aData)
"CanvasLayerOGL can't have both surface and GLContext");
mNeedsYFlip = PR_FALSE;
if (mCanvasSurface->GetType() == gfxASurface::SurfaceTypeXlib)
mCanvasSurfaceAsGLContext = sGLContextProvider.CreateForNativePixmapSurface(mCanvasSurface);
mCanvasSurfaceAsGLContext = GLContextProvider::CreateForNativePixmapSurface(mCanvasSurface);
} else if (aData.mGLContext) {
// this must be a pbuffer context
void *pbuffer = aData.mGLContext->GetNativeData(GLContext::NativePBuffer);

Просмотреть файл

@ -543,7 +543,7 @@ CairoImageOGL::SetData(const CairoImage::Data &aData)
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
if (!mASurfaceAsGLContext) {
mASurfaceAsGLContext = sGLContextProvider.CreateForNativePixmapSurface(aData.mSurface);
mASurfaceAsGLContext = GLContextProvider::CreateForNativePixmapSurface(aData.mSurface);
if (mASurfaceAsGLContext)
mASurfaceAsGLContext->BindTexImage();
}

Просмотреть файл

@ -93,7 +93,7 @@ LayerManagerOGL::Initialize(GLContext *aExistingContext)
if (aExistingContext) {
mGLContext = aExistingContext;
} else {
mGLContext = sGLContextProvider.CreateForWindow(mWidget);
mGLContext = gl::GLContextProvider::CreateForWindow(mWidget);
if (!mGLContext) {
NS_WARNING("Failed to create LayerManagerOGL context");

Просмотреть файл

@ -53,7 +53,6 @@ namespace gl {
// define this here since it's global to GLContextProvider, not any
// specific implementation
typedef GLContextProvider::ContextFormat ContextFormat;
const ContextFormat ContextFormat::BasicRGBA32Format(ContextFormat::BasicRGBA32);
#define MAX_SYMBOL_LENGTH 128

Просмотреть файл

@ -18,6 +18,7 @@
*
* Contributor(s):
* Bas Schouten <bschouten@mozilla.com>
* Vladimir Vukicevic <vladimir@pobox.com>
*
* 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
@ -33,7 +34,6 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef GLCONTEXTPROVIDER_H_
#define GLCONTEXTPROVIDER_H_
@ -48,126 +48,104 @@ class gfxASurface;
namespace mozilla {
namespace gl {
class THEBES_API GLContextProvider
{
public:
struct ContextFormat {
static const ContextFormat BasicRGBA32Format;
struct THEBES_API ContextFormat {
static const ContextFormat BasicRGBA32Format;
enum StandardContextFormat {
Empty,
BasicRGBA32,
StrictBasicRGBA32,
BasicRGBX32,
StrictBasicRGBX32
};
ContextFormat(const StandardContextFormat cf) {
memset(this, 0, sizeof(ContextFormat));
switch (cf) {
case BasicRGBA32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = minAlpha = 1;
break;
case StrictBasicRGBA32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = minAlpha = 8;
break;
case BasicRGBX32:
red = green = blue = 8;
minRed = minGreen = minBlue = 1;
break;
case StrictBasicRGBX32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = 8;
break;
default:
break;
}
}
int depth, minDepth;
int stencil, minStencil;
int red, minRed;
int green, minGreen;
int blue, minBlue;
int alpha, minAlpha;
int colorBits() const { return red + green + blue; }
enum StandardContextFormat {
Empty,
BasicRGBA32,
StrictBasicRGBA32,
BasicRGBX32,
StrictBasicRGBX32
};
/**
* Creates a PBuffer.
*
* @param aSize Size of the pbuffer to create
* @param aFormat A ContextFormat describing the desired context attributes. Defaults to a basic RGBA32 context.
*
* @return Context to use for this Pbuffer
*/
already_AddRefed<GLContext> CreatePBuffer(const gfxIntSize &aSize,
const ContextFormat& aFormat = ContextFormat::BasicRGBA32Format);
ContextFormat(const StandardContextFormat cf) {
memset(this, 0, sizeof(ContextFormat));
/**
* Create a context that renders to the surface of the widget that is
* passed in.
*
* @param Widget whose surface to create a context for
* @return Context to use for this window
*/
already_AddRefed<GLContext> CreateForWindow(nsIWidget *aWidget);
switch (cf) {
case BasicRGBA32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = minAlpha = 1;
break;
/**
* Try to create a GL context from native surface for arbitrary gfxASurface
* If surface not compatible this will return NULL
*
* @param aSurface surface to create a context for
* @return Context to use for this surface
*/
already_AddRefed<GLContext> CreateForNativePixmapSurface(gfxASurface *aSurface);
case StrictBasicRGBA32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = minAlpha = 8;
break;
case BasicRGBX32:
red = green = blue = 8;
minRed = minGreen = minBlue = 1;
break;
case StrictBasicRGBX32:
red = green = blue = alpha = 8;
minRed = minGreen = minBlue = 8;
break;
default:
break;
}
}
int depth, minDepth;
int stencil, minStencil;
int red, minRed;
int green, minGreen;
int blue, minBlue;
int alpha, minAlpha;
int colorBits() const { return red + green + blue; }
};
/** Same as GLContextProvider but for off-screen Mesa rendering */
class THEBES_API GLContextProviderOSMesa
{
public:
typedef GLContextProvider::ContextFormat ContextFormat;
#define IN_GL_CONTEXT_PROVIDER_H
/**
* Creates a PBuffer.
*
* @param aSize Size of the pbuffer to create
* @param aFormat A ContextFormat describing the desired context attributes. Defaults to a basic RGBA32 context.
*
* @return Context to use for this Pbuffer
*/
static already_AddRefed<GLContext> CreatePBuffer(const gfxIntSize &aSize,
const ContextFormat& aFormat = ContextFormat::BasicRGBA32Format);
// Null and OSMesa are always there
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderNull
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
/**
* Create a context that renders to the surface of the widget that is
* passed in.
*
* @param Widget whose surface to create a context for
* @return Context to use for this window
*/
static already_AddRefed<GLContext> CreateForWindow(nsIWidget *aWidget);
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderOSMesa
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
/**
* Try to create a GL context from native surface for arbitrary gfxASurface
* If surface not compatible this will return NULL
*
* @param aSurface surface to create a context for
* @return Context to use for this surface
*/
static already_AddRefed<GLContext> CreateForNativePixmapSurface(gfxASurface *aSurface);
};
#ifdef XP_WIN
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderWGL
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderWGL
#define DEFAULT_IMPL WGL
#endif
extern GLContextProvider THEBES_API sGLContextProvider;
#ifdef XP_MACOSX
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderCGL
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderCGL
#endif
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderEGL
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderEGL
#endif
// X11, but only if we didn't use EGL above
#if defined(MOZ_X11) && !defined(GL_CONTEXT_PROVIDER_DEFAULT)
#define GL_CONTEXT_PROVIDER_NAME GLContextProviderGLX
#include "GLContextProviderImpl.h"
#undef GL_CONTEXT_PROVIDER_NAME
#define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderGLX
#endif
#ifdef GL_CONTEXT_PROVIDER_DEFAULT
typedef GL_CONTEXT_PROVIDER_DEFAULT GLContextProvider;
#else
typedef GLContextProviderNull GLContextProvider;
#endif
#undef IN_GL_CONTEXT_PROVIDER_H
}
}

Просмотреть файл

@ -47,8 +47,6 @@
namespace mozilla {
namespace gl {
GLContextProvider sGLContextProvider;
class CGLLibrary
{
public:
@ -207,7 +205,7 @@ GLContextCGL::CreateBasicTextureImage(GLuint aTexture,
}
already_AddRefed<GLContext>
GLContextProvider::CreateForWindow(nsIWidget *aWidget)
GLContextProviderCGL::CreateForWindow(nsIWidget *aWidget)
{
if (!sCGLLibrary.EnsureInitialized()) {
return nsnull;
@ -242,8 +240,8 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget)
}
already_AddRefed<GLContext>
GLContextProvider::CreatePBuffer(const gfxIntSize &aSize,
const ContextFormat &aFormat)
GLContextProviderCGL::CreatePBuffer(const gfxIntSize &aSize,
const ContextFormat &aFormat)
{
if (!sCGLLibrary.EnsureInitialized()) {
return nsnull;
@ -315,7 +313,7 @@ GLContextProvider::CreatePBuffer(const gfxIntSize &aSize,
}
already_AddRefed<GLContext>
GLContextProvider::CreateForNativePixmapSurface(gfxASurface *aSurface)
GLContextProviderCGL::CreateForNativePixmapSurface(gfxASurface *aSurface)
{
return nsnull;
}

Просмотреть файл

@ -111,9 +111,6 @@ typedef void *GLeglImageOES;
#define EGL_NO_DISPLAY ((EGLDisplay)0)
#define EGL_NO_SURFACE ((EGLSurface)0)
GLContextProvider sGLContextProvider;
static class EGLLibrary
{
public:
@ -476,7 +473,7 @@ GLContextEGL::CreateTextureImage(const nsIntSize& aSize,
}
already_AddRefed<GLContext>
GLContextProvider::CreateForWindow(nsIWidget *aWidget)
GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
{
if (!sEGLLibrary.EnsureInitialized()) {
return nsnull;
@ -584,7 +581,7 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget)
}
already_AddRefed<GLContext>
GLContextProvider::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat &aFormat)
GLContextProviderEGL::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat &aFormat)
{
if (!sEGLLibrary.EnsureInitialized()) {
return nsnull;
@ -665,7 +662,7 @@ GLContextProvider::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat &a
}
already_AddRefed<GLContext>
GLContextProvider::CreateForNativePixmapSurface(gfxASurface *aSurface)
GLContextProviderEGL::CreateForNativePixmapSurface(gfxASurface *aSurface)
{
EGLDisplay display = nsnull;
EGLSurface surface = nsnull;

Просмотреть файл

@ -61,8 +61,6 @@
namespace mozilla {
namespace gl {
GLContextProvider sGLContextProvider;
PRBool
GLXLibrary::EnsureInitialized()
{
@ -347,7 +345,7 @@ static PRBool AreCompatibleVisuals(XVisualInfo *one, XVisualInfo *two)
}
already_AddRefed<GLContext>
GLContextProvider::CreateForWindow(nsIWidget *aWidget)
GLContextProviderGLX::CreateForWindow(nsIWidget *aWidget)
{
if (!sGLXLibrary.EnsureInitialized()) {
return nsnull;
@ -448,7 +446,7 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget)
}
already_AddRefed<GLContext>
GLContextProvider::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat& aFormat)
GLContextProviderGLX::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat& aFormat)
{
if (!sGLXLibrary.EnsureInitialized()) {
return nsnull;
@ -511,7 +509,7 @@ GLContextProvider::CreatePBuffer(const gfxIntSize &aSize, const ContextFormat& a
}
already_AddRefed<GLContext>
GLContextProvider::CreateForNativePixmapSurface(gfxASurface *aSurface)
GLContextProviderGLX::CreateForNativePixmapSurface(gfxASurface *aSurface)
{
return nsnull;
}

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- 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 Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Bas Schouten <bschouten@mozilla.com>
* Matt Woodrow <mwoodrow@mozilla.com>
*
* 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 IN_GL_CONTEXT_PROVIDER_H
#error GLContextProviderImpl.h must only be included from GLContextProvider.h
#endif
#ifndef GL_CONTEXT_PROVIDER_NAME
#error GL_CONTEXT_PROVIDER_NAME not defined
#endif
class THEBES_API GL_CONTEXT_PROVIDER_NAME
{
public:
/**
* Create a context that renders to the surface of the widget that is
* passed in.
*
* @param Widget whose surface to create a context for
* @return Context to use for this window
*/
static already_AddRefed<GLContext>
CreateForWindow(nsIWidget *aWidget);
/**
* Creates a PBuffer.
*
* @param aSize Size of the pbuffer to create
* @param aFormat A ContextFormat describing the desired context attributes. Defaults to a basic RGBA32 context.
*
* @return Context to use for this Pbuffer
*/
static already_AddRefed<GLContext>
CreatePBuffer(const gfxIntSize &aSize,
const ContextFormat& aFormat = ContextFormat::BasicRGBA32Format);
/**
* Try to create a GL context from native surface for arbitrary gfxASurface
* If surface not compatible this will return NULL
*
* @param aSurface surface to create a context for
* @return Context to use for this surface
*/
static already_AddRefed<GLContext>
CreateForNativePixmapSurface(gfxASurface *aSurface);
};

Просмотреть файл

@ -38,22 +38,20 @@
namespace mozilla {
namespace gl {
GLContextProvider sGLContextProvider;
already_AddRefed<GLContext>
GLContextProvider::CreateForWindow(nsIWidget*)
GLContextProviderNull::CreateForWindow(nsIWidget*)
{
return nsnull;
}
already_AddRefed<GLContext>
GLContextProvider::CreateForNativePixmapSurface(gfxASurface *aSurface)
GLContextProviderNull::CreateForNativePixmapSurface(gfxASurface *aSurface)
{
return 0;
}
already_AddRefed<GLContext>
GLContextProvider::CreatePBuffer(const gfxIntSize &, const ContextFormat &)
GLContextProviderNull::CreatePBuffer(const gfxIntSize &, const ContextFormat &)
{
return nsnull;
}

Просмотреть файл

@ -165,7 +165,7 @@ public:
sOSMesaLibrary.fDestroyContext(mContext);
}
PRBool Init(const gfxIntSize &aSize, const GLContextProvider::ContextFormat& aFormat)
PRBool Init(const gfxIntSize &aSize, const ContextFormat& aFormat)
{
int osmesa_format = -1;
int gfxasurface_imageformat = -1;

Просмотреть файл

@ -47,7 +47,6 @@
namespace mozilla {
namespace gl {
GLContextProvider sGLContextProvider;
WGLLibrary sWGLLibrary;
static HWND gDummyWindow = 0;
@ -347,7 +346,7 @@ GLContextWGL::CreateBasicTextureImage(GLuint aTexture,
}
already_AddRefed<GLContext>
GLContextProvider::CreateForWindow(nsIWidget *aWidget)
GLContextProviderWGL::CreateForWindow(nsIWidget *aWidget)
{
if (!sWGLLibrary.EnsureInitialized()) {
return nsnull;
@ -385,7 +384,7 @@ GLContextProvider::CreateForWindow(nsIWidget *aWidget)
}
already_AddRefed<GLContext>
GLContextProvider::CreatePBuffer(const gfxIntSize& aSize, const ContextFormat& aFormat)
GLContextProviderWGL::CreatePBuffer(const gfxIntSize& aSize, const ContextFormat& aFormat)
{
if (!sWGLLibrary.EnsureInitialized()) {
return nsnull;
@ -468,7 +467,7 @@ GLContextProvider::CreatePBuffer(const gfxIntSize& aSize, const ContextFormat& a
}
already_AddRefed<GLContext>
GLContextProvider::CreateForNativePixmapSurface(gfxASurface *aSurface)
GLContextProviderWGL::CreateForNativePixmapSurface(gfxASurface *aSurface)
{
return nsnull;
}

Просмотреть файл

@ -40,6 +40,7 @@ EXPORTS = \
GLDefs.h \
GLContext.h \
GLContextProvider.h \
GLContextProviderImpl.h \
nsCoreAnimationSupport.h \
$(NULL)