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

Side by Side Diff: mojo/services/native_viewport/native_viewport_service.cc

Issue 131153007: Send size to NativeViewportClient::OnCreated instead of GLES2Client::DidCreateContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix TODO Created 6 years, 11 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/services/native_viewport/native_viewport.mojom ('k') | no next file » | 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/services/native_viewport/native_viewport_service.h" 5 #include "mojo/services/native_viewport/native_viewport_service.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "mojo/services/gles2/gles2_impl.h" 9 #include "mojo/services/gles2/gles2_impl.h"
10 #include "mojo/services/native_viewport/native_viewport.h" 10 #include "mojo/services/native_viewport/native_viewport.h"
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 25
26 class NativeViewportService::NativeViewportImpl 26 class NativeViewportService::NativeViewportImpl
27 : public mojo::NativeViewport, 27 : public mojo::NativeViewport,
28 public NativeViewportDelegate { 28 public NativeViewportDelegate {
29 public: 29 public:
30 NativeViewportImpl(NativeViewportService* service, 30 NativeViewportImpl(NativeViewportService* service,
31 ScopedMessagePipeHandle client_handle) 31 ScopedMessagePipeHandle client_handle)
32 : service_(service), 32 : service_(service),
33 widget_(gfx::kNullAcceleratedWidget), 33 widget_(gfx::kNullAcceleratedWidget),
34 on_created_sent_(false),
34 waiting_for_event_ack_(false), 35 waiting_for_event_ack_(false),
35 pending_event_timestamp_(0), 36 pending_event_timestamp_(0),
36 client_(client_handle.Pass(), this) { 37 client_(client_handle.Pass(), this) {
37 } 38 }
38 virtual ~NativeViewportImpl() {} 39 virtual ~NativeViewportImpl() {}
39 40
40 virtual void Open() MOJO_OVERRIDE { 41 virtual void Open() MOJO_OVERRIDE {
41 native_viewport_ = 42 native_viewport_ =
42 services::NativeViewport::Create(service_->context_, this); 43 services::NativeViewport::Create(service_->context_, this);
43 native_viewport_->Init(); 44 native_viewport_->Init();
44 client_->OnCreated();
45 } 45 }
46 46
47 virtual void Close() MOJO_OVERRIDE { 47 virtual void Close() MOJO_OVERRIDE {
48 gles2_.reset(); 48 gles2_.reset();
49 DCHECK(native_viewport_); 49 DCHECK(native_viewport_);
50 native_viewport_->Close(); 50 native_viewport_->Close();
51 } 51 }
52 52
53 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) 53 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle)
54 MOJO_OVERRIDE { 54 MOJO_OVERRIDE {
55 gles2_.reset(new GLES2Impl(client_handle.Pass())); 55 gles2_.reset(new GLES2Impl(client_handle.Pass()));
56 CreateGLES2ContextIfNeeded(); 56 CreateGLES2ContextIfNeeded();
57 } 57 }
58 58
59 virtual void AckEvent(const Event& event) MOJO_OVERRIDE { 59 virtual void AckEvent(const Event& event) MOJO_OVERRIDE {
60 DCHECK_EQ(event.time_stamp(), pending_event_timestamp_); 60 DCHECK_EQ(event.time_stamp(), pending_event_timestamp_);
61 waiting_for_event_ack_ = false; 61 waiting_for_event_ack_ = false;
62 } 62 }
63 63
64 void CreateGLES2ContextIfNeeded() { 64 void CreateGLES2ContextIfNeeded() {
65 if (widget_ == gfx::kNullAcceleratedWidget || !gles2_) 65 if (!on_created_sent_ || !gles2_)
66 return; 66 return;
67 DCHECK(widget_ != gfx::kNullAcceleratedWidget);
67 gfx::Size size = native_viewport_->GetSize(); 68 gfx::Size size = native_viewport_->GetSize();
68 if (size.width() == 0 || size.height() == 0) 69 DCHECK(!size.IsEmpty());
69 return;
70 gles2_->CreateContext(widget_, size); 70 gles2_->CreateContext(widget_, size);
71 } 71 }
72 72
73 virtual bool OnEvent(ui::Event* ui_event) MOJO_OVERRIDE { 73 virtual bool OnEvent(ui::Event* ui_event) MOJO_OVERRIDE {
74 // Must not return early before updating capture. 74 // Must not return early before updating capture.
75 switch (ui_event->type()) { 75 switch (ui_event->type()) {
76 case ui::ET_MOUSE_PRESSED: 76 case ui::ET_MOUSE_PRESSED:
77 case ui::ET_TOUCH_PRESSED: 77 case ui::ET_TOUCH_PRESSED:
78 native_viewport_->SetCapture(); 78 native_viewport_->SetCapture();
79 break; 79 break;
(...skipping 29 matching lines...) Expand all
109 TouchData::Builder touch_data; 109 TouchData::Builder touch_data;
110 touch_data.set_pointer_id(touch_event->touch_id()); 110 touch_data.set_pointer_id(touch_event->touch_id());
111 event.set_touch_data(touch_data.Finish()); 111 event.set_touch_data(touch_data.Finish());
112 } 112 }
113 113
114 client_->OnEvent(event.Finish()); 114 client_->OnEvent(event.Finish());
115 waiting_for_event_ack_ = true; 115 waiting_for_event_ack_ = true;
116 return false; 116 return false;
117 } 117 }
118 118
119 void MaybeSendOnCreated() {
darin (slow to review) 2014/01/27 06:08:15 nit: A name like SendOnCreatedIfNeeded is a bit mo
piman 2014/01/27 22:10:24 Done.
120 if (widget_ == gfx::kNullAcceleratedWidget ||
121 on_created_sent_)
122 return;
123 gfx::Size size = native_viewport_->GetSize();
124 if (size.IsEmpty())
125 return;
126 on_created_sent_ = true;
127 client_->OnCreated(size.width(), size.height());
128 CreateGLES2ContextIfNeeded();
129 }
130
119 virtual void OnAcceleratedWidgetAvailable( 131 virtual void OnAcceleratedWidgetAvailable(
120 gfx::AcceleratedWidget widget) MOJO_OVERRIDE { 132 gfx::AcceleratedWidget widget) MOJO_OVERRIDE {
121 widget_ = widget; 133 widget_ = widget;
122 CreateGLES2ContextIfNeeded(); 134 MaybeSendOnCreated();
123 } 135 }
124 136
125 virtual void OnResized(const gfx::Size& size) MOJO_OVERRIDE { 137 virtual void OnResized(const gfx::Size& size) MOJO_OVERRIDE {
126 CreateGLES2ContextIfNeeded(); 138 MaybeSendOnCreated();
127 } 139 }
128 140
129 virtual void OnDestroyed() MOJO_OVERRIDE { 141 virtual void OnDestroyed() MOJO_OVERRIDE {
130 // TODO(beng): 142 // TODO(beng):
131 // Destroying |gles2_| on the shell thread here hits thread checker 143 // Destroying |gles2_| on the shell thread here hits thread checker
132 // asserts. All code must stop touching the AcceleratedWidget at this 144 // asserts. All code must stop touching the AcceleratedWidget at this
133 // point as it is dead after this call stack. jamesr said we probably 145 // point as it is dead after this call stack. jamesr said we probably
134 // should make our own GLSurface and simply tell it to stop touching the 146 // should make our own GLSurface and simply tell it to stop touching the
135 // AcceleratedWidget via Destroy() but we have no good way of doing that 147 // AcceleratedWidget via Destroy() but we have no good way of doing that
136 // right now given our current threading model so james' recommendation 148 // right now given our current threading model so james' recommendation
137 // was just to wait until after we move the gl service out of process. 149 // was just to wait until after we move the gl service out of process.
138 // gles2_.reset(); 150 // gles2_.reset();
139 client_->OnDestroyed(); 151 client_->OnDestroyed();
140 base::MessageLoop::current()->Quit(); 152 base::MessageLoop::current()->Quit();
141 } 153 }
142 154
143 private: 155 private:
144 NativeViewportService* service_; 156 NativeViewportService* service_;
145 gfx::AcceleratedWidget widget_; 157 gfx::AcceleratedWidget widget_;
146 scoped_ptr<services::NativeViewport> native_viewport_; 158 scoped_ptr<services::NativeViewport> native_viewport_;
147 scoped_ptr<GLES2Impl> gles2_; 159 scoped_ptr<GLES2Impl> gles2_;
160 bool on_created_sent_;
148 bool waiting_for_event_ack_; 161 bool waiting_for_event_ack_;
149 int64 pending_event_timestamp_; 162 int64 pending_event_timestamp_;
150 163
151 RemotePtr<NativeViewportClient> client_; 164 RemotePtr<NativeViewportClient> client_;
152 }; 165 };
153 166
154 NativeViewportService::NativeViewportService( 167 NativeViewportService::NativeViewportService(
155 ScopedMessagePipeHandle shell_handle) 168 ScopedMessagePipeHandle shell_handle)
156 : shell_(shell_handle.Pass(), this), 169 : shell_(shell_handle.Pass(), this),
157 context_(NULL) { 170 context_(NULL) {
(...skipping 24 matching lines...) Expand all
182 extern "C" MOJO_NATIVE_VIEWPORT_EXPORT MojoResult MojoMain( 195 extern "C" MOJO_NATIVE_VIEWPORT_EXPORT MojoResult MojoMain(
183 const MojoHandle shell_handle) { 196 const MojoHandle shell_handle) {
184 base::MessageLoopForUI loop; 197 base::MessageLoopForUI loop;
185 mojo::services::NativeViewportService app( 198 mojo::services::NativeViewportService app(
186 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); 199 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
187 base::MessageLoop::current()->Run(); 200 base::MessageLoop::current()->Run();
188 return MOJO_RESULT_OK; 201 return MOJO_RESULT_OK;
189 } 202 }
190 203
191 #endif // !OS_ANDROID 204 #endif // !OS_ANDROID
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport.mojom ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698