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

Side by Side Diff: mojo/examples/sample_app/gles2_client_impl.cc

Issue 131153007: Send size to NativeViewportClient::OnCreated instead of GLES2Client::DidCreateContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix various issues Created 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.h ('k') | mojo/examples/sample_app/sample_app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 10
11 #include "mojo/public/gles2/gles2.h" 11 #include "mojo/public/gles2/gles2.h"
12 #include "ui/events/event_constants.h" 12 #include "ui/events/event_constants.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 namespace examples { 15 namespace examples {
16 namespace { 16 namespace {
17 17
18 float CalculateDragDistance(const gfx::PointF& start, const Point& end) { 18 float CalculateDragDistance(const gfx::PointF& start, const Point& end) {
19 return hypot(start.x() - end.x(), start.y() - end.y()); 19 return hypot(start.x() - end.x(), start.y() - end.y());
20 } 20 }
21 21
22 } 22 }
23 23
24 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) 24 GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe)
25 : getting_animation_frames_(false) { 25 : getting_animation_frames_(false),
26 context_created_(false) {
26 context_ = MojoGLES2CreateContext( 27 context_ = MojoGLES2CreateContext(
27 pipe.release().value(), 28 pipe.release().value(),
28 &DidCreateContextThunk, 29 &DidCreateContextThunk,
29 &ContextLostThunk, 30 &ContextLostThunk,
30 &DrawAnimationFrameThunk, 31 &DrawAnimationFrameThunk,
31 this); 32 this);
32 } 33 }
33 34
34 GLES2ClientImpl::~GLES2ClientImpl() { 35 GLES2ClientImpl::~GLES2ClientImpl() {
35 MojoGLES2DestroyContext(context_); 36 MojoGLES2DestroyContext(context_);
36 } 37 }
37 38
39 void GLES2ClientImpl::SetSize(const Size& size) {
40 size_ = gfx::Size(size.width(), size.height());
41 InitializeCubeIfNeeded();
42 }
43
38 void GLES2ClientImpl::HandleInputEvent(const Event& event) { 44 void GLES2ClientImpl::HandleInputEvent(const Event& event) {
39 switch (event.action()) { 45 switch (event.action()) {
40 case ui::ET_MOUSE_PRESSED: 46 case ui::ET_MOUSE_PRESSED:
41 case ui::ET_TOUCH_PRESSED: 47 case ui::ET_TOUCH_PRESSED:
42 CancelAnimationFrames(); 48 CancelAnimationFrames();
43 capture_point_.SetPoint(event.location().x(), event.location().y()); 49 capture_point_.SetPoint(event.location().x(), event.location().y());
44 last_drag_point_ = capture_point_; 50 last_drag_point_ = capture_point_;
45 drag_start_time_ = GetTimeTicksNow(); 51 drag_start_time_ = GetTimeTicksNow();
46 break; 52 break;
47 case ui::ET_MOUSE_DRAGGED: 53 case ui::ET_MOUSE_DRAGGED:
(...skipping 20 matching lines...) Expand all
68 74
69 capture_point_ = last_drag_point_ = gfx::PointF(); 75 capture_point_ = last_drag_point_ = gfx::PointF();
70 RequestAnimationFrames(); 76 RequestAnimationFrames();
71 } 77 }
72 break; 78 break;
73 default: 79 default:
74 break; 80 break;
75 } 81 }
76 } 82 }
77 83
78 void GLES2ClientImpl::DidCreateContext(uint32_t width, 84 void GLES2ClientImpl::DidCreateContext() {
79 uint32_t height) {
80 MojoGLES2MakeCurrent(context_); 85 MojoGLES2MakeCurrent(context_);
86 context_created_ = true;
87 InitializeCubeIfNeeded();
88 }
81 89
82 cube_.Init(width, height); 90 void GLES2ClientImpl::InitializeCubeIfNeeded() {
91 if (size_.IsEmpty() || !context_created_)
92 return;
93 cube_.Init(size_.width(), size_.height());
83 RequestAnimationFrames(); 94 RequestAnimationFrames();
84 } 95 }
85 96
86 void GLES2ClientImpl::DidCreateContextThunk( 97 void GLES2ClientImpl::DidCreateContextThunk(void* closure) {
87 void* closure, 98 static_cast<GLES2ClientImpl*>(closure)->DidCreateContext();
88 uint32_t width,
89 uint32_t height) {
90 static_cast<GLES2ClientImpl*>(closure)->DidCreateContext(width, height);
91 } 99 }
92 100
93 void GLES2ClientImpl::ContextLost() { 101 void GLES2ClientImpl::ContextLost() {
94 CancelAnimationFrames(); 102 CancelAnimationFrames();
95 } 103 }
96 104
97 void GLES2ClientImpl::ContextLostThunk(void* closure) { 105 void GLES2ClientImpl::ContextLostThunk(void* closure) {
98 static_cast<GLES2ClientImpl*>(closure)->ContextLost(); 106 static_cast<GLES2ClientImpl*>(closure)->ContextLost();
99 } 107 }
100 108
(...skipping 18 matching lines...) Expand all
119 last_time_ = GetTimeTicksNow(); 127 last_time_ = GetTimeTicksNow();
120 } 128 }
121 129
122 void GLES2ClientImpl::CancelAnimationFrames() { 130 void GLES2ClientImpl::CancelAnimationFrames() {
123 getting_animation_frames_ = false; 131 getting_animation_frames_ = false;
124 MojoGLES2CancelAnimationFrames(context_); 132 MojoGLES2CancelAnimationFrames(context_);
125 } 133 }
126 134
127 } // namespace examples 135 } // namespace examples
128 } // namespace mojo 136 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/sample_app/gles2_client_impl.h ('k') | mojo/examples/sample_app/sample_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698