Index: mojo/services/native_viewport/native_viewport_impl.cc |
diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc |
index 0b871dc33845e9bc335f7ccecb4715d447585f1d..9d6ff23f0778c116a49686e186500d90d0bf4575 100644 |
--- a/mojo/services/native_viewport/native_viewport_impl.cc |
+++ b/mojo/services/native_viewport/native_viewport_impl.cc |
@@ -9,9 +9,12 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/time/time.h" |
#include "mojo/public/cpp/application/application_delegate.h" |
+#include "mojo/public/cpp/application/application_impl.h" |
#include "mojo/public/cpp/application/interface_factory.h" |
+#include "mojo/services/native_viewport/viewport_surface.h" |
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
+#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
#include "ui/events/event.h" |
namespace mojo { |
@@ -25,10 +28,12 @@ bool IsRateLimitedEventType(ui::Event* event) { |
} // namespace |
-NativeViewportImpl::NativeViewportImpl() |
- : widget_(gfx::kNullAcceleratedWidget), |
- waiting_for_event_ack_(false), |
- weak_factory_(this) {} |
+NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app) |
+ : widget_id_(0u), waiting_for_event_ack_(false), weak_factory_(this) { |
+ app->ConnectToService("mojo:mojo_surfaces_service", &surfaces_service_); |
+ // TODO(jamesr): Should be mojo_gpu_service |
+ app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
+} |
NativeViewportImpl::~NativeViewportImpl() { |
// Destroy the NativeViewport early on as it may call us back during |
@@ -59,15 +64,39 @@ void NativeViewportImpl::SetBounds(RectPtr bounds) { |
platform_viewport_->SetBounds(bounds.To<gfx::Rect>()); |
} |
+void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { |
+ if (child_surface_id_.is_null()) { |
+ // If this is the first indication that the client will use surfaces, |
+ // initialize that system. |
+ // TODO(jamesr): When everything is converted to surfaces initialize this |
+ // eagerly. |
+ viewport_surface_.reset( |
+ new ViewportSurface(surfaces_service_.get(), |
+ gpu_service_.get(), |
+ bounds_, |
+ child_surface_id.To<cc::SurfaceId>())); |
+ if (widget_id_) |
+ viewport_surface_->SetWidgetId(widget_id_); |
+ } |
+ child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); |
+ if (viewport_surface_) |
+ viewport_surface_->SetChildId(child_surface_id_); |
+} |
+ |
void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
+ bounds_ = bounds; |
client()->OnBoundsChanged(Rect::From(bounds)); |
+ if (viewport_surface_) |
+ viewport_surface_->SetBounds(bounds); |
} |
void NativeViewportImpl::OnAcceleratedWidgetAvailable( |
gfx::AcceleratedWidget widget) { |
- widget_ = widget; |
- uintptr_t widget_ptr = bit_cast<uintptr_t>(widget); |
- client()->OnCreated(static_cast<uint64_t>(widget_ptr)); |
+ widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); |
+ // TODO(jamesr): Remove once everything is converted to surfaces. |
+ client()->OnCreated(widget_id_); |
+ if (viewport_surface_) |
+ viewport_surface_->SetWidgetId(widget_id_); |
} |
bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { |