Back out 243cd4db5edd and 4175fc853e16 (bug 712716) for OS X 10.6 and 10.7 assertions

This commit is contained in:
Phil Ringnalda 2012-03-15 23:21:54 -07:00
parent 4ad16ff672
commit 807c91234e
9 changed files with 46 additions and 117 deletions

View File

@ -137,7 +137,6 @@ enum ShaderProgramType {
ComponentAlphaPass2ProgramType,
Copy2DProgramType,
Copy2DRectProgramType,
Copy2DExternalProgramType,
NumProgramTypes
};

View File

@ -204,22 +204,12 @@ LayerManagerOGL::Initialize(nsRefPtr<GLContext> aContext, bool force)
// We unfortunately can't do generic initialization here, since the
// concrete type actually matters. This macro generates the
// initialization using a concrete type and index.
enum {
// Causes Initialize to fail if shdaer can't compile
SHADER_MANDATORY,
// Sets the shader as NULL if it fails to compile
SHADER_OPTIONAL
};
#define SHADER_PROGRAM(penum, ptype, vsstr, fsstr, optional) do { \
#define SHADER_PROGRAM(penum, ptype, vsstr, fsstr) do { \
NS_ASSERTION(programIndex++ == penum, "out of order shader initialization!"); \
ptype *p = new ptype(mGLContext); \
if (!p->Initialize(vsstr, fsstr)) { \
delete p; \
if (optional == SHADER_OPTIONAL) \
p = nsnull; \
else \
return false; \
return false; \
} \
mPrograms.AppendElement(p); \
} while (0)
@ -233,33 +223,28 @@ LayerManagerOGL::Initialize(nsRefPtr<GLContext> aContext, bool force)
/* Layer programs */
SHADER_PROGRAM(RGBALayerProgramType, ColorTextureLayerProgram,
sLayerVS, sRGBATextureLayerFS, SHADER_MANDATORY);
sLayerVS, sRGBATextureLayerFS);
SHADER_PROGRAM(BGRALayerProgramType, ColorTextureLayerProgram,
sLayerVS, sBGRATextureLayerFS, SHADER_MANDATORY);
sLayerVS, sBGRATextureLayerFS);
SHADER_PROGRAM(RGBXLayerProgramType, ColorTextureLayerProgram,
sLayerVS, sRGBXTextureLayerFS, SHADER_MANDATORY);
sLayerVS, sRGBXTextureLayerFS);
SHADER_PROGRAM(BGRXLayerProgramType, ColorTextureLayerProgram,
sLayerVS, sBGRXTextureLayerFS, SHADER_MANDATORY);
sLayerVS, sBGRXTextureLayerFS);
SHADER_PROGRAM(RGBARectLayerProgramType, ColorTextureLayerProgram,
sLayerVS, sRGBARectTextureLayerFS, SHADER_MANDATORY);
sLayerVS, sRGBARectTextureLayerFS);
SHADER_PROGRAM(ColorLayerProgramType, SolidColorLayerProgram,
sLayerVS, sSolidColorLayerFS, SHADER_MANDATORY);
sLayerVS, sSolidColorLayerFS);
SHADER_PROGRAM(YCbCrLayerProgramType, YCbCrTextureLayerProgram,
sLayerVS, sYCbCrTextureLayerFS, SHADER_MANDATORY);
sLayerVS, sYCbCrTextureLayerFS);
SHADER_PROGRAM(ComponentAlphaPass1ProgramType, ComponentAlphaTextureLayerProgram,
sLayerVS, sComponentPass1FS, SHADER_MANDATORY);
sLayerVS, sComponentPass1FS);
SHADER_PROGRAM(ComponentAlphaPass2ProgramType, ComponentAlphaTextureLayerProgram,
sLayerVS, sComponentPass2FS, SHADER_MANDATORY);
sLayerVS, sComponentPass2FS);
/* Copy programs (used for final framebuffer blit) */
SHADER_PROGRAM(Copy2DProgramType, CopyProgram,
sCopyVS, sCopy2DFS, SHADER_MANDATORY);
sCopyVS, sCopy2DFS);
SHADER_PROGRAM(Copy2DRectProgramType, CopyProgram,
sCopyVS, sCopy2DRectFS, SHADER_MANDATORY);
#ifdef ANDROID
SHADER_PROGRAM(Copy2DExternalProgramType, CopyProgram,
sCopyVS, sCopy2DExternalFS, SHADER_OPTIONAL);
#endif
sCopyVS, sCopy2DRectFS);
#undef SHADER_PROGRAM

