| 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 "services/native_viewport/native_viewport_impl.h" | 5 #include "services/native_viewport/native_viewport_impl.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 12 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/native_viewport/surface_configuration_type_converters.
h" |
| 13 #include "mojo/public/cpp/application/interface_factory.h" | 14 #include "mojo/public/cpp/application/interface_factory.h" |
| 14 #include "services/gles2/gpu_state.h" | 15 #include "services/gles2/gpu_state.h" |
| 15 #include "services/native_viewport/platform_viewport_headless.h" | 16 #include "services/native_viewport/platform_viewport_headless.h" |
| 16 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 #include "ui/gl/gl_surface.h" |
| 17 | 19 |
| 18 namespace native_viewport { | 20 namespace native_viewport { |
| 19 | 21 |
| 20 NativeViewportImpl::NativeViewportImpl( | 22 NativeViewportImpl::NativeViewportImpl( |
| 21 bool is_headless, | 23 bool is_headless, |
| 22 const scoped_refptr<gles2::GpuState>& gpu_state, | 24 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 23 mojo::InterfaceRequest<mojo::NativeViewport> request) | 25 mojo::InterfaceRequest<mojo::NativeViewport> request) |
| 24 : is_headless_(is_headless), | 26 : is_headless_(is_headless), |
| 25 context_provider_(gpu_state), | 27 context_provider_(gpu_state), |
| 26 sent_metrics_(false), | 28 sent_metrics_(false), |
| 27 metrics_(mojo::ViewportMetrics::New()), | 29 metrics_(mojo::ViewportMetrics::New()), |
| 28 binding_(this, request.Pass()), | 30 binding_(this, request.Pass()), |
| 29 weak_factory_(this) { | 31 weak_factory_(this) { |
| 30 binding_.set_error_handler(this); | 32 binding_.set_error_handler(this); |
| 31 } | 33 } |
| 32 | 34 |
| 33 NativeViewportImpl::~NativeViewportImpl() { | 35 NativeViewportImpl::~NativeViewportImpl() { |
| 34 // Destroy the NativeViewport early on as it may call us back during | 36 // Destroy the NativeViewport early on as it may call us back during |
| 35 // destruction and we want to be in a known state. | 37 // destruction and we want to be in a known state. |
| 36 platform_viewport_.reset(); | 38 platform_viewport_.reset(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void NativeViewportImpl::Create(mojo::SizePtr size, | 41 void NativeViewportImpl::Create( |
| 40 const CreateCallback& callback) { | 42 const mojo::SizePtr size, |
| 43 mojo::SurfaceConfigurationPtr requested_configuration, |
| 44 const CreateCallback& callback) { |
| 45 |
| 46 if (requested_configuration == nullptr) { |
| 47 requested_configuration = mojo::SurfaceConfiguration::New(); |
| 48 } |
| 49 |
| 41 create_callback_ = callback; | 50 create_callback_ = callback; |
| 42 metrics_->size = size.Clone(); | 51 metrics_->size = size.Clone(); |
| 52 context_provider_.set_surface_configuration( |
| 53 requested_configuration.To<gfx::SurfaceConfiguration>()); |
| 43 if (is_headless_) | 54 if (is_headless_) |
| 44 platform_viewport_ = PlatformViewportHeadless::Create(this); | 55 platform_viewport_ = PlatformViewportHeadless::Create(this); |
| 45 else | 56 else |
| 46 platform_viewport_ = PlatformViewport::Create(this); | 57 platform_viewport_ = PlatformViewport::Create(this); |
| 47 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); | 58 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); |
| 48 } | 59 } |
| 49 | 60 |
| 50 void NativeViewportImpl::RequestMetrics( | 61 void NativeViewportImpl::RequestMetrics( |
| 51 const RequestMetricsCallback& callback) { | 62 const RequestMetricsCallback& callback) { |
| 52 if (!sent_metrics_) { | 63 if (!sent_metrics_) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 63 | 74 |
| 64 void NativeViewportImpl::Hide() { | 75 void NativeViewportImpl::Hide() { |
| 65 platform_viewport_->Hide(); | 76 platform_viewport_->Hide(); |
| 66 } | 77 } |
| 67 | 78 |
| 68 void NativeViewportImpl::Close() { | 79 void NativeViewportImpl::Close() { |
| 69 DCHECK(platform_viewport_); | 80 DCHECK(platform_viewport_); |
| 70 platform_viewport_->Close(); | 81 platform_viewport_->Close(); |
| 71 } | 82 } |
| 72 | 83 |
| 73 void NativeViewportImpl::SetSize(mojo::SizePtr size) { | 84 void NativeViewportImpl::SetSize(const mojo::SizePtr size) { |
| 74 platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>())); | 85 platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>())); |
| 75 } | 86 } |
| 76 | 87 |
| 77 void NativeViewportImpl::GetContextProvider( | 88 void NativeViewportImpl::GetContextProvider( |
| 78 mojo::InterfaceRequest<mojo::ContextProvider> request) { | 89 mojo::InterfaceRequest<mojo::ContextProvider> request) { |
| 79 context_provider_.Bind(request.Pass()); | 90 context_provider_.Bind(request.Pass()); |
| 80 } | 91 } |
| 81 | 92 |
| 82 void NativeViewportImpl::SetEventDispatcher( | 93 void NativeViewportImpl::SetEventDispatcher( |
| 83 mojo::NativeViewportEventDispatcherPtr dispatcher) { | 94 mojo::NativeViewportEventDispatcherPtr dispatcher) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 void NativeViewportImpl::OnConnectionError() { | 166 void NativeViewportImpl::OnConnectionError() { |
| 156 binding_.set_error_handler(nullptr); | 167 binding_.set_error_handler(nullptr); |
| 157 delete this; | 168 delete this; |
| 158 } | 169 } |
| 159 | 170 |
| 160 void NativeViewportImpl::AckEvent(int32 pointer_id) { | 171 void NativeViewportImpl::AckEvent(int32 pointer_id) { |
| 161 pointers_waiting_on_ack_.erase(pointer_id); | 172 pointers_waiting_on_ack_.erase(pointer_id); |
| 162 } | 173 } |
| 163 | 174 |
| 164 } // namespace native_viewport | 175 } // namespace native_viewport |
| OLD | NEW |