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_TEST_MOCK_DRM_DEVICE_H_
6 #define UI_OZONE_PLATFORM_DRM_TEST_MOCK_DRM_DEVICE_H_
12 #include "skia/ext/refptr.h"
13 #include "third_party/skia/include/core/SkSurface.h"
14 #include "ui/ozone/platform/drm/gpu/drm_device.h"
20 // The real DrmDevice makes actual DRM calls which we can't use in unit tests.
21 class MockDrmDevice
: public ui::DrmDevice
{
24 MockDrmDevice(bool use_sync_flips
,
25 std::vector
<uint32_t> crtcs
,
26 size_t planes_per_crtc
);
28 int get_get_crtc_call_count() const { return get_crtc_call_count_
; }
29 int get_set_crtc_call_count() const { return set_crtc_call_count_
; }
30 int get_restore_crtc_call_count() const { return restore_crtc_call_count_
; }
31 int get_add_framebuffer_call_count() const {
32 return add_framebuffer_call_count_
;
34 int get_remove_framebuffer_call_count() const {
35 return remove_framebuffer_call_count_
;
37 int get_page_flip_call_count() const { return page_flip_call_count_
; }
38 int get_overlay_flip_call_count() const { return overlay_flip_call_count_
; }
39 int get_overlay_clear_call_count() const { return overlay_clear_call_count_
; }
40 void set_set_crtc_expectation(bool state
) { set_crtc_expectation_
= state
; }
41 void set_page_flip_expectation(bool state
) { page_flip_expectation_
= state
; }
42 void set_add_framebuffer_expectation(bool state
) {
43 add_framebuffer_expectation_
= state
;
45 void set_create_dumb_buffer_expectation(bool state
) {
46 create_dumb_buffer_expectation_
= state
;
49 uint32_t current_framebuffer() const { return current_framebuffer_
; }
51 const std::vector
<skia::RefPtr
<SkSurface
>> buffers() const {
55 uint32_t get_cursor_handle_for_crtc(uint32_t crtc
) const {
56 const auto it
= crtc_cursor_map_
.find(crtc
);
57 return it
!= crtc_cursor_map_
.end() ? it
->second
: 0;
63 ScopedDrmCrtcPtr
GetCrtc(uint32_t crtc_id
) override
;
64 bool SetCrtc(uint32_t crtc_id
,
66 std::vector
<uint32_t> connectors
,
67 drmModeModeInfo
* mode
) override
;
68 bool SetCrtc(drmModeCrtc
* crtc
, std::vector
<uint32_t> connectors
) override
;
69 bool DisableCrtc(uint32_t crtc_id
) override
;
70 ScopedDrmConnectorPtr
GetConnector(uint32_t connector_id
) override
;
71 bool AddFramebuffer(uint32_t width
,
77 uint32_t* framebuffer
) override
;
78 bool RemoveFramebuffer(uint32_t framebuffer
) override
;
79 ScopedDrmFramebufferPtr
GetFramebuffer(uint32_t framebuffer
) override
;
80 bool PageFlip(uint32_t crtc_id
,
83 const PageFlipCallback
& callback
) override
;
84 bool PageFlipOverlay(uint32_t crtc_id
,
86 const gfx::Rect
& location
,
87 const gfx::Rect
& source
,
88 int overlay_plane
) override
;
89 ScopedDrmPropertyPtr
GetProperty(drmModeConnector
* connector
,
90 const char* name
) override
;
91 bool SetProperty(uint32_t connector_id
,
93 uint64_t value
) override
;
94 bool GetCapability(uint64_t capability
, uint64_t* value
) override
;
95 ScopedDrmPropertyBlobPtr
GetPropertyBlob(drmModeConnector
* connector
,
96 const char* name
) override
;
97 bool SetCursor(uint32_t crtc_id
,
99 const gfx::Size
& size
) override
;
100 bool MoveCursor(uint32_t crtc_id
, const gfx::Point
& point
) override
;
101 bool CreateDumbBuffer(const SkImageInfo
& info
,
104 void** pixels
) override
;
105 void DestroyDumbBuffer(const SkImageInfo
& info
,
108 void* pixels
) override
;
109 bool CommitProperties(drmModePropertySet
* properties
,
111 const PageFlipCallback
& callback
) override
;
114 ~MockDrmDevice() override
;
116 int get_crtc_call_count_
;
117 int set_crtc_call_count_
;
118 int restore_crtc_call_count_
;
119 int add_framebuffer_call_count_
;
120 int remove_framebuffer_call_count_
;
121 int page_flip_call_count_
;
122 int overlay_flip_call_count_
;
123 int overlay_clear_call_count_
;
124 int allocate_buffer_count_
;
126 bool set_crtc_expectation_
;
127 bool add_framebuffer_expectation_
;
128 bool page_flip_expectation_
;
129 bool create_dumb_buffer_expectation_
;
131 bool use_sync_flips_
;
133 uint32_t current_framebuffer_
;
135 std::vector
<skia::RefPtr
<SkSurface
>> buffers_
;
137 std::map
<uint32_t, uint32_t> crtc_cursor_map_
;
139 std::queue
<PageFlipCallback
> callbacks_
;
141 DISALLOW_COPY_AND_ASSIGN(MockDrmDevice
);
146 #endif // UI_OZONE_PLATFORM_DRM_TEST_MOCK_DRM_DEVICE_H_