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