OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/examples/sample_app/gles2_client_impl.h" | 5 #include "mojo/examples/sample_app/gles2_client_impl.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <math.h> | 9 #include <math.h> |
| 10 #include <stdlib.h> |
10 | 11 |
11 #include "mojo/public/c/gles2/gles2.h" | 12 #include "mojo/public/c/gles2/gles2.h" |
12 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace examples { | 16 namespace examples { |
16 namespace { | 17 namespace { |
17 | 18 |
18 float CalculateDragDistance(const gfx::PointF& start, const Point& end) { | 19 float CalculateDragDistance(const gfx::PointF& start, const Point& end) { |
19 return hypot(start.x() - end.x(), start.y() - end.y()); | 20 return hypot(start.x() - end.x(), start.y() - end.y()); |
20 } | 21 } |
21 | 22 |
| 23 float GetRandomColor() { |
| 24 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX); |
| 25 } |
| 26 |
22 } | 27 } |
23 | 28 |
24 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) | 29 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) |
25 : getting_animation_frames_(false) { | 30 : getting_animation_frames_(false) { |
26 context_ = MojoGLES2CreateContext( | 31 context_ = MojoGLES2CreateContext( |
27 pipe.release().value(), | 32 pipe.release().value(), |
28 &ContextLostThunk, | 33 &ContextLostThunk, |
29 &DrawAnimationFrameThunk, | 34 &DrawAnimationFrameThunk, |
30 this); | 35 this); |
31 MojoGLES2MakeCurrent(context_); | 36 MojoGLES2MakeCurrent(context_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 72 } |
68 break; | 73 break; |
69 case ui::ET_MOUSE_RELEASED: | 74 case ui::ET_MOUSE_RELEASED: |
70 case ui::ET_TOUCH_RELEASED: { | 75 case ui::ET_TOUCH_RELEASED: { |
71 MojoTimeTicks offset = GetTimeTicksNow() - drag_start_time_; | 76 MojoTimeTicks offset = GetTimeTicksNow() - drag_start_time_; |
72 float delta = static_cast<float>(offset) / 1000000.; | 77 float delta = static_cast<float>(offset) / 1000000.; |
73 cube_.SetFlingMultiplier( | 78 cube_.SetFlingMultiplier( |
74 CalculateDragDistance(capture_point_, event.location()), | 79 CalculateDragDistance(capture_point_, event.location()), |
75 delta); | 80 delta); |
76 | 81 |
| 82 cube_.set_color(GetRandomColor(), GetRandomColor(), GetRandomColor()); |
| 83 |
77 capture_point_ = last_drag_point_ = gfx::PointF(); | 84 capture_point_ = last_drag_point_ = gfx::PointF(); |
78 RequestAnimationFrames(); | 85 RequestAnimationFrames(); |
79 } | 86 } |
80 break; | 87 break; |
81 default: | 88 default: |
82 break; | 89 break; |
83 } | 90 } |
84 } | 91 } |
85 | 92 |
86 void GLES2ClientImpl::ContextLost() { | 93 void GLES2ClientImpl::ContextLost() { |
(...skipping 25 matching lines...) Expand all Loading... |
112 last_time_ = GetTimeTicksNow(); | 119 last_time_ = GetTimeTicksNow(); |
113 } | 120 } |
114 | 121 |
115 void GLES2ClientImpl::CancelAnimationFrames() { | 122 void GLES2ClientImpl::CancelAnimationFrames() { |
116 getting_animation_frames_ = false; | 123 getting_animation_frames_ = false; |
117 MojoGLES2CancelAnimationFrames(context_); | 124 MojoGLES2CancelAnimationFrames(context_); |
118 } | 125 } |
119 | 126 |
120 } // namespace examples | 127 } // namespace examples |
121 } // namespace mojo | 128 } // namespace mojo |
OLD | NEW |