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-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)
|
|
|
|
|
2012-10-01 13:01:35 -07:00
|
|
|
#ifndef MOZ_ANDROID_OMTC
|
2011-09-22 22:58:15 -07:00
|
|
|
static EGLSurface
|
2010-12-13 14:36:35 -08:00
|
|
|
CreateSurfaceForWindow(nsIWidget *aWidget, EGLConfig config);
|
2012-06-19 21:12:30 -07:00
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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)
|
2012-08-01 11:57:54 -07:00
|
|
|
, mTemporaryEGLImageTexture(0)
|
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()
|
|
|
|
{
|
2012-08-01 11:57:54 -07:00
|
|
|
if (MakeCurrent()) {
|
|
|
|
if (mTemporaryEGLImageTexture != 0) {
|
|
|
|
fDeleteTextures(1, &mTemporaryEGLImageTexture);
|
|
|
|
mTemporaryEGLImageTexture = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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:36 -08:00
|
|
|
if (mSurface) {
|
2011-08-23 13:48:27 -07:00
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), 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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-07-23 13:39:29 -07:00
|
|
|
SetupLookupFunction();
|
2013-03-04 16:44:31 -08:00
|
|
|
if (!InitWithPrefix("gl", true))
|
|
|
|
return false;
|
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 08:28:38 -08:00
|
|
|
virtual void SetEGLSurfaceOverride(void* 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() {
|
2012-06-12 07:24:31 -07:00
|
|
|
sEGLLibrary.fMakeCurrent(EGL_DISPLAY(), EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
if (!mSurface) {
|
2012-10-01 13:01:35 -07:00
|
|
|
#ifdef MOZ_ANDROID_OMTC
|
2013-02-28 10:28:23 -08:00
|
|
|
mSurface = mozilla::AndroidBridge::Bridge()->ProvideEGLSurface();
|
2013-01-10 08:21:10 -08:00
|
|
|
if (!mSurface) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-29 10:46:37 -07:00
|
|
|
#else
|
2012-06-12 07:24:31 -07:00
|
|
|
EGLConfig config;
|
|
|
|
CreateConfig(&config);
|
2013-07-20 01:48:55 -07:00
|
|
|
mSurface = CreateSurfaceForWindow(nullptr, config);
|
2012-05-29 10:46:37 -07:00
|
|
|
#endif
|
2012-06-12 07:24:31 -07:00
|
|
|
}
|
2010-12-13 14:36:35 -08:00
|
|
|
return sEGLLibrary.fMakeCurrent(EGL_DISPLAY(),
|
|
|
|
mSurface, mSurface,
|
|
|
|
mContext);
|
|
|
|
}
|
|
|
|
|
2011-08-23 13:48:27 -07:00
|
|
|
virtual void
|
|
|
|
ReleaseSurface() {
|
2013-11-15 08:28:36 -08:00
|
|
|
if (mSurface) {
|
2011-08-23 13:48:27 -07:00
|
|
|
sEGLLibrary.fMakeCurrent(EGL_DISPLAY(), EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), mSurface);
|
2013-07-20 01:48:55 -07:00
|
|
|
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
|
|
|
}
|
2011-07-06 11:00:47 -07:00
|
|
|
// GLContext interface - returns Tiled Texture Image in our case
|
2010-07-01 09:30:38 -07:00
|
|
|
virtual already_AddRefed<TextureImage>
|
|
|
|
CreateTextureImage(const nsIntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType,
|
2010-11-12 12:02:20 -08:00
|
|
|
GLenum aWrapMode,
|
2013-08-07 15:38:21 -07:00
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags,
|
2013-09-24 13:45:13 -07:00
|
|
|
TextureImage::ImageFormat aImageFormat = gfxImageFormatUnknown);
|
2010-07-01 09:30:38 -07:00
|
|
|
|
2011-07-06 11:00:47 -07:00
|
|
|
// a function to generate Tiles for Tiled Texture Image
|
|
|
|
virtual already_AddRefed<TextureImage>
|
|
|
|
TileGenFunc(const nsIntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType,
|
2013-08-07 15:38:21 -07:00
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags,
|
2013-09-24 13:45:13 -07:00
|
|
|
TextureImage::ImageFormat aImageFormat = gfxImageFormatUnknown) MOZ_OVERRIDE;
|
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
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
|
|
|
|
void* buffer,
|
|
|
|
SharedTextureBufferType bufferType);
|
|
|
|
virtual void UpdateSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle);
|
|
|
|
virtual void ReleaseSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle);
|
|
|
|
virtual bool GetSharedHandleDetails(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle,
|
|
|
|
SharedHandleDetails& details);
|
|
|
|
virtual bool AttachSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle);
|
2013-02-13 15:26:24 -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
|
|
|
|
2012-08-01 11:57:54 -07:00
|
|
|
// A dummy texture ID that can be used when we need a texture object whose
|
|
|
|
// images we're going to define with EGLImageTargetTexture2D.
|
|
|
|
GLuint mTemporaryEGLImageTexture;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
enum SharedHandleType {
|
|
|
|
SharedHandleType_Image
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-09-04 05:14:52 -07:00
|
|
|
, SharedHandleType_SurfaceTexture
|
2012-07-20 12:20:51 -07:00
|
|
|
#endif
|
2013-09-04 05:14:52 -07:00
|
|
|
};
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
class SharedTextureHandleWrapper
|
2012-05-31 18:30:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-07-20 12:20:51 -07:00
|
|
|
SharedTextureHandleWrapper(SharedHandleType aHandleType) : mHandleType(aHandleType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SharedTextureHandleWrapper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedHandleType Type() { return mHandleType; }
|
|
|
|
|
|
|
|
SharedHandleType mHandleType;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
class SurfaceTextureWrapper: public SharedTextureHandleWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SurfaceTextureWrapper(nsSurfaceTexture* aSurfaceTexture) :
|
2013-09-04 05:14:52 -07:00
|
|
|
SharedTextureHandleWrapper(SharedHandleType_SurfaceTexture)
|
2012-07-20 12:20:51 -07:00
|
|
|
, mSurfaceTexture(aSurfaceTexture)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SurfaceTextureWrapper() {
|
2012-07-30 07:20:58 -07:00
|
|
|
mSurfaceTexture = nullptr;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSurfaceTexture* SurfaceTexture() { return mSurfaceTexture; }
|
|
|
|
|
|
|
|
nsRefPtr<nsSurfaceTexture> mSurfaceTexture;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
|
|
|
class EGLTextureWrapper : public SharedTextureHandleWrapper
|
|
|
|
{
|
|
|
|
public:
|
2012-08-01 11:57:54 -07:00
|
|
|
EGLTextureWrapper() :
|
2013-09-04 05:14:52 -07:00
|
|
|
SharedTextureHandleWrapper(SharedHandleType_Image)
|
2012-07-30 07:20:58 -07:00
|
|
|
, mEGLImage(nullptr)
|
|
|
|
, mSyncObject(nullptr)
|
2012-05-31 18:30:08 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-01 11:57:54 -07:00
|
|
|
// Args are the active GL context, and a texture in that GL
|
|
|
|
// context for which to create an EGLImage. After the EGLImage
|
|
|
|
// is created, the texture is unused by EGLTextureWrapper.
|
|
|
|
bool CreateEGLImage(GLContextEGL *ctx, GLuint texture) {
|
|
|
|
MOZ_ASSERT(!mEGLImage && texture && sEGLLibrary.HasKHRImageBase());
|
2012-05-31 18:30:08 -07:00
|
|
|
static const EGLint eglAttributes[] = {
|
|
|
|
LOCAL_EGL_NONE
|
|
|
|
};
|
2013-02-13 15:26:24 -08:00
|
|
|
EGLContext eglContext = (EGLContext)ctx->GetEGLContext();
|
|
|
|
mEGLImage = sEGLLibrary.fCreateImage(EGL_DISPLAY(), eglContext, LOCAL_EGL_GL_TEXTURE_2D,
|
2012-08-01 11:57:54 -07:00
|
|
|
(EGLClientBuffer)texture, eglAttributes);
|
2012-05-31 18:30:08 -07:00
|
|
|
if (!mEGLImage) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf_stderr("Could not create EGL images: ERROR (0x%04x)\n", sEGLLibrary.fGetError());
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~EGLTextureWrapper() {
|
|
|
|
if (mEGLImage) {
|
|
|
|
sEGLLibrary.fDestroyImage(EGL_DISPLAY(), mEGLImage);
|
2012-07-30 07:20:58 -07:00
|
|
|
mEGLImage = nullptr;
|
2012-05-31 18:30:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const EGLImage GetEGLImage() {
|
|
|
|
return mEGLImage;
|
|
|
|
}
|
|
|
|
|
2012-08-01 11:57:54 -07:00
|
|
|
// Insert a sync point on the given context, which should be the current active
|
|
|
|
// context.
|
|
|
|
bool MakeSync(GLContext *ctx) {
|
2012-07-30 07:20:58 -07:00
|
|
|
MOZ_ASSERT(mSyncObject == nullptr);
|
2012-07-17 18:20:28 -07:00
|
|
|
|
|
|
|
if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync)) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mSyncObject = sEGLLibrary.fCreateSync(EGL_DISPLAY(), LOCAL_EGL_SYNC_FENCE, nullptr);
|
2012-07-17 18:20:28 -07:00
|
|
|
// We need to flush to make sure the sync object enters the command stream;
|
|
|
|
// we can't use EGL_SYNC_FLUSH_COMMANDS_BIT at wait time, because the wait
|
|
|
|
// happens on a different thread/context.
|
2012-08-01 11:57:54 -07:00
|
|
|
ctx->fFlush();
|
2012-07-17 18:20:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mSyncObject == EGL_NO_SYNC) {
|
|
|
|
// we failed to create one, so just do a finish
|
2012-08-01 11:57:54 -07:00
|
|
|
ctx->fFinish();
|
2012-07-17 18:20:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WaitSync() {
|
|
|
|
if (!mSyncObject) {
|
|
|
|
// if we have no sync object, then we did a Finish() earlier
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-26 18:31:42 -07:00
|
|
|
// wait at most 1 second; this should really be never/rarely hit
|
|
|
|
const uint64_t ns_per_ms = 1000 * 1000;
|
|
|
|
EGLTime timeout = 1000 * ns_per_ms;
|
|
|
|
|
|
|
|
EGLint result = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), mSyncObject, 0, timeout);
|
2012-07-17 18:20:28 -07:00
|
|
|
sEGLLibrary.fDestroySync(EGL_DISPLAY(), mSyncObject);
|
2012-07-30 07:20:58 -07:00
|
|
|
mSyncObject = nullptr;
|
2012-07-17 18:20:28 -07:00
|
|
|
|
|
|
|
return result == LOCAL_EGL_CONDITION_SATISFIED;
|
|
|
|
}
|
|
|
|
|
2012-05-31 18:30:08 -07:00
|
|
|
private:
|
|
|
|
EGLImage mEGLImage;
|
2012-07-17 18:20:28 -07:00
|
|
|
EGLSync mSyncObject;
|
2012-05-31 18:30:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2012-11-26 14:23:27 -08:00
|
|
|
GLContextEGL::UpdateSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle)
|
2012-05-31 18:30:08 -07:00
|
|
|
{
|
2012-11-26 14:23:27 -08:00
|
|
|
if (shareType != SameProcess) {
|
2012-05-31 18:30:08 -07:00
|
|
|
NS_ERROR("Implementation not available for this sharing type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
|
2012-07-20 12:20:51 -07:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
NS_ASSERTION(wrapper->Type() == SharedHandleType_Image, "Expected EGLImage shared handle");
|
2012-05-31 18:30:08 -07:00
|
|
|
NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
EGLTextureWrapper* wrap = reinterpret_cast<EGLTextureWrapper*>(wrapper);
|
2012-05-31 18:30:08 -07:00
|
|
|
// We need to copy the current GLContext drawing buffer to the texture
|
|
|
|
// exported by the EGLImage. Need to save both the read FBO and the texture
|
|
|
|
// binding, because we're going to munge them to do this.
|
2013-02-13 15:26:24 -08:00
|
|
|
ScopedBindTexture autoTex(this, mTemporaryEGLImageTexture);
|
2012-08-01 11:57:54 -07:00
|
|
|
fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, wrap->GetEGLImage());
|
2012-05-31 18:30:08 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
// CopyTexSubImage2D, is ~2x slower than simple FBO render to texture with
|
|
|
|
// draw quads, but if we want that, we need to assure that our default
|
|
|
|
// framebuffer is texture-backed.
|
|
|
|
gfxIntSize size = OffscreenSize();
|
|
|
|
BlitFramebufferToTexture(0, mTemporaryEGLImageTexture, size, size);
|
2012-05-31 18:30:08 -07:00
|
|
|
|
2012-07-26 18:31:42 -07:00
|
|
|
// Make sure our copy is finished, so that we can be ready to draw
|
|
|
|
// in different thread GLContext. If we have KHR_fence_sync, then
|
|
|
|
// we insert a sync object, otherwise we have to do a GuaranteeResolve.
|
2012-08-01 11:57:54 -07:00
|
|
|
wrap->MakeSync(this);
|
2012-05-31 18:30:08 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
SharedTextureHandle
|
2012-11-26 14:23:27 -08:00
|
|
|
GLContextEGL::CreateSharedHandle(SharedTextureShareType shareType,
|
|
|
|
void* buffer,
|
|
|
|
SharedTextureBufferType bufferType)
|
2012-07-20 12:20:51 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
// Both EGLImage and SurfaceTexture only support same-process currently, but
|
2012-07-20 12:20:51 -07:00
|
|
|
// it's possible to make SurfaceTexture work across processes. We should do that.
|
2012-11-26 14:23:27 -08:00
|
|
|
if (shareType != SameProcess)
|
2012-07-25 02:27:00 -07:00
|
|
|
return 0;
|
2012-07-20 12:20:51 -07:00
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
switch (bufferType) {
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
case SharedTextureBufferType::SurfaceTexture:
|
|
|
|
if (!IsExtensionSupported(GLContext::OES_EGL_image_external)) {
|
|
|
|
NS_WARNING("Missing GL_OES_EGL_image_external");
|
2012-07-25 02:27:00 -07:00
|
|
|
return 0;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
return (SharedTextureHandle) new SurfaceTextureWrapper(reinterpret_cast<nsSurfaceTexture*>(buffer));
|
2012-07-20 12:20:51 -07:00
|
|
|
#endif
|
|
|
|
case SharedTextureBufferType::TextureID: {
|
|
|
|
if (!mShareWithEGLImage)
|
2012-07-25 02:27:00 -07:00
|
|
|
return 0;
|
2012-07-20 12:20:51 -07:00
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
GLuint texture = (uintptr_t)buffer;
|
2012-08-01 11:57:54 -07:00
|
|
|
EGLTextureWrapper* tex = new EGLTextureWrapper();
|
|
|
|
if (!tex->CreateEGLImage(this, texture)) {
|
2012-07-20 12:20:51 -07:00
|
|
|
NS_ERROR("EGLImage creation for EGLTextureWrapper failed");
|
|
|
|
delete tex;
|
2012-07-25 02:27:00 -07:00
|
|
|
return 0;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return (SharedTextureHandle)tex;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown shared texture buffer type");
|
2012-07-25 02:27:00 -07:00
|
|
|
return 0;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
void GLContextEGL::ReleaseSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle)
|
2012-05-31 18:30:08 -07:00
|
|
|
{
|
2012-11-26 14:23:27 -08:00
|
|
|
if (shareType != SameProcess) {
|
2012-05-31 18:30:08 -07:00
|
|
|
NS_ERROR("Implementation not available for this sharing type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
|
2012-07-20 12:20:51 -07:00
|
|
|
|
2012-07-20 12:20:51 -07:00
|
|
|
switch (wrapper->Type()) {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_SurfaceTexture:
|
2012-07-20 12:20:51 -07:00
|
|
|
delete wrapper;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_Image: {
|
2012-07-20 12:20:51 -07:00
|
|
|
NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
|
2012-07-20 12:20:51 -07:00
|
|
|
delete wrap;
|
|
|
|
break;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown shared handle type");
|
2012-11-26 14:23:27 -08:00
|
|
|
return;
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
2012-07-20 12:20:51 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
bool GLContextEGL::GetSharedHandleDetails(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle,
|
|
|
|
SharedHandleDetails& details)
|
2012-07-20 12:20:51 -07:00
|
|
|
{
|
2012-11-26 14:23:27 -08:00
|
|
|
if (shareType != SameProcess)
|
2012-07-20 12:20:51 -07:00
|
|
|
return false;
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
switch (wrapper->Type()) {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_SurfaceTexture: {
|
2012-07-20 12:20:51 -07:00
|
|
|
SurfaceTextureWrapper* surfaceWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
details.mTarget = LOCAL_GL_TEXTURE_EXTERNAL;
|
2013-07-04 10:25:50 -07:00
|
|
|
details.mTextureFormat = FORMAT_R8G8B8A8;
|
2012-11-26 14:23:27 -08:00
|
|
|
surfaceWrapper->SurfaceTexture()->GetTransformMatrix(details.mTextureTransform);
|
2012-07-20 12:20:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_Image:
|
2012-11-26 14:23:27 -08:00
|
|
|
details.mTarget = LOCAL_GL_TEXTURE_2D;
|
2013-07-04 10:25:50 -07:00
|
|
|
details.mTextureFormat = FORMAT_R8G8B8A8;
|
2012-07-20 12:20:51 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown shared handle type");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-05-31 18:30:08 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
bool GLContextEGL::AttachSharedHandle(SharedTextureShareType shareType,
|
|
|
|
SharedTextureHandle sharedHandle)
|
2012-05-31 18:30:08 -07:00
|
|
|
{
|
2012-11-26 14:23:27 -08:00
|
|
|
if (shareType != SameProcess)
|
2012-05-31 18:30:08 -07:00
|
|
|
return false;
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
SharedTextureHandleWrapper* wrapper = reinterpret_cast<SharedTextureHandleWrapper*>(sharedHandle);
|
2012-07-20 12:20:51 -07:00
|
|
|
|
|
|
|
switch (wrapper->Type()) {
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_SurfaceTexture: {
|
2012-07-20 12:20:51 -07:00
|
|
|
#ifndef DEBUG
|
|
|
|
/**
|
|
|
|
* NOTE: SurfaceTexture spams us if there are any existing GL errors, so we'll clear
|
|
|
|
* them here in order to avoid that.
|
|
|
|
*/
|
|
|
|
GetAndClearError();
|
|
|
|
#endif
|
|
|
|
SurfaceTextureWrapper* surfaceTextureWrapper = reinterpret_cast<SurfaceTextureWrapper*>(wrapper);
|
|
|
|
|
|
|
|
// FIXME: SurfaceTexture provides a transform matrix which is supposed to
|
|
|
|
// be applied to the texture coordinates. We should return that here
|
|
|
|
// so we can render correctly. Bug 775083
|
|
|
|
surfaceTextureWrapper->SurfaceTexture()->UpdateTexImage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
2013-02-13 15:26:24 -08:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
case SharedHandleType_Image: {
|
2012-07-20 12:20:51 -07:00
|
|
|
NS_ASSERTION(mShareWithEGLImage, "EGLImage not supported or disabled in runtime");
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
EGLTextureWrapper* wrap = (EGLTextureWrapper*)sharedHandle;
|
2012-07-30 08:07:23 -07:00
|
|
|
wrap->WaitSync();
|
2012-07-20 12:20:51 -07:00
|
|
|
fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, wrap->GetEGLImage());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown shared handle type");
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-31 18:30:08 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-07-01 09:30:38 -07:00
|
|
|
already_AddRefed<TextureImage>
|
|
|
|
GLContextEGL::CreateTextureImage(const nsIntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType,
|
2010-11-12 12:02:20 -08:00
|
|
|
GLenum aWrapMode,
|
2013-08-07 15:38:21 -07:00
|
|
|
TextureImage::Flags aFlags,
|
|
|
|
TextureImage::ImageFormat aImageFormat)
|
2011-07-06 11:00:47 -07:00
|
|
|
{
|
2013-08-07 15:38:21 -07:00
|
|
|
nsRefPtr<TextureImage> t = new gl::TiledTextureImage(this, aSize, aContentType, aFlags, aImageFormat);
|
2011-07-06 11:00:47 -07:00
|
|
|
return t.forget();
|
2012-03-11 14:41:03 -07:00
|
|
|
}
|
2011-07-06 11:00:47 -07:00
|
|
|
|
|
|
|
already_AddRefed<TextureImage>
|
|
|
|
GLContextEGL::TileGenFunc(const nsIntSize& aSize,
|
2013-05-09 14:02:48 -07:00
|
|
|
TextureImage::ContentType aContentType,
|
2013-08-07 15:38:21 -07:00
|
|
|
TextureImage::Flags aFlags,
|
|
|
|
TextureImage::ImageFormat aImageFormat)
|
2010-07-01 09:30:38 -07:00
|
|
|
{
|
|
|
|
MakeCurrent();
|
|
|
|
|
|
|
|
GLuint texture;
|
|
|
|
fGenTextures(1, &texture);
|
|
|
|
|
2010-11-26 13:41:53 -08:00
|
|
|
nsRefPtr<TextureImageEGL> teximage =
|
2013-08-07 15:38:21 -07:00
|
|
|
new TextureImageEGL(texture, aSize, LOCAL_GL_CLAMP_TO_EDGE, aContentType,
|
|
|
|
this, aFlags, TextureImage::Created, aImageFormat);
|
2012-06-14 11:57:26 -07:00
|
|
|
|
|
|
|
teximage->BindTexture(LOCAL_GL_TEXTURE0);
|
2010-11-26 13:41:53 -08:00
|
|
|
|
2012-05-09 13:55:31 -07:00
|
|
|
GLint texfilter = aFlags & TextureImage::UseNearestFilter ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR;
|
2010-07-01 09:30:38 -07:00
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter);
|
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
|
2011-07-06 11:00:47 -07:00
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
2010-07-01 09:30:38 -07:00
|
|
|
|
|
|
|
return teximage.forget();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-01 13:01:35 -07:00
|
|
|
// When MOZ_ANDROID_OMTC is defined,
|
2012-06-19 21:12:30 -07:00
|
|
|
// use mozilla::AndroidBridge::Bridge()->ProvideEGLSurface() instead.
|
2012-10-01 13:01:35 -07:00
|
|
|
#ifndef MOZ_ANDROID_OMTC
|
2011-09-22 22:58:15 -07:00
|
|
|
static EGLSurface
|
2010-12-13 14:36:35 -08:00
|
|
|
CreateSurfaceForWindow(nsIWidget *aWidget, EGLConfig config)
|
|
|
|
{
|
|
|
|
EGLSurface surface;
|
|
|
|
|
2012-02-21 13:15:39 -08:00
|
|
|
#ifdef DEBUG
|
2010-09-09 13:40:11 -07:00
|
|
|
sEGLLibrary.DumpEGLConfig(config);
|
|
|
|
#endif
|
|
|
|
|
2013-02-19 09:35:38 -08:00
|
|
|
#if !defined(MOZ_WIDGET_ANDROID)
|
2010-09-08 15:19:11 -07:00
|
|
|
surface = sEGLLibrary.fCreateWindowSurface(EGL_DISPLAY(), config, GET_NATIVE_WINDOW(aWidget), 0);
|
2010-06-25 17:52:37 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
gScreenBounds.x = 0;
|
|
|
|
gScreenBounds.y = 0;
|
|
|
|
sEGLLibrary.fQuerySurface(EGL_DISPLAY(), surface, LOCAL_EGL_WIDTH, &gScreenBounds.width);
|
|
|
|
sEGLLibrary.fQuerySurface(EGL_DISPLAY(), surface, LOCAL_EGL_HEIGHT, &gScreenBounds.height);
|
|
|
|
#endif
|
|
|
|
|
2010-12-13 14:36:35 -08:00
|
|
|
return surface;
|
|
|
|
}
|
2012-06-19 21:12:30 -07:00
|
|
|
#endif
|
2010-12-13 14:36:35 -08:00
|
|
|
|
|
|
|
already_AddRefed<GLContext>
|
|
|
|
GLContextProviderEGL::CreateForWindow(nsIWidget *aWidget)
|
|
|
|
{
|
|
|
|
if (!sEGLLibrary.EnsureInitialized()) {
|
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)) {
|
2010-12-13 14:36:35 -08:00
|
|
|
printf_stderr("Failed to create EGL config!\n");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-12-13 14:36:35 -08:00
|
|
|
}
|
|
|
|
|
2012-10-01 13:01:35 -07:00
|
|
|
#ifdef MOZ_ANDROID_OMTC
|
2012-02-06 13:53:09 -08:00
|
|
|
mozilla::AndroidBridge::Bridge()->RegisterCompositor();
|
2013-02-28 10:28:23 -08:00
|
|
|
EGLSurface surface = mozilla::AndroidBridge::Bridge()->ProvideEGLSurface();
|
2012-05-29 10:46:37 -07:00
|
|
|
#else
|
|
|
|
EGLSurface surface = CreateSurfaceForWindow(aWidget, config);
|
2012-02-06 13:53:09 -08:00
|
|
|
#endif
|
|
|
|
|
2010-06-09 15:27:29 -07:00
|
|
|
if (!surface) {
|
2013-02-13 15:26:24 -08:00
|
|
|
printf_stderr("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-02-13 15:26:24 -08:00
|
|
|
sEGLLibrary.fDestroySurface(EGL_DISPLAY(), 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 */
|
|
|
|
|