OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ui/ozone/platform/dri/test/mock_dri_wrapper.h" | |
6 | |
7 #include <xf86drm.h> | |
8 #include <xf86drmMode.h> | |
9 | |
10 #include "base/logging.h" | |
11 #include "third_party/skia/include/core/SkCanvas.h" | |
12 #include "ui/ozone/platform/dri/hardware_display_plane_manager_legacy.h" | |
13 | |
14 namespace ui { | |
15 | |
16 namespace { | |
17 | |
18 template<class Object> Object* DrmAllocator() { | |
19 return static_cast<Object*>(drmMalloc(sizeof(Object))); | |
20 } | |
21 | |
22 class MockHardwareDisplayPlaneManager | |
23 : public HardwareDisplayPlaneManagerLegacy { | |
24 public: | |
25 MockHardwareDisplayPlaneManager(DriWrapper* drm, | |
26 std::vector<uint32_t> crtcs, | |
27 size_t planes_per_crtc) { | |
28 const int kPlaneBaseId = 50; | |
29 drm_ = drm; | |
30 crtcs_.swap(crtcs); | |
31 for (size_t crtc_idx = 0; crtc_idx < crtcs_.size(); crtc_idx++) { | |
32 for (size_t i = 0; i < planes_per_crtc; i++) { | |
33 planes_.push_back( | |
34 new HardwareDisplayPlane(kPlaneBaseId + i, 1 << crtc_idx)); | |
35 } | |
36 } | |
37 } | |
38 }; | |
39 | |
40 } // namespace | |
41 | |
42 MockDriWrapper::MockDriWrapper() | |
43 : DriWrapper(base::FilePath(), base::File()), | |
44 get_crtc_call_count_(0), | |
45 set_crtc_call_count_(0), | |
46 restore_crtc_call_count_(0), | |
47 add_framebuffer_call_count_(0), | |
48 remove_framebuffer_call_count_(0), | |
49 page_flip_call_count_(0), | |
50 overlay_flip_call_count_(0), | |
51 set_crtc_expectation_(true), | |
52 add_framebuffer_expectation_(true), | |
53 page_flip_expectation_(true), | |
54 create_dumb_buffer_expectation_(true), | |
55 current_framebuffer_(0) { | |
56 plane_manager_.reset(new HardwareDisplayPlaneManagerLegacy()); | |
57 } | |
58 | |
59 MockDriWrapper::MockDriWrapper(bool use_sync_flips, | |
60 std::vector<uint32_t> crtcs, | |
61 size_t planes_per_crtc) | |
62 : DriWrapper(base::FilePath(), base::File()), | |
63 get_crtc_call_count_(0), | |
64 set_crtc_call_count_(0), | |
65 restore_crtc_call_count_(0), | |
66 add_framebuffer_call_count_(0), | |
67 remove_framebuffer_call_count_(0), | |
68 page_flip_call_count_(0), | |
69 overlay_flip_call_count_(0), | |
70 overlay_clear_call_count_(0), | |
71 set_crtc_expectation_(true), | |
72 add_framebuffer_expectation_(true), | |
73 page_flip_expectation_(true), | |
74 create_dumb_buffer_expectation_(true), | |
75 use_sync_flips_(use_sync_flips), | |
76 current_framebuffer_(0) { | |
77 plane_manager_.reset( | |
78 new MockHardwareDisplayPlaneManager(this, crtcs, planes_per_crtc)); | |
79 } | |
80 | |
81 MockDriWrapper::~MockDriWrapper() { | |
82 } | |
83 | |
84 ScopedDrmCrtcPtr MockDriWrapper::GetCrtc(uint32_t crtc_id) { | |
85 get_crtc_call_count_++; | |
86 return ScopedDrmCrtcPtr(DrmAllocator<drmModeCrtc>()); | |
87 } | |
88 | |
89 bool MockDriWrapper::SetCrtc(uint32_t crtc_id, | |
90 uint32_t framebuffer, | |
91 std::vector<uint32_t> connectors, | |
92 drmModeModeInfo* mode) { | |
93 current_framebuffer_ = framebuffer; | |
94 set_crtc_call_count_++; | |
95 return set_crtc_expectation_; | |
96 } | |
97 | |
98 bool MockDriWrapper::SetCrtc(drmModeCrtc* crtc, | |
99 std::vector<uint32_t> connectors) { | |
100 restore_crtc_call_count_++; | |
101 return true; | |
102 } | |
103 | |
104 bool MockDriWrapper::DisableCrtc(uint32_t crtc_id) { | |
105 current_framebuffer_ = 0; | |
106 return true; | |
107 } | |
108 | |
109 ScopedDrmConnectorPtr MockDriWrapper::GetConnector(uint32_t connector_id) { | |
110 return ScopedDrmConnectorPtr(DrmAllocator<drmModeConnector>()); | |
111 } | |
112 | |
113 bool MockDriWrapper::AddFramebuffer(uint32_t width, | |
114 uint32_t height, | |
115 uint8_t depth, | |
116 uint8_t bpp, | |
117 uint32_t stride, | |
118 uint32_t handle, | |
119 uint32_t* framebuffer) { | |
120 add_framebuffer_call_count_++; | |
121 *framebuffer = add_framebuffer_call_count_; | |
122 return add_framebuffer_expectation_; | |
123 } | |
124 | |
125 bool MockDriWrapper::RemoveFramebuffer(uint32_t framebuffer) { | |
126 remove_framebuffer_call_count_++; | |
127 return true; | |
128 } | |
129 | |
130 ScopedDrmFramebufferPtr MockDriWrapper::GetFramebuffer(uint32_t framebuffer) { | |
131 return ScopedDrmFramebufferPtr(); | |
132 } | |
133 | |
134 bool MockDriWrapper::PageFlip(uint32_t crtc_id, | |
135 uint32_t framebuffer, | |
136 bool is_sync, | |
137 const PageFlipCallback& callback) { | |
138 page_flip_call_count_++; | |
139 current_framebuffer_ = framebuffer; | |
140 if (page_flip_expectation_) { | |
141 if (use_sync_flips_) | |
142 callback.Run(0, 0, 0); | |
143 else | |
144 callbacks_.push(callback); | |
145 } | |
146 | |
147 return page_flip_expectation_; | |
148 } | |
149 | |
150 bool MockDriWrapper::PageFlipOverlay(uint32_t crtc_id, | |
151 uint32_t framebuffer, | |
152 const gfx::Rect& location, | |
153 const gfx::Rect& source, | |
154 int overlay_plane) { | |
155 if (!framebuffer) | |
156 overlay_clear_call_count_++; | |
157 overlay_flip_call_count_++; | |
158 return true; | |
159 } | |
160 | |
161 ScopedDrmPropertyPtr MockDriWrapper::GetProperty(drmModeConnector* connector, | |
162 const char* name) { | |
163 return ScopedDrmPropertyPtr(DrmAllocator<drmModePropertyRes>()); | |
164 } | |
165 | |
166 bool MockDriWrapper::SetProperty(uint32_t connector_id, | |
167 uint32_t property_id, | |
168 uint64_t value) { | |
169 return true; | |
170 } | |
171 | |
172 bool MockDriWrapper::GetCapability(uint64_t capability, uint64_t* value) { | |
173 return true; | |
174 } | |
175 | |
176 ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob( | |
177 drmModeConnector* connector, | |
178 const char* name) { | |
179 return ScopedDrmPropertyBlobPtr(DrmAllocator<drmModePropertyBlobRes>()); | |
180 } | |
181 | |
182 bool MockDriWrapper::SetCursor(uint32_t crtc_id, | |
183 uint32_t handle, | |
184 const gfx::Size& size) { | |
185 return true; | |
186 } | |
187 | |
188 bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) { | |
189 return true; | |
190 } | |
191 | |
192 bool MockDriWrapper::CreateDumbBuffer(const SkImageInfo& info, | |
193 uint32_t* handle, | |
194 uint32_t* stride, | |
195 void** pixels) { | |
196 if (!create_dumb_buffer_expectation_) | |
197 return false; | |
198 | |
199 *handle = 0; | |
200 *stride = info.minRowBytes(); | |
201 *pixels = new char[info.getSafeSize(*stride)]; | |
202 buffers_.push_back( | |
203 skia::AdoptRef(SkSurface::NewRasterDirect(info, *pixels, *stride))); | |
204 buffers_.back()->getCanvas()->clear(SK_ColorBLACK); | |
205 | |
206 return true; | |
207 } | |
208 | |
209 void MockDriWrapper::DestroyDumbBuffer(const SkImageInfo& info, | |
210 uint32_t handle, | |
211 uint32_t stride, | |
212 void* pixels) { | |
213 delete[] static_cast<char*>(pixels); | |
214 } | |
215 | |
216 void MockDriWrapper::RunCallbacks() { | |
217 while (!callbacks_.empty()) { | |
218 PageFlipCallback callback = callbacks_.front(); | |
219 callbacks_.pop(); | |
220 callback.Run(0, 0, 0); | |
221 } | |
222 } | |
223 | |
224 } // namespace ui | |
OLD | NEW |