b=561168; convert canvas to use layers for rendering - file removals

This commit is contained in:
Vladimir Vukicevic 2010-05-17 21:04:21 -07:00
Родитель 6b0e2eb7a2
Коммит c63384f10d
11 изменённых файлов: 0 добавлений и 6274 удалений

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

@ -1,112 +0,0 @@
/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Vladimir Vukicevic <vladimir@pobox.com>
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* 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 nsICanvasElement_h___
#define nsICanvasElement_h___
#include "nsISupports.h"
#include "gfxPattern.h"
class gfxContext;
class nsIFrame;
struct gfxRect;
// {D31B3CCF-DDA3-49a8-AEF6-B95AF8E09159}
#define NS_ICANVASELEMENT_IID \
{ 0xd31b3ccf, 0xdda3, 0x49a8, { 0xae, 0xf6, 0xb9, 0x5a, 0xf8, 0xe0, 0x91, 0x59 } }
class nsIRenderingContext;
class nsICanvasRenderingContextInternal;
struct _cairo_surface;
class nsICanvasElement : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASELEMENT_IID)
/**
* Ask the canvas Element to return the primary frame, if any
*/
NS_IMETHOD GetPrimaryCanvasFrame (nsIFrame **aFrame) = 0;
/**
* Get the size in pixels of this canvas element
*/
NS_IMETHOD GetSize (PRUint32 *width, PRUint32 *height) = 0;
/*
* Ask the canvas element to tell the contexts to render themselves
* to the given gfxContext at the origin of its coordinate space.
*/
NS_IMETHOD RenderContexts (gfxContext *ctx, gfxPattern::GraphicsFilter aFilter) = 0;
/**
* Determine whether the canvas is write-only.
*/
virtual PRBool IsWriteOnly() = 0;
/**
* Force the canvas to be write-only.
*/
virtual void SetWriteOnly() = 0;
/*
* Ask the canvas frame to invalidate itself
*/
NS_IMETHOD InvalidateFrame () = 0;
/*
* Ask the canvas frame to invalidate a portion of the frame; damageRect
* is relative to the origin of the canvas frame in CSS pixels.
*/
NS_IMETHOD InvalidateFrameSubrect (const gfxRect& damageRect) = 0;
/*
* Get the number of contexts in this canvas, and request a context at
* an index.
*/
virtual PRInt32 CountContexts () = 0;
virtual nsICanvasRenderingContextInternal *GetContextAtIndex (PRInt32 index) = 0;
virtual PRBool GetIsOpaque() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasElement, NS_ICANVASELEMENT_IID)
#endif /* nsICanvasElement_h___ */

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

@ -1,343 +0,0 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
* Mark Steele <mwsteele@gmail.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 ***** */
#ifdef C3D_STANDALONE_BUILD
#include "c3d-standalone.h"
#endif
#include <string.h>
#include <stdio.h>
#include "prlink.h"
#include "glwrap.h"
#define MAX_SYMBOL_LENGTH 128
#define MAX_SYMBOL_NAMES 5
bool
LibrarySymbolLoader::OpenLibrary(const char *library)
{
PRLibSpec lspec;
lspec.type = PR_LibSpec_Pathname;
lspec.value.pathname = library;
mLibrary = PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
if (!mLibrary)
return false;
return true;
}
PRFuncPtr
LibrarySymbolLoader::LookupSymbol(const char *sym, bool tryplatform)
{
PRFuncPtr res = 0;
// try finding it in the library directly, if we have one
if (mLibrary) {
res = PR_FindFunctionSymbol(mLibrary, sym);
}
// try finding it in the process
if (!res) {
PRLibrary *leakedLibRef;
res = PR_FindFunctionSymbolAndLibrary(sym, &leakedLibRef);
}
// no? then try looking it up via the lookup symbol
if (!res && tryplatform && mLookupFunc) {
res = mLookupFunc (sym);
}
return res;
}
bool
LibrarySymbolLoader::LoadSymbols(SymLoadStruct *firstStruct, bool tryplatform, const char *prefix)
{
char sbuf[MAX_SYMBOL_LENGTH * 2];
SymLoadStruct *ss = firstStruct;
while (ss->symPointer) {
*ss->symPointer = 0;
for (int i = 0; i < MAX_SYMBOL_NAMES; i++) {
if (ss->symNames[i] == NULL)
break;
const char *s = ss->symNames[i];
if (prefix && *prefix != 0) {
strcpy(sbuf, prefix);
strcat(sbuf, ss->symNames[i]);
s = sbuf;
}
PRFuncPtr p = LookupSymbol(s, tryplatform);
if (p) {
*ss->symPointer = p;
break;
}
}
if (*ss->symPointer == 0) {
fprintf (stderr, "Can't find symbol '%s'\n", ss->symNames[0]);
return false;
}
ss++;
}
return true;
}
bool
OSMesaWrap::Init()
{
if (fCreateContextExt)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fCreateContextExt, { "OSMesaCreateContextExt", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
{ (PRFuncPtr*) &fPixelStore, { "OSMesaPixelStore", NULL } },
{ (PRFuncPtr*) &fDestroyContext, { "OSMesaDestroyContext", NULL } },
{ (PRFuncPtr*) &fGetCurrentContext, { "OSMesaGetCurrentContext", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "OSMesaMakeCurrent", NULL } },
{ (PRFuncPtr*) &fGetProcAddress, { "OSMesaGetProcAddress", NULL } },
{ NULL, { NULL } }
};
return LoadSymbols(&symbols[0]);
}
bool
GLES20Wrap::Init(NativeGLMode mode)
{
if (mode & TRY_NATIVE_GL) {
if (InitNative())
return true;
}
if (mode & TRY_SOFTWARE_GL) {
if (InitSoftware())
return true;
}
return false;
}
bool
GLES20Wrap::InitNative()
{
return InitWithPrefix("gl", true);
}
bool
GLES20Wrap::InitSoftware()
{
return InitWithPrefix("mgl", true);
}
/*
* XXX - we should really know the ARB/EXT variants of these
* instead of only handling the symbol if it's exposed directly.
*/
bool
GLES20Wrap::InitWithPrefix(const char *prefix, bool trygl)
{
if (ok)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fActiveTexture, { "ActiveTexture", "ActiveTextureARB", NULL } },
{ (PRFuncPtr*) &fAttachShader, { "AttachShader", "AttachShaderARB", NULL } },
{ (PRFuncPtr*) &fBindAttribLocation, { "BindAttribLocation", "BindAttribLocationARB", NULL } },
{ (PRFuncPtr*) &fBindBuffer, { "BindBuffer", "BindBufferARB", NULL } },
{ (PRFuncPtr*) &fBindTexture, { "BindTexture", "BindTextureARB", NULL } },
{ (PRFuncPtr*) &fBlendColor, { "BlendColor", NULL } },
{ (PRFuncPtr*) &fBlendEquation, { "BlendEquation", NULL } },
{ (PRFuncPtr*) &fBlendEquationSeparate, { "BlendEquationSeparate", "BlendEquationSeparateEXT", NULL } },
{ (PRFuncPtr*) &fBlendFunc, { "BlendFunc", NULL } },
{ (PRFuncPtr*) &fBlendFuncSeparate, { "BlendFuncSeparate", "BlendFuncSeparateEXT", NULL } },
{ (PRFuncPtr*) &fBufferData, { "BufferData", NULL } },
{ (PRFuncPtr*) &fBufferSubData, { "BufferSubData", NULL } },
{ (PRFuncPtr*) &fClear, { "Clear", NULL } },
{ (PRFuncPtr*) &fClearColor, { "ClearColor", NULL } },
#ifdef USE_GLES2
{ (PRFuncPtr*) &fClearDepthf, { "ClearDepthf", NULL } },
#else
{ (PRFuncPtr*) &fClearDepth, { "ClearDepth", NULL } },
#endif
{ (PRFuncPtr*) &fClearStencil, { "ClearStencil", NULL } },
{ (PRFuncPtr*) &fColorMask, { "ColorMask", NULL } },
{ (PRFuncPtr*) &fCreateProgram, { "CreateProgram", "CreateProgramARB", NULL } },
{ (PRFuncPtr*) &fCreateShader, { "CreateShader", "CreateShaderARB", NULL } },
{ (PRFuncPtr*) &fCullFace, { "CullFace", NULL } },
{ (PRFuncPtr*) &fDeleteBuffers, { "DeleteBuffers", "DeleteBuffersARB", NULL } },
{ (PRFuncPtr*) &fDeleteTextures, { "DeleteTextures", "DeleteTexturesARB", NULL } },
{ (PRFuncPtr*) &fDeleteProgram, { "DeleteProgram", "DeleteProgramARB", NULL } },
{ (PRFuncPtr*) &fDeleteShader, { "DeleteShader", "DeleteShaderARB", NULL } },
{ (PRFuncPtr*) &fDetachShader, { "DetachShader", "DetachShaderARB", NULL } },
{ (PRFuncPtr*) &fDepthFunc, { "DepthFunc", NULL } },
{ (PRFuncPtr*) &fDepthMask, { "DepthMask", NULL } },
#ifdef USE_GLES2
{ (PRFuncPtr*) &fDepthRangef, { "DepthRangef", NULL } },
#else
{ (PRFuncPtr*) &fDepthRange, { "DepthRange", NULL } },
#endif
{ (PRFuncPtr*) &fDisable, { "Disable", NULL } },
{ (PRFuncPtr*) &fDisableVertexAttribArray, { "DisableVertexAttribArray", "DisableVertexAttribArrayARB", NULL } },
{ (PRFuncPtr*) &fDrawArrays, { "DrawArrays", NULL } },
{ (PRFuncPtr*) &fDrawElements, { "DrawElements", NULL } },
{ (PRFuncPtr*) &fEnable, { "Enable", NULL } },
{ (PRFuncPtr*) &fEnableVertexAttribArray, { "EnableVertexAttribArray", "EnableVertexAttribArrayARB", NULL } },
{ (PRFuncPtr*) &fFinish, { "Finish", NULL } },
{ (PRFuncPtr*) &fFlush, { "Flush", NULL } },
{ (PRFuncPtr*) &fFrontFace, { "FrontFace", NULL } },
{ (PRFuncPtr*) &fGetActiveAttrib, { "GetActiveAttrib", "GetActiveAttribARB", NULL } },
{ (PRFuncPtr*) &fGetActiveUniform, { "GetActiveUniform", "GetActiveUniformARB", NULL } },
{ (PRFuncPtr*) &fGetAttachedShaders, { "GetAttachedShaders", "GetAttachedShadersARB", NULL } },
{ (PRFuncPtr*) &fGetAttribLocation, { "GetAttribLocation", "GetAttribLocationARB", NULL } },
{ (PRFuncPtr*) &fGetIntegerv, { "GetIntegerv", NULL } },
{ (PRFuncPtr*) &fGetFloatv, { "GetFloatv", NULL } },
{ (PRFuncPtr*) &fGetBooleanv, { "GetBooleanv", NULL } },
{ (PRFuncPtr*) &fGetBufferParameteriv, { "GetBufferParameteriv", "GetBufferParameterivARB", NULL } },
{ (PRFuncPtr*) &fGenBuffers, { "GenBuffers", "GenBuffersARB", NULL } },
{ (PRFuncPtr*) &fGenTextures, { "GenTextures", NULL } },
{ (PRFuncPtr*) &fGetError, { "GetError", NULL } },
{ (PRFuncPtr*) &fGetProgramiv, { "GetProgramiv", "GetProgramivARB", NULL } },
{ (PRFuncPtr*) &fGetProgramInfoLog, { "GetProgramInfoLog", "GetProgramInfoLogARB", NULL } },
{ (PRFuncPtr*) &fTexParameteri, { "TexParameteri", NULL } },
{ (PRFuncPtr*) &fTexParameterf, { "TexParameterf", NULL } },
{ (PRFuncPtr*) &fGetTexParameterfv, { "GetTexParameterfv", NULL } },
{ (PRFuncPtr*) &fGetTexParameteriv, { "GetTexParameteriv", NULL } },
{ (PRFuncPtr*) &fGetUniformfv, { "GetUniformfv", "GetUniformfvARB", NULL } },
{ (PRFuncPtr*) &fGetUniformiv, { "GetUniformiv", "GetUniformivARB", NULL } },
{ (PRFuncPtr*) &fGetUniformLocation, { "GetUniformLocation", "GetUniformLocationARB", NULL } },
{ (PRFuncPtr*) &fGetVertexAttribfv, { "GetVertexAttribfv", "GetVertexAttribfvARB", NULL } },
{ (PRFuncPtr*) &fGetVertexAttribiv, { "GetVertexAttribiv", "GetVertexAttribivARB", NULL } },
{ (PRFuncPtr*) &fHint, { "Hint", NULL } },
{ (PRFuncPtr*) &fIsBuffer, { "IsBuffer", "IsBufferARB", NULL } },
{ (PRFuncPtr*) &fIsEnabled, { "IsEnabled", NULL } },
{ (PRFuncPtr*) &fIsProgram, { "IsProgram", "IsProgramARB", NULL } },
{ (PRFuncPtr*) &fIsShader, { "IsShader", "IsShaderARB", NULL } },
{ (PRFuncPtr*) &fIsTexture, { "IsTexture", "IsTextureARB", NULL } },
{ (PRFuncPtr*) &fLineWidth, { "LineWidth", NULL } },
{ (PRFuncPtr*) &fLinkProgram, { "LinkProgram", "LinkProgramARB", NULL } },
{ (PRFuncPtr*) &fPixelStorei, { "PixelStorei", NULL } },
{ (PRFuncPtr*) &fPolygonOffset, { "PolygonOffset", NULL } },
{ (PRFuncPtr*) &fReadPixels, { "ReadPixels", NULL } },
{ (PRFuncPtr*) &fSampleCoverage, { "SampleCoverage", NULL } },
{ (PRFuncPtr*) &fScissor, { "Scissor", NULL } },
{ (PRFuncPtr*) &fStencilFunc, { "StencilFunc", NULL } },
{ (PRFuncPtr*) &fStencilFuncSeparate, { "StencilFuncSeparate", "StencilFuncSeparateEXT", NULL } },
{ (PRFuncPtr*) &fStencilMask, { "StencilMask", NULL } },
{ (PRFuncPtr*) &fStencilMaskSeparate, { "StencilMaskSeparate", "StencilMaskSeparateEXT", NULL } },
{ (PRFuncPtr*) &fStencilOp, { "StencilOp", NULL } },
{ (PRFuncPtr*) &fStencilOpSeparate, { "StencilOpSeparate", "StencilOpSeparateEXT", NULL } },
{ (PRFuncPtr*) &fTexImage2D, { "TexImage2D", NULL } },
{ (PRFuncPtr*) &fTexSubImage2D, { "TexSubImage2D", NULL } },
{ (PRFuncPtr*) &fUniform1f, { "Uniform1f", NULL } },
{ (PRFuncPtr*) &fUniform1fv, { "Uniform1fv", NULL } },
{ (PRFuncPtr*) &fUniform1i, { "Uniform1i", NULL } },
{ (PRFuncPtr*) &fUniform1iv, { "Uniform1iv", NULL } },
{ (PRFuncPtr*) &fUniform2f, { "Uniform2f", NULL } },
{ (PRFuncPtr*) &fUniform2fv, { "Uniform2fv", NULL } },
{ (PRFuncPtr*) &fUniform2i, { "Uniform2i", NULL } },
{ (PRFuncPtr*) &fUniform2iv, { "Uniform2iv", NULL } },
{ (PRFuncPtr*) &fUniform3f, { "Uniform3f", NULL } },
{ (PRFuncPtr*) &fUniform3fv, { "Uniform3fv", NULL } },
{ (PRFuncPtr*) &fUniform3i, { "Uniform3i", NULL } },
{ (PRFuncPtr*) &fUniform3iv, { "Uniform3iv", NULL } },
{ (PRFuncPtr*) &fUniform4f, { "Uniform4f", NULL } },
{ (PRFuncPtr*) &fUniform4fv, { "Uniform4fv", NULL } },
{ (PRFuncPtr*) &fUniform4i, { "Uniform4i", NULL } },
{ (PRFuncPtr*) &fUniform4iv, { "Uniform4iv", NULL } },
{ (PRFuncPtr*) &fUniformMatrix2fv, { "UniformMatrix2fv", NULL } },
{ (PRFuncPtr*) &fUniformMatrix3fv, { "UniformMatrix3fv", NULL } },
{ (PRFuncPtr*) &fUniformMatrix4fv, { "UniformMatrix4fv", NULL } },
{ (PRFuncPtr*) &fUseProgram, { "UseProgram", NULL } },
{ (PRFuncPtr*) &fValidateProgram, { "ValidateProgram", NULL } },
{ (PRFuncPtr*) &fVertexAttribPointer, { "VertexAttribPointer", NULL } },
{ (PRFuncPtr*) &fVertexAttrib1f, { "VertexAttrib1f", NULL } },
{ (PRFuncPtr*) &fVertexAttrib2f, { "VertexAttrib2f", NULL } },
{ (PRFuncPtr*) &fVertexAttrib3f, { "VertexAttrib3f", NULL } },
{ (PRFuncPtr*) &fVertexAttrib4f, { "VertexAttrib4f", NULL } },
{ (PRFuncPtr*) &fVertexAttrib1fv, { "VertexAttrib1fv", NULL } },
{ (PRFuncPtr*) &fVertexAttrib2fv, { "VertexAttrib2fv", NULL } },
{ (PRFuncPtr*) &fVertexAttrib3fv, { "VertexAttrib3fv", NULL } },
{ (PRFuncPtr*) &fVertexAttrib4fv, { "VertexAttrib4fv", NULL } },
{ (PRFuncPtr*) &fViewport, { "Viewport", NULL } },
{ (PRFuncPtr*) &fCompileShader, { "CompileShader", NULL } },
{ (PRFuncPtr*) &fCopyTexImage2D, { "CopyTexImage2D", NULL } },
{ (PRFuncPtr*) &fCopyTexSubImage2D, { "CopyTexSubImage2D", NULL } },
{ (PRFuncPtr*) &fGetShaderiv, { "GetShaderiv", NULL } },
{ (PRFuncPtr*) &fGetShaderInfoLog, { "GetShaderInfoLog", NULL } },
{ (PRFuncPtr*) &fGetShaderSource, { "GetShaderSource", NULL } },
{ (PRFuncPtr*) &fShaderSource, { "ShaderSource", NULL } },
{ (PRFuncPtr*) &fVertexAttribPointer, { "VertexAttribPointer", NULL } },
{ (PRFuncPtr*) &fBindFramebuffer, { "BindFramebuffer", "BindFramebufferEXT", NULL } },
{ (PRFuncPtr*) &fBindRenderbuffer, { "BindRenderbuffer", "BindRenderbufferEXT", NULL } },
{ (PRFuncPtr*) &fCheckFramebufferStatus, { "CheckFramebufferStatus", "CheckFramebufferStatusEXT", NULL } },
{ (PRFuncPtr*) &fDeleteFramebuffers, { "DeleteFramebuffers", "DeleteFramebuffersEXT", NULL } },
{ (PRFuncPtr*) &fDeleteRenderbuffers, { "DeleteRenderbuffers", "DeleteRenderbuffersEXT", NULL } },
{ (PRFuncPtr*) &fFramebufferRenderbuffer, { "FramebufferRenderbuffer", "FramebufferRenderbufferEXT", NULL } },
{ (PRFuncPtr*) &fFramebufferTexture2D, { "FramebufferTexture2D", "FramebufferTexture2DEXT", NULL } },
{ (PRFuncPtr*) &fGenerateMipmap, { "GenerateMipmap", "GenerateMipmapEXT", NULL } },
{ (PRFuncPtr*) &fGenFramebuffers, { "GenFramebuffers", "GenFramebuffersEXT", NULL } },
{ (PRFuncPtr*) &fGenRenderbuffers, { "GenRenderbuffers", "GenRenderbuffersEXT", NULL } },
{ (PRFuncPtr*) &fGetFramebufferAttachmentParameteriv, { "GetFramebufferAttachmentParameteriv", "GetFramebufferAttachmentParameterivEXT", NULL } },
{ (PRFuncPtr*) &fGetRenderbufferParameteriv, { "GetRenderbufferParameteriv", "GetRenderbufferParameterivEXT", NULL } },
{ (PRFuncPtr*) &fIsFramebuffer, { "IsFramebuffer", "IsFramebufferEXT", NULL } },
{ (PRFuncPtr*) &fIsRenderbuffer, { "IsRenderbuffer", "IsRenderbufferEXT", NULL } },
{ (PRFuncPtr*) &fRenderbufferStorage, { "RenderbufferStorage", "RenderbufferStorageEXT", NULL } },
#if 0
{ (PRFuncPtr*) &fMapBuffer, { "MapBuffer", NULL } },
{ (PRFuncPtr*) &fUnmapBuffer, { "UnmapBuffer", NULL } },
#endif
{ NULL, { NULL } },
};
ok = LoadSymbols(&symbols[0], trygl, prefix);
return ok;
}

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

