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.
8 #include "mojo/examples/sample_app/gles2_client_impl.h"
9 #include "mojo/public/cpp/application/application_connection.h"
10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/system/core.h"
13 #include "mojo/public/cpp/system/macros.h"
14 #include "mojo/public/cpp/utility/run_loop.h"
15 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
19 class SampleApp : public mojo::ApplicationDelegate,
20 public mojo::NativeViewportClient {
24 virtual ~SampleApp() {
25 // TODO(darin): Fix shutdown so we don't need to leak this.
26 MOJO_ALLOW_UNUSED GLES2ClientImpl* leaked = gles2_client_.release();
29 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE {
30 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
31 viewport_.set_client(this);
33 mojo::RectPtr rect(mojo::Rect::New());
38 viewport_->Create(rect.Pass());
41 mojo::CommandBufferPtr command_buffer;
42 viewport_->CreateGLES2Context(Get(&command_buffer));
43 gles2_client_.reset(new GLES2ClientImpl(command_buffer.Pass()));
46 virtual void OnCreated() MOJO_OVERRIDE {
49 virtual void OnDestroyed(
50 const mojo::Callback<void()>& callback) MOJO_OVERRIDE {
51 mojo::RunLoop::current()->Quit();
55 virtual void OnBoundsChanged(mojo::RectPtr bounds) MOJO_OVERRIDE {
57 mojo::SizePtr size(mojo::Size::New());
58 size->width = bounds->width;
59 size->height = bounds->height;
60 gles2_client_->SetSize(*size);
63 virtual void OnEvent(mojo::EventPtr event,
64 const mojo::Callback<void()>& callback) MOJO_OVERRIDE {
67 gles2_client_->HandleInputEvent(*event);
72 scoped_ptr<GLES2ClientImpl> gles2_client_;
73 mojo::NativeViewportPtr viewport_;
75 DISALLOW_COPY_AND_ASSIGN(SampleApp);
78 } // namespace examples
83 ApplicationDelegate* ApplicationDelegate::Create() {
84 return new examples::SampleApp();