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 #include <stdlib.h> |
11 | 11 |
12 #include "mojo/public/c/gles2/gles2.h" | 12 #include "mojo/public/c/gles2/gles2.h" |
| 13 #include "mojo/public/cpp/environment/environment.h" |
13 #include "mojo/public/cpp/utility/run_loop.h" | 14 #include "mojo/public/cpp/utility/run_loop.h" |
14 | 15 |
15 namespace examples { | 16 namespace examples { |
16 namespace { | 17 namespace { |
17 | 18 |
18 float CalculateDragDistance(const mojo::Point& start, const mojo::Point& end) { | 19 float CalculateDragDistance(const mojo::Point& start, const mojo::Point& end) { |
19 return hypot(static_cast<float>(start.x - end.x), | 20 return hypot(static_cast<float>(start.x - end.x), |
20 static_cast<float>(start.y - end.y)); | 21 static_cast<float>(start.y - end.y)); |
21 } | 22 } |
22 | 23 |
23 float GetRandomColor() { | 24 float GetRandomColor() { |
24 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX); | 25 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX); |
25 } | 26 } |
26 | 27 |
27 } | 28 } |
28 | 29 |
29 GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer) | 30 GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer) |
30 : last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) { | 31 : last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) { |
31 context_ = MojoGLES2CreateContext( | 32 context_ = |
32 command_buffer.PassMessagePipe().release().value(), | 33 MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(), |
33 &ContextLostThunk, | 34 &ContextLostThunk, |
34 this); | 35 this, |
| 36 mojo::Environment::GetDefaultAsyncWaiter()); |
35 MojoGLES2MakeCurrent(context_); | 37 MojoGLES2MakeCurrent(context_); |
36 } | 38 } |
37 | 39 |
38 GLES2ClientImpl::~GLES2ClientImpl() { | 40 GLES2ClientImpl::~GLES2ClientImpl() { |
39 MojoGLES2DestroyContext(context_); | 41 MojoGLES2DestroyContext(context_); |
40 } | 42 } |
41 | 43 |
42 void GLES2ClientImpl::SetSize(const mojo::Size& size) { | 44 void GLES2ClientImpl::SetSize(const mojo::Size& size) { |
43 size_ = size; | 45 size_ = size; |
44 if (size_.width == 0 || size_.height == 0) | 46 if (size_.width == 0 || size_.height == 0) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 float delta = static_cast<float>(offset) / 1000000.; | 127 float delta = static_cast<float>(offset) / 1000000.; |
126 last_time_ = now; | 128 last_time_ = now; |
127 cube_.UpdateForTimeDelta(delta); | 129 cube_.UpdateForTimeDelta(delta); |
128 cube_.Draw(); | 130 cube_.Draw(); |
129 | 131 |
130 MojoGLES2SwapBuffers(); | 132 MojoGLES2SwapBuffers(); |
131 WantToDraw(); | 133 WantToDraw(); |
132 } | 134 } |
133 | 135 |
134 } // namespace examples | 136 } // namespace examples |
OLD | NEW |