Use some pylib Android helpers in Mojo tool scripts.
[chromium-blink-merge.git] / components / view_manager / display_manager.h
blob9bbeeca2a6d8e96c8678b9a5975c33bdad30c02b
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_DISPLAY_MANAGER_H_
6 #define COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h"
14 #include "components/view_manager/public/interfaces/display.mojom.h"
15 #include "components/view_manager/public/interfaces/native_viewport.mojom.h"
16 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
18 #include "ui/gfx/geometry/rect.h"
20 namespace cc {
21 class SurfaceIdAllocator;
24 namespace mojo {
25 class ApplicationImpl;
28 namespace view_manager {
30 class ConnectionManager;
31 class ServerView;
33 // DisplayManager is used to connect the root ServerView to a display.
34 class DisplayManager {
35 public:
36 virtual ~DisplayManager() {}
38 virtual void Init(
39 ConnectionManager* connection_manager,
40 mojo::NativeViewportEventDispatcherPtr event_dispatcher) = 0;
42 // Schedules a paint for the specified region in the coordinates of |view|.
43 virtual void SchedulePaint(const ServerView* view,
44 const gfx::Rect& bounds) = 0;
46 virtual void SetViewportSize(const gfx::Size& size) = 0;
48 virtual const mojo::ViewportMetrics& GetViewportMetrics() = 0;
51 // DisplayManager implementation that connects to the services necessary to
52 // actually display.
53 class DefaultDisplayManager : public DisplayManager,
54 public mojo::ErrorHandler {
55 public:
56 DefaultDisplayManager(
57 mojo::ApplicationImpl* app_impl,
58 const mojo::Callback<void()>& native_viewport_closed_callback);
59 ~DefaultDisplayManager() override;
61 // DisplayManager:
62 void Init(ConnectionManager* connection_manager,
63 mojo::NativeViewportEventDispatcherPtr event_dispatcher) override;
64 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override;
65 void SetViewportSize(const gfx::Size& size) override;
66 const mojo::ViewportMetrics& GetViewportMetrics() override;
68 private:
69 void WantToDraw();
70 void Draw();
71 void DidDraw();
73 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics);
75 // ErrorHandler:
76 void OnConnectionError() override;
78 mojo::ApplicationImpl* app_impl_;
79 ConnectionManager* connection_manager_;
81 mojo::ViewportMetrics metrics_;
82 gfx::Rect dirty_rect_;
83 base::Timer draw_timer_;
84 bool frame_pending_;
86 mojo::DisplayPtr display_;
87 mojo::NativeViewportPtr native_viewport_;
88 mojo::Callback<void()> native_viewport_closed_callback_;
89 base::WeakPtrFactory<DefaultDisplayManager> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager);
94 } // namespace view_manager
96 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_