| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.h" | 5 #include "ui/gl/gl_surface.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 } | 571 } |
| 572 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); | 572 GLSurfaceOzoneSurfaceless::SwapBuffersAsync(callback); |
| 573 current_surface_ ^= 1; | 573 current_surface_ ^= 1; |
| 574 BindFramebuffer(); | 574 BindFramebuffer(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { | 577 void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() { |
| 578 if (!context_) | 578 if (!context_) |
| 579 return; | 579 return; |
| 580 scoped_refptr<gfx::GLContext> previous_context = gfx::GLContext::GetCurrent(); | 580 scoped_refptr<gfx::GLContext> previous_context = gfx::GLContext::GetCurrent(); |
| 581 scoped_refptr<gfx::GLSurface> previous_surface = gfx::GLSurface::GetCurrent(); | 581 scoped_refptr<gfx::GLSurface> previous_surface; |
| 582 context_->MakeCurrent(this); | 582 |
| 583 bool was_current = previous_context && previous_context->IsCurrent(nullptr) && |
| 584 gfx::GLSurface::GetCurrent() == this; |
| 585 if (!was_current) { |
| 586 // Only take a reference to previous surface if it's not |this| |
| 587 // because otherwise we can take a self reference from our own dtor. |
| 588 previous_surface = gfx::GLSurface::GetCurrent(); |
| 589 context_->MakeCurrent(this); |
| 590 } |
| 583 | 591 |
| 584 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); | 592 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); |
| 585 if (fbo_) { | 593 if (fbo_) { |
| 586 glDeleteTextures(arraysize(textures_), textures_); | 594 glDeleteTextures(arraysize(textures_), textures_); |
| 587 for (auto& texture : textures_) | 595 for (auto& texture : textures_) |
| 588 texture = 0; | 596 texture = 0; |
| 589 glDeleteFramebuffersEXT(1, &fbo_); | 597 glDeleteFramebuffersEXT(1, &fbo_); |
| 590 fbo_ = 0; | 598 fbo_ = 0; |
| 591 } | 599 } |
| 592 for (auto image : images_) { | 600 for (auto image : images_) { |
| 593 if (image) | 601 if (image) |
| 594 image->Destroy(true); | 602 image->Destroy(true); |
| 595 } | 603 } |
| 596 | 604 |
| 597 if (previous_context.get()) { | 605 if (!was_current) { |
| 598 previous_context->MakeCurrent(previous_surface.get()); | 606 previous_context->MakeCurrent(previous_surface.get()); |
| 599 } else { | 607 } else { |
| 600 context_->ReleaseCurrent(this); | 608 context_->ReleaseCurrent(this); |
| 601 } | 609 } |
| 602 } | 610 } |
| 603 | 611 |
| 604 bool GLSurfaceOzoneSurfacelessSurfaceImpl::IsSurfaceless() const { | 612 bool GLSurfaceOzoneSurfacelessSurfaceImpl::IsSurfaceless() const { |
| 605 return false; | 613 return false; |
| 606 } | 614 } |
| 607 | 615 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 780 } |
| 773 } | 781 } |
| 774 | 782 |
| 775 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 783 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
| 776 return ui::OzonePlatform::GetInstance() | 784 return ui::OzonePlatform::GetInstance() |
| 777 ->GetSurfaceFactoryOzone() | 785 ->GetSurfaceFactoryOzone() |
| 778 ->GetNativeDisplay(); | 786 ->GetNativeDisplay(); |
| 779 } | 787 } |
| 780 | 788 |
| 781 } // namespace gfx | 789 } // namespace gfx |
| OLD | NEW |