2012-03-17 02:24:12 +04: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/. */
|
|
|
|
|
|
|
|
#include "GLLibraryEGL.h"
|
|
|
|
|
2016-07-16 01:12:46 +03:00
|
|
|
#include "angle/Platform.h"
|
2016-05-02 18:56:31 +03:00
|
|
|
#include "gfxConfig.h"
|
2012-03-17 02:24:12 +04:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "gfxUtils.h"
|
2012-03-17 02:24:12 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-05-31 08:39:16 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-05-27 02:05:13 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2016-07-16 01:12:46 +03:00
|
|
|
#include "mozilla/Tokenizer.h"
|
|
|
|
#include "mozilla/ScopeExit.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2017-03-15 15:14:17 +03:00
|
|
|
#include "mozilla/webrender/RenderThread.h"
|
2012-05-15 22:55:50 +04:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2012-07-07 08:44:48 +04:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2015-07-23 20:11:04 +03:00
|
|
|
#include "nsIGfxInfo.h"
|
2012-07-07 08:44:48 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2014-03-26 17:41:57 +04:00
|
|
|
#ifdef XP_WIN
|
2018-01-09 13:07:50 +03:00
|
|
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
2014-03-26 17:41:57 +04:00
|
|
|
#include "nsWindowsHelpers.h"
|
2018-01-09 13:07:50 +03:00
|
|
|
|
|
|
|
#include <d3d11.h>
|
2014-03-26 17:41:57 +04:00
|
|
|
#endif
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "OGLShaderProgram.h"
|
2012-07-17 19:26:12 +04:00
|
|
|
#include "prenv.h"
|
2017-03-29 17:14:19 +03:00
|
|
|
#include "prsystem.h"
|
2013-02-14 03:26:24 +04:00
|
|
|
#include "GLContext.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "GLContextProvider.h"
|
2014-02-28 21:59:38 +04:00
|
|
|
#include "gfxPrefs.h"
|
2015-10-12 06:21:03 +03:00
|
|
|
#include "ScopedGLHelpers.h"
|
2012-03-17 02:24:12 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
StaticMutex GLLibraryEGL::sMutex;
|
2013-10-11 17:16:44 +04:00
|
|
|
GLLibraryEGL sEGLLibrary;
|
2014-05-30 20:15:40 +04:00
|
|
|
|
2012-06-13 01:39:18 +04:00
|
|
|
// should match the order of EGLExtensions, and be null-terminated.
|
2016-06-11 04:37:07 +03:00
|
|
|
static const char* sEGLExtensionNames[] = {
|
2012-06-13 01:39:18 +04:00
|
|
|
"EGL_KHR_image_base",
|
|
|
|
"EGL_KHR_image_pixmap",
|
|
|
|
"EGL_KHR_gl_texture_2D_image",
|
|
|
|
"EGL_KHR_lock_surface",
|
|
|
|
"EGL_ANGLE_surface_d3d_texture_2d_share_handle",
|
|
|
|
"EGL_EXT_create_context_robustness",
|
|
|
|
"EGL_KHR_image",
|
2012-06-13 01:39:43 +04:00
|
|
|
"EGL_KHR_fence_sync",
|
2015-07-10 21:47:48 +03:00
|
|
|
"EGL_ANDROID_native_fence_sync",
|
2015-07-20 02:03:10 +03:00
|
|
|
"EGL_ANDROID_image_crop",
|
2015-09-30 02:04:17 +03:00
|
|
|
"EGL_ANGLE_platform_angle",
|
2017-02-20 04:44:50 +03:00
|
|
|
"EGL_ANGLE_platform_angle_d3d",
|
2017-02-10 07:31:36 +03:00
|
|
|
"EGL_ANGLE_d3d_share_handle_client_buffer",
|
|
|
|
"EGL_KHR_create_context",
|
2017-05-29 07:15:07 +03:00
|
|
|
"EGL_KHR_stream",
|
|
|
|
"EGL_KHR_stream_consumer_gltexture",
|
|
|
|
"EGL_EXT_device_query",
|
|
|
|
"EGL_NV_stream_consumer_gltexture_yuv",
|
|
|
|
"EGL_ANGLE_stream_producer_d3d_texture_nv12",
|
2017-08-31 09:57:45 +03:00
|
|
|
"EGL_ANGLE_device_creation",
|
|
|
|
"EGL_ANGLE_device_creation_d3d11",
|
2012-06-13 01:39:18 +04:00
|
|
|
};
|
|
|
|
|
2012-05-15 22:55:50 +04:00
|
|
|
#if defined(ANDROID)
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
static PRLibrary* LoadApitraceLibrary()
|
|
|
|
{
|
2015-02-19 00:50:31 +03:00
|
|
|
// Initialization of gfx prefs here is only needed during the unit tests...
|
|
|
|
gfxPrefs::GetSingleton();
|
2014-02-28 21:59:38 +04:00
|
|
|
if (!gfxPrefs::UseApitrace()) {
|
2013-07-30 22:54:29 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-20 12:48:55 +04:00
|
|
|
static PRLibrary* sApitraceLibrary = nullptr;
|
2012-03-17 02:24:12 +04:00
|
|
|
|
|
|
|
if (sApitraceLibrary)
|
|
|
|
return sApitraceLibrary;
|
|
|
|
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString logFile;
|
|
|
|
Preferences::GetCString("gfx.apitrace.logfile", logFile);
|
2012-03-17 02:24:12 +04:00
|
|
|
if (logFile.IsEmpty()) {
|
|
|
|
logFile = "firefox.trace";
|
|
|
|
}
|
|
|
|
|
|
|
|
// The firefox process can't write to /data/local, but it can write
|
|
|
|
// to $GRE_HOME/
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString logPath;
|
2012-03-17 02:24:12 +04:00
|
|
|
logPath.AppendPrintf("%s/%s", getenv("GRE_HOME"), logFile.get());
|
|
|
|
|
|
|
|
// apitrace uses the TRACE_FILE environment variable to determine where
|
|
|
|
// to log trace output to
|
|
|
|
printf_stderr("Logging GL tracing output to %s", logPath.get());
|
|
|
|
setenv("TRACE_FILE", logPath.get(), false);
|
|
|
|
|
|
|
|
printf_stderr("Attempting load of %s\n", APITRACE_LIB);
|
|
|
|
|
|
|
|
sApitraceLibrary = PR_LoadLibrary(APITRACE_LIB);
|
|
|
|
|
|
|
|
return sApitraceLibrary;
|
|
|
|
}
|
|
|
|
|
2012-05-15 22:55:50 +04:00
|
|
|
#endif // ANDROID
|
|
|
|
|
2012-07-07 08:44:48 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// see the comment in GLLibraryEGL::EnsureInitialized() for the rationale here.
|
|
|
|
static PRLibrary*
|
|
|
|
LoadLibraryForEGLOnWindows(const nsAString& filename)
|
|
|
|
{
|
2017-03-29 17:14:19 +03:00
|
|
|
nsAutoCString path(gfx::gfxVars::GREDirectory());
|
|
|
|
path.Append(PR_GetDirectorySeparator());
|
|
|
|
path.Append(ToNewUTF8String(filename));
|
|
|
|
|
|
|
|
PRLibSpec lspec;
|
|
|
|
lspec.type = PR_LibSpec_Pathname;
|
|
|
|
lspec.value.pathname = path.get();
|
|
|
|
return PR_LoadLibraryWithFlags(lspec, PR_LD_LAZY | PR_LD_LOCAL);
|
2012-07-07 08:44:48 +04:00
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
|
2012-07-07 08:44:48 +04:00
|
|
|
#endif // XP_WIN
|
|
|
|
|
2015-07-23 20:11:04 +03:00
|
|
|
static EGLDisplay
|
|
|
|
GetAndInitWARPDisplay(GLLibraryEGL& egl, void* displayType)
|
|
|
|
{
|
2016-04-06 23:47:25 +03:00
|
|
|
EGLint attrib_list[] = { LOCAL_EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
|
|
|
|
LOCAL_EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE,
|
|
|
|
// Requires:
|
|
|
|
LOCAL_EGL_PLATFORM_ANGLE_TYPE_ANGLE,
|
|
|
|
LOCAL_EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
|
2015-07-23 20:11:04 +03:00
|
|
|
LOCAL_EGL_NONE };
|
|
|
|
EGLDisplay display = egl.fGetPlatformDisplayEXT(LOCAL_EGL_PLATFORM_ANGLE_ANGLE,
|
|
|
|
displayType,
|
|
|
|
attrib_list);
|
|
|
|
|
2016-04-06 23:47:25 +03:00
|
|
|
if (display == EGL_NO_DISPLAY) {
|
|
|
|
const EGLint err = egl.fGetError();
|
|
|
|
if (err != LOCAL_EGL_SUCCESS) {
|
2016-06-16 18:15:29 +03:00
|
|
|
gfxCriticalError() << "Unexpected GL error: " << gfx::hexa(err);
|
2016-05-06 17:19:31 +03:00
|
|
|
MOZ_CRASH("GFX: Unexpected GL error.");
|
2016-04-06 23:47:25 +03:00
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
return EGL_NO_DISPLAY;
|
2016-04-06 23:47:25 +03:00
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
|
|
|
|
if (!egl.fInitialize(display, nullptr, nullptr))
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2017-11-29 07:13:40 +03:00
|
|
|
static EGLDisplay
|
|
|
|
GetAndInitDisplayForWebRender(GLLibraryEGL& egl, void* displayType)
|
|
|
|
{
|
2018-01-09 13:07:50 +03:00
|
|
|
#ifdef XP_WIN
|
|
|
|
const EGLint attrib_list[] = { LOCAL_EGL_EXPERIMENTAL_PRESENT_PATH_ANGLE,
|
2017-11-29 07:13:40 +03:00
|
|
|
LOCAL_EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE,
|
|
|
|
LOCAL_EGL_NONE };
|
2018-01-09 13:07:50 +03:00
|
|
|
RefPtr<ID3D11Device> d3d11Device = gfx::DeviceManagerDx::Get()->GetCompositorDevice();
|
|
|
|
if (!d3d11Device) {
|
|
|
|
gfxCriticalNote << "Failed to get compositor device for EGLDisplay";
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|
|
|
|
EGLDeviceEXT eglDevice = egl.fCreateDeviceANGLE(LOCAL_EGL_D3D11_DEVICE_ANGLE, reinterpret_cast<void *>(d3d11Device.get()), nullptr);
|
|
|
|
if (!eglDevice) {
|
|
|
|
gfxCriticalNote << "Failed to get EGLDeviceEXT of D3D11Device";
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|
|
|
|
// Create an EGLDisplay using the EGLDevice
|
|
|
|
EGLDisplay display = egl.fGetPlatformDisplayEXT(LOCAL_EGL_PLATFORM_DEVICE_EXT, eglDevice, attrib_list);
|
|
|
|
if (!display) {
|
|
|
|
gfxCriticalNote << "Failed to get EGLDisplay of D3D11Device";
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|
2017-11-29 07:13:40 +03:00
|
|
|
|
|
|
|
if (display == EGL_NO_DISPLAY) {
|
|
|
|
const EGLint err = egl.fGetError();
|
|
|
|
if (err != LOCAL_EGL_SUCCESS) {
|
|
|
|
gfxCriticalError() << "Unexpected GL error: " << gfx::hexa(err);
|
|
|
|
MOZ_CRASH("GFX: Unexpected GL error.");
|
|
|
|
}
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
}
|
|
|
|
|
2018-01-09 13:07:50 +03:00
|
|
|
if (!egl.fInitialize(display, nullptr, nullptr)) {
|
2017-11-29 07:13:40 +03:00
|
|
|
return EGL_NO_DISPLAY;
|
2018-01-09 13:07:50 +03:00
|
|
|
}
|
2017-11-29 07:13:40 +03:00
|
|
|
return display;
|
2018-01-09 13:07:50 +03:00
|
|
|
#else
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
#endif
|
2017-11-29 07:13:40 +03:00
|
|
|
}
|
|
|
|
|
2015-07-23 20:11:04 +03:00
|
|
|
static bool
|
2016-06-11 05:01:00 +03:00
|
|
|
IsAccelAngleSupported(const nsCOMPtr<nsIGfxInfo>& gfxInfo,
|
|
|
|
nsACString* const out_failureId)
|
2015-07-23 20:11:04 +03:00
|
|
|
{
|
2017-03-15 15:14:17 +03:00
|
|
|
if (wr::RenderThread::IsInRenderThread()) {
|
2017-01-13 23:16:52 +03:00
|
|
|
// We can only enter here with WebRender, so assert that this is a
|
|
|
|
// WebRender-enabled build.
|
2017-03-23 00:36:25 +03:00
|
|
|
#ifndef MOZ_BUILD_WEBRENDER
|
2017-01-13 23:16:52 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
#endif
|
2016-12-21 04:40:49 +03:00
|
|
|
return true;
|
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
int32_t angleSupport;
|
2016-06-06 20:37:59 +03:00
|
|
|
nsCString failureId;
|
2015-10-12 06:21:03 +03:00
|
|
|
gfxUtils::ThreadSafeGetFeatureStatus(gfxInfo,
|
|
|
|
nsIGfxInfo::FEATURE_WEBGL_ANGLE,
|
2016-05-27 02:05:13 +03:00
|
|
|
failureId,
|
2015-10-12 06:21:03 +03:00
|
|
|
&angleSupport);
|
2016-07-28 00:14:19 +03:00
|
|
|
if (failureId.IsEmpty() && angleSupport != nsIGfxInfo::FEATURE_STATUS_OK) {
|
|
|
|
// This shouldn't happen, if we see this it's because we've missed
|
|
|
|
// some failure paths
|
|
|
|
failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_ACCL_ANGLE_NOT_OK");
|
|
|
|
}
|
|
|
|
if (out_failureId->IsEmpty()) {
|
2016-06-11 05:01:00 +03:00
|
|
|
*out_failureId = failureId;
|
2016-06-06 23:52:42 +03:00
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
return (angleSupport == nsIGfxInfo::FEATURE_STATUS_OK);
|
|
|
|
}
|
|
|
|
|
2014-10-09 03:32:50 +04:00
|
|
|
static EGLDisplay
|
|
|
|
GetAndInitDisplay(GLLibraryEGL& egl, void* displayType)
|
|
|
|
{
|
|
|
|
EGLDisplay display = egl.fGetDisplay(displayType);
|
|
|
|
if (display == EGL_NO_DISPLAY)
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
if (!egl.fInitialize(display, nullptr, nullptr))
|
|
|
|
return EGL_NO_DISPLAY;
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2017-05-24 10:20:02 +03:00
|
|
|
class AngleErrorReporting {
|
2016-07-16 01:12:46 +03:00
|
|
|
public:
|
|
|
|
AngleErrorReporting()
|
|
|
|
{
|
|
|
|
// No static constructor
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFailureId(nsACString* const aFailureId)
|
|
|
|
{
|
|
|
|
mFailureId = aFailureId;
|
|
|
|
}
|
|
|
|
|
2017-05-24 10:20:02 +03:00
|
|
|
void logError(const char *errorMessage)
|
2016-07-16 01:12:46 +03:00
|
|
|
{
|
2016-07-24 18:11:09 +03:00
|
|
|
if (!mFailureId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-16 01:12:46 +03:00
|
|
|
nsCString str(errorMessage);
|
|
|
|
Tokenizer tokenizer(str);
|
|
|
|
|
|
|
|
// Parse "ANGLE Display::initialize error " << error.getID() << ": "
|
|
|
|
// << error.getMessage()
|
|
|
|
nsCString currWord;
|
|
|
|
Tokenizer::Token intToken;
|
|
|
|
if (tokenizer.CheckWord("ANGLE") &&
|
|
|
|
tokenizer.CheckWhite() &&
|
|
|
|
tokenizer.CheckWord("Display") &&
|
|
|
|
tokenizer.CheckChar(':') &&
|
|
|
|
tokenizer.CheckChar(':') &&
|
|
|
|
tokenizer.CheckWord("initialize") &&
|
|
|
|
tokenizer.CheckWhite() &&
|
|
|
|
tokenizer.CheckWord("error") &&
|
|
|
|
tokenizer.CheckWhite() &&
|
|
|
|
tokenizer.Check(Tokenizer::TOKEN_INTEGER, intToken)) {
|
|
|
|
*mFailureId = "FAILURE_ID_ANGLE_ID_";
|
2016-12-14 19:32:21 +03:00
|
|
|
mFailureId->AppendPrintf("%" PRIu64, intToken.AsInteger());
|
2016-07-16 01:12:46 +03:00
|
|
|
} else {
|
|
|
|
*mFailureId = "FAILURE_ID_ANGLE_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsACString* mFailureId;
|
|
|
|
};
|
|
|
|
|
|
|
|
AngleErrorReporting gAngleErrorReporter;
|
|
|
|
|
2016-01-22 05:47:29 +03:00
|
|
|
static EGLDisplay
|
2016-07-16 01:12:46 +03:00
|
|
|
GetAndInitDisplayForAccelANGLE(GLLibraryEGL& egl, nsACString* const out_failureId)
|
2016-01-22 05:47:29 +03:00
|
|
|
{
|
|
|
|
EGLDisplay ret = 0;
|
|
|
|
|
2017-03-29 17:14:19 +03:00
|
|
|
if (wr::RenderThread::IsInRenderThread()) {
|
2017-11-29 07:13:40 +03:00
|
|
|
return GetAndInitDisplayForWebRender(egl, EGL_DEFAULT_DISPLAY);
|
2017-03-29 17:14:19 +03:00
|
|
|
}
|
|
|
|
|
2016-05-24 21:24:03 +03:00
|
|
|
FeatureState& d3d11ANGLE = gfxConfig::GetFeature(Feature::D3D11_HW_ANGLE);
|
2016-05-02 18:56:31 +03:00
|
|
|
|
|
|
|
if (!gfxPrefs::WebGLANGLETryD3D11())
|
2016-06-03 21:54:56 +03:00
|
|
|
d3d11ANGLE.UserDisable("User disabled D3D11 ANGLE by pref",
|
|
|
|
NS_LITERAL_CSTRING("FAILURE_ID_ANGLE_PREF"));
|
2016-05-02 18:56:31 +03:00
|
|
|
|
|
|
|
if (gfxPrefs::WebGLANGLEForceD3D11())
|
|
|
|
d3d11ANGLE.UserForceEnable("User force-enabled D3D11 ANGLE on disabled hardware");
|
|
|
|
|
2016-07-16 01:12:46 +03:00
|
|
|
gAngleErrorReporter.SetFailureId(out_failureId);
|
|
|
|
|
|
|
|
auto guardShutdown = mozilla::MakeScopeExit([&] {
|
|
|
|
gAngleErrorReporter.SetFailureId(nullptr);
|
|
|
|
// NOTE: Ideally we should be calling ANGLEPlatformShutdown after the
|
|
|
|
// ANGLE display is destroyed. However gAngleErrorReporter
|
|
|
|
// will live longer than the ANGLE display so we're fine.
|
|
|
|
});
|
|
|
|
|
|
|
|
if (gfxConfig::IsForcedOnByUser(Feature::D3D11_HW_ANGLE)) {
|
2016-05-02 18:56:31 +03:00
|
|
|
return GetAndInitDisplay(egl, LOCAL_EGL_D3D11_ONLY_DISPLAY_ANGLE);
|
2016-07-16 01:12:46 +03:00
|
|
|
}
|
2016-05-02 18:56:31 +03:00
|
|
|
|
|
|
|
if (d3d11ANGLE.IsEnabled()) {
|
|
|
|
ret = GetAndInitDisplay(egl, LOCAL_EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE);
|
2016-01-22 05:47:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
ret = GetAndInitDisplay(egl, EGL_DEFAULT_DISPLAY);
|
|
|
|
}
|
|
|
|
|
2016-08-04 00:28:26 +03:00
|
|
|
if (!ret && out_failureId->IsEmpty()) {
|
2016-07-28 00:14:19 +03:00
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_ACCL_ANGLE_NO_DISP");
|
|
|
|
}
|
|
|
|
|
2016-01-22 05:47:29 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-12 06:21:03 +03:00
|
|
|
bool
|
|
|
|
GLLibraryEGL::ReadbackEGLImage(EGLImage image, gfx::DataSourceSurface* out_surface)
|
|
|
|
{
|
|
|
|
StaticMutexAutoUnlock lock(sMutex);
|
|
|
|
if (!mReadbackGL) {
|
2016-06-06 23:52:42 +03:00
|
|
|
nsCString discardFailureId;
|
|
|
|
mReadbackGL = gl::GLContextProvider::CreateHeadless(gl::CreateContextFlags::NONE,
|
2016-06-11 05:01:00 +03:00
|
|
|
&discardFailureId);
|
2015-10-12 06:21:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedTexture destTex(mReadbackGL);
|
2016-07-13 13:16:54 +03:00
|
|
|
const GLuint target = mReadbackGL->GetPreferredEGLImageTextureTarget();
|
2015-10-12 06:21:03 +03:00
|
|
|
ScopedBindTexture autoTex(mReadbackGL, destTex.Texture(), target);
|
|
|
|
mReadbackGL->fTexParameteri(target, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
mReadbackGL->fTexParameteri(target, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
mReadbackGL->fTexParameteri(target, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_NEAREST);
|
|
|
|
mReadbackGL->fTexParameteri(target, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST);
|
|
|
|
mReadbackGL->fEGLImageTargetTexture2D(target, image);
|
|
|
|
|
|
|
|
ShaderConfigOGL config = ShaderConfigFromTargetAndFormat(target,
|
|
|
|
out_surface->GetFormat());
|
|
|
|
int shaderConfig = config.mFeatures;
|
|
|
|
mReadbackGL->ReadTexImageHelper()->ReadTexImage(out_surface, 0, target,
|
|
|
|
out_surface->GetSize(), shaderConfig);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
bool
|
2016-06-11 05:01:00 +03:00
|
|
|
GLLibraryEGL::EnsureInitialized(bool forceAccel, nsACString* const out_failureId)
|
2012-03-17 02:24:12 +04:00
|
|
|
{
|
|
|
|
if (mInitialized) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ScopedGfxFeatureReporter reporter("EGL");
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (!mEGLLibrary) {
|
2012-07-07 08:44:48 +04:00
|
|
|
// On Windows, the GLESv2, EGL and DXSDK libraries are shipped with libxul and
|
2012-05-15 22:55:50 +04:00
|
|
|
// we should look for them there. We have to load the libs in this
|
2012-07-07 08:44:48 +04:00
|
|
|
// order, because libEGL.dll depends on libGLESv2.dll which depends on the DXSDK
|
|
|
|
// libraries. This matters especially for WebRT apps which are in a different directory.
|
|
|
|
// See bug 760323 and bug 749459
|
2012-05-15 22:55:50 +04:00
|
|
|
|
2014-05-03 02:31:05 +04:00
|
|
|
// Also note that we intentionally leak the libs we load.
|
|
|
|
|
|
|
|
do {
|
2016-11-15 01:02:49 +03:00
|
|
|
// Windows 8.1+ has d3dcompiler_47.dll in the system directory.
|
2014-05-03 02:31:05 +04:00
|
|
|
// Try it first. Note that _46 will never be in the system
|
2016-11-15 01:02:49 +03:00
|
|
|
// directory. So there is no point trying _46 in the system
|
|
|
|
// directory.
|
2014-05-03 02:31:05 +04:00
|
|
|
|
|
|
|
if (LoadLibrarySystem32(L"d3dcompiler_47.dll"))
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef MOZ_D3DCOMPILER_VISTA_DLL
|
|
|
|
if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_VISTA_DLL))))
|
|
|
|
break;
|
2012-07-07 08:44:48 +04:00
|
|
|
#endif
|
2014-05-03 02:31:05 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(false, "d3dcompiler DLL loading failed.");
|
|
|
|
} while (false);
|
2012-05-15 22:55:50 +04:00
|
|
|
|
2012-07-07 08:44:48 +04:00
|
|
|
LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libGLESv2.dll"));
|
2012-05-15 22:55:50 +04:00
|
|
|
|
2012-07-07 08:44:48 +04:00
|
|
|
mEGLLibrary = LoadLibraryForEGLOnWindows(NS_LITERAL_STRING("libEGL.dll"));
|
2012-05-15 22:55:50 +04:00
|
|
|
|
2016-09-13 21:17:29 +03:00
|
|
|
if (!mEGLLibrary) {
|
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_LOAD");
|
2012-05-15 22:55:50 +04:00
|
|
|
return false;
|
2016-09-13 21:17:29 +03:00
|
|
|
}
|
2012-05-15 22:55:50 +04:00
|
|
|
}
|
2014-08-12 20:04:36 +04:00
|
|
|
|
2012-05-15 22:55:50 +04:00
|
|
|
#else // !Windows
|
|
|
|
|
|
|
|
// On non-Windows (Android) we use system copies of libEGL. We look for
|
|
|
|
// the APITrace lib, libEGL.so, and libEGL.so.1 in that order.
|
|
|
|
|
|
|
|
#if defined(ANDROID)
|
|
|
|
if (!mEGLLibrary)
|
2012-03-17 02:24:12 +04:00
|
|
|
mEGLLibrary = LoadApitraceLibrary();
|
2012-05-15 22:55:50 +04:00
|
|
|
#endif
|
2012-03-17 02:24:12 +04:00
|
|
|
|
2012-05-15 22:55:50 +04:00
|
|
|
if (!mEGLLibrary) {
|
|
|
|
printf_stderr("Attempting load of libEGL.so\n");
|
|
|
|
mEGLLibrary = PR_LoadLibrary("libEGL.so");
|
|
|
|
}
|
2012-03-17 02:24:12 +04:00
|
|
|
#if defined(XP_UNIX)
|
2012-05-15 22:55:50 +04:00
|
|
|
if (!mEGLLibrary) {
|
|
|
|
mEGLLibrary = PR_LoadLibrary("libEGL.so.1");
|
2012-03-17 02:24:12 +04:00
|
|
|
}
|
2012-05-15 22:55:50 +04:00
|
|
|
#endif
|
2012-03-17 02:24:12 +04:00
|
|
|
|
|
|
|
if (!mEGLLibrary) {
|
|
|
|
NS_WARNING("Couldn't load EGL LIB.");
|
2016-09-13 21:17:29 +03:00
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_LOAD_2");
|
2012-03-17 02:24:12 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-15 22:55:50 +04:00
|
|
|
#endif // !Windows
|
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
#define SYMBOL(X) { (PRFuncPtr*)&mSymbols.f##X, { "egl" #X, nullptr } }
|
|
|
|
#define END_OF_SYMBOLS { nullptr, { nullptr } }
|
2012-03-17 02:24:12 +04:00
|
|
|
|
|
|
|
GLLibraryLoader::SymLoadStruct earlySymbols[] = {
|
|
|
|
SYMBOL(GetDisplay),
|
2014-10-09 03:32:50 +04:00
|
|
|
SYMBOL(Terminate),
|
2012-03-17 02:24:12 +04:00
|
|
|
SYMBOL(GetCurrentSurface),
|
|
|
|
SYMBOL(GetCurrentContext),
|
|
|
|
SYMBOL(MakeCurrent),
|
|
|
|
SYMBOL(DestroyContext),
|
|
|
|
SYMBOL(CreateContext),
|
|
|
|
SYMBOL(DestroySurface),
|
|
|
|
SYMBOL(CreateWindowSurface),
|
|
|
|
SYMBOL(CreatePbufferSurface),
|
2017-03-04 03:49:49 +03:00
|
|
|
SYMBOL(CreatePbufferFromClientBuffer),
|
2012-03-17 02:24:12 +04:00
|
|
|
SYMBOL(CreatePixmapSurface),
|
|
|
|
SYMBOL(BindAPI),
|
|
|
|
SYMBOL(Initialize),
|
|
|
|
SYMBOL(ChooseConfig),
|
|
|
|
SYMBOL(GetError),
|
|
|
|
SYMBOL(GetConfigs),
|
|
|
|
SYMBOL(GetConfigAttrib),
|
|
|
|
SYMBOL(WaitNative),
|
|
|
|
SYMBOL(GetProcAddress),
|
|
|
|
SYMBOL(SwapBuffers),
|
|
|
|
SYMBOL(CopyBuffers),
|
|
|
|
SYMBOL(QueryString),
|
|
|
|
SYMBOL(QueryContext),
|
|
|
|
SYMBOL(BindTexImage),
|
|
|
|
SYMBOL(ReleaseTexImage),
|
2017-11-24 03:09:29 +03:00
|
|
|
SYMBOL(SwapInterval),
|
2012-03-17 02:24:12 +04:00
|
|
|
SYMBOL(QuerySurface),
|
2017-03-04 03:49:49 +03:00
|
|
|
END_OF_SYMBOLS
|
2012-03-17 02:24:12 +04:00
|
|
|
};
|
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!GLLibraryLoader::LoadSymbols(mEGLLibrary, earlySymbols)) {
|
2012-03-17 02:24:12 +04:00
|
|
|
NS_WARNING("Couldn't find required entry points in EGL library (early init)");
|
2016-09-13 21:17:29 +03:00
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_EGL_SYM");
|
2012-03-17 02:24:12 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
{
|
|
|
|
const char internalFuncName[] = "_Z35eglQueryStringImplementationANDROIDPvi";
|
|
|
|
const auto& internalFunc = PR_FindFunctionSymbol(mEGLLibrary, internalFuncName);
|
|
|
|
if (internalFunc) {
|
|
|
|
*(PRFuncPtr*)&mSymbols.fQueryString = internalFunc;
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 03:59:30 +04:00
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
InitClientExtensions();
|
2015-07-10 21:47:48 +03:00
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
const auto lookupFunction =
|
2015-07-10 21:47:48 +03:00
|
|
|
(GLLibraryLoader::PlatformLookupFunction)mSymbols.fGetProcAddress;
|
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
const auto fnLoadSymbols = [&](const GLLibraryLoader::SymLoadStruct* symbols) {
|
|
|
|
if (GLLibraryLoader::LoadSymbols(mEGLLibrary, symbols, lookupFunction))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
ClearSymbols(symbols);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2017-03-04 07:38:57 +03:00
|
|
|
// Check the ANGLE support the system has
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
mIsANGLE = IsExtensionSupported(ANGLE_platform_angle);
|
|
|
|
|
|
|
|
EGLDisplay chosenDisplay = nullptr;
|
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
// Client exts are ready. (But not display exts!)
|
2017-03-04 07:38:57 +03:00
|
|
|
|
|
|
|
if (mIsANGLE) {
|
|
|
|
MOZ_ASSERT(IsExtensionSupported(ANGLE_platform_angle_d3d));
|
|
|
|
const GLLibraryLoader::SymLoadStruct angleSymbols[] = {
|
2017-03-04 03:49:49 +03:00
|
|
|
SYMBOL(GetPlatformDisplayEXT),
|
|
|
|
END_OF_SYMBOLS
|
2015-07-10 21:47:48 +03:00
|
|
|
};
|
2017-03-04 07:38:57 +03:00
|
|
|
if (!fnLoadSymbols(angleSymbols)) {
|
|
|
|
gfxCriticalError() << "Failed to load ANGLE symbols!";
|
|
|
|
return false;
|
2015-07-10 21:47:48 +03:00
|
|
|
}
|
2018-01-09 13:07:50 +03:00
|
|
|
MOZ_ASSERT(IsExtensionSupported(ANGLE_platform_angle_d3d));
|
|
|
|
const GLLibraryLoader::SymLoadStruct createDeviceSymbols[] = {
|
|
|
|
SYMBOL(CreateDeviceANGLE),
|
|
|
|
SYMBOL(ReleaseDeviceANGLE),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(createDeviceSymbols)) {
|
|
|
|
NS_ERROR("EGL supports ANGLE_device_creation without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(ANGLE_device_creation);
|
|
|
|
}
|
2015-07-10 21:47:48 +03:00
|
|
|
}
|
2015-11-13 00:41:45 +03:00
|
|
|
|
|
|
|
if (IsExtensionSupported(ANGLE_platform_angle_d3d)) {
|
2016-07-28 00:14:19 +03:00
|
|
|
nsCString accelAngleFailureId;
|
|
|
|
bool accelAngleSupport = IsAccelAngleSupported(gfxInfo, &accelAngleFailureId);
|
2015-07-23 20:12:59 +03:00
|
|
|
bool shouldTryAccel = forceAccel || accelAngleSupport;
|
2016-07-13 20:51:40 +03:00
|
|
|
bool shouldTryWARP = !forceAccel; // Only if ANGLE not supported or fails
|
|
|
|
|
|
|
|
// If WARP preferred, will override ANGLE support
|
2015-07-23 20:11:04 +03:00
|
|
|
if (gfxPrefs::WebGLANGLEForceWARP()) {
|
|
|
|
shouldTryWARP = true;
|
2015-07-23 20:12:59 +03:00
|
|
|
shouldTryAccel = false;
|
2016-07-28 00:14:19 +03:00
|
|
|
if (accelAngleFailureId.IsEmpty()) {
|
|
|
|
accelAngleFailureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_FORCE_WARP");
|
|
|
|
}
|
2015-07-23 20:11:04 +03:00
|
|
|
}
|
|
|
|
|
2016-07-13 20:51:40 +03:00
|
|
|
// Hardware accelerated ANGLE path (supported or force accel)
|
|
|
|
if (shouldTryAccel) {
|
2016-07-16 01:12:46 +03:00
|
|
|
chosenDisplay = GetAndInitDisplayForAccelANGLE(*this, out_failureId);
|
2015-07-23 20:11:04 +03:00
|
|
|
}
|
2014-04-03 09:29:22 +04:00
|
|
|
|
2016-07-28 00:14:19 +03:00
|
|
|
// Report the acceleration status to telemetry
|
|
|
|
if (!chosenDisplay) {
|
|
|
|
if (accelAngleFailureId.IsEmpty()) {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID,
|
|
|
|
NS_LITERAL_CSTRING("FEATURE_FAILURE_ACCL_ANGLE_UNKNOWN"));
|
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID,
|
|
|
|
accelAngleFailureId);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Telemetry::Accumulate(Telemetry::CANVAS_WEBGL_ACCL_FAILURE_ID,
|
|
|
|
NS_LITERAL_CSTRING("SUCCESS"));
|
|
|
|
}
|
|
|
|
|
2016-07-13 20:51:40 +03:00
|
|
|
// Fallback to a WARP display if ANGLE fails, or if WARP is forced
|
|
|
|
if (!chosenDisplay && shouldTryWARP) {
|
|
|
|
chosenDisplay = GetAndInitWARPDisplay(*this, EGL_DEFAULT_DISPLAY);
|
|
|
|
if (!chosenDisplay) {
|
2016-06-11 05:01:00 +03:00
|
|
|
if (out_failureId->IsEmpty()) {
|
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WARP_FALLBACK");
|
2016-06-06 23:52:42 +03:00
|
|
|
}
|
2016-07-13 20:51:40 +03:00
|
|
|
NS_ERROR("Fallback WARP context failed to initialize.");
|
2015-11-13 00:41:45 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-13 20:51:40 +03:00
|
|
|
mIsWARP = true;
|
2014-10-09 03:32:50 +04:00
|
|
|
}
|
2015-11-13 00:41:45 +03:00
|
|
|
} else {
|
|
|
|
chosenDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY);
|
2015-07-23 20:12:59 +03:00
|
|
|
}
|
2012-03-17 02:24:12 +04:00
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
if (!chosenDisplay) {
|
2016-06-11 05:01:00 +03:00
|
|
|
if (out_failureId->IsEmpty()) {
|
|
|
|
*out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_DISPLAY");
|
2016-06-06 23:52:42 +03:00
|
|
|
}
|
2015-11-13 00:41:45 +03:00
|
|
|
NS_WARNING("Failed to initialize a display.");
|
|
|
|
return false;
|
2012-03-17 02:24:12 +04:00
|
|
|
}
|
2015-11-13 00:41:45 +03:00
|
|
|
mEGLDisplay = chosenDisplay;
|
2014-05-03 02:31:05 +04:00
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
InitDisplayExtensions();
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Alright, load display exts.
|
2012-03-17 02:24:12 +04:00
|
|
|
|
2012-06-13 01:39:18 +04:00
|
|
|
if (IsExtensionSupported(KHR_lock_surface)) {
|
2017-03-04 03:49:49 +03:00
|
|
|
const GLLibraryLoader::SymLoadStruct lockSymbols[] = {
|
|
|
|
SYMBOL(LockSurfaceKHR),
|
|
|
|
SYMBOL(UnlockSurfaceKHR),
|
|
|
|
END_OF_SYMBOLS
|
2012-03-17 02:24:12 +04:00
|
|
|
};
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!fnLoadSymbols(lockSymbols)) {
|
2012-06-13 01:39:18 +04:00
|
|
|
NS_ERROR("EGL supports KHR_lock_surface without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(KHR_lock_surface);
|
|
|
|
}
|
2012-03-17 02:24:12 +04:00
|
|
|
}
|
|
|
|
|
2012-06-13 01:39:18 +04:00
|
|
|
if (IsExtensionSupported(ANGLE_surface_d3d_texture_2d_share_handle)) {
|
2017-03-04 03:49:49 +03:00
|
|
|
const GLLibraryLoader::SymLoadStruct d3dSymbols[] = {
|
|
|
|
SYMBOL(QuerySurfacePointerANGLE),
|
|
|
|
END_OF_SYMBOLS
|
2012-03-17 02:24:12 +04:00
|
|
|
};
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!fnLoadSymbols(d3dSymbols)) {
|
2012-06-13 01:39:18 +04:00
|
|
|
NS_ERROR("EGL supports ANGLE_surface_d3d_texture_2d_share_handle without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(ANGLE_surface_d3d_texture_2d_share_handle);
|
|
|
|
}
|
2012-03-17 02:24:12 +04:00
|
|
|
}
|
|
|
|
|
2012-06-13 01:39:43 +04:00
|
|
|
if (IsExtensionSupported(KHR_fence_sync)) {
|
2017-03-04 03:49:49 +03:00
|
|
|
const GLLibraryLoader::SymLoadStruct syncSymbols[] = {
|
|
|
|
SYMBOL(CreateSyncKHR),
|
|
|
|
SYMBOL(DestroySyncKHR),
|
|
|
|
SYMBOL(ClientWaitSyncKHR),
|
|
|
|
SYMBOL(GetSyncAttribKHR),
|
|
|
|
END_OF_SYMBOLS
|
2012-06-13 01:39:43 +04:00
|
|
|
};
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!fnLoadSymbols(syncSymbols)) {
|
2012-06-13 01:39:43 +04:00
|
|
|
NS_ERROR("EGL supports KHR_fence_sync without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(KHR_fence_sync);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
if (IsExtensionSupported(KHR_image) || IsExtensionSupported(KHR_image_base)) {
|
2017-03-04 03:49:49 +03:00
|
|
|
const GLLibraryLoader::SymLoadStruct imageSymbols[] = {
|
|
|
|
SYMBOL(CreateImageKHR),
|
|
|
|
SYMBOL(DestroyImageKHR),
|
|
|
|
END_OF_SYMBOLS
|
2013-02-14 03:26:24 +04:00
|
|
|
};
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!fnLoadSymbols(imageSymbols)) {
|
2013-02-14 03:26:24 +04:00
|
|
|
NS_ERROR("EGL supports KHR_image(_base) without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(KHR_image);
|
|
|
|
MarkExtensionUnsupported(KHR_image_base);
|
|
|
|
MarkExtensionUnsupported(KHR_image_pixmap);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MarkExtensionUnsupported(KHR_image_pixmap);
|
|
|
|
}
|
|
|
|
|
2014-06-08 17:18:53 +04:00
|
|
|
if (IsExtensionSupported(ANDROID_native_fence_sync)) {
|
2017-03-04 03:49:49 +03:00
|
|
|
const GLLibraryLoader::SymLoadStruct nativeFenceSymbols[] = {
|
|
|
|
SYMBOL(DupNativeFenceFDANDROID),
|
|
|
|
END_OF_SYMBOLS
|
2014-06-08 17:18:53 +04:00
|
|
|
};
|
2017-03-04 03:49:49 +03:00
|
|
|
if (!fnLoadSymbols(nativeFenceSymbols)) {
|
2014-06-08 17:18:53 +04:00
|
|
|
NS_ERROR("EGL supports ANDROID_native_fence_sync without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(ANDROID_native_fence_sync);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-29 07:15:07 +03:00
|
|
|
if (IsExtensionSupported(KHR_stream)) {
|
|
|
|
const GLLibraryLoader::SymLoadStruct streamSymbols[] = {
|
|
|
|
SYMBOL(CreateStreamKHR),
|
|
|
|
SYMBOL(DestroyStreamKHR),
|
|
|
|
SYMBOL(QueryStreamKHR),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(streamSymbols)) {
|
|
|
|
NS_ERROR("EGL supports KHR_stream without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(KHR_stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExtensionSupported(KHR_stream_consumer_gltexture)) {
|
|
|
|
const GLLibraryLoader::SymLoadStruct streamConsumerSymbols[] = {
|
2017-07-18 05:17:41 +03:00
|
|
|
SYMBOL(StreamConsumerGLTextureExternalKHR),
|
2017-05-29 07:15:07 +03:00
|
|
|
SYMBOL(StreamConsumerAcquireKHR),
|
|
|
|
SYMBOL(StreamConsumerReleaseKHR),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(streamConsumerSymbols)) {
|
|
|
|
NS_ERROR("EGL supports KHR_stream_consumer_gltexture without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(KHR_stream_consumer_gltexture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExtensionSupported(EXT_device_query)) {
|
|
|
|
const GLLibraryLoader::SymLoadStruct queryDisplaySymbols[] = {
|
2017-08-07 13:15:21 +03:00
|
|
|
SYMBOL(QueryDisplayAttribEXT),
|
2017-05-29 07:15:07 +03:00
|
|
|
SYMBOL(QueryDeviceAttribEXT),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(queryDisplaySymbols)) {
|
|
|
|
NS_ERROR("EGL supports EXT_device_query without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(EXT_device_query);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExtensionSupported(NV_stream_consumer_gltexture_yuv)) {
|
|
|
|
const GLLibraryLoader::SymLoadStruct nvStreamSymbols[] = {
|
|
|
|
SYMBOL(StreamConsumerGLTextureExternalAttribsNV),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(nvStreamSymbols)) {
|
|
|
|
NS_ERROR("EGL supports NV_stream_consumer_gltexture_yuv without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(NV_stream_consumer_gltexture_yuv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsExtensionSupported(ANGLE_stream_producer_d3d_texture_nv12)) {
|
|
|
|
const GLLibraryLoader::SymLoadStruct nvStreamSymbols[] = {
|
|
|
|
SYMBOL(CreateStreamProducerD3DTextureNV12ANGLE),
|
|
|
|
SYMBOL(StreamPostD3DTextureNV12ANGLE),
|
|
|
|
END_OF_SYMBOLS
|
|
|
|
};
|
|
|
|
if (!fnLoadSymbols(nvStreamSymbols)) {
|
|
|
|
NS_ERROR("EGL supports ANGLE_stream_producer_d3d_texture_nv12 without exposing its functions!");
|
|
|
|
MarkExtensionUnsupported(ANGLE_stream_producer_d3d_texture_nv12);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
mInitialized = true;
|
|
|
|
reporter.SetSuccessful();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-04 03:49:49 +03:00
|
|
|
#undef SYMBOL
|
|
|
|
#undef END_OF_SYMBOLS
|
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
template<size_t N>
|
|
|
|
static void
|
|
|
|
MarkExtensions(const char* rawExtString, bool shouldDumpExts, const char* extType,
|
|
|
|
std::bitset<N>* const out)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(rawExtString);
|
|
|
|
|
|
|
|
const nsDependentCString extString(rawExtString);
|
|
|
|
|
|
|
|
std::vector<nsCString> extList;
|
|
|
|
SplitByChar(extString, ' ', &extList);
|
|
|
|
|
|
|
|
if (shouldDumpExts) {
|
|
|
|
printf_stderr("%u EGL %s extensions: (*: recognized)\n",
|
|
|
|
(uint32_t)extList.size(), extType);
|
|
|
|
}
|
|
|
|
|
|
|
|
MarkBitfieldByStrings(extList, shouldDumpExts, sEGLExtensionNames, out);
|
|
|
|
}
|
|
|
|
|
2012-06-13 01:39:18 +04:00
|
|
|
void
|
2015-11-13 00:41:45 +03:00
|
|
|
GLLibraryEGL::InitClientExtensions()
|
2012-06-13 01:39:18 +04:00
|
|
|
{
|
2015-11-13 00:41:45 +03:00
|
|
|
const bool shouldDumpExts = GLContext::ShouldDumpExts();
|
2012-06-13 01:39:18 +04:00
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
const char* rawExtString = nullptr;
|
|
|
|
|
|
|
|
#ifndef ANDROID
|
|
|
|
// Bug 1209612: Crashes on a number of android drivers.
|
|
|
|
// Ideally we would only blocklist this there, but for now we don't need the client
|
|
|
|
// extension list on ANDROID (we mostly need it on ANGLE), and we'd rather not crash.
|
|
|
|
rawExtString = (const char*)fQueryString(nullptr, LOCAL_EGL_EXTENSIONS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!rawExtString) {
|
|
|
|
if (shouldDumpExts) {
|
|
|
|
printf_stderr("No EGL client extensions.\n");
|
|
|
|
}
|
|
|
|
return;
|
2015-01-29 11:44:19 +03:00
|
|
|
}
|
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
MarkExtensions(rawExtString, shouldDumpExts, "client", &mAvailableExtensions);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLLibraryEGL::InitDisplayExtensions()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mEGLDisplay);
|
|
|
|
|
2015-02-13 06:00:41 +03:00
|
|
|
const bool shouldDumpExts = GLContext::ShouldDumpExts();
|
2015-11-13 00:41:45 +03:00
|
|
|
|
|
|
|
const auto rawExtString = (const char*)fQueryString(mEGLDisplay,
|
|
|
|
LOCAL_EGL_EXTENSIONS);
|
|
|
|
if (!rawExtString) {
|
|
|
|
NS_WARNING("Failed to query EGL display extensions!.");
|
|
|
|
return;
|
2015-02-13 06:00:41 +03:00
|
|
|
}
|
|
|
|
|
2015-11-13 00:41:45 +03:00
|
|
|
MarkExtensions(rawExtString, shouldDumpExts, "display", &mAvailableExtensions);
|
2012-06-13 01:39:18 +04:00
|
|
|
}
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
void
|
|
|
|
GLLibraryEGL::DumpEGLConfig(EGLConfig cfg)
|
|
|
|
{
|
|
|
|
int attrval;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
#define ATTR(_x) do { \
|
|
|
|
fGetConfigAttrib(mEGLDisplay, cfg, LOCAL_EGL_##_x, &attrval); \
|
|
|
|
if ((err = fGetError()) != 0x3000) { \
|
|
|
|
printf_stderr(" %s: ERROR (0x%04x)\n", #_x, err); \
|
|
|
|
} else { \
|
|
|
|
printf_stderr(" %s: %d (0x%04x)\n", #_x, attrval, attrval); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
printf_stderr("EGL Config: %d [%p]\n", (int)(intptr_t)cfg, cfg);
|
|
|
|
|
|
|
|
ATTR(BUFFER_SIZE);
|
|
|
|
ATTR(ALPHA_SIZE);
|
|
|
|
ATTR(BLUE_SIZE);
|
|
|
|
ATTR(GREEN_SIZE);
|
|
|
|
ATTR(RED_SIZE);
|
|
|
|
ATTR(DEPTH_SIZE);
|
|
|
|
ATTR(STENCIL_SIZE);
|
|
|
|
ATTR(CONFIG_CAVEAT);
|
|
|
|
ATTR(CONFIG_ID);
|
|
|
|
ATTR(LEVEL);
|
|
|
|
ATTR(MAX_PBUFFER_HEIGHT);
|
|
|
|
ATTR(MAX_PBUFFER_PIXELS);
|
|
|
|
ATTR(MAX_PBUFFER_WIDTH);
|
|
|
|
ATTR(NATIVE_RENDERABLE);
|
|
|
|
ATTR(NATIVE_VISUAL_ID);
|
|
|
|
ATTR(NATIVE_VISUAL_TYPE);
|
|
|
|
ATTR(PRESERVED_RESOURCES);
|
|
|
|
ATTR(SAMPLES);
|
|
|
|
ATTR(SAMPLE_BUFFERS);
|
|
|
|
ATTR(SURFACE_TYPE);
|
|
|
|
ATTR(TRANSPARENT_TYPE);
|
|
|
|
ATTR(TRANSPARENT_RED_VALUE);
|
|
|
|
ATTR(TRANSPARENT_GREEN_VALUE);
|
|
|
|
ATTR(TRANSPARENT_BLUE_VALUE);
|
|
|
|
ATTR(BIND_TO_TEXTURE_RGB);
|
|
|
|
ATTR(BIND_TO_TEXTURE_RGBA);
|
|
|
|
ATTR(MIN_SWAP_INTERVAL);
|
|
|
|
ATTR(MAX_SWAP_INTERVAL);
|
|
|
|
ATTR(LUMINANCE_SIZE);
|
|
|
|
ATTR(ALPHA_MASK_SIZE);
|
|
|
|
ATTR(COLOR_BUFFER_TYPE);
|
|
|
|
ATTR(RENDERABLE_TYPE);
|
|
|
|
ATTR(CONFORMANT);
|
|
|
|
|
|
|
|
#undef ATTR
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GLLibraryEGL::DumpEGLConfigs()
|
|
|
|
{
|
|
|
|
int nc = 0;
|
2013-07-20 12:48:55 +04:00
|
|
|
fGetConfigs(mEGLDisplay, nullptr, 0, &nc);
|
2016-06-11 04:37:07 +03:00
|
|
|
EGLConfig* ec = new EGLConfig[nc];
|
2012-03-17 02:24:12 +04:00
|
|
|
fGetConfigs(mEGLDisplay, ec, nc, &nc);
|
|
|
|
|
|
|
|
for (int i = 0; i < nc; ++i) {
|
2016-06-07 02:29:08 +03:00
|
|
|
printf_stderr("========= EGL Config %d ========\n", i);
|
2012-03-17 02:24:12 +04:00
|
|
|
DumpEGLConfig(ec[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] ec;
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:29:08 +03:00
|
|
|
static bool
|
|
|
|
ShouldTrace()
|
|
|
|
{
|
|
|
|
static bool ret = gfxEnv::GlDebugVerbose();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-04 06:24:51 +03:00
|
|
|
void
|
|
|
|
BeforeEGLCall(const char* glFunction)
|
2013-09-04 16:14:52 +04:00
|
|
|
{
|
2016-06-07 02:29:08 +03:00
|
|
|
if (ShouldTrace()) {
|
|
|
|
printf_stderr("[egl] > %s\n", glFunction);
|
2013-09-04 16:14:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 06:24:51 +03:00
|
|
|
void
|
|
|
|
AfterEGLCall(const char* glFunction)
|
2013-09-04 16:14:52 +04:00
|
|
|
{
|
2016-06-07 02:29:08 +03:00
|
|
|
if (ShouldTrace()) {
|
2013-09-04 16:14:52 +04:00
|
|
|
printf_stderr("[egl] < %s\n", glFunction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 02:24:12 +04:00
|
|
|
} /* namespace gl */
|
|
|
|
} /* namespace mozilla */
|
|
|
|
|