| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |
| #define SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |
| |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| #include "mojo/public/cpp/bindings/strong_binding.h" |
| #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
| #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.h" |
| #include "services/native_viewport/onscreen_context_provider.h" |
| #include "services/native_viewport/platform_viewport.h" |
| #include "ui/gfx/geometry/rect.h" |
| |
| namespace gles2 { |
| class GpuState; |
| } |
| |
| namespace ui { |
| class Event; |
| } |
| |
| namespace native_viewport { |
| |
| // A NativeViewportImpl is bound to a message pipe and to a PlatformViewport. |
| // The NativeViewportImpl's lifetime ends when either the message pipe is closed |
| // or the PlatformViewport informs the NativeViewportImpl that it has been |
| // destroyed. |
| class NativeViewportImpl : public mojo::NativeViewport, |
| public PlatformViewport::Delegate, |
| public mojo::ErrorHandler { |
| public: |
| NativeViewportImpl(bool is_headless, |
| const scoped_refptr<gles2::GpuState>& gpu_state, |
| mojo::InterfaceRequest<mojo::NativeViewport> request); |
| ~NativeViewportImpl() override; |
| |
| // NativeViewport implementation. |
| void Create(mojo::SizePtr size, const CreateCallback& callback) override; |
| void RequestMetrics(const RequestMetricsCallback& callback) override; |
| void Show() override; |
| void Hide() override; |
| void Close() override; |
| void SetSize(mojo::SizePtr size) override; |
| void GetContextProvider( |
| mojo::InterfaceRequest<mojo::ContextProvider> request) override; |
| void SetEventDispatcher( |
| mojo::NativeViewportEventDispatcherPtr dispatcher) override; |
| |
| // PlatformViewport::Delegate implementation. |
| void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override; |
| void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget) override; |
| void OnAcceleratedWidgetDestroyed() override; |
| bool OnEvent(ui::Event* ui_event) override; |
| void OnDestroyed() override; |
| |
| // mojo::ErrorHandler implementation. |
| void OnConnectionError() override; |
| |
| void AckEvent(); |
| |
| private: |
| bool is_headless_; |
| scoped_ptr<PlatformViewport> platform_viewport_; |
| OnscreenContextProvider context_provider_; |
| bool sent_metrics_; |
| mojo::ViewportMetricsPtr metrics_; |
| bool waiting_for_event_ack_; |
| CreateCallback create_callback_; |
| RequestMetricsCallback metrics_callback_; |
| mojo::NativeViewportEventDispatcherPtr event_dispatcher_; |
| mojo::Binding<mojo::NativeViewport> binding_; |
| base::WeakPtrFactory<NativeViewportImpl> weak_factory_; |
| |
| DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl); |
| }; |
| |
| } // namespace native_viewport |
| |
| #endif // SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_ |