summaryrefslogtreecommitdiffstats
path: root/mojo/examples/sample_app/native_viewport_client_impl.cc
blob: 17991dad8f10765cf958627fe6e5ff3c41dbcc0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/examples/sample_app/native_viewport_client_impl.h"

#include <stdio.h>

#include "base/logging.h"
#include "base/message_loop/message_loop.h"

namespace mojo {
namespace examples {

NativeViewportClientImpl::NativeViewportClientImpl(ScopedMessagePipeHandle pipe)
    : service_(pipe.Pass()) {
  service_.SetPeer(this);
}

NativeViewportClientImpl::~NativeViewportClientImpl() {
  service_->Close();
}

void NativeViewportClientImpl::Open() {
  service_->Open();

  ScopedMessagePipeHandle gles2;
  ScopedMessagePipeHandle gles2_client;
  CreateMessagePipe(&gles2, &gles2_client);

  gles2_client_.reset(new GLES2ClientImpl(gles2.Pass()));
  service_->CreateGLES2Context(gles2_client.Pass());
}

void NativeViewportClientImpl::OnCreated() {
}

void NativeViewportClientImpl::OnDestroyed() {
  base::MessageLoop::current()->Quit();
}

void NativeViewportClientImpl::OnEvent(const Event& event) {
  if (!event.location().is_null()) {
    gles2_client_->HandleInputEvent(event);
    service_->AckEvent(event);
  }
}

}  // namespace examples
}  // namespace mojo