| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gl/gl_surface_egl.h" | 5 #include "ui/gl/gl_surface_egl.h" |
| 6 | 6 |
| 7 #if defined(OS_ANDROID) | 7 #if defined(OS_ANDROID) |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "ui/gl/egl_util.h" | 15 #include "ui/gl/egl_util.h" |
| 16 #include "ui/gl/gl_context.h" | 16 #include "ui/gl/gl_context.h" |
| 17 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
| 18 #include "ui/gl/gl_surface_stub.h" | 18 #include "ui/gl/gl_surface_stub.h" |
| 19 #include "ui/gl/scoped_make_current.h" |
| 19 | 20 |
| 20 #if defined(USE_X11) | 21 #if defined(USE_X11) |
| 21 extern "C" { | 22 extern "C" { |
| 22 #include <X11/Xlib.h> | 23 #include <X11/Xlib.h> |
| 23 } | 24 } |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 #if defined (USE_OZONE) | 27 #if defined (USE_OZONE) |
| 27 #include "ui/base/ozone/surface_factory_ozone.h" | 28 #include "ui/base/ozone/surface_factory_ozone.h" |
| 28 #endif | 29 #endif |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 return gfx::Size(); | 404 return gfx::Size(); |
| 404 } | 405 } |
| 405 | 406 |
| 406 return gfx::Size(width, height); | 407 return gfx::Size(width, height); |
| 407 } | 408 } |
| 408 | 409 |
| 409 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) { | 410 bool NativeViewGLSurfaceEGL::Resize(const gfx::Size& size) { |
| 410 if (size == GetSize()) | 411 if (size == GetSize()) |
| 411 return true; | 412 return true; |
| 412 | 413 |
| 413 GLContext* current_context = GLContext::GetCurrent(); | 414 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| 414 bool was_current = current_context && current_context->IsCurrent(this); | 415 GLContext* current_real_context = GLContext::GetRealCurrent(); |
| 415 if (was_current) | 416 bool was_current = |
| 416 current_context->ReleaseCurrent(this); | 417 current_real_context && current_real_context->IsCurrent(this); |
| 418 if (was_current) { |
| 419 scoped_make_current.reset( |
| 420 new ui::ScopedMakeCurrent(current_real_context, this)); |
| 421 current_real_context->ReleaseCurrent(this); |
| 422 } |
| 417 | 423 |
| 418 Destroy(); | 424 Destroy(); |
| 419 | 425 |
| 420 if (!Initialize()) { | 426 if (!Initialize()) { |
| 421 LOG(ERROR) << "Failed to resize pbuffer."; | 427 LOG(ERROR) << "Failed to resize window."; |
| 422 return false; | 428 return false; |
| 423 } | 429 } |
| 424 | 430 |
| 425 if (was_current) | |
| 426 return current_context->MakeCurrent(this); | |
| 427 return true; | 431 return true; |
| 428 } | 432 } |
| 429 | 433 |
| 430 bool NativeViewGLSurfaceEGL::Recreate() { | 434 bool NativeViewGLSurfaceEGL::Recreate() { |
| 431 Destroy(); | 435 Destroy(); |
| 432 if (!Initialize()) { | 436 if (!Initialize()) { |
| 433 LOG(ERROR) << "Failed to create surface."; | 437 LOG(ERROR) << "Failed to create surface."; |
| 434 return false; | 438 return false; |
| 435 } | 439 } |
| 436 return true; | 440 return true; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 551 } |
| 548 | 552 |
| 549 gfx::Size PbufferGLSurfaceEGL::GetSize() { | 553 gfx::Size PbufferGLSurfaceEGL::GetSize() { |
| 550 return size_; | 554 return size_; |
| 551 } | 555 } |
| 552 | 556 |
| 553 bool PbufferGLSurfaceEGL::Resize(const gfx::Size& size) { | 557 bool PbufferGLSurfaceEGL::Resize(const gfx::Size& size) { |
| 554 if (size == size_) | 558 if (size == size_) |
| 555 return true; | 559 return true; |
| 556 | 560 |
| 557 GLContext* current_context = GLContext::GetCurrent(); | 561 scoped_ptr<ui::ScopedMakeCurrent> scoped_make_current; |
| 558 bool was_current = current_context && current_context->IsCurrent(this); | 562 GLContext* current_real_context = GLContext::GetRealCurrent(); |
| 563 bool was_current = |
| 564 current_real_context && current_real_context->IsCurrent(this); |
| 565 if (was_current) { |
| 566 scoped_make_current.reset( |
| 567 new ui::ScopedMakeCurrent(current_real_context, this)); |
| 568 } |
| 559 | 569 |
| 560 size_ = size; | 570 size_ = size; |
| 561 | 571 |
| 562 if (!Initialize()) { | 572 if (!Initialize()) { |
| 563 LOG(ERROR) << "Failed to resize pbuffer."; | 573 LOG(ERROR) << "Failed to resize pbuffer."; |
| 564 return false; | 574 return false; |
| 565 } | 575 } |
| 566 | 576 |
| 567 if (was_current) | |
| 568 return current_context->MakeCurrent(this); | |
| 569 | |
| 570 return true; | 577 return true; |
| 571 } | 578 } |
| 572 | 579 |
| 573 EGLSurface PbufferGLSurfaceEGL::GetHandle() { | 580 EGLSurface PbufferGLSurfaceEGL::GetHandle() { |
| 574 return surface_; | 581 return surface_; |
| 575 } | 582 } |
| 576 | 583 |
| 577 void* PbufferGLSurfaceEGL::GetShareHandle() { | 584 void* PbufferGLSurfaceEGL::GetShareHandle() { |
| 578 #if defined(OS_ANDROID) | 585 #if defined(OS_ANDROID) |
| 579 NOTREACHED(); | 586 NOTREACHED(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 664 } |
| 658 default: | 665 default: |
| 659 NOTREACHED(); | 666 NOTREACHED(); |
| 660 return NULL; | 667 return NULL; |
| 661 } | 668 } |
| 662 } | 669 } |
| 663 | 670 |
| 664 #endif | 671 #endif |
| 665 | 672 |
| 666 } // namespace gfx | 673 } // namespace gfx |
| OLD | NEW |