b=594553; correctly create gl layer manager on android; r=jrmuizel

This commit is contained in:
Vladimir Vukicevic 2010-09-08 18:19:11 -04:00
parent acdcaa5b39
commit e421717237
5 changed files with 95 additions and 39 deletions

View File

@ -958,20 +958,10 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
#else
EGLDisplay display;
EGLConfig config;
EGLSurface surface;
EGLContext context;
display = sEGLLibrary.fGetDisplay(aWidget->GetNativeData(NS_NATIVE_DISPLAY));
if (!display) {
return nsnull;
}
if (!sEGLLibrary.fInitialize(display, NULL, NULL)) {
return nsnull;
}
EGLint attribs[] = {
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_WINDOW_BIT,
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
@ -988,7 +978,7 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
EGLConfig configs[64];
EGLint ncfg = 64;
if (!sEGLLibrary.fChooseConfig(display, attribs, configs, ncfg, &ncfg) ||
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs, configs, ncfg, &ncfg) ||
ncfg < 1)
{
return nsnull;
@ -1022,11 +1012,13 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
//
// We also only have one true "window", so we just use it directly and ignore
// what was passed in.
printf_stderr("... requesting window surface from bridge\n");
surface = mozilla::AndroidBridge::Bridge()->
CallEglCreateWindowSurface(display, config,
CallEglCreateWindowSurface(EGL_DISPLAY(), config,
mozilla::AndroidBridge::Bridge()->SurfaceView());
printf_stderr("got surface %p\n", surface);
#else
surface = sEGLLibrary.fCreateWindowSurface(display, config, GET_NATIVE_WINDOW(aWidget), 0);
surface = sEGLLibrary.fCreateWindowSurface(EGL_DISPLAY(), config, GET_NATIVE_WINDOW(aWidget), 0);
#endif
if (!surface) {
@ -1034,7 +1026,7 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
}
if (!sEGLLibrary.fBindAPI(LOCAL_EGL_OPENGL_ES_API)) {
sEGLLibrary.fDestroySurface(display, surface);
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
return nsnull;
}
@ -1046,7 +1038,7 @@ GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
GLContextEGL *shareContext = GetGlobalContextEGL();
TRY_AGAIN_NO_SHARING:
context = sEGLLibrary.fCreateContext(display,
context = sEGLLibrary.fCreateContext(EGL_DISPLAY(),
config,
shareContext ? shareContext->mContext : EGL_NO_CONTEXT,
cxattribs);
@ -1058,7 +1050,7 @@ TRY_AGAIN_NO_SHARING:
}
NS_WARNING("CreateForWindow -- no context, giving up");
sEGLLibrary.fDestroySurface(display, surface);
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
return nsnull;
}

View File

@ -83,6 +83,7 @@ static nsTArray<nsWindow*> gTopLevelWindows;
static nsWindow* gFocusedWindow = nsnull;
static nsRefPtr<gl::GLContext> sGLContext;
static bool sFailedToCreateGLContext = false;
// Multitouch swipe thresholds (in screen pixels)
static const double SWIPE_MAX_PINCH_DELTA = 100;
@ -577,6 +578,56 @@ nsWindow::SetWindowClass(const nsAString& xulWinType)
return NS_OK;
}
mozilla::layers::LayerManager*
nsWindow::GetLayerManager()
{
if (mLayerManager) {
return mLayerManager;
}
printf_stderr("nsWindow::GetLayerManager\n");
nsWindow *topWindow = TopWindow();
if (!topWindow) {
printf_stderr(" -- no topwindow\n");
mLayerManager = new BasicLayerManager(this);
return mLayerManager;
}
mUseAcceleratedRendering = GetShouldAccelerate();
if (!mUseAcceleratedRendering ||
sFailedToCreateGLContext)
{
printf_stderr(" -- creating basic, not accelerated\n");
mLayerManager = new BasicLayerManager(this);
return mLayerManager;
}
if (!sGLContext) {
// the window we give doesn't matter here
sGLContext = mozilla::gl::GLContextProvider::CreateForWindow(this);
}
if (sGLContext) {
nsRefPtr<mozilla::layers::LayerManagerOGL> layerManager =
new mozilla::layers::LayerManagerOGL(this);
if (layerManager && layerManager->Initialize(sGLContext))
mLayerManager = layerManager;
}
if (!sGLContext || !mLayerManager) {
sGLContext = nsnull;
sFailedToCreateGLContext = PR_TRUE;
mLayerManager = new BasicLayerManager(this);
}
return mLayerManager;
}
gfxASurface*
nsWindow::GetThebesSurface()
{

View File

@ -160,6 +160,7 @@ public:
NS_IMETHOD OnIMETextChange(PRUint32 aStart, PRUint32 aOldEnd, PRUint32 aNewEnd);
NS_IMETHOD OnIMESelectionChange(void);
LayerManager* GetLayerManager();
gfxASurface* GetThebesSurface();
protected:

View File

@ -761,34 +761,45 @@ nsBaseWidget::AutoLayerManagerSetup::~AutoLayerManagerSetup()
}
}
PRBool
nsBaseWidget::GetShouldAccelerate()
{
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
PRBool disableAcceleration = PR_FALSE;
PRBool accelerateByDefault = PR_TRUE;
if (prefs) {
prefs->GetBoolPref("layers.accelerate-all",
&accelerateByDefault);
prefs->GetBoolPref("layers.accelerate-none",
&disableAcceleration);
}
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
accelerateByDefault = accelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
PRBool safeMode = PR_FALSE;
if (xr)
xr->GetInSafeMode(&safeMode);
if (disableAcceleration || safeMode)
return PR_FALSE;
if (accelerateByDefault)
return PR_TRUE;
return mUseAcceleratedRendering;
}
LayerManager* nsBaseWidget::GetLayerManager()
{
if (!mLayerManager) {
nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
PRBool disableAcceleration = PR_FALSE;
PRBool accelerateByDefault = PR_TRUE;
if (prefs) {
prefs->GetBoolPref("layers.accelerate-all",
&accelerateByDefault);
prefs->GetBoolPref("layers.accelerate-none",
&disableAcceleration);
}
const char *acceleratedEnv = PR_GetEnv("MOZ_ACCELERATED");
accelerateByDefault = accelerateByDefault ||
(acceleratedEnv && (*acceleratedEnv != '0'));
nsCOMPtr<nsIXULRuntime> xr = do_GetService("@mozilla.org/xre/runtime;1");
PRBool safeMode = PR_FALSE;
if (xr)
xr->GetInSafeMode(&safeMode);
if (disableAcceleration || safeMode)
mUseAcceleratedRendering = PR_FALSE;
else if (accelerateByDefault)
mUseAcceleratedRendering = PR_TRUE;
mUseAcceleratedRendering = GetShouldAccelerate();
if (mUseAcceleratedRendering) {
nsRefPtr<LayerManagerOGL> layerManager =

View File

@ -146,6 +146,7 @@ public:
NS_IMETHOD CancelIMEComposition() { return NS_OK; }
NS_IMETHOD SetAcceleratedRendering(PRBool aEnabled);
virtual PRBool GetAcceleratedRendering();
virtual PRBool GetShouldAccelerate();
NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD OnIMEFocusChange(PRBool aFocus) { return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD OnIMETextChange(PRUint32 aStart, PRUint32 aOldEnd, PRUint32 aNewEnd) { return NS_ERROR_NOT_IMPLEMENTED; }