Add chrome://flags entry for --try-supported-channel-layouts
[chromium-blink-merge.git] / components / native_viewport / native_viewport_impl.h
blob503509df9f10992ab62f991e05e96b92624b3114
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_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
6 #define COMPONENTS_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
8 #include <set>
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "components/gpu/public/interfaces/gpu.mojom.h"
13 #include "components/native_viewport/onscreen_context_provider.h"
14 #include "components/native_viewport/platform_viewport.h"
15 #include "components/native_viewport/public/interfaces/native_viewport.mojom.h"
16 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
17 #include "ui/gfx/geometry/rect.h"
19 namespace gles2 {
20 class GpuState;
23 namespace ui {
24 class Event;
27 namespace native_viewport {
29 // 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
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 public:
37 NativeViewportImpl(bool is_headless,
38 const scoped_refptr<gles2::GpuState>& gpu_state,
39 mojo::InterfaceRequest<mojo::NativeViewport> request);
40 ~NativeViewportImpl() override;
42 // NativeViewport implementation.
43 void Create(mojo::SizePtr size, const CreateCallback& callback) override;
44 void RequestMetrics(const RequestMetricsCallback& callback) override;
45 void Show() override;
46 void Hide() override;
47 void Close() override;
48 void SetSize(mojo::SizePtr size) override;
49 void GetContextProvider(
50 mojo::InterfaceRequest<mojo::ContextProvider> request) override;
51 void SetEventDispatcher(
52 mojo::NativeViewportEventDispatcherPtr dispatcher) override;
54 // PlatformViewport::Delegate implementation.
55 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override;
56 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
57 float device_pixel_ratio) override;
58 void OnAcceleratedWidgetDestroyed() override;
59 bool OnEvent(mojo::EventPtr event) override;
60 void OnDestroyed() override;
62 // mojo::ErrorHandler implementation.
63 void OnConnectionError() override;
65 private:
66 // Callback when the dispatcher has processed a message we're waiting on
67 // an ack from. |pointer_id| identifies the pointer the message was associated
68 // with.
69 void AckEvent(int32 pointer_id);
71 bool is_headless_;
72 scoped_ptr<PlatformViewport> platform_viewport_;
73 OnscreenContextProvider context_provider_;
74 bool sent_metrics_;
75 mojo::ViewportMetricsPtr metrics_;
76 CreateCallback create_callback_;
77 RequestMetricsCallback metrics_callback_;
78 mojo::NativeViewportEventDispatcherPtr event_dispatcher_;
79 mojo::Binding<mojo::NativeViewport> binding_;
81 // Set of pointer_ids we've sent a move to and are waiting on an ack.
82 std::set<int32> pointers_waiting_on_ack_;
84 base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
86 DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl);
89 } // namespace native_viewport
91 #endif // COMPONENTS_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_