diff options
Diffstat (limited to 'mojo/examples')
-rw-r--r-- | mojo/examples/sample_app/DEPS | 5 | ||||
-rw-r--r-- | mojo/examples/sample_app/gles2_client_impl.cc | 50 | ||||
-rw-r--r-- | mojo/examples/sample_app/gles2_client_impl.h | 41 | ||||
-rw-r--r-- | mojo/examples/sample_app/native_viewport_client_impl.cc | 4 | ||||
-rw-r--r-- | mojo/examples/sample_app/native_viewport_client_impl.h | 5 | ||||
-rw-r--r-- | mojo/examples/sample_app/sample_app.cc | 6 | ||||
-rw-r--r-- | mojo/examples/sample_app/sample_gles2_delegate.cc | 45 | ||||
-rw-r--r-- | mojo/examples/sample_app/sample_gles2_delegate.h | 36 |
8 files changed, 98 insertions, 94 deletions
diff --git a/mojo/examples/sample_app/DEPS b/mojo/examples/sample_app/DEPS deleted file mode 100644 index 2f6ef95..0000000 --- a/mojo/examples/sample_app/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - # TODO(abarth): Rather than including this interface directly, - # we need to figure out the right way for apps to call GL. - "!gpu/command_buffer/client/gles2_interface.h", -] diff --git a/mojo/examples/sample_app/gles2_client_impl.cc b/mojo/examples/sample_app/gles2_client_impl.cc new file mode 100644 index 0000000..2a87ca0 --- /dev/null +++ b/mojo/examples/sample_app/gles2_client_impl.cc @@ -0,0 +1,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/gles2_client_impl.h" + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#include "mojo/public/gles2/gles2.h" + +namespace mojo { +namespace examples { + +GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) + : service_(pipe.Pass()) { + service_.SetPeer(this); +} + +GLES2ClientImpl::~GLES2ClientImpl() { + service_->Destroy(); +} + +void GLES2ClientImpl::DidCreateContext(uint64_t encoded, + uint32_t width, + uint32_t height) { + MojoGLES2MakeCurrent(encoded); + + cube_.Init(width, height); + last_time_ = base::Time::Now(); + timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), + this, &GLES2ClientImpl::Draw); +} + +void GLES2ClientImpl::Draw() { + base::Time now = base::Time::Now(); + base::TimeDelta offset = now - last_time_; + last_time_ = now; + cube_.Update(offset.InSecondsF()); + cube_.Draw(); + + MojoGLES2SwapBuffers(); +} + +void GLES2ClientImpl::ContextLost() { + timer_.Stop(); +} + +} // namespace examples +} // namespace mojo diff --git a/mojo/examples/sample_app/gles2_client_impl.h b/mojo/examples/sample_app/gles2_client_impl.h new file mode 100644 index 0000000..1d38a3c --- /dev/null +++ b/mojo/examples/sample_app/gles2_client_impl.h @@ -0,0 +1,41 @@ +// 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. + +#ifndef MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ +#define MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ + +#include "base/timer/timer.h" +#include "mojo/examples/sample_app/spinning_cube.h" +#include "mojo/public/bindings/lib/remote_ptr.h" +#include "mojom/gles2.h" + +namespace mojo { +namespace examples { + +class GLES2ClientImpl : public GLES2ClientStub { + public: + explicit GLES2ClientImpl(ScopedMessagePipeHandle pipe); + virtual ~GLES2ClientImpl(); + + private: + virtual void DidCreateContext(uint64_t encoded, + uint32_t width, + uint32_t height) MOJO_OVERRIDE; + virtual void ContextLost() MOJO_OVERRIDE; + + void Draw(); + + base::Time last_time_; + base::RepeatingTimer<GLES2ClientImpl> timer_; + SpinningCube cube_; + + RemotePtr<GLES2> service_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(GLES2ClientImpl); +}; + +} // namespace examples +} // namespace mojo + +#endif // MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ diff --git a/mojo/examples/sample_app/native_viewport_client_impl.cc b/mojo/examples/sample_app/native_viewport_client_impl.cc index 6f10990..5d70df1 100644 --- a/mojo/examples/sample_app/native_viewport_client_impl.cc +++ b/mojo/examples/sample_app/native_viewport_client_impl.cc @@ -6,8 +6,6 @@ #include <stdio.h> -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" - namespace mojo { namespace examples { @@ -27,7 +25,7 @@ void NativeViewportClientImpl::Open() { ScopedMessagePipeHandle gles2_client; CreateMessagePipe(&gles2, &gles2_client); - gles2_client_.reset(new GLES2ClientImpl(&gles2_delegate_, gles2.Pass())); + gles2_client_.reset(new GLES2ClientImpl(gles2.Pass())); service_->CreateGLES2Context(gles2_client.release()); } diff --git a/mojo/examples/sample_app/native_viewport_client_impl.h b/mojo/examples/sample_app/native_viewport_client_impl.h index d959c45..32beb6b 100644 --- a/mojo/examples/sample_app/native_viewport_client_impl.h +++ b/mojo/examples/sample_app/native_viewport_client_impl.h @@ -6,7 +6,7 @@ #define MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_ #include "base/memory/scoped_ptr.h" -#include "mojo/examples/sample_app/sample_gles2_delegate.h" +#include "mojo/examples/sample_app/gles2_client_impl.h" #include "mojo/public/bindings/lib/remote_ptr.h" #include "mojom/native_viewport.h" @@ -23,10 +23,11 @@ class NativeViewportClientImpl : public NativeViewportClientStub { private: virtual void DidOpen() MOJO_OVERRIDE; - SampleGLES2Delegate gles2_delegate_; scoped_ptr<GLES2ClientImpl> gles2_client_; RemotePtr<NativeViewport> service_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(NativeViewportClientImpl); }; } // namespace examples diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc index 1cf86c4..02d4ce2 100644 --- a/mojo/examples/sample_app/sample_app.cc +++ b/mojo/examples/sample_app/sample_app.cc @@ -8,8 +8,8 @@ #include "base/message_loop/message_loop.h" #include "mojo/common/bindings_support_impl.h" #include "mojo/examples/sample_app/native_viewport_client_impl.h" -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" #include "mojo/public/bindings/lib/bindings_support.h" +#include "mojo/public/gles2/gles2.h" #include "mojo/public/system/core.h" #include "mojo/public/system/macros.h" @@ -40,13 +40,13 @@ extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { base::MessageLoop loop; mojo::common::BindingsSupportImpl bindings_support; mojo::BindingsSupport::Set(&bindings_support); - mojo::GLES2ClientImpl::Initialize(); + MojoGLES2Initialize(); mojo::ScopedMessagePipeHandle scoped_handle; scoped_handle.reset(mojo::MessagePipeHandle(pipe)); mojo::examples::Start(scoped_handle.Pass()); - mojo::GLES2ClientImpl::Terminate(); + MojoGLES2Terminate(); mojo::BindingsSupport::Set(NULL); return MOJO_RESULT_OK; } diff --git a/mojo/examples/sample_app/sample_gles2_delegate.cc b/mojo/examples/sample_app/sample_gles2_delegate.cc deleted file mode 100644 index 4bac022..0000000 --- a/mojo/examples/sample_app/sample_gles2_delegate.cc +++ /dev/null @@ -1,45 +0,0 @@ -// 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/sample_gles2_delegate.h" - -#include <stdio.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> - -namespace mojo { -namespace examples { - -SampleGLES2Delegate::SampleGLES2Delegate() - : gl_(NULL) { -} - -SampleGLES2Delegate::~SampleGLES2Delegate() { -} - -void SampleGLES2Delegate::DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height) { - gl_ = gl; - cube_.Init(width, height); - last_time_ = base::Time::Now(); - timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), - this, &SampleGLES2Delegate::Draw); -} - -void SampleGLES2Delegate::Draw() { - base::Time now = base::Time::Now(); - base::TimeDelta offset = now - last_time_; - last_time_ = now; - cube_.Update(offset.InSecondsF()); - cube_.Draw(); - gl_->SwapBuffers(); -} - -void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) { - gl_ = NULL; - timer_.Stop(); -} - -} // namespace examples -} // namespace mojo diff --git a/mojo/examples/sample_app/sample_gles2_delegate.h b/mojo/examples/sample_app/sample_gles2_delegate.h deleted file mode 100644 index efd4872..0000000 --- a/mojo/examples/sample_app/sample_gles2_delegate.h +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -#ifndef MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ -#define MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ - -#include "base/timer/timer.h" -#include "mojo/examples/sample_app/spinning_cube.h" -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" - -namespace mojo { -namespace examples { - -class SampleGLES2Delegate : public GLES2Delegate { - public: - SampleGLES2Delegate(); - virtual ~SampleGLES2Delegate(); - - private: - virtual void DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE; - virtual void ContextLost(GLES2ClientImpl* gl) MOJO_OVERRIDE; - - void Draw(); - - base::Time last_time_; - base::RepeatingTimer<SampleGLES2Delegate> timer_; - SpinningCube cube_; - GLES2ClientImpl* gl_; -}; - -} // namespace examples -} // namespace mojo - -#endif // MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ |