Commit 5b19be3a authored by sky's avatar sky Committed by Commit bot

Makes NativeViewport send OnBoundsChanged() after widget available

It was possible for us to send it before.

BUG=none
TEST=none
R=ben@chromium.org, darin@chromium.org

Review URL: https://codereview.chromium.org/617513003

Cr-Commit-Position: refs/heads/master@{#297472}
parent e650b32b
...@@ -47,6 +47,10 @@ class Callback<void()> { ...@@ -47,6 +47,10 @@ class Callback<void()> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -86,6 +90,10 @@ class Callback<void(A1)> { ...@@ -86,6 +90,10 @@ class Callback<void(A1)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -133,6 +141,10 @@ class Callback<void(A1, A2)> { ...@@ -133,6 +141,10 @@ class Callback<void(A1, A2)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -187,6 +199,10 @@ class Callback<void(A1, A2, A3)> { ...@@ -187,6 +199,10 @@ class Callback<void(A1, A2, A3)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -246,6 +262,10 @@ class Callback<void(A1, A2, A3, A4)> { ...@@ -246,6 +262,10 @@ class Callback<void(A1, A2, A3, A4)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -310,6 +330,10 @@ class Callback<void(A1, A2, A3, A4, A5)> { ...@@ -310,6 +330,10 @@ class Callback<void(A1, A2, A3, A4, A5)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -380,6 +404,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6)> { ...@@ -380,6 +404,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
...@@ -455,6 +483,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6, A7)> { ...@@ -455,6 +483,10 @@ class Callback<void(A1, A2, A3, A4, A5, A6, A7)> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
......
...@@ -63,6 +63,10 @@ class Callback<void($for ARG , [[A$(ARG)]])> { ...@@ -63,6 +63,10 @@ class Callback<void($for ARG , [[A$(ARG)]])> {
return !sink_.get(); return !sink_.get();
} }
void reset() {
sink_.reset();
}
private: private:
template <typename Sink> template <typename Sink>
struct Adapter : public Runnable { struct Adapter : public Runnable {
......
...@@ -31,6 +31,10 @@ class SharedPtr { ...@@ -31,6 +31,10 @@ class SharedPtr {
return impl_.value().ptr; return impl_.value().ptr;
} }
void reset() {
impl_.reset();
}
P* operator->() { return get(); } P* operator->() { return get(); }
const P* operator->() const { return get(); } const P* operator->() const { return get(); }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "mojo/services/native_viewport/native_viewport_impl.h" #include "mojo/services/native_viewport/native_viewport_impl.h"
#include "base/auto_reset.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
...@@ -48,13 +49,12 @@ NativeViewportImpl::~NativeViewportImpl() { ...@@ -48,13 +49,12 @@ NativeViewportImpl::~NativeViewportImpl() {
void NativeViewportImpl::Create(SizePtr size, void NativeViewportImpl::Create(SizePtr size,
const Callback<void(uint64_t)>& callback) { const Callback<void(uint64_t)>& callback) {
create_callback_ = callback; create_callback_ = callback;
size_ = size.To<gfx::Size>();
if (is_headless_) if (is_headless_)
platform_viewport_ = PlatformViewportHeadless::Create(this); platform_viewport_ = PlatformViewportHeadless::Create(this);
else else
platform_viewport_ = PlatformViewport::Create(this); platform_viewport_ = PlatformViewport::Create(this);
const gfx::Rect bounds(gfx::Rect(size.To<gfx::Size>())); platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>()));
platform_viewport_->Init(bounds);
OnBoundsChanged(bounds);
} }
void NativeViewportImpl::Show() { void NativeViewportImpl::Show() {
...@@ -94,10 +94,14 @@ void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { ...@@ -94,10 +94,14 @@ void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) {
} }
void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) {
if (size_ == bounds.size())
return;
size_ = bounds.size(); size_ = bounds.size();
client()->OnSizeChanged(Size::From(size_));
if (viewport_surface_) // Wait for the accelerated widget before telling the client of the bounds.
viewport_surface_->SetSize(size_); if (create_callback_.is_null())
ProcessOnBoundsChanged();
} }
void NativeViewportImpl::OnAcceleratedWidgetAvailable( void NativeViewportImpl::OnAcceleratedWidgetAvailable(
...@@ -105,6 +109,10 @@ void NativeViewportImpl::OnAcceleratedWidgetAvailable( ...@@ -105,6 +109,10 @@ void NativeViewportImpl::OnAcceleratedWidgetAvailable(
widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget));
// TODO(jamesr): Remove once everything is converted to surfaces. // TODO(jamesr): Remove once everything is converted to surfaces.
create_callback_.Run(widget_id_); 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_) if (viewport_surface_)
viewport_surface_->SetWidgetId(widget_id_); viewport_surface_->SetWidgetId(widget_id_);
} }
...@@ -142,5 +150,11 @@ void NativeViewportImpl::AckEvent() { ...@@ -142,5 +150,11 @@ void NativeViewportImpl::AckEvent() {
waiting_for_event_ack_ = false; waiting_for_event_ack_ = false;
} }
void NativeViewportImpl::ProcessOnBoundsChanged() {
client()->OnSizeChanged(Size::From(size_));
if (viewport_surface_)
viewport_surface_->SetSize(size_);
}
} // namespace mojo } // namespace mojo
...@@ -46,6 +46,8 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>, ...@@ -46,6 +46,8 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
void AckEvent(); void AckEvent();
private: private:
void ProcessOnBoundsChanged();
bool is_headless_; bool is_headless_;
scoped_ptr<PlatformViewport> platform_viewport_; scoped_ptr<PlatformViewport> platform_viewport_;
scoped_ptr<ViewportSurface> viewport_surface_; scoped_ptr<ViewportSurface> viewport_surface_;
......
...@@ -13,7 +13,6 @@ module mojo { ...@@ -13,7 +13,6 @@ module mojo {
interface NativeViewport { interface NativeViewport {
// TODO(sky): having a create function is awkward. Should there be a factory // TODO(sky): having a create function is awkward. Should there be a factory
// to create the NativeViewport that takes the size? // to create the NativeViewport that takes the size?
// TODO(sky): callback should take size too.
Create(Size size) => (uint64 native_viewport_id); Create(Size size) => (uint64 native_viewport_id);
Show(); Show();
Hide(); Hide();
...@@ -23,6 +22,8 @@ interface NativeViewport { ...@@ -23,6 +22,8 @@ interface NativeViewport {
}; };
interface NativeViewportClient { interface NativeViewportClient {
// OnSizeChanged() is sent at least once after the callback from Create() is
// called.
OnSizeChanged(Size size); OnSizeChanged(Size size);
OnDestroyed(); OnDestroyed();
OnEvent(Event event) => (); OnEvent(Event event) => ();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment