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 | 10 |
11 #include "mojo/public/c/gles2/gles2.h" | 11 #include "mojo/public/c/gles2/gles2.h" |
12 #include "ui/events/event_constants.h" | 12 #include "ui/events/event_constants.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace examples { | 15 namespace examples { |
16 namespace { | 16 namespace { |
17 | 17 |
18 float CalculateDragDistance(const gfx::PointF& start, const Point& end) { | 18 float CalculateDragDistance(const gfx::PointF& start, const Point& end) { |
19 return hypot(start.x() - end.x(), start.y() - end.y()); | 19 return hypot(start.x() - end.x, start.y() - end.y); |
20 } | 20 } |
21 | 21 |
22 } | 22 } |
23 | 23 |
24 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) | 24 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) |
25 : getting_animation_frames_(false) { | 25 : getting_animation_frames_(false) { |
26 context_ = MojoGLES2CreateContext( | 26 context_ = MojoGLES2CreateContext( |
27 pipe.release().value(), | 27 pipe.release().value(), |
28 &ContextLostThunk, | 28 &ContextLostThunk, |
29 &DrawAnimationFrameThunk, | 29 &DrawAnimationFrameThunk, |
30 this); | 30 this); |
31 MojoGLES2MakeCurrent(context_); | 31 MojoGLES2MakeCurrent(context_); |
32 } | 32 } |
33 | 33 |
34 GLES2ClientImpl::~GLES2ClientImpl() { | 34 GLES2ClientImpl::~GLES2ClientImpl() { |
35 MojoGLES2DestroyContext(context_); | 35 MojoGLES2DestroyContext(context_); |
36 } | 36 } |
37 | 37 |
38 void GLES2ClientImpl::SetSize(const Size& size) { | 38 void GLES2ClientImpl::SetSize(const Size& size) { |
39 size_ = gfx::Size(size.width(), size.height()); | 39 size_ = gfx::Size(size.width, size.height); |
40 if (size_.IsEmpty()) | 40 if (size_.IsEmpty()) |
41 return; | 41 return; |
42 cube_.Init(size_.width(), size_.height()); | 42 cube_.Init(size_.width(), size_.height()); |
43 RequestAnimationFrames(); | 43 RequestAnimationFrames(); |
44 } | 44 } |
45 | 45 |
46 void GLES2ClientImpl::HandleInputEvent(const Event& event) { | 46 void GLES2ClientImpl::HandleInputEvent(const Event& event) { |
47 switch (event.action()) { | 47 switch (event.action) { |
48 case ui::ET_MOUSE_PRESSED: | 48 case ui::ET_MOUSE_PRESSED: |
49 case ui::ET_TOUCH_PRESSED: | 49 case ui::ET_TOUCH_PRESSED: |
50 CancelAnimationFrames(); | 50 CancelAnimationFrames(); |
51 capture_point_.SetPoint(event.location().x(), event.location().y()); | 51 capture_point_.SetPoint(event.location->x, event.location->y); |
52 last_drag_point_ = capture_point_; | 52 last_drag_point_ = capture_point_; |
53 drag_start_time_ = GetTimeTicksNow(); | 53 drag_start_time_ = GetTimeTicksNow(); |
54 break; | 54 break; |
55 case ui::ET_MOUSE_DRAGGED: | 55 case ui::ET_MOUSE_DRAGGED: |
56 case ui::ET_TOUCH_MOVED: | 56 case ui::ET_TOUCH_MOVED: |
57 if (!getting_animation_frames_) { | 57 if (!getting_animation_frames_) { |
58 int direction = event.location().y() < last_drag_point_.y() || | 58 int direction = event.location->y < last_drag_point_.y() || |
59 event.location().x() > last_drag_point_.x() ? 1 : -1; | 59 event.location->x > last_drag_point_.x() ? 1 : -1; |
60 cube_.set_direction(direction); | 60 cube_.set_direction(direction); |
61 cube_.UpdateForDragDistance( | 61 cube_.UpdateForDragDistance( |
62 CalculateDragDistance(last_drag_point_, event.location())); | 62 CalculateDragDistance(last_drag_point_, *event.location)); |
63 cube_.Draw(); | 63 cube_.Draw(); |
64 MojoGLES2SwapBuffers(); | 64 MojoGLES2SwapBuffers(); |
65 | 65 |
66 last_drag_point_.SetPoint(event.location().x(), event.location().y()); | 66 last_drag_point_.SetPoint(event.location->x, event.location->y); |
67 } | 67 } |
68 break; | 68 break; |
69 case ui::ET_MOUSE_RELEASED: | 69 case ui::ET_MOUSE_RELEASED: |
70 case ui::ET_TOUCH_RELEASED: { | 70 case ui::ET_TOUCH_RELEASED: { |
71 MojoTimeTicks offset = GetTimeTicksNow() - drag_start_time_; | 71 MojoTimeTicks offset = GetTimeTicksNow() - drag_start_time_; |
72 float delta = static_cast<float>(offset) / 1000000.; | 72 float delta = static_cast<float>(offset) / 1000000.; |
73 cube_.SetFlingMultiplier( | 73 cube_.SetFlingMultiplier( |
74 CalculateDragDistance(capture_point_, event.location()), | 74 CalculateDragDistance(capture_point_, *event.location), |
75 delta); | 75 delta); |
76 | 76 |
77 capture_point_ = last_drag_point_ = gfx::PointF(); | 77 capture_point_ = last_drag_point_ = gfx::PointF(); |
78 RequestAnimationFrames(); | 78 RequestAnimationFrames(); |
79 } | 79 } |
80 break; | 80 break; |
81 default: | 81 default: |
82 break; | 82 break; |
83 } | 83 } |
84 } | 84 } |
(...skipping 27 matching lines...) Expand all Loading... |
112 last_time_ = GetTimeTicksNow(); | 112 last_time_ = GetTimeTicksNow(); |
113 } | 113 } |
114 | 114 |
115 void GLES2ClientImpl::CancelAnimationFrames() { | 115 void GLES2ClientImpl::CancelAnimationFrames() { |
116 getting_animation_frames_ = false; | 116 getting_animation_frames_ = false; |
117 MojoGLES2CancelAnimationFrames(context_); | 117 MojoGLES2CancelAnimationFrames(context_); |
118 } | 118 } |
119 | 119 |
120 } // namespace examples | 120 } // namespace examples |
121 } // namespace mojo | 121 } // namespace mojo |
OLD | NEW |