| Index: app/gfx/gl/gl_context_egl.cc
|
| ===================================================================
|
| --- app/gfx/gl/gl_context_egl.cc (revision 71275)
|
| +++ app/gfx/gl/gl_context_egl.cc (working copy)
|
| @@ -58,6 +58,22 @@
|
| }
|
| } // namespace anonymous
|
|
|
| +SharedEGLSurface::SharedEGLSurface(EGLSurface surface) : surface_(surface) {
|
| +}
|
| +
|
| +SharedEGLSurface::~SharedEGLSurface() {
|
| + if (surface_) {
|
| + if (!eglDestroySurface(g_display, surface_)) {
|
| + LOG(ERROR) << "eglDestroySurface failed with error "
|
| + << GetLastEGLErrorString();
|
| + }
|
| + }
|
| +}
|
| +
|
| +EGLSurface SharedEGLSurface::egl_surface() const {
|
| + return surface_;
|
| +}
|
| +
|
| bool BaseEGLContext::InitializeOneOff() {
|
| static bool initialized = false;
|
| if (initialized)
|
| @@ -143,7 +159,6 @@
|
|
|
| NativeViewEGLContext::NativeViewEGLContext(void* window)
|
| : window_(window),
|
| - surface_(NULL),
|
| context_(NULL)
|
| {
|
| }
|
| @@ -157,9 +172,12 @@
|
| // Create a surface for the native window.
|
| EGLNativeWindowType native_window =
|
| reinterpret_cast<EGLNativeWindowType>(window_);
|
| - surface_ = eglCreateWindowSurface(g_display, g_config, native_window, NULL);
|
| + surface_ = new SharedEGLSurface(eglCreateWindowSurface(g_display,
|
| + g_config,
|
| + native_window,
|
| + NULL));
|
|
|
| - if (!surface_) {
|
| + if (!surface_->egl_surface()) {
|
| LOG(ERROR) << "eglCreateWindowSurface failed with error "
|
| << GetLastEGLErrorString();
|
| Destroy();
|
| @@ -204,20 +222,14 @@
|
| context_ = NULL;
|
| }
|
|
|
| - if (surface_) {
|
| - if (!eglDestroySurface(g_display, surface_)) {
|
| - LOG(ERROR) << "eglDestroySurface failed with error "
|
| - << GetLastEGLErrorString();
|
| - }
|
| -
|
| - surface_ = NULL;
|
| - }
|
| + surface_ = NULL;
|
| }
|
|
|
| bool NativeViewEGLContext::MakeCurrent() {
|
| DCHECK(context_);
|
| if (!eglMakeCurrent(g_display,
|
| - surface_, surface_,
|
| + surface_->egl_surface(),
|
| + surface_->egl_surface(),
|
| context_)) {
|
| VLOG(1) << "eglMakeCurrent failed with error "
|
| << GetLastEGLErrorString();
|
| @@ -237,7 +249,7 @@
|
| }
|
|
|
| bool NativeViewEGLContext::SwapBuffers() {
|
| - if (!eglSwapBuffers(g_display, surface_)) {
|
| + if (!eglSwapBuffers(g_display, surface_->egl_surface())) {
|
| VLOG(1) << "eglSwapBuffers failed with error "
|
| << GetLastEGLErrorString();
|
| return false;
|
| @@ -260,8 +272,10 @@
|
| // get updated on resize. When it does, we can share the code.
|
| EGLint width;
|
| EGLint height;
|
| - if (!eglQuerySurface(g_display, surface_, EGL_WIDTH, &width) ||
|
| - !eglQuerySurface(g_display, surface_, EGL_HEIGHT, &height)) {
|
| + if (!eglQuerySurface(
|
| + g_display, surface_->egl_surface(), EGL_WIDTH, &width) ||
|
| + !eglQuerySurface(
|
| + g_display, surface_->egl_surface(), EGL_HEIGHT, &height)) {
|
| NOTREACHED() << "eglQuerySurface failed with error "
|
| << GetLastEGLErrorString();
|
| return gfx::Size();
|
| @@ -283,14 +297,12 @@
|
| }
|
| }
|
|
|
| -EGLSurface NativeViewEGLContext::GetSurface() {
|
| +SharedEGLSurface* NativeViewEGLContext::GetSurface() {
|
| return surface_;
|
| }
|
|
|
| SecondaryEGLContext::SecondaryEGLContext()
|
| - : surface_(NULL),
|
| - own_surface_(false),
|
| - context_(NULL)
|
| + : context_(NULL)
|
| {
|
| }
|
|
|
| @@ -307,7 +319,6 @@
|
|
|
| if (shared_context) {
|
| surface_ = static_cast<BaseEGLContext*>(shared_context)->GetSurface();
|
| - own_surface_ = false;
|
|
|
| // Create a context.
|
| context_ = eglCreateContext(g_display,
|
| @@ -322,13 +333,15 @@
|
| EGL_NONE
|
| };
|
|
|
| - surface_ = eglCreatePbufferSurface(g_display, g_config, kPbufferAttribs);
|
| - if (!surface_) {
|
| + surface_ = new SharedEGLSurface(eglCreatePbufferSurface(g_display,
|
| + g_config,
|
| + kPbufferAttribs));
|
| + if (!surface_->egl_surface()) {
|
| LOG(ERROR) << "eglCreatePbufferSurface failed with error "
|
| << GetLastEGLErrorString();
|
| + Destroy();
|
| return false;
|
| }
|
| - own_surface_ = true;
|
|
|
| context_ = eglCreateContext(g_display, g_config, NULL, kContextAttributes);
|
| #else
|
| @@ -348,16 +361,6 @@
|
| }
|
|
|
| void SecondaryEGLContext::Destroy() {
|
| - if (own_surface_) {
|
| - if (!eglDestroySurface(g_display, surface_)) {
|
| - LOG(ERROR) << "eglDestroySurface failed with error "
|
| - << GetLastEGLErrorString();
|
| - }
|
| -
|
| - own_surface_ = false;
|
| - }
|
| - surface_ = NULL;
|
| -
|
| if (context_) {
|
| if (!eglDestroyContext(g_display, context_)) {
|
| LOG(ERROR) << "eglDestroyContext failed with error "
|
| @@ -366,12 +369,15 @@
|
|
|
| context_ = NULL;
|
| }
|
| +
|
| + surface_ = NULL;
|
| }
|
|
|
| bool SecondaryEGLContext::MakeCurrent() {
|
| DCHECK(context_);
|
| if (!eglMakeCurrent(g_display,
|
| - surface_, surface_,
|
| + surface_->egl_surface(),
|
| + surface_->egl_surface(),
|
| context_)) {
|
| VLOG(1) << "eglMakeCurrent failed with error "
|
| << GetLastEGLErrorString();
|
| @@ -409,7 +415,7 @@
|
| NOTREACHED() << "Attempt to call SetSwapInterval on a SecondaryEGLContext.";
|
| }
|
|
|
| -EGLSurface SecondaryEGLContext::GetSurface() {
|
| +SharedEGLSurface* SecondaryEGLContext::GetSurface() {
|
| return surface_;
|
| }
|
|
|
|
|