| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport.h" | 5 #include "mojo/services/native_viewport/native_viewport.h" |
| 6 | 6 |
| 7 #import <AppKit/NSApplication.h> | 7 #import <AppKit/NSApplication.h> |
| 8 #import <AppKit/NSView.h> | 8 #import <AppKit/NSView.h> |
| 9 #import <AppKit/NSWindow.h> | 9 #import <AppKit/NSWindow.h> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/mac/scoped_nsobject.h" | |
| 13 #include "gpu/command_buffer/client/gl_in_process_context.h" | |
| 14 #include "gpu/command_buffer/client/gles2_implementation.h" | |
| 15 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 16 | 13 |
| 17 namespace mojo { | 14 namespace mojo { |
| 18 namespace services { | 15 namespace services { |
| 19 | 16 |
| 20 class NativeViewportMac : public NativeViewport { | 17 class NativeViewportMac : public NativeViewport { |
| 21 public: | 18 public: |
| 22 NativeViewportMac(NativeViewportDelegate* delegate) | 19 NativeViewportMac(NativeViewportDelegate* delegate) |
| 23 : delegate_(delegate), | 20 : delegate_(delegate), |
| 24 window_(nil), | 21 window_(nil), |
| 25 rect_(10, 10, 500, 500) { | 22 rect_(10, 10, 500, 500) { |
| 26 [NSApplication sharedApplication]; | 23 [NSApplication sharedApplication]; |
| 27 | 24 |
| 28 window_ = [[NSWindow alloc] | 25 window_ = [[NSWindow alloc] |
| 29 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) | 26 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) |
| 30 styleMask:NSTitledWindowMask | 27 styleMask:NSTitledWindowMask |
| 31 backing:NSBackingStoreBuffered | 28 backing:NSBackingStoreBuffered |
| 32 defer:NO]; | 29 defer:NO]; |
| 33 [window_ orderFront:nil]; | 30 [window_ orderFront:nil]; |
| 34 | 31 delegate_->OnAcceleratedWidgetAvailable([window_ contentView]); |
| 35 gpu::GLInProcessContextAttribs attribs; | |
| 36 gl_context_.reset(gpu::GLInProcessContext::CreateContext( | |
| 37 false, [window_ contentView], rect_.size(), false, | |
| 38 attribs, gfx::PreferDiscreteGpu)); | |
| 39 gl_context_->SetContextLostCallback(base::Bind( | |
| 40 &NativeViewportMac::OnGLContextLost, base::Unretained(this))); | |
| 41 | |
| 42 delegate_->OnGLContextAvailable(gl_context_->GetImplementation()); | |
| 43 } | 32 } |
| 44 | 33 |
| 45 virtual ~NativeViewportMac() { | 34 virtual ~NativeViewportMac() { |
| 46 [window_ orderOut:nil]; | 35 [window_ orderOut:nil]; |
| 47 [window_ close]; | 36 [window_ close]; |
| 48 } | 37 } |
| 49 | 38 |
| 50 private: | 39 private: |
| 51 // Overridden from NativeViewport: | 40 // Overridden from NativeViewport: |
| 41 virtual gfx::Size GetSize() OVERRIDE { |
| 42 return rect_.size(); |
| 43 } |
| 44 |
| 52 virtual void Close() OVERRIDE { | 45 virtual void Close() OVERRIDE { |
| 53 // TODO(beng): perform this in response to NSWindow destruction. | 46 // TODO(beng): perform this in response to NSWindow destruction. |
| 54 delegate_->OnDestroyed(); | 47 delegate_->OnDestroyed(); |
| 55 } | 48 } |
| 56 | 49 |
| 57 void OnGLContextLost() { | |
| 58 gl_context_.reset(); | |
| 59 delegate_->OnGLContextLost(); | |
| 60 } | |
| 61 | |
| 62 NativeViewportDelegate* delegate_; | 50 NativeViewportDelegate* delegate_; |
| 63 NSWindow* window_; | 51 NSWindow* window_; |
| 64 gfx::Rect rect_; | 52 gfx::Rect rect_; |
| 65 scoped_ptr<gpu::GLInProcessContext> gl_context_; | |
| 66 | 53 |
| 67 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac); | 54 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac); |
| 68 }; | 55 }; |
| 69 | 56 |
| 70 // static | 57 // static |
| 71 scoped_ptr<NativeViewport> NativeViewport::Create( | 58 scoped_ptr<NativeViewport> NativeViewport::Create( |
| 72 shell::Context* context, | 59 shell::Context* context, |
| 73 NativeViewportDelegate* delegate) { | 60 NativeViewportDelegate* delegate) { |
| 74 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass(); | 61 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass(); |
| 75 } | 62 } |
| 76 | 63 |
| 77 } // namespace services | 64 } // namespace services |
| 78 } // namespace mojo | 65 } // namespace mojo |
| OLD | NEW |