2010-06-09 22:27:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2013-12-09 02:52:54 +00:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
#include "GLContextEGL.h"
|
2012-03-09 00:01:12 +00:00
|
|
|
|
2011-08-24 16:15:58 +00:00
|
|
|
#if defined(XP_UNIX)
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2012-06-28 00:15:32 +00:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2010-06-09 22:27:29 +00:00
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
// we're using default display for now
|
|
|
|
#define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)GDK_WINDOW_XID((GdkWindow *) aWidget->GetNativeData(NS_NATIVE_WINDOW))
|
2014-02-21 02:08:50 +00:00
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#define GET_NATIVE_WINDOW(aWidget) (EGLNativeWindowType)(aWidget->GetNativeData(NS_NATIVE_SHAREABLE_WINDOW))
|
2011-11-11 00:17:46 +00:00
|
|
|
#elif defined(MOZ_WIDGET_GONK)
|
|
|
|
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_WINDOW))
|
2012-11-19 17:58:38 +00:00
|
|
|
#include "HwcComposer2D.h"
|
2013-05-08 03:58:22 +00:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
2010-06-09 22:27:29 +00:00
|
|
|
#endif
|
|
|
|
|
2011-08-24 16:15:58 +00:00
|
|
|
#if defined(ANDROID)
|
2010-06-26 00:52:37 +00:00
|
|
|
/* from widget */
|
2011-11-11 00:17:46 +00:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-06-26 00:52:37 +00:00
|
|
|
#include "AndroidBridge.h"
|
2012-07-20 19:20:51 +00:00
|
|
|
#include "nsSurfaceTexture.h"
|
2011-11-11 00:17:46 +00:00
|
|
|
#endif
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2011-11-11 00:17:46 +00:00
|
|
|
#include <android/log.h>
|
2012-06-13 04:20:27 +00:00
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
|
|
|
|
|
|
|
# if defined(MOZ_WIDGET_GONK)
|
|
|
|
# include "cutils/properties.h"
|
|
|
|
# include <ui/GraphicBuffer.h>
|
|
|
|
|
|
|
|
using namespace android;
|
|
|
|
# endif
|
|
|
|
|
2012-01-20 14:18:56 +00:00
|
|
|
#endif
|
|
|
|
|
2012-01-13 06:23:02 +00:00
|
|
|
#define GLES2_LIB "libGLESv2.so"
|
2012-01-20 14:18:56 +00:00
|
|
|
#define GLES2_LIB2 "libGLESv2.so.2"
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2010-08-07 05:09:18 +00:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2010-08-07 05:09:18 +00:00
|
|
|
|
2012-03-16 22:24:12 +00:00
|
|
|
#define GLES2_LIB "libGLESv2.dll"
|
|
|
|
|
2010-08-07 05:09:18 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
// a little helper
|
|
|
|
class AutoDestroyHWND {
|
|
|
|
public:
|
2013-07-20 08:48:55 +00:00
|
|
|
AutoDestroyHWND(HWND aWnd = nullptr)
|
2010-08-07 05:09:18 +00:00
|
|
|
: mWnd(aWnd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoDestroyHWND() {
|
|
|
|
if (mWnd) {
|
|
|
|
::DestroyWindow(mWnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HWND() {
|
|
|
|
return mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND forget() {
|
|
|
|
HWND w = mWnd;
|
2013-07-20 08:48:55 +00:00
|
|
|
mWnd = nullptr;
|
2010-08-07 05:09:18 +00:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND operator=(HWND aWnd) {
|
|
|
|
if (mWnd && mWnd != aWnd) {
|
|
|
|
::DestroyWindow(mWnd);
|
|
|
|
}
|
|
|
|
mWnd = aWnd;
|
|
|
|
return mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND mWnd;
|
|
|
|
};
|
|
|
|
|
2010-06-09 22:27:29 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#error "Platform not recognized"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-03-12 15:43:14 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-01-13 13:20:50 +00:00
|
|
|
#include "gfxUtils.h"
|
2011-08-31 14:27:05 +00:00
|
|
|
#include "gfxFailure.h"
|
2010-06-23 15:50:51 +00:00
|
|
|
#include "gfxASurface.h"
|
2010-09-09 20:40:11 +00:00
|
|
|
#include "gfxImageSurface.h"
|
2010-07-01 16:30:38 +00:00
|
|
|
#include "gfxPlatform.h"
|
2010-06-09 22:27:29 +00:00
|
|
|
#include "GLContextProvider.h"
|
2012-03-16 22:24:12 +00:00
|
|
|
#include "GLLibraryEGL.h"
|
2013-10-11 13:16:44 +00:00
|
|
|
#include "TextureImageEGL.h"
|
2010-06-09 22:27:29 +00:00
|
|
|
#include "nsDebug.h"
|
2010-11-26 21:41:53 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-09 22:27:29 +00:00
|
|
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2011-03-02 20:50:36 +00:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2013-11-30 22:20:57 +00:00
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
|
2013-07-04 17:25:50 +00:00
|
|
|
using namespace mozilla::gfx;
|
2012-07-20 19:20:51 +00:00
|
|
|
|
2011-11-11 00:17:46 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
extern nsIntRect gScreenBounds;
|
|
|
|
#endif
|
|
|
|
|
2010-06-09 22:27:29 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2011-01-06 22:07:12 +00:00
|
|
|
#define ADD_ATTR_2(_array, _k, _v) do { \
|
|
|
|
(_array).AppendElement(_k); \
|
|
|
|
(_array).AppendElement(_v); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define ADD_ATTR_1(_array, _k) do { \
|
|
|
|
(_array).AppendElement(_k); \
|
|
|
|
} while (0)
|
|
|
|
|
2011-09-23 05:58:15 +00:00
|
|
|
static bool
|
|
|
|
CreateConfig(EGLConfig* aConfig);
|
2010-12-13 22:36:35 +00:00
|
|
|
|
2013-12-13 20:15:07 +00:00
|
|
|
// append three zeros at the end of attribs list to work around
|
|
|
|
// EGL implementation bugs that iterate until they find 0, instead of
|
|
|
|
// EGL_NONE. See bug 948406.
|
|
|
|
#define EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS \
|
|
|
|
LOCAL_EGL_NONE, 0, 0, 0
|
|
|
|
|
|
|
|
static EGLint gTerminationAttribs[] = {
|
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
|
|
|
};
|
|
|
|
|
2011-12-15 00:57:09 +00:00
|
|
|
static EGLint gContextAttribs[] = {
|
|
|
|
LOCAL_EGL_CONTEXT_CLIENT_VERSION, 2,
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2011-12-15 00:57:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static EGLint gContextAttribsRobustness[] = {
|
|
|
|
LOCAL_EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
//LOCAL_EGL_CONTEXT_ROBUST_ACCESS_EXT, LOCAL_EGL_TRUE,
|
|
|
|
LOCAL_EGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_EXT, LOCAL_EGL_LOSE_CONTEXT_ON_RESET_EXT,
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2011-12-15 00:57:09 +00:00
|
|
|
};
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
static int
|
|
|
|
next_power_of_two(int v)
|
|
|
|
{
|
|
|
|
v--;
|
|
|
|
v |= v >> 1;
|
|
|
|
v |= v >> 2;
|
|
|
|
v |= v >> 4;
|
|
|
|
v |= v >> 8;
|
|
|
|
v |= v >> 16;
|
|
|
|
v++;
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
is_power_of_two(int v)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(v >= 0, "bad value");
|
|
|
|
|
|
|
|
if (v == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return (v & (v-1)) == 0;
|
|
|
|
}
|
|
|
|
|
2013-11-15 16:28:54 +00:00
|
|
|
static void
|
|
|
|
DestroySurface(EGLSurface oldSurface) {
|
|
|
|
if (oldSurface != EGL_NO_SURFACE) {
|
|
|
|
sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), oldSurface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static EGLSurface
|
|
|
|
CreateSurfaceForWindow(nsIWidget* widget, const EGLConfig& config) {
|
|
|
|
EGLSurface newSurface = EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
#ifdef MOZ_ANDROID_OMTC
|
|
|
|
mozilla::AndroidBridge::Bridge()->RegisterCompositor();
|
2013-11-15 16:28:59 +00:00
|
|
|
newSurface = mozilla::AndroidBridge::Bridge()->CreateEGLSurfaceForCompositor();
|
2013-11-15 16:28:54 +00:00
|
|
|
if (newSurface == EGL_NO_SURFACE) {
|
|
|
|
return EGL_NO_SURFACE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
MOZ_ASSERT(widget != nullptr);
|
|
|
|
newSurface = sEGLLibrary.fCreateWindowSurface(EGL_DISPLAY(), config, GET_NATIVE_WINDOW(widget), 0);
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
gScreenBounds.x = 0;
|
|
|
|
gScreenBounds.y = 0;
|
|
|
|
sEGLLibrary.fQuerySurface(EGL_DISPLAY(), newSurface, LOCAL_EGL_WIDTH, &gScreenBounds.width);
|
|
|
|
sEGLLibrary.fQuerySurface(EGL_DISPLAY(), newSurface, LOCAL_EGL_HEIGHT, &gScreenBounds.height);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
return newSurface;
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextEGL::GLContextEGL(
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
GLContext* shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
EGLConfig config,
|
|
|
|
EGLSurface surface,
|
|
|
|
EGLContext context)
|
|
|
|
: GLContext(caps, shareContext, isOffscreen)
|
|
|
|
, mConfig(config)
|
|
|
|
, mSurface(surface)
|
|
|
|
, mSurfaceOverride(EGL_NO_SURFACE)
|
|
|
|
, mContext(context)
|
|
|
|
, mThebesSurface(nullptr)
|
|
|
|
, mBound(false)
|
|
|
|
, mIsPBuffer(false)
|
|
|
|
, mIsDoubleBuffered(false)
|
|
|
|
, mCanBindToTexture(false)
|
|
|
|
, mShareWithEGLImage(false)
|
2010-06-09 22:27:29 +00:00
|
|
|
{
|
2014-01-07 20:02:18 +00:00
|
|
|
// any EGL contexts will always be GLESv2
|
|
|
|
SetProfileVersion(ContextProfile::OpenGLES, 200);
|
2010-09-09 20:40:11 +00:00
|
|
|
|
2012-02-21 21:15:39 +00:00
|
|
|
#ifdef DEBUG
|
2014-01-07 20:02:18 +00:00
|
|
|
printf_stderr("Initializing context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
|
2012-08-24 19:42:45 +00:00
|
|
|
#endif
|
2013-09-11 13:10:33 +00:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!mIsOffscreen) {
|
|
|
|
mHwc = HwcComposer2D::GetInstance();
|
|
|
|
MOZ_ASSERT(!mHwc->Initialized());
|
2012-08-24 19:42:45 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (mHwc->Init(EGL_DISPLAY(), mSurface)) {
|
|
|
|
NS_WARNING("HWComposer initialization failed!");
|
|
|
|
mHwc = nullptr;
|
2012-08-24 19:42:45 +00:00
|
|
|
}
|
2010-08-07 05:09:18 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
GLContextEGL::~GLContextEGL()
|
|
|
|
{
|
|
|
|
MarkDestroyed();
|
2010-08-07 05:09:18 +00:00
|
|
|
|
2012-02-21 21:15:39 +00:00
|
|
|
#ifdef DEBUG
|
2014-01-07 20:02:18 +00:00
|
|
|
printf_stderr("Destroying context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
|
2010-09-13 15:53:52 +00:00
|
|
|
#endif
|
2010-09-09 20:40:11 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
sEGLLibrary.fDestroyContext(EGL_DISPLAY(), mContext);
|
|
|
|
mozilla::gl::DestroySurface(mSurface);
|
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::Init()
|
|
|
|
{
|
2012-02-29 21:55:46 +00:00
|
|
|
#if defined(ANDROID)
|
2014-01-07 20:02:18 +00:00
|
|
|
// We can't use LoadApitraceLibrary here because the GLContext
|
|
|
|
// expects its own handle to the GL library
|
|
|
|
if (!OpenLibrary(APITRACE_LIB))
|
2012-02-29 21:55:46 +00:00
|
|
|
#endif
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!OpenLibrary(GLES2_LIB)) {
|
2012-01-20 14:18:56 +00:00
|
|
|
#if defined(XP_UNIX)
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!OpenLibrary(GLES2_LIB2)) {
|
|
|
|
NS_WARNING("Couldn't load GLES2 LIB.");
|
|
|
|
return false;
|
2012-02-29 21:55:46 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
#endif
|
2011-08-31 14:27:05 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
SetupLookupFunction();
|
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
2012-06-01 01:30:08 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool current = MakeCurrent();
|
|
|
|
if (!current) {
|
|
|
|
gfx::LogFailure(NS_LITERAL_CSTRING(
|
|
|
|
"Couldn't get device attachments for device."));
|
|
|
|
return false;
|
2010-09-09 20:40:11 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
PR_STATIC_ASSERT(sizeof(GLint) >= sizeof(int32_t));
|
|
|
|
mMaxTextureImageSize = INT32_MAX;
|
2010-09-09 20:40:11 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
mShareWithEGLImage = sEGLLibrary.HasKHRImageBase() &&
|
|
|
|
sEGLLibrary.HasKHRImageTexture2D() &&
|
|
|
|
IsExtensionSupported(OES_EGL_image);
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-12-15 00:57:09 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::BindTexImage()
|
|
|
|
{
|
|
|
|
if (!mSurface)
|
|
|
|
return false;
|
2011-11-19 03:57:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (mBound && !ReleaseTexImage())
|
|
|
|
return false;
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
EGLBoolean success = sEGLLibrary.fBindTexImage(EGL_DISPLAY(),
|
|
|
|
(EGLSurface)mSurface, LOCAL_EGL_BACK_BUFFER);
|
|
|
|
if (success == LOCAL_EGL_FALSE)
|
|
|
|
return false;
|
2010-06-24 10:04:28 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
mBound = true;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::ReleaseTexImage()
|
|
|
|
{
|
|
|
|
if (!mBound)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!mSurface)
|
|
|
|
return false;
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
EGLBoolean success;
|
|
|
|
success = sEGLLibrary.fReleaseTexImage(EGL_DISPLAY(),
|
|
|
|
(EGLSurface)mSurface,
|
|
|
|
LOCAL_EGL_BACK_BUFFER);
|
|
|
|
if (success == LOCAL_EGL_FALSE)
|
|
|
|
return false;
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
mBound = false;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-23 09:24:31 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
void
|
|
|
|
GLContextEGL::SetEGLSurfaceOverride(EGLSurface surf) {
|
|
|
|
if (Screen()) {
|
|
|
|
/* Blit `draw` to `read` if we need to, before we potentially juggle
|
|
|
|
* `read` around. If we don't, we might attach a different `read`,
|
|
|
|
* and *then* hit AssureBlitted, which will blit a dirty `draw` onto
|
|
|
|
* the wrong `read`!
|
|
|
|
*/
|
|
|
|
Screen()->AssureBlitted();
|
2010-06-23 09:24:31 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
mSurfaceOverride = surf ? (EGLSurface) surf : mSurface;
|
|
|
|
MakeCurrent(true);
|
|
|
|
}
|
2013-02-13 23:26:24 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::MakeCurrentImpl(bool aForce) {
|
|
|
|
bool succeeded = true;
|
|
|
|
|
|
|
|
// Assume that EGL has the same problem as WGL does,
|
|
|
|
// where MakeCurrent with an already-current context is
|
|
|
|
// still expensive.
|
|
|
|
if (aForce || sEGLLibrary.fGetCurrentContext() != mContext) {
|
|
|
|
EGLSurface surface = mSurfaceOverride != EGL_NO_SURFACE
|
|
|
|
? mSurfaceOverride
|
|
|
|
: mSurface;
|
2014-01-17 23:10:54 +00:00
|
|
|
if (surface == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
|
|
|
|
surface, surface,
|
|
|
|
mContext);
|
|
|
|
int eglError = sEGLLibrary.fGetError();
|
|
|
|
if (!succeeded) {
|
|
|
|
if (eglError == LOCAL_EGL_CONTEXT_LOST) {
|
|
|
|
mContextLost = true;
|
|
|
|
NS_WARNING("EGL context has been lost.");
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to make GL context current!");
|
2012-08-01 18:57:54 +00:00
|
|
|
#ifdef DEBUG
|
2014-01-07 20:02:18 +00:00
|
|
|
printf_stderr("EGL Error: 0x%04x\n", eglError);
|
2012-08-01 18:57:54 +00:00
|
|
|
#endif
|
2012-05-12 23:23:56 +00:00
|
|
|
}
|
2010-06-23 08:02:12 +00:00
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
GLContextEGL::IsCurrent() {
|
|
|
|
return sEGLLibrary.fGetCurrentContext() == mContext;
|
|
|
|
}
|
2012-08-22 03:30:20 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::RenewSurface() {
|
2013-11-15 16:28:54 +00:00
|
|
|
#ifndef MOZ_WIDGET_ANDROID
|
2014-01-07 20:02:18 +00:00
|
|
|
MOZ_CRASH("unimplemented");
|
|
|
|
// to support this on non-Android platforms, need to keep track of the nsIWidget that
|
|
|
|
// this GLContext was created for (with CreateForWindow) so that we know what to
|
|
|
|
// pass again to CreateSurfaceForWindow below.
|
|
|
|
// The reason why Android doesn't need this is that it delegates EGLSurface creation to
|
|
|
|
// Java code which is the only thing that knows about our actual widget.
|
2012-05-29 17:46:37 +00:00
|
|
|
#endif
|
2014-01-07 20:02:18 +00:00
|
|
|
// unconditionally release the surface and create a new one. Don't try to optimize this away.
|
|
|
|
// If we get here, then by definition we know that we want to get a new surface.
|
|
|
|
ReleaseSurface();
|
|
|
|
mSurface = mozilla::gl::CreateSurfaceForWindow(nullptr, mConfig); // the nullptr here is where we assume Android.
|
|
|
|
if (mSurface == EGL_NO_SURFACE) {
|
|
|
|
return false;
|
2010-12-13 22:36:35 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
return MakeCurrent(true);
|
|
|
|
}
|
2010-12-13 22:36:35 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
void
|
|
|
|
GLContextEGL::ReleaseSurface() {
|
|
|
|
DestroySurface(mSurface);
|
2014-01-17 23:10:54 +00:00
|
|
|
mSurface = EGL_NO_SURFACE;
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
2011-08-23 20:48:27 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::SetupLookupFunction()
|
|
|
|
{
|
|
|
|
mLookupFunc = (PlatformLookupFunction)sEGLLibrary.mSymbols.fGetProcAddress;
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
bool
|
|
|
|
GLContextEGL::SwapBuffers()
|
|
|
|
{
|
|
|
|
if (mSurface) {
|
2012-08-24 19:42:45 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!mIsOffscreen) {
|
|
|
|
if (mHwc) {
|
|
|
|
return mHwc->Render(EGL_DISPLAY(), mSurface);
|
|
|
|
} else {
|
|
|
|
return GetGonkDisplay()->SwapBuffers(EGL_DISPLAY(), mSurface);
|
|
|
|
}
|
|
|
|
} else
|
2012-08-24 19:42:45 +00:00
|
|
|
#endif
|
2014-01-07 20:02:18 +00:00
|
|
|
return sEGLLibrary.fSwapBuffers(EGL_DISPLAY(), mSurface);
|
|
|
|
} else {
|
|
|
|
return false;
|
2010-06-26 00:52:37 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
}
|
2013-12-03 18:44:38 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
// hold a reference to the given surface
|
|
|
|
// for the lifetime of this context.
|
|
|
|
void
|
|
|
|
GLContextEGL::HoldSurface(gfxASurface *aSurf) {
|
|
|
|
mThebesSurface = aSurf;
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
already_AddRefed<GLContextEGL>
|
|
|
|
GLContextEGL::CreateGLContext(const SurfaceCaps& caps,
|
|
|
|
GLContextEGL *shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
EGLConfig config,
|
|
|
|
EGLSurface surface)
|
|
|
|
{
|
|
|
|
if (sEGLLibrary.fBindAPI(LOCAL_EGL_OPENGL_ES_API) == LOCAL_EGL_FALSE) {
|
|
|
|
NS_WARNING("Failed to bind API to GLES!");
|
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
EGLContext eglShareContext = shareContext ? shareContext->mContext
|
|
|
|
: EGL_NO_CONTEXT;
|
|
|
|
EGLint* attribs = sEGLLibrary.HasRobustness() ? gContextAttribsRobustness
|
|
|
|
: gContextAttribs;
|
|
|
|
|
|
|
|
EGLContext context = sEGLLibrary.fCreateContext(EGL_DISPLAY(),
|
|
|
|
config,
|
|
|
|
eglShareContext,
|
|
|
|
attribs);
|
|
|
|
if (!context && shareContext) {
|
|
|
|
shareContext = nullptr;
|
|
|
|
context = sEGLLibrary.fCreateContext(EGL_DISPLAY(),
|
|
|
|
config,
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
attribs);
|
|
|
|
}
|
|
|
|
if (!context) {
|
|
|
|
NS_WARNING("Failed to create EGLContext!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-01-06 22:07:12 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
nsRefPtr<GLContextEGL> glContext = new GLContextEGL(caps,
|
|
|
|
shareContext,
|
|
|
|
isOffscreen,
|
|
|
|
config,
|
|
|
|
surface,
|
|
|
|
context);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (!glContext->Init())
|
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
EGLSurface
|
|
|
|
GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
|
|
|
|
EGLenum bindToTextureFormat,
|
|
|
|
gfxIntSize& pbsize)
|
|
|
|
{
|
|
|
|
nsTArray<EGLint> pbattrs(16);
|
|
|
|
EGLSurface surface = nullptr;
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
TRY_AGAIN_POWER_OF_TWO:
|
|
|
|
pbattrs.Clear();
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_WIDTH); pbattrs.AppendElement(pbsize.width);
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_HEIGHT); pbattrs.AppendElement(pbsize.height);
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
if (bindToTextureFormat != LOCAL_EGL_NONE) {
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_TARGET);
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_2D);
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_FORMAT);
|
|
|
|
pbattrs.AppendElement(bindToTextureFormat);
|
|
|
|
}
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
for (size_t i = 0; i < MOZ_ARRAY_LENGTH(gTerminationAttribs); i++) {
|
|
|
|
pbattrs.AppendElement(gTerminationAttribs[i]);
|
|
|
|
}
|
2011-01-31 21:10:57 +00:00
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
surface = sEGLLibrary.fCreatePbufferSurface(EGL_DISPLAY(), config, &pbattrs[0]);
|
|
|
|
if (!surface) {
|
|
|
|
if (!is_power_of_two(pbsize.width) ||
|
|
|
|
!is_power_of_two(pbsize.height))
|
|
|
|
{
|
|
|
|
if (!is_power_of_two(pbsize.width))
|
|
|
|
pbsize.width = next_power_of_two(pbsize.width);
|
|
|
|
if (!is_power_of_two(pbsize.height))
|
|
|
|
pbsize.height = next_power_of_two(pbsize.height);
|
|
|
|
|
|
|
|
NS_WARNING("Failed to create pbuffer, trying power of two dims");
|
|
|
|
goto TRY_AGAIN_POWER_OF_TWO;
|
2011-01-31 21:10:57 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 20:02:18 +00:00
|
|
|
NS_WARNING("Failed to create pbuffer surface");
|
|
|
|
return nullptr;
|
2011-01-31 21:10:57 +00:00
|
|
|
}
|
2014-01-07 20:02:18 +00:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
static const EGLint kEGLConfigAttribsOffscreenPBuffer[] = {
|
|
|
|
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_PBUFFER_BIT,
|
|
|
|
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
|
2014-03-14 15:24:58 +00:00
|
|
|
// Old versions of llvmpipe seem to need this to properly create the pbuffer (bug 981856)
|
|
|
|
LOCAL_EGL_RED_SIZE, 8,
|
|
|
|
LOCAL_EGL_GREEN_SIZE, 8,
|
|
|
|
LOCAL_EGL_BLUE_SIZE, 8,
|
|
|
|
LOCAL_EGL_ALPHA_SIZE, 0,
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2013-02-13 23:26:24 +00:00
|
|
|
};
|
|
|
|
|
2011-09-23 05:58:15 +00:00
|
|
|
static const EGLint kEGLConfigAttribsRGB16[] = {
|
|
|
|
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_WINDOW_BIT,
|
|
|
|
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
|
|
|
|
LOCAL_EGL_RED_SIZE, 5,
|
|
|
|
LOCAL_EGL_GREEN_SIZE, 6,
|
|
|
|
LOCAL_EGL_BLUE_SIZE, 5,
|
|
|
|
LOCAL_EGL_ALPHA_SIZE, 0,
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2011-09-23 05:58:15 +00:00
|
|
|
};
|
|
|
|
|
2012-07-07 14:06:59 +00:00
|
|
|
static const EGLint kEGLConfigAttribsRGB24[] = {
|
|
|
|
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_WINDOW_BIT,
|
|
|
|
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
|
|
|
|
LOCAL_EGL_RED_SIZE, 8,
|
|
|
|
LOCAL_EGL_GREEN_SIZE, 8,
|
|
|
|
LOCAL_EGL_BLUE_SIZE, 8,
|
2013-02-13 23:26:24 +00:00
|
|
|
LOCAL_EGL_ALPHA_SIZE, 0,
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2012-07-07 14:06:59 +00:00
|
|
|
};
|
2011-09-23 05:58:15 +00:00
|
|
|
|
|
|
|
static const EGLint kEGLConfigAttribsRGBA32[] = {
|
|
|
|
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_WINDOW_BIT,
|
|
|
|
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
|
|
|
|
LOCAL_EGL_RED_SIZE, 8,
|
|
|
|
LOCAL_EGL_GREEN_SIZE, 8,
|
|
|
|
LOCAL_EGL_BLUE_SIZE, 8,
|
|
|
|
LOCAL_EGL_ALPHA_SIZE, 8,
|
2013-05-08 03:58:22 +00:00
|
|
|
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
|
|
|
LOCAL_EGL_FRAMEBUFFER_TARGET_ANDROID, LOCAL_EGL_TRUE,
|
|
|
|
#endif
|
2013-12-13 20:15:07 +00:00
|
|
|
EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|
2011-09-23 05:58:15 +00:00
|
|
|
};
|
2010-06-26 00:52:37 +00:00
|
|
|
|
2011-09-23 05:58:15 +00:00
|
|
|
static bool
|
2012-08-22 15:56:38 +00:00
|
|
|
CreateConfig(EGLConfig* aConfig, int32_t depth)
|
2011-09-23 05:58:15 +00:00
|
|
|
{
|
2010-07-19 05:01:14 +00:00
|
|
|
EGLConfig configs[64];
|
2012-07-07 14:06:59 +00:00
|
|
|
const EGLint* attribs;
|
2012-03-09 00:01:12 +00:00
|
|
|
EGLint ncfg = ArrayLength(configs);
|
|
|
|
|
2012-07-07 14:06:59 +00:00
|
|
|
switch (depth) {
|
|
|
|
case 16:
|
|
|
|
attribs = kEGLConfigAttribsRGB16;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
attribs = kEGLConfigAttribsRGB24;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
attribs = kEGLConfigAttribsRGBA32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown pixel depth");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-09 00:01:12 +00:00
|
|
|
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs,
|
|
|
|
configs, ncfg, &ncfg) ||
|
|
|
|
ncfg < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2012-03-09 00:01:12 +00:00
|
|
|
for (int j = 0; j < ncfg; ++j) {
|
|
|
|
EGLConfig config = configs[j];
|
|
|
|
EGLint r, g, b, a;
|
|
|
|
|
|
|
|
if (sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
|
|
|
|
LOCAL_EGL_RED_SIZE, &r) &&
|
|
|
|
sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
|
|
|
|
LOCAL_EGL_GREEN_SIZE, &g) &&
|
|
|
|
sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
|
|
|
|
LOCAL_EGL_BLUE_SIZE, &b) &&
|
|
|
|
sEGLLibrary.fGetConfigAttrib(EGL_DISPLAY(), config,
|
|
|
|
LOCAL_EGL_ALPHA_SIZE, &a) &&
|
|
|
|
((depth == 16 && r == 5 && g == 6 && b == 5) ||
|
2012-07-07 14:06:59 +00:00
|
|
|
(depth == 24 && r == 8 && g == 8 && b == 8) ||
|
|
|
|
(depth == 32 && r == 8 && g == 8 && b == 8 && a == 8)))
|
2011-09-23 05:58:15 +00:00
|
|
|
{
|
2012-03-09 00:01:12 +00:00
|
|
|
*aConfig = config;
|
|
|
|
return true;
|
2010-09-09 20:40:11 +00:00
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2011-09-23 05:58:15 +00:00
|
|
|
return false;
|
2010-12-13 22:36:35 +00:00
|
|
|
}
|
|
|
|
|
2012-03-30 02:47:22 +00:00
|
|
|
// Return true if a suitable EGLConfig was found and pass it out
|
|
|
|
// through aConfig. Return false otherwise.
|
|
|
|
//
|
|
|
|
// NB: It's entirely legal for the returned EGLConfig to be valid yet
|
|
|
|
// have the value null.
|
|
|
|
static bool
|
|
|
|
CreateConfig(EGLConfig* aConfig)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t depth = gfxPlatform::GetPlatform()->GetScreenDepth();
|
2012-03-30 02:47:22 +00:00
|
|
|
if (!CreateConfig(aConfig, depth)) {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// Bug 736005
|
|
|
|
// Android doesn't always support 16 bit so also try 24 bit
|
|
|
|
if (depth == 16) {
|
|
|
|
return CreateConfig(aConfig, 24);
|
|
|
|
}
|
2014-02-24 22:17:34 +00:00
|
|
|
// Bug 970096
|
|
|
|
// Some devices that have 24 bit screens only support 16 bit OpenGL?
|
|
|
|
if (depth == 24) {
|
|
|
|
return CreateConfig(aConfig, 16);
|
|
|
|
}
|
2012-03-30 02:47:22 +00:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 22:36:35 +00:00
|
|
|
already_AddRefed<GLContext>
|
|
|
|
GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
|
|
|
|
{
|
|
|
|
if (!sEGLLibrary.EnsureInitialized()) {
|
2013-11-26 02:48:27 +00:00
|
|
|
MOZ_CRASH("Failed to load EGL library!\n");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-13 22:36:35 +00:00
|
|
|
}
|
|
|
|
|
2012-04-12 04:18:35 +00:00
|
|
|
bool doubleBuffered = true;
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
EGLConfig config;
|
2011-09-23 05:58:15 +00:00
|
|
|
if (!CreateConfig(&config)) {
|
2013-11-26 02:48:27 +00:00
|
|
|
MOZ_CRASH("Failed to create EGLConfig!\n");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-12-13 22:36:35 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 16:28:54 +00:00
|
|
|
EGLSurface surface = mozilla::gl::CreateSurfaceForWindow(aWidget, config);
|
2012-02-06 21:53:09 +00:00
|
|
|
|
2013-11-15 16:28:54 +00:00
|
|
|
if (surface == EGL_NO_SURFACE) {
|
2013-11-26 02:48:27 +00:00
|
|
|
MOZ_CRASH("Failed to create EGLSurface!\n");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps caps = SurfaceCaps::Any();
|
2011-06-10 01:18:43 +00:00
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextEGL::CreateGLContext(caps,
|
2013-10-11 13:16:44 +00:00
|
|
|
nullptr, false,
|
2013-02-13 23:26:24 +00:00
|
|
|
config, surface);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2011-06-10 01:18:43 +00:00
|
|
|
if (!glContext) {
|
2013-11-26 02:48:27 +00:00
|
|
|
MOZ_CRASH("Failed to create EGLContext!\n");
|
2013-11-15 16:28:54 +00:00
|
|
|
DestroySurface(surface);
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 04:20:27 +00:00
|
|
|
glContext->MakeCurrent();
|
2012-04-12 04:18:35 +00:00
|
|
|
glContext->SetIsDoubleBuffered(doubleBuffered);
|
2010-09-09 20:40:11 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
return glContext.forget();
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
already_AddRefed<GLContextEGL>
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextEGL::CreateEGLPBufferOffscreenContext(const gfxIntSize& size)
|
2010-06-09 22:27:29 +00:00
|
|
|
{
|
|
|
|
EGLConfig config;
|
|
|
|
EGLSurface surface;
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
const EGLint numConfigs = 1; // We only need one.
|
|
|
|
EGLConfig configs[numConfigs];
|
|
|
|
EGLint foundConfigs = 0;
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(),
|
2013-02-13 23:26:24 +00:00
|
|
|
kEGLConfigAttribsOffscreenPBuffer,
|
2010-07-19 05:01:14 +00:00
|
|
|
configs, numConfigs,
|
2011-01-31 21:10:54 +00:00
|
|
|
&foundConfigs)
|
|
|
|
|| foundConfigs == 0)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
NS_WARNING("No EGL Config for minimal PBuffer!");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
// We absolutely don't care, so just pick the first one.
|
2010-06-09 22:27:29 +00:00
|
|
|
config = configs[0];
|
2013-02-13 23:26:24 +00:00
|
|
|
if (GLContext::DebugMode())
|
|
|
|
sEGLLibrary.DumpEGLConfig(config);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxIntSize pbSize(size);
|
2011-01-31 21:10:57 +00:00
|
|
|
surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(config,
|
2013-02-13 23:26:24 +00:00
|
|
|
LOCAL_EGL_NONE,
|
|
|
|
pbSize);
|
2012-03-12 22:10:38 +00:00
|
|
|
if (!surface) {
|
|
|
|
NS_WARNING("Failed to create PBuffer for context!");
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-03-12 22:10:38 +00:00
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
|
|
|
GLContextEGL::CreateGLContext(dummyCaps,
|
2013-10-11 13:16:44 +00:00
|
|
|
nullptr, true,
|
2013-02-13 23:26:24 +00:00
|
|
|
config, surface);
|
|
|
|
if (!glContext) {
|
2012-03-12 22:10:38 +00:00
|
|
|
NS_WARNING("Failed to create GLContext from PBuffer");
|
2010-07-19 05:01:14 +00:00
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
if (!glContext->Init()) {
|
2012-03-12 22:10:38 +00:00
|
|
|
NS_WARNING("Failed to initialize GLContext!");
|
2013-02-13 23:26:24 +00:00
|
|
|
// GLContextEGL::dtor will destroy |surface| for us.
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2010-06-09 22:27:29 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<GLContextEGL>
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextEGL::CreateEGLPixmapOffscreenContext(const gfxIntSize& size)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
gfxASurface *thebesSurface = nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
EGLNativePixmapType pixmap = 0;
|
|
|
|
|
|
|
|
if (!pixmap) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-06 22:07:12 +00:00
|
|
|
EGLSurface surface = 0;
|
2010-07-19 05:01:14 +00:00
|
|
|
EGLConfig config = 0;
|
|
|
|
|
2010-10-04 11:21:32 +00:00
|
|
|
if (!config) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
2013-02-13 23:26:24 +00:00
|
|
|
MOZ_ASSERT(surface);
|
2010-07-19 05:01:14 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2013-02-21 19:54:25 +00:00
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
2013-02-28 04:56:29 +00:00
|
|
|
GLContextEGL::CreateGLContext(dummyCaps,
|
2013-10-11 13:16:44 +00:00
|
|
|
nullptr, true,
|
2013-02-28 04:56:29 +00:00
|
|
|
config, surface);
|
2013-02-13 23:26:24 +00:00
|
|
|
if (!glContext) {
|
|
|
|
NS_WARNING("Failed to create GLContext from XSurface");
|
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!glContext->Init()) {
|
|
|
|
NS_WARNING("Failed to initialize GLContext!");
|
|
|
|
// GLContextEGL::dtor will destroy |surface| for us.
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-07-19 05:01:14 +00:00
|
|
|
|
|
|
|
glContext->HoldSurface(thebesSurface);
|
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-25 23:56:53 +00:00
|
|
|
// Under EGL, on Android, pbuffers are supported fine, though
|
2010-07-19 05:01:14 +00:00
|
|
|
// often without the ability to texture from them directly.
|
|
|
|
already_AddRefed<GLContext>
|
2013-02-13 23:26:24 +00:00
|
|
|
GLContextProviderEGL::CreateOffscreen(const gfxIntSize& size,
|
2014-01-10 18:55:23 +00:00
|
|
|
const SurfaceCaps& caps)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
|
|
|
if (!sEGLLibrary.EnsureInitialized()) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
nsRefPtr<GLContextEGL> glContext;
|
|
|
|
glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
|
2011-10-19 19:09:57 +00:00
|
|
|
|
|
|
|
if (!glContext)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-10-19 19:09:57 +00:00
|
|
|
|
2014-01-01 19:47:19 +00:00
|
|
|
if (!glContext->InitOffscreen(ToIntSize(size), caps))
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-03-02 17:28:06 +00:00
|
|
|
|
2011-06-10 01:18:43 +00:00
|
|
|
return glContext.forget();
|
2010-06-09 22:27:29 +00:00
|
|
|
}
|
|
|
|
|
2012-06-14 15:59:40 +00:00
|
|
|
// Don't want a global context on Android as 1) share groups across 2 threads fail on many Tegra drivers (bug 759225)
|
|
|
|
// and 2) some mobile devices have a very strict limit on global number of GL contexts (bug 754257)
|
2012-11-21 02:45:13 +00:00
|
|
|
// and 3) each EGL context eats 750k on B2G (bug 813783)
|
2012-11-22 18:53:11 +00:00
|
|
|
GLContext *
|
2014-01-10 18:55:23 +00:00
|
|
|
GLContextProviderEGL::GetGlobalContext()
|
2012-11-22 18:53:11 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 04:05:42 +00:00
|
|
|
void
|
|
|
|
GLContextProviderEGL::Shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-09 22:27:29 +00:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|
2013-12-13 20:15:07 +00:00
|
|
|
#undef EGL_ATTRIBS_LIST_SAFE_TERMINATION_WORKING_AROUND_BUGS
|