| 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/converters/native_viewport/surface_configuration_type_converters.
h" |
| 14 #include "mojo/public/cpp/application/application_impl.h" | |
| 15 #include "services/gles2/gpu_state.h" | 14 #include "services/gles2/gpu_state.h" |
| 16 #include "services/native_viewport/platform_viewport_headless.h" | 15 #include "services/native_viewport/platform_viewport_headless.h" |
| 17 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 18 #include "ui/gl/gl_surface.h" | 17 #include "ui/gl/gl_surface.h" |
| 19 | 18 |
| 20 namespace native_viewport { | 19 namespace native_viewport { |
| 21 | 20 |
| 22 NativeViewportImpl::NativeViewportImpl( | 21 NativeViewportImpl::NativeViewportImpl( |
| 23 mojo::ApplicationImpl* application, | 22 mojo::Shell* shell, |
| 24 bool is_headless, | 23 bool is_headless, |
| 25 const scoped_refptr<gles2::GpuState>& gpu_state, | 24 const scoped_refptr<gles2::GpuState>& gpu_state, |
| 26 mojo::InterfaceRequest<mojo::NativeViewport> request) | 25 mojo::InterfaceRequest<mojo::NativeViewport> request) |
| 27 : application_(application), | 26 : shell_(shell), |
| 28 is_headless_(is_headless), | 27 is_headless_(is_headless), |
| 29 context_provider_(gpu_state), | 28 context_provider_(gpu_state), |
| 30 sent_metrics_(false), | 29 sent_metrics_(false), |
| 31 metrics_(mojo::ViewportMetrics::New()), | 30 metrics_(mojo::ViewportMetrics::New()), |
| 32 binding_(this, request.Pass()), | 31 binding_(this, request.Pass()), |
| 33 weak_factory_(this) {} | 32 weak_factory_(this) {} |
| 34 | 33 |
| 35 NativeViewportImpl::~NativeViewportImpl() { | 34 NativeViewportImpl::~NativeViewportImpl() { |
| 36 // Destroy the NativeViewport early on as it may call us back during | 35 // Destroy the NativeViewport early on as it may call us back during |
| 37 // destruction and we want to be in a known state. | 36 // destruction and we want to be in a known state. |
| 38 platform_viewport_.reset(); | 37 platform_viewport_.reset(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void NativeViewportImpl::Create( | 40 void NativeViewportImpl::Create( |
| 42 mojo::SizePtr size, | 41 mojo::SizePtr size, |
| 43 mojo::SurfaceConfigurationPtr requested_configuration, | 42 mojo::SurfaceConfigurationPtr requested_configuration, |
| 44 const CreateCallback& callback) { | 43 const CreateCallback& callback) { |
| 45 if (!requested_configuration) | 44 if (!requested_configuration) |
| 46 requested_configuration = mojo::SurfaceConfiguration::New(); | 45 requested_configuration = mojo::SurfaceConfiguration::New(); |
| 47 | 46 |
| 48 create_callback_ = callback; | 47 create_callback_ = callback; |
| 49 metrics_->size = size.Clone(); | 48 metrics_->size = size.Clone(); |
| 50 context_provider_.set_surface_configuration( | 49 context_provider_.set_surface_configuration( |
| 51 requested_configuration.To<gfx::SurfaceConfiguration>()); | 50 requested_configuration.To<gfx::SurfaceConfiguration>()); |
| 52 if (is_headless_) | 51 if (is_headless_) |
| 53 platform_viewport_ = PlatformViewportHeadless::Create(this); | 52 platform_viewport_ = PlatformViewportHeadless::Create(this); |
| 54 else | 53 else |
| 55 platform_viewport_ = PlatformViewport::Create(application_, this); | 54 platform_viewport_ = PlatformViewport::Create(shell_, this); |
| 56 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); | 55 platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>())); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void NativeViewportImpl::RequestMetrics( | 58 void NativeViewportImpl::RequestMetrics( |
| 60 const RequestMetricsCallback& callback) { | 59 const RequestMetricsCallback& callback) { |
| 61 if (!sent_metrics_) { | 60 if (!sent_metrics_) { |
| 62 callback.Run(metrics_.Clone()); | 61 callback.Run(metrics_.Clone()); |
| 63 sent_metrics_ = true; | 62 sent_metrics_ = true; |
| 64 return; | 63 return; |
| 65 } | 64 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 158 |
| 160 void NativeViewportImpl::OnDestroyed() { | 159 void NativeViewportImpl::OnDestroyed() { |
| 161 delete this; | 160 delete this; |
| 162 } | 161 } |
| 163 | 162 |
| 164 void NativeViewportImpl::AckEvent(int32 pointer_id) { | 163 void NativeViewportImpl::AckEvent(int32 pointer_id) { |
| 165 pointers_waiting_on_ack_.erase(pointer_id); | 164 pointers_waiting_on_ack_.erase(pointer_id); |
| 166 } | 165 } |
| 167 | 166 |
| 168 } // namespace native_viewport | 167 } // namespace native_viewport |
| OLD | NEW |