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_DRM_WINDOW_H_
6 #define UI_OZONE_PLATFORM_DRM_GPU_DRM_WINDOW_H_
10 #include "base/timer/timer.h"
11 #include "ui/gfx/geometry/point.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/gfx/swap_result.h"
15 #include "ui/ozone/ozone_export.h"
16 #include "ui/ozone/platform/drm/gpu/overlay_plane.h"
17 #include "ui/ozone/platform/drm/gpu/page_flip_request.h"
18 #include "ui/ozone/public/surface_ozone_egl.h"
30 class DrmDeviceManager
;
31 class HardwareDisplayController
;
32 struct OverlayCheck_Params
;
33 class ScanoutBufferGenerator
;
36 // The GPU object representing a window.
38 // The main purpose of this object is to associate drawing surfaces with
39 // displays. A surface created with the same id as the window (from
40 // GetAcceleratedWidget()) will paint onto that window. A window with
41 // the same bounds as a display will paint onto that display.
43 // If there's no display whose bounds match the window's, the window is
44 // disconnected and its contents will not be visible to the user.
45 class OZONE_EXPORT DrmWindow
{
47 DrmWindow(gfx::AcceleratedWidget widget
,
48 DrmDeviceManager
* device_manager
,
49 ScreenManager
* screen_manager
);
53 gfx::Rect
bounds() const { return bounds_
; }
59 // Returns the accelerated widget associated with the window.
60 gfx::AcceleratedWidget
GetAcceleratedWidget();
62 // Returns the current controller the window is displaying on. Callers should
63 // not cache the result as the controller may change as the window is moved.
64 HardwareDisplayController
* GetController();
66 void SetController(HardwareDisplayController
* controller
);
68 // Called when the window is resized/moved.
69 void OnBoundsChanged(const gfx::Rect
& bounds
);
71 // Update the HW cursor bitmap & move to specified location. If
72 // the bitmap is empty, the cursor is hidden.
73 void SetCursor(const std::vector
<SkBitmap
>& bitmaps
,
74 const gfx::Point
& location
,
77 // Update the HW cursor bitmap & move to specified location. If
78 // the bitmap is empty, the cursor is hidden.
79 void SetCursorWithoutAnimations(const std::vector
<SkBitmap
>& bitmaps
,
80 const gfx::Point
& location
);
82 // Move the HW cursor to the specified location.
83 void MoveCursor(const gfx::Point
& location
);
85 // Queue overlay planes and page flips.
86 // If hardware display controller is available, forward the information
87 // immediately, otherwise queue up on the window and forward when the hardware
88 // is once again ready.
89 void QueueOverlayPlane(const OverlayPlane
& plane
);
91 bool SchedulePageFlip(bool is_sync
, const SwapCompletionCallback
& callback
);
92 bool TestPageFlip(const std::vector
<OverlayCheck_Params
>& planes
,
93 ScanoutBufferGenerator
* buffer_generator
);
95 // Returns the last buffer associated with this window.
96 const OverlayPlane
* GetLastModesetBuffer();
99 // Draw the last set cursor & update the cursor plane.
100 void ResetCursor(bool bitmap_only
);
102 // Draw next frame in an animated cursor.
103 void OnCursorAnimationTimeout();
105 // When |controller_| changes this is called to reallocate the cursor buffers
106 // since the allocation DRM device may have changed.
107 void UpdateCursorBuffers();
109 gfx::AcceleratedWidget widget_
;
111 DrmDeviceManager
* device_manager_
; // Not owned.
112 ScreenManager
* screen_manager_
; // Not owned.
114 // The current bounds of the window.
117 // The controller associated with the current window. This may be nullptr if
118 // the window isn't over an active display.
119 HardwareDisplayController
* controller_
= nullptr;
121 base::RepeatingTimer
<DrmWindow
> cursor_timer_
;
123 scoped_refptr
<DrmBuffer
> cursor_buffers_
[2];
124 int cursor_frontbuffer_
= 0;
126 std::vector
<SkBitmap
> cursor_bitmaps_
;
127 gfx::Point cursor_location_
;
128 int cursor_frame_
= 0;
129 int cursor_frame_delay_ms_
= 0;
131 // Planes and flips currently being queued in the absence of hardware display
133 OverlayPlaneList pending_planes_
;
134 OverlayPlaneList last_submitted_planes_
;
135 bool last_swap_sync_
= false;
137 bool force_buffer_reallocation_
= false;
139 DISALLOW_COPY_AND_ASSIGN(DrmWindow
);
144 #endif // UI_OZONE_PLATFORM_DRM_GPU_DRM_WINDOW_H_