Chromium Code Reviews| Index: mojo/services/native_viewport/native_viewport_service.cc |
| diff --git a/mojo/services/native_viewport/native_viewport_service.cc b/mojo/services/native_viewport/native_viewport_service.cc |
| index 4a375ea27134834773d30d9376fb2b5a58eefc43..b3bd629feea9ccf4264445ed7f9b4d0f7d1603ec 100644 |
| --- a/mojo/services/native_viewport/native_viewport_service.cc |
| +++ b/mojo/services/native_viewport/native_viewport_service.cc |
| @@ -31,6 +31,7 @@ class NativeViewportService::NativeViewportImpl |
| ScopedMessagePipeHandle client_handle) |
| : service_(service), |
| widget_(gfx::kNullAcceleratedWidget), |
| + on_created_sent_(false), |
| waiting_for_event_ack_(false), |
| pending_event_timestamp_(0), |
| client_(client_handle.Pass(), this) { |
| @@ -41,7 +42,6 @@ class NativeViewportService::NativeViewportImpl |
| native_viewport_ = |
| services::NativeViewport::Create(service_->context_, this); |
| native_viewport_->Init(); |
| - client_->OnCreated(); |
| } |
| virtual void Close() MOJO_OVERRIDE { |
| @@ -62,11 +62,11 @@ class NativeViewportService::NativeViewportImpl |
| } |
| void CreateGLES2ContextIfNeeded() { |
| - if (widget_ == gfx::kNullAcceleratedWidget || !gles2_) |
| + if (!on_created_sent_ || !gles2_) |
| return; |
| + DCHECK(widget_ != gfx::kNullAcceleratedWidget); |
| gfx::Size size = native_viewport_->GetSize(); |
| - if (size.width() == 0 || size.height() == 0) |
| - return; |
| + DCHECK(!size.IsEmpty()); |
| gles2_->CreateContext(widget_, size); |
| } |
| @@ -116,14 +116,26 @@ class NativeViewportService::NativeViewportImpl |
| return false; |
| } |
| + 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.
|
| + if (widget_ == gfx::kNullAcceleratedWidget || |
| + on_created_sent_) |
| + return; |
| + gfx::Size size = native_viewport_->GetSize(); |
| + if (size.IsEmpty()) |
| + return; |
| + on_created_sent_ = true; |
| + client_->OnCreated(size.width(), size.height()); |
| + CreateGLES2ContextIfNeeded(); |
| + } |
| + |
| virtual void OnAcceleratedWidgetAvailable( |
| gfx::AcceleratedWidget widget) MOJO_OVERRIDE { |
| widget_ = widget; |
| - CreateGLES2ContextIfNeeded(); |
| + MaybeSendOnCreated(); |
| } |
| virtual void OnResized(const gfx::Size& size) MOJO_OVERRIDE { |
| - CreateGLES2ContextIfNeeded(); |
| + MaybeSendOnCreated(); |
| } |
| virtual void OnDestroyed() MOJO_OVERRIDE { |
| @@ -145,6 +157,7 @@ class NativeViewportService::NativeViewportImpl |
| gfx::AcceleratedWidget widget_; |
| scoped_ptr<services::NativeViewport> native_viewport_; |
| scoped_ptr<GLES2Impl> gles2_; |
| + bool on_created_sent_; |
| bool waiting_for_event_ack_; |
| int64 pending_event_timestamp_; |