Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: ui/gfx/gl/gl_context_nsview.mm

Issue 8486020: compositor_unittests target is unimplmented on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address piman's comments (#6) Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/gl/gl_context_nsview.mm
diff --git a/ui/gfx/gl/gl_context_nsview.mm b/ui/gfx/gl/gl_context_nsview.mm
new file mode 100644
index 0000000000000000000000000000000000000000..918e07cb1ac36558027a2292c1bb62910306e666
--- /dev/null
+++ b/ui/gfx/gl/gl_context_nsview.mm
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/gl/gl_context_nsview.h"
+
+#include <vector>
+
+#import <AppKit/NSOpenGL.h>
+
+#include "base/logging.h"
+
+namespace gfx {
+
+GLContextNSView::GLContextNSView(GLShareGroup* group)
+ : GLContext(group) {
+}
+
+GLContextNSView::~GLContextNSView() {
+}
+
+bool GLContextNSView::Initialize(GLSurface* surface,
+ GpuPreference gpu_preference) {
+ DCHECK(!context_) << "NSGLContext was previously initialized.";
+ gpu_preference_ = gpu_preference;
+
+ std::vector<NSOpenGLPixelFormatAttribute> attributes;
+ attributes.push_back(NSOpenGLPFAAccelerated);
+ attributes.push_back(NSOpenGLPFADoubleBuffer);
+ attributes.push_back(0);
+
+ scoped_nsobject<NSOpenGLPixelFormat> pixel_format;
+ pixel_format.reset([[NSOpenGLPixelFormat alloc]
+ initWithAttributes:&attributes.front()]);
+ if (!pixel_format) {
+ LOG(ERROR) << "NSOpenGLPixelFormat initWithAttributes failed.";
+ return false;
+ }
+
+ context_.reset([[NSOpenGLContext alloc] initWithFormat:pixel_format
+ shareContext:nil]);
+ if (!context_) {
+ LOG(ERROR) << "NSOpenGLContext initWithFormat failed";
+ return false;
+ }
+
+ return true;
+}
+
+void GLContextNSView::Destroy() {
+ context_.reset(nil);
+}
+
+bool GLContextNSView::MakeCurrent(GLSurface* surface) {
+ [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'
+ return true;
+}
+
+void GLContextNSView::ReleaseCurrent(GLSurface* surface) {
+ [NSOpenGLContext clearCurrentContext];
+}
+
+bool GLContextNSView::IsCurrent(GLSurface* surface) {
+ return context_ == [NSOpenGLContext currentContext];
+}
+
+void* GLContextNSView::GetHandle() {
+ return context_;
+}
+
+void GLContextNSView::SetSwapInterval(int interval) {
+ DCHECK(interval == 0 || interval == 1);
+ GLint swap = interval;
+ [context_ setValues:&swap forParameter:NSOpenGLCPSwapInterval];
+}
+
+} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698