OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/gl/gl_context_nsview.h" | 5 #include "ui/gfx/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 28 matching lines...) Expand all Loading... |
39 return false; | 39 return false; |
40 } | 40 } |
41 | 41 |
42 context_.reset([[NSOpenGLContext alloc] initWithFormat:pixel_format | 42 context_.reset([[NSOpenGLContext alloc] initWithFormat:pixel_format |
43 shareContext:nil]); | 43 shareContext:nil]); |
44 if (!context_) { | 44 if (!context_) { |
45 LOG(ERROR) << "NSOpenGLContext initWithFormat failed"; | 45 LOG(ERROR) << "NSOpenGLContext initWithFormat failed"; |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 // Allow the surface to call back when in need of |FlushBuffer|. | |
50 static_cast<GLSurfaceNSView*>(surface)->SetGLContext(this); | |
51 | |
52 return true; | 49 return true; |
53 } | 50 } |
54 | 51 |
55 void GLContextNSView::Destroy() { | 52 void GLContextNSView::Destroy() { |
56 context_.reset(nil); | 53 context_.reset(nil); |
57 } | 54 } |
58 | 55 |
59 bool GLContextNSView::MakeCurrent(GLSurface* surface) { | 56 bool GLContextNSView::MakeCurrent(GLSurface* surface) { |
60 PluginWindowHandle view = | 57 PluginWindowHandle view = |
61 static_cast<PluginWindowHandle>(surface->GetHandle()); | 58 static_cast<PluginWindowHandle>(surface->GetHandle()); |
62 // Only set the context's view if the view is parented. | 59 // Only set the context's view if the view is parented. |
63 // I.e. it is a valid drawable. | 60 // I.e. it is a valid drawable. |
64 if ([view window]) | 61 if ([view window]) |
65 [context_ setView:view]; | 62 [context_ setView:view]; |
66 [context_ makeCurrentContext]; | 63 [context_ makeCurrentContext]; |
| 64 |
| 65 if (!surface->OnMakeCurrent(this)) { |
| 66 LOG(ERROR) << "Unable to make gl context current."; |
| 67 return false; |
| 68 } |
| 69 |
67 return true; | 70 return true; |
68 } | 71 } |
69 | 72 |
70 void GLContextNSView::ReleaseCurrent(GLSurface* surface) { | 73 void GLContextNSView::ReleaseCurrent(GLSurface* surface) { |
71 [NSOpenGLContext clearCurrentContext]; | 74 [NSOpenGLContext clearCurrentContext]; |
72 } | 75 } |
73 | 76 |
74 bool GLContextNSView::IsCurrent(GLSurface* surface) { | 77 bool GLContextNSView::IsCurrent(GLSurface* surface) { |
75 return context_ == [NSOpenGLContext currentContext]; | 78 return context_ == [NSOpenGLContext currentContext]; |
76 } | 79 } |
77 | 80 |
78 void* GLContextNSView::GetHandle() { | 81 void* GLContextNSView::GetHandle() { |
79 return context_; | 82 return context_; |
80 } | 83 } |
81 | 84 |
82 void GLContextNSView::SetSwapInterval(int interval) { | 85 void GLContextNSView::SetSwapInterval(int interval) { |
83 DCHECK(interval == 0 || interval == 1); | 86 DCHECK(interval == 0 || interval == 1); |
84 GLint swap = interval; | 87 GLint swap = interval; |
85 [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval]; | 88 [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval]; |
86 } | 89 } |
87 | 90 |
88 void GLContextNSView::FlushBuffer() { | 91 void GLContextNSView::FlushBuffer() { |
89 [context_ flushBuffer]; | 92 [context_ flushBuffer]; |
90 } | 93 } |
91 | 94 |
92 } // namespace gfx | 95 } // namespace gfx |
OLD | NEW |