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_MUS_DISPLAY_MANAGER_H_
6 #define COMPONENTS_MUS_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/mus/display_manager_delegate.h"
15 #include "components/mus/public/interfaces/view_tree.mojom.h"
16 #include "components/mus/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
;
36 struct TextInputState
;
41 class DisplayManagerFactory
;
42 class EventDispatcher
;
44 class SurfacesScheduler
;
47 // DisplayManager is used to connect the root ServerView to a display.
48 class DisplayManager
{
50 virtual ~DisplayManager() {}
52 static DisplayManager
* Create(
54 mojo::ApplicationImpl
* app_impl
,
55 const scoped_refptr
<GpuState
>& gpu_state
,
56 const scoped_refptr
<SurfacesState
>& surfaces_state
);
58 virtual void Init(DisplayManagerDelegate
* delegate
) = 0;
60 // Schedules a paint for the specified region in the coordinates of |view|.
61 virtual void SchedulePaint(const ServerView
* view
,
62 const gfx::Rect
& bounds
) = 0;
64 virtual void SetViewportSize(const gfx::Size
& size
) = 0;
66 virtual void SetTitle(const base::string16
& title
) = 0;
68 virtual const mojo::ViewportMetrics
& GetViewportMetrics() = 0;
70 virtual void UpdateTextInputState(const ui::TextInputState
& state
) = 0;
71 virtual void SetImeVisibility(bool visible
) = 0;
73 // Overrides factory for testing. Default (NULL) value indicates regular
74 // (non-test) environment.
75 static void set_factory_for_testing(DisplayManagerFactory
* factory
) {
76 DisplayManager::factory_
= factory
;
80 // Static factory instance (always NULL for non-test).
81 static DisplayManagerFactory
* factory_
;
84 // DisplayManager implementation that connects to the services necessary to
86 class DefaultDisplayManager
: public DisplayManager
,
87 public ui::PlatformWindowDelegate
{
89 DefaultDisplayManager(bool is_headless
,
90 mojo::ApplicationImpl
* app_impl
,
91 const scoped_refptr
<GpuState
>& gpu_state
,
92 const scoped_refptr
<SurfacesState
>& surfaces_state
);
93 ~DefaultDisplayManager() override
;
96 void Init(DisplayManagerDelegate
* delegate
) override
;
97 void SchedulePaint(const ServerView
* view
, const gfx::Rect
& bounds
) override
;
98 void SetViewportSize(const gfx::Size
& size
) override
;
99 void SetTitle(const base::string16
& title
) override
;
100 const mojo::ViewportMetrics
& GetViewportMetrics() override
;
101 void UpdateTextInputState(const ui::TextInputState
& state
) override
;
102 void SetImeVisibility(bool visible
) override
;
107 // This method initiates a top level redraw of the display.
108 // TODO(fsamuel): This should use vblank as a signal rather than a timer
109 // http://crbug.com/533042
112 // This is called after cc::Display has completed generating a new frame
113 // for the display. TODO(fsamuel): Idle time processing should happen here
114 // if there is budget for it.
116 void UpdateMetrics(const gfx::Size
& size
, float device_pixel_ratio
);
117 scoped_ptr
<cc::CompositorFrame
> GenerateCompositorFrame();
118 const cc::CompositorFrame
* GetLastCompositorFrame() const;
120 // ui::PlatformWindowDelegate:
121 void OnBoundsChanged(const gfx::Rect
& new_bounds
) override
;
122 void OnDamageRect(const gfx::Rect
& damaged_region
) override
;
123 void DispatchEvent(ui::Event
* event
) override
;
124 void OnCloseRequest() override
;
125 void OnClosed() override
;
126 void OnWindowStateChanged(ui::PlatformWindowState new_state
) override
;
127 void OnLostCapture() override
;
128 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget
,
129 float device_pixel_ratio
) override
;
130 void OnActivationChanged(bool active
) override
;
133 mojo::ApplicationImpl
* app_impl_
;
134 scoped_refptr
<GpuState
> gpu_state_
;
135 scoped_refptr
<SurfacesState
> surfaces_state_
;
136 DisplayManagerDelegate
* delegate_
;
138 mojo::ViewportMetrics metrics_
;
139 gfx::Rect dirty_rect_
;
140 base::Timer draw_timer_
;
143 scoped_ptr
<TopLevelDisplayClient
> top_level_display_client_
;
144 scoped_ptr
<ui::PlatformWindow
> platform_window_
;
146 base::WeakPtrFactory
<DefaultDisplayManager
> weak_factory_
;
148 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager
);
153 #endif // COMPONENTS_MUS_DISPLAY_MANAGER_H_