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 #ifndef GL_GLEXT_PROTOTYPES | 5 #ifndef GL_GLEXT_PROTOTYPES |
6 #define GL_GLEXT_PROTOTYPES | 6 #define GL_GLEXT_PROTOTYPES |
7 #endif | 7 #endif |
8 | 8 |
9 #include "examples/spinning_cube/gles2_client_impl.h" | 9 #include "examples/spinning_cube/gles2_client_impl.h" |
10 | 10 |
11 #include <math.h> | 11 #include <math.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <cmath> | 13 #include <cmath> |
| 14 #include <utility> |
14 | 15 |
15 #include "mojo/public/c/gpu/MGL/mgl.h" | 16 #include "mojo/public/c/gpu/MGL/mgl.h" |
16 #include "mojo/public/c/gpu/MGL/mgl_onscreen.h" | 17 #include "mojo/public/c/gpu/MGL/mgl_onscreen.h" |
17 #include "mojo/public/cpp/environment/environment.h" | 18 #include "mojo/public/cpp/environment/environment.h" |
18 #include "mojo/public/cpp/utility/run_loop.h" | 19 #include "mojo/public/cpp/utility/run_loop.h" |
19 | 20 |
20 namespace examples { | 21 namespace examples { |
21 namespace { | 22 namespace { |
22 | 23 |
23 // TODO(johngro) : investigate extending mojom with a formal flags type which it | 24 // TODO(johngro) : investigate extending mojom with a formal flags type which it |
(...skipping 25 matching lines...) Expand all Loading... |
49 : (current.y - last.y); | 50 : (current.y - last.y); |
50 return delta > 0 ? -1 : 1; | 51 return delta > 0 ? -1 : 1; |
51 } | 52 } |
52 } // namespace | 53 } // namespace |
53 | 54 |
54 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider) | 55 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider) |
55 : last_time_(mojo::GetTimeTicksNow()), | 56 : last_time_(mojo::GetTimeTicksNow()), |
56 waiting_to_draw_(false), | 57 waiting_to_draw_(false), |
57 context_provider_(context_provider.Pass()), | 58 context_provider_(context_provider.Pass()), |
58 context_(nullptr) { | 59 context_(nullptr) { |
59 context_provider_->Create(nullptr, | 60 context_provider_->Create( |
60 [this](mojo::CommandBufferPtr command_buffer) { | 61 nullptr, |
61 ContextCreated(command_buffer.Pass()); | 62 [this](mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) { |
62 }); | 63 ContextCreated(std::move(command_buffer)); |
| 64 }); |
63 } | 65 } |
64 | 66 |
65 GLES2ClientImpl::~GLES2ClientImpl() { | 67 GLES2ClientImpl::~GLES2ClientImpl() { |
66 MGLDestroyContext(context_); | 68 MGLDestroyContext(context_); |
67 } | 69 } |
68 | 70 |
69 void GLES2ClientImpl::SetSize(const mojo::Size& size) { | 71 void GLES2ClientImpl::SetSize(const mojo::Size& size) { |
70 size_ = size; | 72 size_ = size; |
71 cube_.set_size(size_.width, size_.height); | 73 cube_.set_size(size_.width, size_.height); |
72 if (size_.width == 0 || size_.height == 0 || !context_) | 74 if (size_.width == 0 || size_.height == 0 || !context_) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 127 |
126 capture_point_ = last_drag_point_ = mojo::PointF(); | 128 capture_point_ = last_drag_point_ = mojo::PointF(); |
127 WantToDraw(); | 129 WantToDraw(); |
128 break; | 130 break; |
129 } | 131 } |
130 default: | 132 default: |
131 break; | 133 break; |
132 } | 134 } |
133 } | 135 } |
134 | 136 |
135 void GLES2ClientImpl::ContextCreated(mojo::CommandBufferPtr command_buffer) { | 137 void GLES2ClientImpl::ContextCreated( |
136 context_ = MGLCreateContext( | 138 mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) { |
137 MGL_API_VERSION_GLES2, | 139 context_ = MGLCreateContext(MGL_API_VERSION_GLES2, |
138 command_buffer.PassInterfaceHandle().PassHandle().release().value(), | 140 command_buffer.PassHandle().release().value(), |
139 MGL_NO_CONTEXT, &ContextLostThunk, this, | 141 MGL_NO_CONTEXT, &ContextLostThunk, this, |
140 mojo::Environment::GetDefaultAsyncWaiter()); | 142 mojo::Environment::GetDefaultAsyncWaiter()); |
141 MGLMakeCurrent(context_); | 143 MGLMakeCurrent(context_); |
142 cube_.Init(); | 144 cube_.Init(); |
143 WantToDraw(); | 145 WantToDraw(); |
144 } | 146 } |
145 | 147 |
146 void GLES2ClientImpl::ContextLost() { | 148 void GLES2ClientImpl::ContextLost() { |
147 cube_.OnGLContextLost(); | 149 cube_.OnGLContextLost(); |
148 MGLDestroyContext(context_); | 150 MGLDestroyContext(context_); |
149 context_ = nullptr; | 151 context_ = nullptr; |
150 context_provider_->Create(nullptr, | 152 context_provider_->Create( |
151 [this](mojo::CommandBufferPtr command_buffer) { | 153 nullptr, |
152 ContextCreated(command_buffer.Pass()); | 154 [this](mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) { |
153 }); | 155 ContextCreated(std::move(command_buffer)); |
| 156 }); |
154 } | 157 } |
155 | 158 |
156 void GLES2ClientImpl::ContextLostThunk(void* closure) { | 159 void GLES2ClientImpl::ContextLostThunk(void* closure) { |
157 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); | 160 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); |
158 } | 161 } |
159 | 162 |
160 void GLES2ClientImpl::WantToDraw() { | 163 void GLES2ClientImpl::WantToDraw() { |
161 if (waiting_to_draw_ || !context_) | 164 if (waiting_to_draw_ || !context_) |
162 return; | 165 return; |
163 waiting_to_draw_ = true; | 166 waiting_to_draw_ = true; |
(...skipping 10 matching lines...) Expand all Loading... |
174 float delta = static_cast<float>(offset) / 1000000.; | 177 float delta = static_cast<float>(offset) / 1000000.; |
175 last_time_ = now; | 178 last_time_ = now; |
176 cube_.UpdateForTimeDelta(delta); | 179 cube_.UpdateForTimeDelta(delta); |
177 cube_.Draw(); | 180 cube_.Draw(); |
178 | 181 |
179 MGLSwapBuffers(); | 182 MGLSwapBuffers(); |
180 WantToDraw(); | 183 WantToDraw(); |
181 } | 184 } |
182 | 185 |
183 } // namespace examples | 186 } // namespace examples |
OLD | NEW |