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_
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/display_manager_delegate.h"
15 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
16 #include "components/view_manager/surfaces/top_level_display_client.h"
17 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/platform_window/platform_window_delegate.h"
22 class SurfaceIdAllocator
;
31 class ApplicationImpl
;
35 class SurfacesScheduler
;
37 } // namespace surfaces
41 struct TextInputState
;
44 namespace view_manager
{
46 class DisplayManagerFactory
;
47 class EventDispatcher
;
50 // DisplayManager is used to connect the root ServerView to a display.
51 class DisplayManager
{
53 virtual ~DisplayManager() {}
55 static DisplayManager
* Create(
57 mojo::ApplicationImpl
* app_impl
,
58 const scoped_refptr
<gles2::GpuState
>& gpu_state
,
59 const scoped_refptr
<surfaces::SurfacesState
>& surfaces_state
);
61 virtual void Init(DisplayManagerDelegate
* delegate
) = 0;
63 // Schedules a paint for the specified region in the coordinates of |view|.
64 virtual void SchedulePaint(const ServerView
* view
,
65 const gfx::Rect
& bounds
) = 0;
67 virtual void SetViewportSize(const gfx::Size
& size
) = 0;
69 virtual const mojo::ViewportMetrics
& GetViewportMetrics() = 0;
71 virtual void UpdateTextInputState(const ui::TextInputState
& state
) = 0;
72 virtual void SetImeVisibility(bool visible
) = 0;
74 // Overrides factory for testing. Default (NULL) value indicates regular
75 // (non-test) environment.
76 static void set_factory_for_testing(DisplayManagerFactory
* factory
) {
77 DisplayManager::factory_
= factory
;
81 // Static factory instance (always NULL for non-test).
82 static DisplayManagerFactory
* factory_
;
85 // DisplayManager implementation that connects to the services necessary to
87 class DefaultDisplayManager
:
88 public DisplayManager
,
89 public ui::PlatformWindowDelegate
{
91 DefaultDisplayManager(
93 mojo::ApplicationImpl
* app_impl
,
94 const scoped_refptr
<gles2::GpuState
>& gpu_state
,
95 const scoped_refptr
<surfaces::SurfacesState
>& surfaces_state
);
96 ~DefaultDisplayManager() override
;
99 void Init(DisplayManagerDelegate
* delegate
) override
;
100 void SchedulePaint(const ServerView
* view
, const gfx::Rect
& bounds
) override
;
101 void SetViewportSize(const gfx::Size
& size
) override
;
102 const mojo::ViewportMetrics
& GetViewportMetrics() override
;
103 void UpdateTextInputState(const ui::TextInputState
& state
) override
;
104 void SetImeVisibility(bool visible
) override
;
110 void UpdateMetrics(const gfx::Size
& size
, float device_pixel_ratio
);
112 // ui::PlatformWindowDelegate:
113 void OnBoundsChanged(const gfx::Rect
& new_bounds
) override
;
114 void OnDamageRect(const gfx::Rect
& damaged_region
) override
;
115 void DispatchEvent(ui::Event
* event
) override
;
116 void OnCloseRequest() override
;
117 void OnClosed() override
;
118 void OnWindowStateChanged(ui::PlatformWindowState new_state
) override
;
119 void OnLostCapture() override
;
120 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget
,
121 float device_pixel_ratio
) override
;
122 void OnActivationChanged(bool active
) override
;
125 mojo::ApplicationImpl
* app_impl_
;
126 scoped_refptr
<gles2::GpuState
> gpu_state_
;
127 scoped_refptr
<surfaces::SurfacesState
> surfaces_state_
;
128 DisplayManagerDelegate
* delegate_
;
130 mojo::ViewportMetrics metrics_
;
131 gfx::Rect dirty_rect_
;
132 base::Timer draw_timer_
;
135 scoped_ptr
<surfaces::TopLevelDisplayClient
> top_level_display_client_
;
136 scoped_ptr
<ui::PlatformWindow
> platform_window_
;
138 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager
);
141 } // namespace view_manager
143 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_