ozone: fix HDPMLegacy - do the PF after overlays, also clear old overlays
[chromium-blink-merge.git] / ui / ozone / platform / dri / crtc_controller.h
blobd9e26bc3c8403b12a5b1399057092ef25e4f327c
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_CRTC_CONTROLLER_H_
6 #define UI_OZONE_PLATFORM_DRI_CRTC_CONTROLLER_H_
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <xf86drmMode.h>
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "ui/ozone/platform/dri/hardware_display_plane_manager.h"
15 #include "ui/ozone/platform/dri/overlay_plane.h"
16 #include "ui/ozone/platform/dri/scoped_drm_types.h"
18 namespace ui {
20 class DriWrapper;
21 class PageFlipObserver;
23 // Wrapper around a CRTC.
25 // One CRTC can be paired up with one or more connectors. The simplest
26 // configuration represents one CRTC driving one monitor, while pairing up a
27 // CRTC with multiple connectors results in hardware mirroring.
28 class CrtcController : public base::SupportsWeakPtr<CrtcController> {
29 public:
30 CrtcController(DriWrapper* drm, uint32_t crtc, uint32_t connector);
31 ~CrtcController();
33 uint32_t crtc() const { return crtc_; }
34 uint32_t connector() const { return connector_; }
35 DriWrapper* drm() const { return drm_; }
36 bool is_disabled() const { return is_disabled_; }
37 bool page_flip_pending() const { return page_flip_pending_; }
38 uint64_t time_of_last_flip() const { return time_of_last_flip_; }
40 drmModeCrtc* saved_crtc() const { return saved_crtc_.get(); }
42 // Perform the initial modesetting operation using |plane| as the buffer for
43 // the primary plane. The CRTC configuration is specified by |mode|.
44 bool Modeset(const OverlayPlane& plane, drmModeModeInfo mode);
46 // Disables the controller.
47 bool Disable();
49 // Schedule a page flip event and present the overlays in |planes|.
50 bool SchedulePageFlip(HardwareDisplayPlaneList* plane_list,
51 const OverlayPlaneList& planes);
53 // Called if the page flip for this CRTC fails after being scheduled.
54 void PageFlipFailed();
56 // Called when the page flip event occurred. The event is provided by the
57 // kernel when a VBlank event finished. This allows the controller to
58 // update internal state and propagate the update to the surface.
59 // The tuple (seconds, useconds) represents the event timestamp. |seconds|
60 // represents the number of seconds while |useconds| represents the
61 // microseconds (< 1 second) in the timestamp.
62 void OnPageFlipEvent(unsigned int frame,
63 unsigned int seconds,
64 unsigned int useconds);
66 bool SetCursor(const scoped_refptr<ScanoutBuffer>& buffer);
67 bool UnsetCursor();
68 bool MoveCursor(const gfx::Point& location);
70 void AddObserver(PageFlipObserver* observer);
71 void RemoveObserver(PageFlipObserver* observer);
73 private:
74 DriWrapper* drm_; // Not owned.
76 HardwareDisplayPlaneManager* overlay_plane_manager_; // Not owned.
78 // Buffers need to be declared first so that they are destroyed last. Needed
79 // since the controllers may reference the buffers.
80 OverlayPlaneList current_planes_;
81 OverlayPlaneList pending_planes_;
82 scoped_refptr<ScanoutBuffer> cursor_buffer_;
84 uint32_t crtc_;
86 // TODO(dnicoara) Add support for hardware mirroring (multiple connectors).
87 uint32_t connector_;
89 drmModeModeInfo mode_;
91 // Store the state of the CRTC before we took over. Used to restore the CRTC
92 // once we no longer need it.
93 ScopedDrmCrtcPtr saved_crtc_;
95 // Keeps track of the CRTC state. If a surface has been bound, then the value
96 // is set to false. Otherwise it is true.
97 bool is_disabled_;
99 // True if a successful SchedulePageFlip occurred. Reset to false by a modeset
100 // operation or when the OnPageFlipEvent callback is triggered.
101 bool page_flip_pending_;
103 // The time of the last page flip event as reported by the kernel callback.
104 uint64_t time_of_last_flip_;
106 ObserverList<PageFlipObserver> observers_;
108 DISALLOW_COPY_AND_ASSIGN(CrtcController);
111 } // namespace ui
113 #endif // UI_OZONE_PLATFORM_DRI_CRTC_CONTROLLER_H_