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 UI_OZONE_PLATFORM_DRM_GPU_SCREEN_MANAGER_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_SCREEN_MANAGER_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_vector.h"
11 #include "base/observer_list.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/ozone/ozone_export.h"
14 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
16 typedef struct _drmModeModeInfo drmModeModeInfo
;
28 class ScanoutBufferGenerator
;
30 // Responsible for keeping track of active displays and configuring them.
31 class OZONE_EXPORT ScreenManager
{
33 ScreenManager(ScanoutBufferGenerator
* surface_generator
);
34 virtual ~ScreenManager();
36 // Register a display controller. This must be called before trying to
38 void AddDisplayController(const scoped_refptr
<DrmDevice
>& drm
,
42 // Remove a display controller from the list of active controllers. The
43 // controller is removed since it was disconnected.
44 void RemoveDisplayController(const scoped_refptr
<DrmDevice
>& drm
,
47 // Configure a display controller. The display controller is identified by
48 // (|crtc|, |connector|) and the controller is modeset using |mode|.
49 bool ConfigureDisplayController(const scoped_refptr
<DrmDevice
>& drm
,
52 const gfx::Point
& origin
,
53 const drmModeModeInfo
& mode
);
55 // Disable the display controller identified by |crtc|. Note, the controller
56 // may still be connected, so this does not remove the controller.
57 bool DisableDisplayController(const scoped_refptr
<DrmDevice
>& drm
,
60 // Returns a reference to the display controller configured to display within
61 // |bounds|. If the caller caches the controller it must also register as an
62 // observer to be notified when the controller goes out of scope.
63 HardwareDisplayController
* GetDisplayController(const gfx::Rect
& bounds
);
65 // Adds a window for |widget|. Note: |widget| should not be associated with a
66 // window when calling this function.
67 void AddWindow(gfx::AcceleratedWidget widget
, scoped_ptr
<DrmWindow
> window
);
69 // Removes the window for |widget|. Note: |widget| must have a window
70 // associated with it when calling this function.
71 scoped_ptr
<DrmWindow
> RemoveWindow(gfx::AcceleratedWidget widget
);
73 // Returns the window associated with |widget|. Note: This function should be
74 // called only if a valid window has been associated with |widget|.
75 DrmWindow
* GetWindow(gfx::AcceleratedWidget widget
);
77 // Updates the mapping between display controllers and windows such that a
78 // controller will be associated with at most one window.
79 void UpdateControllerToWindowMapping();
82 typedef ScopedVector
<HardwareDisplayController
> HardwareDisplayControllers
;
84 typedef base::ScopedPtrHashMap
<gfx::AcceleratedWidget
, DrmWindow
>
87 // Returns an iterator into |controllers_| for the controller identified by
88 // (|crtc|, |connector|).
89 HardwareDisplayControllers::iterator
FindDisplayController(
90 const scoped_refptr
<DrmDevice
>& drm
,
93 bool ActualConfigureDisplayController(const scoped_refptr
<DrmDevice
>& drm
,
96 const gfx::Point
& origin
,
97 const drmModeModeInfo
& mode
);
99 // Returns an iterator into |controllers_| for the controller located at
101 HardwareDisplayControllers::iterator
FindActiveDisplayControllerByLocation(
102 const gfx::Rect
& bounds
);
104 // Perform modesetting in |controller| using |origin| and |mode|.
105 bool ModesetDisplayController(HardwareDisplayController
* controller
,
106 const gfx::Point
& origin
,
107 const drmModeModeInfo
& mode
);
109 // Tries to set the controller identified by (|crtc|, |connector|) to mirror
110 // those in |mirror|. |original| is an iterator to the HDC where the
111 // controller is currently present.
112 bool HandleMirrorMode(HardwareDisplayControllers::iterator original
,
113 HardwareDisplayControllers::iterator mirror
,
114 const scoped_refptr
<DrmDevice
>& drm
,
118 DrmWindow
* FindWindowAt(const gfx::Rect
& bounds
) const;
120 ScanoutBufferGenerator
* buffer_generator_
; // Not owned.
121 // List of display controllers (active and disabled).
122 HardwareDisplayControllers controllers_
;
124 WidgetToWindowMap window_map_
;
126 DISALLOW_COPY_AND_ASSIGN(ScreenManager
);
131 #endif // UI_OZONE_PLATFORM_DRM_GPU_SCREEN_MANAGER_H_