diff options
Diffstat (limited to 'mojo')
-rw-r--r-- | mojo/public/cpp/bindings/callback.h | 32 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/callback.h.pump | 4 | ||||
-rw-r--r-- | mojo/public/cpp/bindings/lib/shared_ptr.h | 4 | ||||
-rw-r--r-- | mojo/services/native_viewport/native_viewport_impl.cc | 26 | ||||
-rw-r--r-- | mojo/services/native_viewport/native_viewport_impl.h | 2 | ||||
-rw-r--r-- | mojo/services/public/interfaces/native_viewport/native_viewport.mojom | 3 |
6 files changed, 64 insertions, 7 deletions
diff --git a/mojo/public/cpp/bindings/callback.h b/mojo/public/cpp/bindings/callback.h index 1486776..0cd4924 100644 --- a/mojo/public/cpp/bindings/callback.h +++ b/mojo/public/cpp/bindings/callback.h @@ -47,6 +47,10 @@ class Callback<void()> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -86,6 +90,10 @@ class Callback<void(A1)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -133,6 +141,10 @@ class Callback<void(A1, A2)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -187,6 +199,10 @@ class Callback<void(A1, A2, A3)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -246,6 +262,10 @@ class Callback<void(A1, A2, A3, A4)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -310,6 +330,10 @@ class Callback<void(A1, A2, A3, A4, A5)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -380,6 +404,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { @@ -455,6 +483,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6, A7)> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { diff --git a/mojo/public/cpp/bindings/callback.h.pump b/mojo/public/cpp/bindings/callback.h.pump index 8d7f728..856e85b 100644 --- a/mojo/public/cpp/bindings/callback.h.pump +++ b/mojo/public/cpp/bindings/callback.h.pump @@ -63,6 +63,10 @@ class Callback<void($for ARG , [[A$(ARG)]])> { return !sink_.get(); } + void reset() { + sink_.reset(); + } + private: template <typename Sink> struct Adapter : public Runnable { diff --git a/mojo/public/cpp/bindings/lib/shared_ptr.h b/mojo/public/cpp/bindings/lib/shared_ptr.h index ad22bfb..899e792 100644 --- a/mojo/public/cpp/bindings/lib/shared_ptr.h +++ b/mojo/public/cpp/bindings/lib/shared_ptr.h @@ -31,6 +31,10 @@ class SharedPtr { return impl_.value().ptr; } + void reset() { + impl_.reset(); + } + P* operator->() { return get(); } const P* operator->() const { return get(); } diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc index 6aba9ab..3006612 100644 --- a/mojo/services/native_viewport/native_viewport_impl.cc +++ b/mojo/services/native_viewport/native_viewport_impl.cc @@ -4,6 +4,7 @@ #include "mojo/services/native_viewport/native_viewport_impl.h" +#include "base/auto_reset.h" #include "base/bind.h" #include "base/macros.h" #include "base/message_loop/message_loop.h" @@ -48,13 +49,12 @@ NativeViewportImpl::~NativeViewportImpl() { void NativeViewportImpl::Create(SizePtr size, const Callback<void(uint64_t)>& callback) { create_callback_ = callback; + size_ = size.To<gfx::Size>(); if (is_headless_) platform_viewport_ = PlatformViewportHeadless::Create(this); else platform_viewport_ = PlatformViewport::Create(this); - const gfx::Rect bounds(gfx::Rect(size.To<gfx::Size>())); - platform_viewport_->Init(bounds); - OnBoundsChanged(bounds); + platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); } void NativeViewportImpl::Show() { @@ -94,10 +94,14 @@ void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { } void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { + if (size_ == bounds.size()) + return; + size_ = bounds.size(); - client()->OnSizeChanged(Size::From(size_)); - if (viewport_surface_) - viewport_surface_->SetSize(size_); + + // Wait for the accelerated widget before telling the client of the bounds. + if (create_callback_.is_null()) + ProcessOnBoundsChanged(); } void NativeViewportImpl::OnAcceleratedWidgetAvailable( @@ -105,6 +109,10 @@ void NativeViewportImpl::OnAcceleratedWidgetAvailable( widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); // TODO(jamesr): Remove once everything is converted to surfaces. create_callback_.Run(widget_id_); + create_callback_.reset(); + // Immediately tell the client of the size. The size may be wrong, if so we'll + // get the right one in the next OnBoundsChanged() call. + ProcessOnBoundsChanged(); if (viewport_surface_) viewport_surface_->SetWidgetId(widget_id_); } @@ -142,5 +150,11 @@ void NativeViewportImpl::AckEvent() { waiting_for_event_ack_ = false; } +void NativeViewportImpl::ProcessOnBoundsChanged() { + client()->OnSizeChanged(Size::From(size_)); + if (viewport_surface_) + viewport_surface_->SetSize(size_); +} + } // namespace mojo diff --git a/mojo/services/native_viewport/native_viewport_impl.h b/mojo/services/native_viewport/native_viewport_impl.h index 82f38a9..ad8e5c4 100644 --- a/mojo/services/native_viewport/native_viewport_impl.h +++ b/mojo/services/native_viewport/native_viewport_impl.h @@ -46,6 +46,8 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>, void AckEvent(); private: + void ProcessOnBoundsChanged(); + bool is_headless_; scoped_ptr<PlatformViewport> platform_viewport_; scoped_ptr<ViewportSurface> viewport_surface_; diff --git a/mojo/services/public/interfaces/native_viewport/native_viewport.mojom b/mojo/services/public/interfaces/native_viewport/native_viewport.mojom index 0a68532..6f05b72 100644 --- a/mojo/services/public/interfaces/native_viewport/native_viewport.mojom +++ b/mojo/services/public/interfaces/native_viewport/native_viewport.mojom @@ -13,7 +13,6 @@ module mojo { interface NativeViewport { // TODO(sky): having a create function is awkward. Should there be a factory // to create the NativeViewport that takes the size? - // TODO(sky): callback should take size too. Create(Size size) => (uint64 native_viewport_id); Show(); Hide(); @@ -23,6 +22,8 @@ interface NativeViewport { }; interface NativeViewportClient { + // OnSizeChanged() is sent at least once after the callback from Create() is + // called. OnSizeChanged(Size size); OnDestroyed(); OnEvent(Event event) => (); |