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/native_viewport/platform_viewport.h"
16 #include "components/view_manager/public/interfaces/display.mojom.h"
17 #include "components/view_manager/public/interfaces/view_manager.mojom.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
19 #include "ui/gfx/geometry/rect.h"
22 class SurfaceIdAllocator
;
29 namespace native_viewport
{
30 class OnscreenContextProvider
;
31 } // namespace native_viewport
34 class ApplicationImpl
;
37 namespace view_manager
{
39 class DisplayManagerFactory
;
40 class EventDispatcher
;
43 // DisplayManager is used to connect the root ServerView to a display.
44 class DisplayManager
{
46 virtual ~DisplayManager() {}
48 static DisplayManager
* Create(
50 mojo::ApplicationImpl
* app_impl
,
51 const scoped_refptr
<gles2::GpuState
>& gpu_state
);
53 virtual void Init(DisplayManagerDelegate
* delegate
) = 0;
55 // Schedules a paint for the specified region in the coordinates of |view|.
56 virtual void SchedulePaint(const ServerView
* view
,
57 const gfx::Rect
& bounds
) = 0;
59 virtual void SetViewportSize(const gfx::Size
& size
) = 0;
61 virtual const mojo::ViewportMetrics
& GetViewportMetrics() = 0;
63 // Overrides factory for testing. Default (NULL) value indicates regular
64 // (non-test) environment.
65 static void set_factory_for_testing(DisplayManagerFactory
* factory
) {
66 DisplayManager::factory_
= factory
;
70 // Static factory instance (always NULL for non-test).
71 static DisplayManagerFactory
* factory_
;
74 // DisplayManager implementation that connects to the services necessary to
76 class DefaultDisplayManager
:
77 public DisplayManager
,
78 public native_viewport::PlatformViewport::Delegate
{
80 DefaultDisplayManager(bool is_headless
,
81 mojo::ApplicationImpl
* app_impl
,
82 const scoped_refptr
<gles2::GpuState
>& gpu_state
);
83 ~DefaultDisplayManager() override
;
86 void Init(DisplayManagerDelegate
* delegate
) override
;
87 void SchedulePaint(const ServerView
* view
, const gfx::Rect
& bounds
) override
;
88 void SetViewportSize(const gfx::Size
& size
) override
;
89 const mojo::ViewportMetrics
& GetViewportMetrics() override
;
96 // PlatformViewport::Delegate implementation:
97 void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget
,
98 float device_pixel_ratio
) override
;
99 void OnAcceleratedWidgetDestroyed() override
;
100 void OnEvent(mojo::EventPtr event
) override
;
101 void OnMetricsChanged(const gfx::Size
& size
,
102 float device_scale_factor
) override
;
103 void OnDestroyed() override
;
106 mojo::ApplicationImpl
* app_impl_
;
107 scoped_refptr
<gles2::GpuState
> gpu_state_
;
108 DisplayManagerDelegate
* delegate_
;
110 mojo::ViewportMetrics metrics_
;
111 gfx::Rect dirty_rect_
;
112 base::Timer draw_timer_
;
115 mojo::DisplayPtr display_
;
116 scoped_ptr
<native_viewport::OnscreenContextProvider
> context_provider_
;
117 scoped_ptr
<native_viewport::PlatformViewport
> platform_viewport_
;
119 base::WeakPtrFactory
<DefaultDisplayManager
> weak_factory_
;
121 DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager
);
124 } // namespace view_manager
126 #endif // COMPONENTS_VIEW_MANAGER_DISPLAY_MANAGER_H_