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
Родитель ed4466fd73
Коммит b155b17422
9 изменённых файлов: 46 добавлений и 117 удалений

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

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

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

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

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

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

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

@ -269,19 +269,6 @@ void main()
} }
@end @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 @shader sCopy2DRectFS
#extension GL_ARB_texture_rectangle : enable #extension GL_ARB_texture_rectangle : enable

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

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

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

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

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

@ -46,7 +46,6 @@
#define EGL_NATIVE_BUFFER_ANDROID 0x3140 #define EGL_NATIVE_BUFFER_ANDROID 0x3140
#define EGL_IMAGE_PRESERVED_KHR 0x30D2 #define EGL_IMAGE_PRESERVED_KHR 0x30D2
#define GL_TEXTURE_EXTERNAL_OES 0x8D65
typedef void *EGLContext; typedef void *EGLContext;
typedef void *EGLDisplay; typedef void *EGLDisplay;
@ -65,23 +64,10 @@ typedef gfxASurface::gfxImageFormat gfxImageFormat;
#define ANDROID_LIBUI_PATH "libui.so" #define ANDROID_LIBUI_PATH "libui.so"
#define ANDROID_GLES_PATH "libGLESv2.so" #define ANDROID_GLES_PATH "libGLESv2.so"
#define ANDROID_EGL_PATH "libEGL.so" #define ANDROID_EGL_PATH "libEGL.so"
#define ANDROID_LIBC_PATH "libc.so"
// Really I have no idea, but this should be big enough // Really I have no idea, but this should be big enough
#define GRAPHIC_BUFFER_SIZE 1024 #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 { enum {
/* buffer is never read in software */ /* buffer is never read in software */
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000, GRALLOC_USAGE_SW_READ_NEVER = 0x00000000,
@ -179,9 +165,6 @@ public:
typedef int (*pfnGraphicBufferReallocate)(void*, PRUint32 w, PRUint32 h, PRUint32 format); typedef int (*pfnGraphicBufferReallocate)(void*, PRUint32 w, PRUint32 h, PRUint32 format);
pfnGraphicBufferReallocate fGraphicBufferReallocate; pfnGraphicBufferReallocate fGraphicBufferReallocate;
typedef void* (*pfnMalloc)(size_t size);
pfnMalloc fMalloc;
bool EnsureInitialized() bool EnsureInitialized()
{ {
if (mInitialized) { if (mInitialized) {
@ -219,19 +202,6 @@ public:
return false; 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); handle = dlopen(ANDROID_LIBUI_PATH, RTLD_LAZY);
if (!handle) { if (!handle) {
LOG("Couldn't load libui.so"); LOG("Couldn't load libui.so");
@ -300,41 +270,43 @@ AndroidGraphicBuffer::~AndroidGraphicBuffer()
void void
AndroidGraphicBuffer::DestroyBuffer() 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 (mEGLImage) {
if (sGLFunctions.EnsureInitialized()) { if (sGLFunctions.EnsureInitialized()) {
EGLDisplay display = sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY); sGLFunctions.fDestroyImageKHR(sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY), mEGLImage);
sGLFunctions.fDestroyImageKHR(display, mEGLImage);
mEGLImage = NULL; mEGLImage = NULL;
} }
} }
#endif
mEGLImage = NULL; mEGLImage = NULL;
// Refcount will destroy the object for us at the correct time, even after if (mHandle) {
// deleting the EGLImage the driver still sometimes holds a reference if (sGLFunctions.EnsureInitialized()) {
// at this point. sGLFunctions.fGraphicBufferDtor(mHandle);
void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle); }
android_native_base_t* nativeBufferBase = (android_native_base_t*)nativeBuffer; free(mHandle);
nativeBufferBase->decRef(nativeBufferBase); mHandle = NULL;
mHandle = NULL; }
} }
bool bool
AndroidGraphicBuffer::EnsureBufferCreated() AndroidGraphicBuffer::EnsureBufferCreated()
{ {
if (!mHandle) { if (!mHandle) {
// Using libc malloc is important here: mHandle = malloc(GRAPHIC_BUFFER_SIZE);
// 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);
sGLFunctions.fGraphicBufferCtor(mHandle, mWidth, mHeight, GetAndroidFormat(mFormat), GetAndroidUsage(mUsage)); 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; return true;
@ -457,23 +429,15 @@ AndroidGraphicBuffer::EnsureEGLImage()
if (!EnsureInitialized()) if (!EnsureInitialized())
return false; return false;
EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGLint eglImgAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE, EGL_NONE };
EGL_TRUE, EGL_NONE, EGL_NONE };
EGLDisplay display = sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY);
if (!display) {
return false;
}
void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle); void* nativeBuffer = sGLFunctions.fGraphicBufferGetNativeBuffer(mHandle);
mEGLImage = sGLFunctions.fCreateImageKHR(display, EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID, mEGLImage = sGLFunctions.fCreateImageKHR(sGLFunctions.fGetDisplay(EGL_DEFAULT_DISPLAY), EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, (EGLClientBuffer)nativeBuffer, eglImgAttrs);
(EGLClientBuffer)nativeBuffer,
eglImgAttrs);
return mEGLImage != NULL; return mEGLImage != NULL;
} }
bool bool
AndroidGraphicBuffer::Bind(GLenum target) AndroidGraphicBuffer::Bind()
{ {
if (!EnsureInitialized()) if (!EnsureInitialized())
return false; return false;
@ -484,7 +448,7 @@ AndroidGraphicBuffer::Bind(GLenum target)
} }
clearGLError(); clearGLError();
sGLFunctions.fImageTargetTexture2DOES(target, mEGLImage); sGLFunctions.fImageTargetTexture2DOES(GL_TEXTURE_2D, mEGLImage);
return ensureNoGLError("glEGLImageTargetTexture2DOES"); return ensureNoGLError("glEGLImageTargetTexture2DOES");
} }

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

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

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

@ -92,7 +92,7 @@ XPIDLSRCS = \
SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a 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 include $(topsrcdir)/config/rules.mk