Remove dependencies on base from SampleApp

- Change to use mojo::utility::RunLoop
- Move timer from gles2_client_impl to gles2_impl with added api.

BUG=None
TEST=None
R=darin

Review URL: https://codereview.chromium.org/128813002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243695 0039d316-1c4b-4281-b951-d872f2087c98
parent f3364a26
...@@ -40,5 +40,7 @@ gpu::ContextSupport* GLES2ClientImpl::Support() const { ...@@ -40,5 +40,7 @@ gpu::ContextSupport* GLES2ClientImpl::Support() const {
void GLES2ClientImpl::ContextLost() { impl_ = NULL; } void GLES2ClientImpl::ContextLost() { impl_ = NULL; }
void GLES2ClientImpl::DrawAnimationFrame() {}
} // namespace examples } // namespace examples
} // namespace mojo } // namespace mojo
...@@ -38,6 +38,7 @@ class GLES2ClientImpl : public GLES2Client { ...@@ -38,6 +38,7 @@ class GLES2ClientImpl : public GLES2Client {
uint32_t width, uint32_t width,
uint32_t height) MOJO_OVERRIDE; uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost() MOJO_OVERRIDE; virtual void ContextLost() MOJO_OVERRIDE;
virtual void DrawAnimationFrame() MOJO_OVERRIDE;
base::Callback<void(gfx::Size viewport_size)> context_created_callback_; base::Callback<void(gfx::Size viewport_size)> context_created_callback_;
gpu::gles2::GLES2Implementation* impl_; gpu::gles2::GLES2Implementation* impl_;
......
...@@ -22,7 +22,8 @@ float CalculateDragDistance(const gfx::PointF& start, const Point& end) { ...@@ -22,7 +22,8 @@ float CalculateDragDistance(const gfx::PointF& start, const Point& end) {
} }
GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe)
: service_(pipe.Pass(), this) { : getting_animation_frames_(false),
service_(pipe.Pass(), this) {
} }
GLES2ClientImpl::~GLES2ClientImpl() { GLES2ClientImpl::~GLES2ClientImpl() {
...@@ -33,14 +34,14 @@ void GLES2ClientImpl::HandleInputEvent(const Event& event) { ...@@ -33,14 +34,14 @@ void GLES2ClientImpl::HandleInputEvent(const Event& event) {
switch (event.action()) { switch (event.action()) {
case ui::ET_MOUSE_PRESSED: case ui::ET_MOUSE_PRESSED:
case ui::ET_TOUCH_PRESSED: case ui::ET_TOUCH_PRESSED:
timer_.Stop(); CancelAnimationFrames();
capture_point_.SetPoint(event.location().x(), event.location().y()); capture_point_.SetPoint(event.location().x(), event.location().y());
last_drag_point_ = capture_point_; last_drag_point_ = capture_point_;
drag_start_time_ = base::Time::Now(); drag_start_time_ = GetTimeTicksNow();
break; break;
case ui::ET_MOUSE_DRAGGED: case ui::ET_MOUSE_DRAGGED:
case ui::ET_TOUCH_MOVED: case ui::ET_TOUCH_MOVED:
if (!timer_.IsRunning()) { if (!getting_animation_frames_) {
int direction = event.location().y() < last_drag_point_.y() || int direction = event.location().y() < last_drag_point_.y() ||
event.location().x() > last_drag_point_.x() ? 1 : -1; event.location().x() > last_drag_point_.x() ? 1 : -1;
cube_.set_direction(direction); cube_.set_direction(direction);
...@@ -54,12 +55,14 @@ void GLES2ClientImpl::HandleInputEvent(const Event& event) { ...@@ -54,12 +55,14 @@ void GLES2ClientImpl::HandleInputEvent(const Event& event) {
break; break;
case ui::ET_MOUSE_RELEASED: case ui::ET_MOUSE_RELEASED:
case ui::ET_TOUCH_RELEASED: { case ui::ET_TOUCH_RELEASED: {
MojoTimeTicks offset = GetTimeTicksNow() - drag_start_time_;
float delta = static_cast<float>(offset) / 1000000.;
cube_.SetFlingMultiplier( cube_.SetFlingMultiplier(
CalculateDragDistance(capture_point_, event.location()), CalculateDragDistance(capture_point_, event.location()),
base::TimeDelta(base::Time::Now() - drag_start_time_).InSecondsF()); delta);
capture_point_ = last_drag_point_ = gfx::PointF(); capture_point_ = last_drag_point_ = gfx::PointF();
StartTimer(); RequestAnimationFrames();
} }
break; break;
default: default:
...@@ -73,27 +76,33 @@ void GLES2ClientImpl::DidCreateContext(uint64_t encoded, ...@@ -73,27 +76,33 @@ void GLES2ClientImpl::DidCreateContext(uint64_t encoded,
MojoGLES2MakeCurrent(encoded); MojoGLES2MakeCurrent(encoded);
cube_.Init(width, height); cube_.Init(width, height);
StartTimer(); RequestAnimationFrames();
} }
void GLES2ClientImpl::ContextLost() { void GLES2ClientImpl::ContextLost() {
timer_.Stop(); CancelAnimationFrames();
} }
void GLES2ClientImpl::Draw() { void GLES2ClientImpl::DrawAnimationFrame() {
base::Time now = base::Time::Now(); MojoTimeTicks now = GetTimeTicksNow();
base::TimeDelta offset = now - last_time_; MojoTimeTicks offset = now - last_time_;
float delta = static_cast<float>(offset) / 1000000.;
last_time_ = now; last_time_ = now;
cube_.UpdateForTimeDelta(offset.InSecondsF()); cube_.UpdateForTimeDelta(delta);
cube_.Draw(); cube_.Draw();
MojoGLES2SwapBuffers(); MojoGLES2SwapBuffers();
} }
void GLES2ClientImpl::StartTimer() { void GLES2ClientImpl::RequestAnimationFrames() {
last_time_ = base::Time::Now(); getting_animation_frames_ = true;
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), service_->RequestAnimationFrames();
this, &GLES2ClientImpl::Draw); last_time_ = GetTimeTicksNow();
}
void GLES2ClientImpl::CancelAnimationFrames() {
getting_animation_frames_ = false;
service_->CancelAnimationFrames();
} }
} // namespace examples } // namespace examples
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#ifndef MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ #ifndef MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_
#define MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ #define MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "mojo/examples/sample_app/spinning_cube.h" #include "mojo/examples/sample_app/spinning_cube.h"
#include "mojo/public/bindings/lib/remote_ptr.h" #include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojom/gles2.h" #include "mojom/gles2.h"
...@@ -28,16 +26,17 @@ class GLES2ClientImpl : public GLES2Client { ...@@ -28,16 +26,17 @@ class GLES2ClientImpl : public GLES2Client {
uint32_t width, uint32_t width,
uint32_t height) MOJO_OVERRIDE; uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost() MOJO_OVERRIDE; virtual void ContextLost() MOJO_OVERRIDE;
virtual void DrawAnimationFrame() MOJO_OVERRIDE;
void Draw(); void RequestAnimationFrames();
void StartTimer(); void CancelAnimationFrames();
base::Time last_time_; MojoTimeTicks last_time_;
base::RepeatingTimer<GLES2ClientImpl> timer_;
SpinningCube cube_; SpinningCube cube_;
gfx::PointF capture_point_; gfx::PointF capture_point_;
gfx::PointF last_drag_point_; gfx::PointF last_drag_point_;
base::Time drag_start_time_; MojoTimeTicks drag_start_time_;
bool getting_animation_frames_;
RemotePtr<GLES2> service_; RemotePtr<GLES2> service_;
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include "base/message_loop/message_loop.h"
#include "mojo/common/bindings_support_impl.h"
#include "mojo/examples/sample_app/gles2_client_impl.h" #include "mojo/examples/sample_app/gles2_client_impl.h"
#include "mojo/public/bindings/lib/bindings_support.h" #include "mojo/public/bindings/lib/bindings_support.h"
#include "mojo/public/bindings/lib/remote_ptr.h" #include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojo/public/gles2/gles2.h" #include "mojo/public/gles2/gles2.h"
#include "mojo/public/system/core.h" #include "mojo/public/system/core.h"
#include "mojo/public/system/macros.h" #include "mojo/public/system/macros.h"
#include "mojo/public/utility/environment.h"
#include "mojo/public/utility/run_loop.h"
#include "mojom/native_viewport.h" #include "mojom/native_viewport.h"
#include "mojom/shell.h" #include "mojom/shell.h"
...@@ -42,7 +42,6 @@ class SampleApp : public ShellClient { ...@@ -42,7 +42,6 @@ class SampleApp : public ShellClient {
} }
virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE { virtual void AcceptConnection(ScopedMessagePipeHandle handle) MOJO_OVERRIDE {
NOTREACHED() << "SampleApp can't be connected to.";
} }
private: private:
...@@ -63,7 +62,7 @@ class SampleApp : public ShellClient { ...@@ -63,7 +62,7 @@ class SampleApp : public ShellClient {
} }
virtual void OnDestroyed() MOJO_OVERRIDE { virtual void OnDestroyed() MOJO_OVERRIDE {
base::MessageLoop::current()->Quit(); utility::RunLoop::current()->Quit();
} }
virtual void OnEvent(const Event& event) MOJO_OVERRIDE { virtual void OnEvent(const Event& event) MOJO_OVERRIDE {
...@@ -86,9 +85,8 @@ class SampleApp : public ShellClient { ...@@ -86,9 +85,8 @@ class SampleApp : public ShellClient {
extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
MojoHandle shell_handle) { MojoHandle shell_handle) {
base::MessageLoop loop; mojo::utility::Environment env;
mojo::common::BindingsSupportImpl bindings_support_impl; mojo::utility::RunLoop loop;
mojo::BindingsSupport::Set(&bindings_support_impl);
MojoGLES2Initialize(); MojoGLES2Initialize();
mojo::examples::SampleApp app( mojo::examples::SampleApp app(
......
...@@ -8,17 +8,16 @@ ...@@ -8,17 +8,16 @@
'target_name': 'mojo_sample_app', 'target_name': 'mojo_sample_app',
'type': 'shared_library', 'type': 'shared_library',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base',
'../gpu/gpu.gyp:gles2_c_lib', '../gpu/gpu.gyp:gles2_c_lib',
'../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry', '../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gl/gl.gyp:gl', '../ui/gl/gl.gyp:gl',
'mojo_common_lib',
'mojo_gles2', 'mojo_gles2',
'mojo_gles2_bindings', 'mojo_gles2_bindings',
'mojo_native_viewport_bindings', 'mojo_native_viewport_bindings',
'mojo_shell_bindings', 'mojo_shell_bindings',
'mojo_system', 'mojo_system',
'mojo_utility',
], ],
'sources': [ 'sources': [
'examples/sample_app/gles2_client_impl.cc', 'examples/sample_app/gles2_client_impl.cc',
......
...@@ -6,6 +6,8 @@ module mojo { ...@@ -6,6 +6,8 @@ module mojo {
[Peer=GLES2Client] [Peer=GLES2Client]
interface GLES2 { interface GLES2 {
void RequestAnimationFrames();
void CancelAnimationFrames();
void Destroy(); void Destroy();
}; };
...@@ -13,6 +15,7 @@ interface GLES2 { ...@@ -13,6 +15,7 @@ interface GLES2 {
interface GLES2Client { interface GLES2Client {
void DidCreateContext(uint64 encoded, uint32 width, uint32 height); void DidCreateContext(uint64 encoded, uint32 width, uint32 height);
void ContextLost(); void ContextLost();
void DrawAnimationFrame();
}; };
} }
...@@ -19,6 +19,15 @@ GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client) ...@@ -19,6 +19,15 @@ GLES2Impl::GLES2Impl(ScopedMessagePipeHandle client)
GLES2Impl::~GLES2Impl() { GLES2Impl::~GLES2Impl() {
} }
void GLES2Impl::RequestAnimationFrames() {
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16),
this, &GLES2Impl::DrawAnimationFrame);
}
void GLES2Impl::CancelAnimationFrames() {
timer_.Stop();
}
void GLES2Impl::Destroy() { void GLES2Impl::Destroy() {
gl_context_.reset(); gl_context_.reset();
} }
...@@ -41,5 +50,9 @@ void GLES2Impl::OnGLContextLost() { ...@@ -41,5 +50,9 @@ void GLES2Impl::OnGLContextLost() {
client_->ContextLost(); client_->ContextLost();
} }
void GLES2Impl::DrawAnimationFrame() {
client_->DrawAnimationFrame();
}
} // namespace services } // namespace services
} // namespace mojo } // namespace mojo
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MOJO_SERVICES_GLES2_GLES2_IMPL_H_ #define MOJO_SERVICES_GLES2_GLES2_IMPL_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
#include "mojo/public/bindings/lib/remote_ptr.h" #include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojo/public/system/core_cpp.h" #include "mojo/public/system/core_cpp.h"
#include "mojom/gles2.h" #include "mojom/gles2.h"
...@@ -24,13 +25,17 @@ class GLES2Impl : public GLES2 { ...@@ -24,13 +25,17 @@ class GLES2Impl : public GLES2 {
explicit GLES2Impl(ScopedMessagePipeHandle client); explicit GLES2Impl(ScopedMessagePipeHandle client);
virtual ~GLES2Impl(); virtual ~GLES2Impl();
virtual void Destroy() OVERRIDE;
void CreateContext(gfx::AcceleratedWidget widget, const gfx::Size& size); void CreateContext(gfx::AcceleratedWidget widget, const gfx::Size& size);
private: private:
virtual void RequestAnimationFrames() OVERRIDE;
virtual void CancelAnimationFrames() OVERRIDE;
virtual void Destroy() OVERRIDE;
void OnGLContextLost(); void OnGLContextLost();
void DrawAnimationFrame();
base::RepeatingTimer<GLES2Impl> timer_;
scoped_ptr<gpu::GLInProcessContext> gl_context_; scoped_ptr<gpu::GLInProcessContext> gl_context_;
RemotePtr<GLES2Client> client_; RemotePtr<GLES2Client> client_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment