| 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_context_nsview.h" | 5 #include "ui/gl/gl_context_nsview.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #import <AppKit/NSOpenGL.h> | 9 #import <AppKit/NSOpenGL.h> |
| 10 #import <AppKit/NSView.h> | 10 #import <AppKit/NSView.h> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 return true; | 50 return true; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void GLContextNSView::Destroy() { | 53 void GLContextNSView::Destroy() { |
| 54 context_.reset(nil); | 54 context_.reset(nil); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool GLContextNSView::MakeCurrent(GLSurface* surface) { | 57 bool GLContextNSView::MakeCurrent(GLSurface* surface) { |
| 58 ScopedReleaseCurrent release_current; |
| 58 TRACE_EVENT0("gpu", "GLContextNSView::MakeCurrent"); | 59 TRACE_EVENT0("gpu", "GLContextNSView::MakeCurrent"); |
| 59 AcceleratedWidget view = | 60 AcceleratedWidget view = |
| 60 static_cast<AcceleratedWidget>(surface->GetHandle()); | 61 static_cast<AcceleratedWidget>(surface->GetHandle()); |
| 61 // Only set the context's view if the view is parented. | 62 // Only set the context's view if the view is parented. |
| 62 // I.e. it is a valid drawable. | 63 // I.e. it is a valid drawable. |
| 63 if ([view window]) | 64 if ([view window]) |
| 64 [context_ setView:view]; | 65 [context_ setView:view]; |
| 65 [context_ makeCurrentContext]; | 66 [context_ makeCurrentContext]; |
| 66 | 67 |
| 67 SetRealGLApi(); | 68 SetRealGLApi(); |
| 68 SetCurrent(surface); | 69 SetCurrent(surface); |
| 69 if (!InitializeDynamicBindings()) { | 70 if (!InitializeDynamicBindings()) { |
| 70 ReleaseCurrent(surface); | |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 | 73 |
| 74 if (!surface->OnMakeCurrent(this)) { | 74 if (!surface->OnMakeCurrent(this)) { |
| 75 LOG(ERROR) << "Unable to make gl context current."; | 75 LOG(ERROR) << "Unable to make gl context current."; |
| 76 return false; | 76 return false; |
| 77 } | 77 } |
| 78 | 78 |
| 79 release_current.Cancel(); |
| 79 return true; | 80 return true; |
| 80 } | 81 } |
| 81 | 82 |
| 82 void GLContextNSView::ReleaseCurrent(GLSurface* surface) { | 83 void GLContextNSView::ReleaseCurrent(GLSurface* surface) { |
| 83 [NSOpenGLContext clearCurrentContext]; | 84 [NSOpenGLContext clearCurrentContext]; |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool GLContextNSView::IsCurrent(GLSurface* surface) { | 87 bool GLContextNSView::IsCurrent(GLSurface* surface) { |
| 87 return context_ == [NSOpenGLContext currentContext]; | 88 return context_ == [NSOpenGLContext currentContext]; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void* GLContextNSView::GetHandle() { | 91 void* GLContextNSView::GetHandle() { |
| 91 return context_; | 92 return context_; |
| 92 } | 93 } |
| 93 | 94 |
| 94 void GLContextNSView::SetSwapInterval(int interval) { | 95 void GLContextNSView::SetSwapInterval(int interval) { |
| 95 DCHECK(interval == 0 || interval == 1); | 96 DCHECK(interval == 0 || interval == 1); |
| 96 GLint swap = interval; | 97 GLint swap = interval; |
| 97 [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval]; | 98 [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval]; |
| 98 } | 99 } |
| 99 | 100 |
| 100 void GLContextNSView::FlushBuffer() { | 101 void GLContextNSView::FlushBuffer() { |
| 101 [context_ flushBuffer]; | 102 [context_ flushBuffer]; |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace gfx | 105 } // namespace gfx |
| OLD | NEW |