Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/native_viewport/native_viewport.h" | |
| 6 | |
| 7 #import <AppKit/NSApplication.h> | |
| 8 #import <AppKit/NSView.h> | |
| 9 #import <AppKit/NSWindow.h> | |
| 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 { | |
| 18 namespace services { | |
| 19 | |
| 20 class NativeViewportMac : public NativeViewport { | |
| 21 public: | |
| 22 NativeViewportMac(NativeViewportDelegate* delegate) | |
| 23 : delegate_(delegate), | |
| 24 window_(nil), | |
| 25 rect_(10, 10, 500, 500) { | |
| 26 [NSApplication sharedApplication]; | |
| 27 | |
| 28 window_ = [[NSWindow alloc] | |
| 29 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) | |
| 30 styleMask:NSBorderlessWindowMask | |
|
Ben Goodger (Google)
2013/11/05 06:57:01
for developer convenience, we might like to make t
abarth-chromium
2013/11/05 07:03:25
Will do.
| |
| 31 backing:NSBackingStoreBuffered | |
| 32 defer:NO]; | |
| 33 [window_ orderFront:nil]; | |
| 34 | |
| 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 } | |
| 44 | |
| 45 virtual ~NativeViewportMac() { | |
| 46 [window_ orderOut:nil]; | |
| 47 [window_ close]; | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 // Overridden from NativeViewport: | |
| 52 virtual void Close() OVERRIDE { | |
| 53 // TODO(beng): perform this in response to XWindow destruction. | |
|
Ben Goodger (Google)
2013/11/05 06:57:01
in response to NSWindow destruction
abarth-chromium
2013/11/05 07:03:25
Yep.
| |
| 54 delegate_->OnDestroyed(); | |
| 55 } | |
| 56 | |
| 57 void OnGLContextLost() { | |
| 58 gl_context_.reset(); | |
| 59 delegate_->OnGLContextLost(); | |
| 60 } | |
| 61 | |
| 62 NativeViewportDelegate* delegate_; | |
| 63 NSWindow* window_; | |
| 64 gfx::Rect rect_; | |
| 65 scoped_ptr<gpu::GLInProcessContext> gl_context_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac); | |
| 68 }; | |
| 69 | |
| 70 // static | |
| 71 scoped_ptr<NativeViewport> NativeViewport::Create( | |
| 72 shell::Context* context, | |
| 73 NativeViewportDelegate* delegate) { | |
| 74 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass(); | |
| 75 } | |
| 76 | |
| 77 } // namespace services | |
| 78 } // namespace mojo | |
| OLD | NEW |