@ -1,441 +0,0 @@
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
* Mark Steele <mwsteele@gmail.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 GLWRAP_H_
#define GLWRAP_H_
#ifdef WIN32
#include <windows.h>
#endif
#include "localgl.h"
#include "prlink.h"
#ifndef GLAPIENTRY
#ifdef XP_WIN
#define GLAPIENTRY __stdcall
#else
#define GLAPIENTRY
#endif
#define GLAPI
#endif
typedef char realGLboolean;
class LibrarySymbolLoader
{
public:
bool OpenLibrary(const char *library);
typedef PRFuncPtr (GLAPIENTRY * PlatformLookupFunction) (const char *);
void SetLookupFunc(PlatformLookupFunction plf) {
mLookupFunc = plf;
}
enum {
MAX_SYMBOL_NAMES = 5,
MAX_SYMBOL_LENGTH = 128
};
typedef struct {
PRFuncPtr *symPointer;
const char *symNames[MAX_SYMBOL_NAMES];
} SymLoadStruct;
PRFuncPtr LookupSymbol(const char *symname, bool tryplatform = false);
bool LoadSymbols(SymLoadStruct *firstStruct, bool tryplatform = false, const char *prefix = NULL);
protected:
LibrarySymbolLoader() {
mLibrary = NULL;
mLookupFunc = NULL;
}
PRLibrary *mLibrary;
PlatformLookupFunction mLookupFunc;
};
typedef void *PrivateOSMesaContext;
class OSMesaWrap
: public LibrarySymbolLoader
{
public:
OSMesaWrap() : fCreateContextExt(0) { }
bool Init();
protected:
//
// the wrapped functions
//
public:
typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESACREATECONTEXTEXT) (GLenum, GLint, GLint, GLint, PrivateOSMesaContext);
typedef void (GLAPIENTRY * PFNOSMESADESTROYCONTEXT) (PrivateOSMesaContext);
typedef bool (GLAPIENTRY * PFNOSMESAMAKECURRENT) (PrivateOSMesaContext, void *, GLenum, GLsizei, GLsizei);
typedef PrivateOSMesaContext (GLAPIENTRY * PFNOSMESAGETCURRENTCONTEXT) (void);
typedef void (GLAPIENTRY * PFNOSMESAPIXELSTORE) (GLint, GLint);
typedef PRFuncPtr (GLAPIENTRY * PFNOSMESAGETPROCADDRESS) (const char*);
PFNOSMESACREATECONTEXTEXT fCreateContextExt;
PFNOSMESADESTROYCONTEXT fDestroyContext;
PFNOSMESAMAKECURRENT fMakeCurrent;
PFNOSMESAGETCURRENTCONTEXT fGetCurrentContext;
PFNOSMESAPIXELSTORE fPixelStore;
PFNOSMESAGETPROCADDRESS fGetProcAddress;
};
class GLES20Wrap
: public LibrarySymbolLoader
{
public:
enum NativeGLMode {
TRY_NATIVE_GL = 1 << 0,
TRY_SOFTWARE_GL = 1 << 1
};
GLES20Wrap() : ok(false) { }
bool Init(NativeGLMode mode);
protected:
bool ok;
bool InitNative();
bool InitSoftware();
bool InitWithPrefix(const char *prefix, bool trygl );
//
// the wrapped functions
//
public:
/* One would think that this would live in some nice perl-or-python-or-js script somewhere and would be autogenerated;
* one would be wrong.
*/
typedef void (GLAPIENTRY * PFNGLACTIVETEXTUREPROC) (GLenum texture);
PFNGLACTIVETEXTUREPROC fActiveTexture;
typedef void (GLAPIENTRY * PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
PFNGLATTACHSHADERPROC fAttachShader;
typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);
PFNGLBINDATTRIBLOCATIONPROC fBindAttribLocation;
typedef void (GLAPIENTRY * PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
PFNGLBINDBUFFERPROC fBindBuffer;
typedef void (GLAPIENTRY * PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
PFNGLBINDTEXTUREPROC fBindTexture;
typedef void (GLAPIENTRY * PFNGLBLENDCOLORPROC) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
PFNGLBLENDCOLORPROC fBlendColor;
typedef void (GLAPIENTRY * PFNGLBLENDEQUATIONPROC) (GLenum mode);
PFNGLBLENDEQUATIONPROC fBlendEquation;
typedef void (GLAPIENTRY * PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum, GLenum);
PFNGLBLENDEQUATIONSEPARATEPROC fBlendEquationSeparate;
typedef void (GLAPIENTRY * PFNGLBLENDFUNCPROC) (GLenum, GLenum);
PFNGLBLENDFUNCPROC fBlendFunc;
typedef void (GLAPIENTRY * PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
PFNGLBLENDFUNCSEPARATEPROC fBlendFuncSeparate;
typedef void (GLAPIENTRY * PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage);
PFNGLBUFFERDATAPROC fBufferData;
typedef void (GLAPIENTRY * PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data);
PFNGLBUFFERSUBDATAPROC fBufferSubData;
typedef void (GLAPIENTRY * PFNGLCLEARPROC) (GLbitfield);
PFNGLCLEARPROC fClear;
typedef void (GLAPIENTRY * PFNGLCLEARCOLORPROC) (GLclampf, GLclampf, GLclampf, GLclampf);
PFNGLCLEARCOLORPROC fClearColor;
#ifdef USE_GLES2
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHFPROC) (GLclampf);
PFNGLCLEARDEPTHFPROC fClearDepthf;
#else
typedef void (GLAPIENTRY * PFNGLCLEARDEPTHPROC) (GLclampd);
PFNGLCLEARDEPTHPROC fClearDepth;
#endif
typedef void (GLAPIENTRY * PFNGLCLEARSTENCILPROC) (GLint);
PFNGLCLEARSTENCILPROC fClearStencil;
typedef void (GLAPIENTRY * PFNGLCOLORMASKPROC) (realGLboolean red, realGLboolean green, realGLboolean blue, realGLboolean alpha);
PFNGLCOLORMASKPROC fColorMask;
typedef GLuint (GLAPIENTRY * PFNGLCREATEPROGRAMPROC) (void);
PFNGLCREATEPROGRAMPROC fCreateProgram;
typedef GLuint (GLAPIENTRY * PFNGLCREATESHADERPROC) (GLenum type);
PFNGLCREATESHADERPROC fCreateShader;
typedef void (GLAPIENTRY * PFNGLCULLFACEPROC) (GLenum mode);
PFNGLCULLFACEPROC fCullFace;
typedef void (GLAPIENTRY * PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint* buffers);
PFNGLDELETEBUFFERSPROC fDeleteBuffers;
typedef void (GLAPIENTRY * PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint* textures);
PFNGLDELETETEXTURESPROC fDeleteTextures;
typedef void (GLAPIENTRY * PFNGLDELETEPROGRAMPROC) (GLuint program);
PFNGLDELETEPROGRAMPROC fDeleteProgram;
typedef void (GLAPIENTRY * PFNGLDELETESHADERPROC) (GLuint shader);
PFNGLDELETESHADERPROC fDeleteShader;
typedef void (GLAPIENTRY * PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
PFNGLDETACHSHADERPROC fDetachShader;
typedef void (GLAPIENTRY * PFNGLDEPTHFUNCPROC) (GLenum);
PFNGLDEPTHFUNCPROC fDepthFunc;
typedef void (GLAPIENTRY * PFNGLDEPTHMASKPROC) (realGLboolean);
PFNGLDEPTHMASKPROC fDepthMask;
#ifdef USE_GLES2
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEFPROC) (GLclampf, GLclampf);
PFNGLDEPTHRANGEFPROC fDepthRangef;
#else
typedef void (GLAPIENTRY * PFNGLDEPTHRANGEPROC) (GLclampd, GLclampd);
PFNGLDEPTHRANGEPROC fDepthRange;
#endif
typedef void (GLAPIENTRY * PFNGLDISABLEPROC) (GLenum);
PFNGLDISABLEPROC fDisable;
typedef void (GLAPIENTRY * PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint);
PFNGLDISABLEVERTEXATTRIBARRAYPROC fDisableVertexAttribArray;
typedef void (GLAPIENTRY * PFNGLDRAWARRAYSPROC) (GLenum mode, GLint first, GLsizei count);
PFNGLDRAWARRAYSPROC fDrawArrays;
typedef void (GLAPIENTRY * PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
PFNGLDRAWELEMENTSPROC fDrawElements;
typedef void (GLAPIENTRY * PFNGLENABLEPROC) (GLenum);
PFNGLENABLEPROC fEnable;
typedef void (GLAPIENTRY * PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint);
PFNGLENABLEVERTEXATTRIBARRAYPROC fEnableVertexAttribArray;
typedef void (GLAPIENTRY * PFNGLFINISHPROC) (void);
PFNGLFINISHPROC fFinish;
typedef void (GLAPIENTRY * PFNGLFLUSHPROC) (void);
PFNGLFLUSHPROC fFlush;
typedef void (GLAPIENTRY * PFNGLFRONTFACEPROC) (GLenum);
PFNGLFRONTFACEPROC fFrontFace;
typedef void (GLAPIENTRY * PFNGLGETACTIVEATTRIBPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
PFNGLGETACTIVEATTRIBPROC fGetActiveAttrib;
typedef void (GLAPIENTRY * PFNGLGETACTIVEUNIFORMPROC) (GLuint program, GLuint index, GLsizei maxLength, GLsizei* length, GLint* size, GLenum* type, GLchar* name);
PFNGLGETACTIVEUNIFORMPROC fGetActiveUniform;
typedef void (GLAPIENTRY * PFNGLGETATTACHEDSHADERSPROC) (GLuint program, GLsizei maxCount, GLsizei* count, GLuint* shaders);
PFNGLGETATTACHEDSHADERSPROC fGetAttachedShaders;
typedef GLint (GLAPIENTRY * PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar* name);
PFNGLGETATTRIBLOCATIONPROC fGetAttribLocation;
typedef void (GLAPIENTRY * PFNGLGETINTEGERVPROC) (GLenum pname, GLint *params);
PFNGLGETINTEGERVPROC fGetIntegerv;
typedef void (GLAPIENTRY * PFNGLGETFLOATVPROC) (GLenum pname, GLfloat *params);
PFNGLGETFLOATVPROC fGetFloatv;
typedef void (GLAPIENTRY * PFNGLGETBOOLEANBPROC) (GLenum pname, realGLboolean *params);
PFNGLGETBOOLEANBPROC fGetBooleanv;
typedef void (GLAPIENTRY * PFNGLGETBUFFERPARAMETERIVPROC) (GLenum target, GLenum pname, GLint* params);
PFNGLGETBUFFERPARAMETERIVPROC fGetBufferParameteriv;
typedef void (GLAPIENTRY * PFNGLGENBUFFERSPROC) (GLsizei n, GLuint* buffers);
PFNGLGENBUFFERSPROC fGenBuffers;
typedef void (GLAPIENTRY * PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
PFNGLGENTEXTURESPROC fGenTextures;
typedef void (GLAPIENTRY * PFNGLGENERATEMIPMAPPROC) (GLenum target);
PFNGLGENERATEMIPMAPPROC fGenerateMipmap;
typedef GLenum (GLAPIENTRY * PFNGLGETERRORPROC) (void);
PFNGLGETERRORPROC fGetError;
typedef void (GLAPIENTRY * PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint* param);
PFNGLGETPROGRAMIVPROC fGetProgramiv;
typedef void (GLAPIENTRY * PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
PFNGLGETPROGRAMINFOLOGPROC fGetProgramInfoLog;
typedef void (GLAPIENTRY * PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
PFNGLTEXPARAMETERIPROC fTexParameteri;
typedef void (GLAPIENTRY * PFNGLTEXPARAMETERFPROC) (GLenum target, GLenum pname, GLfloat param);
PFNGLTEXPARAMETERFPROC fTexParameterf;
typedef void (GLAPIENTRY * PFNGLGETTEXPARAMETERFVPROC) (GLenum target, GLenum pname, const GLfloat *params);
PFNGLGETTEXPARAMETERFVPROC fGetTexParameterfv;
typedef void (GLAPIENTRY * PFNGLGETTEXPARAMETERIVPROC) (GLenum target, GLenum pname, const GLint *params);
PFNGLGETTEXPARAMETERIVPROC fGetTexParameteriv;
typedef void (GLAPIENTRY * PFNGLGETUNIFORMFVPROC) (GLuint program, GLint location, GLfloat* params);
PFNGLGETUNIFORMFVPROC fGetUniformfv;
typedef void (GLAPIENTRY * PFNGLGETUNIFORMIVPROC) (GLuint program, GLint location, GLint* params);
PFNGLGETUNIFORMIVPROC fGetUniformiv;
typedef GLint (GLAPIENTRY * PFNGLGETUNIFORMLOCATIONPROC) (GLint programObj, const GLchar* name);
PFNGLGETUNIFORMLOCATIONPROC fGetUniformLocation;
typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBFVPROC) (GLuint, GLenum, GLfloat*);
PFNGLGETVERTEXATTRIBFVPROC fGetVertexAttribfv;
typedef void (GLAPIENTRY * PFNGLGETVERTEXATTRIBIVPROC) (GLuint, GLenum, GLint*);
PFNGLGETVERTEXATTRIBIVPROC fGetVertexAttribiv;
typedef void (GLAPIENTRY * PFNGLHINTPROC) (GLenum target, GLenum mode);
PFNGLHINTPROC fHint;
typedef realGLboolean (GLAPIENTRY * PFNGLISBUFFERPROC) (GLuint buffer);
PFNGLISBUFFERPROC fIsBuffer;
typedef realGLboolean (GLAPIENTRY * PFNGLISENABLEDPROC) (GLenum cap);
PFNGLISENABLEDPROC fIsEnabled;
typedef realGLboolean (GLAPIENTRY * PFNGLISPROGRAMPROC) (GLuint program);
PFNGLISPROGRAMPROC fIsProgram;
typedef realGLboolean (GLAPIENTRY * PFNGLISSHADERPROC) (GLuint shader);
PFNGLISSHADERPROC fIsShader;
typedef realGLboolean (GLAPIENTRY * PFNGLISTEXTUREPROC) (GLuint texture);
PFNGLISTEXTUREPROC fIsTexture;
typedef void (GLAPIENTRY * PFNGLLINEWIDTHPROC) (GLfloat width);
PFNGLLINEWIDTHPROC fLineWidth;
typedef void (GLAPIENTRY * PFNGLLINKPROGRAMPROC) (GLuint program);
PFNGLLINKPROGRAMPROC fLinkProgram;
#if 0
typedef void * (GLAPIENTRY * PFNGLMAPBUFFERPROC) (GLenum target, GLenum access);
PFNGLMAPBUFFERPROC fMapBuffer;
typedef realGLboolean (GLAPIENTRY * PFNGLUNAMPBUFFERPROC) (GLenum target);
PFNGLUNAMPBUFFERPROC fUnmapBuffer;
#endif
typedef void (GLAPIENTRY * PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
PFNGLPIXELSTOREIPROC fPixelStorei;
typedef void (GLAPIENTRY * PFNGLPOLYGONOFFSETPROC) (GLfloat factor, GLfloat bias);
PFNGLPOLYGONOFFSETPROC fPolygonOffset;
typedef void (GLAPIENTRY * PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
PFNGLREADPIXELSPROC fReadPixels;
typedef void (GLAPIENTRY * PFNGLSAMPLECOVERAGEPROC) (GLclampf value, realGLboolean invert);
PFNGLSAMPLECOVERAGEPROC fSampleCoverage;
typedef void (GLAPIENTRY * PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
PFNGLSCISSORPROC fScissor;
typedef void (GLAPIENTRY * PFNGLSTENCILFUNCPROC) (GLenum func, GLint ref, GLuint mask);
PFNGLSTENCILFUNCPROC fStencilFunc;
typedef void (GLAPIENTRY * PFNGLSTENCILFUNCSEPARATEPROC) (GLenum frontfunc, GLenum backfunc, GLint ref, GLuint mask);
PFNGLSTENCILFUNCSEPARATEPROC fStencilFuncSeparate;
typedef void (GLAPIENTRY * PFNGLSTENCILMASKPROC) (GLuint mask);
PFNGLSTENCILMASKPROC fStencilMask;
typedef void (GLAPIENTRY * PFNGLSTENCILMASKSEPARATEPROC) (GLenum, GLuint);
PFNGLSTENCILMASKSEPARATEPROC fStencilMaskSeparate;
typedef void (GLAPIENTRY * PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum zpass);
PFNGLSTENCILOPPROC fStencilOp;
typedef void (GLAPIENTRY * PFNGLSTENCILOPSEPARATEPROC) (GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass);
PFNGLSTENCILOPSEPARATEPROC fStencilOpSeparate;
typedef void (GLAPIENTRY * PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
PFNGLTEXIMAGE2DPROC fTexImage2D;
typedef void (GLAPIENTRY * PFNGLTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void* pixels);
PFNGLTEXSUBIMAGE2DPROC fTexSubImage2D;
typedef void (GLAPIENTRY * PFNGLUNIFORM1FPROC) (GLint location, GLfloat v0);
PFNGLUNIFORM1FPROC fUniform1f;
typedef void (GLAPIENTRY * PFNGLUNIFORM1FVPROC) (GLint location, GLsizei count, const GLfloat* value);
PFNGLUNIFORM1FVPROC fUniform1fv;
typedef void (GLAPIENTRY * PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
PFNGLUNIFORM1IPROC fUniform1i;
typedef void (GLAPIENTRY * PFNGLUNIFORM1IVPROC) (GLint location, GLsizei count, const GLint* value);
PFNGLUNIFORM1IVPROC fUniform1iv;
typedef void (GLAPIENTRY * PFNGLUNIFORM2FPROC) (GLint location, GLfloat v0, GLfloat v1);
PFNGLUNIFORM2FPROC fUniform2f;
typedef void (GLAPIENTRY * PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat* value);
PFNGLUNIFORM2FVPROC fUniform2fv;
typedef void (GLAPIENTRY * PFNGLUNIFORM2IPROC) (GLint location, GLint v0, GLint v1);
PFNGLUNIFORM2IPROC fUniform2i;
typedef void (GLAPIENTRY * PFNGLUNIFORM2IVPROC) (GLint location, GLsizei count, const GLint* value);
PFNGLUNIFORM2IVPROC fUniform2iv;
typedef void (GLAPIENTRY * PFNGLUNIFORM3FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
PFNGLUNIFORM3FPROC fUniform3f;
typedef void (GLAPIENTRY * PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat* value);
PFNGLUNIFORM3FVPROC fUniform3fv;
typedef void (GLAPIENTRY * PFNGLUNIFORM3IPROC) (GLint location, GLint v0, GLint v1, GLint v2);
PFNGLUNIFORM3IPROC fUniform3i;
typedef void (GLAPIENTRY * PFNGLUNIFORM3IVPROC) (GLint location, GLsizei count, const GLint* value);
PFNGLUNIFORM3IVPROC fUniform3iv;
typedef void (GLAPIENTRY * PFNGLUNIFORM4FPROC) (GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
PFNGLUNIFORM4FPROC fUniform4f;
typedef void (GLAPIENTRY * PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat* value);
PFNGLUNIFORM4FVPROC fUniform4fv;
typedef void (GLAPIENTRY * PFNGLUNIFORM4IPROC) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
PFNGLUNIFORM4IPROC fUniform4i;
typedef void (GLAPIENTRY * PFNGLUNIFORM4IVPROC) (GLint location, GLsizei count, const GLint* value);
PFNGLUNIFORM4IVPROC fUniform4iv;
typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX2FVPROC) (GLint location, GLsizei count, realGLboolean transpose, const GLfloat* value);
PFNGLUNIFORMMATRIX2FVPROC fUniformMatrix2fv;
typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, realGLboolean transpose, const GLfloat* value);
PFNGLUNIFORMMATRIX3FVPROC fUniformMatrix3fv;
typedef void (GLAPIENTRY * PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, realGLboolean transpose, const GLfloat* value);
PFNGLUNIFORMMATRIX4FVPROC fUniformMatrix4fv;
typedef void (GLAPIENTRY * PFNGLUSEPROGRAMPROC) (GLuint program);
PFNGLUSEPROGRAMPROC fUseProgram;
typedef void (GLAPIENTRY * PFNGLVALIDATEPROGRAMPROC) (GLuint program);
PFNGLVALIDATEPROGRAMPROC fValidateProgram;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, realGLboolean normalized, GLsizei stride, const GLvoid* pointer);
PFNGLVERTEXATTRIBPOINTERPROC fVertexAttribPointer;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FPROC) (GLuint index, GLfloat x);
PFNGLVERTEXATTRIB1FPROC fVertexAttrib1f;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FPROC) (GLuint index, GLfloat x, GLfloat y);
PFNGLVERTEXATTRIB2FPROC fVertexAttrib2f;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z);
PFNGLVERTEXATTRIB3FPROC fVertexAttrib3f;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FPROC) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
PFNGLVERTEXATTRIB4FPROC fVertexAttrib4f;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB1FVPROC) (GLuint index, const GLfloat* v);
PFNGLVERTEXATTRIB1FVPROC fVertexAttrib1fv;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB2FVPROC) (GLuint index, const GLfloat* v);
PFNGLVERTEXATTRIB2FVPROC fVertexAttrib2fv;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB3FVPROC) (GLuint index, const GLfloat* v);
PFNGLVERTEXATTRIB3FVPROC fVertexAttrib3fv;
typedef void (GLAPIENTRY * PFNGLVERTEXATTRIB4FVPROC) (GLuint index, const GLfloat* v);
PFNGLVERTEXATTRIB4FVPROC fVertexAttrib4fv;
typedef void (GLAPIENTRY * PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
PFNGLVIEWPORTPROC fViewport;
typedef void (GLAPIENTRY * PFNGLCOMPILESHADERPROC) (GLuint shader);
PFNGLCOMPILESHADERPROC fCompileShader;
typedef void (GLAPIENTRY * PFNGLCOPYTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
PFNGLCOPYTEXIMAGE2DPROC fCopyTexImage2D;
typedef void (GLAPIENTRY * PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
PFNGLCOPYTEXSUBIMAGE2DPROC fCopyTexSubImage2D;
typedef void (GLAPIENTRY * PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint* param);
PFNGLGETSHADERIVPROC fGetShaderiv;
typedef void (GLAPIENTRY * PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei* length, GLchar* infoLog);
PFNGLGETSHADERINFOLOGPROC fGetShaderInfoLog;
typedef void (GLAPIENTRY * PFNGLGETSHADERSOURCEPROC) (GLint obj, GLsizei maxLength, GLsizei* length, GLchar* source);
PFNGLGETSHADERSOURCEPROC fGetShaderSource;
typedef void (GLAPIENTRY * PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar** strings, const GLint* lengths);
PFNGLSHADERSOURCEPROC fShaderSource;
typedef void (GLAPIENTRY * PFNGLBINDFRAMEBUFFER) (GLenum target, GLuint framebuffer);
PFNGLBINDFRAMEBUFFER fBindFramebuffer;
typedef void (GLAPIENTRY * PFNGLBINDRENDERBUFFER) (GLenum target, GLuint renderbuffer);
PFNGLBINDRENDERBUFFER fBindRenderbuffer;
typedef GLenum (GLAPIENTRY * PFNGLCHECKFRAMEBUFFERSTATUS) (GLenum target);
PFNGLCHECKFRAMEBUFFERSTATUS fCheckFramebufferStatus;
typedef void (GLAPIENTRY * PFNGLDELETEFRAMEBUFFERS) (GLsizei n, const GLuint* ids);
PFNGLDELETEFRAMEBUFFERS fDeleteFramebuffers;
typedef void (GLAPIENTRY * PFNGLDELETERENDERBUFFERS) (GLsizei n, const GLuint* ids);
PFNGLDELETERENDERBUFFERS fDeleteRenderbuffers;
typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERRENDERBUFFER) (GLenum target, GLenum attachmentPoint, GLenum renderbufferTarget, GLuint renderbuffer);
PFNGLFRAMEBUFFERRENDERBUFFER fFramebufferRenderbuffer;
typedef void (GLAPIENTRY * PFNGLFRAMEBUFFERTEXTURE2D) (GLenum target, GLenum attachmentPoint, GLenum textureTarget, GLuint texture, GLint level);
PFNGLFRAMEBUFFERTEXTURE2D fFramebufferTexture2D;
typedef void (GLAPIENTRY * PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIV) (GLenum target, GLenum attachment, GLenum pname, GLint* value);
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIV fGetFramebufferAttachmentParameteriv;
typedef void (GLAPIENTRY * PFNGLGETRENDERBUFFERPARAMETERIV) (GLenum target, GLenum pname, GLint* value);
PFNGLGETRENDERBUFFERPARAMETERIV fGetRenderbufferParameteriv;
typedef void (GLAPIENTRY * PFNGLGENFRAMEBUFFERS) (GLsizei n, GLuint* ids);
PFNGLGENFRAMEBUFFERS fGenFramebuffers;
typedef void (GLAPIENTRY * PFNGLGENRENDERBUFFERS) (GLsizei n, GLuint* ids);
PFNGLGENRENDERBUFFERS fGenRenderbuffers;
typedef realGLboolean (GLAPIENTRY * PFNGLISFRAMEBUFFER) (GLuint framebuffer);
PFNGLISFRAMEBUFFER fIsFramebuffer;
typedef realGLboolean (GLAPIENTRY * PFNGLISRENDERBUFFER) (GLuint renderbuffer);
PFNGLISRENDERBUFFER fIsRenderbuffer;
typedef void (GLAPIENTRY * PFNGLRENDERBUFFERSTORAGE) (GLenum target, GLenum internalFormat, GLsizei width, GLsizei height);
PFNGLRENDERBUFFERSTORAGE fRenderbufferStorage;
};
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -1,141 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 <stdarg.h>
#include "prprf.h"
#include "nsGLPbuffer.h"
#include "nsIConsoleService.h"
#include "nsServiceManagerUtils.h"
#if 0
#include <xmmintrin.h>
#endif
void *nsGLPbuffer::sCurrentContextToken = nsnull;
void
nsGLPbuffer::LogMessage(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char buf[256];
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
if (console) {
PR_vsnprintf(buf, 256, fmt, ap);
console->LogStringMessage(NS_ConvertUTF8toUTF16(nsDependentCString(buf)).get());
fprintf(stderr, "%s\n", buf);
}
va_end(ap);
}
static void
premultiply_slow(unsigned char *src, unsigned int len)
{
int a,t;
for (unsigned int i=0; i<len; i+=4) {
a = src[i+3];
t = src[i]*a+0x80;
src[i] = ((t>>8) + t) >> 8;
t = src[i+1]*a+0x80;
src[i+1] = ((t>>8) + t) >> 8;
t = src[i+2]*a+0x80;
src[i+2] = ((t>>8) + t) >> 8;
}
}
#if 0
static void
premultiply_sse2(__m128i* block, __m128i* block_end)
{
__m128i xmm0080, xmm0101, xmmAlpha, data, dataLo, dataHi, alphaLo, alphaHi;
while (block < block_end) {
xmm0080 = _mm_set1_epi16(0x0080);
xmm0101 = _mm_set1_epi16(0x0101);
xmmAlpha = _mm_set_epi32(0x00ff0000, 0x00000000, 0x00ff0000, 0x00000000);
data = _mm_loadu_si128(block);
dataLo = _mm_unpacklo_epi8 (data, _mm_setzero_si128 ());
dataHi = _mm_unpackhi_epi8 (data, _mm_setzero_si128 ());
alphaLo = _mm_shufflelo_epi16 (dataLo, _MM_SHUFFLE(3, 3, 3, 3));
alphaHi = _mm_shufflelo_epi16 (dataHi, _MM_SHUFFLE(3, 3, 3, 3));
alphaLo = _mm_shufflehi_epi16 (alphaLo, _MM_SHUFFLE(3, 3, 3, 3));
alphaHi = _mm_shufflehi_epi16 (alphaHi, _MM_SHUFFLE(3, 3, 3, 3));
alphaLo = _mm_or_si128(alphaLo, xmmAlpha);
alphaHi = _mm_or_si128(alphaHi, xmmAlpha);
dataLo = _mm_shufflelo_epi16 (dataLo, _MM_SHUFFLE(3, 2, 1, 0));
dataLo = _mm_shufflehi_epi16 (dataLo, _MM_SHUFFLE(3, 2, 1, 0));
dataHi = _mm_shufflelo_epi16 (dataHi, _MM_SHUFFLE(3, 2, 1, 0));
dataHi = _mm_shufflehi_epi16 (dataHi, _MM_SHUFFLE(3, 2, 1, 0));
dataLo = _mm_mullo_epi16(dataLo, alphaLo);
dataHi = _mm_mullo_epi16(dataHi, alphaHi);
dataLo = _mm_adds_epu16(dataLo, xmm0080);
dataHi = _mm_adds_epu16(dataHi, xmm0080);
dataLo = _mm_mulhi_epu16(dataLo, xmm0101);
dataHi = _mm_mulhi_epu16(dataHi, xmm0101);
data = _mm_packus_epi16 (dataLo, dataHi);
_mm_storeu_si128(block, data);
++block;
}
}
#endif
void
nsGLPbuffer::Premultiply(unsigned char *src, unsigned int len)
{
#if 0
if (can_sse2) {
premultiply_sse2((__m128i*)src, (__m128i*)(src+len));
return;
}
#endif
premultiply_slow(src, len);
}

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

@ -1,273 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 NSGLPBUFFER_H_
#define NSGLPBUFFER_H_
#ifdef C3D_STANDALONE_BUILD
#include "c3d-standalone.h"
#endif
#include "nsStringGlue.h"
#include "gfxASurface.h"
#include "gfxImageSurface.h"
#ifdef USE_EGL
typedef int EGLint;
typedef unsigned int EGLBoolean;
typedef unsigned int EGLenum;
typedef void *EGLConfig;
typedef void *EGLContext;
typedef void *EGLDisplay;
typedef void *EGLSurface;
typedef void *EGLClientBuffer;
#endif
#ifdef XP_WIN
#include "gfxWindowsSurface.h"
#endif
#ifdef MOZ_X11
#include "gfxXlibSurface.h"
#endif
#if defined(WINCE) && defined(CAIRO_HAS_DDRAW_SURFACE)
#include "gfxDDrawSurface.h"
#endif
#ifdef USE_GLX
#define GLX_GLXEXT_LEGACY
#include "GL/glx.h"
#endif
#ifdef USE_CGL
#include "gfxQuartzImageSurface.h"
#include <OpenGL/CGLTypes.h>
#endif
#include "glwrap.h"
namespace mozilla {
class WebGLContext;
}
class nsGLPbuffer {
public:
nsGLPbuffer() : mWidth(0), mHeight(0), mPriv(0) { }
virtual ~nsGLPbuffer() { }
virtual PRBool Init(mozilla::WebGLContext *priv) = 0;
virtual PRBool Resize(PRInt32 width, PRInt32 height) = 0;
virtual void Destroy() = 0;
virtual void MakeContextCurrent() = 0;
virtual void SwapBuffers() = 0;
virtual gfxASurface* ThebesSurface() = 0;
PRInt32 Width() { return mWidth; }
PRInt32 Height() { return mHeight; }
GLES20Wrap *GL() { return &mGLWrap; }
protected:
PRInt32 mWidth, mHeight;
GLES20Wrap mGLWrap;
static void *sCurrentContextToken;
mozilla::WebGLContext *mPriv;
void Premultiply(unsigned char *src, unsigned int len);
void LogMessage (const char *fmt, ...);
};
class nsGLPbufferOSMESA :
public nsGLPbuffer
{
public:
nsGLPbufferOSMESA();
virtual ~nsGLPbufferOSMESA();
virtual PRBool Init(mozilla::WebGLContext *priv);
virtual PRBool Resize(PRInt32 width, PRInt32 height);
virtual void Destroy();
virtual void MakeContextCurrent();
virtual void SwapBuffers();
virtual gfxASurface* ThebesSurface();
protected:
nsRefPtr<gfxImageSurface> mThebesSurface;
PrivateOSMesaContext mMesaContext;
};
#ifdef USE_CGL
class nsGLPbufferCGL :
public nsGLPbuffer
{
public:
nsGLPbufferCGL();
virtual ~nsGLPbufferCGL();
virtual PRBool Init(mozilla::WebGLContext *priv);
virtual PRBool Resize(PRInt32 width, PRInt32 height);
virtual void Destroy();
virtual void MakeContextCurrent();
virtual void SwapBuffers();
virtual gfxASurface* ThebesSurface();
CGLPixelFormatObj GetCGLPixelFormat() { return mPixelFormat; }
CGLContextObj GetCGLContext() { return mContext; }
CGLPBufferObj GetCGLPbuffer() { return mPbuffer; }
protected:
CGLPixelFormatObj mPixelFormat;
CGLContextObj mContext;
CGLPBufferObj mPbuffer;
PRBool mImageNeedsUpdate;
nsRefPtr<gfxImageSurface> mThebesSurface;
nsRefPtr<gfxQuartzImageSurface> mQuartzSurface;
typedef void (GLAPIENTRY * PFNGLFLUSHPROC) (void);
PFNGLFLUSHPROC fFlush;
};
#endif
#ifdef USE_GLX
class nsGLPbufferGLX :
public nsGLPbuffer
{
public:
nsGLPbufferGLX();
virtual ~nsGLPbufferGLX();
virtual PRBool Init(mozilla::WebGLContext *priv);
virtual PRBool Resize(PRInt32 width, PRInt32 height);
virtual void Destroy();
virtual void MakeContextCurrent();
virtual void SwapBuffers();
virtual gfxASurface* ThebesSurface();
protected:
nsRefPtr<gfxImageSurface> mThebesSurface;
Display *mDisplay;
GLXFBConfig mFBConfig;
GLXPbuffer mPbuffer;
GLXContext mPbufferContext;
};
#endif
#ifdef USE_EGL
class nsGLPbufferEGL :
public nsGLPbuffer
{
public:
nsGLPbufferEGL();
virtual ~nsGLPbufferEGL();
virtual PRBool Init(mozilla::WebGLContext *priv);
virtual PRBool Resize(PRInt32 width, PRInt32 height);
virtual void Destroy();
virtual void MakeContextCurrent();
virtual void SwapBuffers();
virtual gfxASurface* ThebesSurface();
protected:
EGLDisplay mDisplay;
EGLConfig mConfig;
EGLSurface mSurface;
EGLContext mContext;
#if defined(XP_WIN)
nsRefPtr<gfxImageSurface> mThebesSurface;
nsRefPtr<gfxWindowsSurface> mWindowsSurface;
#elif defined(MOZ_X11)
nsRefPtr<gfxImageSurface> mThebesSurface;
nsRefPtr<gfxXlibSurface> mXlibSurface;
Visual *mVisual;
#endif
};
#endif
#ifdef USE_WGL
class nsGLPbufferWGL :
public nsGLPbuffer
{
public:
nsGLPbufferWGL();
virtual ~nsGLPbufferWGL();
virtual PRBool Init(mozilla::WebGLContext *priv);
virtual PRBool Resize(PRInt32 width, PRInt32 height);
virtual void Destroy();
virtual void MakeContextCurrent();
virtual void SwapBuffers();
virtual gfxASurface* ThebesSurface();
protected:
// this is the crap that we need to get the gl entry points
HWND mGlewWindow;
HDC mGlewDC;
HANDLE mGlewWglContext;
// and this is the actual stuff that we need to render
HANDLE mPbuffer;
HDC mPbufferDC;
HANDLE mPbufferContext;
nsRefPtr<gfxImageSurface> mThebesSurface;
nsRefPtr<gfxWindowsSurface> mWindowsSurface;
};
#endif
#endif /* NSGLPBUFFER_H_ */

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

@ -1,251 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "nsGLPbuffer.h"
#include "WebGLContext.h"
#include <OpenGL/OpenGL.h>
#include "gfxContext.h"
using namespace mozilla;
static PRUint32 gActiveBuffers = 0;
nsGLPbufferCGL::nsGLPbufferCGL()
: mContext(nsnull), mPbuffer(nsnull), fFlush(nsnull)
{
gActiveBuffers++;
fprintf (stderr, "nsGLPbuffer: gActiveBuffers: %d\n", gActiveBuffers);
}
PRBool
nsGLPbufferCGL::Init(WebGLContext *priv)
{
mPriv = priv;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch("extensions.canvas3d.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
PRInt32 prefAntialiasing;
rv = prefBranch->GetIntPref("antialiasing", &prefAntialiasing);
if (NS_FAILED(rv))
prefAntialiasing = 0;
CGLPixelFormatAttribute attrib[] = {
kCGLPFAAccelerated,
kCGLPFAMinimumPolicy,
kCGLPFAPBuffer,
kCGLPFAColorSize, (CGLPixelFormatAttribute) 24,
kCGLPFAAlphaSize, (CGLPixelFormatAttribute) 8,
kCGLPFADepthSize, (CGLPixelFormatAttribute) 8,
(CGLPixelFormatAttribute) 0
};
#if 0
if (false && prefAntialiasing > 0) {
attrib[12] = AGL_SAMPLE_BUFFERS_ARB;
attrib[13] = 1;
attrib[14] = AGL_SAMPLES_ARB;
attrib[15] = 1 << prefAntialiasing;
}
#endif
CGLError err;
GLint npix;
err = CGLChoosePixelFormat(attrib, &mPixelFormat, &npix);
if (err) {
fprintf (stderr, "CGLChoosePixelFormat failed: %d\n", err);
return PR_FALSE;
}
// we need a context for glewInit
Resize(2, 2);
MakeContextCurrent();
if (!mGLWrap.OpenLibrary("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib")) {
LogMessage("Canvas 3D: Failed to open LibGL.dylib (tried system OpenGL.framework)");
return PR_FALSE;
}
if (!mGLWrap.Init(GLES20Wrap::TRY_NATIVE_GL)) {
LogMessage("Canvas 3D: GLWrap init failed");
return PR_FALSE;
}
fFlush = (PFNGLFLUSHPROC) mGLWrap.LookupSymbol("glFlush", true);
return PR_TRUE;
}
PRBool
nsGLPbufferCGL::Resize(PRInt32 width, PRInt32 height)
{
if (mWidth == width &&
mHeight == height)
{
return PR_TRUE;
}
Destroy();
mThebesSurface = nsnull;
mQuartzSurface = nsnull;
CGLError err;
err = CGLCreateContext(mPixelFormat, NULL, &mContext);
if (err) {
fprintf (stderr, "CGLCreateContext failed: %d\n", err);
return PR_FALSE;
}
err = CGLCreatePBuffer(width, height, LOCAL_GL_TEXTURE_RECTANGLE_EXT, LOCAL_GL_RGBA, 0, &mPbuffer);
if (err) {
fprintf (stderr, "CGLCreatePBuffer failed: %d\n", err);
return PR_FALSE;
}
GLint screen;
err = CGLGetVirtualScreen(mContext, &screen);
if (err) {
fprintf (stderr, "CGLGetVirtualScreen failed: %d\n", err);
return PR_FALSE;
}
err = CGLSetPBuffer(mContext, mPbuffer, 0, 0, screen);
if (err) {
fprintf (stderr, "CGLSetPBuffer failed: %d\n", err);
return PR_FALSE;
}
mWidth = width;
mHeight = height;
return PR_TRUE;
}
void
nsGLPbufferCGL::Destroy()
{
sCurrentContextToken = nsnull;
mThebesSurface = nsnull;
if (mContext) {
CGLDestroyContext(mContext);
mContext = nsnull;
}
if (mPbuffer) {
CGLDestroyPBuffer(mPbuffer);
mPbuffer = nsnull;
}
}
nsGLPbufferCGL::~nsGLPbufferCGL()
{
Destroy();
if (mPixelFormat) {
CGLDestroyPixelFormat(mPixelFormat);
mPixelFormat = nsnull;
}
gActiveBuffers--;
fprintf (stderr, "nsGLPbuffer: gActiveBuffers: %d\n", gActiveBuffers);
fflush (stderr);
}
void
nsGLPbufferCGL::MakeContextCurrent()
{
CGLError err = CGLSetCurrentContext (mContext);
if (err) {
fprintf (stderr, "CGLSetCurrentContext failed: %d\n", err);
}
}
void
nsGLPbufferCGL::SwapBuffers()
{
MakeContextCurrent();
// oddly, CGLFlushDrawable() doesn't seem to work, even though it should be calling
// glFlush first.
if (fFlush)
fFlush();
mImageNeedsUpdate = PR_TRUE;
}
gfxASurface*
nsGLPbufferCGL::ThebesSurface()
{
if (!mThebesSurface) {
mThebesSurface = new gfxImageSurface(gfxIntSize(mWidth, mHeight), gfxASurface::ImageFormatARGB32);
if (mThebesSurface->CairoStatus() != 0) {
fprintf (stderr, "image surface failed\n");
mThebesSurface = nsnull;
return nsnull;
}
mQuartzSurface = new gfxQuartzImageSurface(mThebesSurface);
mImageNeedsUpdate = PR_TRUE;
}
if (mImageNeedsUpdate) {
MakeContextCurrent();
mGLWrap.fReadPixels (0, 0, mWidth, mHeight, LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV, mThebesSurface->Data());
mQuartzSurface->Flush();
mImageNeedsUpdate = PR_FALSE;
}
return mQuartzSurface;
}

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

@ -1,497 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 ***** */
// this must be first, else windows.h breaks us
#include "WebGLContext.h"
#include "nsGLPbuffer.h"
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPrefService.h"
#include "gfxContext.h"
#include "glwrap.h"
#ifdef MOZ_X11
#ifdef MOZ_WIDGET_GTK2
#include <gdk/gdkx.h>
#define DISPLAY gdk_x11_get_default_xdisplay
#elif defined(MOZ_WIDGET_QT)
#ifdef CursorShape
#undef CursorShape
#endif
#include <QX11Info>
#define DISPLAY QX11Info::display
#endif
typedef Display* EGLNativeDisplayType;
typedef Window EGLNativeWindowType;
typedef Pixmap EGLNativePixmapType;
#endif
#ifdef WINCE
typedef HDC EGLNativeDisplayType;
typedef HWND EGLNativeWindowType;
typedef HDC EGLNativePixmapType;
#endif
// some EGL defines
#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
#define EGL_NO_CONTEXT ((EGLContext)0)
#define EGL_NO_DISPLAY ((EGLDisplay)0)
#define EGL_NO_SURFACE ((EGLSurface)0)
using namespace mozilla;
static PRUint32 gActiveBuffers = 0;
class EGLWrap
: public LibrarySymbolLoader
{
public:
EGLWrap() : fGetCurrentContext(0) { }
bool Init();
public:
typedef EGLDisplay (*pfnGetDisplay)(void *display_id);
pfnGetDisplay fGetDisplay;
typedef EGLContext (*pfnGetCurrentContext)(void);
pfnGetCurrentContext fGetCurrentContext;
typedef EGLBoolean (*pfnMakeCurrent)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
pfnMakeCurrent fMakeCurrent;
typedef EGLBoolean (*pfnDestroyContext)(EGLDisplay dpy, EGLContext ctx);
pfnDestroyContext fDestroyContext;
typedef EGLContext (*pfnCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);
pfnCreateContext fCreateContext;
typedef EGLBoolean (*pfnDestroySurface)(EGLDisplay dpy, EGLSurface surface);
pfnDestroySurface fDestroySurface;
typedef EGLSurface (*pfnCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list);
pfnCreatePbufferSurface fCreatePbufferSurface;
typedef EGLSurface (*pfnCreatePixmapSurface)(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
pfnCreatePixmapSurface fCreatePixmapSurface;
typedef EGLBoolean (*pfnBindAPI)(EGLenum api);
pfnBindAPI fBindAPI;
typedef EGLBoolean (*pfnInitialize)(EGLDisplay dpy, EGLint *major, EGLint *minor);
pfnInitialize fInitialize;
typedef EGLBoolean (*pfnChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config);
pfnChooseConfig fChooseConfig;
typedef EGLint (*pfnGetError)(void);
pfnGetError fGetError;
typedef EGLBoolean (*pfnGetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value);
pfnGetConfigAttrib fGetConfigAttrib;
typedef EGLBoolean (*pfnGetConfigs)(EGLDisplay dpy, EGLConfig *configs, EGLint config_size, EGLint *num_config);
pfnGetConfigs fGetConfigs;
typedef EGLBoolean (*pfnWaitNative)(EGLint engine);
pfnWaitNative fWaitNative;
};
bool
EGLWrap::Init()
{
if (fGetDisplay)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fGetDisplay, { "eglGetDisplay", NULL } },
{ (PRFuncPtr*) &fGetCurrentContext, { "eglGetCurrentContext", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "eglMakeCurrent", NULL } },
{ (PRFuncPtr*) &fDestroyContext, { "eglDestroyContext", NULL } },
{ (PRFuncPtr*) &fCreateContext, { "eglCreateContext", NULL } },
{ (PRFuncPtr*) &fDestroySurface, { "eglDestroySurface", NULL } },
{ (PRFuncPtr*) &fCreatePbufferSurface, { "eglCreatePbufferSurface", NULL } },
{ (PRFuncPtr*) &fCreatePixmapSurface, { "eglCreatePixmapSurface", NULL } },
{ (PRFuncPtr*) &fBindAPI, { "eglBindAPI", NULL } },
{ (PRFuncPtr*) &fInitialize, { "eglInitialize", NULL } },
{ (PRFuncPtr*) &fChooseConfig, { "eglChooseConfig", NULL } },
{ (PRFuncPtr*) &fGetError, { "eglGetError", NULL } },
{ (PRFuncPtr*) &fGetConfigs, { "eglGetConfigs", NULL } },
{ (PRFuncPtr*) &fGetConfigAttrib, { "eglGetConfigAttrib", NULL } },
{ (PRFuncPtr*) &fWaitNative, { "eglWaitNative", NULL } },
{ NULL, { NULL } }
};
return LoadSymbols(&symbols[0], true);
}
static EGLWrap gEGLWrap;
nsGLPbufferEGL::nsGLPbufferEGL()
: mDisplay(0), mConfig(0), mSurface(0)
{
gActiveBuffers++;
}
#ifdef WINCE
// XXX wrong
#define EGL_LIB "\\windows\\libEGL.dll"
#define GLES2_LIB "\\windows\\libGLESv2.dll"
#else
#define EGL_LIB "/usr/lib/libEGL.so"
#define GLES2_LIB "/usr/lib/libGLESv2.so"
#endif
PRBool
nsGLPbufferEGL::Init(mozilla::WebGLContext *priv)
{
mPriv = priv;
#ifdef MOZ_PLATFORM_MAEMO
// Maemo has missing DSO dependencies on their OpenGL libraries;
// so ensure that the prerequisite libs are loaded in the process
// before loading GL. An alternate approach is to use LD_PRELOAD.
// We'll just leak these libs; pvr_um.so seems to have been
// present on an older OS image, and now pvr2d.so is used.
PRLibSpec lspec;
lspec.type = PR_LibSpec_Pathname;
lspec.value.pathname = "/usr/lib/libpvr_um.so";
PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_GLOBAL);
lspec.value.pathname = "/usr/lib/libpvr2d.so";
PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_GLOBAL);
#endif
if (!gEGLWrap.OpenLibrary(EGL_LIB)) {
LogMessage("egl OpenLibrary failed");
return PR_FALSE;
}
if (!gEGLWrap.Init()) {
LogMessage("eglWrap init failed");
return PR_FALSE;
}
mDisplay = gEGLWrap.fGetDisplay(0);
if (!gEGLWrap.fInitialize(mDisplay, NULL, NULL)) {
LogMessage("egl init failed");
return PR_FALSE;
}
gEGLWrap.fBindAPI (EGL_OPENGL_ES_API);
#if defined(MOZ_X11) && defined(MOZ_PLATFORM_MAEMO)
EGLint attribs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_PIXMAP_BIT,
EGL_RED_SIZE, 3,
EGL_GREEN_SIZE, 3,
EGL_BLUE_SIZE, 3,
EGL_ALPHA_SIZE, 3,
EGL_DEPTH_SIZE, 1,
EGL_NONE
};
EGLint ncfg = 0;
EGLConfig cfg;
if (!gEGLWrap.fChooseConfig(mDisplay, attribs, &cfg, 1, &ncfg) ||
ncfg < 1)
{
LogMessage("Canvas 3D: eglChooseConfig failed (ncfg: %d err: 0x%04x)", ncfg, gEGLWrap.fGetError());
return PR_FALSE;
}
EGLint visid;
gEGLWrap.fGetConfigAttrib(mDisplay, cfg, EGL_NATIVE_VISUAL_ID, &visid);
XVisualInfo vinfo;
vinfo.visualid = visid;
int pad;
LogMessage("Visual ID: %d\n", visid);
XVisualInfo *vf = XGetVisualInfo(DISPLAY(), VisualIDMask, &vinfo, &pad);
if (!vf) {
LogMessage("Null VisualInfo!");
return PR_FALSE;
}
LogMessage("Visual: 0x%08x\n", vf->visual);
mVisual = vf->visual;
mConfig = cfg;
#elif defined(WINCE)
#define MAX_CONFIGS 32
EGLConfig configs[MAX_CONFIGS];
EGLint numConfigs;
gEGLWrap.fGetConfigs(mDisplay, configs, MAX_CONFIGS, &numConfigs);
mConfig = 0;
for (int i = 0; i < numConfigs; ++i) {
EGLint id;
EGLint surfaces, renderables;
EGLint rsize, gsize, bsize, asize, dsize;
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_CONFIG_ID, &id);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_SURFACE_TYPE, &surfaces);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_RENDERABLE_TYPE, &renderables);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_RED_SIZE, &rsize);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_GREEN_SIZE, &gsize);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_BLUE_SIZE, &bsize);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_ALPHA_SIZE, &asize);
gEGLWrap.fGetConfigAttrib(mDisplay, configs[i], EGL_DEPTH_SIZE, &dsize);
#ifdef DEBUG_vladimir
fprintf(stderr, "config 0x%02x: s %x api %x rgba %d %d %d %d d %d\n", id, surfaces, renderables, rsize, gsize, bsize, asize, dsize);
#endif
if ((surfaces & EGL_PBUFFER_BIT) &&
(renderables & EGL_OPENGL_ES2_BIT) &&
(rsize > 3) &&
(gsize > 3) &&
(bsize > 3) &&
(asize > 3) &&
(dsize > 1))
{
mConfig = configs[i];
break;
}
}
if (mConfig == 0) {
LogMessage("Failed to find config!");
return PR_FALSE;
}
#else
#error need some boilerplate code for EGL
#endif
LogMessage("Resize 2,2");
Resize(2, 2);
LogMessage("OpenLibrary");
if (!mGLWrap.OpenLibrary(GLES2_LIB)) {
LogMessage("Canvas 3D: Couldn't open EGL lib [1]");
return PR_FALSE;
}
LogMessage("GLWrap.Init");
if (!mGLWrap.Init(GLES20Wrap::TRY_NATIVE_GL)) {
LogMessage("Canvas 3D: GLWrap init failed");
return PR_FALSE;
}
LogMessage("Init done");
return PR_TRUE;
}
PRBool
nsGLPbufferEGL::Resize(PRInt32 width, PRInt32 height)
{
if (mWidth == width &&
mHeight == height)
{
return PR_TRUE;
}
LogMessage("Resize %d %d start", width, height);
Destroy();
LogMessage("Destroyed");
#ifdef XP_WIN
mWindowsSurface = new gfxWindowsSurface(gfxIntSize(width, height),
gfxASurface::ImageFormatARGB32);
if (mWindowsSurface->CairoStatus() != 0) {
#ifdef DEBUG_vladimir
fprintf (stderr, "image surface failed\n");
#endif
return PR_FALSE;
}
mThebesSurface = mWindowsSurface->GetImageSurface();
EGLint attrs[] = {
EGL_WIDTH, width,
EGL_HEIGHT, height,
EGL_NONE
};
mSurface = gEGLWrap.fCreatePbufferSurface(mDisplay, mConfig, attrs);
if (!mSurface) {
LogMessage("Canvas 3D: eglCreatePbufferSurface failed");
return PR_FALSE;
}
#else
mXlibSurface = new gfxXlibSurface(DISPLAY(),
mVisual,
gfxIntSize(width, height),
32);
if (!mXlibSurface || mXlibSurface->CairoStatus() != 0) {
#ifdef DEBUG_vladimir
fprintf (stderr, "Failed to create gfxXlibSurface");
#endif
return PR_FALSE;
}
LogMessage("Created gfxXlibSurface, Drawable: 0x%08x", mXlibSurface->XDrawable());
// we need to XSync to ensure that the Pixmap is created on the server side,
// otherwise eglCreatePixmapSurface will fail (because it isn't part of the normal
// X protocol).
XSync(DISPLAY(), 0);
EGLint attrs[] = {
EGL_NONE
};
Pixmap px = (Pixmap) mXlibSurface->XDrawable();
mSurface = gEGLWrap.fCreatePixmapSurface(mDisplay, mConfig, (EGLNativePixmapType) px, attrs);
if (!mSurface) {
#ifdef DEBUG_vladimir
fprintf (stderr, "Failed to create Pixmap EGLSurface\n");
#endif
return PR_FALSE;
}
LogMessage("mSurface: %p", mSurface);
#endif
gEGLWrap.fBindAPI(EGL_OPENGL_ES_API);
EGLint cxattrs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
mContext = gEGLWrap.fCreateContext(mDisplay, mConfig, EGL_NO_CONTEXT, cxattrs);
if (!mContext) {
Destroy();
return PR_FALSE;
}
mWidth = width;
mHeight = height;
#ifdef MOZ_X11
mThebesSurface = new gfxImageSurface(gfxIntSize(width, height), gfxASurface::ImageFormatARGB32);
#endif
return PR_TRUE;
}
void
nsGLPbufferEGL::Destroy()
{
if (mContext) {
gEGLWrap.fDestroyContext(mDisplay, mContext);
mContext = 0;
}
if (mSurface) {
gEGLWrap.fDestroySurface(mDisplay, mSurface);
mSurface = 0;
}
sCurrentContextToken = nsnull;
// leak this
#ifdef MOZ_X11
NS_IF_ADDREF(mXlibSurface.get());
mXlibSurface = nsnull;
#else
mWindowsSurface = nsnull;
#endif
mThebesSurface = nsnull;
}
nsGLPbufferEGL::~nsGLPbufferEGL()
{
Destroy();
gActiveBuffers--;
fflush (stderr);
}
void
nsGLPbufferEGL::MakeContextCurrent()
{
if (gEGLWrap.fGetCurrentContext() == mContext)
return;
gEGLWrap.fMakeCurrent(mDisplay, mSurface, mSurface, mContext);
}
void
nsGLPbufferEGL::SwapBuffers()
{
// eglCopyBuffers(mDisplay, mSurface, mWindowsSurface->GetDC());
MakeContextCurrent();
//printf ("SwapBuffers0: %04x\n", mGLWrap.fGetError());
// this is wrong, we need to figure out a way to swap this, but we don't do anything here
mGLWrap.fFinish ();
mGLWrap.fReadPixels (0, 0, mWidth, mHeight, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, mThebesSurface->Data());
//printf ("SwapBuffers: %04x\n", mGLWrap.fGetError());
#if 0
// premultiply the image
int len = mWidth*mHeight*4;
unsigned char *src = mThebesSurface->Data();
Premultiply(src, len);
#endif
}
gfxASurface*
nsGLPbufferEGL::ThebesSurface()
{
#if defined(MOZ_X11) && defined(MOZ_PLATFORM_MAEMO)
if (getenv("IMAGE"))
return mThebesSurface;
return mXlibSurface;
#elif defined(WINCE)
return mThebesSurface;
#endif
}

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

