Index: examples/ganesh_app/ganesh_view.cc |
diff --git a/examples/ganesh_app/ganesh_view.cc b/examples/ganesh_app/ganesh_view.cc |
index fa4041de7741f5a5a4791e138c12ae23e9cca8bd..a14b8f2b97df95b84abcf149fb66b07be81c7f18 100644 |
--- a/examples/ganesh_app/ganesh_view.cc |
+++ b/examples/ganesh_app/ganesh_view.cc |
@@ -4,6 +4,7 @@ |
#include "examples/ganesh_app/ganesh_view.h" |
+#include "base/message_loop/message_loop.h" |
#include "examples/ganesh_app/ganesh_texture.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
@@ -16,14 +17,24 @@ mojo::Size ToSize(const mojo::Rect& rect) { |
size.height = rect.height; |
return size; |
} |
+ |
+int RadiusAt(base::TimeTicks base_time, base::TimeTicks frame_time) { |
+ return 50 + ((frame_time - base_time).InMilliseconds() % 6000) / 60; |
+} |
} |
GaneshView::GaneshView(mojo::Shell* shell, mojo::View* view) |
: view_(view), |
gl_context_(shell), |
gr_context_(gl_context_.context()), |
- texture_uploader_(this, shell, gl_context_.context()) { |
- Draw(ToSize(view_->bounds())); |
+ texture_uploader_(this, shell, gl_context_.context()), |
+ base_time_(base::TimeTicks::Now()), |
+ scheduler_(this, base::MessageLoop::current()->task_runner().get()) { |
+ // TODO(abarth): Get the vsync parameters from the output surface. |
+ base::TimeDelta sixty_hz = base::TimeDelta::FromSecondsD(1.0 / 60); |
+ scheduler_.UpdateVSync(mc::TimeInterval(base_time_, sixty_hz)); |
+ |
+ scheduler_.SetNeedsFrame(); |
} |
GaneshView::~GaneshView() { |
@@ -40,20 +51,32 @@ void GaneshView::OnViewDestroyed(mojo::View* view) { |
void GaneshView::OnViewBoundsChanged(mojo::View* view, |
const mojo::Rect& old_bounds, |
const mojo::Rect& new_bounds) { |
- Draw(ToSize(new_bounds)); |
+ scheduler_.SetNeedsFrame(); |
} |
-void GaneshView::Draw(const mojo::Size& size) { |
+base::TimeDelta GaneshView::Draw(base::TimeTicks frame_time) { |
+ base::TimeTicks start = base::TimeTicks::Now(); |
+ |
+ mojo::Size size = ToSize(view_->bounds()); |
+ |
GaneshTexture texture(gr_context_.context(), size); |
SkCanvas* canvas = texture.canvas(); |
SkPaint paint; |
paint.setColor(SK_ColorRED); |
paint.setFlags(SkPaint::kAntiAlias_Flag); |
- canvas->drawCircle(50, 100, 100, paint); |
+ canvas->drawCircle(50, 100, RadiusAt(base_time_, frame_time), paint); |
canvas->flush(); |
texture_uploader_.Upload(texture.texture_id(), size); |
+ |
+ return base::TimeTicks::Now() - start; |
+} |
+ |
+void GaneshView::BeginFrame(base::TimeTicks frame_time, |
+ base::TimeTicks deadline) { |
+ scheduler_.UpdateFrameDuration(Draw(frame_time)); |
+ scheduler_.SetNeedsFrame(); |
} |
} // namespace examples |