summaryrefslogtreecommitdiffstats
path: root/mojo/examples
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 23:33:36 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-08 23:33:36 +0000
commitbe88d4cb2d8f7e63c92207649d91345b79d77f51 (patch)
tree7009aa39be187cada475d6532bf98df35f6c795e /mojo/examples
parentf3364a26ae5ef64346a04ac3483bc28b6efabb21 (diff)
downloadchromium_src-be88d4cb2d8f7e63c92207649d91345b79d77f51.zip
chromium_src-be88d4cb2d8f7e63c92207649d91345b79d77f51.tar.gz
chromium_src-be88d4cb2d8f7e63c92207649d91345b79d77f51.tar.bz2
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
Diffstat (limited to 'mojo/examples')
-rw-r--r--mojo/examples/compositor_app/gles2_client_impl.cc2
-rw-r--r--mojo/examples/compositor_app/gles2_client_impl.h1
-rw-r--r--mojo/examples/sample_app/gles2_client_impl.cc41
-rw-r--r--mojo/examples/sample_app/gles2_client_impl.h13
-rw-r--r--mojo/examples/sample_app/sample_app.cc12
5 files changed, 39 insertions, 30 deletions
diff --git a/mojo/examples/compositor_app/gles2_client_impl.cc b/mojo/examples/compositor_app/gles2_client_impl.cc
index f6849fd..7bd0b06 100644
--- a/mojo/examples/compositor_app/gles2_client_impl.cc
+++ b/mojo/examples/compositor_app/gles2_client_impl.cc
@@ -40,5 +40,7 @@ gpu::ContextSupport* GLES2ClientImpl::Support() const {
void GLES2ClientImpl::ContextLost() { impl_ = NULL; }
+void GLES2ClientImpl::DrawAnimationFrame() {}
+
} // namespace examples
} // namespace mojo
diff --git a/mojo/examples/compositor_app/gles2_client_impl.h b/mojo/examples/compositor_app/gles2_client_impl.h
index 38d80b5..fbb49b0 100644
--- a/mojo/examples/compositor_app/gles2_client_impl.h
+++ b/mojo/examples/compositor_app/gles2_client_impl.h
@@ -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_;
diff --git a/mojo/examples/sample_app/gles2_client_impl.cc b/mojo/examples/sample_app/gles2_client_impl.cc
index 3dd943d..644645c 100644
--- a/mojo/examples/sample_app/gles2_client_impl.cc
+++ b/mojo/examples/sample_app/gles2_client_impl.cc
@@ -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
diff --git a/mojo/examples/sample_app/gles2_client_impl.h b/mojo/examples/sample_app/gles2_client_impl.h
index 8dbc91d..35f59ff 100644
--- a/mojo/examples/sample_app/gles2_client_impl.h
+++ b/mojo/examples/sample_app/gles2_client_impl.h
@@ -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_;
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index b3bd71f..382aac9 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -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(