| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // TODO(jamesr): Should be mojo_gpu_service | 38 // TODO(jamesr): Should be mojo_gpu_service |
| 39 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); | 39 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); |
| 40 } | 40 } |
| 41 | 41 |
| 42 NativeViewportImpl::~NativeViewportImpl() { | 42 NativeViewportImpl::~NativeViewportImpl() { |
| 43 // Destroy the NativeViewport early on as it may call us back during | 43 // Destroy the NativeViewport early on as it may call us back during |
| 44 // destruction and we want to be in a known state. | 44 // destruction and we want to be in a known state. |
| 45 platform_viewport_.reset(); | 45 platform_viewport_.reset(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void NativeViewportImpl::Create(SizePtr bounds) { | 48 void NativeViewportImpl::Create(SizePtr size, |
| 49 const Callback<void(uint64_t)>& callback) { |
| 50 create_callback_ = callback; |
| 49 if (is_headless_) | 51 if (is_headless_) |
| 50 platform_viewport_ = PlatformViewportHeadless::Create(this); | 52 platform_viewport_ = PlatformViewportHeadless::Create(this); |
| 51 else | 53 else |
| 52 platform_viewport_ = PlatformViewport::Create(this); | 54 platform_viewport_ = PlatformViewport::Create(this); |
| 53 gfx::Rect rect = gfx::Rect(bounds.To<gfx::Size>()); | 55 const gfx::Rect bounds(gfx::Rect(size.To<gfx::Size>())); |
| 54 platform_viewport_->Init(rect); | 56 platform_viewport_->Init(bounds); |
| 55 OnBoundsChanged(rect); | 57 OnBoundsChanged(bounds); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void NativeViewportImpl::Show() { | 60 void NativeViewportImpl::Show() { |
| 59 platform_viewport_->Show(); | 61 platform_viewport_->Show(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void NativeViewportImpl::Hide() { | 64 void NativeViewportImpl::Hide() { |
| 63 platform_viewport_->Hide(); | 65 platform_viewport_->Hide(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void NativeViewportImpl::Close() { | 68 void NativeViewportImpl::Close() { |
| 67 DCHECK(platform_viewport_); | 69 DCHECK(platform_viewport_); |
| 68 platform_viewport_->Close(); | 70 platform_viewport_->Close(); |
| 69 } | 71 } |
| 70 | 72 |
| 71 void NativeViewportImpl::SetBounds(SizePtr bounds) { | 73 void NativeViewportImpl::SetSize(SizePtr size) { |
| 72 platform_viewport_->SetBounds(gfx::Rect(bounds.To<gfx::Size>())); | 74 platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>())); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { | 77 void NativeViewportImpl::SubmittedFrame(SurfaceIdPtr child_surface_id) { |
| 76 if (child_surface_id_.is_null()) { | 78 if (child_surface_id_.is_null()) { |
| 77 // If this is the first indication that the client will use surfaces, | 79 // If this is the first indication that the client will use surfaces, |
| 78 // initialize that system. | 80 // initialize that system. |
| 79 // TODO(jamesr): When everything is converted to surfaces initialize this | 81 // TODO(jamesr): When everything is converted to surfaces initialize this |
| 80 // eagerly. | 82 // eagerly. |
| 81 viewport_surface_.reset( | 83 viewport_surface_.reset( |
| 82 new ViewportSurface(surfaces_service_.get(), | 84 new ViewportSurface(surfaces_service_.get(), |
| 83 gpu_service_.get(), | 85 gpu_service_.get(), |
| 84 bounds_.size(), | 86 size_, |
| 85 child_surface_id.To<cc::SurfaceId>())); | 87 child_surface_id.To<cc::SurfaceId>())); |
| 86 if (widget_id_) | 88 if (widget_id_) |
| 87 viewport_surface_->SetWidgetId(widget_id_); | 89 viewport_surface_->SetWidgetId(widget_id_); |
| 88 } | 90 } |
| 89 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); | 91 child_surface_id_ = child_surface_id.To<cc::SurfaceId>(); |
| 90 if (viewport_surface_) | 92 if (viewport_surface_) |
| 91 viewport_surface_->SetChildId(child_surface_id_); | 93 viewport_surface_->SetChildId(child_surface_id_); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { | 96 void NativeViewportImpl::OnBoundsChanged(const gfx::Rect& bounds) { |
| 95 bounds_ = bounds; | 97 size_ = bounds.size(); |
| 96 client()->OnBoundsChanged(Size::From(bounds.size())); | 98 client()->OnSizeChanged(Size::From(size_)); |
| 97 if (viewport_surface_) | 99 if (viewport_surface_) |
| 98 viewport_surface_->SetSize(bounds.size()); | 100 viewport_surface_->SetSize(size_); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void NativeViewportImpl::OnAcceleratedWidgetAvailable( | 103 void NativeViewportImpl::OnAcceleratedWidgetAvailable( |
| 102 gfx::AcceleratedWidget widget) { | 104 gfx::AcceleratedWidget widget) { |
| 103 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); | 105 widget_id_ = static_cast<uint64_t>(bit_cast<uintptr_t>(widget)); |
| 104 // TODO(jamesr): Remove once everything is converted to surfaces. | 106 // TODO(jamesr): Remove once everything is converted to surfaces. |
| 105 client()->OnCreated(widget_id_); | 107 create_callback_.Run(widget_id_); |
| 106 if (viewport_surface_) | 108 if (viewport_surface_) |
| 107 viewport_surface_->SetWidgetId(widget_id_); | 109 viewport_surface_->SetWidgetId(widget_id_); |
| 108 } | 110 } |
| 109 | 111 |
| 110 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { | 112 bool NativeViewportImpl::OnEvent(ui::Event* ui_event) { |
| 111 // Must not return early before updating capture. | 113 // Must not return early before updating capture. |
| 112 switch (ui_event->type()) { | 114 switch (ui_event->type()) { |
| 113 case ui::ET_MOUSE_PRESSED: | 115 case ui::ET_MOUSE_PRESSED: |
| 114 case ui::ET_TOUCH_PRESSED: | 116 case ui::ET_TOUCH_PRESSED: |
| 115 platform_viewport_->SetCapture(); | 117 platform_viewport_->SetCapture(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 135 void NativeViewportImpl::OnDestroyed() { | 137 void NativeViewportImpl::OnDestroyed() { |
| 136 client()->OnDestroyed(); | 138 client()->OnDestroyed(); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void NativeViewportImpl::AckEvent() { | 141 void NativeViewportImpl::AckEvent() { |
| 140 waiting_for_event_ack_ = false; | 142 waiting_for_event_ack_ = false; |
| 141 } | 143 } |
| 142 | 144 |
| 143 } // namespace mojo | 145 } // namespace mojo |
| 144 | 146 |
| OLD | NEW |