Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Unified Diff: ui/gfx/gl/gl_surface_egl.cc

Issue 6839008: Split EGLContext in GLContextEGL and GLSurfaceEGL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/gl/gl_surface_egl.cc
===================================================================
--- ui/gfx/gl/gl_surface_egl.cc (revision 80956)
+++ ui/gfx/gl/gl_surface_egl.cc (working copy)
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "ui/gfx/gl/gl_surface_egl.h"
#include "build/build_config.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/angle/include/EGL/egl.h"
-#include "ui/gfx/gl/gl_context_egl.h"
+#include "ui/gfx/gl/egl_util.h"
// This header must come after the above third-party include, as
// it brings in #defines that cause conflicts.
@@ -17,70 +18,22 @@
extern "C" {
#include <X11/Xlib.h>
}
-#define EGL_HAS_PBUFFERS 1
#endif
namespace gfx {
namespace {
-
-// The EGL configuration to use.
-EGLDisplay g_display;
EGLConfig g_config;
-
-// Returns the last EGL error as a string.
-const char* GetLastEGLErrorString() {
- EGLint error = eglGetError();
- switch (error) {
- case EGL_SUCCESS:
- return "EGL_SUCCESS";
- case EGL_BAD_ACCESS:
- return "EGL_BAD_ACCESS";
- case EGL_BAD_ALLOC:
- return "EGL_BAD_ALLOC";
- case EGL_BAD_ATTRIBUTE:
- return "EGL_BAD_ATTRIBUTE";
- case EGL_BAD_CONTEXT:
- return "EGL_BAD_CONTEXT";
- case EGL_BAD_CONFIG:
- return "EGL_BAD_CONFIG";
- case EGL_BAD_CURRENT_SURFACE:
- return "EGL_BAD_CURRENT_SURFACE";
- case EGL_BAD_DISPLAY:
- return "EGL_BAD_DISPLAY";
- case EGL_BAD_SURFACE:
- return "EGL_BAD_SURFACE";
- case EGL_BAD_MATCH:
- return "EGL_BAD_MATCH";
- case EGL_BAD_PARAMETER:
- return "EGL_BAD_PARAMETER";
- case EGL_BAD_NATIVE_PIXMAP:
- return "EGL_BAD_NATIVE_PIXMAP";
- case EGL_BAD_NATIVE_WINDOW:
- return "EGL_BAD_NATIVE_WINDOW";
- default:
- return "UNKNOWN";
- }
+EGLDisplay g_display;
}
-} // namespace anonymous
-SharedEGLSurface::SharedEGLSurface(EGLSurface surface) : surface_(surface) {
+GLSurfaceEGL::GLSurfaceEGL() {
}
-SharedEGLSurface::~SharedEGLSurface() {
- if (surface_) {
- if (!eglDestroySurface(g_display, surface_)) {
- LOG(ERROR) << "eglDestroySurface failed with error "
- << GetLastEGLErrorString();
- }
- }
+GLSurfaceEGL::~GLSurfaceEGL() {
}
-EGLSurface SharedEGLSurface::egl_surface() const {
- return surface_;
-}
-
-bool BaseEGLContext::InitializeOneOff() {
+bool GLSurfaceEGL::InitializeOneOff() {
static bool initialized = false;
if (initialized)
return true;
@@ -151,113 +104,61 @@
return true;
}
-EGLDisplay BaseEGLContext::GetDisplay() {
+EGLDisplay GLSurfaceEGL::GetDisplay() {
return g_display;
}
-std::string BaseEGLContext::GetExtensions() {
- const char* extensions = eglQueryString(g_display, EGL_EXTENSIONS);
- if (!extensions)
- return GLContext::GetExtensions();
-
- return GLContext::GetExtensions() + " " + extensions;
+EGLConfig GLSurfaceEGL::GetConfig() {
+ return g_config;
}
-NativeViewEGLContext::NativeViewEGLContext(void* window)
+NativeViewGLSurfaceEGL::NativeViewGLSurfaceEGL(void* window)
: window_(window),
- context_(NULL)
+ surface_(NULL)
{
}
-NativeViewEGLContext::~NativeViewEGLContext() {
+NativeViewGLSurfaceEGL::~NativeViewGLSurfaceEGL() {
+ Destroy();
}
-bool NativeViewEGLContext::Initialize() {
- DCHECK(!context_);
+bool NativeViewGLSurfaceEGL::Initialize() {
+ DCHECK(!surface_);
// Create a surface for the native window.
EGLNativeWindowType native_window =
reinterpret_cast<EGLNativeWindowType>(window_);
- surface_ = new SharedEGLSurface(eglCreateWindowSurface(g_display,
- g_config,
- native_window,
- NULL));
+ surface_ = eglCreateWindowSurface(g_display,
+ g_config,
+ native_window,
+ NULL);
- if (!surface_->egl_surface()) {
+ if (!surface_) {
LOG(ERROR) << "eglCreateWindowSurface failed with error "
<< GetLastEGLErrorString();
Destroy();
return false;
}
- static const EGLint kContextAttributes[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE
- };
-
- context_ = eglCreateContext(g_display, g_config, NULL, kContextAttributes);
- if (!context_) {
- LOG(ERROR) << "eglCreateContext failed with error "
- << GetLastEGLErrorString();
- Destroy();
- return false;
- }
-
- if (!MakeCurrent()) {
- LOG(ERROR) << "MakeCurrent failed.";
- Destroy();
- return false;
- }
-
- if (!InitializeCommon()) {
- LOG(ERROR) << "GLContext::InitializeCommon failed.";
- Destroy();
- return false;
- }
-
return true;
}
-void NativeViewEGLContext::Destroy() {
- if (context_) {
- if (!eglDestroyContext(g_display, context_)) {
- LOG(ERROR) << "eglDestroyContext failed with error "
+void NativeViewGLSurfaceEGL::Destroy() {
+ if (surface_) {
+ if (!eglDestroySurface(g_display, surface_)) {
+ LOG(ERROR) << "eglDestroySurface failed with error "
<< GetLastEGLErrorString();
}
-
- context_ = NULL;
+ surface_ = NULL;
}
-
- surface_ = NULL;
}
-bool NativeViewEGLContext::MakeCurrent() {
- DCHECK(context_);
- if (context_ == eglGetCurrentContext())
- return true;
- if (!eglMakeCurrent(g_display,
- surface_->egl_surface(),
- surface_->egl_surface(),
- context_)) {
- VLOG(1) << "eglMakeCurrent failed with error "
- << GetLastEGLErrorString();
- return false;
- }
-
- return true;
-}
-
-bool NativeViewEGLContext::IsCurrent() {
- DCHECK(context_);
- return context_ == eglGetCurrentContext();
-}
-
-bool NativeViewEGLContext::IsOffscreen() {
+bool NativeViewGLSurfaceEGL::IsOffscreen() {
return false;
}
-bool NativeViewEGLContext::SwapBuffers() {
- if (!eglSwapBuffers(g_display, surface_->egl_surface())) {
+bool NativeViewGLSurfaceEGL::SwapBuffers() {
+ if (!eglSwapBuffers(g_display, surface_)) {
VLOG(1) << "eglSwapBuffers failed with error "
<< GetLastEGLErrorString();
return false;
@@ -266,100 +167,46 @@
return true;
}
-gfx::Size NativeViewEGLContext::GetSize() {
-#if defined(OS_WIN)
- RECT rect;
- if (!GetClientRect(static_cast<HWND>(window_), &rect)) {
- DCHECK(false) << "GetClientRect failed.";
- return gfx::Size();
- }
-
- return gfx::Size(rect.right - rect.left, rect.bottom - rect.top);
-#else
- // TODO(piman): This doesn't work correctly on Windows yet, the size doesn't
- // get updated on resize. When it does, we can share the code.
+gfx::Size NativeViewGLSurfaceEGL::GetSize() {
EGLint width;
EGLint height;
- if (!eglQuerySurface(
- g_display, surface_->egl_surface(), EGL_WIDTH, &width) ||
- !eglQuerySurface(
- g_display, surface_->egl_surface(), EGL_HEIGHT, &height)) {
+ if (!eglQuerySurface(g_display, surface_, EGL_WIDTH, &width) ||
+ !eglQuerySurface(g_display, surface_, EGL_HEIGHT, &height)) {
NOTREACHED() << "eglQuerySurface failed with error "
<< GetLastEGLErrorString();
return gfx::Size();
}
return gfx::Size(width, height);
-#endif
}
-void* NativeViewEGLContext::GetHandle() {
- return context_;
-}
-
-void NativeViewEGLContext::SetSwapInterval(int interval) {
- DCHECK(IsCurrent());
- if (!eglSwapInterval(g_display, interval)) {
- LOG(ERROR) << "eglSwapInterval failed with error "
- << GetLastEGLErrorString();
- }
-}
-
-SharedEGLSurface* NativeViewEGLContext::GetSurface() {
+EGLSurface NativeViewGLSurfaceEGL::GetHandle() {
return surface_;
}
-SecondaryEGLContext::SecondaryEGLContext()
- : context_(NULL)
-{
+PbufferGLSurfaceEGL::PbufferGLSurfaceEGL(const gfx::Size& size)
+ : size_(size),
+ surface_(NULL) {
}
-SecondaryEGLContext::~SecondaryEGLContext() {
+PbufferGLSurfaceEGL::~PbufferGLSurfaceEGL() {
+ Destroy();
}
-bool SecondaryEGLContext::Initialize(GLContext* shared_context) {
- DCHECK(!context_);
+bool PbufferGLSurfaceEGL::Initialize() {
+ DCHECK(!surface_);
- static const EGLint kContextAttributes[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
+ const EGLint pbuffer_attribs[] = {
+ EGL_WIDTH, size_.width(),
+ EGL_HEIGHT, size_.height(),
EGL_NONE
};
- if (shared_context) {
- surface_ = static_cast<BaseEGLContext*>(shared_context)->GetSurface();
-
- // Create a context.
- context_ = eglCreateContext(g_display,
- g_config,
- shared_context->GetHandle(),
- kContextAttributes);
- } else {
-#ifdef EGL_HAS_PBUFFERS
- static const EGLint kPbufferAttribs[] = {
- EGL_WIDTH, 1,
- EGL_HEIGHT, 1,
- EGL_NONE
- };
-
- surface_ = new SharedEGLSurface(eglCreatePbufferSurface(g_display,
- g_config,
- kPbufferAttribs));
- if (!surface_->egl_surface()) {
- LOG(ERROR) << "eglCreatePbufferSurface failed with error "
- << GetLastEGLErrorString();
- Destroy();
- return false;
- }
-
- context_ = eglCreateContext(g_display, g_config, NULL, kContextAttributes);
-#else
- NOTIMPLEMENTED() << "Offscreen non-shared GLES context";
- return false;
-#endif
- }
-
- if (!context_) {
- LOG(ERROR) << "eglCreateContext failed with error "
+ surface_ = eglCreatePbufferSurface(g_display,
+ g_config,
+ pbuffer_attribs);
+ if (!surface_) {
+ LOG(ERROR) << "eglCreatePbufferSurface failed with error "
<< GetLastEGLErrorString();
Destroy();
return false;
@@ -368,64 +215,30 @@
return true;
}
-void SecondaryEGLContext::Destroy() {
- if (context_) {
- if (!eglDestroyContext(g_display, context_)) {
- LOG(ERROR) << "eglDestroyContext failed with error "
+void PbufferGLSurfaceEGL::Destroy() {
+ if (surface_) {
+ if (!eglDestroySurface(g_display, surface_)) {
+ LOG(ERROR) << "eglDestroySurface failed with error "
<< GetLastEGLErrorString();
}
-
- context_ = NULL;
+ surface_ = NULL;
}
-
- surface_ = NULL;
}
-bool SecondaryEGLContext::MakeCurrent() {
- DCHECK(context_);
- if (context_ == eglGetCurrentContext())
- return true;
- if (!eglMakeCurrent(g_display,
- surface_->egl_surface(),
- surface_->egl_surface(),
- context_)) {
- VLOG(1) << "eglMakeCurrent failed with error "
- << GetLastEGLErrorString();
- return false;
- }
-
+bool PbufferGLSurfaceEGL::IsOffscreen() {
return true;
}
-bool SecondaryEGLContext::IsCurrent() {
- DCHECK(context_);
- return context_ == eglGetCurrentContext();
-}
-
-bool SecondaryEGLContext::IsOffscreen() {
- return true;
-}
-
-bool SecondaryEGLContext::SwapBuffers() {
- NOTREACHED() << "Attempted to call SwapBuffers on a SecondaryEGLContext.";
+bool PbufferGLSurfaceEGL::SwapBuffers() {
+ NOTREACHED() << "Attempted to call SwapBuffers on a PbufferGLSurfaceEGL.";
return false;
}
-gfx::Size SecondaryEGLContext::GetSize() {
- NOTREACHED() << "Should not be requesting size of this SecondaryEGLContext.";
- return gfx::Size(1, 1);
+gfx::Size PbufferGLSurfaceEGL::GetSize() {
+ return size_;
}
-void* SecondaryEGLContext::GetHandle() {
- return context_;
-}
-
-void SecondaryEGLContext::SetSwapInterval(int interval) {
- DCHECK(IsCurrent());
- NOTREACHED() << "Attempt to call SetSwapInterval on a SecondaryEGLContext.";
-}
-
-SharedEGLSurface* SecondaryEGLContext::GetSurface() {
+EGLSurface PbufferGLSurfaceEGL::GetHandle() {
return surface_;
}
« no previous file with comments | « ui/gfx/gl/gl_surface_egl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698