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 #ifndef SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | 5 #ifndef SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |
6 #define SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | 6 #define SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "cc/surfaces/surface_id.h" | 10 #include "cc/surfaces/surface_id.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
11 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" | 12 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
12 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" | 13 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" |
13 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 14 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
14 #include "services/native_viewport/platform_viewport.h" | 15 #include "services/native_viewport/platform_viewport.h" |
15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
16 | 17 |
17 namespace ui { | 18 namespace ui { |
18 class Event; | 19 class Event; |
19 } | 20 } |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
22 class ApplicationImpl; | 23 class ApplicationImpl; |
23 } | 24 } |
24 | 25 |
25 namespace native_viewport { | 26 namespace native_viewport { |
26 class ViewportSurface; | 27 class ViewportSurface; |
27 | 28 |
28 class NativeViewportImpl : public mojo::InterfaceImpl<mojo::NativeViewport>, | 29 // A NativeViewportImpl is bound to a message pipe and to a PlatformViewport. |
29 public PlatformViewport::Delegate { | 30 // The NativeViewportImpl's lifetime ends when either the message pipe is closed |
| 31 // or the PlatformViewport informs the NativeViewportImpl that it has been |
| 32 // destroyed. |
| 33 class NativeViewportImpl : public mojo::NativeViewport, |
| 34 public PlatformViewport::Delegate, |
| 35 public mojo::ErrorHandler { |
| 36 using CreateCallback = mojo::Callback<void(uint64_t native_viewport_id, |
| 37 mojo::ViewportMetricsPtr metrics)>; |
| 38 using MetricsCallback = |
| 39 mojo::Callback<void(mojo::ViewportMetricsPtr metrics)>; |
| 40 |
30 public: | 41 public: |
31 NativeViewportImpl(mojo::ApplicationImpl* app, bool is_headless); | 42 NativeViewportImpl(mojo::ApplicationImpl* app, |
| 43 bool is_headless, |
| 44 mojo::InterfaceRequest<mojo::NativeViewport> request); |
32 ~NativeViewportImpl() override; | 45 ~NativeViewportImpl() override; |
33 | 46 |
34 // InterfaceImpl<NativeViewport> implementation. | 47 // InterfaceImpl<NativeViewport> implementation. |
35 void Create(mojo::SizePtr size, | 48 void Create(mojo::SizePtr size, const CreateCallback& callback) override; |
36 const mojo::Callback<void(uint64_t)>& callback) override; | 49 void RequestMetrics(const MetricsCallback& callback) override; |
37 void Show() override; | 50 void Show() override; |
38 void Hide() override; | 51 void Hide() override; |
39 void Close() override; | 52 void Close() override; |
40 void SetSize(mojo::SizePtr size) override; | 53 void SetSize(mojo::SizePtr size) override; |
41 void SubmittedFrame(mojo::SurfaceIdPtr surface_id) override; | 54 void SubmittedFrame(mojo::SurfaceIdPtr surface_id) override; |
42 void SetEventDispatcher( | 55 void SetEventDispatcher( |
43 mojo::NativeViewportEventDispatcherPtr dispatcher) override; | 56 mojo::NativeViewportEventDispatcherPtr dispatcher) override; |
44 | 57 |
45 // PlatformViewport::Delegate implementation. | 58 // PlatformViewport::Delegate implementation. |
46 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override; | 59 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override; |
47 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; | 60 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; |
48 bool OnEvent(ui::Event* ui_event) override; | 61 bool OnEvent(ui::Event* ui_event) override; |
49 void OnDestroyed() override; | 62 void OnDestroyed() override; |
50 | 63 |
| 64 // mojo::ErrorHandler implementation. |
| 65 void OnConnectionError() override; |
| 66 |
51 void AckEvent(); | 67 void AckEvent(); |
52 | 68 |
53 private: | 69 private: |
54 void ProcessOnMetricsChanged(); | |
55 | |
56 bool is_headless_; | 70 bool is_headless_; |
57 scoped_ptr<PlatformViewport> platform_viewport_; | 71 scoped_ptr<PlatformViewport> platform_viewport_; |
58 scoped_ptr<ViewportSurface> viewport_surface_; | 72 scoped_ptr<ViewportSurface> viewport_surface_; |
59 uint64_t widget_id_; | 73 uint64_t widget_id_; |
| 74 bool sent_metrics_; |
60 mojo::ViewportMetricsPtr metrics_; | 75 mojo::ViewportMetricsPtr metrics_; |
61 mojo::GpuPtr gpu_service_; | 76 mojo::GpuPtr gpu_service_; |
62 mojo::SurfacePtr surface_; | 77 mojo::SurfacePtr surface_; |
63 cc::SurfaceId child_surface_id_; | 78 cc::SurfaceId child_surface_id_; |
64 bool waiting_for_event_ack_; | 79 bool waiting_for_event_ack_; |
65 mojo::Callback<void(uint64_t)> create_callback_; | 80 CreateCallback create_callback_; |
| 81 MetricsCallback metrics_callback_; |
66 mojo::NativeViewportEventDispatcherPtr event_dispatcher_; | 82 mojo::NativeViewportEventDispatcherPtr event_dispatcher_; |
| 83 mojo::Binding<mojo::NativeViewport> binding_; |
67 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | 84 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
68 | 85 |
69 DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl); | 86 DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl); |
70 }; | 87 }; |
71 | 88 |
72 } // namespace native_viewport | 89 } // namespace native_viewport |
73 | 90 |
74 #endif // SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | 91 #endif // SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |
OLD | NEW |