summaryrefslogtreecommitdiffstats
path: root/ui/gfx/gl
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gfx/gl')
-rw-r--r--ui/gfx/gl/gl.gyp1
-rw-r--r--ui/gfx/gl/gl_context_egl.cc18
-rw-r--r--ui/gfx/gl/gl_context_egl.h4
-rw-r--r--ui/gfx/gl/gl_implementation_win.cc11
-rw-r--r--ui/gfx/gl/gl_surface.h2
-rw-r--r--ui/gfx/gl/gl_surface_egl.cc96
-rw-r--r--ui/gfx/gl/gl_surface_egl.h14
-rw-r--r--ui/gfx/gl/gl_surface_linux.cc12
-rw-r--r--ui/gfx/gl/gl_surface_mac.cc4
-rw-r--r--ui/gfx/gl/gl_surface_win.cc10
10 files changed, 139 insertions, 33 deletions
diff --git a/ui/gfx/gl/gl.gyp b/ui/gfx/gl/gl.gyp
index f7c7879..5771682 100644
--- a/ui/gfx/gl/gl.gyp
+++ b/ui/gfx/gl/gl.gyp
@@ -20,6 +20,7 @@
'gl_binding_output_dir': '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gl',
},
'include_dirs': [
+ '<(DEPTH)/third_party/swiftshader/include',
'<(DEPTH)/third_party/mesa/MesaLib/include',
'<(gl_binding_output_dir)',
],
diff --git a/ui/gfx/gl/gl_context_egl.cc b/ui/gfx/gl/gl_context_egl.cc
index 63f63e9..f18d59f 100644
--- a/ui/gfx/gl/gl_context_egl.cc
+++ b/ui/gfx/gl/gl_context_egl.cc
@@ -24,7 +24,7 @@ extern "C" {
namespace gfx {
std::string GLContextEGL::GetExtensions() {
- const char* extensions = eglQueryString(GLSurfaceEGL::GetDisplay(),
+ const char* extensions = eglQueryString(display_,
EGL_EXTENSIONS);
if (!extensions)
return GLContext::GetExtensions();
@@ -51,9 +51,13 @@ bool GLContextEGL::Initialize(GLSurface* compatible_surface) {
EGL_NONE
};
+ GLSurfaceEGL* egl_surface = static_cast<GLSurfaceEGL*>(compatible_surface);
+ display_ = egl_surface->GetDisplay();
+ config_ = egl_surface->GetConfig();
+
context_ = eglCreateContext(
- GLSurfaceEGL::GetDisplay(),
- GLSurfaceEGL::GetConfig(),
+ display_,
+ config_,
share_group() ? share_group()->GetHandle() : NULL,
kContextAttributes);
if (!context_) {
@@ -68,7 +72,7 @@ bool GLContextEGL::Initialize(GLSurface* compatible_surface) {
void GLContextEGL::Destroy() {
if (context_) {
- if (!eglDestroyContext(GLSurfaceEGL::GetDisplay(), context_)) {
+ if (!eglDestroyContext(display_, context_)) {
LOG(ERROR) << "eglDestroyContext failed with error "
<< GetLastEGLErrorString();
}
@@ -82,7 +86,7 @@ bool GLContextEGL::MakeCurrent(GLSurface* surface) {
if (IsCurrent(surface))
return true;
- if (!eglMakeCurrent(GLSurfaceEGL::GetDisplay(),
+ if (!eglMakeCurrent(display_,
surface->GetHandle(),
surface->GetHandle(),
context_)) {
@@ -98,7 +102,7 @@ void GLContextEGL::ReleaseCurrent(GLSurface* surface) {
if (!IsCurrent(surface))
return;
- eglMakeCurrent(GLSurfaceEGL::GetDisplay(),
+ eglMakeCurrent(display_,
EGL_NO_SURFACE,
EGL_NO_SURFACE,
EGL_NO_CONTEXT);
@@ -123,7 +127,7 @@ void* GLContextEGL::GetHandle() {
void GLContextEGL::SetSwapInterval(int interval) {
DCHECK(IsCurrent(NULL));
- if (!eglSwapInterval(GLSurfaceEGL::GetDisplay(), interval)) {
+ if (!eglSwapInterval(display_, interval)) {
LOG(ERROR) << "eglSwapInterval failed with error "
<< GetLastEGLErrorString();
}
diff --git a/ui/gfx/gl/gl_context_egl.h b/ui/gfx/gl/gl_context_egl.h
index f1a8193..5a86f28 100644
--- a/ui/gfx/gl/gl_context_egl.h
+++ b/ui/gfx/gl/gl_context_egl.h
@@ -11,6 +11,8 @@
#include "ui/gfx/gl/gl_context.h"
typedef void* EGLContext;
+typedef void* EGLDisplay;
+typedef void* EGLConfig;
namespace gfx {
@@ -34,6 +36,8 @@ class GLContextEGL : public GLContext {
private:
EGLContext context_;
+ EGLDisplay display_;
+ EGLConfig config_;
DISALLOW_COPY_AND_ASSIGN(GLContextEGL);
};
diff --git a/ui/gfx/gl/gl_implementation_win.cc b/ui/gfx/gl/gl_implementation_win.cc
index 9061bb3..4d6fff7 100644
--- a/ui/gfx/gl/gl_implementation_win.cc
+++ b/ui/gfx/gl/gl_implementation_win.cc
@@ -12,6 +12,10 @@
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_implementation.h"
+#if defined(ENABLE_SWIFTSHADER)
+#include "software_renderer_d3d9.h"
+#endif
+
namespace gfx {
namespace {
@@ -72,6 +76,13 @@ bool InitializeGLBindings(GLImplementation implementation) {
if (!PathService::Get(base::DIR_MODULE, &module_path))
return false;
+#if defined(ENABLE_SWIFTSHADER)
+ base::NativeLibrary swiftshader_library = base::LoadNativeLibrary(
+ module_path.Append(L"swiftshader_d3d9.dll"), NULL);
+
+ SetupSoftwareRenderer();
+#endif
+
// Load libglesv2.dll before libegl.dll because the latter is dependent on
// the former and if there is another version of libglesv2.dll in the dll
// search path, it will get loaded.
diff --git a/ui/gfx/gl/gl_surface.h b/ui/gfx/gl/gl_surface.h
index 513f37d..7a89d5b 100644
--- a/ui/gfx/gl/gl_surface.h
+++ b/ui/gfx/gl/gl_surface.h
@@ -50,11 +50,13 @@ class GLSurface : public base::RefCounted<GLSurface> {
#if !defined(OS_MACOSX)
// Create a GL surface that renders directly to a view.
static scoped_refptr<GLSurface> CreateViewGLSurface(
+ bool software,
gfx::PluginWindowHandle window);
#endif
// Create a GL surface used for offscreen rendering.
static scoped_refptr<GLSurface> CreateOffscreenGLSurface(
+ bool software,
const gfx::Size& size);
protected:
diff --git a/ui/gfx/gl/gl_surface_egl.cc b/ui/gfx/gl/gl_surface_egl.cc
index 603cff4..bf509bd 100644
--- a/ui/gfx/gl/gl_surface_egl.cc
+++ b/ui/gfx/gl/gl_surface_egl.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/angle/include/EGL/egl.h"
+#include "third_party/angle/include/EGL/eglext.h"
#include "ui/gfx/gl/egl_util.h"
// This header must come after the above third-party include, as
@@ -26,6 +27,9 @@ namespace {
EGLConfig g_config;
EGLDisplay g_display;
EGLNativeDisplayType g_native_display;
+EGLConfig g_software_config;
+EGLDisplay g_software_display;
+EGLNativeDisplayType g_software_native_display;
}
GLSurfaceEGL::GLSurfaceEGL() {
@@ -85,39 +89,84 @@ bool GLSurfaceEGL::InitializeOneOff() {
return false;
}
- scoped_array<EGLConfig> configs(new EGLConfig[num_configs]);
if (!eglChooseConfig(g_display,
kConfigAttribs,
- configs.get(),
- num_configs,
+ &g_config,
+ 1,
&num_configs)) {
LOG(ERROR) << "eglChooseConfig failed with error "
<< GetLastEGLErrorString();
return false;
}
- g_config = configs[0];
-
initialized = true;
+
+#if defined(USE_X11)
+ return true;
+#else
+ g_software_native_display = EGL_SOFTWARE_DISPLAY_ANGLE;
+#endif
+ g_software_display = eglGetDisplay(g_software_native_display);
+ if (!g_software_display) {
+ return true;
+ }
+
+ if (!eglInitialize(g_software_display, NULL, NULL)) {
+ return true;
+ }
+
+ if (!eglChooseConfig(g_software_display,
+ kConfigAttribs,
+ NULL,
+ 0,
+ &num_configs)) {
+ g_software_display = NULL;
+ return true;
+ }
+
+ if (num_configs == 0) {
+ g_software_display = NULL;
+ return true;
+ }
+
+ if (!eglChooseConfig(g_software_display,
+ kConfigAttribs,
+ &g_software_config,
+ 1,
+ &num_configs)) {
+ g_software_display = NULL;
+ return false;
+ }
+
return true;
}
EGLDisplay GLSurfaceEGL::GetDisplay() {
- return g_display;
+ return software_ ? g_software_display : g_display;
}
EGLConfig GLSurfaceEGL::GetConfig() {
- return g_config;
+ return software_ ? g_software_config : g_config;
+}
+
+EGLDisplay GLSurfaceEGL::GetHardwareDisplay() {
+ return g_display;
+}
+
+EGLDisplay GLSurfaceEGL::GetSoftwareDisplay() {
+ return g_software_display;
}
EGLNativeDisplayType GLSurfaceEGL::GetNativeDisplay() {
return g_native_display;
}
-NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(gfx::PluginWindowHandle window)
+NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(bool software,
+ gfx::PluginWindowHandle window)
: window_(window),
surface_(NULL)
{
+ software_ = software;
}
NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
@@ -127,9 +176,14 @@ NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
bool NativeViewGLSurfaceEGL::Initialize() {
DCHECK(!surface_);
+ if (!GetDisplay()) {
+ LOG(ERROR) << "Trying to create surface with invalid display.";
+ return false;
+ }
+
// Create a surface for the native window.
- surface_ = eglCreateWindowSurface(g_display,
- g_config,
+ surface_ = eglCreateWindowSurface(GetDisplay(),
+ GetConfig(),
window_,
NULL);
@@ -145,7 +199,7 @@ bool NativeViewGLSurfaceEGL::Initialize() {
void NativeViewGLSurfaceEGL::Destroy() {
if (surface_) {
- if (!eglDestroySurface(g_display, surface_)) {
+ if (!eglDestroySurface(GetDisplay(), surface_)) {
LOG(ERROR) << "eglDestroySurface failed with error "
<< GetLastEGLErrorString();
}
@@ -158,7 +212,7 @@ bool NativeViewGLSurfaceEGL::IsOffscreen() {
}
bool NativeViewGLSurfaceEGL::SwapBuffers() {
- if (!eglSwapBuffers(g_display, surface_)) {
+ if (!eglSwapBuffers(GetDisplay(), surface_)) {
VLOG(1) << "eglSwapBuffers failed with error "
<< GetLastEGLErrorString();
return false;
@@ -170,8 +224,8 @@ bool NativeViewGLSurfaceEGL::SwapBuffers() {
gfx::Size NativeViewGLSurfaceEGL::GetSize() {
EGLint width;
EGLint height;
- if (!eglQuerySurface(g_display, surface_, EGL_WIDTH, &width) ||
- !eglQuerySurface(g_display, surface_, EGL_HEIGHT, &height)) {
+ if (!eglQuerySurface(GetDisplay(), surface_, EGL_WIDTH, &width) ||
+ !eglQuerySurface(GetDisplay(), surface_, EGL_HEIGHT, &height)) {
NOTREACHED() << "eglQuerySurface failed with error "
<< GetLastEGLErrorString();
return gfx::Size();
@@ -184,9 +238,10 @@ EGLSurface NativeViewGLSurfaceEGL::GetHandle() {
return surface_;
}
-PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size)
+PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(bool software, const gfx::Size& size)
: size_(size),
surface_(NULL) {
+ software_ = software;
}
PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
@@ -196,14 +251,19 @@ PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
bool PbufferGLSurfaceEGL::Initialize() {
DCHECK(!surface_);
+ if (!GetDisplay()) {
+ LOG(ERROR) << "Trying to create surface with invalid display.";
+ return false;
+ }
+
const EGLint pbuffer_attribs[] = {
EGL_WIDTH, size_.width(),
EGL_HEIGHT, size_.height(),
EGL_NONE
};
- surface_ = eglCreatePbufferSurface(g_display,
- g_config,
+ surface_ = eglCreatePbufferSurface(GetDisplay(),
+ GetConfig(),
pbuffer_attribs);
if (!surface_) {
LOG(ERROR) << "eglCreatePbufferSurface failed with error "
@@ -217,7 +277,7 @@ bool PbufferGLSurfaceEGL::Initialize() {
void PbufferGLSurfaceEGL::Destroy() {
if (surface_) {
- if (!eglDestroySurface(g_display, surface_)) {
+ if (!eglDestroySurface(GetDisplay(), surface_)) {
LOG(ERROR) << "eglDestroySurface failed with error "
<< GetLastEGLErrorString();
}
diff --git a/ui/gfx/gl/gl_surface_egl.h b/ui/gfx/gl/gl_surface_egl.h
index 2bf8f82..19e7f4f 100644
--- a/ui/gfx/gl/gl_surface_egl.h
+++ b/ui/gfx/gl/gl_surface_egl.h
@@ -33,10 +33,15 @@ class GLSurfaceEGL : public GLSurface {
virtual ~GLSurfaceEGL();
static bool InitializeOneOff();
- static EGLDisplay GetDisplay();
- static EGLConfig GetConfig();
+ EGLDisplay GetDisplay();
+ EGLConfig GetConfig();
+ static EGLDisplay GetHardwareDisplay();
+ static EGLDisplay GetSoftwareDisplay();
static EGLNativeDisplayType GetNativeDisplay();
+protected:
+ bool software_;
+
private:
DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL);
};
@@ -44,7 +49,8 @@ class GLSurfaceEGL : public GLSurface {
// Encapsulates an EGL surface bound to a view.
class NativeViewGLSurfaceEGL : public GLSurfaceEGL {
public:
- explicit NativeViewGLSurfaceEGL(gfx::PluginWindowHandle window);
+ explicit NativeViewGLSurfaceEGL(bool software,
+ gfx::PluginWindowHandle window);
virtual ~NativeViewGLSurfaceEGL();
// Implement GLSurface.
@@ -65,7 +71,7 @@ class NativeViewGLSurfaceEGL : public GLSurfaceEGL {
// Encapsulates a pbuffer EGL surface.
class PbufferGLSurfaceEGL : public GLSurfaceEGL {
public:
- explicit PbufferGLSurfaceEGL(const gfx::Size& size);
+ explicit PbufferGLSurfaceEGL(bool software, const gfx::Size& size);
virtual ~PbufferGLSurfaceEGL();
// Implement GLSurface.
diff --git a/ui/gfx/gl/gl_surface_linux.cc b/ui/gfx/gl/gl_surface_linux.cc
index fe96989..968ca618 100644
--- a/ui/gfx/gl/gl_surface_linux.cc
+++ b/ui/gfx/gl/gl_surface_linux.cc
@@ -244,7 +244,11 @@ bool NativeViewGLSurfaceOSMesa::UpdateSize() {
}
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
+ bool software,
gfx::PluginWindowHandle window) {
+ if (software)
+ return NULL;
+
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(
@@ -256,7 +260,7 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
}
case kGLImplementationEGLGLES2: {
scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL(
- window));
+ false, window));
if (!surface->Initialize())
return NULL;
@@ -279,7 +283,11 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
}
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
+ bool software,
const gfx::Size& size) {
+ if (software)
+ return NULL;
+
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
@@ -290,7 +298,7 @@ scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
return surface;
}
case kGLImplementationEGLGLES2: {
- scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(size));
+ scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(false, size));
if (!surface->Initialize())
return NULL;
diff --git a/ui/gfx/gl/gl_surface_mac.cc b/ui/gfx/gl/gl_surface_mac.cc
index 2367679..440db41 100644
--- a/ui/gfx/gl/gl_surface_mac.cc
+++ b/ui/gfx/gl/gl_surface_mac.cc
@@ -79,7 +79,11 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
#endif
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
+ bool software,
const gfx::Size& size) {
+ if (software)
+ return NULL;
+
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
scoped_refptr<GLSurface> surface(new GLSurfaceOSMesa(OSMESA_RGBA,
diff --git a/ui/gfx/gl/gl_surface_win.cc b/ui/gfx/gl/gl_surface_win.cc
index 6b3ea8c..77810af 100644
--- a/ui/gfx/gl/gl_surface_win.cc
+++ b/ui/gfx/gl/gl_surface_win.cc
@@ -168,6 +168,7 @@ void NativeViewGLSurfaceOSMesa::UpdateSize() {
}
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
+ bool software,
gfx::PluginWindowHandle window) {
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
@@ -179,7 +180,7 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
return surface;
}
case kGLImplementationEGLGLES2: {
- scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL(
+ scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGL(software,
window));
if (!surface->Initialize())
return NULL;
@@ -187,6 +188,8 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
return surface;
}
case kGLImplementationDesktopGL: {
+ if (software)
+ return NULL;
scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceWGL(
window));
if (!surface->Initialize())
@@ -203,6 +206,7 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
}
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
+ bool software,
const gfx::Size& size) {
switch (GetGLImplementation()) {
case kGLImplementationOSMesaGL: {
@@ -214,13 +218,15 @@ scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
return surface;
}
case kGLImplementationEGLGLES2: {
- scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(size));
+ scoped_refptr<GLSurface> surface(new PbufferGLSurfaceEGL(software, size));
if (!surface->Initialize())
return NULL;
return surface;
}
case kGLImplementationDesktopGL: {
+ if (software)
+ return NULL;
scoped_refptr<GLSurface> surface(new PbufferGLSurfaceWGL(size));
if (!surface->Initialize())
return NULL;