2010-06-09 15:27:29 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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 15:27:29 -07:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
#include "mozilla/Util.h"
|
2012-03-08 16:01:12 -08:00
|
|
|
|
2011-08-24 09:15:58 -07:00
|
|
|
#if defined(XP_UNIX)
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2010-06-09 15:27:29 -07: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))
|
2011-11-10 16:17:46 -08:00
|
|
|
#elif defined(MOZ_WIDGET_GONK)
|
|
|
|
#define GET_NATIVE_WINDOW(aWidget) ((EGLNativeWindowType)aWidget->GetNativeData(NS_NATIVE_WINDOW))
|
2012-11-19 09:58:38 -08:00
|
|
|
#include "HwcComposer2D.h"
|
2013-05-07 20:58:22 -07:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
2010-06-09 15:27:29 -07:00
|
|
|
#endif
|
|
|
|
|
2011-08-24 09:15:58 -07:00
|
|
|
#if defined(ANDROID)
|
2010-06-25 17:52:37 -07:00
|
|
|
/* from widget */
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-06-25 17:52:37 -07:00
|
|
|
#include "AndroidBridge.h"
|
2012-07-20 12:20:51 -07:00
|
|
|
#include "nsSurfaceTexture.h"
|
2011-11-10 16:17:46 -08:00
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#include <android/log.h>
|
2012-06-12 21:20:27 -07: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 06:18:56 -08:00
|
|
|
#endif
|
|
|
|
|
2012-01-12 22:23:02 -08:00
|
|
|
#define GLES2_LIB "libGLESv2.so"
|
2012-01-20 06:18:56 -08:00
|
|
|
#define GLES2_LIB2 "libGLESv2.so.2"
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
#include "nsIFile.h"
|
2010-08-06 22:09:18 -07:00
|
|
|
|
2012-03-16 15:24:12 -07:00
|
|
|
#define GLES2_LIB "libGLESv2.dll"
|
|
|
|
|
2010-08-06 22:09:18 -07: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 01:48:55 -07:00
|
|
|
AutoDestroyHWND(HWND aWnd = nullptr)
|
2010-08-06 22:09:18 -07:00
|
|
|
: mWnd(aWnd)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoDestroyHWND() {
|
|
|
|
if (mWnd) {
|
|
|
|
::DestroyWindow(mWnd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
operator HWND() {
|
|
|
|
return mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND forget() {
|
|
|
|
HWND w = mWnd;
|
2013-07-20 01:48:55 -07:00
|
|
|
mWnd = nullptr;
|
2010-08-06 22:09:18 -07:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND operator=(HWND aWnd) {
|
|
|
|
if (mWnd && mWnd != aWnd) {
|
|
|
|
::DestroyWindow(mWnd);
|
|
|
|
}
|
|
|
|
mWnd = aWnd;
|
|
|
|
return mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND mWnd;
|
|
|
|
};
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
#else
|
|
|
|
|
|
|
|
#error "Platform not recognized"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2012-03-12 08:43:14 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-01-13 05:20:50 -08:00
|
|
|
#include "gfxUtils.h"
|
2011-08-31 07:27:05 -07:00
|
|
|
#include "gfxFailure.h"
|
2010-06-23 08:50:51 -07:00
|
|
|
#include "gfxASurface.h"
|
2010-09-09 13:40:11 -07:00
|
|
|
#include "gfxImageSurface.h"
|
2010-07-01 09:30:38 -07:00
|
|
|
#include "gfxPlatform.h"
|
2010-06-09 15:27:29 -07:00
|
|
|
#include "GLContextProvider.h"
|
2012-03-16 15:24:12 -07:00
|
|
|
#include "GLLibraryEGL.h"
|
2013-10-11 06:16:44 -07:00
|
|
|
#include "TextureImageEGL.h"
|
2010-06-09 15:27:29 -07:00
|
|
|
#include "nsDebug.h"
|
2010-11-26 13:41:53 -08:00
|
|
|
#include "nsThreadUtils.h"
|
2010-06-09 15:27:29 -07:00
|
|
|
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2011-03-02 12:50:36 -08:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
|
|
|
|
2013-11-30 14:20:57 -08:00
|
|
|
#include "ScopedGLHelpers.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
|
2013-07-04 10:25:50 -07:00
|
|
|
using namespace mozilla::gfx;
|
2012-07-20 12:20:51 -07:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
extern nsIntRect gScreenBounds;
|
|
|
|
#endif
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2011-01-06 14:07:12 -08: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-22 22:58:15 -07:00
|
|
|
static bool
|
|
|
|
CreateConfig(EGLConfig* aConfig);
|
2010-12-13 14:36:35 -08:00
|
|
|
|
2011-12-14 16:57:09 -08:00
|
|
|
static EGLint gContextAttribs[] = {
|
|
|
|
LOCAL_EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
|
|
|
|
2010-07-18 22:01:14 -07: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 08:28:54 -08: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 08:28:59 -08:00
|
|
|
newSurface = mozilla::AndroidBridge::Bridge()->CreateEGLSurfaceForCompositor();
|
2013-11-15 08:28:54 -08: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;
|
|
|
|
}
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
class GLContextEGL : public GLContext
|
|
|
|
{
|
2010-07-01 09:30:38 -07:00
|
|
|
friend class TextureImageEGL;
|
|
|
|
|
2011-06-09 18:18:43 -07:00
|
|
|
static already_AddRefed<GLContextEGL>
|
2013-02-13 15:26:24 -08:00
|
|
|
CreateGLContext(const SurfaceCaps& caps,
|
2013-02-21 11:54:25 -08:00
|
|
|
GLContextEGL *shareContext,
|
2013-02-13 15:26:24 -08:00
|
|
|
bool isOffscreen,
|
|
|
|
EGLConfig config,
|
|
|
|
EGLSurface surface)
|
2011-06-09 18:18:43 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
if (sEGLLibrary.fBindAPI(LOCAL_EGL_OPENGL_ES_API) == LOCAL_EGL_FALSE) {
|
|
|
|
NS_WARNING("Failed to bind API to GLES!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2013-02-27 20:56:29 -08:00
|
|
|
}
|
|
|
|
if (!context) {
|
|
|
|
NS_WARNING("Failed to create EGLContext!");
|
|
|
|
return nullptr;
|
2011-06-09 18:18:43 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
nsRefPtr<GLContextEGL> glContext = new GLContextEGL(caps,
|
|
|
|
shareContext,
|
|
|
|
isOffscreen,
|
|
|
|
config,
|
|
|
|
surface,
|
|
|
|
context);
|
2011-06-09 18:18:43 -07:00
|
|
|
|
|
|
|
if (!glContext->Init())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-09 18:18:43 -07:00
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
public:
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextEGL(const SurfaceCaps& caps,
|
|
|
|
GLContext* shareContext,
|
|
|
|
bool isOffscreen,
|
|
|
|
EGLConfig config,
|
|
|
|
EGLSurface surface,
|
|
|
|
EGLContext context)
|
|
|
|
: GLContext(caps, shareContext, isOffscreen)
|
|
|
|
, mConfig(config)
|
|
|
|
, mSurface(surface)
|
2013-11-15 08:28:38 -08:00
|
|
|
, mSurfaceOverride(EGL_NO_SURFACE)
|
2013-02-13 15:26:24 -08:00
|
|
|
, mContext(context)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mThebesSurface(nullptr)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mBound(false)
|
|
|
|
, mIsPBuffer(false)
|
|
|
|
, mIsDoubleBuffered(false)
|
2012-03-21 17:16:31 -07:00
|
|
|
, mCanBindToTexture(false)
|
2012-05-31 18:30:08 -07:00
|
|
|
, mShareWithEGLImage(false)
|
2010-08-06 22:09:18 -07:00
|
|
|
{
|
|
|
|
// any EGL contexts will always be GLESv2
|
2013-08-01 16:43:27 -07:00
|
|
|
SetProfileVersion(ContextProfile::OpenGLES, 200);
|
2010-09-09 13:40:11 -07:00
|
|
|
|
2012-02-21 13:15:39 -08:00
|
|
|
#ifdef DEBUG
|
2010-09-09 13:40:11 -07:00
|
|
|
printf_stderr("Initializing context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
|
2012-08-24 12:42:45 -07:00
|
|
|
#endif
|
2013-09-11 06:10:33 -07:00
|
|
|
#if defined(MOZ_WIDGET_GONK)
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!mIsOffscreen) {
|
2012-11-19 09:58:38 -08:00
|
|
|
mHwc = HwcComposer2D::GetInstance();
|
|
|
|
MOZ_ASSERT(!mHwc->Initialized());
|
2012-08-24 12:42:45 -07:00
|
|
|
|
2012-11-19 09:58:38 -08:00
|
|
|
if (mHwc->Init(EGL_DISPLAY(), mSurface)) {
|
|
|
|
NS_WARNING("HWComposer initialization failed!");
|
|
|
|
mHwc = nullptr;
|
|
|
|
}
|
2012-08-24 12:42:45 -07:00
|
|
|
}
|
2010-09-13 08:53:52 -07:00
|
|
|
#endif
|
2010-08-06 22:09:18 -07:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
|
|
|
~GLContextEGL()
|
|
|
|
{
|
2010-09-21 12:41:24 -07:00
|
|
|
MarkDestroyed();
|
2010-08-06 22:09:18 -07:00
|
|
|
|
2012-02-21 13:15:39 -08:00
|
|
|
#ifdef DEBUG
|
2010-09-09 13:40:11 -07:00
|
|
|
printf_stderr("Destroying context %p surface %p on display %p\n", mContext, mSurface, EGL_DISPLAY());
|
2010-09-13 08:53:52 -07:00
|
|
|
#endif
|
2010-09-09 13:40:11 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
sEGLLibrary.fDestroyContext(EGL_DISPLAY(), mContext);
|
2013-11-15 08:28:54 -08:00
|
|
|
mozilla::gl::DestroySurface(mSurface);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GLContextType GetContextType() {
|
|
|
|
return ContextTypeEGL;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Init()
|
2010-06-09 15:27:29 -07:00
|
|
|
{
|
2012-02-29 13:55:46 -08:00
|
|
|
#if defined(ANDROID)
|
|
|
|
// We can't use LoadApitraceLibrary here because the GLContext
|
|
|
|
// expects its own handle to the GL library
|
|
|
|
if (!OpenLibrary(APITRACE_LIB))
|
|
|
|
#endif
|
|
|
|
if (!OpenLibrary(GLES2_LIB)) {
|
2012-01-20 06:18:56 -08:00
|
|
|
#if defined(XP_UNIX)
|
2012-02-29 13:55:46 -08:00
|
|
|
if (!OpenLibrary(GLES2_LIB2)) {
|
|
|
|
NS_WARNING("Couldn't load GLES2 LIB.");
|
|
|
|
return false;
|
|
|
|
}
|
2012-01-20 06:18:56 -08:00
|
|
|
#endif
|
2012-02-29 13:55:46 -08:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2013-12-03 02:44:37 -08:00
|
|
|
SetupLookupFunction();
|
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool current = MakeCurrent();
|
2011-08-31 07:27:05 -07:00
|
|
|
if (!current) {
|
|
|
|
gfx::LogFailure(NS_LITERAL_CSTRING(
|
|
|
|
"Couldn't get device attachments for device."));
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-08-31 07:27:05 -07:00
|
|
|
}
|
|
|
|
|
2011-10-26 14:36:18 -07:00
|
|
|
PR_STATIC_ASSERT(sizeof(GLint) >= sizeof(int32_t));
|
2012-09-27 23:57:33 -07:00
|
|
|
mMaxTextureImageSize = INT32_MAX;
|
2011-12-14 16:57:09 -08:00
|
|
|
|
2012-05-31 18:30:08 -07:00
|
|
|
mShareWithEGLImage = sEGLLibrary.HasKHRImageBase() &&
|
|
|
|
sEGLLibrary.HasKHRImageTexture2D() &&
|
|
|
|
IsExtensionSupported(OES_EGL_image);
|
|
|
|
|
2013-03-04 16:44:31 -08:00
|
|
|
return true;
|
2010-09-09 13:40:11 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsDoubleBuffered() {
|
2010-09-09 13:40:11 -07:00
|
|
|
return mIsDoubleBuffered;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetIsDoubleBuffered(bool aIsDB) {
|
2010-09-09 13:40:11 -07:00
|
|
|
mIsDoubleBuffered = aIsDB;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
virtual EGLContext GetEGLContext() {
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GLLibraryEGL* GetLibraryEGL() {
|
|
|
|
return &sEGLLibrary;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-18 19:57:29 -08:00
|
|
|
bool SupportsRobustness()
|
|
|
|
{
|
2011-12-14 16:57:09 -08:00
|
|
|
return sEGLLibrary.HasRobustness();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsANGLE()
|
|
|
|
{
|
|
|
|
return sEGLLibrary.IsANGLE();
|
2011-11-18 19:57:29 -08:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool BindTexImage()
|
2010-06-23 02:24:31 -07:00
|
|
|
{
|
2010-06-24 03:04:28 -07:00
|
|
|
if (!mSurface)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-23 02:24:31 -07:00
|
|
|
|
2010-06-24 03:04:28 -07:00
|
|
|
if (mBound && !ReleaseTexImage())
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-24 03:04:28 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
EGLBoolean success = sEGLLibrary.fBindTexImage(EGL_DISPLAY(),
|
2010-06-24 03:04:28 -07:00
|
|
|
(EGLSurface)mSurface, LOCAL_EGL_BACK_BUFFER);
|
|
|
|
if (success == LOCAL_EGL_FALSE)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-23 02:24:31 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mBound = true;
|
|
|
|
return true;
|
2010-06-23 02:24:31 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ReleaseTexImage()
|
2010-06-23 02:24:31 -07:00
|
|
|
{
|
|
|
|
if (!mBound)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-23 02:24:31 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!mSurface)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-23 02:24:31 -07:00
|
|
|
|
2010-06-24 03:04:28 -07:00
|
|
|
EGLBoolean success;
|
2010-07-18 22:01:14 -07:00
|
|
|
success = sEGLLibrary.fReleaseTexImage(EGL_DISPLAY(),
|
|
|
|
(EGLSurface)mSurface,
|
|
|
|
LOCAL_EGL_BACK_BUFFER);
|
2010-06-24 03:04:28 -07:00
|
|
|
if (success == LOCAL_EGL_FALSE)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-06-23 02:24:31 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mBound = false;
|
|
|
|
return true;
|
2010-06-23 02:24:31 -07:00
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
EGLImage CreateEGLImageForNativeBuffer(void* buffer) MOZ_OVERRIDE
|
2012-07-16 19:12:58 -07:00
|
|
|
{
|
|
|
|
EGLint attrs[] = {
|
2012-07-19 21:14:14 -07:00
|
|
|
LOCAL_EGL_IMAGE_PRESERVED, LOCAL_EGL_TRUE,
|
2012-07-16 19:12:58 -07:00
|
|
|
LOCAL_EGL_NONE, LOCAL_EGL_NONE
|
|
|
|
};
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 02:20:52 -07:00
|
|
|
return sEGLLibrary.fCreateImage(EGL_DISPLAY(),
|
|
|
|
EGL_NO_CONTEXT,
|
|
|
|
LOCAL_EGL_NATIVE_BUFFER_ANDROID,
|
|
|
|
buffer, attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DestroyEGLImage(EGLImage image) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), image);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-15 09:33:51 -08:00
|
|
|
virtual void SetEGLSurfaceOverride(EGLSurface surf) MOZ_OVERRIDE {
|
2013-10-07 15:56:08 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-11-15 08:28:38 -08:00
|
|
|
mSurfaceOverride = surf ? (EGLSurface) surf : mSurface;
|
2013-02-13 15:26:24 -08:00
|
|
|
MakeCurrent(true);
|
|
|
|
}
|
|
|
|
|
2012-05-12 16:23:56 -07:00
|
|
|
bool MakeCurrentImpl(bool aForce = false) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool succeeded = true;
|
2010-06-23 01:02:12 -07:00
|
|
|
|
|
|
|
// Assume that EGL has the same problem as WGL does,
|
|
|
|
// where MakeCurrent with an already-current context is
|
|
|
|
// still expensive.
|
2012-05-12 16:23:56 -07:00
|
|
|
if (aForce || sEGLLibrary.fGetCurrentContext() != mContext) {
|
2013-11-15 08:28:38 -08:00
|
|
|
EGLSurface surface = mSurfaceOverride != EGL_NO_SURFACE
|
|
|
|
? mSurfaceOverride
|
|
|
|
: mSurface;
|
2012-05-12 16:23:56 -07:00
|
|
|
succeeded = sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
|
2013-11-15 08:28:38 -08:00
|
|
|
surface, surface,
|
2012-05-12 16:23:56 -07:00
|
|
|
mContext);
|
2012-08-01 11:57:54 -07:00
|
|
|
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!");
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf_stderr("EGL Error: 0x%04x\n", eglError);
|
|
|
|
#endif
|
|
|
|
}
|
2012-05-12 16:23:56 -07:00
|
|
|
}
|
2010-06-23 01:02:12 -07:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
2012-08-21 20:30:20 -07:00
|
|
|
virtual bool IsCurrent() {
|
|
|
|
return sEGLLibrary.fGetCurrentContext() == mContext;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool
|
2010-12-13 14:36:35 -08:00
|
|
|
RenewSurface() {
|
2013-11-15 08:28:54 -08:00
|
|
|
#ifndef MOZ_WIDGET_ANDROID
|
|
|
|
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 10:46:37 -07:00
|
|
|
#endif
|
2013-11-15 08:28:54 -08: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;
|
2012-06-12 07:24:31 -07:00
|
|
|
}
|
2013-11-15 08:28:54 -08:00
|
|
|
return MakeCurrent(true);
|
2010-12-13 14:36:35 -08:00
|
|
|
}
|
|
|
|
|
2011-08-23 13:48:27 -07:00
|
|
|
virtual void
|
|
|
|
ReleaseSurface() {
|
2013-11-15 08:28:54 -08:00
|
|
|
DestroySurface(mSurface);
|
|
|
|
mSurface = nullptr;
|
2011-08-23 13:48:27 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SetupLookupFunction()
|
2010-06-09 15:27:29 -07:00
|
|
|
{
|
2012-02-09 11:05:11 -08:00
|
|
|
mLookupFunc = (PlatformLookupFunction)sEGLLibrary.mSymbols.fGetProcAddress;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *GetNativeData(NativeDataType aType)
|
|
|
|
{
|
|
|
|
switch (aType) {
|
|
|
|
case NativeGLContext:
|
|
|
|
return mContext;
|
|
|
|
|
|
|
|
default:
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool SwapBuffers()
|
2010-06-25 17:52:37 -07:00
|
|
|
{
|
2013-11-15 08:28:36 -08:00
|
|
|
if (mSurface) {
|
2012-08-24 12:42:45 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-10-08 08:29:35 -07:00
|
|
|
if (!mIsOffscreen) {
|
|
|
|
if (mHwc) {
|
|
|
|
return mHwc->Render(EGL_DISPLAY(), mSurface);
|
|
|
|
} else {
|
|
|
|
return GetGonkDisplay()->SwapBuffers(EGL_DISPLAY(), mSurface);
|
|
|
|
}
|
|
|
|
} else
|
2012-08-24 12:42:45 -07:00
|
|
|
#endif
|
|
|
|
return sEGLLibrary.fSwapBuffers(EGL_DISPLAY(), mSurface);
|
2011-08-23 13:48:27 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2011-08-23 13:48:27 -07:00
|
|
|
}
|
2010-06-25 17:52:37 -07:00
|
|
|
}
|
2013-12-03 10:44:38 -08:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
// hold a reference to the given surface
|
|
|
|
// for the lifetime of this context.
|
|
|
|
void HoldSurface(gfxASurface *aSurf) {
|
|
|
|
mThebesSurface = aSurf;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGLContext Context() {
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool BindTex2DOffscreen(GLContext *aOffscreen);
|
2010-07-18 22:01:14 -07:00
|
|
|
void UnbindTex2DOffscreen(GLContext *aOffscreen);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ResizeOffscreen(const gfxIntSize& aNewSize);
|
2010-07-18 22:01:14 -07:00
|
|
|
void BindOffscreenFramebuffer();
|
|
|
|
|
|
|
|
static already_AddRefed<GLContextEGL>
|
2013-02-13 15:26:24 -08:00
|
|
|
CreateEGLPixmapOffscreenContext(const gfxIntSize& size);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
static already_AddRefed<GLContextEGL>
|
2013-02-13 15:26:24 -08:00
|
|
|
CreateEGLPBufferOffscreenContext(const gfxIntSize& size);
|
2011-01-06 14:07:12 -08:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
protected:
|
|
|
|
friend class GLContextProviderEGL;
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
EGLConfig mConfig;
|
|
|
|
EGLSurface mSurface;
|
2013-11-15 08:28:38 -08:00
|
|
|
EGLSurface mSurfaceOverride;
|
2010-06-09 15:27:29 -07:00
|
|
|
EGLContext mContext;
|
2010-07-18 22:01:14 -07:00
|
|
|
nsRefPtr<gfxASurface> mThebesSurface;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mBound;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsPBuffer;
|
|
|
|
bool mIsDoubleBuffered;
|
2012-03-21 17:16:31 -07:00
|
|
|
bool mCanBindToTexture;
|
2012-05-31 18:30:08 -07:00
|
|
|
bool mShareWithEGLImage;
|
2012-08-24 12:42:45 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2012-11-19 09:58:38 -08:00
|
|
|
nsRefPtr<HwcComposer2D> mHwc;
|
2012-08-24 12:42:45 -07:00
|
|
|
#endif
|
2011-01-31 13:10:57 -08:00
|
|
|
|
|
|
|
static EGLSurface CreatePBufferSurfaceTryingPowerOfTwo(EGLConfig config,
|
|
|
|
EGLenum bindToTextureFormat,
|
|
|
|
gfxIntSize& pbsize)
|
|
|
|
{
|
|
|
|
nsTArray<EGLint> pbattrs(16);
|
2012-07-30 07:20:58 -07:00
|
|
|
EGLSurface surface = nullptr;
|
2011-01-31 13:10:57 -08: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);
|
|
|
|
|
|
|
|
if (bindToTextureFormat != LOCAL_EGL_NONE) {
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_TARGET);
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_2D);
|
|
|
|
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_TEXTURE_FORMAT);
|
|
|
|
pbattrs.AppendElement(bindToTextureFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
pbattrs.AppendElement(LOCAL_EGL_NONE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Failed to create pbuffer surface");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-01-31 13:10:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
};
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-18 22:01:14 -07:00
|
|
|
GLContextEGL::ResizeOffscreen(const gfxIntSize& aNewSize)
|
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
return ResizeScreenBuffer(aNewSize);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
static const EGLint kEGLConfigAttribsOffscreenPBuffer[] = {
|
|
|
|
LOCAL_EGL_SURFACE_TYPE, LOCAL_EGL_PBUFFER_BIT,
|
|
|
|
LOCAL_EGL_RENDERABLE_TYPE, LOCAL_EGL_OPENGL_ES2_BIT,
|
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
|
|
|
|
2011-09-22 22:58:15 -07: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,
|
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
|
|
|
|
2012-07-07 07:06:59 -07: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 15:26:24 -08:00
|
|
|
LOCAL_EGL_ALPHA_SIZE, 0,
|
2012-07-07 07:06:59 -07:00
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
2011-09-22 22:58:15 -07: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-07 20:58:22 -07:00
|
|
|
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
|
|
|
|
LOCAL_EGL_FRAMEBUFFER_TARGET_ANDROID, LOCAL_EGL_TRUE,
|
|
|
|
#endif
|
2011-09-22 22:58:15 -07:00
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2011-09-22 22:58:15 -07:00
|
|
|
static bool
|
2012-08-22 08:56:38 -07:00
|
|
|
CreateConfig(EGLConfig* aConfig, int32_t depth)
|
2011-09-22 22:58:15 -07:00
|
|
|
{
|
2010-07-18 22:01:14 -07:00
|
|
|
EGLConfig configs[64];
|
2012-07-07 07:06:59 -07:00
|
|
|
const EGLint* attribs;
|
2012-03-08 16:01:12 -08:00
|
|
|
EGLint ncfg = ArrayLength(configs);
|
|
|
|
|
2012-07-07 07:06:59 -07: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-08 16:01:12 -08:00
|
|
|
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(), attribs,
|
|
|
|
configs, ncfg, &ncfg) ||
|
|
|
|
ncfg < 1) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2012-03-08 16:01:12 -08: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 07:06:59 -07:00
|
|
|
(depth == 24 && r == 8 && g == 8 && b == 8) ||
|
|
|
|
(depth == 32 && r == 8 && g == 8 && b == 8 && a == 8)))
|
2011-09-22 22:58:15 -07:00
|
|
|
{
|
2012-03-08 16:01:12 -08:00
|
|
|
*aConfig = config;
|
|
|
|
return true;
|
2010-09-09 13:40:11 -07:00
|
|
|
}
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2011-09-22 22:58:15 -07:00
|
|
|
return false;
|
2010-12-13 14:36:35 -08:00
|
|
|
}
|
|
|
|
|
2012-03-29 19:47:22 -07: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 08:56:38 -07:00
|
|
|
int32_t depth = gfxPlatform::GetPlatform()->GetScreenDepth();
|
2012-03-29 19:47:22 -07: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);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-13 14:36:35 -08:00
|
|
|
already_AddRefed<GLContext>
|
|
|
|
GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
|
|
|
|
{
|
|
|
|
if (!sEGLLibrary.EnsureInitialized()) {
|
2013-11-25 18:48:27 -08:00
|
|
|
MOZ_CRASH("Failed to load EGL library!\n");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-13 14:36:35 -08:00
|
|
|
}
|
|
|
|
|
2012-04-11 21:18:35 -07:00
|
|
|
bool doubleBuffered = true;
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
EGLConfig config;
|
2011-09-22 22:58:15 -07:00
|
|
|
if (!CreateConfig(&config)) {
|
2013-11-25 18:48:27 -08:00
|
|
|
MOZ_CRASH("Failed to create EGLConfig!\n");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-13 14:36:35 -08:00
|
|
|
}
|
|
|
|
|
2013-11-15 08:28:54 -08:00
|
|
|
EGLSurface surface = mozilla::gl::CreateSurfaceForWindow(aWidget, config);
|
2012-02-06 13:53:09 -08:00
|
|
|
|
2013-11-15 08:28:54 -08:00
|
|
|
if (surface == EGL_NO_SURFACE) {
|
2013-11-25 18:48:27 -08:00
|
|
|
MOZ_CRASH("Failed to create EGLSurface!\n");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps caps = SurfaceCaps::Any();
|
2011-06-09 18:18:43 -07:00
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextEGL::CreateGLContext(caps,
|
2013-10-11 06:16:44 -07:00
|
|
|
nullptr, false,
|
2013-02-13 15:26:24 -08:00
|
|
|
config, surface);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2011-06-09 18:18:43 -07:00
|
|
|
if (!glContext) {
|
2013-11-25 18:48:27 -08:00
|
|
|
MOZ_CRASH("Failed to create EGLContext!\n");
|
2013-11-15 08:28:54 -08:00
|
|
|
DestroySurface(surface);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 21:20:27 -07:00
|
|
|
glContext->MakeCurrent();
|
2012-04-11 21:18:35 -07:00
|
|
|
glContext->SetIsDoubleBuffered(doubleBuffered);
|
2010-09-09 13:40:11 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return glContext.forget();
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
already_AddRefed<GLContextEGL>
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextEGL::CreateEGLPBufferOffscreenContext(const gfxIntSize& size)
|
2010-06-09 15:27:29 -07:00
|
|
|
{
|
|
|
|
EGLConfig config;
|
|
|
|
EGLSurface surface;
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
const EGLint numConfigs = 1; // We only need one.
|
|
|
|
EGLConfig configs[numConfigs];
|
|
|
|
EGLint foundConfigs = 0;
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!sEGLLibrary.fChooseConfig(EGL_DISPLAY(),
|
2013-02-13 15:26:24 -08:00
|
|
|
kEGLConfigAttribsOffscreenPBuffer,
|
2010-07-18 22:01:14 -07:00
|
|
|
configs, numConfigs,
|
2011-01-31 13:10:54 -08:00
|
|
|
&foundConfigs)
|
|
|
|
|| foundConfigs == 0)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
NS_WARNING("No EGL Config for minimal PBuffer!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// We absolutely don't care, so just pick the first one.
|
2010-06-09 15:27:29 -07:00
|
|
|
config = configs[0];
|
2013-02-13 15:26:24 -08:00
|
|
|
if (GLContext::DebugMode())
|
|
|
|
sEGLLibrary.DumpEGLConfig(config);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gfxIntSize pbSize(size);
|
2011-01-31 13:10:57 -08:00
|
|
|
surface = GLContextEGL::CreatePBufferSurfaceTryingPowerOfTwo(config,
|
2013-02-13 15:26:24 -08:00
|
|
|
LOCAL_EGL_NONE,
|
|
|
|
pbSize);
|
2012-03-12 15:10:38 -07:00
|
|
|
if (!surface) {
|
|
|
|
NS_WARNING("Failed to create PBuffer for context!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-12 15:10:38 -07:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
|
|
|
GLContextEGL::CreateGLContext(dummyCaps,
|
2013-10-11 06:16:44 -07:00
|
|
|
nullptr, true,
|
2013-02-13 15:26:24 -08:00
|
|
|
config, surface);
|
|
|
|
if (!glContext) {
|
2012-03-12 15:10:38 -07:00
|
|
|
NS_WARNING("Failed to create GLContext from PBuffer");
|
2010-07-18 22:01:14 -07:00
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), surface);
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
if (!glContext->Init()) {
|
2012-03-12 15:10:38 -07:00
|
|
|
NS_WARNING("Failed to initialize GLContext!");
|
2013-02-13 15:26:24 -08:00
|
|
|
// GLContextEGL::dtor will destroy |surface| for us.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2010-06-09 15:27:29 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<GLContextEGL>
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextEGL::CreateEGLPixmapOffscreenContext(const gfxIntSize& size)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
gfxASurface *thebesSurface = nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
EGLNativePixmapType pixmap = 0;
|
|
|
|
|
|
|
|
if (!pixmap) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2011-01-06 14:07:12 -08:00
|
|
|
EGLSurface surface = 0;
|
2010-07-18 22:01:14 -07:00
|
|
|
EGLConfig config = 0;
|
|
|
|
|
2010-10-04 04:21:32 -07:00
|
|
|
if (!config) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
2013-02-13 15:26:24 -08:00
|
|
|
MOZ_ASSERT(surface);
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
SurfaceCaps dummyCaps = SurfaceCaps::Any();
|
2013-02-21 11:54:25 -08:00
|
|
|
nsRefPtr<GLContextEGL> glContext =
|
2013-02-27 20:56:29 -08:00
|
|
|
GLContextEGL::CreateGLContext(dummyCaps,
|
2013-10-11 06:16:44 -07:00
|
|
|
nullptr, true,
|
2013-02-27 20:56:29 -08:00
|
|
|
config, surface);
|
2013-02-13 15:26:24 -08: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-18 22:01:14 -07:00
|
|
|
|
|
|
|
glContext->HoldSurface(thebesSurface);
|
|
|
|
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2013-08-25 16:56:53 -07:00
|
|
|
// Under EGL, on Android, pbuffers are supported fine, though
|
2010-07-18 22:01:14 -07:00
|
|
|
// often without the ability to texture from them directly.
|
|
|
|
already_AddRefed<GLContext>
|
2013-02-13 15:26:24 -08:00
|
|
|
GLContextProviderEGL::CreateOffscreen(const gfxIntSize& size,
|
|
|
|
const SurfaceCaps& caps,
|
|
|
|
ContextFlags flags)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
|
|
|
if (!sEGLLibrary.EnsureInitialized()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
gfxIntSize dummySize = gfxIntSize(16, 16);
|
|
|
|
nsRefPtr<GLContextEGL> glContext;
|
|
|
|
glContext = GLContextEGL::CreateEGLPBufferOffscreenContext(dummySize);
|
2011-10-19 12:09:57 -07:00
|
|
|
|
|
|
|
if (!glContext)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-10-19 12:09:57 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (!glContext->InitOffscreen(size, caps))
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-02 09:28:06 -08:00
|
|
|
|
2011-06-09 18:18:43 -07:00
|
|
|
return glContext.forget();
|
2010-06-09 15:27:29 -07:00
|
|
|
}
|
|
|
|
|
2012-06-14 08:59:40 -07: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-20 18:45:13 -08:00
|
|
|
// and 3) each EGL context eats 750k on B2G (bug 813783)
|
2012-11-22 10:53:11 -08:00
|
|
|
GLContext *
|
|
|
|
GLContextProviderEGL::GetGlobalContext(const ContextFlags)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 21:05:42 -07:00
|
|
|
void
|
|
|
|
GLContextProviderEGL::Shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|