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_TEST_MOCK_DRM_DEVICE_H_
6 #define UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRM_DEVICE_H_
11 #include "skia/ext/refptr.h"
12 #include "third_party/skia/include/core/SkSurface.h"
13 #include "ui/ozone/platform/dri/drm_device.h"
19 // The real DrmDevice makes actual DRM calls which we can't use in unit tests.
20 class MockDrmDevice
: public ui::DrmDevice
{
23 MockDrmDevice(bool use_sync_flips
,
24 std::vector
<uint32_t> crtcs
,
25 size_t planes_per_crtc
);
27 int get_get_crtc_call_count() const { return get_crtc_call_count_
; }
28 int get_set_crtc_call_count() const { return set_crtc_call_count_
; }
29 int get_restore_crtc_call_count() const { return restore_crtc_call_count_
; }
30 int get_add_framebuffer_call_count() const {
31 return add_framebuffer_call_count_
;
33 int get_remove_framebuffer_call_count() const {
34 return remove_framebuffer_call_count_
;
36 int get_page_flip_call_count() const { return page_flip_call_count_
; }
37 int get_overlay_flip_call_count() const { return overlay_flip_call_count_
; }
38 int get_overlay_clear_call_count() const { return overlay_clear_call_count_
; }
39 void set_set_crtc_expectation(bool state
) { set_crtc_expectation_
= state
; }
40 void set_page_flip_expectation(bool state
) { page_flip_expectation_
= state
; }
41 void set_add_framebuffer_expectation(bool state
) {
42 add_framebuffer_expectation_
= state
;
44 void set_create_dumb_buffer_expectation(bool state
) {
45 create_dumb_buffer_expectation_
= state
;
48 uint32_t current_framebuffer() const { return current_framebuffer_
; }
50 const std::vector
<skia::RefPtr
<SkSurface
>> buffers() const {
57 ScopedDrmCrtcPtr
GetCrtc(uint32_t crtc_id
) override
;
58 bool SetCrtc(uint32_t crtc_id
,
60 std::vector
<uint32_t> connectors
,
61 drmModeModeInfo
* mode
) override
;
62 bool SetCrtc(drmModeCrtc
* crtc
, std::vector
<uint32_t> connectors
) override
;
63 bool DisableCrtc(uint32_t crtc_id
) override
;
64 ScopedDrmConnectorPtr
GetConnector(uint32_t connector_id
) override
;
65 bool AddFramebuffer(uint32_t width
,
71 uint32_t* framebuffer
) override
;
72 bool RemoveFramebuffer(uint32_t framebuffer
) override
;
73 ScopedDrmFramebufferPtr
GetFramebuffer(uint32_t framebuffer
) override
;
74 bool PageFlip(uint32_t crtc_id
,
77 const PageFlipCallback
& callback
) override
;
78 bool PageFlipOverlay(uint32_t crtc_id
,
80 const gfx::Rect
& location
,
81 const gfx::Rect
& source
,
82 int overlay_plane
) override
;
83 ScopedDrmPropertyPtr
GetProperty(drmModeConnector
* connector
,
84 const char* name
) override
;
85 bool SetProperty(uint32_t connector_id
,
87 uint64_t value
) override
;
88 bool GetCapability(uint64_t capability
, uint64_t* value
) override
;
89 ScopedDrmPropertyBlobPtr
GetPropertyBlob(drmModeConnector
* connector
,
90 const char* name
) override
;
91 bool SetCursor(uint32_t crtc_id
,
93 const gfx::Size
& size
) override
;
94 bool MoveCursor(uint32_t crtc_id
, const gfx::Point
& point
) override
;
95 bool CreateDumbBuffer(const SkImageInfo
& info
,
98 void** pixels
) override
;
99 void DestroyDumbBuffer(const SkImageInfo
& info
,
102 void* pixels
) override
;
105 ~MockDrmDevice() override
;
107 int get_crtc_call_count_
;
108 int set_crtc_call_count_
;
109 int restore_crtc_call_count_
;
110 int add_framebuffer_call_count_
;
111 int remove_framebuffer_call_count_
;
112 int page_flip_call_count_
;
113 int overlay_flip_call_count_
;
114 int overlay_clear_call_count_
;
116 bool set_crtc_expectation_
;
117 bool add_framebuffer_expectation_
;
118 bool page_flip_expectation_
;
119 bool create_dumb_buffer_expectation_
;
121 bool use_sync_flips_
;
123 uint32_t current_framebuffer_
;
125 std::vector
<skia::RefPtr
<SkSurface
>> buffers_
;
127 std::queue
<PageFlipCallback
> callbacks_
;
129 DISALLOW_COPY_AND_ASSIGN(MockDrmDevice
);
134 #endif // UI_OZONE_PLATFORM_DRI_TEST_MOCK_DRM_DEVICE_H_