Commit 988e5eb0 authored by abarth@chromium.org's avatar abarth@chromium.org

Add a basic NativeViewportMac for Mojo

This CL adds a basic implementation of NativeViewport for Mac OS X. It puts a
window on screen and initializes GL for that window using an in-process
command buffer.

R=ben@chromium.org, ccameron@chromium.org, kbr@chromium.org

Review URL: https://codereview.chromium.org/56833002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233227 0039d316-1c4b-4281-b951-d872f2087c98
parent 80a558e8
...@@ -291,6 +291,7 @@ ...@@ -291,6 +291,7 @@
'../gpu/gpu.gyp:gles2_implementation', '../gpu/gpu.gyp:gles2_implementation',
'../ui/events/events.gyp:events', '../ui/events/events.gyp:events',
'../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx',
'../ui/gl/gl.gyp:gl',
], ],
'sources': [ 'sources': [
'services/native_viewport/android/mojo_viewport.cc', 'services/native_viewport/android/mojo_viewport.cc',
...@@ -299,12 +300,13 @@ ...@@ -299,12 +300,13 @@
'services/native_viewport/native_viewport_android.cc', 'services/native_viewport/native_viewport_android.cc',
'services/native_viewport/native_viewport_controller.cc', 'services/native_viewport/native_viewport_controller.cc',
'services/native_viewport/native_viewport_controller.h', 'services/native_viewport/native_viewport_controller.h',
'services/native_viewport/native_viewport_mac.mm',
'services/native_viewport/native_viewport_stub.cc', 'services/native_viewport/native_viewport_stub.cc',
'services/native_viewport/native_viewport_win.cc', 'services/native_viewport/native_viewport_win.cc',
'services/native_viewport/native_viewport_x11.cc', 'services/native_viewport/native_viewport_x11.cc',
], ],
'conditions': [ 'conditions': [
['OS=="win" or OS=="android" or OS=="linux"', { ['OS=="win" or OS=="android" or OS=="linux" or OS=="mac"', {
'sources!': [ 'sources!': [
'services/native_viewport/native_viewport_stub.cc', 'services/native_viewport/native_viewport_stub.cc',
], ],
......
// Copyright 2013 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 "mojo/services/native_viewport/native_viewport.h"
#import <AppKit/NSApplication.h>
#import <AppKit/NSView.h>
#import <AppKit/NSWindow.h>
#include "base/bind.h"
#include "base/mac/scoped_nsobject.h"
#include "gpu/command_buffer/client/gl_in_process_context.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "ui/gfx/rect.h"
namespace mojo {
namespace services {
class NativeViewportMac : public NativeViewport {
public:
NativeViewportMac(NativeViewportDelegate* delegate)
: delegate_(delegate),
window_(nil),
rect_(10, 10, 500, 500) {
[NSApplication sharedApplication];
window_ = [[NSWindow alloc]
initWithContentRect:NSRectFromCGRect(rect_.ToCGRect())
styleMask:NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window_ orderFront:nil];
gpu::GLInProcessContextAttribs attribs;
gl_context_.reset(gpu::GLInProcessContext::CreateContext(
false, [window_ contentView], rect_.size(), false,
attribs, gfx::PreferDiscreteGpu));
gl_context_->SetContextLostCallback(base::Bind(
&NativeViewportMac::OnGLContextLost, base::Unretained(this)));
delegate_->OnGLContextAvailable(gl_context_->GetImplementation());
}
virtual ~NativeViewportMac() {
[window_ orderOut:nil];
[window_ close];
}
private:
// Overridden from NativeViewport:
virtual void Close() OVERRIDE {
// TODO(beng): perform this in response to NSWindow destruction.
delegate_->OnDestroyed();
}
void OnGLContextLost() {
gl_context_.reset();
delegate_->OnGLContextLost();
}
NativeViewportDelegate* delegate_;
NSWindow* window_;
gfx::Rect rect_;
scoped_ptr<gpu::GLInProcessContext> gl_context_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportMac);
};
// static
scoped_ptr<NativeViewport> NativeViewport::Create(
shell::Context* context,
NativeViewportDelegate* delegate) {
return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass();
}
} // namespace services
} // namespace mojo
...@@ -256,6 +256,10 @@ ...@@ -256,6 +256,10 @@
'gl_context_cgl.h', 'gl_context_cgl.h',
'gl_surface_cgl.cc', 'gl_surface_cgl.cc',
'gl_surface_cgl.h', 'gl_surface_cgl.h',
'gl_context_nsview.mm',
'gl_context_nsview.h',
'gl_surface_nsview.mm',
'gl_surface_nsview.h',
], ],
'link_settings': { 'link_settings': {
'libraries': [ 'libraries': [
...@@ -263,14 +267,6 @@ ...@@ -263,14 +267,6 @@
], ],
}, },
}], }],
['OS=="mac" and use_aura == 1', {
'sources': [
'gl_context_nsview.mm',
'gl_context_nsview.h',
'gl_surface_nsview.mm',
'gl_surface_nsview.h',
],
}],
['OS=="android"', { ['OS=="android"', {
'dependencies': [ 'dependencies': [
'gl_jni_headers', 'gl_jni_headers',
......
...@@ -8,16 +8,13 @@ ...@@ -8,16 +8,13 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "third_party/mesa/src/include/GL/osmesa.h" #include "third_party/mesa/src/include/GL/osmesa.h"
#include "ui/gl/gl_context_cgl.h" #include "ui/gl/gl_context_cgl.h"
#include "ui/gl/gl_context_nsview.h"
#include "ui/gl/gl_context_osmesa.h" #include "ui/gl/gl_context_osmesa.h"
#include "ui/gl/gl_context_stub.h" #include "ui/gl/gl_context_stub.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#if defined(USE_AURA)
#include "ui/gl/gl_context_nsview.h"
#endif
namespace gfx { namespace gfx {
class GLShareGroup; class GLShareGroup;
...@@ -31,14 +28,10 @@ scoped_refptr<GLContext> GLContext::CreateGLContext( ...@@ -31,14 +28,10 @@ scoped_refptr<GLContext> GLContext::CreateGLContext(
case kGLImplementationDesktopGL: case kGLImplementationDesktopGL:
case kGLImplementationAppleGL: { case kGLImplementationAppleGL: {
scoped_refptr<GLContext> context; scoped_refptr<GLContext> context;
#if defined(USE_AURA)
if (compatible_surface->IsOffscreen()) if (compatible_surface->IsOffscreen())
context = new GLContextCGL(share_group); context = new GLContextCGL(share_group);
else else
context = new GLContextNSView(share_group); context = new GLContextNSView(share_group);
#else
context = new GLContextCGL(share_group);
#endif // USE_AURA
if (!context->Initialize(compatible_surface, gpu_preference)) if (!context->Initialize(compatible_surface, gpu_preference))
return NULL; return NULL;
......
...@@ -20,7 +20,6 @@ class GLSurface; ...@@ -20,7 +20,6 @@ class GLSurface;
class GLContextNSView : public GLContextReal { class GLContextNSView : public GLContextReal {
public: public:
explicit GLContextNSView(GLShareGroup* group); explicit GLContextNSView(GLShareGroup* group);
virtual ~GLContextNSView();
// GLContext: // GLContext:
virtual bool Initialize(GLSurface* surface, virtual bool Initialize(GLSurface* surface,
...@@ -36,6 +35,8 @@ class GLContextNSView : public GLContextReal { ...@@ -36,6 +35,8 @@ class GLContextNSView : public GLContextReal {
void FlushBuffer(); void FlushBuffer();
private: private:
virtual ~GLContextNSView();
base::scoped_nsobject<NSOpenGLContext> context_; base::scoped_nsobject<NSOpenGLContext> context_;
GpuPreference gpu_preference_; GpuPreference gpu_preference_;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace gfx { namespace gfx {
GLContextNSView::GLContextNSView(GLShareGroup* group) GLContextNSView::GLContextNSView(GLShareGroup* group)
: GLContext(group) { : GLContextReal(group) {
} }
GLContextNSView::~GLContextNSView() { GLContextNSView::~GLContextNSView() {
...@@ -64,6 +64,7 @@ bool GLContextNSView::MakeCurrent(GLSurface* surface) { ...@@ -64,6 +64,7 @@ bool GLContextNSView::MakeCurrent(GLSurface* surface) {
[context_ setView:view]; [context_ setView:view];
[context_ makeCurrentContext]; [context_ makeCurrentContext];
SetRealGLApi();
SetCurrent(surface); SetCurrent(surface);
if (!surface->OnMakeCurrent(this)) { if (!surface->OnMakeCurrent(this)) {
......
...@@ -13,10 +13,7 @@ ...@@ -13,10 +13,7 @@
#include "ui/gl/gl_surface_cgl.h" #include "ui/gl/gl_surface_cgl.h"
#include "ui/gl/gl_surface_osmesa.h" #include "ui/gl/gl_surface_osmesa.h"
#include "ui/gl/gl_surface_stub.h" #include "ui/gl/gl_surface_stub.h"
#if defined(USE_AURA)
#include "ui/gl/gl_surface_nsview.h" #include "ui/gl/gl_surface_nsview.h"
#endif
namespace gfx { namespace gfx {
...@@ -38,7 +35,6 @@ bool GLSurface::InitializeOneOffInternal() { ...@@ -38,7 +35,6 @@ bool GLSurface::InitializeOneOffInternal() {
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window) { gfx::AcceleratedWidget window) {
TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
#if defined(USE_AURA)
switch (GetGLImplementation()) { switch (GetGLImplementation()) {
case kGLImplementationDesktopGL: case kGLImplementationDesktopGL:
case kGLImplementationAppleGL: { case kGLImplementationAppleGL: {
...@@ -54,9 +50,6 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( ...@@ -54,9 +50,6 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
NOTREACHED(); NOTREACHED();
return NULL; return NULL;
} }
#else
return CreateOffscreenGLSurface(gfx::Size(1, 1));
#endif
} }
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface(
......
...@@ -16,10 +16,9 @@ class GLContextNSView; ...@@ -16,10 +16,9 @@ class GLContextNSView;
// GLSurfaceNSView provides an implementation of the the GLSurface interface // GLSurfaceNSView provides an implementation of the the GLSurface interface
// that is backed by an NSView. This interface pairs with the GLContextNSView // that is backed by an NSView. This interface pairs with the GLContextNSView
// class, and the NSView is expected to use this context for drawing. // class, and the NSView is expected to use this context for drawing.
class GLSurfaceNSView : public GLSurface { class GL_EXPORT GLSurfaceNSView : public GLSurface {
public: public:
explicit GLSurfaceNSView(AcceleratedWidget view); explicit GLSurfaceNSView(AcceleratedWidget view);
virtual ~GLSurfaceNSView();
// GLSurface: // GLSurface:
virtual void Destroy() OVERRIDE; virtual void Destroy() OVERRIDE;
...@@ -32,6 +31,8 @@ class GLSurfaceNSView : public GLSurface { ...@@ -32,6 +31,8 @@ class GLSurfaceNSView : public GLSurface {
virtual bool OnMakeCurrent(GLContext* context) OVERRIDE; virtual bool OnMakeCurrent(GLContext* context) OVERRIDE;
private: private:
virtual ~GLSurfaceNSView();
// Weak. An |NSView*|. // Weak. An |NSView*|.
AcceleratedWidget view_; AcceleratedWidget view_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment