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