Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / ozone / platform / drm / test / mock_drm_device.h
bloba25bad9e91b1edfadf8e8d3ea232c554b4219198
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_
8 #include <map>
9 #include <queue>
10 #include <vector>
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"
16 namespace ui {
18 class CrtcController;
19 struct GammaRampRGBEntry;
21 // The real DrmDevice makes actual DRM calls which we can't use in unit tests.
22 class MockDrmDevice : public ui::DrmDevice {
23 public:
24 MockDrmDevice();
25 MockDrmDevice(bool use_sync_flips,
26 std::vector<uint32_t> crtcs,
27 size_t planes_per_crtc);
29 int get_get_crtc_call_count() const { return get_crtc_call_count_; }
30 int get_set_crtc_call_count() const { return set_crtc_call_count_; }
31 int get_restore_crtc_call_count() const { return restore_crtc_call_count_; }
32 int get_add_framebuffer_call_count() const {
33 return add_framebuffer_call_count_;
35 int get_remove_framebuffer_call_count() const {
36 return remove_framebuffer_call_count_;
38 int get_page_flip_call_count() const { return page_flip_call_count_; }
39 int get_overlay_flip_call_count() const { return overlay_flip_call_count_; }
40 int get_overlay_clear_call_count() const { return overlay_clear_call_count_; }
41 void set_set_crtc_expectation(bool state) { set_crtc_expectation_ = state; }
42 void set_page_flip_expectation(bool state) { page_flip_expectation_ = state; }
43 void set_add_framebuffer_expectation(bool state) {
44 add_framebuffer_expectation_ = state;
46 void set_create_dumb_buffer_expectation(bool state) {
47 create_dumb_buffer_expectation_ = state;
50 uint32_t current_framebuffer() const { return current_framebuffer_; }
52 const std::vector<skia::RefPtr<SkSurface>> buffers() const {
53 return buffers_;
56 uint32_t get_cursor_handle_for_crtc(uint32_t crtc) const {
57 const auto it = crtc_cursor_map_.find(crtc);
58 return it != crtc_cursor_map_.end() ? it->second : 0;
61 void RunCallbacks();
63 // DrmDevice:
64 ScopedDrmCrtcPtr GetCrtc(uint32_t crtc_id) override;
65 bool SetCrtc(uint32_t crtc_id,
66 uint32_t framebuffer,
67 std::vector<uint32_t> connectors,
68 drmModeModeInfo* mode) override;
69 bool SetCrtc(drmModeCrtc* crtc, std::vector<uint32_t> connectors) override;
70 bool DisableCrtc(uint32_t crtc_id) override;
71 ScopedDrmConnectorPtr GetConnector(uint32_t connector_id) override;
72 bool AddFramebuffer(uint32_t width,
73 uint32_t height,
74 uint8_t depth,
75 uint8_t bpp,
76 uint32_t stride,
77 uint32_t handle,
78 uint32_t* framebuffer) override;
79 bool RemoveFramebuffer(uint32_t framebuffer) override;
80 ScopedDrmFramebufferPtr GetFramebuffer(uint32_t framebuffer) override;
81 bool PageFlip(uint32_t crtc_id,
82 uint32_t framebuffer,
83 bool is_sync,
84 const PageFlipCallback& callback) override;
85 bool PageFlipOverlay(uint32_t crtc_id,
86 uint32_t framebuffer,
87 const gfx::Rect& location,
88 const gfx::Rect& source,
89 int overlay_plane) override;
90 ScopedDrmPropertyPtr GetProperty(drmModeConnector* connector,
91 const char* name) override;
92 bool SetProperty(uint32_t connector_id,
93 uint32_t property_id,
94 uint64_t value) override;
95 bool GetCapability(uint64_t capability, uint64_t* value) override;
96 ScopedDrmPropertyBlobPtr GetPropertyBlob(drmModeConnector* connector,
97 const char* name) override;
98 bool SetCursor(uint32_t crtc_id,
99 uint32_t handle,
100 const gfx::Size& size) override;
101 bool MoveCursor(uint32_t crtc_id, const gfx::Point& point) override;
102 bool CreateDumbBuffer(const SkImageInfo& info,
103 uint32_t* handle,
104 uint32_t* stride) override;
105 bool DestroyDumbBuffer(uint32_t handle) override;
106 bool MapDumbBuffer(uint32_t handle, size_t size, void** pixels) override;
107 bool UnmapDumbBuffer(void* pixels, size_t size) override;
108 bool CloseBufferHandle(uint32_t handle) override;
109 bool CommitProperties(drmModePropertySet* properties,
110 uint32_t flags,
111 bool is_sync,
112 bool test_only,
113 const PageFlipCallback& callback) override;
114 bool SetGammaRamp(uint32_t crtc_id,
115 const std::vector<GammaRampRGBEntry>& lut) override;
116 bool SetCapability(uint64_t capability, uint64_t value) override;
118 private:
119 ~MockDrmDevice() override;
121 int get_crtc_call_count_;
122 int set_crtc_call_count_;
123 int restore_crtc_call_count_;
124 int add_framebuffer_call_count_;
125 int remove_framebuffer_call_count_;
126 int page_flip_call_count_;
127 int overlay_flip_call_count_;
128 int overlay_clear_call_count_;
129 int allocate_buffer_count_;
131 bool set_crtc_expectation_;
132 bool add_framebuffer_expectation_;
133 bool page_flip_expectation_;
134 bool create_dumb_buffer_expectation_;
136 bool use_sync_flips_;
138 uint32_t current_framebuffer_;
140 std::vector<skia::RefPtr<SkSurface>> buffers_;
142 std::map<uint32_t, uint32_t> crtc_cursor_map_;
144 std::queue<PageFlipCallback> callbacks_;
146 DISALLOW_COPY_AND_ASSIGN(MockDrmDevice);
149 } // namespace ui
151 #endif // UI_OZONE_PLATFORM_DRM_TEST_MOCK_DRM_DEVICE_H_