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