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

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

Issue 1288583002: Add MGL entry points and port spinning_cube to use them (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix android build Created 5 years, 4 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 <GLES2/gl2.h>
12 #include <GLES2/gl2ext.h>
13 #include <GLES2/gl2extchromium.h>
14 #include <math.h> 11 #include <math.h>
15 #include <stdlib.h> 12 #include <stdlib.h>
16 13
17 #include "mojo/public/c/gles2/gles2.h" 14 #include "mojo/public/c/gpu/MGL/mgl.h"
15 #include "mojo/public/c/gpu/MGL/mgl_onscreen.h"
18 #include "mojo/public/cpp/environment/environment.h" 16 #include "mojo/public/cpp/environment/environment.h"
19 #include "mojo/public/cpp/utility/run_loop.h" 17 #include "mojo/public/cpp/utility/run_loop.h"
20 18
21 namespace examples { 19 namespace examples {
22 namespace { 20 namespace {
23 21
24 float CalculateDragDistance(const mojo::PointF& start, 22 float CalculateDragDistance(const mojo::PointF& start,
25 const mojo::PointF& end) { 23 const mojo::PointF& end) {
26 return hypot(start.x - end.x, start.y - end.y); 24 return hypot(start.x - end.x, start.y - end.y);
27 } 25 }
28 26
29 float GetRandomColor() { 27 float GetRandomColor() {
30 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX); 28 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
31 } 29 }
32 30
33 } // namespace 31 } // namespace
34 32
35 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider) 33 GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider)
36 : last_time_(mojo::GetTimeTicksNow()), 34 : last_time_(mojo::GetTimeTicksNow()),
37 waiting_to_draw_(false), 35 waiting_to_draw_(false),
38 context_provider_(context_provider.Pass()), 36 context_provider_(context_provider.Pass()),
39 context_(nullptr) { 37 context_(nullptr) {
40 context_provider_->Create(nullptr, 38 context_provider_->Create(nullptr,
41 [this](mojo::CommandBufferPtr command_buffer) { 39 [this](mojo::CommandBufferPtr command_buffer) {
42 ContextCreated(command_buffer.Pass()); 40 ContextCreated(command_buffer.Pass());
43 }); 41 });
44 } 42 }
45 43
46 GLES2ClientImpl::~GLES2ClientImpl() { 44 GLES2ClientImpl::~GLES2ClientImpl() {
47 MojoGLES2DestroyContext(context_); 45 MGLDestroyContext(context_);
48 } 46 }
49 47
50 void GLES2ClientImpl::SetSize(const mojo::Size& size) { 48 void GLES2ClientImpl::SetSize(const mojo::Size& size) {
51 size_ = size; 49 size_ = size;
52 cube_.set_size(size_.width, size_.height); 50 cube_.set_size(size_.width, size_.height);
53 if (size_.width == 0 || size_.height == 0 || !context_) 51 if (size_.width == 0 || size_.height == 0 || !context_)
54 return; 52 return;
55 glResizeCHROMIUM(size_.width, size_.height, 1.f); 53 MGLResizeSurface(size_.width, size_.height);
56 WantToDraw(); 54 WantToDraw();
57 } 55 }
58 56
59 void GLES2ClientImpl::HandleInputEvent(const mojo::Event& event) { 57 void GLES2ClientImpl::HandleInputEvent(const mojo::Event& event) {
60 switch (event.action) { 58 switch (event.action) {
61 case mojo::EVENT_TYPE_POINTER_DOWN: 59 case mojo::EVENT_TYPE_POINTER_DOWN:
62 if (event.flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON) 60 if (event.flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON)
63 break; 61 break;
64 capture_point_.x = event.pointer_data->x; 62 capture_point_.x = event.pointer_data->x;
65 capture_point_.y = event.pointer_data->y; 63 capture_point_.y = event.pointer_data->y;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 capture_point_ = last_drag_point_ = mojo::PointF(); 98 capture_point_ = last_drag_point_ = mojo::PointF();
101 WantToDraw(); 99 WantToDraw();
102 break; 100 break;
103 } 101 }
104 default: 102 default:
105 break; 103 break;
106 } 104 }
107 } 105 }
108 106
109 void GLES2ClientImpl::ContextCreated(mojo::CommandBufferPtr command_buffer) { 107 void GLES2ClientImpl::ContextCreated(mojo::CommandBufferPtr command_buffer) {
110 context_ = MojoGLES2CreateContext( 108 context_ = MGLCreateContext(
109 MGL_API_VERSION_GLES2,
111 command_buffer.PassInterface().PassHandle().release().value(), 110 command_buffer.PassInterface().PassHandle().release().value(),
112 &ContextLostThunk, this, mojo::Environment::GetDefaultAsyncWaiter()); 111 MGL_NO_CONTEXT, &ContextLostThunk, this,
113 MojoGLES2MakeCurrent(context_); 112 mojo::Environment::GetDefaultAsyncWaiter());
113 MGLMakeCurrent(context_);
114 cube_.Init(); 114 cube_.Init();
115 WantToDraw(); 115 WantToDraw();
116 } 116 }
117 117
118 void GLES2ClientImpl::ContextLost() { 118 void GLES2ClientImpl::ContextLost() {
119 cube_.OnGLContextLost(); 119 cube_.OnGLContextLost();
120 MojoGLES2DestroyContext(context_); 120 MGLDestroyContext(context_);
121 context_ = nullptr; 121 context_ = nullptr;
122 context_provider_->Create(nullptr, 122 context_provider_->Create(nullptr,
123 [this](mojo::CommandBufferPtr command_buffer) { 123 [this](mojo::CommandBufferPtr command_buffer) {
124 ContextCreated(command_buffer.Pass()); 124 ContextCreated(command_buffer.Pass());
125 }); 125 });
126 } 126 }
127 127
128 void GLES2ClientImpl::ContextLostThunk(void* closure) { 128 void GLES2ClientImpl::ContextLostThunk(void* closure) {
129 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); 129 static_cast<GLES2ClientImpl*>(closure)->ContextLost();
130 } 130 }
(...skipping 10 matching lines...) Expand all
141 waiting_to_draw_ = false; 141 waiting_to_draw_ = false;
142 if (!context_) 142 if (!context_)
143 return; 143 return;
144 MojoTimeTicks now = mojo::GetTimeTicksNow(); 144 MojoTimeTicks now = mojo::GetTimeTicksNow();
145 MojoTimeTicks offset = now - last_time_; 145 MojoTimeTicks offset = now - last_time_;
146 float delta = static_cast<float>(offset) / 1000000.; 146 float delta = static_cast<float>(offset) / 1000000.;
147 last_time_ = now; 147 last_time_ = now;
148 cube_.UpdateForTimeDelta(delta); 148 cube_.UpdateForTimeDelta(delta);
149 cube_.Draw(); 149 cube_.Draw();
150 150
151 MojoGLES2SwapBuffers(); 151 MGLSwapBuffers();
152 WantToDraw(); 152 WantToDraw();
153 } 153 }
154 154
155 } // namespace examples 155 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698