summaryrefslogtreecommitdiffstats
path: root/mojo/services/native_viewport/native_viewport_impl.h
blob: 82f38a971963797575deefbbdc3ca4a3c471880e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// 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 MOJO_SERVICES_NATIVE_VIEWPORT_IMPL_H_
#define MOJO_SERVICES_NATIVE_VIEWPORT_IMPL_H_

#include "base/memory/weak_ptr.h"
#include "cc/surfaces/surface_id.h"
#include "mojo/services/native_viewport/platform_viewport.h"
#include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h"
#include "ui/gfx/geometry/rect.h"

namespace ui {
class Event;
}

namespace mojo {
class ApplicationImpl;
class ViewportSurface;

class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
                           public PlatformViewport::Delegate {
 public:
  NativeViewportImpl(ApplicationImpl* app, bool is_headless);
  virtual ~NativeViewportImpl();

  // InterfaceImpl<NativeViewport> implementation.
  virtual void Create(SizePtr size,
                      const Callback<void(uint64_t)>& callback) OVERRIDE;
  virtual void Show() OVERRIDE;
  virtual void Hide() OVERRIDE;
  virtual void Close() OVERRIDE;
  virtual void SetSize(SizePtr size) OVERRIDE;
  virtual void SubmittedFrame(SurfaceIdPtr surface_id) OVERRIDE;

  // PlatformViewport::Delegate implementation.
  virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE;
  virtual void OnAcceleratedWidgetAvailable(
      gfx::AcceleratedWidget widget) OVERRIDE;
  virtual bool OnEvent(ui::Event* ui_event) OVERRIDE;
  virtual void OnDestroyed() OVERRIDE;

  void AckEvent();

 private:
  bool is_headless_;
  scoped_ptr<PlatformViewport> platform_viewport_;
  scoped_ptr<ViewportSurface> viewport_surface_;
  uint64_t widget_id_;
  gfx::Size size_;
  GpuPtr gpu_service_;
  SurfacesServicePtr surfaces_service_;
  cc::SurfaceId child_surface_id_;
  bool waiting_for_event_ack_;
  Callback<void(uint64_t)> create_callback_;
  base::WeakPtrFactory<NativeViewportImpl> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl);
};

}  // namespace mojo

#endif  // MOJO_SERVICES_NATIVE_VIEWPORT_IMPL_H_