@ -1,343 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 ***** */
// this must be first, else windows.h breaks us
#include "nsICanvasRenderingContextWebGL.h"
#include "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "glwrap.h"
#include "nsGLPbuffer.h"
#include "WebGLContext.h"
#include "gfxContext.h"
using namespace mozilla;
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_X11)
#include <gdk/gdkx.h>
#endif
static PRUint32 gActiveBuffers = 0;
class GLXWrap
: public LibrarySymbolLoader
{
public:
GLXWrap() : fCreateNewContext(0) { }
bool Init();
protected:
//
// the wrapped functions
//
public:
typedef PRFuncPtr (* PFNGLXGETPROCADDRESS) (const GLubyte *procName);
PFNGLXGETPROCADDRESS fGetProcAddress;
typedef GLXContext (* PFNGLXCREATENEWCONTEXTPROC) (Display *dpy, GLXFBConfig config, int render_type, GLXContext share_list, Bool direct);
PFNGLXCREATENEWCONTEXTPROC fCreateNewContext;
typedef XVisualInfo* (* PFNGLXCHOOSEVISUALPROC) (Display *dpy, int scrnum, int *attrib);
PFNGLXCHOOSEVISUALPROC fChooseVisual;
typedef GLXContext (* PFNGLXCREATECONTEXTPROC) (Display *dpy, XVisualInfo *visinfo, GLXContext share_list, Bool direct);
PFNGLXCREATECONTEXTPROC fCreateContext;
typedef GLXPbuffer (* PFNGLXCREATEPBUFFERPROC) (Display *dpy, GLXFBConfig config, const int *attrib_list);
PFNGLXCREATEPBUFFERPROC fCreatePbuffer;
typedef void (* PFNGLXDESTROYCONTEXTPROC) (Display *dpy, GLXContext ctx);
PFNGLXDESTROYCONTEXTPROC fDestroyContext;
typedef void (* PFNGLXDESTROYPBUFFERPROC) (Display *dpy, GLXPbuffer pbuf);
PFNGLXDESTROYPBUFFERPROC fDestroyPbuffer;
typedef GLXFBConfig* (* PFNGLXCHOOSEFBCONFIGPROC) (Display *dpy, int screen, const int *attrib_list, int *nelements);
PFNGLXCHOOSEFBCONFIGPROC fChooseFBConfig;
typedef Bool (* PFNGLXMAKECONTEXTCURRENTPROC) (Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx);
PFNGLXMAKECONTEXTCURRENTPROC fMakeContextCurrent;
typedef GLXContext (* PFNGLXGETCURRENTCONTEXTPROC) ( void );
PFNGLXGETCURRENTCONTEXTPROC fGetCurrentContext;
typedef const char* (* PFNGLXQUERYEXTENSIONSSTRING) (Display *dpy, int screen);
PFNGLXQUERYEXTENSIONSSTRING fQueryExtensionsString;
typedef const char* (* PFNGLXQUERYSERVERSTRING) (Display *dpy, int screen, int name);
PFNGLXQUERYSERVERSTRING fQueryServerString;
};
bool
GLXWrap::Init()
{
if (fCreateNewContext)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fGetProcAddress, { "glXGetProcAddress", "glXGetProcAddressARB", NULL } },
{ (PRFuncPtr*) &fCreateNewContext, { "glXCreateNewContext", NULL } },
{ (PRFuncPtr*) &fCreateContext, { "glXCreateContext", NULL } },
{ (PRFuncPtr*) &fChooseVisual, { "glXChooseVisual", NULL } },
{ (PRFuncPtr*) &fCreatePbuffer, { "glXCreatePbuffer", NULL } },
{ (PRFuncPtr*) &fDestroyContext, { "glXDestroyContext", NULL } },
{ (PRFuncPtr*) &fDestroyPbuffer, { "glXDestroyPbuffer", NULL } },
{ (PRFuncPtr*) &fChooseFBConfig, { "glXChooseFBConfig", NULL } },
{ (PRFuncPtr*) &fMakeContextCurrent, { "glXMakeContextCurrent", NULL } },
{ (PRFuncPtr*) &fGetCurrentContext, { "glXGetCurrentContext", NULL } },
{ (PRFuncPtr*) &fQueryExtensionsString, { "glXQueryExtensionsString", NULL } },
{ (PRFuncPtr*) &fQueryServerString, { "glXQueryServerString", NULL } },
{ NULL, { NULL } }
};
return LoadSymbols(&symbols[0]);
}
static GLXWrap gGLXWrap;
nsGLPbufferGLX::nsGLPbufferGLX()
: mDisplay(nsnull), mFBConfig(0), mPbuffer(0), mPbufferContext(0)
{
gActiveBuffers++;
fprintf (stderr, "nsGLPbufferGLX: gActiveBuffers: %d\n", gActiveBuffers);
}
PRBool
nsGLPbufferGLX::Init(WebGLContext *priv)
{
nsresult rv;
const char *s;
if (!gGLXWrap.OpenLibrary("libGL.so.1")) {
LogMessage("Canvas 3D: Couldn't find libGL.so.1");
return PR_FALSE;
}
if (!gGLXWrap.Init()) {
LogMessage("Canvas 3D: gGLXWrap.Init() failed");
return PR_FALSE;
}
#if defined(MOZ_WIDGET_GTK2) && defined(MOZ_X11)
mDisplay = gdk_x11_get_default_xdisplay();
#else
mDisplay = XOpenDisplay(NULL);
#endif
if (!mDisplay) {
LogMessage("Canvas 3D: XOpenDisplay failed");
return PR_FALSE;
}
// Make sure that everyone agrees that pbuffers are supported
s = gGLXWrap.fQueryExtensionsString(mDisplay, DefaultScreen(mDisplay));
if (!s || strstr(s, "GLX_SGIX_pbuffer") == NULL) {
LogMessage("Canvas 3D: GLX_SGIX_pbuffer not supported");
return PR_FALSE;
}
s = gGLXWrap.fQueryServerString(mDisplay, DefaultScreen(mDisplay), GLX_EXTENSIONS);
if (!s || strstr(s, "GLX_SGIX_pbuffer") == NULL) {
LogMessage("Canvas 3D: GLX_SGIX_pbuffer not supported by server");
return PR_FALSE;
}
mPriv = priv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch("extensions.canvas3d.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
PRInt32 prefAntialiasing;
rv = prefBranch->GetIntPref("antialiasing", &prefAntialiasing);
if (NS_FAILED(rv))
prefAntialiasing = 0;
int attrib[] = { GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_ALPHA_SIZE, 1,
GLX_DEPTH_SIZE, 1,
GLX_SAMPLE_BUFFERS, 1,
GLX_SAMPLES, 1 << prefAntialiasing,
None };
if (prefAntialiasing <= 0)
attrib[16] = 0;
int num;
GLXFBConfig *configs = gGLXWrap.fChooseFBConfig(mDisplay, DefaultScreen(mDisplay),
attrib, &num);
fprintf(stderr, "CANVAS3D FBCONFIG: %d %p\n", num, (void*) configs);
if (!configs) {
LogMessage("Canvas 3D: No GLXFBConfig found");
return PR_FALSE;
}
// choose first matching config;
mFBConfig = *configs;
XFree(configs);
mPbufferContext = gGLXWrap.fCreateNewContext(mDisplay, mFBConfig, GLX_RGBA_TYPE,
nsnull, True);
PRInt64 t1 = PR_Now();
Resize(2, 2);
MakeContextCurrent();
PRInt64 t2 = PR_Now();
fprintf (stderr, "nsGLPbufferGLX::Init!\n");
if (!mGLWrap.OpenLibrary("libGL.so.1")) {
LogMessage("Canvas 3D: GLWrap init failed, couldn't find libGL.so.1");
return PR_FALSE;
}
mGLWrap.SetLookupFunc((LibrarySymbolLoader::PlatformLookupFunction) gGLXWrap.fGetProcAddress);
if (!mGLWrap.Init(GLES20Wrap::TRY_NATIVE_GL)) {
LogMessage("Canvas 3D: GLWrap init failed");
return PR_FALSE;
}
PRInt64 t3 = PR_Now();
fprintf (stderr, "nsGLPbufferGLX:: Initialization took t2-t1: %f t3-t2: %f\n",
((double)(t2-t1))/1000.0, ((double)(t3-t2))/1000.0);
fflush (stderr);
return PR_TRUE;
}
PRBool
nsGLPbufferGLX::Resize(PRInt32 width, PRInt32 height)
{
if (mWidth == width &&
mHeight == height)
{
return PR_TRUE;
}
Destroy();
mThebesSurface = new gfxImageSurface(gfxIntSize(width, height), gfxASurface::ImageFormatARGB32);
if (mThebesSurface->CairoStatus() != 0) {
fprintf (stderr, "image surface failed\n");
return PR_FALSE;
}
// clear the surface
memset (mThebesSurface->Data(),
0,
height * mThebesSurface->Stride());
int attrib[] = { GLX_PBUFFER_WIDTH, width,
GLX_PBUFFER_HEIGHT, height,
None };
mPbuffer = gGLXWrap.fCreatePbuffer(mDisplay, mFBConfig, attrib);
gGLXWrap.fMakeContextCurrent(mDisplay, mPbuffer, mPbuffer, mPbufferContext);
mWidth = width;
mHeight = height;
fprintf (stderr, "Resize: %d %d\n", width, height);
return PR_TRUE;
}
void
nsGLPbufferGLX::Destroy()
{
sCurrentContextToken = nsnull;
mThebesSurface = nsnull;
if (mPbuffer) {
gGLXWrap.fDestroyPbuffer(mDisplay, mPbuffer);
mPbuffer = nsnull;
}
}
nsGLPbufferGLX::~nsGLPbufferGLX()
{
MakeContextCurrent();
#ifndef GL_FRAMEBUFFER
#define GL_FRAMEBUFFER 0x8D40
#endif
// workaround for segfault on glXDestroyContext
mGLWrap.fBindFramebuffer(GL_FRAMEBUFFER, 0);
Destroy();
if (mPbuffer)
gGLXWrap.fDestroyPbuffer(mDisplay, mPbuffer);
if (mPbufferContext)
gGLXWrap.fDestroyContext(mDisplay, mPbufferContext);
#if !(defined(MOZ_WIDGET_GTK2) && defined(MOZ_X11))
if (mDisplay)
XCloseDisplay(mDisplay);
#endif
gActiveBuffers--;
fprintf (stderr, "nsGLPbufferGLX: gActiveBuffers: %d\n", gActiveBuffers);
fflush (stderr);
}
void
nsGLPbufferGLX::MakeContextCurrent()
{
if (gGLXWrap.fGetCurrentContext() != mPbufferContext)
gGLXWrap.fMakeContextCurrent(mDisplay, mPbuffer, mPbuffer, mPbufferContext);
}
void
nsGLPbufferGLX::SwapBuffers()
{
MakeContextCurrent();
mGLWrap.fReadPixels (0, 0, mWidth, mHeight, LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV, mThebesSurface->Data());
unsigned int len = mWidth*mHeight*4;
unsigned char *src = mThebesSurface->Data();
// Premultiply the image
// XXX don't do this if we're known opaque
Premultiply(src, len);
}
gfxASurface*
nsGLPbufferGLX::ThebesSurface()
{
return mThebesSurface;
}

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

@ -1,254 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 ***** */
// this must be first, else windows.h breaks us
#include "nsDirectoryServiceUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIPrefService.h"
#include "glwrap.h"
#include "nsGLPbuffer.h"
#include "gfxContext.h"
#include "gfxImageSurface.h"
using namespace mozilla;
#if 0
#include <GL/osmesa.h>
#else
#define OSMESA_RGBA GL_RGBA
#define OSMESA_BGRA 0x1
#define OSMESA_ARGB 0x2
#define OSMESA_Y_UP 0x11
#endif
static OSMesaWrap gMesaWrap;
static PRUint32 gActiveBuffers = 0;
nsGLPbufferOSMESA::nsGLPbufferOSMESA()
: mMesaContext(nsnull)
{
gActiveBuffers++;
fprintf (stderr, "nsGLPbufferOSMESA: gActiveBuffers: %d\n", gActiveBuffers);
}
PRBool
nsGLPbufferOSMESA::Init(WebGLContext *priv)
{
mPriv = priv;
nsresult rv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch("webgl.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCString osmesalib;
rv = prefBranch->GetCharPref("osmesalib", getter_Copies(osmesalib));
#if 0
if (NS_FAILED(rv)) {
osmesalib.Truncate();
// try our default; build it from the profile dir
nsCOMPtr<nsIFile> libfile;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(libfile));
if (NS_FAILED(rv)) {
fprintf (stderr, "NS_GetSpecialDirectory failed?\n");
return rv;
}
// XXX this makes assumptions about the ID of this extension
rv |= libfile->Append(NS_LITERAL_STRING("extensions"));
rv |= libfile->Append(NS_LITERAL_STRING("canvas3d@mozilla.com"));
rv |= libfile->Append(NS_LITERAL_STRING("platform"));
#if defined(XP_WIN)
rv |= libfile->Append(NS_LITERAL_STRING("WINNT"));
rv |= libfile->Append(NS_LITERAL_STRING("osmesa32.dll"));
#elif defined(XP_MACOSX)
rv |= libfile->Append(NS_LITERAL_STRING("Darwin"));
rv |= libfile->Append(NS_LITERAL_STRING("libOSMesa.7.dylib"));
#elif defined(XP_UNIX)
rv |= libfile->Append(NS_LITERAL_STRING("Linux"));
rv |= libfile->Append(NS_LITERAL_STRING("libOSMesa.so.7"));
#else
#warning No default osmesa library path available
LogMessage("Canvas 3D: No default OSMesa lib path available -- please set the extensions.canvas3d.osmesalib pref to the full path to the OSMesa shared library");
rv = NS_ERROR_FAILURE;
#endif
if (NS_FAILED(rv))
return PR_FALSE;
PRBool exists = PR_FALSE;
rv = libfile->Exists(&exists);
if (NS_FAILED(rv) || !exists) {
LogMessage("Canvas 3D: Couldn't find OSMesa lib -- either default or extension.canvas3d.osmesalib path is incorrect");
return PR_FALSE;
}
// I'm told by the comments in nsIFile that I'm not supposed to do this. Noted.
rv = libfile->GetNativeTarget(osmesalib);
if (NS_FAILED(rv)) {
LogMessage("Canvas 3D: Couldn't find OSMesa lib");
return PR_FALSE;
}
}
#endif
if (NS_FAILED(rv) ||
osmesalib.Length() == 0 ||
!gMesaWrap.OpenLibrary(osmesalib.get()))
{
LogMessage("Canvas 3D: Couldn't open OSMesa lib -- webgl.osmesalib path is incorrect, or not a valid shared library");
return PR_FALSE;
}
if (!gMesaWrap.Init())
return PR_FALSE;
PRInt32 prefAntialiasing;
rv = prefBranch->GetIntPref("antialiasing", &prefAntialiasing);
if (NS_FAILED(rv))
prefAntialiasing = 0;
Resize (2, 2);
if (!mGLWrap.OpenLibrary(osmesalib.get())) {
LogMessage("Canvas 3D: Couldn't open OSMesa lib [1]");
return PR_FALSE;
}
mGLWrap.SetLookupFunc((LibrarySymbolLoader::PlatformLookupFunction) gMesaWrap.fGetProcAddress);
if (!mGLWrap.Init(GLES20Wrap::TRY_SOFTWARE_GL)) {
LogMessage("Canvas 3D: GLWrap init failed");
return PR_FALSE;
}
return PR_TRUE;
}
PRBool
nsGLPbufferOSMESA::Resize(PRInt32 width, PRInt32 height)
{
if (mWidth == width &&
mHeight == height)
{
return PR_TRUE;
}
Destroy();
mThebesSurface = new gfxImageSurface(gfxIntSize(width, height),
gfxASurface::ImageFormatARGB32);
if (mThebesSurface->CairoStatus() != 0) {
fprintf (stderr, "image surface failed\n");
return PR_FALSE;
}
mMesaContext = gMesaWrap.fCreateContextExt (OSMESA_BGRA, 16, 0, 0, NULL);
if (!mMesaContext) {
fprintf (stderr, "OSMesaCreateContextExt failed!\n");
return PR_FALSE;
}
fprintf (stderr, "Surface: %p\n", mThebesSurface->Data());
if (!gMesaWrap.fMakeCurrent (mMesaContext, mThebesSurface->Data(), LOCAL_GL_UNSIGNED_BYTE, width, height))
{
fprintf (stderr, "OSMesaMakeCurrent failed!\n");
return PR_FALSE;
}
gMesaWrap.fPixelStore (OSMESA_Y_UP, 1);
mWidth = width;
mHeight = height;
fprintf (stderr, "Resize: %d %d\n", width, height);
return PR_TRUE;
}
void
nsGLPbufferOSMESA::Destroy()
{
if (mMesaContext) {
gMesaWrap.fDestroyContext (mMesaContext);
mMesaContext = 0;
}
sCurrentContextToken = nsnull;
mThebesSurface = nsnull;
}
nsGLPbufferOSMESA::~nsGLPbufferOSMESA()
{
Destroy();
gActiveBuffers--;
fprintf (stderr, "nsGLPbufferOSMESA: gActiveBuffers: %d\n", gActiveBuffers);
fflush (stderr);
}
void
nsGLPbufferOSMESA::MakeContextCurrent()
{
if (gMesaWrap.fGetCurrentContext() == mMesaContext)
return;
gMesaWrap.fMakeCurrent (mMesaContext, mThebesSurface->Data(), LOCAL_GL_UNSIGNED_BYTE, mWidth, mHeight);
}
void
nsGLPbufferOSMESA::SwapBuffers()
{
// Nothing; we're already rendering to an image
}
gfxASurface*
nsGLPbufferOSMESA::ThebesSurface()
{
return mThebesSurface;
}

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

@ -1,455 +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.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
*
* 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 "nsIPrefService.h"
#include "nsServiceManagerUtils.h"
#include "WebGLContext.h"
#include "nsGLPbuffer.h"
#include "gfxContext.h"
#include "gfxImageSurface.h"
using namespace mozilla;
static PRUint32 gActiveBuffers = 0;
class WGLWrap
: public LibrarySymbolLoader
{
public:
WGLWrap() : fCreatePbuffer(0) { }
bool InitEarly();
bool Init();
public:
// early init
typedef HANDLE (WINAPI * PFNWGLCREATECONTEXTPROC) (HDC hDC);
PFNWGLCREATECONTEXTPROC fCreateContext;
typedef BOOL (WINAPI * PFNWGLMAKECURRENTPROC) (HDC hDC, HANDLE hglrc);
PFNWGLMAKECURRENTPROC fMakeCurrent;
typedef PROC (WINAPI * PFNWGLGETPROCADDRESSPROC) (LPCSTR proc);
PFNWGLGETPROCADDRESSPROC fGetProcAddress;
typedef BOOL (WINAPI * PFNWGLDELETECONTEXTPROC) (HANDLE hglrc);
PFNWGLDELETECONTEXTPROC fDeleteContext;
typedef HANDLE (WINAPI * PFNWGLCREATEPBUFFERPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int* piAttribList);
PFNWGLCREATEPBUFFERPROC fCreatePbuffer;
typedef BOOL (WINAPI * PFNWGLDESTROYPBUFFERPROC) (HANDLE hPbuffer);
PFNWGLDESTROYPBUFFERPROC fDestroyPbuffer;
typedef HDC (WINAPI * PFNWGLGETPBUFFERDCPROC) (HANDLE hPbuffer);
PFNWGLGETPBUFFERDCPROC fGetPbufferDC;
typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
PFNWGLCHOOSEPIXELFORMATPROC fChoosePixelFormat;
typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, int* piAttributes, int *piValues);
PFNWGLGETPIXELFORMATATTRIBIVPROC fGetPixelFormatAttribiv;
};
bool
WGLWrap::InitEarly()
{
if (fCreateContext)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fCreateContext, { "wglCreateContext", NULL } },
{ (PRFuncPtr*) &fMakeCurrent, { "wglMakeCurrent", NULL } },
{ (PRFuncPtr*) &fGetProcAddress, { "wglGetProcAddress", NULL } },
{ (PRFuncPtr*) &fDeleteContext, { "wglDeleteContext", NULL } },
{ NULL, { NULL } }
};
return LoadSymbols(&symbols[0], false);
}
bool
WGLWrap::Init()
{
if (fCreatePbuffer)
return true;
SymLoadStruct symbols[] = {
{ (PRFuncPtr*) &fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", NULL } },
{ (PRFuncPtr*) &fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", NULL } },
{ (PRFuncPtr*) &fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", NULL } },
{ (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", NULL } },
{ (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", NULL } },
{ NULL, { NULL } }
};
return LoadSymbols(&symbols[0], true);
}
static WGLWrap gWGLWrap;
nsGLPbufferWGL::nsGLPbufferWGL()
: mGlewWindow(nsnull), mGlewDC(nsnull), mGlewWglContext(nsnull),
mPbuffer(nsnull), mPbufferDC(nsnull), mPbufferContext(nsnull)
{
gActiveBuffers++;
fprintf (stderr, "nsGLPbufferWGL: gActiveBuffers: %d\n", gActiveBuffers);
}
PRBool
nsGLPbufferWGL::Init(WebGLContext *priv)
{
// XXX lookup SYSTEM32 path!
char *opengl32 = "C:\\WINDOWS\\SYSTEM32\\OPENGL32.DLL";
if (!gWGLWrap.OpenLibrary(opengl32))
return PR_FALSE;
if (!gWGLWrap.InitEarly())
return PR_FALSE;
gWGLWrap.SetLookupFunc((LibrarySymbolLoader::PlatformLookupFunction) gWGLWrap.fGetProcAddress);
mPriv = priv;
WNDCLASSW wc;
PIXELFORMATDESCRIPTOR pfd;
if (!GetClassInfoW(GetModuleHandle(NULL), L"GLEW", &wc)) {
ZeroMemory(&wc, sizeof(WNDCLASS));
wc.hInstance = GetModuleHandle(NULL);
wc.lpfnWndProc = DefWindowProc;
wc.lpszClassName = L"GLEW";
if (!RegisterClassW(&wc)) {
LogMessage("Canvas 3D: RegisterClass failed");
return PR_FALSE;
}
}
// create window
mGlewWindow = CreateWindowW(L"GLEW", L"GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
if (!mGlewWindow) {
LogMessage("Canvas 3D: CreateWindow failed");
return PR_FALSE;
}
// get the device context
mGlewDC = GetDC(mGlewWindow);
if (!mGlewDC) {
LogMessage("Canvas 3D: GetDC failed");
return PR_FALSE;
}
// find default pixel format
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
int pixelformat = ChoosePixelFormat(mGlewDC, &pfd);
// set the pixel format for the dc
if (!SetPixelFormat(mGlewDC, pixelformat, &pfd)) {
LogMessage("Canvas 3D: SetPixelFormat failed");
return PR_FALSE;
}
// create rendering context
mGlewWglContext = gWGLWrap.fCreateContext(mGlewDC);
if (!mGlewWglContext) {
LogMessage("Canvas 3D: wglCreateContext failed");
return PR_FALSE;
}
if (!gWGLWrap.fMakeCurrent(mGlewDC, (HGLRC) mGlewWglContext)) {
LogMessage("Canvas 3D: wglMakeCurrent failed");
return PR_FALSE;
}
// grab all the wgl extension pieces that we couldn't grab before
// we had a context
if (!gWGLWrap.Init())
return PR_FALSE;
// XXX look up system32 dir
if (!mGLWrap.OpenLibrary(opengl32)) {
LogMessage("Canvas 3D: Failed to open opengl32.dll (only looked in c:\\windows\\system32, fixme)");
return PR_FALSE;
}
mGLWrap.SetLookupFunc((LibrarySymbolLoader::PlatformLookupFunction) gWGLWrap.fGetProcAddress);
if (!mGLWrap.Init(GLES20Wrap::TRY_NATIVE_GL)) {
LogMessage("Canvas 3D: GLWrap init failed");
return PR_FALSE;
}
return PR_TRUE;
}
PRBool
nsGLPbufferWGL::Resize(PRInt32 width, PRInt32 height)
{
if (mWidth == width &&
mHeight == height)
{
return PR_TRUE;
}
Destroy();
nsresult rv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch("extensions.canvas3d.", getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, PR_FALSE);
PRInt32 prefAntialiasing;
rv = prefBranch->GetIntPref("antialiasing", &prefAntialiasing);
if (NS_FAILED(rv))
prefAntialiasing = 0;
mThebesSurface = new gfxImageSurface(gfxIntSize(width, height), gfxASurface::ImageFormatARGB32);
if (mThebesSurface->CairoStatus() != 0) {
fprintf (stderr, "image surface failed\n");
return PR_FALSE;
}
// clear the surface
memset (mThebesSurface->Data(),
0,
height * mThebesSurface->Stride());
if (!gWGLWrap.fMakeCurrent(mGlewDC, (HGLRC) mGlewWglContext)) {
fprintf (stderr, "Error: %d\n", GetLastError());
LogMessage("Canvas 3D: wglMakeCurrent failed");
return PR_FALSE;
}
PRBool ignoreAA = PR_FALSE;
int attribs[] = {
WGL_SUPPORT_OPENGL_ARB, LOCAL_GL_TRUE,
WGL_DRAW_TO_PBUFFER_ARB, LOCAL_GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, LOCAL_GL_FALSE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_RED_BITS_ARB, 8,
WGL_GREEN_BITS_ARB, 8,
WGL_BLUE_BITS_ARB, 8,
WGL_ALPHA_BITS_ARB, 8,
0, 0,
0, 0,
0
};
float fattribs[] = { 0.0f };
// ATI's OpenGL impl seems to have a problem with calling
// wglChoosePixelFormatARB with NULL/0 to obtain the number of
// matching formats; so just allocate room for a lot.
#define MAX_NUM_FORMATS 256
UINT numFormats = MAX_NUM_FORMATS;
int formats[MAX_NUM_FORMATS];
//fprintf (stderr, "EXT: %p ARB: %p rest: %s\n", wglewGetContext()->__wglewChoosePixelFormatEXT, wglewGetContext()->__wglewChoosePixelFormatARB, wglGetExtensionsStringARB(mGlewDC));
TRY_FIND_AGAIN:
if (ignoreAA) {
attribs[18] = 0;
} else if (prefAntialiasing > 0) {
attribs[18] = WGL_SAMPLE_BUFFERS_ARB;
attribs[19] = 1;
attribs[20] = WGL_SAMPLES_ARB;
attribs[21] = 1 << prefAntialiasing;
}
if (!gWGLWrap.fChoosePixelFormat(mGlewDC,
attribs,
NULL,
numFormats,
formats,
&numFormats) ||
numFormats == 0)
{
if (!ignoreAA) {
ignoreAA = PR_TRUE;
goto TRY_FIND_AGAIN;
}
LogMessage("Canvas 3D: wglChoosePixelFormat failed (or couldn't find any matching formats).");
ReleaseDC(NULL, mGlewDC);
return PR_FALSE;
}
int chosenFormat = -1;
int question,answer;
for (int priority = 6; priority > 0; priority--) {
//fprintf (stderr, "---- priority: %d\n", priority);
for (UINT i = 0; i < numFormats; i++) {
int fmt = formats[i];
#define CHECK_ATTRIB(q, test) \
question = (q); \
if (!gWGLWrap.fGetPixelFormatAttribiv(mGlewDC, fmt, 0, 1, &question, &answer)) { \
/*fprintf (stderr, "check for %d failed\n", q);*/ \
continue; \
} \
/*fprintf (stderr, #q " -> %d\n", answer);*/ \
if (test) { \
continue; \
}
//fprintf (stderr, "Format %d:\n", fmt);
switch (priority) {
case 6:
CHECK_ATTRIB(WGL_ACCUM_BITS_ARB, answer != 0)
case 5:
CHECK_ATTRIB(WGL_STENCIL_BITS_ARB, answer != 0)
// XXX we only pick 2xAA here, should let user choose
case 4:
CHECK_ATTRIB(WGL_SAMPLE_BUFFERS_ARB, answer != (prefAntialiasing != 0))
case 3:
CHECK_ATTRIB(WGL_SAMPLES_ARB, answer != (prefAntialiasing ? (1 << prefAntialiasing) : 0))
case 2:
CHECK_ATTRIB(WGL_DEPTH_BITS_ARB, answer < 8)
case 1:
CHECK_ATTRIB(WGL_COLOR_BITS_ARB, answer != 32)
default:
chosenFormat = fmt;
}
#undef CHECK_ATTRIB
}
if (chosenFormat != -1)
break;
}
if (chosenFormat == -1) {
LogMessage("Canvas 3D: Couldn't find a suitable pixel format!");
return PR_FALSE;
}
// ok, we now have a pixel format
fprintf (stderr, "***** Chose pixel format: %d\n", chosenFormat);
int pbattribs = 0;
mPbuffer = gWGLWrap.fCreatePbuffer(mGlewDC, chosenFormat, width, height, &pbattribs);
if (!mPbuffer) {
LogMessage("Canvas 3D: Failed to create pbuffer");
return PR_FALSE;
}
mPbufferDC = gWGLWrap.fGetPbufferDC(mPbuffer);
mPbufferContext = gWGLWrap.fCreateContext(mPbufferDC);
mWindowsSurface = new gfxWindowsSurface(gfxIntSize(width, height), gfxASurface::ImageFormatARGB32);
if (mWindowsSurface && mWindowsSurface->CairoStatus() == 0)
mThebesSurface = mWindowsSurface->GetImageSurface();
mWidth = width;
mHeight = height;
fprintf (stderr, "Resize: %d %d\n", width, height);
return PR_TRUE;
}
void
nsGLPbufferWGL::Destroy()
{
sCurrentContextToken = nsnull;
mThebesSurface = nsnull;
if (mPbuffer) {
gWGLWrap.fDeleteContext((HGLRC) mPbufferContext);
gWGLWrap.fDestroyPbuffer(mPbuffer);
mPbuffer = nsnull;
}
}
nsGLPbufferWGL::~nsGLPbufferWGL()
{
Destroy();
if (mGlewWglContext) {
gWGLWrap.fDeleteContext((HGLRC) mGlewWglContext);
mGlewWglContext = nsnull;
}
if (mGlewWindow) {
DestroyWindow(mGlewWindow);
mGlewWindow = nsnull;
}
gActiveBuffers--;
fprintf (stderr, "nsGLPbufferWGL: gActiveBuffers: %d\n", gActiveBuffers);
fflush (stderr);
}
void
nsGLPbufferWGL::MakeContextCurrent()
{
if (sCurrentContextToken == mPbufferContext)
return;
gWGLWrap.fMakeCurrent (mPbufferDC, (HGLRC) mPbufferContext);
sCurrentContextToken = mPbufferContext;
}
void
nsGLPbufferWGL::SwapBuffers()
{
MakeContextCurrent();
mGLWrap.fReadPixels (0, 0, mWidth, mHeight, LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV, mThebesSurface->Data());
// premultiply the image
int len = mWidth*mHeight*4;
unsigned char *src = mThebesSurface->Data();
Premultiply(src, len);
}
gfxASurface*
nsGLPbufferWGL::ThebesSurface()
{
return mThebesSurface;
}