Move GLES2, GPU & Surfaces into the ViewManager directory. This does not merge the...
[chromium-blink-merge.git] / components / view_manager / native_viewport / native_viewport_impl.h
blobf298a536637119a62a4b4fca1914d14a7bcbab05
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.
5 #ifndef COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
6 #define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
8 #include <set>
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"
20 namespace gles2 {
21 class GpuState;
24 namespace ui {
25 class Event;
28 namespace native_viewport {
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 mojo::ErrorHandler {
37 public:
38 NativeViewportImpl(bool is_headless,
39 const scoped_refptr<gles2::GpuState>& gpu_state,
40 mojo::InterfaceRequest<mojo::NativeViewport> request,
41 scoped_ptr<mojo::AppRefCount> app_refcount);
42 ~NativeViewportImpl() override;
44 // NativeViewport implementation.
45 void Create(mojo::SizePtr size, const CreateCallback& callback) override;
46 void RequestMetrics(const RequestMetricsCallback& callback) override;
47 void Show() override;
48 void Hide() override;
49 void Close() override;
50 void SetSize(mojo::SizePtr size) override;
51 void GetContextProvider(
52 mojo::InterfaceRequest<mojo::ContextProvider> request) override;
53 void SetEventDispatcher(
54 mojo::NativeViewportEventDispatcherPtr dispatcher) override;
56 // PlatformViewport::Delegate implementation.
57 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override;
58 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
59 float device_pixel_ratio) override;
60 void OnAcceleratedWidgetDestroyed() override;
61 bool OnEvent(mojo::EventPtr event) override;
62 void OnDestroyed() override;
64 // mojo::ErrorHandler implementation.
65 void OnConnectionError() override;
67 private:
68 // Callback when the dispatcher has processed a message we're waiting on
69 // an ack from. |pointer_id| identifies the pointer the message was associated
70 // with.
71 void AckEvent(int32 pointer_id);
73 bool is_headless_;
74 scoped_ptr<mojo::AppRefCount> app_refcount_;
75 scoped_ptr<PlatformViewport> platform_viewport_;
76 scoped_ptr<OnscreenContextProvider> context_provider_;
77 bool sent_metrics_;
78 mojo::ViewportMetricsPtr metrics_;
79 CreateCallback create_callback_;
80 RequestMetricsCallback metrics_callback_;
81 mojo::NativeViewportEventDispatcherPtr event_dispatcher_;
82 mojo::Binding<mojo::NativeViewport> binding_;
84 // Set of pointer_ids we've sent a move to and are waiting on an ack.
85 std::set<int32> pointers_waiting_on_ack_;
87 base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
89 DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl);
92 } // namespace native_viewport
94 #endif // COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_