Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/gfx/gl/gl_context_nsview.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #import <AppKit/NSOpenGL.h> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 | |
| 13 namespace gfx { | |
| 14 | |
| 15 GLContextNSView::GLContextNSView(GLShareGroup* group) | |
| 16 : GLContext(group) { | |
| 17 } | |
| 18 | |
| 19 GLContextNSView::~GLContextNSView() { | |
| 20 } | |
| 21 | |
| 22 bool GLContextNSView::Initialize(GLSurface* surface, | |
| 23 GpuPreference gpu_preference) { | |
| 24 DCHECK(!context_) << "NSGLContext was previously initialized."; | |
| 25 gpu_preference_ = gpu_preference; | |
| 26 | |
| 27 std::vector<NSOpenGLPixelFormatAttribute> attributes; | |
| 28 attributes.push_back(NSOpenGLPFAAccelerated); | |
| 29 attributes.push_back(NSOpenGLPFADoubleBuffer); | |
| 30 attributes.push_back(0); | |
| 31 | |
| 32 scoped_nsobject<NSOpenGLPixelFormat> pixel_format; | |
| 33 pixel_format.reset([[NSOpenGLPixelFormat alloc] | |
| 34 initWithAttributes:&attributes.front()]); | |
| 35 if (!pixel_format) { | |
| 36 LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed."; | |
| 37 return false; | |
| 38 } | |
| 39 | |
| 40 context_.reset([[NSOpenGLContext alloc] initWithFormat:pixel_format | |
| 41 shareContext:nil]); | |
| 42 if (!context_) { | |
| 43 LOG(ERROR) << "NSOpenGLContext initWithFormat failed"; | |
| 44 return false; | |
| 45 } | |
| 46 | |
| 47 return true; | |
| 48 } | |
| 49 | |
| 50 void GLContextNSView::Destroy() { | |
| 51 context_.reset(nil); | |
| 52 } | |
| 53 | |
| 54 bool GLContextNSView::MakeCurrent(GLSurface* surface) { | |
| 55 [context_ makeCurrentContext]; | |
|
Ken Russell (switch to Gerrit)
2011/11/17 00:14:40
Where do you set the context's view to that in the
dhollowa
2011/11/17 01:41:51
test_compositor_host_mac.mm:41 in the host window'
| |
| 56 return true; | |
| 57 } | |
| 58 | |
| 59 void GLContextNSView::ReleaseCurrent(GLSurface* surface) { | |
| 60 [NSOpenGLContext clearCurrentContext]; | |
| 61 } | |
| 62 | |
| 63 bool GLContextNSView::IsCurrent(GLSurface* surface) { | |
| 64 return context_ == [NSOpenGLContext currentContext]; | |
| 65 } | |
| 66 | |
| 67 void* GLContextNSView::GetHandle() { | |
| 68 return context_; | |
| 69 } | |
| 70 | |
| 71 void GLContextNSView::SetSwapInterval(int interval) { | |
| 72 DCHECK(interval == 0 || interval == 1); | |
| 73 GLint swap = interval; | |
| 74 [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval]; | |
| 75 } | |
| 76 | |
| 77 } // namespace gfx | |
| OLD | NEW |