Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: examples/spinning_cube/gles2_client_impl.cc

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
18 #include "mojo/public/cpp/bindings/interface_handle.h"
17 #include "mojo/public/cpp/environment/environment.h" 19 #include "mojo/public/cpp/environment/environment.h"
18 #include "mojo/public/cpp/utility/run_loop.h" 20 #include "mojo/public/cpp/utility/run_loop.h"
19 21
20 namespace examples { 22 namespace examples {
21 namespace { 23 namespace {
22 24
23 // TODO(johngro) : investigate extending mojom with a formal flags type which it 25 // TODO(johngro) : investigate extending mojom with a formal flags type which it
24 // generates good bindings for, so we don't need to resort to this. 26 // generates good bindings for, so we don't need to resort to this.
25 static inline constexpr bool operator &(const mojo::EventFlags& f1, 27 static inline constexpr bool operator &(const mojo::EventFlags& f1,
26 const mojo::EventFlags& f2) { 28 const mojo::EventFlags& f2) {
(...skipping 22 matching lines...) Expand all
49 : (current.y - last.y); 51 : (current.y - last.y);
50 return delta > 0 ? -1 : 1; 52 return delta > 0 ? -1 : 1;
51 } 53 }
52 } // namespace 54 } // namespace
53 55
54 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider) 56 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider)
55 : last_time_(mojo::GetTimeTicksNow()), 57 : last_time_(mojo::GetTimeTicksNow()),
56 waiting_to_draw_(false), 58 waiting_to_draw_(false),
57 context_provider_(context_provider.Pass()), 59 context_provider_(context_provider.Pass()),
58 context_(nullptr) { 60 context_(nullptr) {
59 context_provider_->Create(nullptr, 61 context_provider_->Create(
60 [this](mojo::CommandBufferPtr command_buffer) { 62 nullptr,
61 ContextCreated(command_buffer.Pass()); 63 [this](mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) {
62 }); 64 ContextCreated(std::move(command_buffer));
65 });
63 } 66 }
64 67
65 GLES2ClientImpl::~GLES2ClientImpl() { 68 GLES2ClientImpl::~GLES2ClientImpl() {
66 MGLDestroyContext(context_); 69 MGLDestroyContext(context_);
67 } 70 }
68 71
69 void GLES2ClientImpl::SetSize(const mojo::Size& size) { 72 void GLES2ClientImpl::SetSize(const mojo::Size& size) {
70 size_ = size; 73 size_ = size;
71 cube_.set_size(size_.width, size_.height); 74 cube_.set_size(size_.width, size_.height);
72 if (size_.width == 0 || size_.height == 0 || !context_) 75 if (size_.width == 0 || size_.height == 0 || !context_)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 128
126 capture_point_ = last_drag_point_ = mojo::PointF(); 129 capture_point_ = last_drag_point_ = mojo::PointF();
127 WantToDraw(); 130 WantToDraw();
128 break; 131 break;
129 } 132 }
130 default: 133 default:
131 break; 134 break;
132 } 135 }
133 } 136 }
134 137
135 void GLES2ClientImpl::ContextCreated(mojo::CommandBufferPtr command_buffer) { 138 void GLES2ClientImpl::ContextCreated(
136 context_ = MGLCreateContext( 139 mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) {
137 MGL_API_VERSION_GLES2, 140 context_ = MGLCreateContext(MGL_API_VERSION_GLES2,
138 command_buffer.PassInterfaceHandle().PassHandle().release().value(), 141 command_buffer.PassHandle().release().value(),
139 MGL_NO_CONTEXT, &ContextLostThunk, this, 142 MGL_NO_CONTEXT, &ContextLostThunk, this,
140 mojo::Environment::GetDefaultAsyncWaiter()); 143 mojo::Environment::GetDefaultAsyncWaiter());
141 MGLMakeCurrent(context_); 144 MGLMakeCurrent(context_);
142 cube_.Init(); 145 cube_.Init();
143 WantToDraw(); 146 WantToDraw();
144 } 147 }
145 148
146 void GLES2ClientImpl::ContextLost() { 149 void GLES2ClientImpl::ContextLost() {
147 cube_.OnGLContextLost(); 150 cube_.OnGLContextLost();
148 MGLDestroyContext(context_); 151 MGLDestroyContext(context_);
149 context_ = nullptr; 152 context_ = nullptr;
150 context_provider_->Create(nullptr, 153 context_provider_->Create(
151 [this](mojo::CommandBufferPtr command_buffer) { 154 nullptr,
152 ContextCreated(command_buffer.Pass()); 155 [this](mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer) {
153 }); 156 ContextCreated(std::move(command_buffer));
157 });
154 } 158 }
155 159
156 void GLES2ClientImpl::ContextLostThunk(void* closure) { 160 void GLES2ClientImpl::ContextLostThunk(void* closure) {
157 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); 161 static_cast<GLES2ClientImpl*>(closure)->ContextLost();
158 } 162 }
159 163
160 void GLES2ClientImpl::WantToDraw() { 164 void GLES2ClientImpl::WantToDraw() {
161 if (waiting_to_draw_ || !context_) 165 if (waiting_to_draw_ || !context_)
162 return; 166 return;
163 waiting_to_draw_ = true; 167 waiting_to_draw_ = true;
(...skipping 10 matching lines...) Expand all
174 float delta = static_cast<float>(offset) / 1000000.; 178 float delta = static_cast<float>(offset) / 1000000.;
175 last_time_ = now; 179 last_time_ = now;
176 cube_.UpdateForTimeDelta(delta); 180 cube_.UpdateForTimeDelta(delta);
177 cube_.Draw(); 181 cube_.Draw();
178 182
179 MGLSwapBuffers(); 183 MGLSwapBuffers();
180 WantToDraw(); 184 WantToDraw();
181 } 185 }
182 186
183 } // namespace examples 187 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698