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_controller.h" | 5 #include "mojo/services/native_viewport/native_viewport_controller.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
9 #include "gpu/command_buffer/client/gles2_interface.h" | 10 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "mojo/services/native_viewport/native_viewport.h" | 12 #include "mojo/services/native_viewport/native_viewport.h" |
11 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
12 | 14 |
13 namespace mojo { | 15 namespace mojo { |
14 namespace services { | 16 namespace services { |
15 | 17 |
16 NativeViewportController::NativeViewportController( | 18 NativeViewportController::NativeViewportController( |
17 shell::Context* context, Handle pipe) | 19 shell::Context* context, Handle pipe) |
18 : pipe_(pipe) { | 20 : pipe_(pipe) { |
19 native_viewport_ = NativeViewport::Create(context, this); | 21 native_viewport_ = NativeViewport::Create(context, this); |
20 } | 22 } |
21 NativeViewportController::~NativeViewportController() { | 23 NativeViewportController::~NativeViewportController() { |
22 } | 24 } |
23 | 25 |
24 void NativeViewportController::Close() { | 26 void NativeViewportController::Close() { |
25 DCHECK(native_viewport_); | 27 DCHECK(native_viewport_); |
26 native_viewport_->Close(); | 28 native_viewport_->Close(); |
27 } | 29 } |
28 | 30 |
29 bool NativeViewportController::OnEvent(ui::Event* event) { | 31 bool NativeViewportController::OnEvent(ui::Event* event) { |
30 ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event); | 32 ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event); |
31 SendString(base::StringPrintf("Event @ %d,%d", | 33 SendString(base::StringPrintf("Event @ %d,%d", |
32 located->location().x(), | 34 located->location().x(), |
33 located->location().y())); | 35 located->location().y())); |
34 return false; | 36 return false; |
35 } | 37 } |
36 | 38 |
37 void NativeViewportController::OnGLContextAvailable( | 39 void NativeViewportController::OnAcceleratedWidgetAvailable( |
38 gpu::gles2::GLES2Interface* gl) { | 40 gfx::AcceleratedWidget widget) { |
| 41 gfx::Size size = native_viewport_->GetSize(); |
| 42 gpu::GLInProcessContextAttribs attribs; |
| 43 gl_context_.reset(gpu::GLInProcessContext::CreateContext( |
| 44 false, widget, size, false, attribs, gfx::PreferDiscreteGpu)); |
| 45 gl_context_->SetContextLostCallback(base::Bind( |
| 46 &NativeViewportController::OnGLContextLost, base::Unretained(this))); |
| 47 |
39 // TODO(abarth): Instead of drawing green, we want to send the context over | 48 // TODO(abarth): Instead of drawing green, we want to send the context over |
40 // pipe_ somehow. | 49 // pipe_ somehow. |
| 50 gpu::gles2::GLES2Interface* gl = gl_context_->GetImplementation(); |
41 gl->ClearColor(0, 1, 0, 0); | 51 gl->ClearColor(0, 1, 0, 0); |
42 gl->Clear(GL_COLOR_BUFFER_BIT); | 52 gl->Clear(GL_COLOR_BUFFER_BIT); |
43 gl->SwapBuffers(); | 53 gl->SwapBuffers(); |
44 } | 54 } |
45 | 55 |
46 void NativeViewportController::OnGLContextLost() { | 56 void NativeViewportController::OnGLContextLost() { |
47 SendString("GL context lost"); | 57 SendString("GL context lost"); |
48 } | 58 } |
49 | 59 |
50 void NativeViewportController::OnResized(const gfx::Size& size) { | 60 void NativeViewportController::OnResized(const gfx::Size& size) { |
51 SendString(base::StringPrintf("Sized to: %d x %d", | 61 SendString(base::StringPrintf("Sized to: %d x %d", |
52 size.width(), | 62 size.width(), |
53 size.height())); | 63 size.height())); |
54 } | 64 } |
55 | 65 |
56 void NativeViewportController::OnDestroyed() { | 66 void NativeViewportController::OnDestroyed() { |
57 base::MessageLoop::current()->Quit(); | 67 base::MessageLoop::current()->Quit(); |
58 } | 68 } |
59 | 69 |
60 void NativeViewportController::SendString(const std::string& string) { | 70 void NativeViewportController::SendString(const std::string& string) { |
61 WriteMessage(pipe_, string.c_str(), string.size()+1, NULL, 0, | 71 WriteMessage(pipe_, string.c_str(), string.size()+1, NULL, 0, |
62 MOJO_WRITE_MESSAGE_FLAG_NONE); | 72 MOJO_WRITE_MESSAGE_FLAG_NONE); |
63 } | 73 } |
64 | 74 |
65 } // namespace services | 75 } // namespace services |
66 } // namespace mojo | 76 } // namespace mojo |
OLD | NEW |