ozone: fix HDPMLegacy - do the PF after overlays, also clear old overlays
[chromium-blink-merge.git] / ui / ozone / platform / dri / hardware_display_plane_manager.h
blobd45c7b79cd86098243c1bc3b33f9a7637bcf56be
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_DRI_HARDWARE_DISPLAY_PLANE_MANAGER_H_
6 #define UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_PLANE_MANAGER_H_
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <xf86drmMode.h>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_vector.h"
15 #include "ui/ozone/platform/dri/hardware_display_plane.h"
16 #include "ui/ozone/platform/dri/overlay_plane.h"
17 #include "ui/ozone/platform/dri/scoped_drm_types.h"
19 namespace gfx {
20 class Rect;
21 } // namespace gfx
23 namespace ui {
25 class DriWrapper;
26 class CrtcController;
28 // This contains the list of planes controlled by one HDC on a given DRM fd.
29 // It is owned by the HDC and filled by the CrtcController.
30 struct HardwareDisplayPlaneList {
31 HardwareDisplayPlaneList();
32 ~HardwareDisplayPlaneList();
34 // This is the list of planes to be committed this time.
35 std::vector<HardwareDisplayPlane*> plane_list;
36 // This is the list of planes that was committed last time.
37 std::vector<HardwareDisplayPlane*> old_plane_list;
39 struct PageFlipInfo {
40 PageFlipInfo(uint32_t crtc_id,
41 uint32_t framebuffer,
42 int plane,
43 CrtcController* crtc);
44 ~PageFlipInfo();
46 uint32_t crtc_id;
47 uint32_t framebuffer;
48 int plane;
49 CrtcController* crtc;
51 struct Plane {
52 Plane(int plane,
53 int framebuffer,
54 const gfx::Rect& bounds,
55 const gfx::Rect& src_rect);
56 ~Plane();
57 int plane;
58 int framebuffer;
59 gfx::Rect bounds;
60 gfx::Rect src_rect;
62 std::vector<Plane> planes;
64 // In the case of non-atomic operation, this info will be used for
65 // pageflipping.
66 std::vector<PageFlipInfo> legacy_page_flips;
68 // Set if the last operation on this list was a Commit().
69 bool committed;
72 class HardwareDisplayPlaneManager {
73 public:
74 HardwareDisplayPlaneManager();
75 virtual ~HardwareDisplayPlaneManager();
77 // This parses information from the drm driver, adding any new planes
78 // or crtcs found.
79 bool Initialize(DriWrapper* drm);
81 // Assign hardware planes from the |planes_| list to |overlay_list| entries,
82 // recording the plane IDs in the |plane_list|. Only planes compatible with
83 // |crtc_id| will be used. |overlay_list| must be sorted bottom-to-top.
84 virtual bool AssignOverlayPlanes(HardwareDisplayPlaneList* plane_list,
85 const OverlayPlaneList& overlay_list,
86 uint32_t crtc_id,
87 CrtcController* crtc);
89 // Commit the plane states in |plane_list|.
90 virtual bool Commit(HardwareDisplayPlaneList* plane_list) = 0;
92 // Set all planes in |plane_list| owned by |crtc_id| to free.
93 static void ResetPlanes(HardwareDisplayPlaneList* plane_list,
94 uint32_t crtc_id);
96 const ScopedVector<HardwareDisplayPlane>& planes() { return planes_; }
98 protected:
99 virtual bool SetPlaneData(HardwareDisplayPlaneList* plane_list,
100 HardwareDisplayPlane* hw_plane,
101 const OverlayPlane& overlay,
102 uint32_t crtc_id,
103 const gfx::Rect& src_rect,
104 CrtcController* crtc) = 0;
105 // Finds the plane located at or after |*index| that is not in use and can
106 // be used with |crtc_index|.
107 HardwareDisplayPlane* FindNextUnusedPlane(size_t* index, uint32_t crtc_index);
109 // Convert |crtc_id| into an index, returning -1 if the ID couldn't be found.
110 int LookupCrtcIndex(uint32_t crtc_id);
112 // Object containing the connection to the graphics device and wraps the API
113 // calls to control it. Not owned.
114 DriWrapper* drm_;
116 ScopedVector<HardwareDisplayPlane> planes_;
117 std::vector<uint32_t> crtcs_;
119 DISALLOW_COPY_AND_ASSIGN(HardwareDisplayPlaneManager);
122 } // namespace ui
124 #endif // UI_OZONE_PLATFORM_DRI_HARDWARE_DISPLAY_PLANE_MANAGER_H_