| 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" | |
| 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" | |
| 16 | |
| 17 namespace mojo { | 11 namespace mojo { |
| 18 namespace services { | 12 namespace services { |
| 19 | 13 |
| 20 class NativeViewportMac : public NativeViewport { | 14 class NativeViewportMac : public NativeViewport { |
| 21 public: | 15 public: |
| 22 NativeViewportMac(NativeViewportDelegate* delegate) | 16 NativeViewportMac(NativeViewportDelegate* delegate) |
| 23 : delegate_(delegate), | 17 : NativeViewport(delegate), |
| 24 window_(nil), | 18 window_(nil) { |
| 25 rect_(10, 10, 500, 500) { | 19 bounds_ = gfx::Rect(10, 10, 500, 500); |
| 20 |
| 26 [NSApplication sharedApplication]; | 21 [NSApplication sharedApplication]; |
| 27 | |
| 28 window_ = [[NSWindow alloc] | 22 window_ = [[NSWindow alloc] |
| 29 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) | 23 initWithContentRect:NSRectFromCGRect(bounds_.ToCGRect()) |
| 30 styleMask:NSTitledWindowMask | 24 styleMask:NSTitledWindowMask |
| 31 backing:NSBackingStoreBuffered | 25 backing:NSBackingStoreBuffered |
| 32 defer:NO]; | 26 defer:NO]; |
| 33 [window_ orderFront:nil]; | 27 [window_ orderFront:nil]; |
| 28 widget_ = [window_ contentView]; |
| 34 | 29 |
| 35 gpu::GLInProcessContextAttribs attribs; | 30 OnAcceleratedWidgetAvailable(); |
| 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 } | 31 } |
| 44 | 32 |
| 45 virtual ~NativeViewportMac() { | 33 virtual ~NativeViewportMac() { |
| 46 [window_ orderOut:nil]; | 34 [window_ orderOut:nil]; |
| 47 [window_ close]; | 35 [window_ close]; |
| 48 } | 36 } |
| 49 | 37 |
| 50 private: | 38 private: |
| 51 // Overridden from NativeViewport: | 39 // Overridden from NativeViewport: |
| 52 virtual void Close() OVERRIDE { | 40 virtual void Close() OVERRIDE { |
| 53 // TODO(beng): perform this in response to NSWindow destruction. | 41 // TODO(beng): perform this in response to NSWindow destruction. |
| 54 delegate_->OnDestroyed(); | 42 delegate_->OnDestroyed(); |
| 55 } | 43 } |
| 56 | 44 |
| 57 void OnGLContextLost() { | |
| 58 gl_context_.reset(); | |
| 59 delegate_->OnGLContextLost(); | |
| 60 } | |
| 61 | |
| 62 NativeViewportDelegate* delegate_; | |
| 63 NSWindow* window_; | 45 NSWindow* window_; |
| 64 gfx::Rect rect_; | |
| 65 scoped_ptr<gpu::GLInProcessContext> gl_context_; | |
| 66 | 46 |
| 67 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac); | 47 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac); |
| 68 }; | 48 }; |
| 69 | 49 |
| 70 // static | 50 // static |
| 71 scoped_ptr<NativeViewport> NativeViewport::Create( | 51 scoped_ptr<NativeViewport> NativeViewport::Create( |
| 72 shell::Context* context, | 52 shell::Context* context, |
| 73 NativeViewportDelegate* delegate) { | 53 NativeViewportDelegate* delegate) { |
| 74 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass(); | 54 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass(); |
| 75 } | 55 } |
| 76 | 56 |
| 77 } // namespace services | 57 } // namespace services |
| 78 } // namespace mojo | 58 } // namespace mojo |
| OLD | NEW |