OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | |
6 #define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | |
7 | |
8 #include <set> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "components/view_manager/native_viewport/onscreen_context_provider.h" | |
13 #include "components/view_manager/native_viewport/platform_viewport.h" | |
14 #include "components/view_manager/public/interfaces/gpu.mojom.h" | |
15 #include "components/view_manager/public/interfaces/native_viewport.mojom.h" | |
16 #include "mojo/application/public/cpp/app_lifetime_helper.h" | |
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h" | |
18 #include "ui/gfx/geometry/rect.h" | |
19 | |
20 namespace gles2 { | |
21 class GpuState; | |
22 } | |
23 | |
24 namespace ui { | |
25 class Event; | |
26 } | |
27 | |
28 namespace native_viewport { | |
29 | |
30 // A NativeViewportImpl is bound to a message pipe and to a PlatformViewport. | |
31 // The NativeViewportImpl's lifetime ends when either the message pipe is closed | |
32 // or the PlatformViewport informs the NativeViewportImpl that it has been | |
33 // destroyed. | |
34 class NativeViewportImpl : public mojo::NativeViewport, | |
35 public PlatformViewport::Delegate { | |
36 public: | |
37 NativeViewportImpl(bool is_headless, | |
38 const scoped_refptr<gles2::GpuState>& gpu_state, | |
39 mojo::InterfaceRequest<mojo::NativeViewport> request, | |
40 scoped_ptr<mojo::AppRefCount> app_refcount); | |
41 ~NativeViewportImpl() override; | |
42 | |
43 // NativeViewport implementation. | |
44 void Create(mojo::SizePtr size, const CreateCallback& callback) override; | |
45 void RequestMetrics(const RequestMetricsCallback& callback) override; | |
46 void Show() override; | |
47 void Hide() override; | |
48 void Close() override; | |
49 void SetSize(mojo::SizePtr size) override; | |
50 void GetContextProvider( | |
51 mojo::InterfaceRequest<mojo::ContextProvider> request) override; | |
52 void SetEventDispatcher( | |
53 mojo::NativeViewportEventDispatcherPtr dispatcher) override; | |
54 | |
55 // PlatformViewport::Delegate implementation. | |
56 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override; | |
57 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, | |
58 float device_pixel_ratio) override; | |
59 void OnAcceleratedWidgetDestroyed() override; | |
60 bool OnEvent(mojo::EventPtr event) override; | |
61 void OnDestroyed() override; | |
62 | |
63 private: | |
64 // Callback when the dispatcher has processed a message we're waiting on | |
65 // an ack from. |pointer_id| identifies the pointer the message was associated | |
66 // with. | |
67 void AckEvent(int32 pointer_id); | |
68 | |
69 bool is_headless_; | |
70 scoped_ptr<mojo::AppRefCount> app_refcount_; | |
71 scoped_ptr<PlatformViewport> platform_viewport_; | |
72 scoped_ptr<OnscreenContextProvider> context_provider_; | |
73 bool sent_metrics_; | |
74 mojo::ViewportMetricsPtr metrics_; | |
75 CreateCallback create_callback_; | |
76 RequestMetricsCallback metrics_callback_; | |
77 mojo::NativeViewportEventDispatcherPtr event_dispatcher_; | |
78 mojo::StrongBinding<mojo::NativeViewport> binding_; | |
79 | |
80 // Set of pointer_ids we've sent a move to and are waiting on an ack. | |
81 std::set<int32> pointers_waiting_on_ack_; | |
82 | |
83 base::WeakPtrFactory<NativeViewportImpl> weak_factory_; | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl); | |
86 }; | |
87 | |
88 } // namespace native_viewport | |
89 | |
90 #endif // COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ | |
OLD | NEW |