| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_impl.h" | 5 #include "mojo/services/native_viewport/native_viewport_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "mojo/public/cpp/application/application_delegate.h" | 11 #include "mojo/public/cpp/application/application_delegate.h" |
| 12 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/application/interface_factory.h" | 13 #include "mojo/public/cpp/application/interface_factory.h" |
| 14 #include "mojo/services/native_viewport/viewport_surface.h" |
| 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 14 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 16 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
| 17 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
| 15 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 16 | 19 |
| 17 namespace mojo { | 20 namespace mojo { |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 bool IsRateLimitedEventType(ui::Event* event) { | 23 bool IsRateLimitedEventType(ui::Event* event) { |
| 21 return event->type() == ui::ET_MOUSE_MOVED || | 24 return event->type() == ui::ET_MOUSE_MOVED || |
| 22 event->type() == ui::ET_MOUSE_DRAGGED || | 25 event->type() == ui::ET_MOUSE_DRAGGED || |
| 23 event->type() == ui::ET_TOUCH_MOVED; | 26 event->type() == ui::ET_TOUCH_MOVED; |
| 24 } | 27 } |
| 25 | 28 |
| 26 } // namespace | 29 } // namespace |
| 27 | 30 |
| 28 NativeViewportImpl::NativeViewportImpl() | 31 NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app) |
| 29 : widget_(gfx::kNullAcceleratedWidget), | 32 : widget_id_(0u), waiting_for_event_ack_(false), weak_factory_(this) { |
| 30 waiting_for_event_ack_(false), | 33 app->ConnectToService("mojo:mojo_surfaces_service", &surfaces_service_); |
| 31 weak_factory_(this) {} | 34 // TODO(jamesr): Should be mojo_gpu_service |
| 35 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
| 36 } |
| 32 | 37 |
| 33 NativeViewportImpl::~NativeViewportImpl() { | 38 NativeViewportImpl::~NativeViewportImpl() { |
| 34 // Destroy the NativeViewport early on as it may call us back during | 39 // Destroy the NativeViewport early on as it may call us back during |
| 35 // destruction and we want to be in a known state. | 40 // destruction and we want to be in a known state. |
| 36 platform_viewport_.reset(); | 41 platform_viewport_.reset(); |
| 37 } | 42 } |
| 38 | 43 |
| 39 void NativeViewportImpl::Create(RectPtr bounds) { | 44 void NativeViewportImpl::Create(RectPtr bounds) { |
| 40 platform_viewport_ = PlatformViewport::Create(this); | 45 platform_viewport_ = PlatformViewport::Create(this); |
| 41 platform_viewport_->Init(bounds.To<gfx::Rect>()); | 46 platform_viewport_->Init(bounds.To<gfx::Rect>()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 | 57 |
| 53 void NativeViewportImpl::Close() { | 58 void NativeViewportImpl::Close() { |
| 54 DCHECK(platform_viewport_); | 59 DCHECK(platform_viewport_); |
| 55 platform_viewport_->Close(); | 60 platform_viewport_->Close(); |
| 56 } | 61 } |
| 57 | 62 |
| 58 void NativeViewportImpl::SetBounds(RectPtr bounds) { | 63 void NativeViewportImpl::SetBounds(RectPtr bounds) { |
| 59 platform_viewport_->SetBounds(bounds.To<gfx::Rect>()); | 64 platform_viewport_->SetBounds(bounds.To<gfx::Rect>()); |
| 60 } | 65 } |
| 61 | 66 |
| 67 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { |
| 68 if (child_surface_id_.is_null()) { |
| 69 // If this is the first indication that the client will use surfaces, |
| 70 // initialize that system. |
| 71 // TODO(jamesr): When everything is converted to surfaces initialize this |
| 72 // eagerly. |
| 73 viewport_surface_.reset( |
| 74 new ViewportSurface(surfaces_service_.get(), |
| 75 gpu_service_.get(), |
| 76 bounds_, |
| 77 child_surface_id.To<cc::SurfaceId>())); |
| 78 if (widget_id_) |
| 79 viewport_surface_->SetWidgetId(widget_id_); |
| 80 } |
| 81 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); |
| 82 if (viewport_surface_) |
| 83 viewport_surface_->SetChildId(child_surface_id_); |
| 84 } |
| 85 |
| 62 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 86 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
| 87 bounds_ = bounds; |
| 63 client()->OnBoundsChanged(Rect::From(bounds)); | 88 client()->OnBoundsChanged(Rect::From(bounds)); |
| 89 if (viewport_surface_) |
| 90 viewport_surface_->SetBounds(bounds); |
| 64 } | 91 } |
| 65 | 92 |
| 66 void NativeViewportImpl::OnAcceleratedWidgetAvailable( | 93 void NativeViewportImpl::OnAcceleratedWidgetAvailable( |
| 67 gfx::AcceleratedWidget widget) { | 94 gfx::AcceleratedWidget widget) { |
| 68 widget_ = widget; | 95 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); |
| 69 uintptr_t widget_ptr = bit_cast<uintptr_t>(widget); | 96 // TODO(jamesr): Remove once everything is converted to surfaces. |
| 70 client()->OnCreated(static_cast<uint64_t>(widget_ptr)); | 97 client()->OnCreated(widget_id_); |
| 98 if (viewport_surface_) |
| 99 viewport_surface_->SetWidgetId(widget_id_); |
| 71 } | 100 } |
| 72 | 101 |
| 73 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { | 102 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { |
| 74 // Must not return early before updating capture. | 103 // Must not return early before updating capture. |
| 75 switch (ui_event->type()) { | 104 switch (ui_event->type()) { |
| 76 case ui::ET_MOUSE_PRESSED: | 105 case ui::ET_MOUSE_PRESSED: |
| 77 case ui::ET_TOUCH_PRESSED: | 106 case ui::ET_TOUCH_PRESSED: |
| 78 platform_viewport_->SetCapture(); | 107 platform_viewport_->SetCapture(); |
| 79 break; | 108 break; |
| 80 case ui::ET_MOUSE_RELEASED: | 109 case ui::ET_MOUSE_RELEASED: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 99 void NativeViewportImpl::OnDestroyed() { | 128 void NativeViewportImpl::OnDestroyed() { |
| 100 client()->OnDestroyed(); | 129 client()->OnDestroyed(); |
| 101 } | 130 } |
| 102 | 131 |
| 103 void NativeViewportImpl::AckEvent() { | 132 void NativeViewportImpl::AckEvent() { |
| 104 waiting_for_event_ack_ = false; | 133 waiting_for_event_ack_ = false; |
| 105 } | 134 } |
| 106 | 135 |
| 107 } // namespace mojo | 136 } // namespace mojo |
| 108 | 137 |
| OLD | NEW |