View File

@ -234,11 +234,6 @@ public:
CopyProgram *GetCopy2DRectProgram() {
return static_cast<CopyProgram*>(mPrograms[gl::Copy2DRectProgramType]);
}
#ifdef ANDROID
CopyProgram *GetCopy2DExternalProgram() {
return static_cast<CopyProgram*>(mPrograms[gl::Copy2DExternalProgramType]);
}
#endif
ColorTextureLayerProgram *GetFBOLayerProgram() {
return static_cast<ColorTextureLayerProgram*>(mPrograms[GetFBOLayerProgramType()]);

View File

@ -269,19 +269,6 @@ void main()
}
@end
@shader sCopy2DExternalFS
$FRAGMENT_SHADER_HEADER$
#extension GL_OES_EGL_image_external : require
varying vec2 vTexCoord;
uniform samplerExternalOES uTexture;
void main()
{
gl_FragColor = texture2D(uTexture, vTexCoord);
}
@end
@shader sCopy2DRectFS
#extension GL_ARB_texture_rectangle : enable

View File

@ -142,7 +142,7 @@ AndroidDirectTexture::Reallocate(PRUint32 aWidth, PRUint32 aHeight, gfxASurface:
}
bool
AndroidDirectTexture::Bind(GLenum target)
AndroidDirectTexture::Bind()
{
MutexAutoLock lock(mLock);
@ -153,7 +153,7 @@ AndroidDirectTexture::Bind(GLenum target)
mNeedFlip = false;
}
return mFrontBuffer->Bind(target);
return mFrontBuffer->Bind();
}
} /* mozilla */

View File

@ -69,7 +69,7 @@ public:
PRUint32 Width() { return mWidth; }
PRUint32 Height() { return mHeight; }
bool Bind(GLenum target);
bool Bind();
private:
mozilla::Mutex mLock;

View File

@ -46,7 +46,6 @@
#define EGL_NATIVE_BUFFER_ANDROID 0x3140
#define EGL_IMAGE_PRESERVED_KHR 0x30D2
#define GL_TEXTURE_EXTERNAL_OES 0x8D65
typedef void *EGLContext;
typedef void *EGLDisplay;
@ -65,23 +64,10 @@ typedef gfxASurface::gfxImageFormat gfxImageFormat;
#define ANDROID_LIBUI_PATH "libui.so"
#define ANDROID_GLES_PATH "libGLESv2.so"
#define ANDROID_EGL_PATH "libEGL.so"
#define ANDROID_LIBC_PATH "libc.so"
// Really I have no idea, but this should be big enough
#define GRAPHIC_BUFFER_SIZE 1024
// This layout is taken from the android source code
// We use this to get at the incRef/decRef functions
// to manage AndroidGraphicBuffer.
struct android_native_base_t
{
int magic;
int version;
void* reserved[4];
void (*incRef)(android_native_base_t* base);
void (*decRef)(android_native_base_t* base);
};
enum {
/* buffer is never read in software */
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000,
@ -179,9 +165,6 @@ public:
typedef int (*pfnGraphicBufferReallocate)(void*, PRUint32 w, PRUint32 h, PRUint32 format);
pfnGraphicBufferReallocate fGraphicBufferReallocate;
typedef void* (*pfnMalloc)(size_t size);
pfnMalloc fMalloc;
bool EnsureInitialized()
{
if (mInitialized) {
@ -219,19 +202,6 @@ public:
return false;
}
handle = dlopen(ANDROID_LIBC_PATH, RTLD_LAZY);
if (!handle) {
LOG("Couldn't load libc.so");
return false;
}
fMalloc = (pfnMalloc)dlsym(handle, "malloc");
if (!fMalloc) {
LOG("Failed to lookup malloc");
return false;
}
handle = dlopen(ANDROID_LIBUI_PATH, RTLD_LAZY);
if (!handle) {
LOG("Couldn't load libui.so");
@ -300,41 +270,43 @@ AndroidGraphicBuffer::~AndroidGraphicBuffer()
void
AndroidGraphicBuffer::DestroyBuffer()
{
/**
* XXX: eglDestroyImageKHR crashes sometimes due to refcount badness (I think)
*
* If you look at egl.cpp (https://github.com/android/platform_frameworks_base/blob/master/opengl/libagl/egl.cpp#L2002)
* you can see that eglCreateImageKHR just refs the native buffer, and eglDestroyImageKHR
* just unrefs it. Somehow the ref count gets messed up and things are already destroyed
* by the time eglDestroyImageKHR gets called. For now, at least, just not calling
* eglDestroyImageKHR should be fine since we do free the GraphicBuffer below.
*
* Bug 712716
*/
#if 0
if (mEGLImage) {
if (sGLFunctions.EnsureInitialized()) {
EGLDisplay display = sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY);
sGLFunctions.fDestroyImageKHR(display, mEGLImage);
sGLFunctions.fDestroyImageKHR(sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY), mEGLImage);
mEGLImage = NULL;
}
}
#endif
mEGLImage = NULL;
// Refcount will destroy the object for us at the correct time, even after
// deleting the EGLImage the driver still sometimes holds a reference
// at this point.
void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle);
android_native_base_t* nativeBufferBase = (android_native_base_t*)nativeBuffer;
nativeBufferBase->decRef(nativeBufferBase);
mHandle = NULL;
if (mHandle) {
if (sGLFunctions.EnsureInitialized()) {
sGLFunctions.fGraphicBufferDtor(mHandle);
}
free(mHandle);
mHandle = NULL;
}
}
bool
AndroidGraphicBuffer::EnsureBufferCreated()
{
if (!mHandle) {
// Using libc malloc is important here:
// libxul is linked with jemalloc, so using malloc here would give us a jemalloc managed block.
// However AndroidGraphicBuffer are native refcounted objects that will be released with libc
// when the ref count goes to zero. If this isn't allocated with libc, the refcount dlfree
// will crash when releasing.
mHandle = sGLFunctions.fMalloc(GRAPHIC_BUFFER_SIZE);
mHandle = malloc(GRAPHIC_BUFFER_SIZE);
sGLFunctions.fGraphicBufferCtor(mHandle, mWidth, mHeight, GetAndroidFormat(mFormat), GetAndroidUsage(mUsage));
void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle);
android_native_base_t* nativeBufferBase = (android_native_base_t*)nativeBuffer;
nativeBufferBase->incRef(nativeBufferBase);
}
return true;
@ -457,23 +429,15 @@ AndroidGraphicBuffer::EnsureEGLImage()
if (!EnsureInitialized())
return false;
EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR,
EGL_TRUE, EGL_NONE, EGL_NONE };
EGLDisplay display = sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY);
if (!display) {
return false;
}
EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle);
mEGLImage = sGLFunctions.fCreateImageKHR(display, EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID,
(EGLClientBuffer)nativeBuffer,
eglImgAttrs);
mEGLImage = sGLFunctions.fCreateImageKHR(sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)nativeBuffer, eglImgAttrs);
return mEGLImage != NULL;
}
bool
AndroidGraphicBuffer::Bind(GLenum target)
AndroidGraphicBuffer::Bind()
{
if (!EnsureInitialized())
return false;
@ -484,7 +448,7 @@ AndroidGraphicBuffer::Bind(GLenum target)
}
clearGLError();
sGLFunctions.fImageTargetTexture2DOES(target, mEGLImage);
sGLFunctions.fImageTargetTexture2DOES(GL_TEXTURE_2D, mEGLImage);
return ensureNoGLError("glEGLImageTargetTexture2DOES");
}

View File

@ -39,7 +39,6 @@
#define AndroidGraphicBuffer_h_
#include "gfxASurface.h"
#include <GLES2/gl2.h>
#include "nsRect.h"
typedef void* EGLImageKHR;
@ -78,7 +77,7 @@ public:
PRUint32 Width() { return mWidth; }
PRUint32 Height() { return mHeight; }
bool Bind(GLenum target);
bool Bind();
static bool IsBlacklisted();

View File

@ -92,7 +92,7 @@ XPIDLSRCS = \
SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidFlexViewWrapper.h AndroidDirectTexture.h AndroidGraphicBuffer.h
EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidFlexViewWrapper.h
include $(topsrcdir)/config/rules.mk