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/sample_gles2_delegate.h" | 5 #include "mojo/examples/sample_app/sample_gles2_delegate.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace examples { | 12 namespace examples { |
13 | 13 |
14 SampleGLES2Delegate::SampleGLES2Delegate() | 14 SampleGLES2Delegate::SampleGLES2Delegate() |
15 : gl_(NULL) { | 15 : gl_(NULL) { |
16 } | 16 } |
17 | 17 |
18 SampleGLES2Delegate::~SampleGLES2Delegate() { | 18 SampleGLES2Delegate::~SampleGLES2Delegate() { |
19 } | 19 } |
20 | 20 |
21 void SampleGLES2Delegate::DidCreateContext( | 21 void SampleGLES2Delegate::DidCreateContext( |
22 GLES2* gl, uint32_t width, uint32_t height) { | 22 GLES2ClientImpl* gl, uint32_t width, uint32_t height) { |
23 gl_ = gl; | 23 gl_ = gl; |
24 cube_.Init(width, height); | 24 cube_.Init(width, height); |
25 last_time_ = base::Time::Now(); | 25 last_time_ = base::Time::Now(); |
26 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), | 26 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), |
27 this, &SampleGLES2Delegate::Draw); | 27 this, &SampleGLES2Delegate::Draw); |
28 } | 28 } |
29 | 29 |
30 void SampleGLES2Delegate::Draw() { | 30 void SampleGLES2Delegate::Draw() { |
31 base::Time now = base::Time::Now(); | 31 base::Time now = base::Time::Now(); |
32 base::TimeDelta offset = now - last_time_; | 32 base::TimeDelta offset = now - last_time_; |
33 last_time_ = now; | 33 last_time_ = now; |
34 cube_.Update(offset.InSecondsF()); | 34 cube_.Update(offset.InSecondsF()); |
35 cube_.Draw(); | 35 cube_.Draw(); |
36 gl_->SwapBuffers(); | 36 gl_->SwapBuffers(); |
37 } | 37 } |
38 | 38 |
39 void SampleGLES2Delegate::ContextLost(GLES2* gl) { | 39 void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) { |
| 40 gl_ = NULL; |
40 timer_.Stop(); | 41 timer_.Stop(); |
41 gl_ = NULL; | |
42 } | 42 } |
43 | 43 |
44 } // namespace examples | 44 } // namespace examples |
45 } // namespace mojo | 45 } // namespace mojo |
OLD | NEW |