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.
5 #include "mojo/services/native_viewport/native_viewport_controller.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h"
9 #include "gpu/command_buffer/client/gles2_interface.h"
10 #include "mojo/services/native_viewport/native_viewport.h"
11 #include "ui/events/event.h"
16 NativeViewportController::NativeViewportController(
17 shell::Context* context, Handle pipe)
19 native_viewport_ = NativeViewport::Create(context, this);
21 NativeViewportController::~NativeViewportController() {
24 void NativeViewportController::Close() {
25 DCHECK(native_viewport_);
26 native_viewport_->Close();
29 bool NativeViewportController::OnEvent(ui::Event* event) {
30 ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event);
31 SendString(base::StringPrintf("Event @ %d,%d",
32 located->location().x(),
33 located->location().y()));
37 void NativeViewportController::OnGLContextAvailable(
38 gpu::gles2::GLES2Interface* gl) {
39 // TODO(abarth): Instead of drawing green, we want to send the context over
41 gl->ClearColor(0, 1, 0, 0);
42 gl->Clear(GL_COLOR_BUFFER_BIT);
46 void NativeViewportController::OnGLContextLost() {
47 SendString("GL context lost");
50 void NativeViewportController::OnResized(const gfx::Size& size) {
51 SendString(base::StringPrintf("Sized to: %d x %d",
56 void NativeViewportController::OnDestroyed() {
57 base::MessageLoop::current()->Quit();
60 void NativeViewportController::SendString(const std::string& string) {
61 WriteMessage(pipe_, string.c_str(), string.size()+1, NULL, 0,
62 MOJO_WRITE_MESSAGE_FLAG_NONE);
65 } // namespace services